home *** CD-ROM | disk | FTP | other *** search
- **
- ** PROGRAM TITLE : HDOSFILE
- **
- ** WRITTEN BY : Paul Long
- **
- ** WRITTEN FOR : Copyright (C) 1992 All rights reserved. XL Systems, Inc.
- **
- ** PROGRAM INTENT: Functions for DOS file access
- **
- ** NOTE: This file uses a hybrid approach It uses "traditional,"
- ** non-OOP programming, but organizing the code along OOP
- ** lines, e.g., one source file per "class."
- **
- #include "fileio.ch"
-
- static lDOSFileFound
-
-
- *******************************************************
- *
- * DOSFileNew
- *
- *******************************************************
- * Construct DOSFile object mainly by opening input file
- *
- function DOSFileNew(cFileName)
-
- local nHandle := F_ERROR
-
- // Initialize variables to a known state
- DOSFileFound(.t.)
-
- if cFileName == nil
- ?? "*** ERROR *** missing file name"
- else
- if (nHandle := fopen(cFileName, FO_READ)) == F_ERROR
- ?? "*** ERROR *** " + cFileName + " cannot be opened"
- endif
- endif
-
- return nHandle
-
-
- *******************************************************
- *
- * DOSFileDestruct
- *
- *******************************************************
- * Destruct DOSFile object by closing input file
- *
- function DOSFileDestruct(nHandle)
-
- fclose(nHandle)
-
- return nil
-
-
- *******************************************************
- *
- * DOSFileRead
- *
- *******************************************************
- * Read next record from input file, moving pointer to next record.
- *
- function DOSFileRead(nHandle)
-
- return freadline(nHandle)
-
-
- *******************************************************
- *
- * DOSFileSkip
- *
- *******************************************************
- * Skip forward through file and read the last, nth record.
- * Currently, non-positive skips are treated like DOSFileSkip(1).
- * This should probably be changed to accomodate non-positive
- * skips.
- *
- function DOSFileSkip(nHandle, nRecords)
-
- local n
-
- // If nil argument, treat like Skip(1)
- nRecords := if(nRecords == nil, 0, nRecords - 1)
- DOSFileFound(.t.)
-
- for n = 1 to nRecords
- if !(DOSFileFound(fadvance(nHandle) != F_ERROR))
- exit
- endif
- next
-
- // Read and return nth record if skip succeeded; otherwise, return null string
- return if(DOSFileFound(), DOSFileRead(nHandle), "")
-
-
- *******************************************************
- *
- * DOSFileLocate
- *
- *******************************************************
- * Search for string in file. If found, the entire record is read in, and
- * file pointer is moved to beginning of next record.
- *
- function DOSFileLocate(nHandle, cString)
-
- if DOSFileFound(flocate(nHandle, cString) >= 0)
- fbol(nHandle)
- endif
-
- return if(DOSFileFound(), DOSFileRead(nHandle), "")
-
-
- *******************************************************
- *
- * DOSFileFound
- *
- *******************************************************
- * Return whether last search succeeded.
- *
- function DOSFileFound(lWhetherFound)
-
- if lWhetherFound != nil
- lDOSFileFound := lWhetherFound
- endif
-
- return lDOSFileFound
-