#!/usr/bin/snobol5 * Hexadecimal dump of file * Windows usage: snobol5 hexadump :filename * Linux usage: snobol5 hexadump :filename * Linux usage: hexadump :filename (if snobol5 is at /usr/bin/snobol5 per first line above) * For interactive version, don't specify a filename on the command line * char to display when not printable: nochar = char(127) nochar = IDENT(&OS,'Linux') char(128) p = dupl(nochar,32) substr(&ALPHABET,32,95) dupl(nochar,129) * look for file name on command line: &PARM char(0) ':' (span(' ' char(0)) | '') break(char(0)) . file test differ(file) :S(got) * otherwise go into interactive mode: OUTPUT = 'Type name of file to be dumped' input('con',3,1024,'IN','-std -vl') file = con :(test) badfile endfile(1) detach('in') endfile(3) detach('con') file = :(test) got OUTPUT = 'File: "' file '"' * how many hex chars per line: c = 16 * pattern for formatting: hp = len(c / 2) . w len(c / 2) . x len(c / 2) . y len(c / 2) . z * set errlimit in case we try to open a bad file name: &ERRLIMIT = 1 input('in',1,4096,file,'-b') :F(badfile) * offset within the file: offset = 0 * read 4096 bytes of the file: lp inline = in :F(finish) * if we got an error, then file is not there: eq(&ERRLIMIT) :S(badfile) * handle c length pieces of the data in the file: lp2 inline pos(0) len(c) . data = :S(do) * handle last chunk: inline pos(0) (len(1) REM) . data = :F(lp) * format and print a line for the c bytes do h = rpad(hex(data),c + c) h hp = w ' ' x ' ' y ' ' z OUTPUT = lpad(offset,10) ' ' lpad(reverse(trim(reverse(hex(offset)),0,1)),10) + 'x ' h ' |' replace(data,&ALPHABET,p) '|' offset = offset + c :(lp2) finish eq(&ERRLIMIT) :S(badfile) end