From b67cd64e964a5dfe4c8212ae0430bb7fccc0c638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 23 Sep 2004 23:46:24 +0000 Subject: [PATCH] Almost rewrote the termios.h header file. It's now much cleaner than before. Removed the tcgetattr() macro; it's now a real function call again. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9049 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/posix/termios.h | 244 +++++++++++++++++----------------------- 1 file changed, 106 insertions(+), 138 deletions(-) diff --git a/headers/posix/termios.h b/headers/posix/termios.h index 35771adf9d..6914e75169 100644 --- a/headers/posix/termios.h +++ b/headers/posix/termios.h @@ -1,16 +1,29 @@ +/* +** Distributed under the terms of the Haiku License. +*/ #ifndef _TERMIOS_H_ #define _TERMIOS_H_ -/* -** Distributed under the terms of the OpenBeOS License. -*/ #include -#include -#define NCC 11 /* number of control characters */ -#define NCCS NCC +typedef unsigned long tcflag_t; +typedef unsigned char speed_t; +typedef unsigned char cc_t; + +#define NCCS 11 /* number of control characters */ + +struct termios { + tcflag_t c_iflag; /* input modes */ + tcflag_t c_oflag; /* output modes */ + tcflag_t c_cflag; /* control modes */ + tcflag_t c_lflag; /* local modes */ + char c_line; /* line discipline */ + speed_t c_ispeed; /* (unused) */ + speed_t c_ospeed; /* (unused) */ + cc_t c_cc[NCCS]; /* control characters */ +}; /* control characters */ #define VINTR 0 @@ -27,61 +40,29 @@ #define VSTOP 9 #define VSUSP 10 - -#define termio termios /* for old non-posix code */ - -typedef unsigned long tcflag_t; -typedef unsigned char speed_t; -typedef unsigned char cc_t; - -struct termios { - tcflag_t c_iflag; /* input modes */ - tcflag_t c_oflag; /* output modes */ - tcflag_t c_cflag; /* control modes */ - tcflag_t c_lflag; /* local modes */ - char c_line; /* line discipline */ - speed_t c_ixxxxx; /* (unused) */ - speed_t c_oxxxxx; /* (unused) */ - cc_t c_cc[NCC]; /* control chars */ -}; - - -struct winsize { /* for the TIOCGWINSZ ioctl */ - unsigned short ws_row; - unsigned short ws_col; - unsigned short ws_xpixel; - unsigned short ws_ypixel; -}; - - -/* - * c_iflag - input control modes - */ -#define IGNBRK 0x01 /* ignore breaks */ +/* c_iflag - input control modes */ +#define IGNBRK 0x01 /* ignore break condition */ #define BRKINT 0x02 /* break sends interrupt */ -#define IGNPAR 0x04 /* ignore chars with parity errors */ -#define PARMRK 0x08 /* marks parity errors */ +#define IGNPAR 0x04 /* ignore characters with parity errors */ +#define PARMRK 0x08 /* mark parity errors */ #define INPCK 0x10 /* enable input parity checking */ #define ISTRIP 0x20 /* strip high bit from characters */ #define INLCR 0x40 /* maps newline to CR on input */ -#define IGNCR 0x80 /* ignores carriage returns */ -#define ICRNL 0x100 /* maps CR to newlines on input */ -#define IUCLC 0x200 /* maps all upper case to lower */ -#define IXON 0x400 /* enables input SW flow control */ +#define IGNCR 0x80 /* ignore carriage returns */ +#define ICRNL 0x100 /* map CR to newline on input */ +#define IUCLC 0x200 /* map all upper case to lower */ +#define IXON 0x400 /* enable input SW flow control */ #define IXANY 0x800 /* any character will restart input */ -#define IXOFF 0x1000 /* enables output SW flow control */ +#define IXOFF 0x1000 /* enable output SW flow control */ - -/* - * c_oflag - output control modes - */ +/* c_oflag - output control modes */ #define OPOST 0x01 /* enable postprocessing of output */ -#define OLCUC 0x02 /* maps lowercase to uppercase */ -#define ONLCR 0x04 /* maps NL to CR-NL on output */ -#define OCRNL 0x08 /* maps CR to NL on output */ +#define OLCUC 0x02 /* map lowercase to uppercase */ +#define ONLCR 0x04 /* map NL to CR-NL on output */ +#define OCRNL 0x08 /* map CR to NL on output */ #define ONOCR 0x10 /* no CR output when at column 0 */ #define ONLRET 0x20 /* newline performs CR function */ -#define OFILL 0x40 /* uses fill characters for delays */ +#define OFILL 0x40 /* use fill characters for delays */ #define OFDEL 0x80 /* Fills are DEL, otherwise NUL */ #define NLDLY 0x100 /* Newline delays: */ #define NL0 0x000 @@ -106,13 +87,11 @@ struct winsize { /* for the TIOCGWINSZ ioctl */ #define FF0 0x0000 #define FF1 0x8000 -/* - * c_cflag - control modes - */ +/* c_cflag - control modes */ #define CBAUD 0x1F /* line speed definitions */ -#define B0 0x00 -#define B50 0x01 +#define B0 0x00 /* hang up */ +#define B50 0x01 /* 50 baud */ #define B75 0x02 #define B110 0x03 #define B134 0x04 @@ -134,12 +113,12 @@ struct winsize { /* for the TIOCGWINSZ ioctl */ #define CSIZE 0x20 /* character size */ #define CS5 0x00 /* only 7 and 8 bits supported */ -#define CS6 0x00 -#define CS7 0x00 +#define CS6 0x00 /* Note, it was not very wise to set all of these */ +#define CS7 0x00 /* to zero, but there is not much we can do about it*/ #define CS8 0x20 #define CSTOPB 0x40 /* send 2 stop bits, not 1 */ -#define CREAD 0x80 /* enables receiver */ -#define PARENB 0x100 /* xmit parity enable */ +#define CREAD 0x80 /* enable receiver */ +#define PARENB 0x100 /* parity enable */ #define PARODD 0x200 /* odd parity, else even */ #define HUPCL 0x400 /* hangs up on last close */ #define CLOCAL 0x800 /* indicates local line */ @@ -148,50 +127,67 @@ struct winsize { /* for the TIOCGWINSZ ioctl */ #define RTSFLOW 0x4000 /* enable RTS flow */ #define CRTSCTS (RTSFLOW | CTSFLOW) -/* - * c_lflag - local modes - */ -#define ISIG (0x01) /* enable signals */ -#define ICANON (0x02) /* Canonical input */ -#define XCASE (0x04) /* Canonical u/l case */ -#define ECHO (0x08) /* Enable echo */ -#define ECHOE (0x10) /* Echo erase as bs-sp-bs */ -#define ECHOK (0x20) /* Echo nl after kill */ -#define ECHONL (0x40) /* Echo nl */ -#define NOFLSH (0x80) /* Disable flush after int or quit */ -#define TOSTOP (0x100) /* stop bg processes that write to tty */ -#define IEXTEN (0x200) /* implementation defined extensions */ +/* c_lflag - local modes */ +#define ISIG 0x01 /* enable signals */ +#define ICANON 0x02 /* Canonical input */ +#define XCASE 0x04 /* Canonical u/l case */ +#define ECHO 0x08 /* Enable echo */ +#define ECHOE 0x10 /* Echo erase as bs-sp-bs */ +#define ECHOK 0x20 /* Echo nl after kill */ +#define ECHONL 0x40 /* Echo nl */ +#define NOFLSH 0x80 /* Disable flush after int or quit */ +#define TOSTOP 0x100 /* stop bg processes that write to tty */ +#define IEXTEN 0x200 /* implementation defined extensions */ -/* - * Event codes. Returned from TCWAITEVENT - */ +/* options to tcsetattr() */ +#define TCSANOW 0x01 /* make change immediate */ +#define TCSADRAIN 0x02 /* drain output, then change */ +#define TCSAFLUSH 0x04 /* drain output, flush input */ + +/* actions for tcflow() */ +#define TCOOFF 0x01 /* suspend output */ +#define TCOON 0x02 /* restart output */ +#define TCIOFF 0x04 /* transmit STOP character, intended to stop input data */ +#define TCION 0x08 /* transmit START character, intended to resume input data */ + +/* values for tcflush() */ +#define TCIFLUSH 0x01 /* flush pending input */ +#define TCOFLUSH 0x02 /* flush untransmitted output */ +#define TCIOFLUSH 0x03 /* flush both */ + + +/* ioctl() identifiers to control the TTY */ +#define TCGETA 0x8000 +#define TCSETA (TCGETA + 1) +#define TCSETAF (TCGETA + 2) +#define TCSETAW (TCGETA + 3) +#define TCWAITEVENT (TCGETA + 4) +#define TCSBRK (TCGETA + 5) +#define TCFLSH (TCGETA + 6) +#define TCXONC (TCGETA + 7) +#define TCQUERYCONNECTED (TCGETA + 8) +#define TCGETBITS (TCGETA + 9) +#define TCSETDTR (TCGETA + 10) +#define TCSETRTS (TCGETA + 11) +#define TIOCGWINSZ (TCGETA + 12) /* pass in a struct winsize */ +#define TIOCSWINSZ (TCGETA + 13) /* pass in a struct winsize */ +#define TCVTIME (TCGETA + 14) /* pass in bigtime_t, old value saved */ + +/* Event codes. Returned from TCWAITEVENT */ #define EV_RING 0x0001 #define EV_BREAK 0x0002 #define EV_CARRIER 0x0004 #define EV_CARRIERLOST 0x0008 -/* - * These are ioctl identifiers to control the serial driver. - */ -#define TCGETA (0x8000) -#define TCSETA (TCGETA+1) -#define TCSETAF (TCGETA+2) -#define TCSETAW (TCGETA+3) -#define TCWAITEVENT (TCGETA+4) -#define TCSBRK (TCGETA+5) -#define TCFLSH (TCGETA+6) -#define TCXONC (TCGETA+7) -#define TCQUERYCONNECTED (TCGETA+8) -#define TCGETBITS (TCGETA+9) -#define TCSETDTR (TCGETA+10) -#define TCSETRTS (TCGETA+11) -#define TIOCGWINSZ (TCGETA+12) /* pass in a struct winsize */ -#define TIOCSWINSZ (TCGETA+13) /* pass in a struct winsize */ -#define TCVTIME (TCGETA+14) /* pass in bigtime_t, old val saved */ +/* for TIOCGWINSZ */ +struct winsize { + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; + unsigned short ws_ypixel; +}; -/* - * Bits for the TCGETBITS control - */ +/* Bits for the TCGETBITS control */ #define TCGB_CTS 0x01 #define TCGB_DSR 0x02 #define TCGB_RI 0x04 @@ -202,46 +198,18 @@ struct winsize { /* for the TIOCGWINSZ ioctl */ extern "C" { #endif -#define tcgetattr(f, t) ioctl(f, TCGETA, (char *)t) - -extern speed_t cfgetispeed( const struct termios *); -extern speed_t cfgetospeed( const struct termios *); -extern int cfsetispeed( struct termios *, speed_t); -extern int cfsetospeed( struct termios *, speed_t); -extern int tcsetattr( int fd, int opt, const struct termios *tp); - -/* - * Options to tcsetattr() - */ -#define TCSANOW 0x01 /* make change immediate */ -#define TCSADRAIN 0x02 /* drain output, then change */ -#define TCSAFLUSH 0x04 /* drain output, flush input */ - - -int tcsendbreak(int fd, int duration); -int tcdrain(int fd); -int tcflow(int fd, int action); - -/* - * Actions for tcflow() - */ -#define TCOOFF 0x01 -#define TCOON 0x02 -#define TCIOFF 0x04 -#define TCION 0x08 - - -int tcflush(int fd, int queue_selector); - -/* - * Values for "queue_selector" in tcflush() - */ -#define TCIFLUSH 0x01 -#define TCOFLUSH 0x02 -#define TCIOFLUSH (TCIFLUSH | TCOFLUSH) - -int tcsetpgrp(int fd, pid_t pgrpid); -pid_t tcgetpgrp(int fd); +extern speed_t cfgetispeed(const struct termios *termios); +extern speed_t cfgetospeed(const struct termios *termios); +extern int cfsetispeed(struct termios *termios, speed_t speed); +extern int cfsetospeed(struct termios *termios, speed_t speed); +extern int tcgetattr(int fd, struct termios *termios); +extern int tcsetattr(int fd, int option, const struct termios *termios); +extern int tcsendbreak(int fd, int duration); +extern int tcdrain(int fd); +extern int tcflow(int fd, int action); +extern int tcflush(int fd, int queueSelector); +extern int tcsetpgrp(int fd, pid_t pgrpid); +extern pid_t tcgetpgrp(int fd); #ifdef __cplusplus }