NAME

tty - general terminal interface

SYNOPSIS

#include <ioctl_p.h>

#include <termio_p.h>

DESCRIPTION

This entry describes the operation of an asynchronous communication port when used with the open(2P) , close(2P) , read(2P) , write(2P) , and ioctl(2P) system subroutines.

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:

INTR
(Rubout or ASCII DEL) generates an interrupt signal. The signal number, file descriptor of the communication line, and the ASCII DEL character will be sent. Normally, a process is forced to terminate, but arrangements may be made either to ignore the signal or to receive a trap to an agreed-upon location; see signal(2P).

QUIT
(Control-\ or ASCII FS) generates a quit signal. The signal number, file descriptor of the communication line, and the ASCII FS character will be sent. Its treatment is identical to the interrupt signal.

ERASE
(#) erases the preceding character. It will not erase beyond the start of a line, as delimited by a CR, EOF, or EOL character.

KILL
(@) deletes the entire line, as delimited by a CR, or EOF, character.

EOF
(Control-d or ASCII EOT) may be used to generate an end-of-file from a terminal. When received, all the characters waiting to be read are immediatly passed to the program, without waiting for a new-line, and the EOF is discarded. Thus, if there are no chracters waiting, which is to say EOF occured at the beginning of a line, zero characters will be passed back, which is the standard end-of-file indication.

NL
(ASCII LF) is the normal line delimiter. It can not be changed or escaped.

STOP
(Control-s or ASCII DC3) can be used to temporarily suspend output. It is useful with CRT terminals to prevent output from disappearing before it can be read. While output is suspended, STOP characters are ignored and not read.

START
(Control-q or ASCII DC1) is used to resume output which has been suspended by a STOP character. While output is not suspeneded, START characters can not be changed or escaped. The start/stop characters can not be changed or escaped.

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:

GETP
Get the parameters associated with the terminal and store them in the termio structure refernced by arg.

SETP
Set the parameters associated with the terminal once the output has drained from the structure referenced by arg.

STAT
Return the number of characters in the raw queue in the int referenced by cnt.

FILES

/dev/ttyX path name for terminal X.

SEE ALSO

open(2P) , close(2P) , read(2P) , write(2P) , and ioctl(2P)