Input / Output

OADL has a full-featured file input/output feature set. It supports both text-mode and binary-mode I/O, and supports pipes as well if the host operating system supports them. A full set of support routines for handing file positioning and errors is implemented.

Files

The base for OADL I/O is the File, which is an OADL handle to either a file that resides in the host operating system's file system, or a pipe to an external program. OADL defines three Files for program use:

io::Input
The standard input File. It might refer to the input console, or it might refer to a file or pipe if the host operating system supports redirection
io::Output
The standard output File. It might refer to the output console, or it might refer to a file or pipe if the host operating system supports redirection
io::ErrOut
The standard error output File. Again, its actual destination depends on operating system support.

Other files are associated with external file system or program resources via the new syntax:

file = new File(name, mode)

where name is the name of the external file or external program, and mode is the file mode.

Various queries and state management methods are provided for File handles:

file.binary()
Query whether file was opened in binary mode
file.clearerr()
Clears any error conditions found on file
file.close()
file.close(disp)
Close the given file. It is an error to access it after it is closed.
file.feof()
Query whether file is at the end-of-file
file.ferror()
Returns the operating system error status associated with file
file.fflush()
Flush any pending buffered output to file
file.fseek(offs, whence)
Change the read/write position of file
file.ftell()
Query the read/write position of file
file.getswab()
Query whether file is in automatic byte-swap mode
file.ispipe()
Query whether file was opened as a pipe
file.readonly()
Query whether file was opened read-only
file.rewind()
Reset the read/write position of file to the beginning-of-file
file.setswab(bSwab)
Sets the automatic byte-swap mode of file.


Formatted Input / Output

OADL supports the formatting and printing of values to ouput files, and the reading of formatted values from input files. The files must be text-mode; the input/output strings are translated from or to streams of UTF-8 sequences. The following intrinsic procedures and method perform formatted input and output:

print(fmtstring, arg, ...)
print(file, fmtstring, arg, ...)
file.print(fmtstring, arg, ...)
Format and print several values
read(fmtstring, typ, ...)
read(file, fmtstring, typ, ...)
file.read(fmtstring, typ, ...)
Read a formatted set of values of the specified types from a file
say(val,val,...)
say(file,val,val,...)
file.say(val val,...)
Print out values to a file using a default format.


Streaming Input / Output

These intrinsic procedures and methods operate character-at-a-time on the input / output files. They support both text-mode and binary-mode files. If used with unformatted files, they operate byte-at-a-time, which can lead to unexpected effects with WideChar values.

getchar()
getchar(file)
file.getchar()
Get a single character of input from a file
putchar(ch)
putchar(file, ch)
file.putchar(ch)
Put a single character to a file
ungetc(ch)
ungetc(file, ch)
file.ungetc(ch)
Return a single character to the file input buffer
readstr()
readstr(file)
file.readstr()
Read a single line of input into a string


OADL supports unformatted reading and writing of values to files. These files must be opened in binary-mode. The values may be byte-swapped on read and write; see setswab and getswab for more information.

read(file, typ, typ, ...)
file.read(typ, typ, ...)
Read binary values from a file
write(file, val, val, ...)
file.write(val, val, ...)
Write binary values to a file

Back to External Procedures

Continue to OADL Format Specifiers

Return to Introduction