Libraries
Null_file Source Code
 previous   up   next 

Types
null_file
Base implementation type for the file interface.

null_file

const type: null_file

Base implementation type for the file interface. A null_file discards all data written to it. Reads from a null_file always yield EOF immediately. A null_file is not seekable. The functions length, seek and tell raise FILE_ERROR. The functions getc, getwd and getln are written such that a derived type can use them. Derived types of null_file need to override the functions write, gets, eof and hasNext. A derived type, which represents a seekable file, needs to override the functions length, seek and tell.


Variable Summary
null_file
STD_NULL
Standard null file.

Operator Summary
file
(attr file) . value
Default value of file (STD_NULL).

Function Summary
void
write (in null_file: outFile, in string: stri)
Write a string to a null_file.
void
writeln (inout null_file: outFile)
Write end-of-line to outFile.
void
writeln (inout null_file: outFile, in string: stri)
Write a string followed by end-of-line to outFile.
string
gets (in null_file: inFile, in integer: maxLength)
Read a string with a maximum length from a null_file.
char
getc (inout null_file: inFile)
Read a character from a null_file.
string
getTerminatedString (inout null_file: inFile, in char: terminator)
Read a string from inFile until the terminator character is found.
string
getwd (inout null_file: inFile)
Read a word from a null_file.
string
getln (inout null_file: inFile)
Read a line from a null_file.
boolean
eof (in null_file: inFile)
Determine the end-of-file indicator.
boolean
hasNext (in null_file: inFile)
Determine if at least one character can be read successfully.
integer
length (in null_file: aFile)
Obtain the length of a file.
boolean
seekable (in null_file: aFile)
Determine if the file aFile is seekable.
void
seek (in null_file: aFile, in integer: position)
Set the current file position.
integer
tell (in null_file: aFile)
Obtain the current file position.
void
close (in null_file: aFile)
Close a null_file.
void
flush (in null_file: aFile)
Forces that all buffered data is sent to its destination.

Variable Detail

STD_NULL

var null_file: STD_NULL

Standard null file. Anything written to STD_NULL is ignored. Reading from STD_NULL does not deliver data.

eof(STD_NULL)      returns TRUE
getc(STD_NULL)     returns EOF
gets(STD_NULL, 1)  returns ""

The file STD_NULL is used to initialize file variables and as result of open, if a file cannot be opened.


Operator Detail

. value

const file: (attr file) . value

Default value of file (STD_NULL).


Function Detail

write

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

Write a string to a null_file. The parameter stri is just ignored. Derived types of null_file need to override this function.


writeln

const proc: writeln (inout null_file: outFile)

Write end-of-line to outFile. This function writes the end-of-line marker '\n'. Derived types can use this function. If a derived type does not use '\n' as end-of-line marker it needs to override this function.


writeln

const proc: writeln (inout null_file: outFile, in string: stri)

Write a string followed by end-of-line to outFile. This function is based on write and writeln. Derived types can use this function. This function must be overridden, if it is necessary to write stri and '\n' together.


gets

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

Read a string with a maximum length from a null_file. Derived types of null_file need to override this function.

Returns:
the empty string ("").
Raises:
RANGE_ERROR - The parameter maxLength is negative.

getc

const func char: getc (inout null_file: inFile)

Read a character from a null_file. This function is based on the gets function. Therefore it is useable for derived types of null_file. For the null_file itself it always returns EOF.

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

getTerminatedString

const func string: getTerminatedString (inout null_file: inFile, in char: terminator)

Read a string from inFile until the terminator character is found. If a terminator is found the string before the terminator is returned and the terminator character is assigned to inFile.bufferChar. The file position is advanced after the terminator character. If no terminator is found the rest of inFile is returned and EOF is assigned to the inFile.bufferChar. When the function is left inFile.bufferChar contains either terminator or EOF. This function is based on the gets function. Therefore it is useable for derived types of null_file. For the null_file itself it always returns "" and assigns EOF to inFile.bufferChar.

Parameters:
inFile - File from which the string is read.
terminator - Character which terminates the string.
Returns:
the string read without the terminator or the rest of the file if no terminator is found.

getwd

const func string: getwd (inout null_file: inFile)

Read a word from a null_file. Before reading the word it skips spaces and tabs. The function accepts words ending with ' ', '\t', '\n' or EOF. The word ending characters are not copied into the string. When the function is left inFile.bufferChar contains ' ', '\t', '\n' or EOF. This function is based on the gets function. Therefore it is useable for derived types of null_file. For the null_file itself it always returns "" and assigns EOF to inFile.bufferChar.

Returns:
the word read.

getln

const func string: getln (inout null_file: inFile)

Read a line from a null_file. The function accepts lines ending with '\n' or EOF. The line ending characters are not copied into the string. When the function is left inFile.bufferChar contains '\n' or EOF. This function is based on the gets function. Therefore it is useable for derived types of null_file. For the null_file itself it always returns "" and assigns EOF to inFile.bufferChar.

Returns:
the line read.

eof

const boolean: eof (in null_file: inFile)

Determine the end-of-file indicator. Derived types of null_file need to override this function.

Returns:
TRUE, since a null_file is always at end-of-file.

hasNext

const boolean: hasNext (in null_file: inFile)

Determine if at least one character can be read successfully. Derived types of null_file need to override this function.

Returns:
FALSE, since the next getc will always return EOF.

length

const func integer: length (in null_file: aFile)

Obtain the length of a file. A null_file is not seekable, therefore FILE_ERROR is raised. Derived types of null_file need to override this function.

Returns:
nothing, because FILE_ERROR is always raised.
Raises:
FILE_ERROR - Is always raised, because a null_file is not seekable.

seekable

const boolean: seekable (in null_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:
FALSE, since a null_file is not seekable.

seek

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

Set the current file position. A null_file is not seekable, therefore FILE_ERROR is raised. If a derived type is seekable it needs to override this function.

Raises:
FILE_ERROR - Is always raised, because a null_file is not seekable.

tell

const func integer: tell (in null_file: aFile)

Obtain the current file position. A null_file is not seekable, therefore FILE_ERROR is raised. If a derived type is seekable it needs to override this function.

Returns:
nothing, because FILE_ERROR is always raised.
Raises:
FILE_ERROR - Is always raised, because a null_file is not seekable.

close

const proc: close (in null_file: aFile)

Close a null_file. Closing a null_file has no effect.


flush

const proc: flush (in null_file: aFile)

Forces that all buffered data is sent to its destination. Flushing a null_file has no effect.



 previous   up   next