Terminal device control

Canonical mode input processing

In canonical mode input processing, terminal input is processed in units of lines. A line is delimited by the new-line ('\n') character, end-of-file (EOF) character or end-of-line (EOL) character (see ``Special characters'' section below for more information on EOF and EOL).

Processing terminal input in units of lines means that a program attempting a read from a terminal-device-file is suspended until an entire line is typed, or a signal is received. Also, no matter how many bytes of data a read may request from a terminal-device-file, it transfers at most one line of input. It is not, however, necessary to read the entire line at once; a read may request any number of bytes of data, even one, without losing any data remaining in the line of input.

If MAX_CANON is defined for this terminal-device, it is a limit on the number of bytes in a line. The behavior of the system when this limit is exceeded is implementation-dependent. If MAX_CANON is not defined for this terminal-device, there is no such limit.

It should be noted that there is a possible inherent deadlock if the program and the implementation conflict on the value of MAX_CANON. With both ICANON and IXOFF set when more than MAX_CANON characters transmitted without a line-feed, transmission is stopped, the line-feed (or carriage-return if ICRLF is set) never arrives, and the read is never satisfied.

A program should never set IXOFF if it is using canonical-mode unless it knows that (even in the face of a transmission error) the conditions described previously cannot be met or unless it is prepared to deal with the possible deadlock in some other way, such as time-outs.

NOTE: This would only occur if the transmitting side was a communications device (for example, an asynchronous port). This normally will not happen since the transmitting side is a user at a terminal.

It should also be noted that this can be made to happen in non-canonical-mode if the number of characters received that would cause IXOFF to be sent is less than VMIN when VTIME equals zero.

In UNIX System V, if the data in the line-discipline buffer exceeds MAX_CANON in canonical mode and IMAXBEL is clear, all the bytes of data saved in the buffer up to that point are discarded without any notice, but if IMAXBEL is set and the data in the line-discipline buffer exceeds MAX_INPUT, the ASCII BEL character is echoed. Further input is not stored, and any data already present in the input-queue remains undisturbed.

During input, erase and kill processing occurs whenever either of two special characters, the ERASE and KILL characters is received (see ``Special characters''). This processing affects data in the input-queue that has yet to be delimited by a new-line, EOF or EOL character. This un-delimited data makes up the current line. The ERASE character deletes the last character (if any) in the current line; it does not erase beyond the beginning of the line. The KILL character deletes all data (if any) in the current line; it optionally outputs a new-line character. The ERASE and KILL characters have no effect if the current line lacks any data.

Both the ERASE and KILL characters operate on a key-stroke basis independently of any backspacing or tabbing. Typically, # is the default ERASE character, and @ is the default KILL character. The ERASE and KILL characters themselves are not placed in the input-queue.

Next topic: Non-canonical mode input processing
Previous topic: Input processing and reading data

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005