17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28b4203d7Marcel Telka/*	  All Rights Reserved	*/
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate
317c478bdstevel@tonic-gate#ifndef _SYS_LDTERM_H
327c478bdstevel@tonic-gate#define	_SYS_LDTERM_H
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gate#ifdef	__cplusplus
357c478bdstevel@tonic-gateextern "C" {
367c478bdstevel@tonic-gate#endif
377c478bdstevel@tonic-gate
387c478bdstevel@tonic-gate#define	IBSIZE	16		/* "standard" input data block size */
397c478bdstevel@tonic-gate#define	OBSIZE	64		/* "standard" output data block size */
407c478bdstevel@tonic-gate#define	EBSIZE	16		/* "standard" echo data block size */
417c478bdstevel@tonic-gate
427c478bdstevel@tonic-gate#ifndef MIN
437c478bdstevel@tonic-gate#define	MIN(a, b) (((a) < (b)) ? (a) : (b))
447c478bdstevel@tonic-gate#endif
457c478bdstevel@tonic-gate
467c478bdstevel@tonic-gate#define	V_MIN 		tp->t_modes.c_cc[VMIN]
477c478bdstevel@tonic-gate#define	V_TIME		tp->t_modes.c_cc[VTIME]
487c478bdstevel@tonic-gate#define	RAW_MODE	!(tp->t_modes.c_lflag & ICANON)
497c478bdstevel@tonic-gate#define	CANON_MODE	(tp->t_modes.c_lflag & ICANON)
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gate/* flow control defines */
527c478bdstevel@tonic-gate#define	TTXOLO	132
537c478bdstevel@tonic-gate#define	TTXOHI	180
547c478bdstevel@tonic-gate#define	HIWAT	1024
557c478bdstevel@tonic-gate#define	LOWAT	200
567c478bdstevel@tonic-gate#define	LDCHUNK	512
577c478bdstevel@tonic-gate
587c478bdstevel@tonic-gate
597c478bdstevel@tonic-gate/*
607c478bdstevel@tonic-gate * The following for EUC and also other types of codesets.
617c478bdstevel@tonic-gate */
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gate#define	EUCSIZE	sizeof (struct eucioc)
647c478bdstevel@tonic-gate#define	EUCIN	0	/* copying eucioc_t IN from ioctl */
657c478bdstevel@tonic-gate#define	EUCOUT	1	/* copying it OUT to user format */
667c478bdstevel@tonic-gate
677c478bdstevel@tonic-gate/*
687c478bdstevel@tonic-gate * One assumption made throughout this module is:  EUC characters have
697c478bdstevel@tonic-gate * a display width less than 255.  Also, assumed around, is that they
707c478bdstevel@tonic-gate * consist of < 256 bytes, but we don't worry much about that.
717c478bdstevel@tonic-gate */
727c478bdstevel@tonic-gate
737c478bdstevel@tonic-gate#define	EUC_TWIDTH	255	/* Width of a TAB, as returned by */
747c478bdstevel@tonic-gate				/* "ldterm_dispwidth" */
757c478bdstevel@tonic-gate#define	EUC_BSWIDTH	254	/* Width of a backspace as returned */
767c478bdstevel@tonic-gate#define	EUC_NLWIDTH	253	/* newline & cr */
777c478bdstevel@tonic-gate#define	EUC_CRWIDTH	252
787c478bdstevel@tonic-gate
797c478bdstevel@tonic-gate#define	UNKNOWN_WIDTH	251
807c478bdstevel@tonic-gate
817c478bdstevel@tonic-gate#define	EUC_MAXW	4	/* max display width and memory width, both */
827c478bdstevel@tonic-gate#define	EUC_WARNCNT	20	/* # bad EUC erase attempts before hollering */
837c478bdstevel@tonic-gate
847c478bdstevel@tonic-gate/* The next version will be the current LDTERM_DATA_VERSION + 1. */
857c478bdstevel@tonic-gate#define	LDTERM_DATA_VERSION		1
867c478bdstevel@tonic-gate
877c478bdstevel@tonic-gate/*
887c478bdstevel@tonic-gate * Supported codeset types:
897c478bdstevel@tonic-gate * When you are adding a new codeset type,  do not add any new codeset type
907c478bdstevel@tonic-gate * value that is smaller than LDTERM_CS_TYPE_MIN. You will also need to
917c478bdstevel@tonic-gate * add the new codeset type sequentially and also increase LDTERM_CS_TYPE_MAX
927c478bdstevel@tonic-gate * so that the LDTERM_CS_TYPE_MAX will be always equal to the last, new
937c478bdstevel@tonic-gate * codeset type value.
947c478bdstevel@tonic-gate *
957c478bdstevel@tonic-gate * Whenever you increase the LDTERM_CS_TYPE_MAX, you will also need to
967c478bdstevel@tonic-gate * increase the LDTERM_DATA_VERSION and also update the ldterm.c so that
977c478bdstevel@tonic-gate * ldterm will have proper version control.
987c478bdstevel@tonic-gate */
997c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_MIN		1
1007c478bdstevel@tonic-gate
1017c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_EUC		1
1027c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_PCCS		2
1037c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8		3
1047c478bdstevel@tonic-gate
1057c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_MAX		3
1067c478bdstevel@tonic-gate
1077c478bdstevel@tonic-gate/*
1087c478bdstevel@tonic-gate * The maximum number of bytes in a character of the codeset that
1097c478bdstevel@tonic-gate * can be handled by ldterm.
1107c478bdstevel@tonic-gate */
1117c478bdstevel@tonic-gate#define	LDTERM_CS_MAX_BYTE_LENGTH	8
1127c478bdstevel@tonic-gate
1137c478bdstevel@tonic-gate/*
1147c478bdstevel@tonic-gate * The maximum number of sub-codesets in a codeset that can be
1157c478bdstevel@tonic-gate * handled by ldterm.
1167c478bdstevel@tonic-gate */
1177c478bdstevel@tonic-gate#define	LDTERM_CS_MAX_CODESETS		10
1187c478bdstevel@tonic-gate
1197c478bdstevel@tonic-gate/* The maximum and minimum sub-codeset numbers possible in EUC codeset. */
1207c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_EUC_MIN_SUBCS	0
1217c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_EUC_MAX_SUBCS	3
1227c478bdstevel@tonic-gate
1237c478bdstevel@tonic-gate/* The maximum and minimum sub-codeset numbers possible in PCCS codeset. */
1247c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_PCCS_MIN_SUBCS	1
1257c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_PCCS_MAX_SUBCS	LDTERM_CS_MAX_CODESETS
1267c478bdstevel@tonic-gate
1277c478bdstevel@tonic-gate/* Some UTF-8 related values: */
1287c478bdstevel@tonic-gate/* The maximum and minimum UTF-8 character subsequent byte values. */
1297c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MIN_BYTE	0x80
1307c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MAX_BYTE	0xbf
1317c478bdstevel@tonic-gate
1327c478bdstevel@tonic-gate/* Some maximum and minimum character values in UTF-32. */
1337c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MAX_P00	0x00ffff
1347c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MAX_P01	0x01ffff
1357c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MIN_CJKEXTB	0x020000
1367c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MAX_CJKEXTB	0x02a6d6
1377c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MIN_CJKCOMP	0x02f800
1387c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MAX_CJKCOMP	0x02fa1d
1397c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MIN_P14	0x0e0000
1407c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MAX_P14	0x0e007f
1417c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MIN_VARSEL	0x0e0100
1427c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MAX_VARSEL	0x0e01ef
1437c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MIN_P15	0x0f0000
1447c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MAX_P15	0x0ffffd
1457c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MIN_P16	0x100000
1467c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_MAX_P16	0x10fffd
1477c478bdstevel@tonic-gate
1487c478bdstevel@tonic-gate/* Bit shift number and mask values for conversion from UTF-8 to UCS-4. */
1497c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_SHIFT_BITS	6
1507c478bdstevel@tonic-gate#define	LDTERM_CS_TYPE_UTF8_BIT_MASK	0x3f
1517c478bdstevel@tonic-gate
1527c478bdstevel@tonic-gate/*
1537c478bdstevel@tonic-gate * The following data structure is to provide codeset-specific
1547c478bdstevel@tonic-gate * information for EUC and PC originated codesets (ldterm_eucpc_data_t)
1557c478bdstevel@tonic-gate */
1567c478bdstevel@tonic-gatestruct _ldterm_eucpc_data {
1577c478bdstevel@tonic-gate	uchar_t	byte_length;
1587c478bdstevel@tonic-gate	uchar_t	screen_width;
1597c478bdstevel@tonic-gate	uchar_t	msb_start;
1607c478bdstevel@tonic-gate	uchar_t	msb_end;
1617c478bdstevel@tonic-gate};
1627c478bdstevel@tonic-gatetypedef struct _ldterm_eucpc_data ldterm_eucpc_data_t;
1637c478bdstevel@tonic-gate
1647c478bdstevel@tonic-gate/* ldterm codeset data information for user side. */
1657c478bdstevel@tonic-gatestruct _ldterm_cs_data_user {
1667c478bdstevel@tonic-gate	uchar_t	version;	/* version: 1 ~ 255 */
1677c478bdstevel@tonic-gate	uchar_t	codeset_type;
1687c478bdstevel@tonic-gate	uchar_t	csinfo_num;	/* the # of codesets */
1697c478bdstevel@tonic-gate	uchar_t	pad;
1707c478bdstevel@tonic-gate	char	locale_name[MAXNAMELEN];
1717c478bdstevel@tonic-gate	ldterm_eucpc_data_t	eucpc_data[LDTERM_CS_MAX_CODESETS];
1727c478bdstevel@tonic-gate						/* width data */
1737c478bdstevel@tonic-gate};
1747c478bdstevel@tonic-gatetypedef struct _ldterm_cs_data_user ldterm_cs_data_user_t;
1757c478bdstevel@tonic-gate
1767c478bdstevel@tonic-gate/* ldterm codeset data information for ldterm. */
1777c478bdstevel@tonic-gatestruct _ldterm_cs_data {
1787c478bdstevel@tonic-gate	uchar_t	version;	/* version: 1 ~ 255 */
1797c478bdstevel@tonic-gate	uchar_t	codeset_type;
1807c478bdstevel@tonic-gate	uchar_t	csinfo_num;	/* the # of codesets */
1817c478bdstevel@tonic-gate	uchar_t	pad;
1827c478bdstevel@tonic-gate	char	*locale_name;
1837c478bdstevel@tonic-gate	ldterm_eucpc_data_t	eucpc_data[LDTERM_CS_MAX_CODESETS];
1847c478bdstevel@tonic-gate						/* width data */
1857c478bdstevel@tonic-gate};
1867c478bdstevel@tonic-gatetypedef struct _ldterm_cs_data ldterm_cs_data_t;
1877c478bdstevel@tonic-gate
1887c478bdstevel@tonic-gate/*
1897c478bdstevel@tonic-gate * The following data structure is to handle Unicode codeset.
1907c478bdstevel@tonic-gate * To represent a single Unicode plane, it requires to have 16384
1917c478bdstevel@tonic-gate * 'ldterm_unicode_data_cell_t' elements.
1927c478bdstevel@tonic-gate */
1937c478bdstevel@tonic-gatestruct _ldterm_unicode_data_cell {
1947c478bdstevel@tonic-gate	uchar_t	u0:2;
1957c478bdstevel@tonic-gate	uchar_t	u1:2;
1967c478bdstevel@tonic-gate	uchar_t	u2:2;
1977c478bdstevel@tonic-gate	uchar_t	u3:2;
1987c478bdstevel@tonic-gate};
1997c478bdstevel@tonic-gatetypedef struct _ldterm_unicode_data_cell ldterm_unicode_data_cell_t;
2007c478bdstevel@tonic-gate
2017c478bdstevel@tonic-gate/* The following function pointers point the current codeset methods.  */
2027c478bdstevel@tonic-gatetypedef struct _ldterm_cs_methods {
2037c478bdstevel@tonic-gate	int (*ldterm_dispwidth)(uchar_t, void *, int);
2047c478bdstevel@tonic-gate	int (*ldterm_memwidth)(uchar_t, void *);
2057c478bdstevel@tonic-gate} ldterm_cs_methods_t;
2067c478bdstevel@tonic-gate
2077c478bdstevel@tonic-gatetypedef struct ldterm_mod {
2087c478bdstevel@tonic-gate	struct termios t_modes;	/* Effective modes set by the provider below */
2097c478bdstevel@tonic-gate	struct termios t_amodes; /* Apparent modes for user programs */
2107c478bdstevel@tonic-gate	struct termios t_dmodes; /* Modes that driver wishes to process */
2117c478bdstevel@tonic-gate	unsigned int t_state;	/* internal state of ldterm module */
2127c478bdstevel@tonic-gate	int	t_line;		/* output line of tty */
2137c478bdstevel@tonic-gate	int	t_col;		/* output column of tty */
2147c478bdstevel@tonic-gate	int	t_rocount;	/* number of chars echoed since last output */
2157c478bdstevel@tonic-gate	int	t_rocol;	/* column in which first such char appeared */
2167c478bdstevel@tonic-gate	mblk_t	*t_message;	/* pointer to first mblk in message being */
2177c478bdstevel@tonic-gate				/* built */
2187c478bdstevel@tonic-gate	mblk_t	*t_endmsg;	/* pointer to last mblk in that message */
2197c478bdstevel@tonic-gate	size_t	t_msglen;	/* number of characters in that message */
2207c478bdstevel@tonic-gate	mblk_t	*t_echomp;	/* echoed output being assembled */
2217c478bdstevel@tonic-gate	int	t_rd_request;   /* Number of bytes requested by M_READ */
2227c478bdstevel@tonic-gate				/* during vmin/vtime read */
2237c478bdstevel@tonic-gate	int	t_iocid;	/* ID of ioctl reply being awaited */
2247c478bdstevel@tonic-gate	bufcall_id_t t_wbufcid;	/* ID of pending write-side bufcall */
2257c478bdstevel@tonic-gate	timeout_id_t t_vtid;	/* vtime timer id */
2267c478bdstevel@tonic-gate
2277c478bdstevel@tonic-gate	/*
2287c478bdstevel@tonic-gate	 * The following are for EUC and also other types of codeset
2297c478bdstevel@tonic-gate	 * processing. Please read 'euc' as 'multi-byte codeset' instead.
2307c478bdstevel@tonic-gate	 */
2317c478bdstevel@tonic-gate	uchar_t	t_codeset;	/* current code set indicator (read side) */
2327c478bdstevel@tonic-gate	uchar_t	t_eucleft;	/* bytes left to get in current char (read) */
2337c478bdstevel@tonic-gate	uchar_t	t_eucign;	/* bytes left to ignore (output post proc) */
2347c478bdstevel@tonic-gate	uchar_t	t_eucpad;	/* padding ... for eucwioc */
2357c478bdstevel@tonic-gate	eucioc_t eucwioc;	/* eucioc structure (have to use bcopy) */
2367c478bdstevel@tonic-gate	uchar_t	*t_eucp;	/* ptr to parallel array of column widths */
2377c478bdstevel@tonic-gate	mblk_t	*t_eucp_mp;	/* the m_blk that holds parallel array */
2387c478bdstevel@tonic-gate	uchar_t	t_maxeuc;	/* the max length in memory bytes of an EUC */
2397c478bdstevel@tonic-gate	int	t_eucwarn;	/* bad EUC counter */
2407c478bdstevel@tonic-gate
2417c478bdstevel@tonic-gate	/*
2427c478bdstevel@tonic-gate	 * The t_csdata, t_csmethods, t_scratch, and, t_scratch_len data
2437c478bdstevel@tonic-gate	 * fields are to support various non-EUC codesets.
2447c478bdstevel@tonic-gate	 */
2457c478bdstevel@tonic-gate	ldterm_cs_data_t	t_csdata;
2467c478bdstevel@tonic-gate	struct _ldterm_cs_methods t_csmethods;
2477c478bdstevel@tonic-gate	uchar_t			t_scratch[LDTERM_CS_MAX_BYTE_LENGTH];
2487c478bdstevel@tonic-gate	uchar_t			t_scratch_len;
2497c478bdstevel@tonic-gate
2507c478bdstevel@tonic-gate	mblk_t	*t_closeopts;	/* preallocated stroptions for close */
2517c478bdstevel@tonic-gate	mblk_t	*t_drainmsg;	/* preallocated TCSBRK drain message */
2527c478bdstevel@tonic-gate} ldtermstd_state_t;
2537c478bdstevel@tonic-gate
2547c478bdstevel@tonic-gate/*
2557c478bdstevel@tonic-gate * Internal state bits.
2567c478bdstevel@tonic-gate */
2577c478bdstevel@tonic-gate#define	TS_XCLUDE	0x00000001	/* exclusive-use flag against open */
2587c478bdstevel@tonic-gate#define	TS_TTSTOP	0x00000002	/* output stopped by ^S */
2597c478bdstevel@tonic-gate#define	TS_TBLOCK	0x00000004	/* input stopped by IXOFF mode */
2607c478bdstevel@tonic-gate#define	TS_QUOT		0x00000008	/* last character input was \ */
2617c478bdstevel@tonic-gate#define	TS_ERASE	0x00000010	/* within a \.../ for PRTRUB */
2627c478bdstevel@tonic-gate#define	TS_SLNCH	0x00000020	/* next character service routine */
2637c478bdstevel@tonic-gate					/* sees is literal */
2647c478bdstevel@tonic-gate#define	TS_PLNCH	0x00000040	/* next character put routine sees */
2657c478bdstevel@tonic-gate					/* is literal */
2667c478bdstevel@tonic-gate
2677c478bdstevel@tonic-gate#define	TS_TTCR		0x00000080	/* mapping NL to CR-NL */
2687c478bdstevel@tonic-gate#define	TS_NOCANON	0x00000100	/* canonicalization done by somebody */
2697c478bdstevel@tonic-gate					/* below us */
2707c478bdstevel@tonic-gate#define	TS_RESCAN	0x00000400	/* canonicalization mode changed, */
2717c478bdstevel@tonic-gate					/* rescan input queue */
2727c478bdstevel@tonic-gate#define	TS_MREAD	0x00000800	/* timer started for vmin/vtime */
2737c478bdstevel@tonic-gate#define	TS_FLUSHWAIT	0x00001000	/* waiting for flush on write side */
2747c478bdstevel@tonic-gate#define	TS_MEUC		0x00010000	/* TRUE if multi-byte codesets used */
2757c478bdstevel@tonic-gate#define	TS_WARNED	0x00020000	/* already warned on console */
2767c478bdstevel@tonic-gate#define	TS_CLOSE	0x00040000	/* close in progress */
2777c478bdstevel@tonic-gate#define	TS_IOCWAIT	0x00080000	/* waiting for reply to ioctl message */
2787c478bdstevel@tonic-gate#define	TS_IFBLOCK	0x00100000	/* input flow blocked */
2797c478bdstevel@tonic-gate#define	TS_OFBLOCK	0x00200000	/* output flow blocked */
2807c478bdstevel@tonic-gate#define	TS_ISPTSTTY	0x00400000	/* is x/open terminal */
2817c478bdstevel@tonic-gate
2827c478bdstevel@tonic-gate#ifdef	__cplusplus
2837c478bdstevel@tonic-gate}
2847c478bdstevel@tonic-gate#endif
2857c478bdstevel@tonic-gate
2867c478bdstevel@tonic-gate#endif	/* _SYS_LDTERM_H */
287