#ident "$Id: termio.h,v 1.1 1995/03/16 17:19:41 garyp Exp $"
/*****************************************************************************
 * Copyright (c) 1988-95 Digi International Inc., All Rights Reserved
 * 
 * This  software  contains  proprietary  and  confidential   information   of
 * Digi International  Inc.   By  accepting  transfer  of this copy, Recipient
 * agrees to retain this software in  confidence,  to  prevent  disclosure  to
 * others,  and  to make no  use of this software other than that for which it
 * was delivered.  This is an unpublished copyright work  Digi   International
 * Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is
 * strictly prohibited.
 * 
 * Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc.
 * Confidential  when   combined   with   the   aggregated  modules  for  this
 * product) OBJECT CODE ONLY SOURCE MATERIALS
 * 
 * (C) COPYRIGHT Digi International Inc. 1995
 * 
 * All Rights Reserved
 * 
 * US   Government   Users   Restricted   Rights   -   Use,   duplication   or
 * disclosure  restricted by GSA ADP Schedule Contract with Digi International
 * Inc.
 * 
 *****************************************************************************/



/************************************************************************
 * Copyright (c) 1993-1994 Digi International Inc., All Rights Reserved.
 * This software contains proprietary and confidential information of Digi
 * International Inc.  By accepting transfer of this copy, Recipient agrees
 * to retain this software in confidence, to prevent disclosure to others,
 * and to make no use of this software other than that for which it was
 * delivered.  This is an unpublished copyrighted work of Digi International
 * Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
 * prohibited.
 */


/* @(#)signal.h	1.8 (Spider Software) 2/3/93
 *
 * Copyright (C) 1989,1992 Spider Systems Limited
 *
 * This Source Code is furnished under Licence, and may not be copied or
 * distributed without express written agreement.
 *
 * All rights reserved.
 *
 * History:
 * 
 * 	For SpiderStreams2.1	MJSC		15 Nov 1992
 */

#define      NCC  8		/* The number of control characters */
#define      NCCS NCC+5   	/* size of termios.c_cc[] */


struct       termio {
unsigned    short   c_iflag;	/* input modes */
unsigned    short   c_oflag;	/* output modes */
unsigned    short   c_cflag;	/* control modes */
unsigned    short   c_lflag;	/* local modes */
char        c_line; 		/* line discipline */
unsigned    char    c_cc[NCC];	/* control chars */
};

/* following defines the positions of the sepcial control */
/* characters in the c_cc array and their initial values  */

#define VINTR	0		/* DEL		*/
#define	VQUIT	1		/* FS		*/
#define	VERASE	2		/* Ctrl-H	*/
#define	VKILL	3		/* Ctrl-U	*/
#define	VEOF	4		/* EOT		*/
#define	VMIN	4		/* EOT		*/
#define	VEOL	5		/* NUL 		*/
#define	VTIME	5		/* NUL		*/
#define	VEOL2	6		/* EOL		*/
#define	VSWTCH	7		/* NUL		*/

/* The following are possible control characters */
#define	CESC	'\\'
#define	CINTR	0177
#define	CQUIT	034
#define	CERASE	010
#define	CKILL	025
#define	CEOF	04
#define	CSTART	021
#define	CSTOP	023
#define	CSWTCH	032
#define	CNSWTCH	0
#define	CSUSP	032

/* the following are flags for the c_iflag field */
/* these flags define standard input controls	 */
#define	IGNBRK  0000001  	/* Ignores break condition */
#define	BRKINT  0000002  	/* Signals interrupt on break */
#define	IGNPAR	0000004		/* Ignores characters with parity errors */
#define	PARMRK	0000010		/* Marks parity errors */
#define	INPCK	0000020		/* Enables input parity check */
#define	ISTRIP	0000040		/* Strips character */
#define	INLCR	0000100		/* Maps NL to CR on input */
#define	IGNCR	0000200		/* Ignores CR */
#define	ICRNL	0000400		/* Maps CR to NL on input */
#define	IUCLC	0001000		/* Maps uppercase to lowercase on input */
#define	IXON	0002000		/* Enables start/stop output control */
#define	IXANY	0004000		/* Enables any character to restart output */
#define	IXOFF	0010000		/* Enables start/stop input control */

/* The c_oflag field defines output controls in the following way */
#define	OPOST	0000001		/* Postprocesses output */
#define	OLCUC	0000002		/* Maps lowercase to uppercase on outp */
#define	ONLCR	0000004		/* Maps NL to CR-NL on output */
#define	OCRNL	0000010		/* No CR output at column 0 */
#define	ONOCR	0000020		/* No CR output at column 0 */
#define	ONLRET	0000040		/* NL performs CR function */
#define	OFILL	0000100		/* Uses fill characters for delay */
#define	OFDEL	0000200		/* Fills is DEL, else NUL */
#define	NLDLY	0000400		/* Selects newline delays */
#define	NL0	0
#define	NL1	0000400
#define	CRDLY	0003000		/* Selects carriage return delays */
#define	CR0	0
#define	CR1	0001000
#define	CR2	0002000
#define	CR3	0003000
#define	TABDLY	0014000		/* Selects horizontal tab delays */
#define	TAB0	0
#define	TAB1	0004000
#define	TAB2	0010000
#define	TAB3	0014000		/* Expands tabs to spaces */
#define	BSDLY	0020000		/* Selects backspace delays */
#define	BS0	0
#define	BS1	0020000
#define	VTDLY	0040000		/* Selects vertical tab delays */
#define	VT0	0
#define	VT1	0040000
#define	FFDLY	0100000		/* Selects form feed delays */
#define	FF0	0
#define	FF1	0100000

/* terminal hardware control is defined by the c_cflag field */
#define	CBAUD	0000017		/* Baud rate */
#define	B0	0		/* Hang up */
#define	B50	0000001		/* 50 baud */
#define	B75	0000002		/* 75 baud */
#define	B110	0000003		/* 110 baud */
#define	B134	0000004		/* 134.5 baud */
#define	B150	0000005		/* 150 baud */
#define	B200	0000006		/* 200 baud */
#define	B300	0000007		/* 300 baud */
#define	B600	0000010		/* 600 baud */
#define	B1200	0000011		/* 1200 baud */
#define	B1800	0000012		/* 1800 baud */
#define	B2400	0000013		/* 2400 baud */
#define	B4800	0000014		/* 4800 baud */
#define B9600	0000015		/* 9600 baud */
#define	EXTA	0000016		/* External A */
#define	EXTB	0000017		/* External B */

#define	CSIZE	0000060		/* Character size */
#define	CS5	0		/* 5 bits */
#define	CS6	0000020		/* 6 bits */
#define	CS7	0000040		/* 7 bits */
#define	CS8	0000060		/* 8 bits */
#define	CSTOPB	0000100		/* Sends two stop bits, else one */
#define	CREAD	0000200		/* Enables receiver */
#define	PARENB	0000400		/* Parity enable */
#define	PARODD	0001000		/* Odd parity, else even */
#define	HUPCL	0002000		/* Hangs up on last close */
#define	CLOCAL	0004000		/* Local line, else dial-up */
#define	LOBLK	0010000		/* Block layer output */
#define	CTSFLOW	0020000		/* Enables CTS protocol for a modem line */
#define	RTSFLOW	0040000		/* Enables RTS signaling for a modem line */

/* The rudimentary line discipline functions are controled by */
/* setting the following bits in the c_lfalg                  */
#define	ISIG	0000001		/* Enable signals */
#define	ICANON	0000002		/* Canonical input */
#define	XCASE	0000004		/* Canonical upper/lower presentation */
#define	ECHO	0000010		/* Enables echo */
#define	ECHOE	0000020		/* Echoes erase character as BS-SP-BS */
#define	ECHOK	0000040		/* Echoes NL after kill character */
#define	ECHONL	0000100		/* Echoes NL */
#define	NOFLSH	0000200		/* Disables flush after interrupt or quit */
#define XCLUDE	0100000		/* Exclusive use of the line */

/* Line discipline ioctl commands */
#define	LDIOC	('D'<<8)
#define	LDOPEN	(LDIOC|0)
#define	LDCLOSE	(LDIOC|1)
#define	LDCHG	(LDIOC|2)
#define	LDGETT	(LDIOC|8)
#define	LDSETT	(LDIOC|9)


/*
 * Terminal types
 */
#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	/* Hewlett-Packard 45 */
#define	TERM_D42	7	/* TTY Mod 40/2B */

/*
 * Terminal flags
 */
#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 */

/* Line discipline ioctl structure */
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 */
};



/* POSIX termios - 'x' to avoid 'p', 'P', and 'X' conflicts */
#define	XIOC	('x'<<8)
#define	XCGETA	(XIOC|1)
#define	XCSETA	(XIOC|2)
#define	XCSETAW	(XIOC|3)
#define	XCSETAF	(XIOC|4)

/* POSIX termios for i(ntel)BCS2 standard - now full word value */
#define N_XIOC            (('i'<<24) | ('X'<<16))
#define N_XCGETA          (N_XIOC|1)
#define N_XCSETA          (N_XIOC|2)
#define N_XCSETAW         (N_XIOC|3)
#define N_XCSETAF         (N_XIOC|4)

#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)

#define TCGETS	(TIOC|13)
#define TCSETS	(TIOC|14)
#define TCSETSW (TIOC|15) 
#define TCSETSF (TIOC|16)

#define TIOCGWINSZ (TIOC|104)
#define TIOCSWINSZ (TIOC|103)

/*
 * POSIX ioctl control packet
 */
struct termios {
    unsigned short        c_iflag;        /* input modes */
    unsigned short        c_oflag;        /* output modes */
    unsigned short        c_cflag;        /* control modes */
    unsigned short        c_lflag;        /* local (line discipline) modes */
    char      c_line;         /* line discipline */
    unsigned char         c_cc[NCCS];     /* control chars */
    char                  c_ispeed;       /* input baud rate */
    char                  c_ospeed;       /* output baud rate */
};

typedef unsigned long tcflag_t ;
typedef unsigned char cc_t ;

#define	NCCS_UW	19 

struct termios_unixware {
	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_UW] ;	/* control characters */
};


/* Windowing structure to support JWINSIZE/TIOCSWINSZ/TIOCGWINSZ */

struct winsize {
	unsigned short ws_row ;	/*rows, in characters */
	unsigned short ws_col ; /*colums, in characters */
	unsigned short ws_xpixel ; /* horizontal size, pixels */
	unsigned short ws_ypixel ; /* vertical size, pixels */
};


/* defines and data structures of pseudo stermio compatibility */

#define	STGET	(('X'<<8)|0)	/* get line options */
#define	STSET	(('X'<<8)|1)	/* set line options */
#define	STTHROW	(('X'<<8)|2)	/* throw away queued input */
#define	STWLINE	(('X'<<8)|3)	/* get synchronous line # */
#define STTSV	(('X'<<8)|4)	/* get all line information */
 
struct stio {
        unsigned short  ttyid;
        char            row;
        char            col;
        char            orow;
        char            ocol;
        char            tab;
        char            aid;
        char            ss1;
        char            ss2;
        unsigned short  imode;
        unsigned short  lmode;
        unsigned short  omode;
};

/*
 *      Mode Definitions.
 */
#define STFLUSH 00400   		/* FLUSH mode; lmode */
#define STWRAP  01000   		/* WRAP mode; lmode */
#define STAPPL  02000   		/* APPLICATION mode; lmode */

/* ttold compatibility */
struct  sgttyb {
        unsigned char   sg_ispeed;
        unsigned char   sg_ospeed;
        unsigned char   sg_erase;
        unsigned char   sg_kill;
        int     sg_flags;
};

/* old tty modes */
#define	O_TANDEM	01
#define	O_CBREAK	02
#define	O_LCASE		04
#define	O_ECHO		010
#define	O_CRMOD		020
#define	O_RAW		040
#define	O_ODDP		0100
#define	O_EVENP		0200
#define	O_NLDELAY	001400
#define	O_NL1		000400
#define	O_NL2		001000
#define O_TBDELAY	005000
#define O_TAB1		001000
#define	O_TAB2		004000
#define	O_XTABS		006000
#define	O_CRDELAY	030000
#define	O_CR1		010000
#define	O_CR2		020000
#define	O_VTDELAY	040000
#define	O_BSDELAY	0100000
#define tIOC		('t'<<8)
#define	TIOCGETP	(tIOC|8)
#define	TIOCSETP	(tIOC|9)

/* use */
#define	TTYHOG	256

/* file handling should stricktly speaking be in file.h */

#define	FOPEN	0xffffffff
#define	FREAD	0x01
#define	FWRITE	0x02
#define	FNDELAY	0x04


