Created
May 30, 2010 15:54
-
-
Save kosh04/419119 to your computer and use it in GitHub Desktop.
xd.lsp - 16進ダンプツール (hexdump -C風味)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
read関数が指定したバイト数より小さい場合でも入力を受けつけるのがちょっと気になる…。