home *** CD-ROM | disk | FTP | other *** search
- *********************
-
- FUNCTION Viewing
-
- PARAMETERS _vfile, _vrow, _vcol, _vdown, _vover, _vwidth, _spock
-
- IF EMPTY(PCOUNT())
- RETURN(.F.)
- ELSEIF !FILE(_vfile)
- RETURN(.F.)
- ENDIF
-
- _sayings = .T.
-
- IF PCOUNT() = 1
- _vrow = 1
- _vcol = 1
- _vdown = 20
- _vover = 70
- _vwidth = 250
- _spock = 1
- _sayings = .F.
- ELSEIF PCOUNT() = 2 && It's assumed to have come from the DEBUGGER
- _vcol = 1
- _vdown = 20
- _vover = 70
- _vwidth = 250
- _spock = _vrow
- _vrow = 1
- IF _spock = 0
- _spock = 1
- ENDIF
- ELSEIF PCOUNT() = 3
- _vdown = 20
- _vover = 70
- _vwidth = 250
- _spock = 1
- ELSEIF PCOUNT() = 4
- _vover = 70
- _vwidth = 250
- _spock = 1
- ELSEIF PCOUNT() = 5
- _vwidth = 250
- _spock = 1
- ELSEIF PCOUNT() = 6
- _spock = 1
- ENDIF
-
- IF TYPE("_vfile") + TYPE("_vrow") + TYPE("_vcol") + ;
- TYPE("_vdown") + TYPE("_vover") + TYPE("_vwidth") + ;
- TYPE("_spock") != "CNNNNNN"
- RETURN(.F.)
- ENDIF
-
- IF _vdown + _vrow > 22 && This adjusts the proper
- _vrow = 1 && screen coordinates for
- IF _vdown + _vrow > 22 && the viewing audiences.
- _vdown = 20
- ENDIF
- ENDIF
- IF _vover + _vcol > 75
- _vcol = 1
- IF _vover + _vcol > 75
- _vover = 70
- ENDIF
- ENDIF
-
- _bugaboo = ""
-
- SET KEY 3 TO
- SET KEY 18 TO
- SET KEY 5 TO
- SET KEY 24 TO
- SET KEY 1 TO
- SET KEY 6 TO
- SET KEY 31 TO
- SET KEY 30 TO
- SET KEY 29 TO
- SET KEY 27 TO
- SET KEY 19 TO
- WINDOWPUSH(_vrow, _vcol, _vrow + _vdown, _vcol + _vover)
-
- _lhand = FOPEN(_vfile) && The file to open
- _posit = 1
- _bugaboo = "" && the string to read in
- _istop = .T. && toggle to the top of file
- _isend = .F. && toggle to the end of file
- _check = 0 && _check bytes actually read
- IF TYPE("_bpread") = "U"
- _bpread = IF( FILESIZE(_vfile) < 3000, FILESIZE(_vfile), 3000)
- ENDIF
-
- * I'm now forcing the number of bytes to read at 3000 bytes.
- * In earlier versions, I used a rough calculation using the
- * MEMORY(0) function; however, in this, I want to limit the
- * number of bytes read at one time.
-
- _okcount = 0
-
- IF _spock != 1 && go to a specific line number
- * first count the number of CHR(13)+CHR(10)
- * move to that line. And continue on as
- * normal, making sure to REWIND the line number
- * so that the rest of the trick could work.
- Gotoline()
- ENDIF
- _cont = .T.
- DO WHILE _cont
- _cont = .F.
- _mbytes = 0 && This is an important trick!!!
- _temp = SPACE(_bpread)
- _check = FREAD(_lhand, @_temp, _bpread)
- IF FEOF(_lhand)
- _istop = .F.
- _isend = .T.
- ELSEIF FBOF(_lhand)
- _istop = .T.
- _isend = .F.
- ELSE
- _istop = .F.
- _isend = .F.
- ENDIF
- * read in a portion of the string
- * keep a file pointer
- * use the low level file functions
- * if on last byte or first byte of
- * page, pan in next buffer, break out
- * of MEMOEDIT() and continue on
-
- SET CURSOR ON
- MEMOEDIT(_temp, WROW(1), WCOL(2), WROW(1) + _vdown-2, WCOL(_vover-2), .F.,"NEWKEYS",_vwidth)
- SET CURSOR (scrcursor)
-
- ENDDO
- FCLOSE(_lhand)
- WINDOWPOP()
- CALL __cclr
- RETURN(.T.)
-
- ******************
-
- FUNCTION Newkeys
-
- PARAMETERS _mode, _nrow, _ncol
-
- IF _sayings
- @ _vrow +_vdown + 1,_vcol+3 SAY "Row:" + TRANSFORM(_nrow, "@B99999999")
- @ ROW(),COL()+3 SAY "Col:" + TRANSFORM(_ncol, "@B99999999")
- ENDIF
-
- IF LASTKEY() = 27
- _cont = .F.
- KEYBOARD CHR(23)
- ENDIF
-
- IF LASTKEY() = 23
- RETURN(23)
- ENDIF
-
- IF LASTKEY() = 31 && Top of file
- FSEEK(_lhand, 0)
- KEYBOARD CHR(23)
- _cont = .T.
- RETURN(0)
-
- ELSEIF LASTKEY() = 30
- FSEEK(_lhand, (-1 * _bpread), 2) && Move back from the end of file
- DO WHILE !FBOF(_lhand)
- FSEEK(_lhand, -1, 1)
- IF FREADSTR(_lhand, 1) = CHR(10)
- FSEEK(_lhand, -2, 1)
- IF FREADSTR(_lhand, 1) = CHR(13)
- FSEEK(_lhand, 1, 1) && Move the _posit back off
- EXIT && of the carriage/return LF
- ENDIF
- ELSE
- FSEEK(_lhand, -1, 1)
- ENDIF
- ENDDO
- * KEYBOARD CHR(23)
- _cont = .T.
- RETURN(23)
-
- ELSEIF LASTKEY() = 3 .OR. LASTKEY() = 24 && Page Down
- * determine if last page
- IF _nrow = _mbytes && _posit hasn't moved
- * first see if it is the END of file. If So, display
- * the message and _cont.
- IF _isend
- ELSE
- DO WHILE !FBOF(_lhand)
- FSEEK(_lhand, -1, 1)
- IF FREADSTR(_lhand, 1) = CHR(10)
- FSEEK(_lhand, -2, 1)
- IF FREADSTR(_lhand, 1) = CHR(13)
- FSEEK(_lhand, 1, 1) && Move the _posit back off
- EXIT && of the carriage/return LF
- ENDIF
- ELSE
- FSEEK(_lhand, -1, 1)
- ENDIF
- ENDDO
- KEYBOARD CHR(23)
- _cont = .T.
- RETURN(0)
-
- * read back the string and find the _posit
- * of the last carriage/return line feed and
- * _posit the marker
- ENDIF
- ELSE
- _mbytes = _nrow
- ENDIF
-
- ELSEIF LASTKEY() = 18 .OR. LASTKEY() = 5 && Page Up
- * determine if first page
- IF _nrow = _mbytes && _posit hasn't moved
- _posit = (FPOSIT(_lhand) - _bpread) && which block to read
- IF _posit < 0
- _posit = 1
- FSEEK(_lhand, 0)
- ELSE
- FSEEK(_lhand, _posit, 0)
- FSEEK(_lhand, (-1 * _bpread), 1)
- IF FPOSIT(_lhand) < 0 && Error trapping condition
- FSEEK(_lhand, 0) && for top of file situation
- ENDIF
- DO WHILE !FBOF(_lhand)
- FSEEK(_lhand, -1, 1)
- IF FREADSTR(_lhand, 1) = CHR(10)
- FSEEK(_lhand, -2, 1)
- IF FREADSTR(_lhand, 1) = CHR(13)
- FSEEK(_lhand, 1, 1) && Move the _posit back off
- EXIT && of the carriage/return LF
- ENDIF
- ELSE
- FSEEK(_lhand, -1, 1)
- ENDIF
- ENDDO
- ENDIF
- KEYBOARD CHR(23)
- _cont = .T.
- RETURN(0)
-
- ELSE
- _mbytes = _nrow
- ENDIF
-
- ELSEIF LASTKEY() = 290 && alt G goto line number
- Wpush(Wrow(3), Wcol(2), Wrow(3) + 2, Wcol(2) + 29)
- @ Wrow(1), Wcol(2) SAY "Enter Line Number:"
- _goto = ""
- DO WHILE INKEY(0) != 13
- IF LASTKEY() = 8 && backspace
- IF LEN(_goto) = 1
- _goto = ""
- ELSE
- _goto = SUBSTR(_goto, 1, LEN(_goto)-1)
- ENDIF
- @ Wrow(1), Wcol(21) SAY SPACE(7)
- ELSEIF LASTKEY() = 27 && escape key
- EXIT
- ELSEIF LASTKEY() >= 48 .AND. LASTKEY() <= 57
- IF LEN(_goto) <= 7
- _goto = _goto + CHR(LASTKEY())
- ENDIF
- ELSE
- LOOP
- ENDIF
- @ Wrow(1), Wcol(21) SAY _goto
- ENDDO
-
- IF LASTKEY() = 13
- FSEEK(_lhand, 0)
- _okcount = 0
- _spock = VAL(_goto)
- Gotoline()
- _cont = .T.
- KEYBOARD CHR(23)
- Wpop()
- RETURN(1)
- ENDIF
-
- Wpop()
-
- ELSEIF LASTKEY() = 289 && alt F file name
-
- Wpush(Wrow(3), Wcol(2), Wrow(3) + 2, Wcol(2) + 32)
- @ Wrow(1), Wcol(2) SAY "Enter File Name: "
- _goto = ""
- DO WHILE INKEY(0) != 13
- IF LASTKEY() = 8 && backspace
- IF LEN(_goto) = 1
- _goto = ""
- ELSE
- _goto = SUBSTR(_goto, 1, LEN(_goto)-1)
- ENDIF
- @ Wrow(1), Wcol(19) SAY SPACE(12)
- ELSEIF LASTKEY() = 27 && escape key
- EXIT
- ELSEIF LASTKEY() >= 45 .AND. LASTKEY() <= 127
- IF LEN(_goto) <= 12
- _goto = _goto + CHR(LASTKEY())
- ENDIF
- ELSE
- LOOP
- ENDIF
- @ Wrow(1), Wcol(19) SAY _goto
- ENDDO
- IF !FILE(TRIM(_goto))
- Clear_area()
- @ Wrow(1), Wcol(2) SAY "File Not Found. Any Key!"
- INKEY(0)
- ELSEIF FILE(TRIM(_goto)) .AND. LASTKEY() = 13
- FCLOSE(_lhand)
- _lhand = FOPEN(TRIM(_goto))
- _posit = 1
- _bugaboo = ""
- _istop = .T.
- _isend = .F.
- _check = 0
- _bpread = 3000
- _okcount = 0
- _spock = 1
- _cont = .T.
- KEYBOARD CHR(23)
- ENDIF
- Wpop()
-
- ENDIF
-
- RETURN(0)
-
- ********************
-
- PROCEDURE Gotoline
-
- IF _spock = 1
- FSEEK(_lhand, 0, 0)
- ELSE
- _okcount = 0
- DO WHILE .T.
- _mbytes = 0 && This is an important trick!!!
- _bugaboo = SPACE(_bpread)
- _check = FREAD(_lhand, @_bugaboo, _bpread)
- DO WHILE !EMPTY(_bugaboo) .AND. _okcount != _spock
- _where = AT(CHR(13)+CHR(10), _bugaboo)
- IF EMPTY(_where)
- _bugaboo = ""
- ELSE
- _okcount = _okcount + 1
- _bugaboo = SUBSTR(_bugaboo, _where+2)
- ENDIF
- _mbytes = _mbytes + _where
- ENDDO
-
- IF _okcount = _spock && we got it!
- * take the length of _tread now, subtract it
- * from 3000 to find out the position. Rewind
- * back the 3000 bytes read from the file and
- * move to the position. Now back off from the
- * until the next CHR(13)+CHR(10) combination is
- * found.
- IF _check < 3000
- FSEEK(_lhand, _mbytes, 0)
- _placeit = FSEEK(_lhand, 0, 1)
- ELSE
- _whereat = _check - LEN(_bugaboo)
- FSEEK(_lhand, (-1 * _check), 1)
- _placeit = FSEEK(_lhand, 0, 1)
- FSEEK(_lhand, _whereat, 1)
- * next, we must move OFF of the
- * CHR(13)/CHR(10) combinations
- * so that the following fseek
- * will act right...
- ENDIF
- _mbytes = 0
- FSEEK(_lhand, -2, 1)
- DO WHILE FSEEK(_lhand, 0, 1) != _placeit
- FSEEK(_lhand, -1, 1)
- IF FREADSTR(_lhand, 1) = CHR(10)
- FSEEK(_lhand, -2, 1)
- IF FREADSTR(_lhand, 1) = CHR(13)
- FSEEK(_lhand, 1, 1) && Move back off
- EXIT && of the CR/LF
- ENDIF
- ELSE
- FSEEK(_lhand, -1, 1)
- ENDIF
- ENDDO
- EXIT
-
- ELSEIF _check != 3000
-
- * no line number was found and the end of file
- * marker was reached, so just reposition to
- * the top of the file, and display a little
- * message at the bottom of the screen showing
- * this!
- FSEEK(_lhand, 0)
- EXIT
-
- ENDIF
- ENDDO
- ENDIF
-
- * End of File
-