# ifndef NO_WHAT
/*
 *      SCCS file type - Emulator Include File
 *
 *      What identification string:
 */
static char *_S_hETTY = "@(#)ETTY.h	3.1";
# endif

/****************************************************************
 *      ETTY.h contains the defines and declarations            *
 *      for variables and constants in the TTY i/o system.      *
 ****************************************************************/

/*
 *      CONSTANTS
 */

/* default terminal settings if cannot read NKSR data base */
#define Derase_char '\010'                   /* back space */
#define Dkill_char '\100'                  /* @ */
#define Dterminal_modes ECHO | EVENP | CRLFMAP

/* standard DEL and interrupt characters */
#define CEOT  '\004'      /* control D */
#define CQUIT '\034'        /* FS,control Shift | */
#define CINTR '\177'        /* DEL       */
#define CNL     '\n'        /* New Line  */
#define CCR     '\r'        /* CR char   */
#define CNULL '\000'        /* null char */
#define CSPACE   ' '        /* space char */
#define CBS   '\010'        /* back space char */

#define EOT_MARKER   0377         /* marker for EOT if in Cooked mode */
				       /* in cooked mode chars are  7 bit  */
				       /* therefor not valid character     */

/* flags used in event messages for TTYs */
#define IO_READ 0
#define IO_WRITE 1
#define IO_ECHO 2



/*
 *      TYPES
 */

typedef struct {                /* buffer used for stty and gtty calls */
		char                    ispeed,ospeed;
		char                    tty_erase, tty_kill;
		int                     tty_mode;
	} sgtty_buf;


/*
 *      TTY_index       : 0 .. OPEN_TTYS -1 ;
 */

#define TTY_index char


typedef struct {
		char                    proc;  /* really type t_FProcTab_index */
		open_mode               mode;
		boolean                 allocated;
	} t_TTY_open_list_entry;


#define t_TTY_index char

/*
 *      t_E_K_read_buf_index    0 .. NE_K_READ_BUF_SIZE -1;
 */
#define t_E_K_read_buf_index char

/*
 *      t_column_cnt = o .. NTTYCOL - 1;
 */
#define t_column_cnt char

/*
 *      t_TTY_mode = wordmask { ....   }
 */
#define t_TTY_modes int

/* tty mode flags */
#define BSDELAY         0100000         /* currently not used                   */
#define VTDELAY         0040000         /* form-feed and vertical-tab delays    */
#define CRDELAY         0030000         /* 1 of 4 carriage-return delays        */
#define TBDELAY         0006000         /* 1 of 4 tab delay algorithms          */
#define NLDELAY         0001400         /* 1 of 4 new line delay algorithms     */
#define EVENP           0000200         /* allow even parity on input           */
#define ODDP            0000100         /* allow odd parity on input            */
#define RAW             0000040         /* raw mode; wake up on all characters  */
#define CRLFMAP         0000020         /* map CR into LF; echo LF or CR as CR-LF*/
#define ECHO            0000010         /* Echo mode; full duplex               */
#define LCASE           0000004         /* Map Upper case to lower case         */
#define XTABS           0000002         /* Expand tabs;echo and print tabs as spaces*/
#define HUPCL           0000001         /* Hang-up mode- not supported          */

#define TABSIZE  8                   /* number of characters between tabs*/

typedef struct {
		boolean         in_use; /* set if tty structure allocated */
	} t_TTY_flags;


typedef struct  {
		SHARED
		SEID            TTY_seid;
		t_TTY_modes     modes;
		char            erase;          /* erase character      */
		char            kill;           /* kill character       */
		t_TTY_flags     flags;
		t_column_cnt    column_cnt;
		int             read_refs;      /* number of family entries */
		int             write_refs;     /*pointing to tty structures*/
						/* with specified modes set */
		t_TTY_open_list_entry   open_list[NFprocs];
				/* process that have tty open, and mode */
	} TTY_common_entry;


typedef struct  {
		SHARED
		char            read_buffer[NREAD_Q_SIZE];

		/* read buffer pointers */
		char            *SADp;          /* Start of available data */
		char            *LPLp;          /* End last processed line */
		char            *CCp;           /* Current cannon pointer  */

		char                    current_read_master;
					/* really t_FProcTab_index */
		KOOD                    CRM_open_object;
					/* CRM_open_object=open descriptor used */
					/* by current read master to tell which */
					/* open it is using.                    */
		char                    request_new_read_master;
					/* really t_FProcTab_index */
		boolean                 flush_read_buffer;
		boolean                 reader_waiting;
		boolean                 lastCbs;   /* set of last char was  */
						   /* back slash            */

		int             read_flags;
				/* read in progress .. */
	} TTY_read_entry;

typedef struct  {
		SHARED

		/* write buffer pointers  */
		char            *wEODp;          /* End of data for write  */
		char            *wSCWp;          /* Start of current write */
		char            *wECWp;          /* End of current wirte   */


		boolean                 writer_active_flag;
				/* flag maintained by the write half of */
				/* the event handler                    */
		boolean                 writer_waiting;
				/* flag set if the writer is waiting for  */
				/* an event notice that it can write more */

		char                    current_write_master;
					/* really t_FProcTab_index */
		KOOD                    CWM_open_object;
		char                    request_new_write_master;
					/* really t_FProcTab_index */
		unsigned        wNull_cnt; /* number of nulls needed to be */
					   /* written for delays           */

		char            wCR_cnt;   /* number of CR needed to be    */
					   /* written- only 1 or 0         */

		char            wSpace_cnt;/* number of SPACES needed to be */
					   /* written-(for tabs),  <= 8     */
	} TTY_write_entry;

typedef struct {
		TTY_common_entry        TTY_common;
		TTY_read_entry          TTY_read;
		TTY_write_entry         TTY_write;
	}  TTY_entry;


/********************************************************************/

		/* TTY buffers */

typedef struct {

		char            write_buffer[NOPEN_TTYS][NWRITE_Q_SIZE];
		char            E_K_buffer[NOPEN_TTYS][NE_K_READ_BUF_SIZE];
	} TTY_buffers;


