##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: December, 2016 # Modified: 2016-12-18/22:19-0500 ##+ # # show-icode.icn, display the parts of a Unicon VM executable # link printf procedure main(argv) f := open(argv[1], "r") | stop("Cannot open " || image(argv[1])) # the shell control preamble as lines while (line := read(f)) ~== "\^L" do write(line) # binary icode as hex dump # reads(f, -1) won't work here as the file is already reading s := "" while s ||:= reads(f) hexdump(s) close(f) end # # display hex codes # procedure hexdump(s) local c, perline := 0, text := " ", scale := 0, counter := 0 if *s = 0 then fail scale := **s scale <:= 4 printf("%0" || scale || "d: ", counter) every c := !s do { if (perline +:= 1) > 16 then { write(text) text := " " perline := 1 printf("%0" || scale || "d: ", counter) } #writes(map(_doprnt("%02x ", [ord(c)]), &lcase, &ucase)) printf("%02x ", ord(c)) text ||:= if 31 < ord(c) < 127 then c else "." counter +:= 1 } if perline > 0 then { writes(repl(" ", (16 - perline) * 3)) write(text) } else write() end