Example HEXDUMP.PRT
; HEXDUMP
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; This program prints out in readable format (hexadecimal) the contents of specified file,
; according to the following template:
;
; 1234: 12 12 12 12 12 12 12 12   12 12 12 12 12 12 12 12  |  123456789012345678

#!proteus -z

IF LT(ARGC, 6)
  CONSOLELN "Syntax: proteus HEXDUMP.PRT <source_file> <destination>"
  ABORT 0
FI

H = FOPEN(ARGV(5), 4)
D = FOPEN(ARGV(6), 26)
L = FSIZE(H)

; Create a mapping to space for all non-printable characters
S = ""
FOR X = 0 TO 31
  S = S CHR(X)
NEXT
MP = MAPNEW(S, REPLICATE(" ", 32))

; Calculate the length of counter at the beginning of each line
M = STRLEN(PFORMAT("X", L))

B = 0
WHILE NOT(FEOF(H))
  SB = FREAD(H, 16)
  ; Print counter
  S = PFORMAT("0" M "X", B) ": "
  ; Print bytes in hexadecimal
  FOR X = 1 TO STRLEN(SB)
    S = S PFORMAT("02X", ASC(SUBSTR(SB, X, 1))) " "
    IF EQ(X, 8)
      S = S "  "
    FI
  NEXT
  ; Pad line
  X = STRLEN(SB)
  IF LT(X, 16)
    Y = MUL(3, SUB(16, X))
    IF LT(X, 9)
      Y = ADD(Y, 2)
    FI
    S = S REPLICATE(" ", Y)
  FI
  ; Print out line, mapping to spaces all non-printable characters
  S = S " |  " MAP(MP, SB)
  FWRITELN(D, S)
  ADD(@B, STRLEN(SB))
LOOP
FCLOSE(H)
FCLOSE(D)

ABORT 0
Samples index Next example Previous example Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell