1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #ifndef _SYS_LDTERM_H 32*0Sstevel@tonic-gate #define _SYS_LDTERM_H 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 11.5 */ 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #ifdef __cplusplus 37*0Sstevel@tonic-gate extern "C" { 38*0Sstevel@tonic-gate #endif 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #define IBSIZE 16 /* "standard" input data block size */ 41*0Sstevel@tonic-gate #define OBSIZE 64 /* "standard" output data block size */ 42*0Sstevel@tonic-gate #define EBSIZE 16 /* "standard" echo data block size */ 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate #ifndef MIN 45*0Sstevel@tonic-gate #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 46*0Sstevel@tonic-gate #endif 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate #define V_MIN tp->t_modes.c_cc[VMIN] 49*0Sstevel@tonic-gate #define V_TIME tp->t_modes.c_cc[VTIME] 50*0Sstevel@tonic-gate #define RAW_MODE !(tp->t_modes.c_lflag & ICANON) 51*0Sstevel@tonic-gate #define CANON_MODE (tp->t_modes.c_lflag & ICANON) 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate /* flow control defines */ 54*0Sstevel@tonic-gate #define TTXOLO 132 55*0Sstevel@tonic-gate #define TTXOHI 180 56*0Sstevel@tonic-gate #define HIWAT 1024 57*0Sstevel@tonic-gate #define LOWAT 200 58*0Sstevel@tonic-gate #define LDCHUNK 512 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate /* 62*0Sstevel@tonic-gate * The following for EUC and also other types of codesets. 63*0Sstevel@tonic-gate */ 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate #define EUCSIZE sizeof (struct eucioc) 66*0Sstevel@tonic-gate #define EUCIN 0 /* copying eucioc_t IN from ioctl */ 67*0Sstevel@tonic-gate #define EUCOUT 1 /* copying it OUT to user format */ 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate /* 70*0Sstevel@tonic-gate * One assumption made throughout this module is: EUC characters have 71*0Sstevel@tonic-gate * a display width less than 255. Also, assumed around, is that they 72*0Sstevel@tonic-gate * consist of < 256 bytes, but we don't worry much about that. 73*0Sstevel@tonic-gate */ 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate #define EUC_TWIDTH 255 /* Width of a TAB, as returned by */ 76*0Sstevel@tonic-gate /* "ldterm_dispwidth" */ 77*0Sstevel@tonic-gate #define EUC_BSWIDTH 254 /* Width of a backspace as returned */ 78*0Sstevel@tonic-gate #define EUC_NLWIDTH 253 /* newline & cr */ 79*0Sstevel@tonic-gate #define EUC_CRWIDTH 252 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate #define UNKNOWN_WIDTH 251 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate #define EUC_MAXW 4 /* max display width and memory width, both */ 84*0Sstevel@tonic-gate #define EUC_WARNCNT 20 /* # bad EUC erase attempts before hollering */ 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate /* The next version will be the current LDTERM_DATA_VERSION + 1. */ 87*0Sstevel@tonic-gate #define LDTERM_DATA_VERSION 1 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate /* 90*0Sstevel@tonic-gate * Supported codeset types: 91*0Sstevel@tonic-gate * When you are adding a new codeset type, do not add any new codeset type 92*0Sstevel@tonic-gate * value that is smaller than LDTERM_CS_TYPE_MIN. You will also need to 93*0Sstevel@tonic-gate * add the new codeset type sequentially and also increase LDTERM_CS_TYPE_MAX 94*0Sstevel@tonic-gate * so that the LDTERM_CS_TYPE_MAX will be always equal to the last, new 95*0Sstevel@tonic-gate * codeset type value. 96*0Sstevel@tonic-gate * 97*0Sstevel@tonic-gate * Whenever you increase the LDTERM_CS_TYPE_MAX, you will also need to 98*0Sstevel@tonic-gate * increase the LDTERM_DATA_VERSION and also update the ldterm.c so that 99*0Sstevel@tonic-gate * ldterm will have proper version control. 100*0Sstevel@tonic-gate */ 101*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_MIN 1 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_EUC 1 104*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_PCCS 2 105*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8 3 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_MAX 3 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate /* 110*0Sstevel@tonic-gate * The maximum number of bytes in a character of the codeset that 111*0Sstevel@tonic-gate * can be handled by ldterm. 112*0Sstevel@tonic-gate */ 113*0Sstevel@tonic-gate #define LDTERM_CS_MAX_BYTE_LENGTH 8 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate /* 116*0Sstevel@tonic-gate * The maximum number of sub-codesets in a codeset that can be 117*0Sstevel@tonic-gate * handled by ldterm. 118*0Sstevel@tonic-gate */ 119*0Sstevel@tonic-gate #define LDTERM_CS_MAX_CODESETS 10 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate /* The maximum and minimum sub-codeset numbers possible in EUC codeset. */ 122*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_EUC_MIN_SUBCS 0 123*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_EUC_MAX_SUBCS 3 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate /* The maximum and minimum sub-codeset numbers possible in PCCS codeset. */ 126*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_PCCS_MIN_SUBCS 1 127*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_PCCS_MAX_SUBCS LDTERM_CS_MAX_CODESETS 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate /* Some UTF-8 related values: */ 130*0Sstevel@tonic-gate /* The maximum and minimum UTF-8 character subsequent byte values. */ 131*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MIN_BYTE 0x80 132*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MAX_BYTE 0xbf 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate /* Some maximum and minimum character values in UTF-32. */ 135*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MAX_P00 0x00ffff 136*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MAX_P01 0x01ffff 137*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MIN_CJKEXTB 0x020000 138*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MAX_CJKEXTB 0x02a6d6 139*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MIN_CJKCOMP 0x02f800 140*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MAX_CJKCOMP 0x02fa1d 141*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MIN_P14 0x0e0000 142*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MAX_P14 0x0e007f 143*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MIN_VARSEL 0x0e0100 144*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MAX_VARSEL 0x0e01ef 145*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MIN_P15 0x0f0000 146*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MAX_P15 0x0ffffd 147*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MIN_P16 0x100000 148*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_MAX_P16 0x10fffd 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate /* Bit shift number and mask values for conversion from UTF-8 to UCS-4. */ 151*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_SHIFT_BITS 6 152*0Sstevel@tonic-gate #define LDTERM_CS_TYPE_UTF8_BIT_MASK 0x3f 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate /* 155*0Sstevel@tonic-gate * The following data structure is to provide codeset-specific 156*0Sstevel@tonic-gate * information for EUC and PC originated codesets (ldterm_eucpc_data_t) 157*0Sstevel@tonic-gate */ 158*0Sstevel@tonic-gate struct _ldterm_eucpc_data { 159*0Sstevel@tonic-gate uchar_t byte_length; 160*0Sstevel@tonic-gate uchar_t screen_width; 161*0Sstevel@tonic-gate uchar_t msb_start; 162*0Sstevel@tonic-gate uchar_t msb_end; 163*0Sstevel@tonic-gate }; 164*0Sstevel@tonic-gate typedef struct _ldterm_eucpc_data ldterm_eucpc_data_t; 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate /* ldterm codeset data information for user side. */ 167*0Sstevel@tonic-gate struct _ldterm_cs_data_user { 168*0Sstevel@tonic-gate uchar_t version; /* version: 1 ~ 255 */ 169*0Sstevel@tonic-gate uchar_t codeset_type; 170*0Sstevel@tonic-gate uchar_t csinfo_num; /* the # of codesets */ 171*0Sstevel@tonic-gate uchar_t pad; 172*0Sstevel@tonic-gate char locale_name[MAXNAMELEN]; 173*0Sstevel@tonic-gate ldterm_eucpc_data_t eucpc_data[LDTERM_CS_MAX_CODESETS]; 174*0Sstevel@tonic-gate /* width data */ 175*0Sstevel@tonic-gate }; 176*0Sstevel@tonic-gate typedef struct _ldterm_cs_data_user ldterm_cs_data_user_t; 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate /* ldterm codeset data information for ldterm. */ 179*0Sstevel@tonic-gate struct _ldterm_cs_data { 180*0Sstevel@tonic-gate uchar_t version; /* version: 1 ~ 255 */ 181*0Sstevel@tonic-gate uchar_t codeset_type; 182*0Sstevel@tonic-gate uchar_t csinfo_num; /* the # of codesets */ 183*0Sstevel@tonic-gate uchar_t pad; 184*0Sstevel@tonic-gate char *locale_name; 185*0Sstevel@tonic-gate ldterm_eucpc_data_t eucpc_data[LDTERM_CS_MAX_CODESETS]; 186*0Sstevel@tonic-gate /* width data */ 187*0Sstevel@tonic-gate }; 188*0Sstevel@tonic-gate typedef struct _ldterm_cs_data ldterm_cs_data_t; 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate /* 191*0Sstevel@tonic-gate * The following data structure is to handle Unicode codeset. 192*0Sstevel@tonic-gate * To represent a single Unicode plane, it requires to have 16384 193*0Sstevel@tonic-gate * 'ldterm_unicode_data_cell_t' elements. 194*0Sstevel@tonic-gate */ 195*0Sstevel@tonic-gate struct _ldterm_unicode_data_cell { 196*0Sstevel@tonic-gate uchar_t u0:2; 197*0Sstevel@tonic-gate uchar_t u1:2; 198*0Sstevel@tonic-gate uchar_t u2:2; 199*0Sstevel@tonic-gate uchar_t u3:2; 200*0Sstevel@tonic-gate }; 201*0Sstevel@tonic-gate typedef struct _ldterm_unicode_data_cell ldterm_unicode_data_cell_t; 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate /* The following function pointers point the current codeset methods. */ 204*0Sstevel@tonic-gate typedef struct _ldterm_cs_methods { 205*0Sstevel@tonic-gate int (*ldterm_dispwidth)(uchar_t, void *, int); 206*0Sstevel@tonic-gate int (*ldterm_memwidth)(uchar_t, void *); 207*0Sstevel@tonic-gate } ldterm_cs_methods_t; 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate typedef struct ldterm_mod { 210*0Sstevel@tonic-gate struct termios t_modes; /* Effective modes set by the provider below */ 211*0Sstevel@tonic-gate struct termios t_amodes; /* Apparent modes for user programs */ 212*0Sstevel@tonic-gate struct termios t_dmodes; /* Modes that driver wishes to process */ 213*0Sstevel@tonic-gate unsigned int t_state; /* internal state of ldterm module */ 214*0Sstevel@tonic-gate int t_line; /* output line of tty */ 215*0Sstevel@tonic-gate int t_col; /* output column of tty */ 216*0Sstevel@tonic-gate int t_rocount; /* number of chars echoed since last output */ 217*0Sstevel@tonic-gate int t_rocol; /* column in which first such char appeared */ 218*0Sstevel@tonic-gate mblk_t *t_message; /* pointer to first mblk in message being */ 219*0Sstevel@tonic-gate /* built */ 220*0Sstevel@tonic-gate mblk_t *t_endmsg; /* pointer to last mblk in that message */ 221*0Sstevel@tonic-gate size_t t_msglen; /* number of characters in that message */ 222*0Sstevel@tonic-gate mblk_t *t_echomp; /* echoed output being assembled */ 223*0Sstevel@tonic-gate int t_rd_request; /* Number of bytes requested by M_READ */ 224*0Sstevel@tonic-gate /* during vmin/vtime read */ 225*0Sstevel@tonic-gate int t_iocid; /* ID of ioctl reply being awaited */ 226*0Sstevel@tonic-gate bufcall_id_t t_wbufcid; /* ID of pending write-side bufcall */ 227*0Sstevel@tonic-gate timeout_id_t t_vtid; /* vtime timer id */ 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate /* 230*0Sstevel@tonic-gate * The following are for EUC and also other types of codeset 231*0Sstevel@tonic-gate * processing. Please read 'euc' as 'multi-byte codeset' instead. 232*0Sstevel@tonic-gate */ 233*0Sstevel@tonic-gate uchar_t t_codeset; /* current code set indicator (read side) */ 234*0Sstevel@tonic-gate uchar_t t_eucleft; /* bytes left to get in current char (read) */ 235*0Sstevel@tonic-gate uchar_t t_eucign; /* bytes left to ignore (output post proc) */ 236*0Sstevel@tonic-gate uchar_t t_eucpad; /* padding ... for eucwioc */ 237*0Sstevel@tonic-gate eucioc_t eucwioc; /* eucioc structure (have to use bcopy) */ 238*0Sstevel@tonic-gate uchar_t *t_eucp; /* ptr to parallel array of column widths */ 239*0Sstevel@tonic-gate mblk_t *t_eucp_mp; /* the m_blk that holds parallel array */ 240*0Sstevel@tonic-gate uchar_t t_maxeuc; /* the max length in memory bytes of an EUC */ 241*0Sstevel@tonic-gate int t_eucwarn; /* bad EUC counter */ 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate /* 244*0Sstevel@tonic-gate * The t_csdata, t_csmethods, t_scratch, and, t_scratch_len data 245*0Sstevel@tonic-gate * fields are to support various non-EUC codesets. 246*0Sstevel@tonic-gate */ 247*0Sstevel@tonic-gate ldterm_cs_data_t t_csdata; 248*0Sstevel@tonic-gate struct _ldterm_cs_methods t_csmethods; 249*0Sstevel@tonic-gate uchar_t t_scratch[LDTERM_CS_MAX_BYTE_LENGTH]; 250*0Sstevel@tonic-gate uchar_t t_scratch_len; 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate mblk_t *t_closeopts; /* preallocated stroptions for close */ 253*0Sstevel@tonic-gate mblk_t *t_drainmsg; /* preallocated TCSBRK drain message */ 254*0Sstevel@tonic-gate } ldtermstd_state_t; 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gate /* 257*0Sstevel@tonic-gate * Internal state bits. 258*0Sstevel@tonic-gate */ 259*0Sstevel@tonic-gate #define TS_XCLUDE 0x00000001 /* exclusive-use flag against open */ 260*0Sstevel@tonic-gate #define TS_TTSTOP 0x00000002 /* output stopped by ^S */ 261*0Sstevel@tonic-gate #define TS_TBLOCK 0x00000004 /* input stopped by IXOFF mode */ 262*0Sstevel@tonic-gate #define TS_QUOT 0x00000008 /* last character input was \ */ 263*0Sstevel@tonic-gate #define TS_ERASE 0x00000010 /* within a \.../ for PRTRUB */ 264*0Sstevel@tonic-gate #define TS_SLNCH 0x00000020 /* next character service routine */ 265*0Sstevel@tonic-gate /* sees is literal */ 266*0Sstevel@tonic-gate #define TS_PLNCH 0x00000040 /* next character put routine sees */ 267*0Sstevel@tonic-gate /* is literal */ 268*0Sstevel@tonic-gate 269*0Sstevel@tonic-gate #define TS_TTCR 0x00000080 /* mapping NL to CR-NL */ 270*0Sstevel@tonic-gate #define TS_NOCANON 0x00000100 /* canonicalization done by somebody */ 271*0Sstevel@tonic-gate /* below us */ 272*0Sstevel@tonic-gate #define TS_RESCAN 0x00000400 /* canonicalization mode changed, */ 273*0Sstevel@tonic-gate /* rescan input queue */ 274*0Sstevel@tonic-gate #define TS_MREAD 0x00000800 /* timer started for vmin/vtime */ 275*0Sstevel@tonic-gate #define TS_FLUSHWAIT 0x00001000 /* waiting for flush on write side */ 276*0Sstevel@tonic-gate #define TS_MEUC 0x00010000 /* TRUE if multi-byte codesets used */ 277*0Sstevel@tonic-gate #define TS_WARNED 0x00020000 /* already warned on console */ 278*0Sstevel@tonic-gate #define TS_CLOSE 0x00040000 /* close in progress */ 279*0Sstevel@tonic-gate #define TS_IOCWAIT 0x00080000 /* waiting for reply to ioctl message */ 280*0Sstevel@tonic-gate #define TS_IFBLOCK 0x00100000 /* input flow blocked */ 281*0Sstevel@tonic-gate #define TS_OFBLOCK 0x00200000 /* output flow blocked */ 282*0Sstevel@tonic-gate #define TS_ISPTSTTY 0x00400000 /* is x/open terminal */ 283*0Sstevel@tonic-gate 284*0Sstevel@tonic-gate #ifdef __cplusplus 285*0Sstevel@tonic-gate } 286*0Sstevel@tonic-gate #endif 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gate #endif /* _SYS_LDTERM_H */ 289