next up previous
Next: Miscellaneous Up: The Terminal Driver Previous: Lower-Half Output Routines

Lower-Half Input Processing

The input interrupt routine is far more complicated than the output interrupt routine because it has to implement the user interface functions. We shall study this routine by looking separately at the actions required to support the three modes: raw, cbreak, and cooked.

Raw Mode

In the raw mode, the terminal driver does not provide any user interface function, and passes the input characters directly to the process wihout any intermediate processing. The following steps are performed:

Extracts the character from RBUF.

If the input buffer is full, it throws away the character and returns.

If the input character has an error, puts the the error value 0200 in the buffer.

Otherwise inserts character into the buffer.

Signals the semaphore isem.

Cbreak Mode

Consider now the cbreak mode. The following steps distinguish it from the raw mode:

If the input character is a `normal' char, then it is put not only in the input queue but also the echo queue.

If the input character is a RETURN, then it converts it into a NEWLINE before putting it into the queues.* gif

If the input character is a stop or start output character, then an appropriate user parameter is changed, which is used by ttyoin. A start output character enables output interrupts..

Otherwise, the input character is put in the echo and input queues.

Cooked Mode

In the cooked mode, the erase and line-kill commands are available to users. These commands allow a user to perform line editing. Characters are made available to a program only when the user types a RETURN or NEWLINE. Thus a user may edit a line of characters before they are consumed by a program. We now look at the steps taken in this mode to support these commands:

A cursor is maintained to keep the count of the number of characters in the current line.

If the user inputs the erase character then the head of input buffer and the cursor are decremented and the last character echoed is erased..

If the user inputs the line-kill character then the head of the input buffer is adjusted and the cursor reset. Also the RETURN-NEWLINE combination is put in the echo queue..

If the user input the NEWLINE or RETURN character then the character is echoed, it is put in the input buffer, isem signalled (cursor + 1) times, and the line cursor set to 0.

If the user inputs a regular character, then the line cursor is incremented, and the character is put in the input buffer. Semaphore isem is not signalled.

Echoing Characters

The following steps are taken to put a character in an echo queue:

If the characters is either a NEWLINE or a RETURN the RETURN-NEWLINE combination is inserted in the echo queue.*

If the character is a control character (ascii value less than ascii of BLANK) or the del character, then a printable representation of 2 characters (followed by (char + 0100)) is stored.

Any other character is put directly into the echo queue.

Erasing Characters

Erasing a character is simple. Normally a backspace character is echoed. However if a terminal parameter says `erasing backspace' is supported, then, in addition, a blank followed by a back space is echoed. Care has to be taken to erase over the two character representation of control characters.


next up previous
Next: Miscellaneous Up: The Terminal Driver Previous: Lower-Half Output Routines



Prasun Dewan
Thu Feb 12 11:37:50 EST 2004