public
Last active

xd.lsp - 16進ダンプツール (hexdump -C風味)

  • Download Gist
xd.lsp
Common Lisp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/usr/bin/newlisp
 
;; Hex dump tool
;; Usage: newlisp xd.lsp < FILENAME
 
(constant 'stdin 0)
 
(define-macro (loop)
(let ((return throw))
(catch (while true
(map eval (args))))))
 
(setq offset 0)
(loop
(or (read stdin s 16) (return 'eof))
;; ADDRESS
(print (format "%08X " offset))
;; HEXDUMP
(print (format (dup "%02X " (length s))
(unpack (dup "b" (length s)) s))
(dup " " (- 16 (length s))))
;; CHARACTER
(print " |" (replace "[^[:print:]]" s "." 0) "|\n")
(++ offset (length s)))
 
(exit)

read関数が指定したバイト数より小さい場合でも入力を受けつけるのがちょっと気になる…。

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.