home *** CD-ROM | disk | FTP | other *** search
-
- !═════════════════════════════════════════════════════════════════════════
- !
- ! 'VIEWFIL2.CLA' - Enhanced Generic File Viewer
- !
- ! Revision Number: '1'
- ! Revision Date : '023-Jul-91'
- !
- ! Copyright : Bobcat Systems (c) 1991
- ! Author : Robert J. Pupazzoni
- ! CIS:[70441,204]
- !
- ! Compiler : Clarion Professional Developer v.2.1, Batch 2105
- !
- !
- ! ACKNOWLDGEMENTS
- !
- ! This code is originally based on Steve Greiners' VIEWFILE utility.
- !
- !
- ! DESCRIPTION
- !
- ! This module lets you view any DOS text file. It includes the following
- ! features:
- !
- ! Reading in the background - you can begin viewing the file without
- ! waiting for all the lines to be read in. This can be a real time
- ! saver when viewing large files.
- !
- ! Horizontal panning for file lines longer than 80 characters
- !
- ! Minimal RAM usage - Typically requires only 4K per 1000 lines of
- ! text.
- !
- ! NOT a LEM - Written entirely in Clarion, so it can be put in an
- ! overlay.
- !
- !═════════════════════════════════════════════════════════════════════════
-
- MEMBER()
-
- !══════════════════════════════════════════════════════════════════════════
- ! Generic DOS File Viewer
- !══════════════════════════════════════════════════════════════════════════
- ViewFile PROCEDURE( xFileName )
-
- ! Parameters:
- xFileName EXTERNAL ! DOS File to view
-
- ! Screens:
- ViewScreen SCREEN WINDOW(25,80),AT(1,1),PRE(SCR),HUE(15,1)
- ROW(25,1) PAINT(1,80),HUE(0,3)
- COL(2) STRING('File:')
- COL(22) STRING('Line:')
- COL(40) STRING('Col: +')
- COL(79) STRING('K')
- REPEAT(23),INDEX(ibViewNdx)
- ssViewLine ROW(1,1) STRING(80)
- .
- ssFileName ROW(25,8) STRING(12),HUE(0,3)
- ssLineNo COL(28) STRING(10),HUE(0,3)
- ssColNo COL(46) STRING(3),HUE(0,3)
- ssStatus COL(58) STRING(10),HUE(0,3)
- ssMemAvail COL(71) STRING(@N7),HUE(0,3)
- .
-
- ErrorScreen SCREEN WINDOW(9,37),AT(9,23),HUE(14,4)
- ROW(1,1) STRING('╔═{35}╗'),HUE(15,4)
- ROW(2,1) REPEAT(7);STRING('║<0{35}>║'),HUE(15,4) .
- ROW(9,1) STRING('╚═{35}╝'),HUE(15,4)
- ROW(3,12) STRING('File Not Found!')
- ROW(7,7) STRING('Press any key to RETURN...')
- .
-
- ! Equates:
- eScrnRows EQUATE(23) ! Rows to display
- eColOffset EQUATE(0) ! Display Column Offset
- eEofMsg EQUATE(' End Of File ') ! End of file message line
-
- ! Locals:
- oDosFile DOS,NAME(xFileName),PRE(FIL),ASCII ! DOS file structure
- RECORD !
- sFileLine STRING(255) !
- . . !
-
- tFileIndex TABLE,PRE(TAB) ! Table of record pointer
- ilPtr LONG,DIM(256) ! arrays
- . !
-
- gTempIndex GROUP,PRE(TMP) ! Pointer array currently
- ilPtr LONG,DIM(256) ! being built
- . !
-
- isColumn SHORT ! Display column
- ilTopLine LONG ! Index of top record
- ibViewNdx BYTE ! Screen repeat index
-
- isBuildSlot SHORT ! Next available array slot
- ilTotLines LONG ! Total lines read
- bbQuit BYTE ! Quit flag
-
- ilDispNdx LONG ! Temporary variables
- ilDispEntry LONG !
- isDispSlot SHORT !
-
- CODE
- OPEN(oDosFile) ! Try to open file
- IF ERRORCODE() ! If failed
- OPEN(ErrorScreen) ! Display error screen
- ASK ! Wait for a keypress
- RETURN ! Return to caller
- . ! Endif
-
- bbQuit = 0 ! Clear done flag
- ilTopLine = 1 ! Set to top record
- isColumn = 1 ! Set to first collumn
- ilTotLines = 0 ! No lines read yet
-
- CLEAR(gTempIndex) ! Clear pointer array
- isBuildSlot = 0 ! Start at first open slot
-
- OPEN(ViewScreen) ! Open view screen
- SET(oDosFile) ! Start at first record
-
- ! -- Display first page --
-
- LOOP ibViewNdx = 1 TO eScrnRows ! Loop
- IF EOF(oDosFile) THEN BREAK. ! Break if end-of-file
- NEXT(oDosFile) ! Read record
- SCR:ssViewLine = SUB(FIL:sFileLine,eColOffset+isColumn,80) ! Display
- ilTotLines += 1 ! Increment line counter
- isBuildSlot += 1 ! Increment slot number
- TMP:ilPtr[isBuildSlot] = POINTER(oDosFile) ! Store record pointer
- . ! End loop
- DO ShowStatus ! Display status line
-
-
- ! -- Allow simultaneous reading and viewing --
-
- LOOP ! Loop
- IF KEYBOARD() ! If a keystroke is waiting
- ASK ! Get it
- DO Command ! Execute command
- IF bbQuit THEN BREAK. ! Break if Esc pressed
- DO ShowStatus ! Display status line
- . ! Endif
- IF ilTotLines % 20 = 0 OR EOF(oDosFile) ! If 20 lines or EOF
- DO ShowStatus ! Display status line
- . ! Endif
- IF NOT EOF(oDosFile) ! If not end-of file
- NEXT(oDosFile) ! Read next record
- ilTotLines += 1 ! Increment line counter
- isBuildSlot += 1 ! Increment slot number
- TMP:ilPtr[isBuildSlot] = POINTER(oDosFile) ! Store record number
- IF isBuildSlot = 256 ! If array is full
- tFileIndex = gTempIndex ! Store to memory table
- ADD(tFileIndex) !
- CLEAR(gTempIndex) ! Clear array
- isBuildSlot = 0 ! Reset slot number
- . . . ! End loop
-
- CLOSE(oDosFile) ! Close file
- FREE(tFileIndex) ! Free memory table
- RETURN ! Return to caller
-
- !──────────────────────────────────────────────────────────────────────────
- Command ROUTINE ! Process keystroke commands
- !──────────────────────────────────────────────────────────────────────────
- CASE KEYCODE()
- OF Esc_Key; bbQuit = 1
- OF Down_Key; DO LineDown
- OF Up_Key; DO LineUp
- OF PgDn_Key; DO PageDown
- OF PgUp_Key; DO PageUp
- OF Ctrl_PgUp; DO FirstPage
- OF Ctrl_PgDn; DO LastPage
- OF Home_Key; DO FirstCol
- OF Left_Key; DO ScrollLeft
- OF Right_Key; DO ScrollRight
- .
-
- !──────────────────────────────────────────────────────────────────────────
- LineDown ROUTINE ! Scroll down one line
- !──────────────────────────────────────────────────────────────────────────
- IF ilTopLine < ilTotLines
- ilTopLine += 1
- SCROLL(1,1,eScrnRows,80,1)
- ibViewNdx = eScrnRows
- DO ShowLine
- ELSE
- BEEP
- .
-
- !──────────────────────────────────────────────────────────────────────────
- LineUp ROUTINE ! Scroll up one line
- !──────────────────────────────────────────────────────────────────────────
- IF ilTopLine > 1
- ilTopLine -= 1
- SCROLL(1,1,eScrnRows,80,-1)
- ibViewNdx = 1
- DO ShowLine
- ELSE
- BEEP
- .
-
- !──────────────────────────────────────────────────────────────────────────
- PageUp ROUTINE ! Scroll up one page
- !──────────────────────────────────────────────────────────────────────────
- ilTopLine -= eScrnRows
- IF ilTopLine < 1
- ilTopLine = 1
- .
- DO ShowPage
-
- !──────────────────────────────────────────────────────────────────────────
- PageDown ROUTINE ! Scroll down one page
- !──────────────────────────────────────────────────────────────────────────
- ilTopLine += eScrnRows
- IF ilTopLine > ilTotLines
- ilTopLine = ilTotLines
- .
- DO ShowPage
-
- !──────────────────────────────────────────────────────────────────────────
- FirstPage ROUTINE ! Show first page
- !──────────────────────────────────────────────────────────────────────────
- ilTopLine = 1
- DO ShowPage
-
- !──────────────────────────────────────────────────────────────────────────
- LastPage ROUTINE ! Show last page
- !──────────────────────────────────────────────────────────────────────────
- ilTopLine = ilTotLines - eScrnRows
- IF ilTopLine < 1
- ilTopLine = 1
- .
- DO ShowPage
-
- !──────────────────────────────────────────────────────────────────────────
- FirstCol ROUTINE ! Reset to first display column
- !──────────────────────────────────────────────────────────────────────────
- isColumn = 1
- DO ShowPage
-
- !──────────────────────────────────────────────────────────────────────────
- ScrollRight ROUTINE ! Scroll display right
- !──────────────────────────────────────────────────────────────────────────
- isColumn += 10
- IF isColumn > 240
- isColumn = 240
- .
- DO ShowPage
-
- !──────────────────────────────────────────────────────────────────────────
- ScrollLeft ROUTINE ! Scroll display left
- !──────────────────────────────────────────────────────────────────────────
- isColumn -= 10
- IF isColumn < 1
- isColumn = 1
- .
- DO ShowPage
-
- !──────────────────────────────────────────────────────────────────────────
- ShowPage ROUTINE ! Save file state and display page
- !──────────────────────────────────────────────────────────────────────────
- ilSavPtr# = POINTER(oDosFile)
- LOOP ibViewNdx = 1 TO eScrnRows
- DO DispLine
- .
- GET(oDosFile,ilSavPtr#)
-
- !──────────────────────────────────────────────────────────────────────────
- ShowLine ROUTINE ! Save file state and display line
- !──────────────────────────────────────────────────────────────────────────
- ilSavPtr# = POINTER(oDosFile)
- DO DispLine
- GET(oDosFile,ilSavPtr#)
-
- !──────────────────────────────────────────────────────────────────────────
- DispLine ROUTINE ! Display a line to the screen
- !──────────────────────────────────────────────────────────────────────────
- ilDispNdx = ilTopLine+(ibViewNdx-1) ! Calculate display index
- IF ilDispNdx = ilTotLines + 1 ! If last line read
- SCR:ssViewLine = ALL('─',40-LEN(eEofMsg)/2) & | !Display eof message
- eEofMsg & |
- ALL('─',40-LEN(eEofMsg)/2) !
- EXIT ! Return
- . ! Endif
-
- IF ilDispNdx > ilTotLines + 1 ! If line not read yet
- SCR:ssViewLine = '' ! Display blank line
- EXIT ! Return
- . ! Endif
-
- ilDispEntry = 1 + BSHIFT(ilDispNdx,-8) ! Calculate table entry no.
- GET(tFileIndex,ilDispEntry) ! Get pointer array
- IF ERRORCODE() ! If not found
- tFileIndex = gTempIndex ! Use one being built
- . ! Endif
-
- isDispSlot = 1 + BAND(ilDispNdx,255) ! Calculate array element
- GET(oDosFile,TAB:ilPtr[isDispSlot]) ! Get line from file
- IF ERRORCODE() ! If not found
- SCR:ssViewLine = '' ! Display blank line
- ELSE ! Else display file line
- SCR:ssViewLine = SUB(FIL:sFileLine,eColOffset+isColumn,80)
- . ! Endif
-
- !──────────────────────────────────────────────────────────────────────────
- ShowStatus ROUTINE ! Display status line
- !──────────────────────────────────────────────────────────────────────────
- ssFileName = UPPER(xFileName)
- ssLineNo = ilTopLine & '/' & ilTotLines
- ssColNo = isColumn
- IF EOF(oDosFile)
- ssStatus = '*Finished*'
- ELSE
- ssStatus = '*Reading*'
- .
- ssMemAvail = MEMORY()
-
-