home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP25.EXE / CHP2514.PRG < prev    next >
Encoding:
Text File  |  1991-06-12  |  1.5 KB  |  61 lines

  1. /*
  2.    Listing 25.14. A file browser for small text files.
  3.    Author: Craig Yellick
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. //───── NOTE: must compile with the /N option!
  12.  
  13. function BrowText(filename)
  14. /*
  15.    A general-purpose file browser for small text files.
  16.    Pass a file name from DOS.
  17. */
  18.  
  19. local textfile, lastLine, line, txt
  20.  
  21.   if filename = nil
  22.     ? "Must specify a file name."
  23.     return nil
  24.   endif
  25.  
  26.   //  Load the contents of the specified file.
  27.   textfile := memoread(filename)
  28.  
  29.   //  Determine how many lines are in the file.
  30.   lastLine := mlcount(textfile)
  31.  
  32.   //  A pointer used to keep track of which line we're on.
  33.   line := 1
  34.  
  35.   @ 8, 19 say "File: " +filename
  36.   @ 9, 19 to 21, 61
  37.  
  38.   //  Create the browse object.
  39.   txt := TBrowseNew(10, 20, 20, 60)
  40.  
  41.   //  Add a column that displays a line of text.
  42.   txt:addColumn(TBColumnNew(, ;
  43.     { || memoline(textfile, 254, line)} ))
  44.  
  45.   //  The data positioning blocks.
  46.   txt:goTopBlock := { || line := 1 }
  47.   txt:goBottomBlock := { || line := lastLine }
  48.   txt:skipBlock := { |n| ArraySkip(lastLine, @line, n) }
  49.  
  50.   //  Display the window and process navigation keystrokes.
  51.   do while .t.
  52.     do while .not. txt:stabilize()
  53.     enddo
  54.     if .not. Navigate(txt, inkey(0))
  55.       exit
  56.     endif
  57.   enddo
  58. return nil
  59.  
  60. // end of file CHP2514.PRG
  61.