The purpose of this program is to browse text files.
******************************************
** Program: LIST.Q **
** Purpose: Text File Browser. **
******************************************
option wstsize = 200 * Set max wst area size
option ifasize = 2000 * Set max ifa area size
equate MAX-ROWS to 24
equate MAX-ROWS-1 to 23
equate TAB to 1
equate BLINK-MSG-COLOR to 138
equate DEFAULT-COLOR to 7
equate wst-area to wst1-200
equate file-table-area to wst1-96 * 24 table entries max
equate fta-top-23 to wst1-92
equate fta-bot-23 to wst5-96
equate fta-entry to wst1-4
equate fta-rec-ptr to wst1-4-L
equate fta-max to wst100-101-I
equate fta-sub to wst102-103-I
equate FTA-ENTRY-LEN to 4
equate record-idx to wst104-105-I
equate record-ptr to wst106-109-L
equate record-ptr2 to wst110-113-L
equate last-record-ptr to wst114-117-L
equate screen-area to wst118-121
equate screen-row-max to wst118-119-I
equate screen-cur-row to wst120-121-I
equate keyboard-area to wst122-123
equate key-keypress to wst122
equate key-scancode to wst123
equate wst-counter to wst124-125-I
equate wst-max-rec-size to wst126-127-I
equate wst-prev-rec-cnt to wst128-129-I
equate wst-scancode-cnt to wst130-131
equate wst-prev-scancode to wst132
equate parm-area to parm1-100
equate file-name to parm1-70
perform 100 * Initialization
perform 200 * Process user commands
perform 1000 * Termination
end * End program
* Initialization
100 cursor off
fastvideo on * Set fast video mode on
open ifa file-name 1000 5000 * Open input file "A"
if ifa is not open
display 'Error opening file - ' noskip
display file-name
cursor on
end.
move MAX-ROWS to fta-max * Set fta-max to
multiply fta-max by FTA-ENTRY-LEN * last
subtract FTA-ENTRY-LEN from fta-max * entry
add 1 to fta-max * used
move 1 to fta-sub * Initialize fta subscript
110 move -1 to fta-rec-ptr (fta-sub) * Set record pointer to EOF
move -1 to last-record-ptr * Initialize last record pointer
add FTA-ENTRY-LEN to fta-sub * bump to next fta entry
if fta-sub < fta-max * until all entries
go to 110. * are set to -1
move MAX-ROWS to screen-row-max * Set max rows on screen
move 1 to record-idx * Initialize record index
move 0 to wst-max-rec-size * Initialize maximum rec len
color DEFAULT-COLOR * Set default colors
cls * Clear video screen
perform 300 * Fill video screen
199 exit
* Process function key commands
200 getkey key-keypress key-scancode * Wait for keyboard input
if key-scancode = x'48' * Up arrow key pressed?
perform 600
go to 200.
if key-scancode = x'49' * key pressed?
move MAX-ROWS-1 to wst-prev-rec-cnt * Set backward read record count
perform 800
go to 200.
if key-scancode = x'50' * Down arrow key pressed?
perform 500
go to 200.
if key-scancode = x'51' * key pressed?
perform 700
go to 200.
if key-scancode = x'4d' * Right shift key pressed?
add TAB to record-idx * Set record index right 1 byte
perform 400 * Redisplay video screen
go to 200. * Return to caller
if key-scancode = x'4b' * Left shift key pressed?
if record-idx > 1 * Left shift possible?
subtract TAB from record-idx * Set record index left 1 byte
perform 400 * Redisplay video screen
go to 200 * Return to caller
else
go to 200. * Return to caller
if key-scancode = x'47' * key pressed?
move 0 to record-ptr
fseek ifa record-ptr
perform 300
go to 200.
if key-scancode = x'4f' * key pressed?
move MAX-ROWS to wst-prev-rec-cnt * Set backward read record count
perform 900 * Find end of file
go to 200. * Return to caller
if key-keypress = x'1B' * key pressed?
cursor on
cursor 24 1
color 7
exit. * Yes, Return to caller
go to 200
299 exit
* Fill video screen
300 move 1 to fta-sub * Initialize file table area subscript
move 1 to screen-cur-row * Initialize current row
cursor 1 1 * Set cursor to row 1, col 1
310 ftell ifa fta-rec-ptr (fta-sub) * Save current record pointer
read ifa at eof 320 * Read record from ifa file
if ifa-recsize > wst-max-rec-size * Largest record len encountered?
move ifa-recsize to wst-max-rec-size * Yes, Store largest rec len
add 2 to wst-max-rec-size. * Account for LF & CR.
display ifa1-79 (record-idx) * Display record on screen
add 1 to screen-cur-row * Add 1 to current row
if screen-cur-row > screen-row-max * Screen filled up?
exit. * Yes, exit routine.
add FTA-ENTRY-LEN to fta-sub * Bump to next entry
go to 310 * Go display next record
320 move spaces to ifa1-79 (record-idx) * Blank out ifa area
330 display ifa1-79 (record-idx) * Display record on screen
move -1 to fta-rec-ptr (fta-sub)
add 1 to screen-cur-row * Add 1 to current row
if screen-cur-row > screen-row-max * Screen filled up?
exit. * Yes, exit routine.
add FTA-ENTRY-LEN to fta-sub * Bump to next entry
go to 330 * Go display blank line
399 exit
* Fill video screen
400 cursor 1 1 * Set cursor to row 1, column 1
move zeros to wst-scancode-cnt * Initialize keyscan counter
move key-scancode to wst-prev-scancode * Save Current scancode
move 1 to screen-cur-row * Initialize current row
move 1 to fta-sub * Set fta subscript to 1
fseek ifa fta-rec-ptr (1) * Set file record pointer
402 getkey key-keypress key-scancode Nowait * Get for keyboard input
if key-scancode = wst-prev-scancode * Shift key pressed?
add 1 to wst-scancode-cnt
if wst-scancode-cnt < 15
go to 402.
410 read ifa at eof 499 * Read record from ifa file
display ifa1-79 (record-idx)
add 1 to screen-cur-row * Add 1 to current row
if screen-cur-row <= screen-row-max * Screen filled up?
add FTA-ENTRY-LEN to fta-sub * Bump to next entry
go to 410. * Go display next record
exit * exit routine.
499 exit
* Display next record
500 if fta-rec-ptr (5) = -1 * Last record on file displayed?
exit. * Yes, Do nothing
if fta-rec-ptr (fta-max) = -1
move fta-bot-23 to fta-top-23 * Copy fta entries up 1
go to 510.
fseek ifa fta-rec-ptr (fta-max) * Save current record pointer
move fta-bot-23 to fta-top-23 * Copy fta entries up 1
read ifa at eof 510 * Read record from ifa file
ftell ifa fta-rec-ptr (fta-max) * Save current record pointer
read ifa at eof 510 * Read record from ifa file
display ifa1-79 (record-idx) * Display record on screen
exit
510 move screen-row-max to wst-counter
add 1 to wst-counter
cursor wst-counter 1
move spaces to ifa1-79 * Blank out ifa area
move -1 to fta-rec-ptr (fta-max) * Set fta sub to EOF
display ifa1-79 * Display record on screen
599 exit * Return to caller
* Display previous record
600 if fta-rec-ptr (1) = 0 * Pointer already at BOF?
exit. * Yes, exit
move zeros to wst-scancode-cnt * Initialize keyscan counte
move fta-rec-ptr (1) to record-ptr * get ptr for 1st record on screen
subtract wst-max-rec-size from record-ptr * Point to a previous record area
if record-ptr < 0 * Pointer before BOF?
move 0 to record-ptr * Yes, Set pointer to BOF
fseek ifa record-ptr * Get current record pointer
go to 640.
move record-ptr to record-ptr2
fseek ifa record-ptr2 * Point to file area
move zeros to wst-counter * Initialize wst counter
610 read ifa * Read record from ifa file
ftell ifa record-ptr2 * Save pointer to record
if record-ptr2 < fta-rec-ptr (1)
add 1 to wst-counter
go to 610.
fseek ifa record-ptr * Point to file area
620 if wst-counter >= 1 * Previous record?
read ifa * No, Go read next record
subtract 1 from wst-counter
go to 620.
630 getkey key-keypress key-scancode Nowait * Get for keyboard input
if key-scancode = x'48' * key pressed?
add 1 to wst-scancode-cnt
if wst-scancode-cnt < 15
go to 630.
640 perform 300
699 exit * Return to caller
* Page down 1 screen
700 move fta-max to fta-sub * Bump to last entry
710 if fta-rec-ptr (fta-sub) > -1
go to 720.
subtract FTA-ENTRY-LEN from fta-sub.
if fta-sub < 1
move 1 to fta-sub
exit.
go to 710.
720 move fta-rec-ptr (fta-sub) to fta-rec-ptr (1) * Reset record pointer
fseek ifa fta-rec-ptr (1)
getkey key-keypress key-scancode Nowait * Get for keyboard input
if key-scancode = x'51' * key pressed?
go to 700.
perform 300
799 exit
* Display previous records
800 if fta-rec-ptr (1) = 0 * Pointer already at BOF?
exit. * Yes, exit
move zeros to wst-scancode-cnt * Initialize keyscan counter
move fta-rec-ptr (1) to record-ptr * Get ptr for 1st record on screen
move wst-max-rec-size to record-ptr2 * Copy max rec len to wst counter
multiply record-ptr2 by wst-prev-rec-cnt * Multiply by number of recs
subtract record-ptr2 from record-ptr * Set record-ptr to new value
if record-ptr < 0 * Pointer before BOF?
move 0 to record-ptr. * Yes, Set pointer to BOF
fseek ifa record-ptr * Get current record pointer
move zeros to wst-counter * Initialize wst counter
810 read ifa * Read record from ifa file
ftell ifa record-ptr2 * Save pointer to record
if record-ptr2 < fta-rec-ptr (1)
add 1 to wst-counter
go to 810.
fseek ifa record-ptr * Point to prev record on file
820 if wst-counter >= wst-prev-rec-cnt * Previous record?
read ifa * No, Go read next record
subtract 1 from wst-counter
go to 820.
830 getkey key-keypress key-scancode Nowait * Get keyboard input
if key-scancode = x'49' * key pressed?
add 1 to wst-scancode-cnt
if wst-scancode-cnt < 15
go to 830.
perform 300
899 exit * Return to caller
* Find End of File
900 if last-record-ptr <> -1
move last-record-ptr to fta-rec-ptr (1) * Point to last record on file
perform 800
exit.
color BLINK-MSG-COLOR
cursor 25 34
display ' Reading... ' noskip
color DEFAULT-COLOR
move -1 to wst-counter
read ifa at eof 920 * Read record from ifa file
move ifa-recsize to wst-counter
go to 915
910 read ifa at eof 920 * Read record from ifa file
915 if ifa-recsize > wst-max-rec-size * Largest record len found?
move ifa-recsize to wst-max-rec-size * Yes, Save record len
add 2 to wst-max-rec-size. * Account for LF & CR.
go to 910
920 if wst-counter = -1
go to 930.
ftell ifa record-ptr
subtract wst-counter from record-ptr
subtract 1 from record-ptr
move record-ptr to fta-rec-ptr (1) * Point to last record on file
move record-ptr to last-record-ptr * Save last record on file
perform 800
930 cursor 25 34
display ' ' noskip
999 exit
* Termination
1000 close ifa
1999 exit