Libraries
External_file Source Code
 previous   up   next 

Types
external_file
File implementation type describing OS files.

external_file

const type: external_file

File implementation type describing OS files. This type provides access to sequential operating system files. External files are seekable, therefore they support the functions length, seek and tell.


Function Summary
file
open (in string: path, in string: mode)
Opens a file with the specified path and mode.
void
close (inout external_file: aFile)
Close an external_file.
void
flush (in external_file: outFile)
Forces that all buffered data of outFile is sent to its destination.
void
write (in external_file: outFile, in string: stri)
Write a string to an external_file.
char
getc (in external_file: inFile)
Read a character from an external_file.
string
gets (in external_file: inFile, in integer: maxLength)
Read a string with a maximum length from an external_file.
string
getwd (inout external_file: inFile)
Read a word from an external_file.
string
getln (inout external_file: inFile)
Read a line from an external_file.
boolean
eof (in external_file: inFile)
Determine the end-of-file indicator.
boolean
hasNext (in external_file: inFile)
Determine if at least one character can be read successfully.
boolean
inputReady (in external_file: inFile)
Determine if at least one character can be read without blocking.
integer
length (in external_file: aFile)
Obtain the length of an external_file.
void
truncate (in external_file: aFile, in integer: length)
Truncate aFile to the given length.
boolean
seekable (in external_file: aFile)
Determine if the file aFile is seekable.
void
seek (in external_file: aFile, in integer: position)
Set the current file position.
integer
tell (in external_file: aFile)
Obtain the current file position.

Function Detail

open

const func file: open (in string: path, in string: mode)

Opens a file with the specified path and mode. There are text modes and binary modes:

  • Binary modes:
    • "r" Open file for reading.
    • "w" Truncate to zero length or create file for writing.
    • "a" Append; open or create file for writing at end-of-file.
    • "r+" Open file for update (reading and writing).
    • "w+" Truncate to zero length or create file for update.
    • "a+" Append; open or create file for update, writing at end-of-file.
  • Text modes:
    • "rt" Open file for reading.
    • "wt" Truncate to zero length or create file for writing.
    • "at" Append; open or create file for writing at end-of-file.
    • "rt+" Open file for update (reading and writing).
    • "wt+" Truncate to zero length or create file for update.
    • "at+" Append; open or create file for update, writing at end-of-file.

Note that this modes differ from the ones used by the C function fopen().

Parameters:
path - Path of the file to be opened. The path must use the standard path representation.
mode - Mode of the file to be opened.
Returns:
the file opened, or STD_NULL if it could not be opened or if path refers to a directory.
Raises:
MEMORY_ERROR - Not enough memory to convert the path to the system path type.
RANGE_ERROR - The mode is not one of the allowed values or path does not use the standard path representation or path cannot be converted to the system path type.

close

const proc: close (inout external_file: aFile)

Close an external_file.

Raises:
FILE_ERROR - A system function returns an error.

flush

const proc: flush (in external_file: outFile)

Forces that all buffered data of outFile is sent to its destination. This causes data to be sent to the file system of the OS.


write

const proc: write (in external_file: outFile, in string: stri)

Write a string to an external_file.

Raises:
FILE_ERROR - A system function returns an error.
RANGE_ERROR - The string contains a character that does not fit into a byte ('\0;' to '\255;' fit into a byte).

getc

const func char: getc (in external_file: inFile)

Read a character from an external_file.

Returns:
the character read, or EOF at the end of the file.

gets

const func string: gets (in external_file: inFile, in integer: maxLength)

Read a string with a maximum length from an external_file.

Returns:
the string read.
Raises:
RANGE_ERROR - The parameter maxLength is negative.
MEMORY_ERROR - Not enough memory to represent the result.
FILE_ERROR - A system function returns an error.

getwd

const func string: getwd (inout external_file: inFile)

Read a word from an external_file. Before reading the word it skips spaces and tabs. The function accepts words ending with ' ', '\t', '\n', "\r\n" or EOF. The word ending characters are not copied into the string. That means that the '\r' of a "\r\n" sequence is silently removed. When the function is left inFile.bufferChar contains ' ', '\t', '\n' or EOF.

Returns:
the word read.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.
FILE_ERROR - A system function returns an error.

getln

const func string: getln (inout external_file: inFile)

Read a line from an external_file. The function accepts lines ending with '\n', "\r\n" or EOF. The line ending characters are not copied into the string. That means that the '\r' of a "\r\n" sequence is silently removed. When the function is left inFile.bufferChar contains '\n' or EOF.

Returns:
the line read.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.
FILE_ERROR - A system function returns an error.

eof

const func boolean: eof (in external_file: inFile)

Determine the end-of-file indicator. The end-of-file indicator is set if at least one request to read from the file failed.

Returns:
TRUE if the end-of-file indicator is set, FALSE otherwise.

hasNext

const func boolean: hasNext (in external_file: inFile)

Determine if at least one character can be read successfully. This function allows a file to be handled like an iterator.

Returns:
FALSE if getc would return EOF, TRUE otherwise.

inputReady

const func boolean: inputReady (in external_file: inFile)

Determine if at least one character can be read without blocking. Blocking means that getc would wait until a character is received. Blocking can last for a period of unspecified length. Regular files do not block.

Returns:
TRUE if getc would not block, FALSE otherwise.

length

const func integer: length (in external_file: aFile)

Obtain the length of an external_file. The file length is measured in bytes.

Returns:
the size of the given file.
Raises:
RANGE_ERROR - The file length does not fit into an integer value.
FILE_ERROR - A system function returns an error or the file length reported by the system is negative.

truncate

const proc: truncate (in external_file: aFile, in integer: length)

Truncate aFile to the given length. If the file previously was larger than length, the extra data is lost. If the file previously was shorter, it is extended, and the extended part is filled with null bytes ('\0;').

Parameters:
aFile - File to be truncated.
length - Requested length of aFile in bytes.
Raises:
RANGE_ERROR - The requested length is negative or the length is not representable in the type used by the system function.
FILE_ERROR - A system function returns an error.

seekable

const func boolean: seekable (in external_file: aFile)

Determine if the file aFile is seekable. If a file is seekable the functions seek and tell can be used to set and and obtain the current file position.

Returns:
TRUE, if aFile is seekable, FALSE otherwise.

seek

const proc: seek (in external_file: aFile, in integer: position)

Set the current file position. The file position is measured in bytes from the start of the file. The first byte in the file has the position 1.

Raises:
RANGE_ERROR - The file position is negative or zero or the file position is not representable in the system file position type.
FILE_ERROR - A system function returns an error.

tell

const func integer: tell (in external_file: aFile)

Obtain the current file position. The file position is measured in bytes from the start of the file. The first byte in the file has the position 1.

Returns:
the current file position.
Raises:
RANGE_ERROR - The file position does not fit into an integer value.
FILE_ERROR - A system function returns an error or the file position reported by the system is negative.


 previous   up   next