home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / aimqb4 / sample / dump.bas next >
Encoding:
BASIC Source File  |  1988-04-03  |  4.3 KB  |  153 lines

  1. '*****************************************************************************
  2.  
  3. 'Copyright (c) 1987 Marcel Madonna
  4.  
  5. 'DUMP.BAS shows how to use the HEXSTR and CHARXLAT functions.  It takes
  6. 'the file specification entered on the command line and proceeds to dump the
  7. 'file to the screen.
  8.  
  9. '
  10. ' ********************* N O T E *************************
  11. '
  12. 'This program cannot be used from the DOS prompt without Microsoft
  13. 'QuickBasic V4.0 and a registered copy of QBWARE.
  14. '
  15. 'To compile it, at the DOS prompt type:
  16.  
  17. '               bc DUMP;
  18. '               link /ex /noe DUMP,,,brun40 qbware;
  19. '               del DUMP.obj
  20. '               del DUMP.map
  21.  
  22. 'To run it fromthe QuickBasic development environment, type:
  23. '
  24. '               qb DUMP /l qbware
  25. '               [Shift] + F5
  26.  
  27. '               qb disphex /l qbfunc.exe;
  28. '               link disphex;
  29. '               del disphex.obj
  30.  
  31. 'DUMP is not very sophisticated and it does not use the any other QBWARE
  32. 'routines so it's easy to modify if you don't have QBWARE/1.
  33.  
  34. 'To run it simply type:
  35. '
  36. '       DUMP AUTOEXEC.BAT
  37.  
  38. 'at the DOS prompt and you will get a dump of youe AUTOEXEC.BAT file - of
  39. 'course it must be in the current directory.
  40.  
  41. '*****************************************************************************
  42.  
  43.     CLS
  44.     LOCATE 1, 1
  45.     Target.File$ = COMMAND$
  46.     IF Target.File$ = "" THEN
  47.         INPUT "Enter a filename:", Target.File$
  48.     END IF
  49.  
  50. ' We need an ASCIIZ string to open the file
  51.  
  52.     Filenum% = 1                    'Just to show you a neat trick
  53.     Reclen% = 512                   'Read 512 bytes at a time
  54.  
  55.     OPEN Target.File$ FOR RANDOM ACCESS READ AS #Filenum% LEN = Reclen%
  56.  
  57.     FIELD #Filenum%, 512 AS Input.Buffer$
  58.  
  59. ' If the file has no length, assume that it was just created by the previous
  60. ' and it was really not on the disk and should be deleted
  61.  
  62.     File.Len# = LOF(Filenum%)        'Need to keep File length
  63.  
  64.     IF File.Len# = 0 THEN
  65.         CLOSE #Filenum%
  66.         KILL Target.File$
  67.         GOTO Invalid.Parameter
  68.     END IF
  69.  
  70. ' Set up the translation table so that all non-printable ASCII codes are
  71. ' changed to a '.'
  72.  
  73.     Xlat.Table$ = STRING$(256, ".")   'Initialize to all '.'
  74.     FOR X% = 33 TO 126                'Fix all displayable codes
  75.         MID$(Xlat.Table$, X% + 1, 1) = CHR$(X%)
  76.     NEXT
  77.  
  78.     COLOR 15, 1
  79.  
  80. ' Initialize some key fields
  81.  
  82.     Rec.Counter% = 1
  83.     GET #Filenum%, Rec.Counter%        'Get the first record
  84.     Text.Out$ = SPACE$(1024)           'Initailize output area
  85.  
  86. ' Retrieve all records until EOF is reached
  87.  
  88.     WHILE NOT EOF(Filenum%) AND X$ <> CHR$(27)
  89.         File.Len# = File.Len# - Reclen% 'Keep track of remaining bytes
  90.         Text.In$ = Input.Buffer$        'Cannot call with Field variables
  91.         CALL HexStr(Text.In$, Text.Out$) 'convert this record
  92.         CALL CharXlat(Text.In$, Xlat.Table$)  'get rid of non-ASCII
  93.         GOSUB Display.Page
  94.         Rec.Counter% = Rec.Counter% + 1
  95.         GET #Filenum%, Rec.Counter%        'Get the next record
  96.     WEND
  97.  
  98. ' If we reached EOF then we need to print the last record that was retrieved
  99.  
  100.     IF X$ <> CHR$(27) AND File.Len# <> 0 THEN
  101.         Text.In$ = Input.Buffer$        'Cannot call with Field variables
  102.         CALL HexStr(Text.In$, Text.Out$) 'convert this record
  103.         CALL CharXlat(Text.In$, Xlat.Table$)  'get rid of non-ASCII
  104.         MID$(Text.In$, File.Len# + 1, Reclen% - File.Len#) = SPACE$(Reclen% - File.Len#)
  105.         MID$(Text.Out$, (File.Len# * 2) + 1, (Reclen% - File.Len#) * 2) = SPACE$((Reclen% - File.Len#) * 2)
  106.         GOSUB Display.Page
  107.     END IF
  108.     CLOSE #Filenum%
  109.  
  110.     END
  111.  
  112.  
  113. ' Displays a page of text onto the screen
  114.  
  115.  
  116.  
  117. Display.Page:
  118.  
  119.     CLS                     'Clear screen
  120.     LOCATE 1, 1
  121.     PRINT Target.File$; TAB(50); "Relative Sector "; Rec.Counter%
  122.  
  123.     Hex.Text% = 1
  124.     Chr.Text% = 1
  125.     Buffer.Count% = 1
  126.  
  127.     FOR Line.Count% = 1 TO 22                   'Max characters on a page
  128.         Output.Line$ = SPACE$(80)         'Clear output line
  129.  
  130.         FOR Line.Control% = 0 TO 5        'Groups on a line
  131.             MID$(Output.Line$, (Line.Control% * 8) + Line.Control% + 1, 8) = MID$(Text.Out$, Hex.Text%, 8)
  132.             Hex.Text% = Hex.Text% + 8
  133.         NEXT Line.Control%
  134.  
  135.  
  136.         MID$(Output.Line$, 55, 24) = MID$(Text.In$, Chr.Text%, 24)
  137.         Chr.Text% = Chr.Text% + 24
  138.         PRINT Output.Line$
  139.     NEXT Line.Count%
  140.  
  141.     LOCATE 24, 20: PRINT "Press any key to continue - [Esc] to end";
  142.     X$ = ""
  143.     WHILE X$ = ""
  144.         X$ = INKEY$
  145.     WEND
  146.  
  147.     RETURN
  148.  
  149. Invalid.Parameter:
  150.     PRINT Target.File$ + " not found"
  151.     END
  152.  
  153.