UNITS - default I/O units and how to use I/O units.

Description:

A B program may have several files open for reading or writing at the same time. Each file is associated with a number called a "unit", to which every I/O call implicitly or explicitly refers.

Predefined Units:

There are five units whose function is predefined and may not be altered by the user.

-5
is an input unit whose origin is always the terminal in TSS or file code I* in batch. It may be used to force reading from the terminal or file code I*, even though the standard input may have been redirected to come from a file. Normally, you should use unit zero instead.
-4
is an output unit whose destination is always the terminal in TSS or file code P* in batch. It is most often used to avoid possible redirection of I/O by forcing error messages to appear on a hard copy device. Normally you should use unit one instead.
-3
is used for primary console input in batch only.
-2
is used for primary console output in batch only.
-1
In TSS, all output directed to this unit behaves as if it were typed at command level. In batch, output to unit -1 goes to the execution report.

Units Zero and One:

Unit zero is initialized as the standard input unit. In TSS, this is the terminal but input may come from a file if redirection of I/O is used. In batch, reads on unit zero come from file code I*, if it is defined and if input was not redirected. If I* is not present and there is no input redirection, unit zero is defined to be a null device (RD.NULL).

Similarly, unit one is initialized as the standard output unit. In TSS, this is again the terminal and is subject to redirection of I/O. In batch, output to unit one goes to the printer, unless redirected.

Free Units:

Units two through 49 may be assigned by or to you, using the file opening call. These units are usually used for permanent or temporary disk files. It is permissible to open units zero or one, but the usual practice is to leave them alone so they may be redirected.

You may assign these units numbers yourself and direct OPEN to initialize a specific unit, or you can let OPEN choose a free unit for you. If you choose a unit that is already open, OPEN will "push down" the current meaning of that unit and it will remain hidden until the unit is closed.

Use of Unit Numbers:

Before any I/O can be done to a unit, it must first be opened with an initializing call to OPEN. This assigns buffer space, sets up internal tables, and accesses and rewinds files as appropriate. Note that units -5 through 1 have been opened before your program receives control. After all I/O has been done on a unit, the unit must be closed by a call to CLOSE. This flushes buffers, frees space, writes end of files, and deaccesses files as appropriate. EXIT will attempt to close any units open at the time it is called, but it is good practice not to depend on this. If you open a unit, you should close it when you are done.

Between the initializing OPEN and the terminating CLOSE there are a number of functions that may be called to act on an open unit. Many of these take an explicit unit number that specifies which unit they are to be applied to. Some of them do not, and instead use the "current read unit" or the "current write unit". Others have optional unit numbers; if these are omitted, they assume the "current read or write unit" as a default. These current unit numbers may be tested and/or set by the functions .READ and .WRITE. The current units are also normally set by a call to OPEN.

Copyright © 1996, Thinkage Ltd.