newLISP Fan Club

Forum => So, what can you actually DO with newLISP? => Topic started by: newdep on March 22, 2004, 04:13:29 PM

Title: 5 Cent tip for today [ Hexdump ]
Post by: newdep on March 22, 2004, 04:13:29 PM
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)

;---------------------------------------------------------------------------
Title:
Post by: Lutz on March 23, 2004, 05:26:43 AM
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



thanks



lutz
Title:
Post by: newdep on March 24, 2004, 12:02:10 PM
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.