ADIR() | Fill a series of arrays with directory information |
BZIP2CLOSE() | Close bZIP2 file. |
BZIP2OPEN() | Open bZip2 file. |
BZIP2READ() | Read data from bZIP2 file. |
BZIP2WRITE() | Write data to bZIP2 file. |
CURDIR() | Return the current DOS directory |
DIRCHANGE() | Change the current DOS directory |
DIRECTORY() | Create an array of directory and file information |
DOSERROR() | Return the last DOS error number |
DOSPATH() | Returns file name as DOS file name. |
FACCESS() | Check access to file. |
FCLOSE() | Close an open binary file and write DOS buffers to disk |
FCREATE() | Create and/or truncate a binary file to zero-length |
FERASE() | Delete a file from disk |
FERROR() | Test for errors after a binary file operation |
FERRORSTR() | Under construction |
FILE() | Determine if files exist in the xClipper default directory or path |
FILEATTR() | Under construction |
FILEATTRS() | Returns string - file attributes. |
FILEGETSTR() | Returns string. |
FOPEN() | Open a binary file |
FREAD() | Read characters from a binary file into a buffer variable |
FREADSTR() | Read characters from a binary file |
FRENAME() | Change the name of a file |
FSEEK() | Set a binary file pointer to a new position |
FT_DFCLOSE() | Close file displayed by FT_DISPFILE() |
FT_DFSETUP() | Set up parameters for FT_DISPFILE() |
FT_FAPPEND() | Appends a line to the currently selected text file |
FT_FBOF() | Determine if attempt to skip past beginning of text file |
FT_FDELETE() | Deletes a line from the currently selected text file |
FT_FEOF() | Determine if end of text file has been encountered |
FT_FERROR() | Return the error code for a text file operation |
FT_FGOBOT() | Go to the last record in a text file |
FT_FGOTO() | Move record pointer to specific record in a text file |
FT_FGOTOP() | Go to the first record in a text file |
FT_FINSERT() | Inserts a line in the currently selected text file |
FT_FLASTRE() | Get the no. of records in the currently selected text file |
FT_FREADLN() | Read a line from the currently selected text file |
FT_FRECNO() | Return the current record number of a text file |
FT_FSELECT() | Select a text file workarea |
FT_FSKIP() | Move the record pointer to a new position in a text file |
FT_FUSE() | Open or close a text file for use by the FT_F* functions |
FT_FWRITELN() | Write a line to the currently selected text file |
FWRITE() | Write to an open binary file |
GZIPCLOSE() | Close GZIP file. |
GZIPOPEN() | Open GZIP file. |
GZIPREAD() | Read data from GZIP file. |
GZIPWRITE() | Write data to GZIP file. |
MAKEPATH() | Returns path to file in UNIX style. |
MEMOREAD() | Return the contents of a disk file as a character string |
MEMOWRIT() | Write a character string or memo field to a disk file |
NETERR() | Determine if a network command has failed |
OUTERR() | Write a list of values to the standard error device |
OUTSTD() | Write a list of values to the standard output device |
STARTPATH() | Returns full path and name of program. |
TCPACCEPT() | Accept a connection on a socket. |
TCPCLOSE() | Close connection. |
TCPCONNECT() | Connect with server. |
TCPLISTEN() | Listen port. |
TCPREAD() | Read to buffer data from connection. |
TCPWRITE() | Commit data from buffer to connection. |
FACCESS(<sFileName>, <sMode>) --> TRUE || FALSE
Returns TRUE if specified access mode is true for file.
FACCESS() checks access mode <sMode> for file <sFileName>.
<sMode> is the string in UNIX format "rwx-rwx-rwx" (owner-group-other)
FACCESS("/usr/home/user1/mbox", "rw--") // TRUE FACCESS("/usr/home/user1/mbox", "rw-rw-rw") // FALSE
FCLOSE(<nHandle>) --> lError
FCLOSE() returns false (.F.) if an error occurs while writing; otherwise, it returns true (.T.).
FCLOSE() is a low-level file function that closes binary files and forces the associated DOS buffers to be written to disk. If the operation fails, FCLOSE() returns false (.F.). FERROR() can then be used to determine the reason for the failure. For example, attempting to use FCLOSE() with an invalid handle returns false (.F.), and FERROR() returns DOS error 6, invalid handle. See FERROR() for a complete list of error numbers.
Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.
This example uses FCLOSE() to close a newly created binary file and displays an error message if the close fails: #include "Fileio.ch" // nHandle := FCREATE("Testfile", FC_NORMAL) IF !FCLOSE(nHandle) ? "Error closing file, error number: ", FERROR() ENDIF
FCREATE(<cFile>, [<nAttribute>]) --> nHandle
<cFile> | is the name of the file to create. If the file already |
exists, its length is truncated to zero without warning. | |
<nAttribute> | is one of the binary file attributes shown in the table |
below. If this argument is omitted, the default value is zero. | |
Binary File Attributes ------------------------------------------------------------------------ Value Fileio.ch Attribute Description ------------------------------------------------------------------------ 0 FC_NORMAL Normal Create normal read/write file (default) 1 FC_READONLY Read-only Create read-only file 2 FC_HIDDEN Hidden Create hidden file 4 FC_SYSTEM System Create system file ------------------------------------------------------------------------ |
FCREATE() returns the DOS file handle number of the new binary file in the range of zero to 65,535. If an error occurs, FCREATE() returns -1 and FERROR() is set to indicate an error code.
FCREATE() is a low-level file function that either creates a new file or opens and truncates an existing file. If <cFile> does not exist, it is created and opened for writing. If it does exist and can be opened for writing, it is truncated to zero-length. If it cannot be opened for writing, FCREATE() returns -1 and FERROR() returns the appropriate error value.
When FCREATE() successfully creates a new file, the file is left open in compatibility sharing mode and read/write access mode. The file attribute specified by the <nAttribute> argument is applied to the new file when it is closed, allowing writing to a newly created read-only file. For a list of access modes, see FOPEN().
Since a file handle is required in order to identify an open file to other file functions, always assign the return value from FCREATE() to a variable for later use.
Like other file functions, FCREATE() does not use either the DEFAULT or PATH settings for its operation. Instead, it writes to the current DOS directory unless a path is explicitly stated.
Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.
This example creates a file called Testfile and opens it for reading and writing: #include "Fileio.ch" // IF (nHandle := FCREATE("Testfile", FC_NORMAL)) == -1 ? "File cannot be created:", FERROR() BREAK ELSE FWRITE(nHandle, "Hello there") FCLOSE(nHandle) ENDIF
FERASE(<cFile>) --> nSuccess
FERASE() returns -1 if the operation fails and zero if it succeeds. In the case of a failure, FERROR() can be used to determine the nature of the error.
FERASE() is a file function that deletes a specified file from disk. FERASE() is the same as the ERASE command but returns a value and can be specified within an expression. When FERASE() is called, <cFile> is deleted from disk only if found in the current DOS directory or in the directory explicitly specified as part of the file name. Like the other file functions and commands, FERASE() does not use either SET DEFAULT or SET PATH to locate <cFile>.
Warning! Files must be CLOSEd before removing them with FERASE().
This example deletes a set of files matching a wildcard pattern: #include "Directry.ch" AEVAL(DIRECTORY("*.BAK"), { |aFile| ; FERASE(aFile[F_NAME]) }) This example erases a file and displays a message if the operation fails: IF FERASE("AFile.txt") == -1 ? "File erase error:", FERROR() BREAK ENDIF
FILE(<cFilespec>) --> lExists
FILE() returns true (.T.) if there is a match for any file matching the <cFilespec> pattern; otherwise, it returns false (.F.).
FILE() is an environment function that determines whether any file matching a file specification pattern is found. FILE() searches the specified directory if a path is explicitly specified.
If a path is not specified, FILE() searches the current xClipper default directory and then the xClipper path. In no case is the DOS path searched. Note also that FILE() does not recognize hidden or system files in its search.
In this example FILE() attempts to find Sales.dbf in other than the current xClipper default: ? FILE("Sales.dbf") // Result: .F. ? FILE("\APPS\DBF\Sales.dbf") // Result: .T. // SET PATH TO \APPS\DBF ? FILE("Sales.dbf") // Result: .T. // SET PATH TO SET DEFAULT TO \APPS\DBF\ ? FILE("Sales.dbf") // Result: .T. ? FILE("*.dbf") // Result: .T.
FILEATTRS(<sFileName>) --> <sFileAttrs>
Returns string <sFileAttrs>, what contents file attributes.
FILEATTRS() lakes FILEATTR(), but returns string <sFileAttrs>, what contents file attributes.
SET("C:", "/usr/home/user1") sUnixFileName := "/usr/home/user1/test.prg" ? FILEATTR(sUnixFileName) // --> 32 ? FILEATTRS(sUnixFileName) // --> A
FILEGETSTR(<nFileHandle>, <nSize>) --> <sFileStr>
Returns string <sFileStr>, what was read from file <nFileHandle>.
FILEGETSTR() reads string from opened file. The size result string restrict <CRLF> or <CR>, but no more then <nSize> symbols.
nFile := FOPEN("test.txt") do while !feof(nFile) ? FILEGETSTR(nFile, 1024) ? enddo fclose()
FOPEN(<cFile>, [<nMode>]) --> nHandle
<cFile> | is the name of the file to open, including the path if there |
is one. | |
<nMode> | is the requested DOS open mode indicating how the opened |
file is to be accessed. The open mode is composed of elements from the | |
two types of modes described in the tables below. If just the Access | |
Mode is used, the file is opened non-sharable. The default open mode is | |
zero, which indicates non-sharable and read-only. | |
FOPEN() Access Modes ------------------------------------------------------------------------ Mode Fileio.ch Operation ------------------------------------------------------------------------ 0 FO_READ Open for reading (default) 1 FO_WRITE Open for writing 2 FO_READWRITE Open for reading or writing ------------------------------------------------------------------------ | |
The Sharing Modes determine how other processes may access the file. | |
FOPEN() Sharing Modes ------------------------------------------------------------------------ Mode Fileio.ch Operation ------------------------------------------------------------------------ 0 FO_COMPAT Compatibility mode (default) 16 FO_EXCLUSIVE Exclusive use 32 FO_DENYWRITE Prevent others from writing 48 FO_DENYREAD Prevent others from reading 64 FO_DENYNONE Allow others to read or write 64 FO_SHARED Same as FO_DENYNONE ------------------------------------------------------------------------ | |
The Access Modes in combination (+) with the Sharing modes determine the | |
accessibility of the file in a network environment. |
FOPEN() returns the file handle of the opened file in the range of zero to 65,535. If an error occurs, FOPEN() returns -1.
FOPEN() is a low-level file function that opens an existing binary file for reading and writing, depending on the <nMode> argument. Whenever there is an open error, use FERROR() to return the DOS error number. For example, if the file does not exist, FOPEN() returns -1 and FERROR() returns 2 to indicate that the file was not found. See FERROR() for a complete list of error numbers.
If the specified file is opened successfully, the value returned is the DOS handle for the file. This value is similar to an alias in the database system and is required to identify the open file to other file functions. It is, therefore, important to assign the return value to a variable for later use as in the example below.
Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.
This example uses FOPEN() to open a file with sharable read/write status and displays an error message if the open fails: #include "Fileio.ch" // nHandle := FOPEN("Temp.txt", FO_READWRITE + FO_SHARED) IF FERROR() != 0 ? "Cannot open file, DOS error ", FERROR() BREAK ENDIF
FREAD(<nHandle>, @<cBufferVar>, <nBytes>) --> nBytes
<nHandle> | is the file handle obtained from FOPEN(), FCREATE(), or |
predefined by DOS. | |
<cBufferVar> | is the name of an existing and initialized character |
variable used to store data read from the specified file. The length of | |
this variable must be greater than or equal to <nBytes>. <cBufferVar> | |
must be passed by reference and, therefore, must be prefaced by the pass- | |
by-reference operator (@). | |
<nBytes> | is the number of bytes to read into the buffer. |
FREAD() returns the number of bytes successfully read as an integer numeric value. A return value less than <nBytes> or zero indicates end of file or some other read error.
FREAD() is a low-level file function that reads characters from a binary file into an existing character variable. It reads from the file starting at the current DOS file pointer position, advancing the file pointer by the number of bytes read. All characters are read including control, null, and high-order (above CHR(127)) characters.
FREAD() is similar in some respects to both FREADSTR() and FSEEK(). FREADSTR() reads a specified number of bytes from a file up to the next null (CHR(0)) character. FSEEK() moves the file pointer without reading.
If there is an error during the file read, FERROR() returns the DOS error number. See FERROR() for the list of error numbers.
Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.
This example uses FREAD() after successfully opening a file to read 128 bytes into a buffer area: #define F_BLOCK 128 // cBuffer := SPACE(F_BLOCK) nHandle := FOPEN("Temp.txt") // IF FERROR() != 0 ? "File open error:", FERROR() ELSE IF FREAD(nHandle, @cBuffer, F_BLOCK) <> F_BLOCK ? "Error reading Temp.txt" ENDIF FCLOSE(nHandle) ENDIF
FREADSTR(<nHandle>, <nBytes>) --> cString
FREADSTR() returns a character string up to 65,535 (64K) bytes. A null return value ("") indicates an error or end of file.
FREADSTR() is a low-level file function that reads characters from an open binary file beginning with the current DOS file pointer position. Characters are read up to <nBytes> or until a null character (CHR(0)) is encountered. All characters are read including control characters except for CHR(0). The file pointer is then moved forward <nBytes>. If <nBytes> is greater than the number of bytes from the pointer position to the end of the file, the file pointer is positioned to the last byte in the file.
Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.
This example displays the ASCII values of the first 16 bytes of a text file: #include "Fileio.ch" // nHandle := FOPEN("New.txt", FC_NORMAL) IF FERROR() != 0 ? "File open error:", FERROR() ELSE cString := FREADSTR(nHandle, 16) ? cString FCLOSE(nHandle) ENDIF
FRENAME(<cOldFile>, <cNewFile>) --> nSuccess
<cOldFile> | is the name of the file to be renamed, including the file |
extension. A drive letter and/or path name may also be included as part | |
of the file name. | |
<cNewFile> | is the new name of the file, including the file |
extension. A drive letter and/or path name may also be included as part | |
of the name. |
FRENAME() returns -1 if the operation fails and zero if it succeeds. In the case of a failure, FERROR() can be used to determine the nature of the error.
FRENAME() is a file function that changes the name of a specified file to a new name and is identical to the RENAME command.
When FRENAME() is called, <cOldFile> is renamed only if it is located in the current DOS directory or in the specified path. FRENAME() does not use SET DEFAULT or SET PATH to locate <cOldFile>.
If the source directory is different from the target directory, the file moves to the target directory. In the instance that either <cNewFile> exists or is currently open, FRENAME() fails and returns -1, indicating that it did not perform its designated action. The nature of the error can be determined with FERROR().
Warning! Files must be CLOSEd before renaming. Attempting to rename an open file will produce unpredictable results. When a database file is renamed, the associated memo (.dbt) file must also be renamed. Failure to do so may compromise the integrity of your databases.
This example demonstrates a file rename: IF FRENAME("OldFile.txt", "NewFile.txt") == -1 ? "File error:", FERROR() ENDIF
FSEEK(<nHandle>, <nOffset>, [<nOrigin>]) --> nPosition
<nHandle> | is the file handle obtained from FOPEN(), FCREATE(), or |
predefined by DOS. | |
<nOffset> | is the number of bytes to move the file pointer from the |
position defined by <nOrigin>. It can be a positive or negative number. | |
A positive number moves the pointer forward, and a negative number moves | |
the pointer backward in the file. | |
<nOrigin> | defines the starting location of the file pointer before |
FSEEK() is executed. The default value is zero, representing the | |
beginning of file. If <nOrigin> is the end of file, <nOffset> must be | |
zero or negative. | |
Methods of Moving the File Pointer ------------------------------------------------------------------------ Origin Fileio.ch Description ------------------------------------------------------------------------ 0 FS_SET Seek from beginning of file 1 FS_RELATIVE Seek from the current pointer position 2 FS_END Seek from end of file ------------------------------------------------------------------------ |
FSEEK() returns the new position of the file pointer relative to the beginning of file (position 0) as an integer numeric value. This value is without regard to the original position of the file pointer.
FSEEK() is a low-level file function that moves the file pointer forward or backward in an open binary file without actually reading the contents of the specified file. The beginning position and offset are specified as function arguments, and the new file position is returned. Regardless of the function arguments specified, the file pointer cannot be moved beyond the beginning or end of file boundaries.
Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.
This example uses FSEEK() to determine the length of a file by seeking from the end of file. Then, the file pointer is reset to the beginning of file: #include "Fileio.ch" // // Open the file read-only IF (nHandle := FOPEN("Temp.txt")) >= 0 // // Get length of the file nLength := FSEEK(nHandle, 0, FS_END) // // Reset file position to beginning of file FSEEK(nHandle, 0) FCLOSE(nHandle) ELSE ? "File open error:", FERROR() ENDIF This pseudofunction positions the file pointer at the last byte in a binary file: #define FileBottom(nHandle); (FSEEK(nHandle, 0, FS_END)) This pseudofunction positions the file pointer at the first byte in a binary file: #define FileTop(nHandle); (FSEEK(nHandle, 0)) This pseudofunction reports the current position of the file pointer in a specified binary file: #define FilePos(nHandle); (FSEEK(nHandle, 0, FS_RELATIVE))
FT_DFCLOSE() -> NIL
No arguments
Closes the file opened by FT_DFSETUP()
@ 4,9 TO 11,71 FT_DFSETUP("test.txt", 5, 10, 10, 70, 1, 7, 15,; "AaBb" + Chr(143), .T., 5, 132, 4096) cKey = FT_DISPFILE() FT_DFCLOSE() @ 20,0 SAY "Key that terminated FT_DISPFILE() was: " + '[' + cKey + ']'
FT_DFSETUP( <cInFile>, <nTop>, <nLeft>, <nBottom>, <nRight>, ; <nStart>, <nCNormal>, <nCHighlight>, <cExitKeys>, ; <lBrowse>, <nColSkip>, <nRMargin>, <nBuffSize> ) -> nResult
<cInFile> | - text file to display (full path and filename) |
<nTop> | - upper row of window |
<nLeft> | - left col of window |
<nBottom> | - lower row of window |
<nRight> | - right col of window |
<nStart> | - line to place highlight at startup |
<nCNormal> | - normal text color (numeric attribute) |
<nCHighlight> | - text highlight color (numeric attribute) |
<cExitKeys> | - terminating key list (each byte of string is a |
key code) | |
<lBrowse> | - act-like-a-browse-routine flag |
<nColSkip> | - col increment for left/right arrows |
<nRMargin> | - right margin - anything to right is truncated |
<nBuffSize> | - size of the paging buffer |
0 if successful, FError() code if not
Note: make sure you allocate a buffer large enough to hold enough data for the number of lines that you have in the window. Use the following formula as a guideline:
buffer size = (# of line) + 1 * RMargin
This is the smallest you should make the buffer. For normal use, 4096 bytes is recommended
@ 4,9 TO 11,71 FT_DFSETUP("test.txt", 5, 10, 10, 70, 1, 7, 15,; "AaBb" + Chr(143), .T., 5, 132, 4096) cKey = FT_DISPFILE() FT_DFCLOSE() @ 20,0 SAY "Key that terminated FT_DISPFILE() was: " + '[' + cKey + ']'
FT_FAPPEND( [ < nLines > ] ) -> NIL
lSuccess. If FALSE, check ^bft_fError()^n for the error code.
This function appends a line of text to the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair. The record pointer is moved to the last appended record.
Multiple lines may be appended with one call to FT_FAPPEND().
A text file "record" is a line of text terminated by a CRLF pair. Each line appended with this function will be empty.
NOTE: Occasionally a text file may contain a non-CRLF terminated line, at the end of the file ("stragglers"). This function assumes these stragglers to be the last line of the file, and begins appending the new lines after this line. In other words, if the last line in the text file is not terminated with a CRLF pair prior to calling FT_FAPPEND(), the function will terminate that last line before appending any new lines.
// add a blank line of text to a file FT_FUSE( "test.txt" ) ?FT_FRECNO() // displays 5 FT_FAPPEND() ?FT_FRECNO() // displays 6
FT_FBOF() -> lResult
No arguments
.T. if an attempt was made to skip past the first record of the currently selected text file, otherwise .F.
This function is similar to the CLIPPER Bof() function.
A text file "record" is a line of text terminated by a CRLF pair.
FT_FUSE( "FTTEXT.C" ) FT_FGOTOP() ? FT_FBOF() // .F. FT_FSKIP(-1) ? FT_FBOF() // .T.
FT_FDELETE( [ < nLines > ] ) -> lSuccess
No arguments
TRUE if successful, otherwise check ^ft_fError()^n for error code.
This function deletes one or several lines of text from the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair. The record pointer is not moved, unless the deleted lines occur at the end of the file, in which case ^bft_fRecno()^n will equal ^bft_fLastRe()^n and ^bft_fEOF()^n will be set to TRUE.
// delete the next 4 lines from a file FT_FUSE( "test.txt" ) FT_FDELETE( 4 )
FT_FEOF() -> lResult
No arguments
.T. if an attempt was made to skip past the last record of the currently selected text file, otherwise .F.
This function is similar to the CLIPPER Eof() function.
A text file "record" is a line of text terminated by a CRLF pair.
FT_FUSE( "FTTEXT.C" ) ? FT_FEOF() // .F. FT_FSKIP() ? FT_FEOF() // .T.
FT_FERROR() -> nErrorNo
No arguments
The DOS error code if one occurred. See a reference on DOS error codes for an explanation of what the code means.
This function returns the DOS error code associated with a file operation on the currently selected text file.
Errors could stem from any open, create, read or write operation, among others.
if ft_fUse( "text.c" ) < 0 // open text file err := ft_fError(); QOUT( 'Error opening file "Text.c", error code (' + ; LTRIM( STR( err ) ) + ')' ) endif
FT_FGOBOT() -> NIL
No arguments
This function moves the record pointer to the last record of the file in the currently selected text file workarea.
If a read error occurs ^ft_fError()^n will contain the error code.
A text file "record" is a line of text terminated by a CRLF pair.
// read last line FT_FUSE( "text.c" ) FT_FGOBOT() ? FT_FREADLN()
FT_FGOTO( nLine ) -> NIL
This function moves the record pointer to a specific record in the file in the currently selected text file workarea. If the record number requested is greater than the number of records in the file, the record pointer will be positioned at the last record.
Internally, the function operates differently depending on how you invoke it. Passing a value for ^b<nLine>^n results in what is effectively a skip operation, which is fairly quick. However if you pass 0 for ^b<nLine>^n, e.g. ft_fGoTo( 0 ), the function internally goes to the top of the file, then skips down the required number of records. Hence if your file is relatively large and the current record is a high number, you may see some delay as ft_fGoTo(0) skips through the file.
A text file "record" is a line of text terminated by a CRLF pair.
// read 5th line of text from file ft_fUse( "FTTEXT.C" ) ft_fGoTo(5) cText := ft_fReadLN()
FT_FGOTOP() -> NIL
No arguments
This function moves the record pointer to the first record in the currently selected text file workarea.
A text file "record" is a line of text terminated by a CRLF pair.
FT_FUSE( "text.c" ) // open text file DO WHILE !FT_FEOF() ? FT_FREADLN() // read thru file FT_FSKIP() ENDDO FT_FGOTOP() // go back to top ? FT_FRECNO() // 1
FT_FINSERT( [ < nLines > ] ) -> lSuccess
No arguments
^blSuccess^n is TRUE if the insert succeeded, FALSE if not. If false check the return value of ^bft_fError()^n for the reason.
This function inserts a line of text in the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair.
The record pointer is not moved.
A text file "record" is a line of text terminated by a CRLF pair. Each line inserted with this function will be empty.
// add a couple of blank lines of text to a file ft fUse( "test.txt" ) ft_fGoTo( 10 ) ft_fInsert( 5 )
FT_FLASTRE() -> nLastRecordNum
No arguments
An integer containing the number of records in the text file in the currently selected text file workarea, or zero if no file is currently open in the workarea.
This function returns the number of the last record in a text file.
A text file "record" is a line of text terminated by a CRLF pair.
FT_FUSE( "text.c" ) ? FT_FLASTRE()
FT_FREADLN() -> cLine
No arguments
A string containing the current record in a text file.
This function returns a line of text read from the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair. The record pointer is not moved.
Currently the maximum record size is 4096 characters. You may increase the maximum record size by changing the value of ^b#define ^bBUFFSIZE^n in the C source and recompiling, however you should consider the performance implications if you do (all read and writes use this buffer size, including ft_fSkip()'s and ft_fGoto()'s).
If a read error occurs ^ft_fError()^n will contain the error code.
A text file "record" is a line of text terminated by a CRLF pair.
// display each record of a text file FT_FUSE( "text.c" ) DO WHILE ! FT_FEOF() ? FT_FREADLN() FT_FSKIP() ENDDO
FT_FRECNO() -> nRecNo
No arguments
The current record number of a text file or 0 if no file is open.
This function returns the current record number of the file open in the currently selected text file workarea.
A text file "record" is a line of text terminated by a CRLF pair.
FT_FUSE( "text.c" ) // open text file DO WHILE !FT_FEOF() ? FT_FREADLN() // read thru file FT_FSKIP() ENDDO FT_FGOTOP() // go back to top ? FT_FRECNO() // 1
FT_FSELECT( [ <nNewArea> ] ) -> nPreviousArea
No arguments
The current selected text file area.
This function selects a text file "workarea" from 1 to 10. A file may or may not be open in the selected area.
Passing 0 for ^b<nNewArea>^n selects the next available workarea, similar to Clipper's SELECT 0 command. If no more workareas are available the current workarea is not changed.
Each file is opened in its own "workarea", similar to the concept used by dbf files. As provided, a maximum of 10 files (in 10 workareas) can be opened (assuming there are sufficient file handles available). That number may be increased by modifying the #define TEXT_WORKAREAS in the C source code and recompiling.
All the FT_F*() file functions operate on the file in the currently selected text file workarea.
Text file workareas are separate from and independent of Clipper's database workareas.
FT_FSELECT(1) nFile1 := FT_FUSE( "temp.c" ) ? FT_FLASTRE() // no. of lines in temp.c FT_FSELECT(2) nFile2 := FT_FUSE( "temp.h" ) ? FT_FLASTRE() // no. of lines in temp.h
FT_FSKIP( [ <nLines> ] ) -> nLinesSkipped
The number of lines actually skipped. If the file's EOF or BOF was encountered before ^b<nLines>^n could be skipped, the return value will be less than ^b<nLines>^n.
This function moves the text file record pointer, similar to the CLIPPER SKIP command.
Use the return value to determine how many records were actually skipped, for example to write a custom skipper function for TBrowse'g text files.
If a read error occurs ^ft_fError()^n will contain the error code.
A text file "record" is a line of text terminated by a CRLF pair.
// display each record of a text file FT_FUSE( "text.c" ) DO WHILE ! FT_FEOF() ? FT_FREADLN() FT_FSKIP() ENDDO
FT_FUSE( [ <cFile> ] [, <nMode> ] ) -> nHandle | 0
No arguments
If ^b<cFile>^n is passed and the file is opened successfully, an integer containing the text file's workarea. If the file cannot be opened, -1 will be returned. In this case, check the return value of ^bft_fError()^n for the cause of the error.
If FT_FUSE() is called without any arguments, it will close the text file in the current "text area" and return 0.
If a read error occurs ^ft_fError()^n will contain the error code.
The FT_F*() file functions are for reading text files, that is, files where each line (record) is delimited by a CRLF pair.
Each file is opened in its own "workarea", similar to the concept use by dbf files. As provided, a maximum of 10 files (in 10 workareas) can be opened (assuming there are sufficient file handles available). That number may be increased by modifying the #define TEXT_WORKAREAS in the C source code and recompiling.
#include "fileio.ch" // open a text file for reading ft_fUse( "text.txt" ) // open a text file for reading and writing ft_fUse( "text.txt", FO_READWRITE + FO_SHARED ) // close file ft_fUse()
FT_FWRITELN( < cData >, [ < lInsert > ] ) -> lSuccess
<cData> | is a string of data to write to the file at the current |
record position. | |
<lInsert> | is a logical indicating whether the contents |
of the current record are to be preserved, that is, if lInsert | |
evaluates to .T., the a new record is inserted at the current | |
position. The current record then is pushed down to FT_FRECNO()+1. | |
If lInsert is .F. or omitted, the current record is replaced by | |
cData. | |
TRUE if successful, otherwise check ^ft_fError()^n for error code.
This function writes a line of text to the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair. The record pointer is not moved.
The contents of the current record are updated to reflect the new new line written, unless the Insert option is selected.
Writing a null string has the effect of clearing the current line if in overstrike mode, else inserting a new line (same as FT_FINSERT()).
A text file "record" is a line of text terminated by a CRLF pair.
// write a line of text to a file FT_FUSE( "config.sys" ) DO WHILE UPPER( FT_FREADLN() ) != "FILES=" .AND. !F_FEOF() FT_FSKIP() ENDDO FT_FWRITELN( "FILES=30", FT_FEOF() )
FWRITE(<nHandle>, <cBuffer>, [<nBytes>]) --> nBytesWritten
<nHandle> | is the file handle obtained from FOPEN(), FCREATE(), or |
predefined by DOS. | |
<cBuffer> | is the character string to write to the specified file. |
<nBytes> | indicates the number of bytes to write beginning at the |
current file pointer position. If omitted, the entire content of | |
<cBuffer> | is written. |
FWRITE() returns the number of bytes written as an integer numeric value. If the value returned is equal to <nBytes>, the operation was successful. If the return value is less than <nBytes> or zero, either the disk is full or another error has occurred.
FWRITE() is a low-level file function that writes data to an open binary file from a character string buffer. You can either write all or a portion of the buffer contents. Writing begins at the current file position, and the function returns the actual number of bytes written.
If FWRITE() results in an error condition, FERROR() can be used to determine the specific error.
Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system
This example copies the contents of one file to another: #include "Fileio.ch" #define F_BLOCK 512 // cBuffer := SPACE(F_BLOCK) nInfile := FOPEN("Temp.txt", FO_READ) nOutfile := FCREATE("Newfile.txt", FC_NORMAL) lDone := .F. // DO WHILE !lDone nBytesRead := FREAD(nInfile, @cBuffer, F_BLOCK) IF FWRITE(nOutfile, cBuffer, nBytesRead) < ; nBytesRead ? "Write fault: ", FERROR() lDone := .T. ELSE lDone := (nBytesRead == 0) ENDIF ENDDO // FCLOSE(nInfile) FCLOSE(nOutfile)
OUTERR(<exp list>) --> NIL
OUTERR() always returns NIL.
OUTERR() is identical to OUTSTD() except that it writes to the standard error device rather than the standard output device. Output sent to the standard error device bypasses the xClipper console and output devices as well as any DOS redirection. It is typically used to log error messages in a manner that will not interfere with the standard screen or printer output.
This example displays an error message along with the date and time of occurrence to the screen: OUTERR("File lock failure", DATE(), TIME())
OUTSTD(<exp list>) --> NIL
OUTSTD() always returns NIL.
OUTSTD() is a simple output function similar to QOUT() except that it writes to the STDOUT device (instead of to the xClipper console output stream). Programs with very simple output requirements (i.e., that perform no full-screen input or output) can use this function to avoid loading the terminal output subsystems. The header file Simplio.ch redefines the ? and ?? commands to use the OUTSTD() function.
Since OUTSTD() sends its output to the standard output device, the output can be redirected using the DOS redirection symbols (>, >, |). This lets you redirect output from a xClipper program to a file or pipe. Refer to your PC/MS-DOS documentation for more information about this operating system facility.
This example uses OUTSTD() to display a list of expressions: OUTSTD(Name, PADR(RTRIM(City) + "," + ; State, 20), ZipCode) This example redirects the output of a xClipper program to a new file using the DOS redirection operator (>): C>MYPROG > FILE.TXT