/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident	"$Header: termio.h 1.21 90/04/11 $"

/* $Log:	termio.h,v $
 */

#ifndef	_SYS_TERMIO_H_
#define _SYS_TERMIO_H_

/* ____________________________________________________________________*
 * This file forms part of the POSIX requirement described in section  *
 * 7 of 1003.1-1988 which should be refered to before making any       *
 * changes.                                                            *
 *_____________________________________________________________________*/

#ifndef _POSIX_SOURCE
#define	NCC	8	/* struct termio */
#endif /* _POSIX_SOURCE */
#define	NCCS	20	/* struct termios */

/* control characters */
#define	VINTR	0
#define	VQUIT	1
#define	VERASE	2
#define	VKILL	3
#define	VEOF	4
#define	VEOL	5
#ifndef _POSIX_SOURCE
#define	VEOL2	6
#endif /* _POSIX_SOURCE */
#define	VMIN	4
#define	VTIME	5
#ifndef _POSIX_SOURCE
#define	VSWTCH	7
#endif /* _POSIX_SOURCE */
#define	VSTART	8
#define	VSTOP	9
#define	VSUSP	10

#ifndef _POSIX_SOURCE
#define	CNUL	0
#define	CDEL	0377
/* default control chars */
#define	CESC	'\\'
#define	CINTR	0177	/* DEL */
#define	CQUIT	034	/* FS, cntl | */
#define	CERASE	'#'
#define	CKILL	'@'
#define	CEOF	04	/* cntl d */
#define	CEOL	CNUL
#define	CEOL2	CNUL
#define	CSTART	021	/* cntl q */
#define	CSTOP	023	/* cntl s */
#define	CSWTCH	032	/* cntl z */
#define	CNSWTCH	0
#define	CSUSP	032	/* cntl z */
#endif /* _POSIX_SOURCE */

/* input modes */
#define	IGNBRK	0x0001
#define	BRKINT	0x0002
#define	IGNPAR	0x0004
#define	PARMRK	0x0008
#define	INPCK	0x0010
#define	ISTRIP	0x0020
#define	INLCR	0x0040
#define	IGNCR	0x0080
#define	ICRNL	0x0100
#ifndef _POSIX_SOURCE
#define	IUCLC	0x0200
#endif /* _POSIX_SOURCE */
#define	IXON	0x0400
#ifndef _POSIX_SOURCE
#define	IXANY	0x0800
#endif /* _POSIX_SOURCE */
#define	IXOFF	0x1000

/* output modes */
#define	OPOST	0x0001
#ifndef _POSIX_SOURCE
#define	OLCUC	0x0002
#define	ONLCR	0x0004
#define	OCRNL	0x0008
#define	ONOCR	0x0010
#define	ONLRET	0x0020
#define	OFILL	0x0040
#define	OFDEL	0x0080
#define	NLDLY	0x0100
#define	NL0	0
#define	NL1	0x0100
#define	CRDLY	0x0600
#define	CR0	0
#define	CR1	0x0200
#define	CR2	0x0400
#define	CR3	0x0600
#define	TABDLY	0x1800
#define	TAB0	0
#define	TAB1	0x0800
#define	TAB2	0x1000
#define	TAB3	0x1800
#define	BSDLY	0x2000
#define	BS0	0
#define	BS1	0x2000
#define	VTDLY	0x4000
#define	VT0	0
#define	VT1	0x4000
#define	FFDLY	0x8000
#define	FF0	0
#define	FF1	0x8000
#endif /* _POSIX_SOURCE */

/* control modes */
#ifndef _POSIX_SOURCE
#define	CBAUD	0x000f
#endif /* _POSIX_SOURCE */
#define	B0	0
#define	B50	0x0001
#define	B75	0x0002
#define	B110	0x0003
#define	B134	0x0004
#define	B150	0x0005
#define	B200	0x0006
#define	B300	0x0007
#define	B600	0x0008
#define	B1200	0x0009
#define	B1800	0x000a
#define	B2400	0x000b
#define	B4800	0x000c
#define	B9600	0x000d
#define	B19200	0x000e
#ifndef _POSIX_SOURCE
#define EXTA	0x000e
#endif /* _POSIX_SOURCE */
#define	B38400	0x000f
#ifndef _POSIX_SOURCE
#define EXTB	0x000f
#endif /* _POSIX_SOURCE */
#define	CSIZE	0x0030
#define	CS5	0
#define	CS6	0x0010
#define	CS7	0x0020
#define	CS8	0x0030
#define	CSTOPB	0x0040
#define	CREAD	0x0080
#define	PARENB	0x0100
#define	PARODD	0x0200
#define	HUPCL	0x0400
#define	CLOCAL	0x0800
#ifndef _POSIX_SOURCE
#define RCV1EN	0x1000
#define	XMT1EN	0x2000
#define	LOBLK	0x4000
#define XCLUDE	0x8000
#endif /* _POSIX_SOURCE */

/* line discipline 0 modes */
#define	ISIG	0x0001
#define	ICANON	0x0002
#ifndef _POSIX_SOURCE
#define	XCASE	0x0004
#endif /* _POSIX_SOURCE */
#define	ECHO	0x0008
#define	ECHOE	0x0010
#define	ECHOK	0x0020
#define	ECHONL	0x0040
#define	NOFLSH	0x0080
#define	TOSTOP	0x0100
#ifndef _POSIX_SOURCE
#define IOLD	0x00020000		/* convert to stty/gtty */
#endif /* _POSIX_SOURCE */
#define	IEXTEN	0x00010000		/* struct termios only */

#ifndef _POSIX_SOURCE
#ifndef u3b5
#define	SSPEED	7	/* default speed: 300 baud */
#else
#define SSPEED	9	/* default speed: 1200 baud */
#endif
#endif /* _POSIX_SOURCE */

#ifndef _POSIX_SOURCE
/*
 * Ioctl control packet
 */
struct termio {
	unsigned short	c_iflag;	/* input modes */
	unsigned short	c_oflag;	/* output modes */
	unsigned short	c_cflag;	/* control modes */
	unsigned short	c_lflag;	/* line discipline modes */
	char 		c_line;		/* line-discipline */
	unsigned char	c_cc[NCC];	/* control chars */
};
#endif /* _POSIX_SOURCE */

typedef	unsigned long	tcflag_t;
typedef	unsigned char	cc_t;
typedef unsigned long	speed_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;	/* line discipline modes */
	cc_t		c_cc[NCCS];	/* control chars */
	int		_reserve[4];	/* for furture expansion */
};
#ifndef _POSIX_SOURCE
#define	IOCTYPE	0xff00

#define	TIOC	('T'<<8)
#define	TCGETA	(TIOC|1)
#define	TCSETA	(TIOC|2)
#define	TCSETAW	(TIOC|3)
#define	TCSETAF	(TIOC|4)
#define	TCSBRK	(TIOC|5)
#define	TCXONC	(TIOC|6)
#define	TCFLSH	(TIOC|7)
#ifdef u3b5
#define TTYTYPE (TIOC|8)
#endif
#define	TIOCGWINSZ	(TIOC|104)
#define	TIOCSWINSZ	(TIOC|103)

#define	TCGETP	(TIOC|201)
#define	TCSETP	(TIOC|202)
#define	TCSETPW	(TIOC|203)
#define	TCSETPF	(TIOC|204)
#endif /* _POSIX_SOURCE */
#define TIOCGPGRP (TIOC|205)
#define TIOCSPGRP (TIOC|206)
#ifndef _POSIX_SOURCE
#define	TCDSET	(TIOC|32)

#define	LDIOC	('D'<<8)
#define	LDOPEN	(LDIOC|0)
#define	LDCLOSE	(LDIOC|1)
#define	LDCHG	(LDIOC|2)
#define	LDLCLOSE	(LDIOC|3)
#define	LDGETT	(LDIOC|8)
#define	LDSETT	(LDIOC|9)
#endif /* _POSIX_SOURCE */

/*
 * Terminal types
 */
#ifndef _POSIX_SOURCE
#define	TERM_NONE	0	/* tty */
#define	TERM_TEC	1	/* TEC Scope */
#define	TERM_V61	2	/* DEC VT61 */
#define	TERM_V10	3	/* DEC VT100 */
#define	TERM_TEX	4	/* Tektronix 4023 */
#define	TERM_D40	5	/* TTY Mod 40/1 */
#define	TERM_H45	6	/* Hewlitt-Packard 45 */
#define	TERM_D42	7	/* TTY Mod 40/2B */
#endif /* _POSIX_SOURCE */

/*
 * Terminal flags
 */
#ifndef _POSIX_SOURCE
#define TM_NONE		0000	/* use default flags */
#define TM_SNL		0001	/* special newline flag */
#define TM_ANL		0002	/* auto newline on column 80 */
#define TM_LCF		0004	/* last col of last row special */
#define TM_CECHO	0010	/* echo terminal cursor control */
#define TM_CINVIS	0020	/* do not send esc seq to user */
#define TM_SET		0200	/* must be on to set/res flags */
#endif /* _POSIX_SOURCE */

/*
 * structure of ioctl arg for LDGETT and LDSETT
 */
struct	termcb	{
	char	st_flgs;	/* term flags */
	char	st_termt;	/* term type */
	char	st_crow;	/* gtty only - current row */
	char	st_ccol;	/* gtty only - current col */
	char	st_vrow;	/* variable row */
	char	st_lrow;	/* last row */
};

/*
 * For get/set state calls and line control functions.
 */
#define TCSANOW		1	/* change state immediately */
#define TCSADRAIN	2	/* change after output written */
#define TCSAFLUSH	3	/* change after output & flush input */
#define TCIFLUSH	4	/* flush data received but not read */
#define TCOFLUSH	5	/* flush data written but not xmitted */
#define TCIOFLUSH	6	/* flush both above */
#define TCOOFF		7	/* suspend output */
#define TCOON		8	/* restart suspended output */
#define TCIOFF		9	/* transmit stop character */
#define TCION		10	/* transmit start character */

/*
 * Windowing structure to support JWINSIZE/TIOCSWINSZ/TIOCGWINSZ 
 */
struct winsize {
	unsigned short ws_row;       /* rows, in characters*/
	unsigned short ws_col;       /* columns, in character */
	unsigned short ws_xpixel;    /* horizontal size, pixels */
	unsigned short ws_ypixel;    /* vertical size, pixels */
};

#ifdef INKERNEL
	/* streams M_CTL types for streamtty's */
#ifndef _POSIX_SOURCE
			/* to streamtty */
#define	MC_STOP		1	/* request to stop output */
#define	MC_START	2	/* request to start output */
#define	MC_STARTI	3	/* request to start input(+start char)*/

			/* to and from streamtty */
#define	MC_STOPI	4	/* request to stop input(+stop char)*/

			/* from streamtty */
#define MC_FRAME_ERR	5	/* next chars (if any) have framming errors */
#define MC_PARITY_ERR	6	/* next chars have parity errors */
#define MC_PFLAGS	7	/* set private cannon/echo mode(s) */
#endif /* _POSIX_SOURCE */

#else	/* ! INKERNEL */

extern speed_t cfgetospeed();
extern speed_t cfgetispeed();

#endif	/* INKERNEL */

#endif	/* _SYS_TERMIO_H_ */
