home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / clipper / oop / oopexm / hdosfile.prg < prev    next >
Encoding:
Text File  |  1992-01-27  |  3.2 KB  |  129 lines

  1. **
  2. **  PROGRAM TITLE  : HDOSFILE
  3. **
  4. **   WRITTEN BY    :  Paul Long
  5. **
  6. **   WRITTEN FOR   :  Copyright (C) 1992 All rights reserved. XL Systems, Inc.
  7. **
  8. **   PROGRAM INTENT:  Functions for DOS file access
  9. **
  10. **   NOTE:            This file uses a hybrid approach  It uses "traditional,"
  11. **                    non-OOP programming, but organizing the code along OOP
  12. **                    lines, e.g., one source file per "class."
  13. **
  14. #include "fileio.ch"
  15.  
  16. static lDOSFileFound
  17.  
  18.  
  19. *******************************************************
  20. *
  21. *                             DOSFileNew
  22. *
  23. *******************************************************
  24. * Construct DOSFile object mainly by opening input file
  25. *
  26. function DOSFileNew(cFileName)
  27.  
  28. local nHandle := F_ERROR
  29.  
  30. // Initialize variables to a known state
  31. DOSFileFound(.t.)
  32.  
  33. if cFileName == nil
  34.    ?? "*** ERROR *** missing file name"
  35. else
  36.    if (nHandle := fopen(cFileName, FO_READ)) == F_ERROR
  37.       ?? "*** ERROR *** " + cFileName + " cannot be opened"
  38.    endif
  39. endif
  40.  
  41. return nHandle
  42.  
  43.  
  44. *******************************************************
  45. *
  46. *                             DOSFileDestruct
  47. *
  48. *******************************************************
  49. * Destruct DOSFile object by closing input file
  50. *
  51. function DOSFileDestruct(nHandle)
  52.  
  53. fclose(nHandle)
  54.  
  55. return nil
  56.  
  57.  
  58. *******************************************************
  59. *
  60. *                             DOSFileRead
  61. *
  62. *******************************************************
  63. * Read next record from input file, moving pointer to next record.
  64. *
  65. function DOSFileRead(nHandle)
  66.  
  67. return freadline(nHandle)
  68.  
  69.  
  70. *******************************************************
  71. *
  72. *                             DOSFileSkip
  73. *
  74. *******************************************************
  75. * Skip forward through file and read the last, nth record.
  76. * Currently, non-positive skips are treated like DOSFileSkip(1).
  77. * This should probably be changed to accomodate non-positive
  78. * skips.
  79. *
  80. function DOSFileSkip(nHandle, nRecords)
  81.  
  82. local n
  83.  
  84. // If nil argument, treat like Skip(1)
  85. nRecords := if(nRecords == nil, 0, nRecords - 1)
  86. DOSFileFound(.t.)
  87.  
  88. for n = 1 to nRecords
  89.    if !(DOSFileFound(fadvance(nHandle) != F_ERROR))
  90.       exit
  91.    endif
  92. next
  93.  
  94. // Read and return nth record if skip succeeded; otherwise, return null string
  95. return if(DOSFileFound(), DOSFileRead(nHandle), "")
  96.  
  97.  
  98. *******************************************************
  99. *
  100. *                             DOSFileLocate
  101. *
  102. *******************************************************
  103. * Search for string in file.  If found, the entire record is read in, and
  104. * file pointer is moved to beginning of next record.
  105. *
  106. function DOSFileLocate(nHandle, cString)
  107.  
  108. if DOSFileFound(flocate(nHandle, cString) >= 0)
  109.    fbol(nHandle)
  110. endif
  111.  
  112. return if(DOSFileFound(), DOSFileRead(nHandle), "")
  113.  
  114.  
  115. *******************************************************
  116. *
  117. *                             DOSFileFound
  118. *
  119. *******************************************************
  120. * Return whether last search succeeded.
  121. *
  122. function DOSFileFound(lWhetherFound)
  123.  
  124. if lWhetherFound != nil
  125.    lDOSFileFound := lWhetherFound
  126. endif
  127.  
  128. return lDOSFileFound
  129.