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