5 Cent tip for today [ Hexdump ]

Started by newdep, March 22, 2004, 04:13:29 PM

Previous topic - Next topic

newdep

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)

;---------------------------------------------------------------------------
-- (define? (Cornflakes))

Lutz

#1
Actually (pretty-print 100) is not necessary in your program. Pretty print only controls the printing of expressions when doing 'save' or 'source' pretty-print formatting expressions.



I'll also include in: http://www.newlisp.org/norman-5-cent.txt">http://www.newlisp.org/norman-5-cent.txt



thanks



lutz

newdep

#2
Hello Lutz,



I need pritty-print in my X-windows terminals otherwise i always get the

default from the nelwisp-realine IO when executing newlisp scripts...



The syslog example also has it where it prints direclty from a buffer,

if i dont use pritty-print there i.e. then the output gets messed-up...





Norman.
-- (define? (Cornflakes))