home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / clarion / library / viewfi / viewfil2.cla < prev    next >
Encoding:
Text File  |  1991-07-19  |  10.6 KB  |  322 lines

  1.  
  2. !═════════════════════════════════════════════════════════════════════════
  3. !
  4. !  'VIEWFIL2.CLA' - Enhanced Generic File Viewer
  5. !
  6. !  Revision Number: '1'
  7. !  Revision Date  : '023-Jul-91'
  8. !
  9. !  Copyright : Bobcat Systems (c) 1991
  10. !  Author    : Robert J. Pupazzoni
  11. !           CIS:[70441,204]
  12. !
  13. !  Compiler  : Clarion Professional Developer v.2.1, Batch 2105
  14. !
  15. !
  16. !  ACKNOWLDGEMENTS
  17. !
  18. !    This code is originally based on Steve Greiners' VIEWFILE utility.
  19. !
  20. !
  21. !  DESCRIPTION
  22. !
  23. !    This module lets you view any DOS text file.  It includes the following
  24. !    features:
  25. !
  26. !       Reading in the background - you can begin viewing the file without
  27. !     waiting for all the lines to be read in.  This can be a real time
  28. !     saver when viewing large files.
  29. !
  30. !       Horizontal panning for file lines longer than 80 characters
  31. !
  32. !       Minimal RAM usage - Typically requires only 4K per 1000 lines of
  33. !     text.
  34. !
  35. !       NOT a LEM - Written entirely in Clarion, so it can be put in an
  36. !     overlay.
  37. !
  38. !═════════════════════════════════════════════════════════════════════════
  39.  
  40.          MEMBER()
  41.  
  42. !══════════════════════════════════════════════════════════════════════════
  43. !              Generic DOS File Viewer
  44. !══════════════════════════════════════════════════════════════════════════
  45. ViewFile     PROCEDURE( xFileName )
  46.  
  47.          ! Parameters:
  48. xFileName    EXTERNAL                 ! DOS File to view
  49.  
  50.          ! Screens:
  51. ViewScreen   SCREEN      WINDOW(25,80),AT(1,1),PRE(SCR),HUE(15,1)
  52.            ROW(25,1)  PAINT(1,80),HUE(0,3)
  53.          COL(2)      STRING('File:')
  54.          COL(22)  STRING('Line:')
  55.          COL(40)  STRING('Col: +')
  56.          COL(79)  STRING('K')
  57.               REPEAT(23),INDEX(ibViewNdx)
  58. ssViewLine     ROW(1,1)        STRING(80)
  59.               .
  60. ssFileName     ROW(25,8)  STRING(12),HUE(0,3)
  61. ssLineNo     COL(28)  STRING(10),HUE(0,3)
  62. ssColNo         COL(46)  STRING(3),HUE(0,3)
  63. ssStatus     COL(58)  STRING(10),HUE(0,3)
  64. ssMemAvail     COL(71)  STRING(@N7),HUE(0,3)
  65.          .
  66.  
  67. ErrorScreen  SCREEN      WINDOW(9,37),AT(9,23),HUE(14,4)
  68.            ROW(1,1)      STRING('╔═{35}╗'),HUE(15,4)
  69.            ROW(2,1)      REPEAT(7);STRING('║<0{35}>║'),HUE(15,4) .
  70.            ROW(9,1)      STRING('╚═{35}╝'),HUE(15,4)
  71.            ROW(3,12)  STRING('File Not Found!')
  72.            ROW(7,7)      STRING('Press any key to RETURN...')
  73.          .
  74.  
  75.          ! Equates:
  76. eScrnRows    EQUATE(23)                 ! Rows to display
  77. eColOffset   EQUATE(0)                 ! Display Column Offset
  78. eEofMsg         EQUATE(' End Of File ')         ! End of file message line
  79.  
  80.          ! Locals:
  81. oDosFile     DOS,NAME(xFileName),PRE(FIL),ASCII     ! DOS file structure
  82.            RECORD                 !
  83. sFileLine     STRING(255)             !
  84.          . .                 !
  85.  
  86. tFileIndex   TABLE,PRE(TAB)             ! Table of record pointer
  87. ilPtr           LONG,DIM(256)             ! arrays
  88.          .                     !
  89.  
  90. gTempIndex   GROUP,PRE(TMP)             ! Pointer array currently
  91. ilPtr           LONG,DIM(256)             ! being built
  92.          .                     !
  93.  
  94. isColumn     SHORT                 ! Display column
  95. ilTopLine    LONG                 ! Index of top record
  96. ibViewNdx    BYTE                 ! Screen repeat index
  97.  
  98. isBuildSlot  SHORT                 ! Next available array slot
  99. ilTotLines   LONG                 ! Total lines read
  100. bbQuit         BYTE                 ! Quit flag
  101.  
  102. ilDispNdx    LONG                 ! Temporary variables
  103. ilDispEntry  LONG                 !
  104. isDispSlot   SHORT                 !
  105.  
  106.   CODE
  107.   OPEN(oDosFile)                 ! Try to open file
  108.   IF ERRORCODE()                 ! If failed
  109.     OPEN(ErrorScreen)                 !   Display error screen
  110.     ASK                         !   Wait for a keypress
  111.     RETURN                     !   Return to caller
  112.   .                         ! Endif
  113.  
  114.   bbQuit     = 0                 ! Clear done flag
  115.   ilTopLine  = 1                 ! Set to top record
  116.   isColumn   = 1                 ! Set to first collumn
  117.   ilTotLines = 0                 ! No lines read yet
  118.  
  119.   CLEAR(gTempIndex)                 ! Clear pointer array
  120.   isBuildSlot = 0                 ! Start at first open slot
  121.  
  122.   OPEN(ViewScreen)                 ! Open view screen
  123.   SET(oDosFile)                     ! Start at first record
  124.  
  125.   ! -- Display first page --
  126.  
  127.   LOOP ibViewNdx = 1 TO eScrnRows         ! Loop
  128.     IF EOF(oDosFile) THEN BREAK.         !   Break if end-of-file
  129.     NEXT(oDosFile)                 !   Read record
  130.     SCR:ssViewLine = SUB(FIL:sFileLine,eColOffset+isColumn,80) ! Display
  131.     ilTotLines    += 1                 !   Increment line counter
  132.     isBuildSlot += 1                 !   Increment slot number
  133.     TMP:ilPtr[isBuildSlot] = POINTER(oDosFile)     !   Store record pointer
  134.   .                         ! End loop
  135.   DO ShowStatus                     ! Display status line
  136.  
  137.  
  138.   ! -- Allow simultaneous reading and viewing --
  139.  
  140.   LOOP                         ! Loop
  141.     IF KEYBOARD()                 !   If a keystroke is waiting
  142.       ASK                     !     Get it
  143.       DO Command                 !     Execute command
  144.       IF bbQuit THEN BREAK.             !     Break if Esc pressed
  145.       DO ShowStatus                 !     Display status line
  146.     .                         !   Endif
  147.     IF ilTotLines % 20 = 0 OR EOF(oDosFile)     !   If 20 lines or EOF
  148.       DO ShowStatus                 !     Display status line
  149.     .                         !   Endif
  150.     IF NOT EOF(oDosFile)             !   If not end-of file
  151.       NEXT(oDosFile)                 !     Read next record
  152.       ilTotLines  += 1                 !     Increment line counter
  153.       isBuildSlot += 1                 !     Increment slot number
  154.       TMP:ilPtr[isBuildSlot] = POINTER(oDosFile) !     Store record number
  155.       IF isBuildSlot = 256             !     If array is full
  156.     tFileIndex = gTempIndex             !     Store to memory table
  157.     ADD(tFileIndex)                 !
  158.     CLEAR(gTempIndex)             !     Clear array
  159.     isBuildSlot = 0                 !     Reset slot number
  160.   . . .                         ! End loop
  161.  
  162.   CLOSE(oDosFile)                 ! Close file
  163.   FREE(tFileIndex)                 ! Free memory table
  164.   RETURN                     ! Return to caller
  165.  
  166. !──────────────────────────────────────────────────────────────────────────
  167. Command         ROUTINE      ! Process keystroke commands
  168. !──────────────────────────────────────────────────────────────────────────
  169.   CASE KEYCODE()
  170.     OF Esc_Key;      bbQuit = 1
  171.     OF Down_Key;  DO LineDown
  172.     OF Up_Key;      DO LineUp
  173.     OF PgDn_Key;  DO PageDown
  174.     OF PgUp_Key;  DO PageUp
  175.     OF Ctrl_PgUp; DO FirstPage
  176.     OF Ctrl_PgDn; DO LastPage
  177.     OF Home_Key;  DO FirstCol
  178.     OF Left_Key;  DO ScrollLeft
  179.     OF Right_Key; DO ScrollRight
  180.   .
  181.  
  182. !──────────────────────────────────────────────────────────────────────────
  183. LineDown     ROUTINE      ! Scroll down one line
  184. !──────────────────────────────────────────────────────────────────────────
  185.   IF ilTopLine < ilTotLines
  186.     ilTopLine += 1
  187.     SCROLL(1,1,eScrnRows,80,1)
  188.     ibViewNdx = eScrnRows
  189.     DO ShowLine
  190.   ELSE
  191.     BEEP
  192.   .
  193.  
  194. !──────────────────────────────────────────────────────────────────────────
  195. LineUp         ROUTINE      ! Scroll up one line
  196. !──────────────────────────────────────────────────────────────────────────
  197.   IF ilTopLine > 1
  198.     ilTopLine -= 1
  199.     SCROLL(1,1,eScrnRows,80,-1)
  200.     ibViewNdx = 1
  201.     DO ShowLine
  202.   ELSE
  203.     BEEP
  204.   .
  205.  
  206. !──────────────────────────────────────────────────────────────────────────
  207. PageUp         ROUTINE      ! Scroll up one page
  208. !──────────────────────────────────────────────────────────────────────────
  209.   ilTopLine -= eScrnRows
  210.   IF ilTopLine < 1
  211.     ilTopLine = 1
  212.   .
  213.   DO ShowPage
  214.  
  215. !──────────────────────────────────────────────────────────────────────────
  216. PageDown     ROUTINE      ! Scroll down one page
  217. !──────────────────────────────────────────────────────────────────────────
  218.   ilTopLine += eScrnRows
  219.   IF ilTopLine > ilTotLines
  220.     ilTopLine = ilTotLines
  221.   .
  222.   DO ShowPage
  223.  
  224. !──────────────────────────────────────────────────────────────────────────
  225. FirstPage    ROUTINE      ! Show first page
  226. !──────────────────────────────────────────────────────────────────────────
  227.   ilTopLine = 1
  228.   DO ShowPage
  229.  
  230. !──────────────────────────────────────────────────────────────────────────
  231. LastPage     ROUTINE      ! Show last page
  232. !──────────────────────────────────────────────────────────────────────────
  233.   ilTopLine = ilTotLines - eScrnRows
  234.   IF ilTopLine < 1
  235.     ilTopLine = 1
  236.   .
  237.   DO ShowPage
  238.  
  239. !──────────────────────────────────────────────────────────────────────────
  240. FirstCol     ROUTINE      ! Reset to first display column
  241. !──────────────────────────────────────────────────────────────────────────
  242.   isColumn = 1
  243.   DO ShowPage
  244.  
  245. !──────────────────────────────────────────────────────────────────────────
  246. ScrollRight  ROUTINE      ! Scroll display right
  247. !──────────────────────────────────────────────────────────────────────────
  248.   isColumn += 10
  249.   IF isColumn > 240
  250.     isColumn = 240
  251.   .
  252.   DO ShowPage
  253.  
  254. !──────────────────────────────────────────────────────────────────────────
  255. ScrollLeft   ROUTINE      ! Scroll display left
  256. !──────────────────────────────────────────────────────────────────────────
  257.   isColumn -= 10
  258.   IF isColumn < 1
  259.     isColumn = 1
  260.   .
  261.   DO ShowPage
  262.  
  263. !──────────────────────────────────────────────────────────────────────────
  264. ShowPage     ROUTINE      ! Save file state and display page
  265. !──────────────────────────────────────────────────────────────────────────
  266.   ilSavPtr# = POINTER(oDosFile)
  267.   LOOP ibViewNdx = 1 TO eScrnRows
  268.     DO DispLine
  269.   .
  270.   GET(oDosFile,ilSavPtr#)
  271.  
  272. !──────────────────────────────────────────────────────────────────────────
  273. ShowLine     ROUTINE      ! Save file state and display line
  274. !──────────────────────────────────────────────────────────────────────────
  275.   ilSavPtr# = POINTER(oDosFile)
  276.   DO DispLine
  277.   GET(oDosFile,ilSavPtr#)
  278.  
  279. !──────────────────────────────────────────────────────────────────────────
  280. DispLine     ROUTINE      ! Display a line to the screen
  281. !──────────────────────────────────────────────────────────────────────────
  282.   ilDispNdx = ilTopLine+(ibViewNdx-1)         ! Calculate display index
  283.   IF ilDispNdx = ilTotLines + 1             !   If last line read
  284.     SCR:ssViewLine = ALL('─',40-LEN(eEofMsg)/2) & | !Display eof message
  285.              eEofMsg            & |
  286.              ALL('─',40-LEN(eEofMsg)/2)     !
  287.     EXIT                     !  Return
  288.   .                         ! Endif
  289.  
  290.   IF ilDispNdx > ilTotLines + 1             ! If line not read yet
  291.     SCR:ssViewLine = ''                 !   Display blank line
  292.     EXIT                     !   Return
  293.   .                         ! Endif
  294.  
  295.   ilDispEntry = 1 + BSHIFT(ilDispNdx,-8)     ! Calculate table entry no.
  296.   GET(tFileIndex,ilDispEntry)             ! Get pointer array
  297.   IF ERRORCODE()                 ! If not found
  298.     tFileIndex = gTempIndex             !   Use one being built
  299.   .                         ! Endif
  300.  
  301.   isDispSlot = 1 + BAND(ilDispNdx,255)         ! Calculate array element
  302.   GET(oDosFile,TAB:ilPtr[isDispSlot])         ! Get line from file
  303.   IF ERRORCODE()                 ! If not found
  304.     SCR:ssViewLine = ''                 !   Display blank line
  305.   ELSE                         ! Else display file line
  306.     SCR:ssViewLine = SUB(FIL:sFileLine,eColOffset+isColumn,80)
  307.   .                         ! Endif
  308.  
  309. !──────────────────────────────────────────────────────────────────────────
  310. ShowStatus   ROUTINE      ! Display status line
  311. !──────────────────────────────────────────────────────────────────────────
  312.   ssFileName = UPPER(xFileName)
  313.   ssLineNo   = ilTopLine & '/' & ilTotLines
  314.   ssColNo    = isColumn
  315.   IF EOF(oDosFile)
  316.     ssStatus = '*Finished*'
  317.   ELSE
  318.     ssStatus = '*Reading*'
  319.   .
  320.   ssMemAvail = MEMORY()
  321.  
  322.