delorie.com/djgpp/doc/libc/libc_816.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Termios functions

The termios functions allow to control terminals and asynchronous communications ports. The DJGPP implementation currently supports the termios functionality for console devices only. It does that by reading the keyboard via the BIOS Int 16h and writes to the screen via the direct output interrupt 29h. This I/O redirection is performed by the special hook internal to the library.

Many of the termios functions accept a termiosp argument which is a pointer to a struct termios variable. Here's the description of this structure:

 
 #define NCCS 12
 struct termios {
   cc_t	        c_cc[NCCS];  /* control characters */
   tcflag_t     c_cflag;     /* control modes */
   tcflag_t     c_iflag;     /* input modes */
   tcflag_t     c_lflag;     /* local modes */
   tcflag_t     c_oflag;     /* output modes */
   speed_t      c_ispeed;    /* input baudrate */
   speed_t      c_ospeed;    /* output baudrate */
 }

The array c_cc[] defines the special control characters. the following table lists the supported control functions the default characters which invoke those functions, and the default values for MIN and TIME parameters:

Index Name Function Default Value
1 VEOF Signal End-Of-Input Ctrl-D
2 VEOL Signal End-Of-Line [Disabled]
3 VERASE Delete previous character Backspace
4 VINTR Generate SIGINT Ctrl-C
5 VKILL Erase current line Ctrl-U
6 VMIN The MIN value 1
7 VQUIT Generate SIGQUIT Ctrl-\
8 VSTART Resume output Ctrl-Q
9 VSTOP Suspend output Ctrl-S
10 VSUSP Suspend program Ctrl-Z
11 VTIME TIME value 0

The special characters (like VEOL, VKILL, etc.) produce their effect only under the canonical input processing, that is, when the ICANON bit in the c_lflag member of struct termios (see below) is set. If ICANON is not set, all characters are processed as regular characters and returned to the caller; only the VMIN and VTIME parameters are meaningful in the non-canonical processing mode.

The VEOL character can be used to signal end of line (and thus end of input in the canonical mode) in addition to the normal RET key. In the non-canonical mode, input ends as soon as at least VMIN characters are received.

Note that the values of VMIN and VTIME are currently ignored; termios functions always work as if VMIN were 1 and VTIME were zero. Other parameters are supported (for console devices only), except that VSTOP and VSTART characters are not inserted to the input, but otherwise produce no effect.

The c_cflag member of struct termios describes the hardware terminal control, as follows:

Symbol Function
B0 Hang up
B50 50 baud
B75 75 baud
B110 110 baud
B134 134.5 baud
B150 150 baud
B200 200 baud
B300 300 baud
B600 600 baud
B1200 1200 baud
B1800 1800 baud
B2400 2400 baud
B4800 4800 baud
B9600 9600 baud
B19200 19200 baud
B38400 38400 baud
CSIZE Character size:
CS5 5-bit characters
CS6 6-bit characters
CS7 7-bit characters
CS8 8-bit characters
CSTOPB If set, send two stop bits
CREAD Enable reading
PARENB Enable parity
PARODD If set, use odd parity
HUPCL Hang up on last close
CLOCAL If set, line is local

Note that since the DOS terminal doesn't use asynchronous ports, the above parameters are always ignored by the implementation. The default value of c_cflag is (CS8|CREAD|CLOCAL).

The c_lflag member of struct termios defines the local modes that control the terminal functions:

Symbol Function
ISIG If set, enable signals SIGINT and SIGQUIT
ICANON If set, enable canonical input processing
ECHO If set, enable echoing
ECHOE Erase character deletes
ECHOK Output newline after the kill character
ECHONL Echo the newline
NOFLSH [Ignored]
TOSTOP [Ignored]
ECHOCTL Echo control characters as ^X
ECHOKE Erase killed line
IEXTEN [Ignored]

The default value of c_lflag is (ISIG|ICANON|ECHO|IEXTEN|ECHOE|ECHOKE|ECHOCTL).

The c_iflag member of struct termios describes the input control:

Symbol Function
IGNBRK Ignore Ctrl-BREAK
BRKINT Generate SIGINT on Ctrl-BREAK
IGNPAR [Ignored]
PARMRK [Ignored]
INPCK [Ignored]
ISTRIP Strip the 8th bit from input
INLCR Map NL to CR on input
IGNCR Ignore CR characters
ICRNL Map CR to NL on input
IXON [Ignored]
IXOFF Enable start/stop input control
IMAXBEL Ring the bell if input line too long

The default value of c_iflag is (BRKINT|ICRNL|IMAXBEL).

The c_oflag member of struct termios specifies the output handling:

Symbol Function
OPOST If not set, output characters verbatim
ONLCR Map newline to CR-LF pair on output
OCRNL Map CR to NL on output
ONOEOT Don't output EOT characters

Note that if the OPOST bit is not set, all the other flags are ignored and the characters are output verbatim. The default value of c_oflag is (OPOST|ONLCR|ONOEOT).

The c_ispeed and c_ospeed members specify, respectively, the input and output baudrate of the terminal. They are set by default to 9600 baud, but the value is always ignored by this implementation, since no asynchronous ports are used.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004