home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 24 / PCPLUS115.iso / install / extern.pak / DBGREP.PRG < prev    next >
Encoding:
Text File  |  1994-08-02  |  1.3 KB  |  67 lines

  1. *******************************************************************************
  2. *  PROGRAM:      dbgrep.prg
  3. *
  4. *  WRITTEN BY:   Borland Samples Group.
  5. *
  6. *  DATE:         1/94
  7. *
  8. *  UPDATED:      3/94
  9. *
  10. *  VERSION:      Field Test March 94
  11. *
  12. *  DESCRIPTION:  Small example that uses dbfile.dll.  It implements 
  13. *                a grep to search for a literal string in a file.
  14. *
  15. *  PARAMETERS:   String to search for, filename.
  16. *
  17. *  CALLS:        To dbfile.dll
  18. *
  19. *  USAGE:        do dbgrep with "string", "filename"
  20. *
  21. *******************************************************************************
  22.  
  23. parameters str, name
  24.  
  25. set talk off
  26.  
  27.  * Check parameters.
  28. tellusage = 1
  29.  
  30.  * Enough parameters?
  31. if pcount() = 2
  32.     * Of the right type?
  33.    if type( "str" ) = "C" .AND. type( "name" ) = "C"
  34.        tellusage = 0
  35.    endif
  36. endif
  37.  
  38. if tellusage = 1
  39.    ? "Usage: do dbgrep with 'string', 'filename'"
  40.    return
  41. endif
  42.  
  43.  * Check for valid file.
  44. if .not. file( name )
  45.    ? "No such file: " + name
  46.    return
  47. endif
  48.  
  49.  * Initialize dbfile.dll
  50. set procedure to dbfile additive
  51. do dbfile
  52.  
  53.  * Open up and set the filter to the string wanted.
  54. f = new textfile()
  55. f.filter( str )
  56. f.open( name )
  57.  
  58.  * Go till something happens.
  59. do while .not. (f.eof() .or. f.error())
  60. str = f.getline()
  61. ? str
  62. enddo
  63.  
  64.  * Close up.
  65. f.close()
  66. f.release()
  67.