home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / DFILE.PRG < prev    next >
Text File  |  1991-08-17  |  7KB  |  232 lines

  1. /*
  2.  * File......: DFILE.PRG
  3.  * Author....: Mike Taylor
  4.  * Date......: $Date:   17 Aug 1991 15:24:14  $
  5.  * Revision..: $Revision:   1.3  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/dfile.prv  $
  7.  * 
  8.  * This is an original work by Mike Taylor and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/dfile.prv  $
  15.  * 
  16.  *    Rev 1.3   17 Aug 1991 15:24:14   GLENN
  17.  * Don Caton corrected some spelling errors in the doc
  18.  * 
  19.  *    Rev 1.2   15 Aug 1991 23:03:24   GLENN
  20.  * Forest Belt proofread/edited/cleaned up doc
  21.  * 
  22.  *    Rev 1.1   14 Jun 1991 19:51:32   GLENN
  23.  * Minor edit to file header
  24.  * 
  25.  *    Rev 1.0   01 Apr 1991 01:01:08   GLENN
  26.  * Nanforum Toolkit
  27.  *
  28.  */
  29.  
  30.  
  31.  
  32. static nHandle := 0
  33.  
  34. #ifdef FT_TEST
  35.  
  36.     FUNCTION MAIN()
  37.  
  38.     @ 0,0 CLEAR
  39.  
  40.     cInFile   := "FT_DFILE.PRG"
  41.     CKEY      := ""
  42.     NNCOLOR   := 7
  43.     NHCOLOR   := 15
  44.     NCOLSKIP  := 5
  45.     NRMARGIN  := 132
  46.     CEXITKEYS := "AABBC       "
  47.     LBROWSE   := .F.
  48.     NSTART    := 1
  49.     NBUFFSIZE := 4096
  50.  
  51.     @ 0,0  SAY "ENTER FILENAME: "   GET CINFILE
  52.     @ 1,0  SAY "    FOREGROUND: "   GET NNCOLOR   PICTURE "999"
  53.     @ 2,0  SAY "     HIGHLIGHT: "   GET NHCOLOR   PICTURE "999"
  54.     @ 3,0  SAY "     EXIT KEYS: "   GET CEXITKEYS
  55.     @ 4,0  SAY "   BUFFER SIZE: "   GET NBUFFSIZE PICTURE "9999"
  56.     @ 1,40 SAY "COLUMN INCREMENT: " GET NCOLSKIP  PICTURE "999"
  57.     @ 2,40 SAY "   MAX LINE SIZE: " GET NRMARGIN  PICTURE "999"
  58.     @ 3,40 SAY "     BROWSE MODE? " GET LBROWSE   PICTURE "Y"
  59.  
  60.     READ
  61.  
  62.     /*
  63.      * REMEMBER A WINDOW WILL BE ONE SIZE LESS AND GREATER THAN THE PASSED COORD.'S
  64.      *
  65.      * THE 9TH PARAMETER CONTAINS THE KEYS THAT THE ROUTINE WILL TERMINATE ON
  66.      * AND THE CHR(143) represents the F3 key.
  67.      *
  68.      */
  69.  
  70.     @ 4,9 TO 11,71
  71.  
  72.     FT_DFSETUP(cInFile, 5, 10, 10, 70, nStart,;
  73.                nNColor, nHColor, cExitKeys + CHR(143),;
  74.                lBrowse, nColSkip, nRMargin, nBuffSize)
  75.  
  76.     cKey := FT_DISPFILE()
  77.  
  78.     FT_DFCLOSE()
  79.  
  80.     @ 20,0 SAY "Key pressed was: " + '[' + cKey + ']'
  81.  
  82.     return (NIL)
  83.  
  84. #endif
  85.  
  86.  
  87.  
  88.  
  89. /*  $DOC$
  90.  *  $FUNCNAME$
  91.  *     FT_DFSETUP()
  92.  *  $CATEGORY$
  93.  *     File I/O
  94.  *  $ONELINER$
  95.  *     Set up parameters for FT_DISPFILE()
  96.  *  $SYNTAX$
  97.  *     FT_DFSETUP( <cInFile>, <nTop>, <nLeft>, <nBottom>, <nRight>, ;
  98.  *              <nStart>, <nCNormal>, <nCHighlight>, <cExitKeys>,   ;
  99.  *              <lBrowse>, <nColSkip>, <nRMargin>, <nBuffSize> ) -> nResult
  100.  *  $ARGUMENTS$
  101.  *        <cInFile>     - text file to display (full path and filename)
  102.  *        <nTop>        - upper row of window
  103.  *        <nLeft>       - left col of window
  104.  *        <nBottom>     - lower row of window
  105.  *        <nRight>      - right col of window
  106.  *        <nStart>      - line to place highlight at startup
  107.  *        <nCNormal>    - normal text color     (numeric attribute)
  108.  *        <nCHighlight> - text highlight color  (numeric attribute)
  109.  *        <cExitKeys>   - terminating key list  (each byte of string is a
  110.  *                        key code)
  111.  *        <lBrowse>     - act-like-a-browse-routine flag
  112.  *        <nColSkip>    - col increment for left/right arrows
  113.  *        <nRMargin>    - right margin - anything to right is truncated
  114.  *        <nBuffSize>   - size of the paging buffer
  115.  *  $RETURNS$
  116.  *     0 if successful, FError() code if not
  117.  *  $DESCRIPTION$
  118.  *     Note: make sure you allocate a buffer large enough to hold enough
  119.  *     data for the number of lines that you have in the window.  Use the
  120.  *     following formula as a guideline:
  121.  *
  122.  *        buffer size = (# of line) + 1 * RMargin
  123.  *
  124.  *     This is the smallest you should make the buffer.  For normal use,
  125.  *     4096 bytes is recommended
  126.  *  $EXAMPLES$
  127.  *     @ 4,9 TO 11,71
  128.  *
  129.  *     FT_DFSETUP("test.txt", 5, 10, 10, 70, 1, 7, 15,;
  130.  *                "AaBb" + Chr(143), .T., 5, 132, 4096)
  131.  *
  132.  *     cKey = FT_DISPFILE()
  133.  *                         
  134.  *     FT_DFCLOSE()
  135.  *
  136.  *     @ 20,0 SAY "Key that terminated FT_DISPFILE() was: " + '[' + cKey + ']'
  137.  *  $SEEALSO$
  138.  *     FT_DISPFILE() FT_DFCLOSE()
  139.  *  $END$
  140.  */
  141.  
  142.  
  143.  
  144. function FT_DFSETUP(cInFile, nTop, nLeft, nBottom, nRight,;
  145.                     nStart, nCNormal, nCHighlight, cExitKeys,;
  146.                     lBrowse, nColSkip, nRMargin, nBuffSize )
  147.  
  148.   local rval := 0
  149.  
  150.   if File(cInFile)
  151.      nTop    := if(ValType(nTop)    == "N", nTop,           0)
  152.      nLeft   := if(ValType(nLeft)   == "N", nLeft,          0)
  153.      nBottom := if(ValType(nBottom) == "N", nBottom, MaxRow())
  154.      nRight  := if(ValType(nRight)  == "N", nRight,  MaxCol())
  155.  
  156.      nCNormal     := if(ValType(nCNormal)    == "N", nCNormal,     7)
  157.      nCHighlight := if(ValType(nCHighlight) == "N", nCHighlight, 15)
  158.  
  159.      nStart    := if(ValType(nStart)    == "N", nStart,      1)
  160.      nColSkip  := if(ValType(nColSkip)  == "N", nColSkip,    1)
  161.      lBrowse   := if(ValType(lBrowse)   == "L", lBrowse,   .F.)
  162.  
  163.      nRMargin  := if(ValType(nRMargin)  == "N", nRMargin,   255)
  164.      nBuffSize := if(ValType(nBuffSize) == "N", nBuffSize, 4096)
  165.  
  166.      cExitKeys := if(ValType(cExitKeys) == "C", cExitKeys,  "")
  167.  
  168.      cExitKeys := if(Len(cExitKeys) > 25, SubStr(cExitKeys, 1, 25), cExitKeys)
  169.  
  170.      nHandle := FOpen(cInFile)
  171.  
  172.      rval := FError()
  173.  
  174.      if ( rval == 0 )
  175.            rval := _FT_DFINIT(nHandle, nTop, nLeft, nBottom, nRight,;
  176.                               nStart, nCNormal, nCHighlight, cExitKeys,;
  177.                               lBrowse, nColSkip, nRMargin, nBuffSize)
  178.      endif
  179.   else
  180.      rval := 2       // simulate a file-not-found DOS file error
  181.   endif
  182.  
  183. return (rval)
  184.  
  185.  
  186.  
  187. /*  $DOC$
  188.  *  $FUNCNAME$
  189.  *     FT_DFCLOSE()
  190.  *  $CATEGORY$
  191.  *     File I/O
  192.  *  $ONELINER$
  193.  *     Close file displayed by FT_DISPFILE()
  194.  *  $SYNTAX$
  195.  *     FT_DFCLOSE() -> NIL
  196.  *  $ARGUMENTS$
  197.  *     None
  198.  *  $RETURNS$
  199.  *     NIL
  200.  *  $DESCRIPTION$
  201.  *     Closes the file opened by FT_DFSETUP()
  202.  *  $EXAMPLES$
  203.  *     @ 4,9 TO 11,71
  204.  *
  205.  *     FT_DFSETUP("test.txt", 5, 10, 10, 70, 1, 7, 15,;
  206.  *                 "AaBb" + Chr(143), .T., 5, 132, 4096)
  207.  *
  208.  *     cKey = FT_DISPFILE()
  209.  *                         
  210.  *     FT_DFCLOSE()
  211.  *
  212.  *     @ 20,0 SAY "Key that terminated FT_DISPFILE() was: " + '[' + cKey + ']'
  213.  *  $SEEALSO$
  214.  *     FT_DFSETUP() FT_DISPFILE()
  215.  *  $END$
  216.  */
  217.  
  218.  
  219.  
  220.  
  221. function FT_DFCLOSE()
  222.  
  223.   if ( nHandle > 0 )
  224.      _FT_DFCLOS()
  225.  
  226.      FClose(nHandle)
  227.  
  228.      nHandle := 0
  229.   endif
  230.  
  231.   return (NIL)
  232.