/* $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.
 */
/*	Copyright (c) 1984 1988 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/


/* #ident	"@(#)head.sys:ld0.h	1.2" */
#ident	"$Header: ld0.h 1.19 90/01/26 $"

#ifndef	_SYS_LD0_H_

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

/* tty line discipline 0 processing for
 * pushable line discipline streams module.
 */

struct ld
{
	lock_t	ld_lock;	/* state lock  */
	ushort	ld_state;	/* internal state of tty ld */
	sema_t	ld_sema;	/* wait for sema */

	uint	ld_defer;	/* deferred action stats */
	int	ld_fticks;	/* pending fticks */
	uint	ld_rbid;	/* bufcal id for read processing */
	uint	ld_wbid;	/* bufcal id for write processing */
	uint	ld_ioctl;	/* ioctl id for TIOCGETP */

	ulong	ld_iflags;	/* input mode: ioctl message can set */
	ulong	ld_oflags;	/* output mode: ioctl can set */
	ulong	ld_lflags;	/* line discipline mode: ioctl can set */
	ulong	ld_cflags;	/* control mode: ioctl can set */
	ulong	ld_pflags;	/* private flags */
	unchar 	ld_col;		/* output column of tty */
	ushort	ld_erase;	/* erase char */
	ushort	ld_kill;	/* line kill char */
	ushort	ld_intrc;	/* interrupt char */
	ushort	ld_quitc;	/* quit char */
	ushort	ld_startc;	/* start char */
	ushort	ld_stopc;	/* stop char */
	ushort	ld_eofc;	/* end-of-file char */
	ushort	ld_eol;		/* input delim char (like NL) */
	ushort	ld_eol2;	/* 2nd input delim char */
	ushort	ld_suspc;	/* suspend char */
	ushort	ld_swtchc;	/* switch char for shl */

	unchar 	ld_canonb[CANBSIZ + 4];   /* input buffer for line formation */
				/* (pad is to allow for partial EUC chars) */
	unchar 	*ld_op;		/* pointer for input buffer */

	unchar	ld_pline[CANBSIZ];    /* pointer into canonb for EUC chars */
	int	ld_current;	/* offset into pline of current char */
	ushort	ld_ign;		/* for OPOST counting of EUC bytes */
	ushort	ld_euc_num;	/* bytes remaining in current input char */
	struct	eucioc ld_eucwioc;    /* describes the current EUC codesets */

	struct	winsize  ld_wd;	/* window size information */
	mblk_t	*ld_flushr;	/* delayed FLUSHR ACK */
};


#define	CTRL(c)	('c'&037)
#define	EOT	CTRL(d)


/* define partab character types */
#define	ORDINARY	0
#define	CONTROL		1
#define	BACKSPACE	2
#define	NEWLINE		3
#define	TAB		4
#define	VTAB		5
#define	RETURN		6
#define	FORMFEED	7

/* internal states for ld module access gated on ld_lock */
#define	TTSTOP		0x0001		/* stopped by ^S */
#define	TTESC		0x0002		/* have just seen '\' (ldinsrv)  */
#define TTCR		0x0004		/* mapping NL to CR-NL */
#define	TTUSE		0x0008		/* this structure in use */
#define	TTBLOCK		0x0010		/* have sent STOP message */
#define TTIOC		0x0020		/* TCGETA just went down */
#define TTESC2  	0x0040		/* 2nd '\' in a row */
#define TTDRAIN 	0x0080		/* waiting to drain */
#define TTHUP 		0x0100		/* hangup seen */
#define TTCANFULL	0x0200		/* canonb full, waiting for buffer */

/* internal indicator for euc code set processing */
#define TTSET0  0x00		/* Set0 code has been set in ld_canonb */
#define TTSET1  0x01		/* Set1 code has been set in ld_canonb */
#define TTSET2  0x02	        /* Set2 code has been set in ld_canonb */
#define TTSET3  0x03	        /* Set3 code has been set in ld_canonb */


/* defered actions state */

#define LD0_INT		0x0001		/* send SIGINT */
#define LD0_QUIT	0x0002		/* send SIGQUIT */
#define LD0_TSTP	0x0004		/* send SIGTSTP */
#define LD0_FLUSHR	0x0008		/* send FLUSHR */
#define LD0_FLUSHW	0x0010		/* send FLUSHW */
#define LD0_STOP	0x0020		/* send MC_STOP */
#define LD0_START	0x0040		/* send MC_START */

/* private flags (unprotected via locks */

#define LD0_CANON		0x0001		/* cannon flag */
#define LD0_ECHO		0x0002		/* LD0 does echoing */

#define	_SYS_LD0_H_
#endif	/* _SYS_LD0_H_ */
