/*
 * $Header: /smsa/bsd:include/termios.h:bsd  1.13  $
 * $Source: /smsa/bsd:include/termios.h: $
 *
 * Copyright (c) 1989 Acorn Computers Ltd., Cambridge, England
 */

#ifndef __termios_h
#define __termios_h

typedef unsigned short tcflag_t;
typedef unsigned char cc_t;
typedef unsigned int speed_t;

/* Indices into c_cc array.  Default values in parentheses. POSIX Table 7-5. */
/* Extended functions (IEXTEN set) are defined on chars marked + */
#define VERASE		0	/* (DEL) erase last character */
#define VKILL		1	/* (CTRL-U) erase entire line */
#define VINTR		2	/* (CTRL-C) interrupt */
#define VQUIT		3	/* (CTRL-\) quit */
#define VSTART		4	/* (CTRL-Q) start output */
#define VSTOP		5	/* (CTRL-S) stop output */
#define VEOF		6	/* (CTRL-D) end-of-file */
#define VEOL		7	/* (DISABLED) alternate input delimiter */
#define VSUSP		8	/* (CTRL-Z) stop process signal */
#define VMIN		9	/* (1) input character count */
#define VTIME		10	/* (0) input timeout (0.1sec units) */
#define VDSUSP		11	/*+(CTRL-Y) delayed stop process signal */
#define VREPRINT	12	/*+(CTRL-R) reprint line */
#define VDISCARD	13	/*+(CTRL-O) flush output (toggles) */
#define VWERASE		14	/*+(CTRL-W) word erase */
#define VLNEXT		15	/*+(CTRL-V) literal next character */

#define NCCS		16	/* size of cc_c array */

/* Primary terminal control structure.  POSIX Table 7-1. */
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 */
    unsigned char c_ispeed;	/* input baud rate */
    unsigned char c_ospeed;	/* output baud rate */
    cc_t c_cc[NCCS];		/* control characters */
    unsigned char c_line;	/* line discipline # */
    unsigned char c_xxxx;	/* reserved */
};

/* Values for termios c_iflag bit map.  POSIX Table 7-2. */
#define BRKINT		0x0001	/* signal interrupt on break */
#define ICRNL		0x0002	/* map CR to NL on input */
#define IGNBRK		0x0004	/* ignore break */
#define IGNCR		0x0008	/* ignore CR */
#define IGNPAR		0x0010	/* ignore characters with parity errors */
#define INLCR		0x0020	/* map NL to CR on input */
#define INPCK		0x0040	/* enable input parity check */
#define ISTRIP		0x0080	/* mask off 8th bit */
#define IXOFF		0x0100	/* enable start/stop input control */
#define IXON		0x0200	/* enable start/stop output control */
#define PARMRK		0x0400	/* mark parity errors in the input queue */
#ifndef	_POSIX_SOURCE
#define IUCLC		0x0800	/* map upper case to lower case on input */
#define IXANY		0x1000	/* enable any character to restart output */
#if defined(_XOPEN_C)
#define PENDIN		0x2000
#else
#define XOPEN_PENDIN	0x2000
#endif
#endif

/* Values for termios c_oflag bit map.  POSIX Sec. 7.1.2.3. */
#define OPOST		0x0001	/* perform output processing */
#ifndef	_POSIX_SOURCE
#define OLCUC		0x0002	/* map lower case to upper case on output */
#define ONLCR		0x0004	/* map NL to CR-NL on output */
#define OCRNL		0x0008	/* map CR to NL on output */
#define ONOCR		0x0010	/* no CR output at column 0 */
#define ONLRET		0x0020	/* NL performs CR function */
#define OFILL		0x0040	/* use fill characters for delay */
#define OFDEL		0x0080	/* fill is DEL, else NUL */

/* Delay values and baud rates are common with <sys/ioctl.h>, <sys/ttydev.h> */
#define NLDLY		0x0100	/* select newline delays */
#define		NL0	0x0000
#define		NL1	0x0100	/* tty 37 */
#define VTDLY		0x0200	/* select vertical-tab delays */
#define		VT0	0x0000	/* vertical-tab delays type 0 */
#define		VT1	0x0200	/* vertical-tab delays type 1 */
#define TABDLY		0x0c00	/* select horizontal-tab delays */
#define		TAB0	0x0000
#define		TAB1	0x0400	/* tty 37 */
#define		TAB2	0x0800
#define		TAB3	0x0c00	/* horizontal-tab delays type 3 */
#define CRDLY		0x3000	/* select carriage-return delays */
#define		CR0	0x0000
#define		CR1	0x1000	/* tn 300 */
#define		CR2	0x2000	/* tty 37 */
#define		CR3	0x3000	/* concept 100 */
#define FFDLY		0x4000	/* select form-feed delays */
#define		FF0	0x0000
#define		FF1	0x4000	/* tty 37 */
#define BSDLY		0x8000	/* select backspace delays */
#define		BS0	0x0000
#define		BS1	0x8000
#endif/*_XOPEN_C

#ifndef(__sys_ttydev_h)
/* Values for the baud rate settings.  POSIX Table 7-6. */
#define B0		0
#define B50		1
#define B75		2
#define B110		3
#define B134		4
#define B150		5
#define B200		6
#define B300		7
#define B600		8
#define B1200		9
#define	B1800		10
#define B2400		11
#define B4800		12
#define B9600		13
#ifndef	_POSIX_SOURCE
#define EXTA		14
#define EXTB		15
#endif
#define B19200		14
#define B38400		15

/* Values for termios c_cflag bit map.  POSIX Table 7-3. */
#define CLOCAL		0x0001	/* ignore modem status lines */
#define CREAD		0x0002	/* enable receiver */
#define CSIZE		0x000c	/* number of bits per character */
#define    CS5		0x0000	/* if CSIZE is CS5, characters are 5 bits */
#define    CS6		0x0004	/* if CSIZE is CS6, characters are 6 bits */
#define    CS7		0x0008	/* if CSIZE is CS7, characters are 7 bits */
#define    CS8		0x000c	/* if CSIZE is CS8, characters are 8 bits */
#define CSTOPB		0x0010	/* send 2 stop bits if set, else 1 */
#define HUPCL		0x0020	/* hang up on last close */
#define PARENB		0x0040	/* enable parity on output */
#define PARODD		0x0080	/* use odd parity if set, else even */
/* BSD compatibility flags */
#define _MDMBUF		0x0100  /* use modem line for flow ctl */
#define _TTXCLUDE	0x0200  /* no more opens on tty allowed */
#define _POSIXLOCK	0x0400  /* lock into POSIX line discipline (temp) */
#define _NOHANG		0x0800  /* Don't send SIGHUP on modem drop */

/* Values for termios c_lflag bit map.  POSIX Table 7-4. */

#if defined(_XOPEN_C) || defined(_POSIX_SOURCE)
#define ECHO 		0x0001	/* enable echoing of input characters */
#else
#define XOPEN_ECHO	0x0001	/* enable echoing of input characters */
#endif
#define ECHOE		0x0002	/* echo ERASE as backspace */
#define ECHOK		0x0004	/* echo KILL */
#define ECHONL		0x0008	/* echo NL */
#ifndef	_POSIX_SOURCE
#define ECHOCTL		0x0010	/*+echo ctrl chars as e.g. ^T */
#endif
#define ICANON		0x0020	/* canonical input (erase and kill enabled) */
#define IEXTEN		0x0040	/* enable extended functions */
#define ISIG		0x0080	/* enable signals */
#if defined(_XOPEN_C) || defined(_POSIX_SOURCE)
#define NOFLSH		0x0100	/* disable flush after interrupt or quit */
#define TOSTOP		0x0200	/* send SIGTTOU (job control) */
#else
#define XOPEN_NOFLSH	0x0100	/* disable flush after interrupt or quit */
#define XOPEN_TOSTOP	0x0200	/* send SIGTTOU (job control) */
#endif
#ifndef	_POSIX_SOURCE
#define XCASE		0x0400	/* Canonical upper/lower presentation */
#define ECHOPRT		0x0800	/*+rubout mode for hard-copy devices */
#define ECHOKE		0x1000  /*+kill line with BS SP BS */
#if defined(_XOPEN_C)
#define FLUSHO		0x2000  /*+flush output (really a state bit!) */
#else
#define XOPEN_FLUSHO	0x2000
#endif
#endif
#define _MAPTILDE	0x4000  /*+map ~ into ` on output (BSD compat) */
#define _NOEOT		0x8000  /*+don't send EOT in normal mode (BSD compat) */

/* Optional actions for tcsetattr().  POSIX Sec. 7.2.1.2. */
#define TCSANOW		1	/* changes take effect immediately */
#define TCSADRAIN	2	/* changes take effect after output is done */
#define TCSAFLUSH	3	/* wait for output to finish and flush input */

/* Queue_selector values for tcflush().  POSIX Sec. 7.2.2.2. */
#define TCIFLUSH	1	/* flush accumulated input data */
#define TCOFLUSH	2	/* flush accumulated output data */
#define TCIOFLUSH	3	/* flush accumulated input and output data */

/* Action values for tcflow().  POSIX Sec. 7.2.2.2. */
#define TCOOFF		1	/* suspend output */
#define TCOON		2	/* restart suspended output */
#define TCIOFF		3	/* transmit a STOP character on the line */
#define TCION		4	/* transmit a START character on the line */

#ifndef	_KERNEL
speed_t cfgetospeed (struct termios *__termios_p);
int cfsetospeed (struct termios *__termios_p, speed_t __speed);
speed_t cfgetispeed (struct termios *__termios_p);
int cfsetispeed (struct termios *__termios_p, speed_t __speed);
int tcgetattr (int __filedes, struct termios *__termios_p);
int tcsetattr (int __filedes, int __opt_actions, struct termios *__termios_p);
int tcsendbreak (int __fildes, int __duration);
int tcdrain (int __filedes);
int tcflush (int __filedes, int __queue_selector);
int tcflow (int __filedes, int __action);
#endif

#endif/*__termios_h*/

/* EOF termios.h */
