2008-01-20 11:52:50 -05:00
|
|
|
USING: arrays combinators.lib io io.streams.string
|
2008-02-01 19:26:32 -05:00
|
|
|
kernel math math.parser namespaces prettyprint
|
|
|
|
sequences splitting strings ascii ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: hexdump
|
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
: header. ( len -- )
|
|
|
|
"Length: " write dup unparse write ", " write >hex write "h" write nl ;
|
|
|
|
|
2008-01-20 11:52:50 -05:00
|
|
|
: offset. ( lineno -- )
|
|
|
|
16 * >hex 8 CHAR: 0 pad-left write "h: " write ;
|
|
|
|
|
|
|
|
: h-pad. ( digit -- )
|
|
|
|
>hex 2 CHAR: 0 pad-left write ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: line. ( str n -- )
|
|
|
|
offset.
|
|
|
|
dup [ h-pad. " " write ] each
|
2008-01-20 11:52:50 -05:00
|
|
|
16 over length - 3 * CHAR: \s <string> write
|
2007-09-20 18:09:08 -04:00
|
|
|
[ dup printable? [ drop CHAR: . ] unless write1 ] each
|
|
|
|
nl ;
|
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
: hexdump ( seq -- str )
|
|
|
|
[
|
|
|
|
dup length header.
|
2008-01-20 11:52:50 -05:00
|
|
|
16 <sliced-groups> [ line. ] each-index
|
2007-09-20 18:09:08 -04:00
|
|
|
] string-out ;
|
|
|
|
|
|
|
|
: hexdump. ( seq -- )
|
|
|
|
hexdump write ;
|