home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a075 / 1.img / TOOLKIT1.EXE / SST288.PRG < prev    next >
Encoding:
Text File  |  1989-09-02  |  11.6 KB  |  409 lines

  1. *********************
  2.  
  3. FUNCTION Viewing
  4.  
  5.    PARAMETERS _vfile, _vrow, _vcol, _vdown, _vover, _vwidth, _spock
  6.  
  7.    IF EMPTY(PCOUNT())
  8.       RETURN(.F.)
  9.    ELSEIF !FILE(_vfile)
  10.       RETURN(.F.)
  11.    ENDIF
  12.  
  13.    _sayings = .T.
  14.  
  15.    IF PCOUNT() = 1
  16.       _vrow = 1
  17.       _vcol = 1
  18.       _vdown = 20
  19.       _vover = 70
  20.       _vwidth = 250
  21.       _spock = 1
  22.       _sayings = .F.
  23.    ELSEIF PCOUNT() = 2  && It's assumed to have come from the DEBUGGER
  24.       _vcol = 1
  25.       _vdown = 20
  26.       _vover = 70
  27.       _vwidth = 250
  28.       _spock = _vrow
  29.       _vrow = 1
  30.       IF _spock = 0
  31.          _spock = 1
  32.       ENDIF
  33.    ELSEIF PCOUNT() = 3
  34.       _vdown = 20
  35.       _vover = 70
  36.       _vwidth = 250
  37.       _spock = 1
  38.    ELSEIF PCOUNT() = 4
  39.       _vover = 70
  40.       _vwidth = 250
  41.       _spock = 1
  42.    ELSEIF PCOUNT() = 5
  43.       _vwidth = 250
  44.       _spock = 1
  45.    ELSEIF PCOUNT() = 6
  46.       _spock = 1
  47.    ENDIF
  48.  
  49.    IF TYPE("_vfile") + TYPE("_vrow") + TYPE("_vcol") + ;
  50.       TYPE("_vdown") + TYPE("_vover") + TYPE("_vwidth") + ;
  51.       TYPE("_spock") != "CNNNNNN"
  52.       RETURN(.F.)
  53.    ENDIF
  54.  
  55.    IF _vdown + _vrow > 22               && This adjusts the proper
  56.       _vrow =  1                       && screen coordinates for
  57.       IF _vdown + _vrow > 22            && the viewing audiences.
  58.          _vdown = 20
  59.       ENDIF
  60.    ENDIF
  61.    IF _vover + _vcol > 75
  62.       _vcol = 1 
  63.       IF _vover + _vcol > 75
  64.          _vover = 70
  65.       ENDIF
  66.    ENDIF
  67.       
  68.    _bugaboo = ""
  69.  
  70.    SET KEY 3 TO
  71.    SET KEY 18 TO
  72.    SET KEY 5 TO
  73.    SET KEY 24 TO
  74.    SET KEY 1 TO
  75.    SET KEY 6 TO
  76.    SET KEY 31 TO
  77.    SET KEY 30 TO
  78.    SET KEY 29 TO
  79.    SET KEY 27 TO
  80.    SET KEY 19 TO
  81.    WINDOWPUSH(_vrow, _vcol, _vrow + _vdown, _vcol + _vover)
  82.  
  83.    _lhand   = FOPEN(_vfile)           && The file to open
  84.    _posit   = 1
  85.    _bugaboo = ""                         && the string to read in
  86.    _istop   = .T.                        && toggle to the top of file
  87.    _isend   = .F.                        && toggle to the end of file
  88.    _check   = 0                          && _check bytes actually read
  89.    IF TYPE("_bpread") = "U"
  90.       _bpread  = IF( FILESIZE(_vfile) < 3000, FILESIZE(_vfile), 3000)
  91.    ENDIF
  92.  
  93.    * I'm now forcing the number of bytes to read at 3000 bytes.
  94.    * In earlier versions, I used a rough calculation using the
  95.    * MEMORY(0) function; however, in this, I want to limit the
  96.    * number of bytes read at one time.
  97.  
  98.    _okcount = 0
  99.  
  100.    IF _spock != 1               && go to a specific line number
  101.       * first count the number of CHR(13)+CHR(10)
  102.       * move to that line.  And continue on as
  103.       * normal, making sure to REWIND the line number
  104.       * so that the rest of the trick could work.
  105.       Gotoline()
  106.    ENDIF
  107.    _cont = .T.
  108.    DO WHILE _cont
  109.       _cont = .F.
  110.       _mbytes = 0    && This is an important trick!!!
  111.       _temp = SPACE(_bpread)
  112.       _check = FREAD(_lhand, @_temp, _bpread)
  113.       IF FEOF(_lhand)
  114.          _istop = .F.
  115.          _isend = .T.
  116.       ELSEIF FBOF(_lhand)
  117.          _istop = .T.
  118.          _isend = .F.
  119.       ELSE
  120.          _istop = .F.
  121.          _isend = .F.
  122.       ENDIF
  123.       * read in a portion of the string
  124.       * keep a file pointer
  125.       * use the low level file functions
  126.       * if on last byte or first byte of
  127.       * page, pan in next buffer, break out
  128.       * of MEMOEDIT() and continue on
  129.  
  130.       SET CURSOR ON        
  131.       MEMOEDIT(_temp, WROW(1), WCOL(2), WROW(1) + _vdown-2, WCOL(_vover-2), .F.,"NEWKEYS",_vwidth)
  132.       SET CURSOR (scrcursor)
  133.  
  134.    ENDDO
  135.    FCLOSE(_lhand)
  136.    WINDOWPOP()
  137.    CALL __cclr
  138.    RETURN(.T.)
  139.  
  140. ******************
  141.  
  142. FUNCTION Newkeys
  143.  
  144.    PARAMETERS _mode, _nrow, _ncol
  145.  
  146.    IF _sayings
  147.       @ _vrow +_vdown + 1,_vcol+3 SAY "Row:" + TRANSFORM(_nrow, "@B99999999")
  148.       @ ROW(),COL()+3        SAY "Col:" + TRANSFORM(_ncol, "@B99999999")
  149.    ENDIF
  150.  
  151.    IF LASTKEY() = 27
  152.       _cont = .F.
  153.       KEYBOARD CHR(23)
  154.    ENDIF
  155.  
  156.    IF LASTKEY() = 23
  157.       RETURN(23)
  158.    ENDIF
  159.  
  160.    IF LASTKEY() = 31        && Top of file
  161.       FSEEK(_lhand, 0)
  162.       KEYBOARD CHR(23)
  163.       _cont = .T.
  164.       RETURN(0)
  165.  
  166.    ELSEIF LASTKEY() = 30
  167.       FSEEK(_lhand, (-1 * _bpread), 2)   && Move back from the end of file
  168.       DO WHILE !FBOF(_lhand)
  169.          FSEEK(_lhand, -1, 1)
  170.          IF FREADSTR(_lhand, 1) = CHR(10)
  171.             FSEEK(_lhand, -2, 1)
  172.             IF FREADSTR(_lhand, 1) = CHR(13)
  173.                FSEEK(_lhand, 1, 1)   && Move the _posit back off
  174.                EXIT                   && of the carriage/return LF
  175.             ENDIF
  176.          ELSE
  177.             FSEEK(_lhand, -1, 1)
  178.          ENDIF
  179.       ENDDO
  180. *      KEYBOARD CHR(23)
  181.       _cont = .T.
  182.       RETURN(23)
  183.  
  184.    ELSEIF LASTKEY() = 3 .OR. LASTKEY() = 24   && Page Down
  185.       * determine if last page
  186.       IF _nrow = _mbytes           && _posit hasn't moved
  187.          * first see if it is the END of file.  If So, display
  188.          * the message and _cont.
  189.          IF _isend
  190.          ELSE
  191.             DO WHILE !FBOF(_lhand)
  192.                FSEEK(_lhand, -1, 1)
  193.                IF FREADSTR(_lhand, 1) = CHR(10)
  194.                   FSEEK(_lhand, -2, 1)
  195.                   IF FREADSTR(_lhand, 1) = CHR(13)
  196.                      FSEEK(_lhand, 1, 1)   && Move the _posit back off
  197.                      EXIT                   && of the carriage/return LF
  198.                   ENDIF
  199.                ELSE
  200.                   FSEEK(_lhand, -1, 1)
  201.                ENDIF
  202.             ENDDO
  203.             KEYBOARD CHR(23)
  204.             _cont = .T.
  205.             RETURN(0)
  206.  
  207.             * read back the string and find the _posit
  208.             * of the last carriage/return line feed and
  209.             * _posit the marker
  210.          ENDIF
  211.       ELSE
  212.          _mbytes = _nrow
  213.       ENDIF
  214.  
  215.    ELSEIF LASTKEY() = 18 .OR. LASTKEY() = 5         && Page Up
  216.       * determine if first page
  217.       IF _nrow = _mbytes                             && _posit hasn't moved
  218.          _posit = (FPOSIT(_lhand) - _bpread)      && which block to read
  219.          IF _posit < 0
  220.             _posit = 1
  221.             FSEEK(_lhand, 0)
  222.          ELSE
  223.             FSEEK(_lhand, _posit, 0)
  224.             FSEEK(_lhand, (-1 * _bpread), 1)
  225.             IF FPOSIT(_lhand) < 0   && Error trapping condition
  226.                FSEEK(_lhand, 0)     && for top of file situation
  227.             ENDIF
  228.             DO WHILE !FBOF(_lhand)
  229.                FSEEK(_lhand, -1, 1)
  230.                IF FREADSTR(_lhand, 1) = CHR(10)
  231.                   FSEEK(_lhand, -2, 1)
  232.                   IF FREADSTR(_lhand, 1) = CHR(13)
  233.                      FSEEK(_lhand, 1, 1)   && Move the _posit back off
  234.                      EXIT                   && of the carriage/return LF
  235.                   ENDIF
  236.                ELSE
  237.                   FSEEK(_lhand, -1, 1)
  238.                ENDIF
  239.             ENDDO
  240.          ENDIF
  241.          KEYBOARD CHR(23)
  242.          _cont = .T.
  243.          RETURN(0)
  244.  
  245.       ELSE
  246.          _mbytes = _nrow
  247.       ENDIF
  248.  
  249.    ELSEIF LASTKEY() = 290     && alt G  goto line number
  250.       Wpush(Wrow(3), Wcol(2), Wrow(3) + 2, Wcol(2) + 29)
  251.       @ Wrow(1), Wcol(2) SAY "Enter Line Number:"
  252.       _goto = ""
  253.       DO WHILE INKEY(0) != 13
  254.          IF LASTKEY() = 8   && backspace
  255.             IF LEN(_goto) = 1
  256.                _goto = ""
  257.             ELSE
  258.                _goto = SUBSTR(_goto, 1, LEN(_goto)-1)
  259.             ENDIF
  260.             @ Wrow(1), Wcol(21) SAY SPACE(7)
  261.          ELSEIF LASTKEY() = 27   && escape key
  262.             EXIT
  263.          ELSEIF LASTKEY() >= 48 .AND. LASTKEY() <= 57
  264.             IF LEN(_goto) <= 7
  265.                _goto = _goto + CHR(LASTKEY())
  266.             ENDIF
  267.          ELSE
  268.             LOOP
  269.          ENDIF
  270.          @ Wrow(1), Wcol(21) SAY _goto
  271.       ENDDO
  272.  
  273.       IF LASTKEY() = 13
  274.          FSEEK(_lhand, 0)
  275.          _okcount = 0
  276.          _spock = VAL(_goto)
  277.          Gotoline()
  278.          _cont = .T.
  279.          KEYBOARD CHR(23)
  280.          Wpop()
  281.          RETURN(1)
  282.       ENDIF
  283.  
  284.       Wpop()
  285.  
  286.    ELSEIF LASTKEY() = 289     && alt F  file name
  287.  
  288.       Wpush(Wrow(3), Wcol(2), Wrow(3) + 2, Wcol(2) + 32)
  289.       @ Wrow(1), Wcol(2) SAY "Enter File Name: "
  290.       _goto = ""
  291.       DO WHILE INKEY(0) != 13
  292.          IF LASTKEY() = 8   && backspace
  293.             IF LEN(_goto) = 1
  294.                _goto = ""
  295.             ELSE
  296.                _goto = SUBSTR(_goto, 1, LEN(_goto)-1)
  297.             ENDIF
  298.             @ Wrow(1), Wcol(19) SAY SPACE(12)
  299.          ELSEIF LASTKEY() = 27   && escape key
  300.             EXIT
  301.          ELSEIF LASTKEY() >= 45 .AND. LASTKEY() <= 127
  302.             IF LEN(_goto) <= 12
  303.                _goto = _goto + CHR(LASTKEY())
  304.             ENDIF
  305.          ELSE
  306.             LOOP
  307.          ENDIF
  308.          @ Wrow(1), Wcol(19) SAY _goto
  309.       ENDDO
  310.       IF !FILE(TRIM(_goto))
  311.          Clear_area()
  312.          @ Wrow(1), Wcol(2) SAY "File Not Found.  Any Key!"
  313.          INKEY(0)
  314.       ELSEIF FILE(TRIM(_goto)) .AND. LASTKEY() = 13
  315.          FCLOSE(_lhand)
  316.         _lhand  = FOPEN(TRIM(_goto))
  317.         _posit = 1
  318.         _bugaboo     = ""        
  319.         _istop    = .T.        
  320.         _isend    = .F.        
  321.         _check    = 0          
  322.         _bpread = 3000
  323.         _okcount = 0
  324.         _spock = 1
  325.          _cont = .T.
  326.          KEYBOARD CHR(23)
  327.       ENDIF
  328.       Wpop()
  329.  
  330.    ENDIF
  331.  
  332.    RETURN(0)
  333.  
  334. ********************
  335.  
  336. PROCEDURE Gotoline
  337.  
  338.    IF _spock = 1
  339.       FSEEK(_lhand, 0, 0)
  340.    ELSE
  341.       _okcount = 0
  342.       DO WHILE .T.
  343.          _mbytes = 0    && This is an important trick!!!
  344.          _bugaboo = SPACE(_bpread)
  345.          _check = FREAD(_lhand, @_bugaboo, _bpread)
  346.          DO WHILE !EMPTY(_bugaboo) .AND. _okcount != _spock
  347.             _where = AT(CHR(13)+CHR(10), _bugaboo)
  348.             IF EMPTY(_where)
  349.                _bugaboo = ""
  350.             ELSE
  351.                _okcount = _okcount + 1
  352.                _bugaboo = SUBSTR(_bugaboo, _where+2)
  353.             ENDIF
  354.             _mbytes = _mbytes + _where
  355.          ENDDO
  356.  
  357.          IF _okcount = _spock   && we got it!
  358.             * take the length of _tread now, subtract it
  359.             * from 3000 to find out the position.  Rewind
  360.             * back the 3000 bytes read from the file and
  361.             * move to the position.  Now back off from the
  362.             * until the next CHR(13)+CHR(10) combination is
  363.             * found.
  364.             IF _check < 3000
  365.                FSEEK(_lhand, _mbytes, 0)
  366.                _placeit = FSEEK(_lhand, 0, 1)
  367.             ELSE
  368.                _whereat = _check - LEN(_bugaboo)
  369.                FSEEK(_lhand, (-1 * _check), 1)
  370.                _placeit = FSEEK(_lhand, 0, 1)
  371.                FSEEK(_lhand, _whereat, 1)
  372.                * next, we must move OFF of the
  373.                * CHR(13)/CHR(10) combinations
  374.                * so that the following fseek
  375.                * will act right...
  376.             ENDIF
  377.             _mbytes = 0   
  378.             FSEEK(_lhand, -2, 1)
  379.             DO WHILE FSEEK(_lhand, 0, 1) != _placeit
  380.                FSEEK(_lhand, -1, 1)
  381.                IF FREADSTR(_lhand, 1) = CHR(10)
  382.                   FSEEK(_lhand, -2, 1)
  383.                   IF FREADSTR(_lhand, 1) = CHR(13)
  384.                      FSEEK(_lhand, 1, 1)   && Move back off
  385.                      EXIT                   && of the CR/LF
  386.                   ENDIF
  387.                ELSE
  388.                   FSEEK(_lhand, -1, 1)
  389.                ENDIF
  390.             ENDDO
  391.             EXIT
  392.    
  393.          ELSEIF _check != 3000
  394.  
  395.             * no line number was found and the end of file
  396.             * marker was reached, so just reposition to
  397.             * the top of the file, and display a little
  398.             * message at the bottom of the screen showing
  399.             * this!
  400.             FSEEK(_lhand, 0)
  401.             EXIT
  402.  
  403.          ENDIF
  404.       ENDDO
  405.    ENDIF
  406.    
  407. * End of File
  408.  
  409.