home *** CD-ROM | disk | FTP | other *** search
/ Amiga Computing 57 / ac057a.adf / Demos / dump.bas < prev    next >
BASIC Source File  |  1988-12-19  |  1KB  |  60 lines

  1. rem Dumps out a file in hex and ASCII
  2. rem using Defeat Window option could be made into a CLI utility
  3.  
  4. deflng l,p,t    ' define long integers
  5. defint a,i        ' define integers
  6.  
  7. ' returns a two-digit hex string given an integer
  8. def fnbhex$(h%)
  9. local a$
  10. a$=hex$(h%): if len(a$)=1 then a$="0"+a$
  11. fnbhex$=a$
  12. end def
  13.  
  14. ' returns an 8-digit hex string given a long integer
  15. def fnlhex$(h&)
  16. local a$
  17. a$=hex$(h&): fnlhex$=string$(8-len(a$),"0"%)+a$
  18. end def
  19.  
  20.  
  21. ' the actual program
  22. f$=command$
  23. print "DUMP © HiSoft 1988 compiled with HiSoft BASIC"
  24.  
  25. repeat main
  26. if f$="" then input "Filename, ? for DIR, or [Return] to quit";f$
  27. if f$="" then
  28.     stop -1                'return without waiting
  29. elseif f$="?" then
  30.     files                'get a directory
  31. elseif not fexists(f$) then
  32.     print "Error: Cannot find file ";f$
  33. else
  34.     open "i",#2,f$,2000
  35.     l=lof(2)
  36.     p=0
  37.         repeat lineloop
  38.         t=16: if p+16>l then t=l-p
  39.         print fnlhex$(p);" ";
  40.         a$=input$(t,#2)
  41.         for i=1 to t
  42.             print fnbhex$(asc(mid$(a$,i,1)));" ";
  43.         next i
  44.         print tab(58);
  45.         for i=1 to t
  46.             if asc(mid$(a$,i,1))>31 then
  47.                 print mid$(a$,i,1);
  48.                 else
  49.                 print ".";
  50.             end if
  51.         next i
  52.         print
  53.         p=p+16: if p>l then exit lineloop
  54.         end repeat lineloop
  55.         close #2
  56. end if
  57. f$=""
  58. end repeat main
  59.  
  60.