lib/zhexdump.rb in zhexdump-0.0.2 vs lib/zhexdump.rb in zhexdump-0.1.0

- old
+ new

@@ -28,16 +28,19 @@ if offset == false show_offset = false offset = 0 end - add = h[:add] || 0 - size = h[:size] || (data.size-offset) - tail = h[:tail] || "\n" - width = h[:width] || 0x10 # row width, in bytes - output = h[:output] || $> + add = h[:add] || 0 + size = h[:size] || (data.size-offset) + tail = h[:tail] || "\n" + width = h[:width] || 0x10 # row width, in bytes + output = h[:output] || $> + indent = h[:indent] || 0 + offset_format = h[:offset_format] || "%08x: " + indent = ' ' * indent size = data.size-offset if size+offset > data.size prevhex = ''; c = nil; prevdup = false; start = offset while true ascii = ''; hex = '' @@ -60,11 +63,11 @@ output << "\n" if offset > start output << row end prevdup = true else - row = (show_offset ? ("%08x: " % (offset + add)) : '') + hex + row = indent + (show_offset ? (offset_format % (offset + add)) : '') + hex yield(row, offset+add, ascii) if block_given? row << ' |' + ascii + "|" output << "\n" if offset > start output << row prevdup = false @@ -73,10 +76,10 @@ offset += width prevhex = hex break if size <= 0 end if show_offset && prevdup - row = "%08x: " % (offset + add) + row = indent + (offset_format % (offset + add)) yield(row) if block_given? output << "\n" << row end output << tail end # dump