hexdump -- blah. instead of .blah
parent
776df12c04
commit
eb3008bfaa
|
@ -1,13 +1,13 @@
|
|||
USING: io kernel math namespaces prettyprint sequences strings ;
|
||||
IN: hexdump-internals
|
||||
|
||||
: .header ( len -- )
|
||||
: header. ( len -- )
|
||||
"Length: " write dup unparse write ", " write >hex write "h" write terpri ;
|
||||
|
||||
: .offset ( lineno -- ) 16 * >hex 8 CHAR: 0 pad-left write "h: " write ;
|
||||
: .h-pad ( digit -- ) >hex 2 CHAR: 0 pad-left write ;
|
||||
: .line ( str n -- )
|
||||
.offset [ [ .h-pad " " write ] each ] keep
|
||||
: offset. ( lineno -- ) 16 * >hex 8 CHAR: 0 pad-left write "h: " write ;
|
||||
: h-pad. ( digit -- ) >hex 2 CHAR: 0 pad-left write ;
|
||||
: line. ( str n -- )
|
||||
offset. [ [ h-pad. " " write ] each ] keep
|
||||
16 over length - [ " " write ] times
|
||||
[ dup printable? [ drop CHAR: . ] unless ch>string write ] each
|
||||
terpri ;
|
||||
|
@ -16,11 +16,11 @@ IN: hexdump
|
|||
: hexdump ( str -- str )
|
||||
#! Write hexdump to a string
|
||||
[
|
||||
dup length .header
|
||||
16 group dup length [ .line ] 2each
|
||||
dup length header.
|
||||
16 group dup length [ line. ] 2each
|
||||
] string-out ;
|
||||
|
||||
: .hexdump ( str -- )
|
||||
: hexdump. ( str -- )
|
||||
#! Print hexdump
|
||||
hexdump write ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue