#include <termio_p.h>
A terminal operates in full-duplex mode. Characters may be typed at any time, even while output is occurring, and are only lost when the system's character input buffers become completely full, which is rare, or when the user has accumulated the maximum allowed number of input characters that have not yet been read by some program. Currently, this limit is 256 characters. When the input limit is reached, all the saved characters are thrown away without notice.
Normally, terminal input is processed in units of lines. A line is delinited by a new-line (ASCII LF) character or an end-of-file (ASCII EOT) character. This means that a program attempting to read will be suspended until an entire line has been typed. Also, no matter how many character are requested in the read call, at most one line will be returned. It is not, however, necessary to read a whole line at once; any number of characters may be requested in a read, even one, without losing information.
During input, erase and kill processing is normally done. By default, the character # erases the last character typed, except that it will not erase beyond the beginning of the line. By default, the character @ kills (deletes) the entire input line, and ouputs a new-line character. Both these characters operate on a key-stroke basis, independently of any backspacing or tabbing that may have been done. Both the erase and kill characters may be entered literally by preceding them with the escape character (\). In this case the escape character is not read. The erase and kill characters may be changed.
Certain characters have special functions on input. These functions and their default character values are summarized as follows:
The character values for ERASE, and KILL, may be changed to suit individual tastes. The ERASE, and KILL characters may be escaped by a preceding \ character, in which case no special function is done.
When one or more characters are written, they are transmitted to the terminal as soon as previously-written characters have finished typing. Input characters are echoed by putting them in the ouput queue as they arrive. If a process produces characters more rapidly than they can be typed, it will be suspended when its output queue exceeds some limit. When the queue has drained down to some threshold, the program is resumed.
Several iotcl(2P) system calls apply to terminal files. THe primary calls use the following structure, defined in termio_p.h:
struct termio { char c_erase; char c_kill; short c_flags; int (*c_iproc)(); };The c_flags field describes the basic terminal control:
TTYCHAR 0000001 Signal SIGCHAR on every character. TTYLINE 0000002 Signal SIGLINE on every line termination. RAW 0000004 Raw character input. ECHO 0000010 Echo input characters. TANDEM 0000020 Automatic flow control.If TTYCHAR is set, input of any character will generate a SIGCHAR signal. The signal number, file descriptor of the communication line, and the character causing the interrupt will be passed to the user.
If TTYLINE is set, a NL or EOF character will generate SIGLINE signal. The signal number, file descriptor of the communication line, and the number of characters in the raw queue will be passed to the user.
If RAW is set, all eight bits of every character are passed to the program. INTR, QUIT, ERASE, KILL, EOF, NL, STOP, and START have no special meaning and are passed along to the program without special functions.
If ECHO is set, characters are echoed as received.
TANDEM mode causes the system to produce a stop character (default control-s) whenver the input queue is in danger of overflowing, and a start character (default control q) when the input queue has drained sufficiently.
The c_iproc field allows the user to provide their own function for processing input characters in a nonstandard way.
The iotcl(2P) system calls have the form:
ioctl (fildes, command, arg) struct termio *arg; ioctl (fildes, command, cnt) int *cnt;where command can be one of: