5 Cent tip for today [ Hexdump ]
Posted: Tue Mar 23, 2004 12:13 am
yes its an oldy, but its always good to have one around ;-)
#!/usr/bin/newlisp
;
;
; HEXDUMP - NEWLISP
;
; Does a quick hex dump on a commandline from filename (watch out :)
; If your not using this as a direct executable from the command line
; Change the (nth 2 (main-args)) into (nth 3 (main-args))
; because the complete line is argument under newlisp.
;
; usage: hex ./filename > log
;
; 000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F abcedfghijklmnno
; 000016 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 1234567890abcdef
; ...
; ...
;
; More Elegant is possible, Enjoy, Norman.
;
(pretty-print 100)
;---------------------------------------------------------------------------
(unless (set 'infile (open (nth 2 (main-args)) "read"))
(begin
(println "Unable to open" (nth 2 (main-args)))
(exit))
(println "Dumping -> " (nth 2 (main-args))))
(while (> (set 'sofar (read-buffer infile 'buff 16 )) 0)
(if (< sofar 16 ) (dotimes (x (- 16 sofar)) (set 'buff (append buff (char 0)))))
(dolist (x (explode buff)) (print (format "%02X " (char x))))
(dolist (x (explode buff)) (unless (and (>= (char x) 32) (<= (char x) 126)) (print ".") (print x)))
(println ""))
(close infile)
(println "Done")
(exit)
;---------------------------------------------------------------------------
#!/usr/bin/newlisp
;
;
; HEXDUMP - NEWLISP
;
; Does a quick hex dump on a commandline from filename (watch out :)
; If your not using this as a direct executable from the command line
; Change the (nth 2 (main-args)) into (nth 3 (main-args))
; because the complete line is argument under newlisp.
;
; usage: hex ./filename > log
;
; 000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F abcedfghijklmnno
; 000016 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 1234567890abcdef
; ...
; ...
;
; More Elegant is possible, Enjoy, Norman.
;
(pretty-print 100)
;---------------------------------------------------------------------------
(unless (set 'infile (open (nth 2 (main-args)) "read"))
(begin
(println "Unable to open" (nth 2 (main-args)))
(exit))
(println "Dumping -> " (nth 2 (main-args))))
(while (> (set 'sofar (read-buffer infile 'buff 16 )) 0)
(if (< sofar 16 ) (dotimes (x (- 16 sofar)) (set 'buff (append buff (char 0)))))
(dolist (x (explode buff)) (print (format "%02X " (char x))))
(dolist (x (explode buff)) (unless (and (>= (char x) 32) (<= (char x) 126)) (print ".") (print x)))
(println ""))
(close infile)
(println "Done")
(exit)
;---------------------------------------------------------------------------