Home | History | Annotate | Line # | Download | only in dist
      1 /* $XTermId: ptyx.h,v 1.1135 2025/01/05 20:36:10 tom Exp $ */
      2 
      3 /*
      4  * Copyright 1999-2024,2025 by Thomas E. Dickey
      5  *
      6  *                         All Rights Reserved
      7  *
      8  * Permission is hereby granted, free of charge, to any person obtaining a
      9  * copy of this software and associated documentation files (the
     10  * "Software"), to deal in the Software without restriction, including
     11  * without limitation the rights to use, copy, modify, merge, publish,
     12  * distribute, sublicense, and/or sell copies of the Software, and to
     13  * permit persons to whom the Software is furnished to do so, subject to
     14  * the following conditions:
     15  *
     16  * The above copyright notice and this permission notice shall be included
     17  * in all copies or substantial portions of the Software.
     18  *
     19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     22  * IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
     23  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     26  *
     27  * Except as contained in this notice, the name(s) of the above copyright
     28  * holders shall not be used in advertising or otherwise to promote the
     29  * sale, use or other dealings in this Software without prior written
     30  * authorization.
     31  *
     32  *
     33  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
     34  *
     35  *                         All Rights Reserved
     36  *
     37  * Permission to use, copy, modify, and distribute this software and its
     38  * documentation for any purpose and without fee is hereby granted,
     39  * provided that the above copyright notice appear in all copies and that
     40  * both that copyright notice and this permission notice appear in
     41  * supporting documentation, and that the name of Digital Equipment
     42  * Corporation not be used in advertising or publicity pertaining to
     43  * distribution of the software without specific, written prior permission.
     44  *
     45  *
     46  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
     47  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
     48  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
     49  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
     50  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
     51  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
     52  * SOFTWARE.
     53  */
     54 
     55 #ifndef included_ptyx_h
     56 #define included_ptyx_h 1
     57 
     58 #ifdef HAVE_CONFIG_H
     59 #include <xtermcfg.h>
     60 #endif
     61 
     62 /* ptyx.h */
     63 /* *INDENT-OFF* */
     64 /* @(#)ptyx.h	X10/6.6	11/10/86 */
     65 
     66 #include <X11/IntrinsicP.h>
     67 #include <X11/Shell.h>		/* for XtNdieCallback, etc. */
     68 #include <X11/StringDefs.h>	/* for standard resource names */
     69 #include <X11/Xmu/Misc.h>	/* For Max() and Min(). */
     70 #include <X11/cursorfont.h>
     71 
     72 
     73 #undef bcopy
     74 #undef bzero
     75 #include <X11/Xfuncs.h>
     76 
     77 #include <X11/Xosdefs.h>
     78 #include <X11/Xmu/Converters.h>
     79 #ifdef XRENDERFONT
     80 #include <X11/Xft/Xft.h>
     81 #endif
     82 
     83 #include <stdio.h>
     84 #include <limits.h>
     85 
     86 #if defined(HAVE_STDINT_H) || !defined(HAVE_CONFIG_H)
     87 #include <stdint.h>
     88 #define DECONST(type,s) ((type *)(intptr_t)(const type *)(s))
     89 #else
     90 #define DECONST(type,s) ((type *)(s))
     91 #endif
     92 
     93 /* adapted from IntrinsicI.h */
     94 #define MyStackAlloc(size, stack_cache_array)     \
     95     ((size) <= sizeof(stack_cache_array)	  \
     96     ?  (stack_cache_array)			  \
     97     :  (char*)malloc((size_t)(size)))
     98 
     99 #define MyStackFree(pointer, stack_cache_array) \
    100     if ((pointer) != ((char *)(stack_cache_array))) free(pointer)
    101 
    102 /* adapted from vile (vi-like-emacs) */
    103 #define TypeCallocN(type,n)	(type *)calloc((size_t) (n), sizeof(type))
    104 #define TypeCalloc(type)	TypeCallocN(type, 1)
    105 
    106 #define TypeMallocN(type,n)	(type *)malloc(sizeof(type) * (size_t) (n))
    107 #define TypeMalloc(type)	TypeMallocN(type, 1)
    108 
    109 #define TypeRealloc(type,n,p)	(type *)realloc(p, (n) * sizeof(type))
    110 
    111 #define TypeXtReallocN(t,p,n)	(t *)(void *)XtRealloc((char *)(p), (Cardinal)(sizeof(t) * (size_t) (n)))
    112 
    113 #define TypeXtMallocX(type,n)	(type *)(void *)XtMalloc((Cardinal)(sizeof(type) + (size_t) (n)))
    114 #define TypeXtMallocN(type,n)	(type *)(void *)XtMalloc((Cardinal)(sizeof(type) * (size_t) (n)))
    115 #define TypeXtMalloc(type)	TypeXtMallocN(type, 1)
    116 
    117 #define CastMalloc(type)	(type *)malloc(sizeof(type))
    118 
    119 #define BumpBuffer(type, buffer, size, want) \
    120 	if (want >= size) { \
    121 	    size = 1 + (want * 2); \
    122 	    buffer = TypeRealloc(type, size, buffer); \
    123 	}
    124 
    125 #define BfBuf(type) screen->bf_buf_##type
    126 #define BfLen(type) screen->bf_len_##type
    127 
    128 #define TypedBuffer(type) \
    129 	type		*bf_buf_##type; \
    130 	Cardinal	bf_len_##type
    131 
    132 #define BumpTypedBuffer(type, want) \
    133 	BumpBuffer(type, BfBuf(type), BfLen(type), want)
    134 
    135 #define FreeTypedBuffer(type) \
    136 	do { \
    137 	    FreeAndNull(BfBuf(type)); \
    138 	    BfLen(type) = 0; \
    139 	} while (0)
    140 
    141 #define FreeAndNull(value) \
    142 	do { \
    143 	    free((void *)(value)); \
    144 	    value = NULL; \
    145 	} while (0)
    146 
    147 /*
    148 ** System V definitions
    149 */
    150 
    151 #ifdef att
    152 #define ATT
    153 #endif
    154 
    155 #ifdef SVR4
    156 #undef  SYSV			/* predefined on Solaris 2.4 */
    157 #define SYSV			/* SVR4 is (approx) superset of SVR3 */
    158 #define ATT
    159 #endif
    160 
    161 #ifdef SYSV
    162 #ifdef X_NOT_POSIX
    163 #if !defined(CRAY) && !defined(SVR4)
    164 #define	dup2(fd1,fd2)	((fd1 == fd2) ? fd1 : \
    165 				(close(fd2), fcntl(fd1, F_DUPFD, fd2)))
    166 #endif
    167 #endif
    168 #endif /* SYSV */
    169 
    170 /*
    171  * Newer versions of <X11/Xft/Xft.h> have a version number.  We use certain
    172  * features from that.
    173  */
    174 #if defined(XRENDERFONT) && defined(XFT_VERSION) && XFT_VERSION >= 20100
    175 #define HAVE_TYPE_FCCHAR32	1	/* compatible: XftChar16 */
    176 #define HAVE_TYPE_XFTCHARSPEC	1	/* new type XftCharSpec */
    177 #endif
    178 
    179 /*
    180 ** Definitions to simplify ifdef's for pty's.
    181 */
    182 #define USE_PTY_DEVICE 1
    183 #define USE_PTY_SEARCH 1
    184 
    185 #if defined(__osf__) || (defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
    186 #undef USE_PTY_DEVICE
    187 #undef USE_PTY_SEARCH
    188 #define USE_PTS_DEVICE 1
    189 #elif defined(PUCC_PTYD)
    190 #undef USE_PTY_SEARCH
    191 #elif (defined(sun) && defined(SVR4)) || defined(_ALL_SOURCE) || defined(__CYGWIN__)
    192 #undef USE_PTY_SEARCH
    193 #elif defined(__OpenBSD__)
    194 #undef USE_PTY_SEARCH
    195 #undef USE_PTY_DEVICE
    196 #endif
    197 
    198 #if (defined (__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)))
    199 #define USE_HANDSHAKE 0	/* "recent" Linux systems do not require handshaking */
    200 #endif
    201 
    202 #if (defined (__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)))
    203 #define USE_USG_PTYS
    204 #elif (defined(ATT) && !defined(__sgi)) || (defined(SYSV) && defined(i386))
    205 #define USE_USG_PTYS
    206 #endif
    207 
    208 /*
    209  * More systems than not require pty-handshaking.
    210  */
    211 #ifndef USE_HANDSHAKE
    212 #define USE_HANDSHAKE 1
    213 #endif
    214 
    215 /*
    216 ** allow for mobility of the pty master/slave directories
    217 */
    218 #ifndef PTYDEV
    219 #if defined(__hpux)
    220 #define	PTYDEV		"/dev/ptym/ptyxx"
    221 #else
    222 #define	PTYDEV		"/dev/ptyxx"
    223 #endif
    224 #endif	/* !PTYDEV */
    225 
    226 #ifndef TTYDEV
    227 #if defined(__hpux)
    228 #define TTYDEV		"/dev/pty/ttyxx"
    229 #elif defined(USE_PTS_DEVICE)
    230 #define TTYDEV		"/dev/pts/0"
    231 #else
    232 #define	TTYDEV		"/dev/ttyxx"
    233 #endif
    234 #endif	/* !TTYDEV */
    235 
    236 #ifndef PTYCHAR1
    237 #ifdef __hpux
    238 #define PTYCHAR1	"zyxwvutsrqp"
    239 #else	/* !__hpux */
    240 #define	PTYCHAR1	"pqrstuvwxyzPQRSTUVWXYZ"
    241 #endif	/* !__hpux */
    242 #endif	/* !PTYCHAR1 */
    243 
    244 #ifndef PTYCHAR2
    245 #ifdef __hpux
    246 #define	PTYCHAR2	"fedcba9876543210"
    247 #else	/* !__hpux */
    248 #if defined(__DragonFly__) || defined(__FreeBSD__)
    249 #define	PTYCHAR2	"0123456789abcdefghijklmnopqrstuv"
    250 #else /* !__FreeBSD__ */
    251 #define	PTYCHAR2	"0123456789abcdef"
    252 #endif /* !__FreeBSD__ */
    253 #endif	/* !__hpux */
    254 #endif	/* !PTYCHAR2 */
    255 
    256 #ifndef TTYFORMAT
    257 #if defined(CRAY)
    258 #define TTYFORMAT "/dev/ttyp%03d"
    259 #else
    260 #define TTYFORMAT "/dev/ttyp%d"
    261 #endif
    262 #endif /* TTYFORMAT */
    263 
    264 #ifndef PTYFORMAT
    265 #ifdef CRAY
    266 #define PTYFORMAT "/dev/pty/%03d"
    267 #else
    268 #define PTYFORMAT "/dev/ptyp%d"
    269 #endif
    270 #endif /* PTYFORMAT */
    271 
    272 #ifndef PTYCHARLEN
    273 #ifdef CRAY
    274 #define PTYCHARLEN 3
    275 #else
    276 #define PTYCHARLEN 2
    277 #endif
    278 #endif
    279 
    280 #ifndef MAXPTTYS
    281 #ifdef CRAY
    282 #define MAXPTTYS 256
    283 #else
    284 #define MAXPTTYS 2048
    285 #endif
    286 #endif
    287 
    288 /* Until the translation manager comes along, I have to do my own translation of
    289  * mouse events into the proper routines. */
    290 
    291 typedef enum {
    292     NORMAL = 0
    293     , LEFTEXTENSION
    294     , RIGHTEXTENSION
    295 } EventMode;
    296 
    297 /*
    298  * The origin of a screen is 0, 0.  Therefore, the number of rows
    299  * on a screen is screen->max_row + 1, and similarly for columns.
    300  */
    301 #define MaxCols(screen)		((screen)->max_col + 1)
    302 #define MaxRows(screen)		((screen)->max_row + 1)
    303 
    304 #define MaxUChar 255
    305 typedef unsigned char Char;		/* to support 8 bit chars */
    306 typedef Char *ScrnPtr;
    307 typedef ScrnPtr *ScrnBuf;
    308 
    309 /*
    310  * Declare an X String, but for unsigned chars.
    311  */
    312 #ifdef _CONST_X_STRING
    313 typedef const Char *UString;
    314 #else
    315 typedef Char *UString;
    316 #endif
    317 
    318 #define IsEmpty(s) ((s) == NULL || *(s) == '\0')
    319 #define IsSpace(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')
    320 
    321 /*
    322  * Check strtol result, using "FullS2L" when no more data is expected, and
    323  * "PartS2L" when more data may follow in the string.
    324  */
    325 #define FullS2L(s,d) (PartS2L(s,d) && (*(d) == '\0'))
    326 #define PartS2L(s,d) (isdigit(CharOf(*(s))) && (d) != (s) && (d) != NULL)
    327 
    328 #define CASETYPE(name) case name: result = #name; break
    329 
    330 #define AsciiOf(n) (0x7f & (n))		/* extract 7-bit character */
    331 #define CharOf(n) ((Char)(n))		/* extract 8-bit character */
    332 
    333 typedef struct {
    334     int row;
    335     int col;
    336 } CELL;
    337 
    338 typedef struct {
    339     Char  *data_buffer;			/* the current selection */
    340     size_t data_limit;			/* size of allocated buffer */
    341     size_t data_length;			/* number of significant bytes */
    342 } SelectedCells;
    343 
    344 #define isSameRow(a,b)		((a)->row == (b)->row)
    345 #define isSameCol(a,b)		((a)->col == (b)->col)
    346 #define isSameCELL(a,b)		(isSameRow(a,b) && isSameCol(a,b))
    347 
    348 #define xBIT(n)         (1 << (n))
    349 
    350 /*
    351  * ANSI emulation, special character codes
    352  */
    353 #define ANSI_EOT	0x04
    354 #define ANSI_BEL	0x07
    355 #define ANSI_BS		0x08
    356 #define ANSI_HT		0x09
    357 #define ANSI_LF		0x0A
    358 #define ANSI_VT		0x0B
    359 #define	ANSI_FF		0x0C		/* C0, C1 control names		*/
    360 #define ANSI_CR		0x0D
    361 #define ANSI_SO		0x0E
    362 #define ANSI_SI		0x0F
    363 #define	ANSI_XON	0x11		/* DC1 */
    364 #define	ANSI_XOFF	0x13		/* DC3 */
    365 #define	ANSI_NAK	0x15
    366 #define	ANSI_CAN	0x18
    367 #define	ANSI_ESC	0x1B
    368 #define	ANSI_SPA	0x20
    369 #define XTERM_POUND	0x1E		/* internal mapping for '#'	*/
    370 #define	ANSI_DEL	0x7F
    371 #define	ANSI_SS2	0x8E
    372 #define	ANSI_SS3	0x8F
    373 #define	ANSI_DCS	0x90
    374 #define	ANSI_SOS	0x98
    375 #define	ANSI_CSI	0x9B
    376 #define	ANSI_ST		0x9C
    377 #define	ANSI_OSC	0x9D
    378 #define	ANSI_PM		0x9E
    379 #define	ANSI_APC	0x9F
    380 #define XTERM_PUA	0xEEEE		/* internal mapping for DEC Technical */
    381 
    382 #define BAD_ASCII	'?'
    383 #define NonLatin1(c)	(((c) != ANSI_LF) && \
    384 			 ((c) != ANSI_HT) && \
    385 			 (((c) < ANSI_SPA) || \
    386 			  ((c) >= ANSI_DEL && (c) <= ANSI_APC)))
    387 #define OnlyLatin1(c)	(NonLatin1(c) ? BAD_ASCII : (c))
    388 
    389 #define L_BLOK		'['
    390 #define R_BLOK		']'
    391 
    392 #define L_CURL		'{'
    393 #define R_CURL		'}'
    394 
    395 #define MIN_DECID  52			/* can emulate VT52 */
    396 #define MAX_DECID 525			/* ...through VT525 */
    397 
    398 #ifndef DFT_DECID
    399 #define DFT_DECID "420"			/* default VT420 */
    400 #endif
    401 
    402 #ifndef DFT_KBD_DIALECT
    403 #define DFT_KBD_DIALECT "B"		/* default USASCII */
    404 #endif
    405 
    406 #define MAX_I_PARAM	65535		/* parameters */
    407 #define MAX_I_DELAY	32767		/* time-delay in ReGIS */
    408 #define MAX_U_COLOR	65535u		/* colors */
    409 #define MAX_U_COORD	32767u		/* coordinates */
    410 #define MAX_U_STRING	65535u		/* string-length */
    411 
    412 /* constants used for utf8 mode */
    413 #define UCS_REPL	0xfffd
    414 #define UCS_LIMIT	0x80000000U	/* both limit and flag for non-UCS */
    415 
    416 #define TERMCAP_SIZE 1500		/* 1023 is standard; 'screen' exceeds */
    417 
    418 #define MAX_XLFD_FONTS	1
    419 #define MAX_XFT_FONTS	2
    420 #define NMENUFONTS	10		/* font entries in fontMenu */
    421 
    422 #define	NBOX	5			/* Number of Points in box	*/
    423 #define	NPARAM	30			/* Max. parameters		*/
    424 
    425 typedef struct {
    426 	String opt;
    427 	String desc;
    428 } OptionHelp;
    429 
    430 typedef	struct {
    431 	int	count;			/* number of values in params[]	*/
    432 	int	has_subparams;		/* true if there are any sub's	*/
    433 	int	is_sub[NPARAM];		/* true for subparam		*/
    434 	int	params[NPARAM];		/* parameter value		*/
    435 } PARAMS;
    436 
    437 typedef short ParmType;
    438 typedef unsigned short UParm;		/* unparseputn passes ParmType	*/
    439 
    440 #define MaxSParm   0x7fff		/* limit if a signed value is needed */
    441 #define MaxUParm   0xffff		/* limit if unsigned value is needed */
    442 
    443 #define SParmOf(n) ((int)(ParmType)(n))
    444 #define UParmOf(n) ((unsigned)(UParm)(n))
    445 
    446 typedef struct {
    447 	Char		a_type;		/* CSI, etc., see unparseq()	*/
    448 	Char		a_pintro;	/* private-mode char, if any	*/
    449 	const char *	a_delim;	/* between parameters (;)	*/
    450 	Char		a_inters;	/* special (before final-char)	*/
    451 	Char		a_final;	/* final-char			*/
    452 	ParmType	a_nparam;	/* # of parameters		*/
    453 	ParmType	a_param[NPARAM]; /* Parameters			*/
    454 	Char		a_radix[NPARAM]; /* Parameters			*/
    455 } ANSI;
    456 
    457 #define TEK_FONT_LARGE 0
    458 #define TEK_FONT_2 1
    459 #define TEK_FONT_3 2
    460 #define TEK_FONT_SMALL 3
    461 #define	TEKNUMFONTS 4
    462 
    463 /* Actually there are 5 types of lines, but four are non-solid lines */
    464 #define	TEKNUMLINES	4
    465 
    466 typedef struct {
    467 	int	x;
    468 	int	y;
    469 	int	fontsize;
    470 	unsigned linetype;
    471 } Tmodes;
    472 
    473 typedef struct {
    474 	int Twidth;
    475 	int Theight;
    476 } T_fontsize;
    477 
    478 typedef struct {
    479 	short *bits;
    480 	int x;
    481 	int y;
    482 	int width;
    483 	int height;
    484 } BitmapBits;
    485 
    486 /* bit-assignments for extensions to DECRQCRA, to omit DEC features */
    487 typedef enum {
    488     csDEC = 0
    489     ,csPOSITIVE = xBIT(0)	/* do not negate the result */
    490     ,csATTRIBS = xBIT(1)	/* do not report the VT100 video attributes */
    491     ,csNOTRIM = xBIT(2)		/* do not omit checksum for blanks */
    492     ,csDRAWN = xBIT(3)		/* do not skip uninitialized cells */
    493     ,csBYTE = xBIT(4)		/* do not mask cell value to 8 bits or ignore combining chars */
    494 } CSBITS;
    495 
    496 #define EXCHANGE(a,b,tmp) tmp = a; a = b; b = tmp
    497 
    498 /***====================================================================***/
    499 
    500 #if (XtSpecificationRelease < 6)
    501 #ifndef NO_ACTIVE_ICON
    502 #define NO_ACTIVE_ICON 1 /* Note: code relies on an X11R6 function */
    503 #endif
    504 #endif
    505 
    506 #ifndef OPT_AIX_COLORS
    507 #define OPT_AIX_COLORS  1 /* true if xterm is configured with AIX (16) colors */
    508 #endif
    509 
    510 #ifndef OPT_ALLOW_XXX_OPS
    511 #define OPT_ALLOW_XXX_OPS 1 /* true if xterm adds "Allow XXX Ops" submenu */
    512 #endif
    513 
    514 #ifndef OPT_BLINK_CURS
    515 #define OPT_BLINK_CURS  1 /* true if xterm has blinking cursor capability */
    516 #endif
    517 
    518 #ifndef OPT_BLINK_TEXT
    519 #define OPT_BLINK_TEXT  OPT_BLINK_CURS /* true if xterm has blinking text capability */
    520 #endif
    521 
    522 #ifndef OPT_BLOCK_SELECT
    523 #define OPT_BLOCK_SELECT 0 /* true if block-select is supported */
    524 #endif
    525 
    526 #ifndef OPT_BOX_CHARS
    527 #define OPT_BOX_CHARS	1 /* true if xterm can simulate box-characters */
    528 #endif
    529 
    530 #ifndef OPT_BUILTIN_XPMS
    531 #define OPT_BUILTIN_XPMS 0 /* true if all xpm data is compiled-in */
    532 #endif
    533 
    534 #ifndef OPT_BROKEN_OSC
    535 #ifdef linux
    536 #define OPT_BROKEN_OSC	1 /* man console_codes, 1st paragraph - cf: ECMA-48 */
    537 #else
    538 #define OPT_BROKEN_OSC	0 /* true if xterm allows Linux's broken OSC parsing */
    539 #endif
    540 #endif
    541 
    542 #ifndef OPT_BROKEN_ST
    543 #define OPT_BROKEN_ST	1 /* true if xterm allows old/broken OSC parsing */
    544 #endif
    545 
    546 #ifndef OPT_C1_PRINT
    547 #define OPT_C1_PRINT	1 /* true if xterm allows C1 controls to be printable */
    548 #endif
    549 
    550 #ifndef OPT_CLIP_BOLD
    551 #define OPT_CLIP_BOLD	1 /* true if xterm uses clipping to avoid bold-trash */
    552 #endif
    553 
    554 #ifndef OPT_COLOR_CLASS
    555 #define OPT_COLOR_CLASS 1 /* true if xterm uses separate color-resource classes */
    556 #endif
    557 
    558 #ifndef OPT_DABBREV
    559 #define OPT_DABBREV 0	/* dynamic abbreviations */
    560 #endif
    561 
    562 #ifndef OPT_DEC_CHRSET
    563 #define OPT_DEC_CHRSET  1 /* true if xterm is configured for DEC charset */
    564 #endif
    565 
    566 #ifndef OPT_DEC_LOCATOR
    567 #define	OPT_DEC_LOCATOR 0 /* true if xterm supports VT220-style mouse events */
    568 #endif
    569 
    570 #ifndef OPT_DEC_RECTOPS
    571 #define OPT_DEC_RECTOPS 1 /* true if xterm is configured for VT420 rectangles */
    572 #endif
    573 
    574 #ifndef OPT_SGR2_HASH
    575 #define OPT_SGR2_HASH 1 /* true if xterm hashes color-lookups for faint color */
    576 #endif
    577 
    578 #ifndef OPT_SIXEL_GRAPHICS
    579 #define OPT_SIXEL_GRAPHICS 0 /* true if xterm supports VT240-style sixel graphics */
    580 #endif
    581 
    582 #ifndef OPT_PRINT_GRAPHICS
    583 #define OPT_PRINT_GRAPHICS 0 /* true if xterm supports screen dumps as sixel graphics */
    584 #endif
    585 
    586 #ifndef OPT_SCREEN_DUMPS
    587 #define OPT_SCREEN_DUMPS 1 /* true if xterm supports screen dumps */
    588 #endif
    589 
    590 #ifndef OPT_REGIS_GRAPHICS
    591 #define OPT_REGIS_GRAPHICS 0 /* true if xterm supports VT125/VT240/VT330 ReGIS graphics */
    592 #endif
    593 
    594 #ifndef OPT_GRAPHICS
    595 #define OPT_GRAPHICS 0 /* true if xterm is configured for any type of graphics */
    596 #endif
    597 
    598 #ifndef OPT_DEC_SOFTFONT
    599 #define OPT_DEC_SOFTFONT 0 /* true if xterm is configured for VT220 softfonts */
    600 #endif
    601 
    602 #ifndef OPT_DOUBLE_BUFFER
    603 #define OPT_DOUBLE_BUFFER 0 /* true if using double-buffering */
    604 #endif
    605 
    606 #ifndef OPT_EXEC_SELECTION
    607 #define OPT_EXEC_SELECTION 1 /* true if xterm can exec to process selection */
    608 #endif
    609 
    610 #ifndef OPT_EXEC_XTERM
    611 #define OPT_EXEC_XTERM 0 /* true if xterm can fork/exec copies of itself */
    612 #endif
    613 
    614 #ifndef OPT_EXTRA_PASTE
    615 #define OPT_EXTRA_PASTE 1
    616 #endif
    617 
    618 #ifndef OPT_FOCUS_EVENT
    619 #define OPT_FOCUS_EVENT	1 /* focus in/out events */
    620 #endif
    621 
    622 #ifndef OPT_HP_FUNC_KEYS
    623 #define OPT_HP_FUNC_KEYS 0 /* true if xterm supports HP-style function keys */
    624 #endif
    625 
    626 #ifndef OPT_I18N_SUPPORT
    627 #if (XtSpecificationRelease >= 5)
    628 #define OPT_I18N_SUPPORT 1 /* true if xterm uses internationalization support */
    629 #else
    630 #define OPT_I18N_SUPPORT 0
    631 #endif
    632 #endif
    633 
    634 #ifndef OPT_INITIAL_ERASE
    635 #define OPT_INITIAL_ERASE 1 /* use pty's erase character if it's not 128 */
    636 #endif
    637 
    638 #ifndef OPT_INPUT_METHOD
    639 #if (XtSpecificationRelease >= 6)
    640 #define OPT_INPUT_METHOD OPT_I18N_SUPPORT /* true if xterm uses input-method support */
    641 #else
    642 #define OPT_INPUT_METHOD 0
    643 #endif
    644 #endif
    645 
    646 #ifndef OPT_ISO_COLORS
    647 #define OPT_ISO_COLORS  1 /* true if xterm is configured with ISO colors */
    648 #endif
    649 
    650 #ifndef OPT_DIRECT_COLOR
    651 #define OPT_DIRECT_COLOR  OPT_ISO_COLORS /* true if xterm is configured with direct-colors */
    652 #endif
    653 
    654 #ifndef OPT_256_COLORS
    655 #define OPT_256_COLORS  1 /* true if xterm is configured with 256 colors */
    656 #endif
    657 
    658 #ifndef OPT_88_COLORS
    659 #define OPT_88_COLORS	1 /* true if xterm is configured with 88 colors */
    660 #endif
    661 
    662 #ifndef OPT_HIGHLIGHT_COLOR
    663 #define OPT_HIGHLIGHT_COLOR 1 /* true if xterm supports color highlighting */
    664 #endif
    665 
    666 #ifndef OPT_LOAD_VTFONTS
    667 #define OPT_LOAD_VTFONTS 0 /* true if xterm has load-vt-fonts() action */
    668 #endif
    669 
    670 #ifndef OPT_LUIT_PROG
    671 #define OPT_LUIT_PROG   1 /* true if xterm supports luit */
    672 #endif
    673 
    674 #ifndef OPT_MAXIMIZE
    675 #define OPT_MAXIMIZE	1 /* add actions for iconify ... maximize */
    676 #endif
    677 
    678 #ifndef OPT_MINI_LUIT
    679 #define OPT_MINI_LUIT   0 /* true if xterm supports built-in mini-luit */
    680 #endif
    681 
    682 #ifndef OPT_MOD_FKEYS
    683 #define OPT_MOD_FKEYS	1 /* modify cursor- and function-keys in normal mode */
    684 #endif
    685 
    686 #ifndef OPT_NUM_LOCK
    687 #define OPT_NUM_LOCK	1 /* use NumLock key only for numeric-keypad */
    688 #endif
    689 
    690 #ifndef OPT_PASTE64
    691 #define OPT_PASTE64	1 /* program control of select/paste via base64 */
    692 #endif
    693 
    694 #ifndef OPT_PC_COLORS
    695 #define OPT_PC_COLORS   1 /* true if xterm supports PC-style (bold) colors */
    696 #endif
    697 
    698 #ifndef OPT_PRINT_ON_EXIT
    699 #define OPT_PRINT_ON_EXIT 1 /* true allows xterm to dump screen on X error */
    700 #endif
    701 
    702 #ifndef OPT_PTY_HANDSHAKE
    703 #define OPT_PTY_HANDSHAKE USE_HANDSHAKE	/* avoid pty races on older systems */
    704 #endif
    705 
    706 #ifndef OPT_PRINT_COLORS
    707 #define OPT_PRINT_COLORS 1 /* true if we print color information */
    708 #endif
    709 
    710 #ifndef OPT_READLINE
    711 #define OPT_READLINE	0 /* mouse-click/paste support for readline */
    712 #endif
    713 
    714 #ifndef OPT_RENDERFONT
    715 #ifdef XRENDERFONT
    716 #define OPT_RENDERFONT 1
    717 #else
    718 #define OPT_RENDERFONT 0
    719 #endif
    720 #endif
    721 
    722 #ifndef OPT_RENDERWIDE
    723 #if OPT_RENDERFONT && OPT_WIDE_CHARS && defined(HAVE_TYPE_XFTCHARSPEC)
    724 #define OPT_RENDERWIDE 1
    725 #else
    726 #define OPT_RENDERWIDE 0
    727 #endif
    728 #endif
    729 
    730 #ifndef OPT_REPORT_CCLASS
    731 #define OPT_REPORT_CCLASS  1 /* provide "-report-charclass" option */
    732 #endif
    733 
    734 #ifndef OPT_REPORT_COLORS
    735 #define OPT_REPORT_COLORS  1 /* provide "-report-colors" option */
    736 #endif
    737 
    738 #ifndef OPT_REPORT_FONTS
    739 #define OPT_REPORT_FONTS   1 /* provide "-report-fonts" option */
    740 #endif
    741 
    742 #ifndef OPT_REPORT_ICONS
    743 #define OPT_REPORT_ICONS   1 /* provide "-report-icons" option */
    744 #endif
    745 
    746 #ifndef OPT_SAME_NAME
    747 #define OPT_SAME_NAME   1 /* suppress redundant updates of title, icon, etc. */
    748 #endif
    749 
    750 #ifndef OPT_SCO_FUNC_KEYS
    751 #define OPT_SCO_FUNC_KEYS 0 /* true if xterm supports SCO-style function keys */
    752 #endif
    753 
    754 #ifndef OPT_SUN_FUNC_KEYS
    755 #define OPT_SUN_FUNC_KEYS 1 /* true if xterm supports Sun-style function keys */
    756 #endif
    757 
    758 #ifndef OPT_SCROLL_LOCK
    759 #define OPT_SCROLL_LOCK 1 /* true if xterm interprets fontsize-shifting */
    760 #endif
    761 
    762 #ifndef OPT_SELECT_REGEX
    763 #define OPT_SELECT_REGEX 1 /* true if xterm supports regular-expression selects */
    764 #endif
    765 
    766 #ifndef OPT_SELECTION_OPS
    767 #define OPT_SELECTION_OPS 1 /* true if xterm supports operations on selection */
    768 #endif
    769 
    770 #ifndef OPT_SESSION_MGT
    771 #if defined(XtNdieCallback) && defined(XtNsaveCallback)
    772 #define OPT_SESSION_MGT 1
    773 #else
    774 #define OPT_SESSION_MGT 0
    775 #endif
    776 #endif
    777 
    778 #ifndef OPT_SHIFT_FONTS
    779 #define OPT_SHIFT_FONTS 0 /* true if xterm interprets fontsize-shifting */
    780 #endif
    781 
    782 #ifndef OPT_STATUS_LINE
    783 #define OPT_STATUS_LINE	0 /* true if xterm supports status-line controls */
    784 #endif
    785 
    786 #ifndef OPT_SUNPC_KBD
    787 #define OPT_SUNPC_KBD	1 /* true if xterm supports Sun/PC keyboard map */
    788 #endif
    789 
    790 #ifndef OPT_TCAP_FKEYS
    791 #define OPT_TCAP_FKEYS	1 /* true for termcap function-keys */
    792 #endif
    793 
    794 #ifndef OPT_TCAP_QUERY
    795 #define OPT_TCAP_QUERY	1 /* true for termcap query */
    796 #endif
    797 
    798 #ifndef OPT_TEK4014
    799 #define OPT_TEK4014     1 /* true if we're using tek4014 emulation */
    800 #endif
    801 
    802 #ifndef OPT_TOOLBAR
    803 #define OPT_TOOLBAR	0 /* true if xterm supports toolbar menus */
    804 #endif
    805 
    806 #ifndef OPT_TRACE
    807 #define OPT_TRACE       0 /* true if we're using debugging traces */
    808 #endif
    809 
    810 #ifndef OPT_TRACE_FLAGS
    811 #define OPT_TRACE_FLAGS 0 /* additional tracing used for SCRN_BUF_FLAGS */
    812 #endif
    813 
    814 #ifndef OPT_TRACE_UNIQUE
    815 #define OPT_TRACE_UNIQUE 0 /* true if we're using multiple trace files */
    816 #endif
    817 
    818 #ifndef OPT_VT52_MODE
    819 #define OPT_VT52_MODE   1 /* true if xterm supports VT52 emulation */
    820 #endif
    821 
    822 #ifndef OPT_WIDE_ATTRS
    823 #define OPT_WIDE_ATTRS  1 /* true if xterm supports 16-bit attributes */
    824 #endif
    825 
    826 #ifndef OPT_VT525_COLORS
    827 #define OPT_VT525_COLORS 1 /* true if xterm is configured for VT525 colors */
    828 #endif
    829 
    830 #ifndef OPT_WIDE_CHARS
    831 #define OPT_WIDE_CHARS  1 /* true if xterm supports 16-bit characters */
    832 #endif
    833 
    834 #ifndef OPT_WIDER_ICHAR
    835 #define OPT_WIDER_ICHAR 1 /* true if xterm uses 32-bits for wide-chars */
    836 #endif
    837 
    838 #ifndef OPT_XMC_GLITCH
    839 #define OPT_XMC_GLITCH	0 /* true if xterm supports xmc (magic cookie glitch) */
    840 #endif
    841 
    842 #ifndef OPT_XRES_QUERY
    843 #define OPT_XRES_QUERY	1 /* true for resource query */
    844 #endif
    845 
    846 #ifndef OPT_XTERM_SGR
    847 #define OPT_XTERM_SGR   1 /* true if xterm supports private SGR controls */
    848 #endif
    849 
    850 #ifndef OPT_ZICONBEEP
    851 #define OPT_ZICONBEEP   1 /* true if xterm supports "-ziconbeep" option */
    852 #endif
    853 
    854 /***====================================================================***/
    855 
    856 #if OPT_AIX_COLORS && !OPT_ISO_COLORS
    857 /* You must have ANSI/ISO colors to support AIX colors */
    858 #undef  OPT_AIX_COLORS
    859 #define OPT_AIX_COLORS 0
    860 #endif
    861 
    862 #if OPT_PC_COLORS && !OPT_ISO_COLORS
    863 /* You must have ANSI/ISO colors to support PC colors */
    864 #undef  OPT_PC_COLORS
    865 #define OPT_PC_COLORS 0
    866 #endif
    867 
    868 #if OPT_PRINT_COLORS && !OPT_ISO_COLORS
    869 /* You must have ANSI/ISO colors to be able to print them */
    870 #undef  OPT_PRINT_COLORS
    871 #define OPT_PRINT_COLORS 0
    872 #endif
    873 
    874 #if OPT_256_COLORS && !OPT_ISO_COLORS
    875 /* You must have ANSI/ISO colors to support 256 colors */
    876 #undef  OPT_256_COLORS
    877 #define OPT_256_COLORS 0
    878 #endif
    879 
    880 #if OPT_88_COLORS && !OPT_ISO_COLORS
    881 /* You must have ANSI/ISO colors to support 88 colors */
    882 #undef  OPT_88_COLORS
    883 #define OPT_88_COLORS 0
    884 #endif
    885 
    886 #if OPT_88_COLORS && OPT_256_COLORS
    887 /* 256 colors supersedes 88 colors */
    888 #undef  OPT_88_COLORS
    889 #define OPT_88_COLORS 0
    890 #endif
    891 
    892 /***====================================================================***/
    893 
    894 /*
    895  * Indices for menu_font_names[][]
    896  */
    897 typedef enum {
    898     fNorm = 0			/* normal font */
    899     , fBold			/* bold font */
    900 #if OPT_WIDE_ATTRS || OPT_RENDERWIDE
    901     , fItal			/* italic font */
    902     , fBtal			/* bold-italic font */
    903 #endif
    904 #if OPT_WIDE_CHARS
    905     , fWide			/* double-width font */
    906     , fWBold			/* double-width bold font */
    907     , fWItal			/* double-width italic font */
    908     , fWBtal			/* double-width bold-italic font */
    909 #endif
    910     , fMAX
    911 } VTFontEnum;
    912 
    913 /*
    914  * Indices for cachedGCs.c (unrelated to VTFontEnum).
    915  */
    916 typedef enum {
    917     gcNorm = 0
    918     , gcBold
    919     , gcNormReverse
    920     , gcBoldReverse
    921     , gcFiller
    922     , gcBorder
    923 #if OPT_BOX_CHARS || OPT_WIDE_CHARS
    924     , gcLine
    925     , gcDots
    926 #endif
    927 #if OPT_DEC_CHRSET
    928     , gcCNorm
    929     , gcCBold
    930 #endif
    931 #if OPT_WIDE_CHARS
    932     , gcWide
    933     , gcWBold
    934     , gcWideReverse
    935     , gcWBoldReverse
    936 #endif
    937     , gcVTcursNormal
    938     , gcVTcursFilled
    939     , gcVTcursReverse
    940     , gcVTcursOutline
    941 #if OPT_TEK4014
    942     , gcTKcurs
    943 #endif
    944     , gcMAX
    945 } CgsEnum;
    946 
    947 #define for_each_text_gc(n) for (n = gcNorm; n < gcVTcursNormal; ++n)
    948 #define for_each_curs_gc(n) for (n = gcVTcursNormal; n <= gcVTcursOutline; ++n)
    949 #define for_each_gc(n)      for (n = gcNorm; n < gcMAX; ++n)
    950 
    951 /*
    952  * Indices for the normal terminal colors in screen.Tcolors[].
    953  * See also OscTextColors, which has corresponding values.
    954  */
    955 typedef enum {
    956     TEXT_FG = 0			/* text foreground */
    957     , TEXT_BG			/* text background */
    958     , TEXT_CURSOR		/* text cursor */
    959     , MOUSE_FG			/* mouse foreground */
    960     , MOUSE_BG			/* mouse background */
    961 #if OPT_TEK4014
    962     , TEK_FG = 5		/* tektronix foreground */
    963     , TEK_BG			/* tektronix background */
    964 #endif
    965 #if OPT_HIGHLIGHT_COLOR
    966     , HIGHLIGHT_BG = 7		/* highlight background */
    967 #endif
    968 #if OPT_TEK4014
    969     , TEK_CURSOR = 8		/* tektronix cursor */
    970 #endif
    971 #if OPT_HIGHLIGHT_COLOR
    972     , HIGHLIGHT_FG = 9		/* highlight foreground */
    973 #endif
    974     , NCOLORS			/* total number of colors */
    975 } TermColors;
    976 
    977 /*
    978  * Definitions for exec-formatted and insert-formatted actions.
    979  */
    980 typedef void (*FormatSelect) (Widget, char *, char *, CELL *, CELL *);
    981 
    982 typedef struct {
    983     Boolean done;
    984     char *format;
    985     char *buffer;
    986     FormatSelect format_select;
    987 #if OPT_PASTE64
    988     Cardinal base64_paste;
    989 #endif
    990 #if OPT_PASTE64 || OPT_READLINE
    991     unsigned paste_brackets;
    992 #endif
    993 } InternalSelect;
    994 
    995 /*
    996  * Constants for titleModes resource
    997  */
    998 typedef enum {
    999     tmSetBase16 = 1		/* set title using hex-string */
   1000     , tmGetBase16 = 2		/* get title using hex-string */
   1001 #if OPT_WIDE_CHARS
   1002 #define MAX_TITLEMODE 3
   1003     , tmSetUtf8 = 4		/* like utf8Title, but controllable */
   1004     , tmGetUtf8 = 8		/* retrieve title encoded as UTF-8 */
   1005 #else
   1006 #define MAX_TITLEMODE 1
   1007 #endif
   1008 } TitleModes;
   1009 
   1010 #define ValidTitleMode(code) ((code) >= 0 && (code) <= MAX_TITLEMODE)
   1011 #define IsTitleMode(xw,mode) (((xw)->screen.title_modes & mode) != 0)
   1012 
   1013 #define IsSetUtf8Title(xw) (IsTitleMode(xw, tmSetUtf8) \
   1014 			 || ((xw)->screen.utf8_title) \
   1015 			 || ((xw)->screen.c1_printable))
   1016 
   1017 #include <xcharmouse.h>
   1018 
   1019 /*
   1020  * For readability...
   1021  */
   1022 #define nrc_percent   100
   1023 #define nrc_dquote    200
   1024 #define nrc_ampersand 300
   1025 typedef enum {
   1026     nrc_ASCII = 0
   1027     ,nrc_British		/* vt100 */
   1028     ,nrc_British_Latin_1	/* vt3xx */
   1029     ,nrc_DEC_Cyrillic		/* vt5xx */
   1030     ,nrc_DEC_Spec_Graphic	/* vt100 */
   1031     ,nrc_DEC_Alt_Chars		/* vt100 */
   1032     ,nrc_DEC_Alt_Graphics	/* vt100 */
   1033     ,nrc_DEC_Supp		/* vt2xx */
   1034     ,nrc_DEC_Supp_Graphic	/* vt3xx */
   1035     ,nrc_DEC_Technical		/* vt3xx */
   1036     ,nrc_DEC_UPSS		/* vt3xx */
   1037     ,nrc_Dutch			/* vt2xx */
   1038     ,nrc_Finnish		/* vt2xx */
   1039     ,nrc_Finnish2		/* vt2xx */
   1040     ,nrc_French			/* vt2xx */
   1041     ,nrc_French2		/* vt2xx */
   1042     ,nrc_French_Canadian	/* vt2xx */
   1043     ,nrc_French_Canadian2	/* vt3xx */
   1044     ,nrc_German			/* vt2xx */
   1045     ,nrc_Greek			/* vt5xx */
   1046     ,nrc_DEC_Greek_Supp		/* vt5xx */
   1047     ,nrc_ISO_Greek_Supp		/* vt5xx */
   1048     ,nrc_DEC_Hebrew_Supp	/* vt5xx */
   1049     ,nrc_Hebrew			/* vt5xx */
   1050     ,nrc_ISO_Hebrew_Supp	/* vt5xx */
   1051     ,nrc_Italian		/* vt2xx */
   1052     ,nrc_ISO_Latin_1_Supp	/* vt3xx */
   1053     ,nrc_ISO_Latin_2_Supp	/* vt5xx */
   1054     ,nrc_ISO_Latin_5_Supp	/* vt5xx */
   1055     ,nrc_ISO_Latin_Cyrillic	/* vt5xx */
   1056     ,nrc_JIS_Katakana		/* vt382 */
   1057     ,nrc_JIS_Roman		/* vt382 */
   1058     ,nrc_Norwegian_Danish	/* vt3xx */
   1059     ,nrc_Norwegian_Danish2	/* vt2xx */
   1060     ,nrc_Norwegian_Danish3	/* vt2xx */
   1061     ,nrc_Portugese		/* vt3xx */
   1062     ,nrc_Russian		/* vt5xx */
   1063     ,nrc_SCS_NRCS		/* vt5xx - probably Serbo/Croatian */
   1064     ,nrc_Spanish		/* vt2xx */
   1065     ,nrc_Swedish		/* vt2xx */
   1066     ,nrc_Swedish2		/* vt2xx */
   1067     ,nrc_Swiss			/* vt2xx */
   1068     ,nrc_DEC_Turkish_Supp	/* vt5xx */
   1069     ,nrc_Turkish		/* vt5xx */
   1070     ,nrc_Unknown
   1071 } DECNRCM_codes;
   1072 
   1073 /*
   1074  * Default and alternate codes for user-preferred supplemental set.
   1075  */
   1076 #define DFT_UPSS nrc_DEC_Supp_Graphic
   1077 #define ALT_UPSS nrc_ISO_Latin_1_Supp
   1078 #define PreferredUPSS(screen)	((screen)->prefer_latin1 ? ALT_UPSS : DFT_UPSS)
   1079 
   1080 /*
   1081  * Use this enumerated type to check consistency among dpmodes(), savemodes()
   1082  * restoremodes() and do_dec_rqm().
   1083  */
   1084 typedef enum {
   1085     srm_DECCKM = 1		/* Cursor Keys Mode */
   1086     ,srm_DECANM = 2		/* ANSI Mode */
   1087     ,srm_DECCOLM = 3		/* Column Mode */
   1088     ,srm_DECSCLM = 4		/* Scrolling Mode */
   1089     ,srm_DECSCNM = 5		/* Screen Mode */
   1090     ,srm_DECOM = 6		/* Origin Mode */
   1091     ,srm_DECAWM = 7		/* Autowrap Mode */
   1092     ,srm_DECARM = 8		/* Autorepeat Mode */
   1093     ,srm_X10_MOUSE = SET_X10_MOUSE
   1094 #if OPT_TOOLBAR
   1095     ,srm_RXVT_TOOLBAR = 10
   1096 #else
   1097     ,srm_DECEDM = 10		/* vt330:edit */
   1098 #endif
   1099     ,srm_DECLTM = 11		/* vt330:line transmit */
   1100 #if OPT_BLINK_CURS
   1101     ,srm_ATT610_BLINK = 12
   1102     ,srm_CURSOR_BLINK_OPS = 13
   1103     ,srm_XOR_CURSOR_BLINKS = 14
   1104 #else
   1105     ,srm_DECKANAM = 12		/* vt382:Katakana shift */
   1106     ,srm_DECSCFDM = 13		/* vt330:space compression field delimiter */
   1107     ,srm_DECTEM = 14		/* vt330:transmission execution */
   1108 #endif
   1109     ,srm_DECEKEM = 16		/* vt330:edit key execution */
   1110     ,srm_DECPFF = 18		/* vt220:Print Form Feed Mode */
   1111     ,srm_DECPEX = 19		/* vt220:Printer Extent Mode */
   1112     ,srm_DECTCEM = 25		/* Text Cursor Enable Mode */
   1113     ,srm_RXVT_SCROLLBAR = 30
   1114     ,srm_DECRLM = 34		/* vt510:Cursor Right to Left Mode */
   1115 #if OPT_SHIFT_FONTS
   1116     ,srm_RXVT_FONTSIZE = 35	/* also vt520:DECHEBM */
   1117 #else
   1118     ,srm_DECHEBM = 35		/* vt520:Hebrew keyboard mapping */
   1119 #endif
   1120     ,srm_DECHEM = 36		/* vt510:Hebrew Encoding Mode */
   1121 #if OPT_TEK4014
   1122     ,srm_DECTEK = 38
   1123 #endif
   1124     ,srm_132COLS = 40
   1125     ,srm_CURSES_HACK = 41
   1126     ,srm_DECNRCM = 42		/* National Replacement Character Set Mode */
   1127 #if OPT_PRINT_GRAPHICS
   1128     ,srm_DECGEPM = 43		/* Graphics Expanded Print Mode */
   1129 #endif
   1130     ,srm_MARGIN_BELL = 44	/* also DECGPCM (Graphics Print Color Mode) */
   1131     ,srm_REVERSEWRAP = 45	/* also DECGPCS (Graphics Print Color Syntax) */
   1132 #ifdef ALLOWLOGGING
   1133     ,srm_ALLOWLOGGING = 46	/* also DECGPBM (Graphics Print Background Mode) */
   1134 #elif OPT_PRINT_GRAPHICS
   1135     ,srm_DECGPBM = 46		/* Graphics Print Background Mode */
   1136 #endif
   1137     ,srm_ALTBUF = 47		/* also DECGRPM (Graphics Rotated Print Mode) */
   1138     ,srm_DEC131TM = 53		/* vt330:VT131 transmit */
   1139     ,srm_DECNAKB = 57		/* vt510:Greek/N-A Keyboard Mapping */
   1140     ,srm_DECIPEM = 58		/* vt510:IBM ProPrinter Emulation Mode */
   1141     ,srm_DECKKDM = 59   	/* vt382:Kanji/Katakana */
   1142     ,srm_DECHCCM = 60		/* vt420:Horizontal Cursor-Coupling Mode */
   1143     ,srm_DECVCCM = 61		/* vt420:Vertical Cursor-Coupling Mode */
   1144     ,srm_DECPCCM = 64		/* vt420:Page Cursor-Coupling Mode */
   1145     ,srm_DECNKM = 66		/* vt420:Numeric Keypad Mode */
   1146     ,srm_DECBKM = 67		/* vt420:Backarrow Key mode */
   1147     ,srm_DECKBUM = 68		/* vt420:Keyboard Usage mode */
   1148     ,srm_DECLRMM = 69		/* vt420:Vertical Split Screen Mode (DECVSSM) */
   1149     ,srm_DECXRLM = 73		/* vt420:Transmit Rate Limiting */
   1150 #if OPT_SIXEL_GRAPHICS
   1151     ,srm_DECSDM = 80		/* vt320:Sixel Display Mode */
   1152 #endif
   1153     ,srm_DECKPM = 81		/* vt420:Key Position Mode */
   1154     ,srm_DECNCSM = 95		/* vt510:No Clearing Screen On Column Change */
   1155     ,srm_DECRLCM = 96		/* vt510:Right-to-Left Copy */
   1156     ,srm_DECCRTSM = 97		/* vt510:CRT Save Mode */
   1157     ,srm_DECARSM = 98		/* vt510:Auto Resize Mode */
   1158     ,srm_DECMCM = 99		/* vt510:Modem Control Mode */
   1159     ,srm_DECAAM = 100		/* vt510:Auto Answerback Mode */
   1160     ,srm_DECCANSM = 101		/* vt510:Conceal Answerback Message Mode */
   1161     ,srm_DECNULM = 102		/* vt510:Ignoring Null Mode */
   1162     ,srm_DECHDPXM = 103		/* vt510:Half-Duplex Mode */
   1163     ,srm_DECESKM = 104		/* vt510:enable secondary keyboard language */
   1164     ,srm_DECOSCNM = 106		/* vt510:Overscan Mode */
   1165     ,srm_DECNUMLK = 108		/* vt510:Num Lock Mode */
   1166     ,srm_DECCAPSLK = 109	/* vt510:Caps Lock Mode */
   1167     ,srm_DECKLHIM = 110		/* vt510:Keyboard LEDs Host Indicator Mode */
   1168     ,srm_DECFWM = 111		/* vt520:Framed Windows Mode */
   1169     ,srm_DECRPL = 112		/* vt520:Review Previous Lines */
   1170     ,srm_DECHWUM = 113		/* vt520:Host Wake-Up */
   1171     ,srm_DECATCUM = 114		/* vt520:Alternate Text Color Underline */
   1172     ,srm_DECATCBM = 115		/* vt520:Alternate Text Color Blink */
   1173     ,srm_DECBBSM = 116		/* vt520:Bold and Blink Style Mode */
   1174     ,srm_DECECM = 117		/* vt520:Erase Color Mode */
   1175     ,srm_VT200_MOUSE = SET_VT200_MOUSE
   1176     ,srm_VT200_HIGHLIGHT_MOUSE = SET_VT200_HIGHLIGHT_MOUSE
   1177     ,srm_BTN_EVENT_MOUSE = SET_BTN_EVENT_MOUSE
   1178     ,srm_ANY_EVENT_MOUSE = SET_ANY_EVENT_MOUSE
   1179 #if OPT_FOCUS_EVENT
   1180     ,srm_FOCUS_EVENT_MOUSE = SET_FOCUS_EVENT_MOUSE
   1181 #endif
   1182     ,srm_EXT_MODE_MOUSE = SET_EXT_MODE_MOUSE
   1183     ,srm_SGR_EXT_MODE_MOUSE = SET_SGR_EXT_MODE_MOUSE
   1184     ,srm_URXVT_EXT_MODE_MOUSE = SET_URXVT_EXT_MODE_MOUSE
   1185     ,srm_PIXEL_POSITION_MOUSE = SET_PIXEL_POSITION_MOUSE
   1186     ,srm_ALTERNATE_SCROLL = SET_ALTERNATE_SCROLL
   1187     ,srm_RXVT_SCROLL_TTY_OUTPUT = 1010
   1188     ,srm_RXVT_SCROLL_TTY_KEYPRESS = 1011
   1189     ,srm_FAST_SCROLL = 1014
   1190     ,srm_EIGHT_BIT_META = 1034
   1191 #if OPT_NUM_LOCK
   1192     ,srm_REAL_NUMLOCK = 1035
   1193     ,srm_META_SENDS_ESC = 1036
   1194 #endif
   1195     ,srm_DELETE_IS_DEL = 1037
   1196 #if OPT_NUM_LOCK
   1197     ,srm_ALT_SENDS_ESC = 1039
   1198 #endif
   1199     ,srm_KEEP_SELECTION = 1040
   1200     ,srm_SELECT_TO_CLIPBOARD = 1041
   1201     ,srm_BELL_IS_URGENT = 1042
   1202     ,srm_POP_ON_BELL = 1043
   1203     ,srm_KEEP_CLIPBOARD = 1044
   1204     ,srm_REVERSEWRAP2 = 1045	/* reverse-wrap without limits */
   1205     ,srm_ALLOW_ALTBUF = 1046
   1206     ,srm_OPT_ALTBUF = 1047
   1207     ,srm_SAVE_CURSOR = 1048
   1208     ,srm_OPT_ALTBUF_CURSOR = 1049
   1209 #if OPT_TCAP_FKEYS
   1210     ,srm_TCAP_FKEYS = 1050
   1211 #endif
   1212 #if OPT_SUN_FUNC_KEYS
   1213     ,srm_SUN_FKEYS = 1051
   1214 #endif
   1215 #if OPT_HP_FUNC_KEYS
   1216     ,srm_HP_FKEYS = 1052
   1217 #endif
   1218 #if OPT_SCO_FUNC_KEYS
   1219     ,srm_SCO_FKEYS = 1053
   1220 #endif
   1221     ,srm_LEGACY_FKEYS = 1060
   1222 #if OPT_SUNPC_KBD
   1223     ,srm_VT220_FKEYS = 1061
   1224 #endif
   1225 #if OPT_GRAPHICS
   1226     ,srm_PRIVATE_COLOR_REGISTERS = 1070
   1227 #endif
   1228 #if OPT_PASTE64 || OPT_READLINE
   1229     ,srm_PASTE_IN_BRACKET = SET_PASTE_IN_BRACKET
   1230 #endif
   1231 #if OPT_READLINE
   1232     ,srm_BUTTON1_MOVE_POINT = SET_BUTTON1_MOVE_POINT
   1233     ,srm_BUTTON2_MOVE_POINT = SET_BUTTON2_MOVE_POINT
   1234     ,srm_DBUTTON3_DELETE = SET_DBUTTON3_DELETE
   1235     ,srm_PASTE_QUOTE = SET_PASTE_QUOTE
   1236     ,srm_PASTE_LITERAL_NL = SET_PASTE_LITERAL_NL
   1237 #endif				/* OPT_READLINE */
   1238 #if OPT_SIXEL_GRAPHICS
   1239     ,srm_SIXEL_SCROLLS_RIGHT = 8452
   1240 #endif
   1241 } DECSET_codes;
   1242 
   1243 /* internal codes for selection atoms */
   1244 typedef enum {
   1245     PRIMARY_CODE = 0
   1246     ,CLIPBOARD_CODE
   1247     ,SECONDARY_CODE
   1248     ,MAX_SELECTION_CODES
   1249 } SelectionCodes;
   1250 
   1251 /* indices for mapping multiple clicks to selection types */
   1252 typedef enum {
   1253     Select_CHAR=0
   1254     ,Select_WORD
   1255     ,Select_LINE
   1256     ,Select_GROUP
   1257     ,Select_PAGE
   1258     ,Select_ALL
   1259 #if OPT_SELECT_REGEX
   1260     ,Select_REGEX
   1261 #endif
   1262     ,NSELECTUNITS
   1263 } SelectUnit;
   1264 
   1265 #if OPT_BLINK_CURS
   1266 typedef enum {
   1267     cbFalse = 0
   1268     , cbTrue
   1269     , cbAlways
   1270     , cbNever
   1271     , cbLAST
   1272 } BlinkOps;
   1273 #endif
   1274 
   1275 typedef enum {
   1276     ecSetColor = 1
   1277     , ecGetColor
   1278     , ecGetAnsiColor
   1279     , ecLAST
   1280 } ColorOps;
   1281 
   1282 typedef enum {
   1283     efSetFont = 1
   1284     , efGetFont
   1285     , efLAST
   1286 } FontOps;
   1287 
   1288 typedef enum {
   1289     esFalse = 0
   1290     , esTrue
   1291     , esAlways
   1292     , esNever
   1293     , esLAST
   1294 } FullscreenOps;
   1295 
   1296 #ifndef NO_ACTIVE_ICON
   1297 typedef enum {
   1298     eiFalse = 0
   1299     , eiTrue
   1300     , eiDefault
   1301     , eiLAST
   1302 } AIconOps;
   1303 #endif
   1304 
   1305 typedef enum {
   1306     emX10 = 1
   1307     , emLocator
   1308     , emVT200Click
   1309     , emVT200Hilite
   1310     , emAnyButton
   1311     , emAnyEvent
   1312     , emFocusEvent
   1313     , emExtended
   1314     , emSGR
   1315     , emURXVT
   1316     , emAlternateScroll
   1317     , emLAST
   1318 } MouseOps;
   1319 
   1320 typedef enum {
   1321 #define DATA(name) ep##name
   1322     DATA(NUL) = 0
   1323     , DATA(SOH) =  1
   1324     , DATA(STX) =  2
   1325     , DATA(ETX) =  3
   1326     , DATA(EOT) =  4
   1327     , DATA(ENQ) =  5
   1328     , DATA(ACK) =  6
   1329     , DATA(BEL) =  7
   1330     , DATA(BS)  =  8
   1331     , DATA(HT)  =  9
   1332     , DATA(LF)  = 10
   1333     , DATA(VT)  = 11
   1334     , DATA(FF)  = 12
   1335     , DATA(CR)  = 13
   1336     , DATA(SO)  = 14
   1337     , DATA(SI)  = 15
   1338     , DATA(DLE) = 16
   1339     , DATA(DC1) = 17
   1340     , DATA(DC2) = 18
   1341     , DATA(DC3) = 19
   1342     , DATA(DC4) = 20
   1343     , DATA(NAK) = 21
   1344     , DATA(SYN) = 22
   1345     , DATA(ETB) = 23
   1346     , DATA(CAN) = 24
   1347     , DATA(EM)  = 25
   1348     , DATA(SUB) = 26
   1349     , DATA(ESC) = 27
   1350     , DATA(FS)  = 28
   1351     , DATA(GS)  = 29
   1352     , DATA(RS)  = 30
   1353     , DATA(US)  = 31
   1354     /* aliases */
   1355     , DATA(C0)
   1356     , DATA(DEL)
   1357     , DATA(STTY)
   1358 #undef DATA
   1359     , epLAST
   1360 } PasteControls;
   1361 
   1362 typedef enum {			/* legal values for keyboard.shift_escape */
   1363     ssFalse = 0
   1364     , ssTrue = 1
   1365     , ssAlways = 2
   1366     , ssNever = 3
   1367     , ssLAST
   1368 } ShiftEscapeOps;
   1369 
   1370 /*
   1371  * xterm uses these codes for the its push-SGR feature.  They match where
   1372  * possible the corresponding SGR coding.  The foreground and background colors
   1373  * do not fit into that scheme (because they are a set of ranges), so those are
   1374  * chosen arbitrarily -TD
   1375  */
   1376 typedef enum {
   1377     psBOLD = 1
   1378 #if OPT_WIDE_ATTRS
   1379     , psATR_FAINT = 2
   1380     , psATR_ITALIC = 3
   1381 #endif
   1382     , psUNDERLINE = 4
   1383     , psBLINK = 5
   1384     , psINVERSE = 7
   1385     , psINVISIBLE = 8
   1386 #if OPT_WIDE_ATTRS
   1387     , psATR_STRIKEOUT = 9
   1388 #endif
   1389     /* SGR 10-19 correspond to primary/alternate fonts, currently unused */
   1390 #if OPT_ISO_COLORS
   1391     , psFG_COLOR_obs = 10
   1392     , psBG_COLOR_obs = 11
   1393 #endif
   1394 #if OPT_WIDE_ATTRS
   1395     , psATR_DBL_UNDER = 21
   1396 #endif
   1397     /* SGR 22-29 mostly are used to reset SGR 1-9 */
   1398 #if OPT_ISO_COLORS
   1399     , psFG_COLOR = 30	/* stack maps many colors to one state */
   1400     , psBG_COLOR = 31
   1401 #endif
   1402     , MAX_PUSH_SGR
   1403 } PushSGR;
   1404 
   1405 typedef enum {
   1406     etSetTcap = 1
   1407     , etGetTcap
   1408     , etLAST
   1409 } TcapOps;
   1410 
   1411 typedef enum {
   1412     /* 1-23 are chosen to be the same as the control-sequence coding */
   1413     ewRestoreWin = 1
   1414     , ewMinimizeWin = 2
   1415     , ewSetWinPosition = 3
   1416     , ewSetWinSizePixels = 4
   1417     , ewRaiseWin = 5
   1418     , ewLowerWin = 6
   1419     , ewRefreshWin = 7
   1420     , ewSetWinSizeChars = 8
   1421 #if OPT_MAXIMIZE
   1422     , ewMaximizeWin = 9
   1423     , ewFullscreenWin = 10
   1424 #endif
   1425     , ewGetWinState = 11
   1426     , ewGetWinPosition = 13
   1427     , ewGetWinSizePixels = 14
   1428 #if OPT_MAXIMIZE
   1429     , ewGetScreenSizePixels = 15
   1430     , ewGetCharSizePixels = 16
   1431 #endif
   1432     , ewGetWinSizeChars = 18
   1433 #if OPT_MAXIMIZE
   1434     , ewGetScreenSizeChars = 19
   1435 #endif
   1436     , ewGetIconTitle = 20
   1437     , ewGetWinTitle = 21
   1438     , ewPushTitle = 22
   1439     , ewPopTitle = 23
   1440     /* these do not fit into that scheme, which is why we use an array */
   1441     , ewSetWinLines
   1442     , ewSetXprop
   1443     , ewGetSelection
   1444     , ewSetSelection
   1445     , ewGetChecksum
   1446     , ewSetChecksum
   1447     /* get the size of the array... */
   1448     , ewLAST
   1449 } WindowOps;
   1450 
   1451 /***====================================================================***/
   1452 
   1453 #define	COLOR_DEFINED(s,w)	((s)->which & (unsigned) (1<<(w)))
   1454 #define	COLOR_VALUE(s,w)	((s)->colors[w])
   1455 #define	SET_COLOR_VALUE(s,w,v)	(((s)->colors[w] = (v)), UIntSet((s)->which, (1<<(w))))
   1456 
   1457 #define	COLOR_NAME(s,w)		((s)->names[w])
   1458 #define	SET_COLOR_NAME(s,w,v)	(((s)->names[w] = (v)), ((s)->which |= (unsigned) (1<<(w))))
   1459 
   1460 #define	UNDEFINE_COLOR(s,w)	((s)->which &= (~((w)<<1)))
   1461 
   1462 /***====================================================================***/
   1463 
   1464 #if OPT_ISO_COLORS
   1465 #if OPT_WIDE_ATTRS
   1466 #define COLOR_FLAGS		(FG_COLOR | BG_COLOR | ATR_DIRECT_FG | ATR_DIRECT_BG)
   1467 #else
   1468 #define COLOR_FLAGS		(FG_COLOR | BG_COLOR)
   1469 #endif
   1470 #define TERM_COLOR_FLAGS(xw)	((xw)->flags & COLOR_FLAGS)
   1471 #define COLOR_0		0
   1472 #define COLOR_1		1
   1473 #define COLOR_2		2
   1474 #define COLOR_3		3
   1475 #define COLOR_4		4
   1476 #define COLOR_5		5
   1477 #define COLOR_6		6
   1478 #define COLOR_7		7
   1479 #define COLOR_8		8
   1480 #define COLOR_9		9
   1481 #define COLOR_10	10
   1482 #define COLOR_11	11
   1483 #define COLOR_12	12
   1484 #define COLOR_13	13
   1485 #define COLOR_14	14
   1486 #define COLOR_15	15
   1487 #define MIN_ANSI_COLORS 16
   1488 
   1489 #if OPT_256_COLORS
   1490 # define NUM_ANSI_COLORS 256
   1491 #elif OPT_88_COLORS
   1492 # define NUM_ANSI_COLORS 88
   1493 #else
   1494 # define NUM_ANSI_COLORS MIN_ANSI_COLORS
   1495 #endif
   1496 
   1497 #define okIndexedColor(n) ((n) >= 0 && (n) < NUM_ANSI_COLORS)
   1498 
   1499 #if NUM_ANSI_COLORS > MIN_ANSI_COLORS
   1500 # define OPT_EXT_COLORS  1
   1501 #else
   1502 # define OPT_EXT_COLORS  0
   1503 #endif
   1504 
   1505 #define COLOR_BD	(NUM_ANSI_COLORS)	/* BOLD */
   1506 #define COLOR_UL	(NUM_ANSI_COLORS+1)	/* UNDERLINE */
   1507 #define COLOR_BL	(NUM_ANSI_COLORS+2)	/* BLINK */
   1508 #define COLOR_RV	(NUM_ANSI_COLORS+3)	/* REVERSE */
   1509 
   1510 #if OPT_WIDE_ATTRS
   1511 #define COLOR_IT	(NUM_ANSI_COLORS+4)	/* ITALIC */
   1512 #define MAXCOLORS	(NUM_ANSI_COLORS+5)
   1513 #else
   1514 #define MAXCOLORS	(NUM_ANSI_COLORS+4)
   1515 #endif
   1516 
   1517 #ifndef DFT_COLORMODE
   1518 #define DFT_COLORMODE True	/* default colorMode resource */
   1519 #endif
   1520 
   1521 #define UseItalicFont(screen) (!(screen)->colorITMode)
   1522 
   1523 #define ReverseOrHilite(screen,flags,hilite) \
   1524 		(( screen->colorRVMode && hilite ) || \
   1525 		    ( !screen->colorRVMode && \
   1526 		      (( (flags & INVERSE) && !hilite) || \
   1527 		       (!(flags & INVERSE) &&  hilite)) ))
   1528 
   1529 #else	/* !OPT_ISO_COLORS */
   1530 
   1531 #define TERM_COLOR_FLAGS(xw) 0
   1532 
   1533 #define UseItalicFont(screen) True
   1534 #define ReverseOrHilite(screen,flags,hilite) \
   1535 		      (( (flags & INVERSE) && !hilite) || \
   1536 		       (!(flags & INVERSE) &&  hilite))
   1537 
   1538 #endif	/* OPT_ISO_COLORS */
   1539 
   1540 typedef enum {
   1541 	XK_TCAPNAME = 3
   1542 	/* Define fake XK codes, we need those for the fake color response in
   1543 	 * xtermcapKeycode().
   1544 	 */
   1545 #if OPT_ISO_COLORS
   1546 	, XK_COLORS
   1547 	, XK_RGB
   1548 #endif
   1549 } TcapQuery;
   1550 
   1551 #if OPT_AIX_COLORS
   1552 #define if_OPT_AIX_COLORS(screen, code) if(screen->colorMode) code
   1553 #else
   1554 #define if_OPT_AIX_COLORS(screen, code) /* nothing */
   1555 #endif
   1556 
   1557 #if OPT_256_COLORS || OPT_88_COLORS || OPT_ISO_COLORS
   1558 # define if_OPT_ISO_COLORS(screen, code) if (screen->colorMode) code
   1559 #else
   1560 # define if_OPT_ISO_COLORS(screen, code) /* nothing */
   1561 #endif
   1562 
   1563 #if OPT_DIRECT_COLOR
   1564 # define if_OPT_DIRECT_COLOR(screen, code) if (screen->direct_color) code
   1565 # define if_OPT_DIRECT_COLOR2(screen, test, code) if (screen->direct_color && (test)) code
   1566 #else
   1567 # define if_OPT_DIRECT_COLOR(screen, code) /* nothing */
   1568 # define if_OPT_DIRECT_COLOR2(screen, test, code) /* nothing */
   1569 #endif
   1570 
   1571 #define if_OPT_DIRECT_COLOR2_else(cond, test, stmt) \
   1572 	if_OPT_DIRECT_COLOR2(cond, test, stmt else)
   1573 
   1574 #define COLOR_RES_NAME(root) "color" root
   1575 
   1576 #if OPT_COLOR_CLASS
   1577 #define COLOR_RES_CLASS(root) "Color" root
   1578 #else
   1579 #define COLOR_RES_CLASS(root) XtCForeground
   1580 #endif
   1581 
   1582 #define COLOR_RES(root,offset,value) Sres(COLOR_RES_NAME(root), COLOR_RES_CLASS(root), offset.resource, value)
   1583 #define COLOR_RES2(name,class,offset,value) Sres(name, class, offset.resource, value)
   1584 
   1585 #define CLICK_RES_NAME(count)  "on" count "Clicks"
   1586 #define CLICK_RES_CLASS(count) "On" count "Clicks"
   1587 #define CLICK_RES(count,offset,value) Sres(CLICK_RES_NAME(count), CLICK_RES_CLASS(count), offset, value)
   1588 
   1589 /***====================================================================***/
   1590 
   1591 #if OPT_DEC_CHRSET
   1592 #define if_OPT_DEC_CHRSET(code) code
   1593 	/* Use 2 bits for encoding the double high/wide sense of characters */
   1594 #define CSET_SWL        0	/* character set: single-width line */
   1595 #define CSET_DHL_TOP    1	/* character set: double-height top line */
   1596 #define CSET_DHL_BOT    2	/* character set: double-height bottom line */
   1597 #define CSET_DWL        3	/* character set: double-width line */
   1598 #define NUM_CHRSET      8	/* normal/bold and 4 CSET_xxx values */
   1599 
   1600 	/* Use remaining bits for encoding the other character-sets */
   1601 #define CSET_NORMAL(code)  ((code) == CSET_SWL)
   1602 #define CSET_DOUBLE(code)  (!CSET_NORMAL(code) && !CSET_EXTEND(code))
   1603 #define CSET_EXTEND(code)  ((int)(code) > CSET_DWL)
   1604 
   1605 #define DBLCS_BITS            4
   1606 #define DBLCS_MASK            BITS2MASK(DBLCS_BITS)
   1607 
   1608 #define GetLineDblCS(ld)      ((ld) != NULL ? (((ld)->bufHead >> LINEFLAG_BITS) & DBLCS_MASK) : 0)
   1609 #define SetLineDblCS(ld,cs)   (ld)->bufHead = (RowData) ((ld->bufHead & LINEFLAG_MASK) | (cs << LINEFLAG_BITS))
   1610 
   1611 #define LineCharSet(screen, ld) \
   1612 	(unsigned) ((CSET_DOUBLE(GetLineDblCS(ld))) \
   1613 		    ? GetLineDblCS(ld) \
   1614 		    : (screen)->cur_chrset)
   1615 #define LineMaxCol(screen, ld) \
   1616 	(CSET_DOUBLE(GetLineDblCS(ld)) \
   1617 	 ? (screen->max_col / 2) \
   1618 	 : (screen->max_col))
   1619 #define LineCursorX(screen, ld, col) \
   1620 	(CSET_DOUBLE(GetLineDblCS(ld)) \
   1621 	 ? CursorX(screen, 2*(col)) \
   1622 	 : CursorX(screen, (col)))
   1623 #define LineFontWidth(screen, ld) \
   1624 	(CSET_DOUBLE(GetLineDblCS(ld)) \
   1625 	 ? 2*FontWidth(screen) \
   1626 	 : FontWidth(screen))
   1627 #else
   1628 
   1629 #define if_OPT_DEC_CHRSET(code) /*nothing*/
   1630 #define CSET_SWL                        0
   1631 #define GetLineDblCS(ld)                0U
   1632 #define LineCharSet(screen, ld)         0U
   1633 #define LineMaxCol(screen, ld)          screen->max_col
   1634 #define LineCursorX(screen, ld, col)    CursorX(screen, col)
   1635 #define LineFontWidth(screen, ld)       FontWidth(screen)
   1636 
   1637 #endif
   1638 
   1639 #if OPT_LUIT_PROG && !OPT_WIDE_CHARS
   1640 /* Luit requires the wide-chars configuration */
   1641 #undef OPT_LUIT_PROG
   1642 #define OPT_LUIT_PROG 0
   1643 #endif
   1644 
   1645 /***====================================================================***/
   1646 
   1647 #if OPT_DEC_RECTOPS
   1648 #define if_OPT_DEC_RECTOPS(stmt) stmt
   1649 #else
   1650 #define if_OPT_DEC_RECTOPS(stmt) /* nothing */
   1651 #endif
   1652 
   1653 /***====================================================================***/
   1654 
   1655 #define CONTROL(a) ((a) & 037)
   1656 
   1657 #define XTERM_ERASE CONTROL('H')
   1658 #define XTERM_LNEXT CONTROL('V')
   1659 
   1660 /***====================================================================***/
   1661 
   1662 #if OPT_TEK4014
   1663 #define TEK4014_ACTIVE(xw)      ((xw)->misc.TekEmu)
   1664 #define TEK4014_SHOWN(xw)       ((xw)->misc.Tshow)
   1665 #define CURRENT_EMU_VAL(tek,vt) (TEK4014_ACTIVE(term) ? tek : vt)
   1666 #define CURRENT_EMU()           CURRENT_EMU_VAL((Widget)tekWidget, (Widget)term)
   1667 #else
   1668 #define TEK4014_ACTIVE(screen)  0
   1669 #define TEK4014_SHOWN(xw)       0
   1670 #define CURRENT_EMU_VAL(tek,vt) (vt)
   1671 #define CURRENT_EMU()           ((Widget)term)
   1672 #endif
   1673 
   1674 /***====================================================================***/
   1675 
   1676 #if OPT_TOOLBAR
   1677 #define SHELL_OF(widget) XtParent(XtParent(widget))
   1678 #else
   1679 #define SHELL_OF(widget) XtParent(widget)
   1680 #endif
   1681 
   1682 /***====================================================================***/
   1683 
   1684 #if OPT_VT52_MODE
   1685 #define if_OPT_VT52_MODE(screen, code) if(screen->vtXX_level == 0) code
   1686 #else
   1687 #define if_OPT_VT52_MODE(screen, code) /* nothing */
   1688 #endif
   1689 
   1690 /***====================================================================***/
   1691 
   1692 #if OPT_XMC_GLITCH
   1693 #define if_OPT_XMC_GLITCH(screen, code) if(screen->xmc_glitch) code
   1694 #define XMC_GLITCH 1	/* the character we'll show */
   1695 #define XMC_FLAGS (INVERSE|UNDERLINE|BOLD|BLINK)
   1696 #else
   1697 #define if_OPT_XMC_GLITCH(screen, code) /* nothing */
   1698 #endif
   1699 
   1700 /***====================================================================***/
   1701 
   1702 typedef unsigned IFlags;	/* at least 32 bits */
   1703 
   1704 #if OPT_WIDE_ATTRS
   1705 typedef unsigned short IAttr;	/* at least 16 bits */
   1706 #else
   1707 typedef unsigned char IAttr;	/* at least 8 bits */
   1708 #endif
   1709 
   1710 /***====================================================================***/
   1711 
   1712 #define LO_BYTE(ch) CharOf((ch) & 0xff)
   1713 #define HI_BYTE(ch) CharOf((ch) >> 8)
   1714 
   1715 #if OPT_WIDE_CHARS
   1716 #define if_OPT_WIDE_CHARS(screen, code) if(screen->wide_chars) code
   1717 #define if_WIDE_OR_NARROW(screen, wide, narrow) if(screen->wide_chars) wide else narrow
   1718 #define NARROW_ICHAR    0xffff
   1719 #if OPT_WIDER_ICHAR
   1720 #define is_NON_CHAR(c)          (((c) >= 0xffd0 && (c) <= 0xfdef) || \
   1721                                  (((c) & 0xffff) >= 0xfffe))
   1722 #define is_UCS_SPECIAL(c)       ((c) >= 0xfff0 && (c) <= 0xffff)
   1723 #define WIDEST_ICHAR    0x1fffff
   1724 typedef unsigned IChar;         /* for 8-21 bit characters */
   1725 #else
   1726 #define is_NON_CHAR(c)          (((c) >= 0xffd0 && (c) <= 0xfdef) || \
   1727                                  ((c) >= 0xfffe && (c) <= 0xffff))
   1728 #define is_UCS_SPECIAL(c)       ((c) >= 0xfff0)
   1729 #define WIDEST_ICHAR    NARROW_ICHAR
   1730 typedef unsigned short IChar;	/* for 8-16 bit characters */
   1731 #endif
   1732 #else	/* !OPT_WIDE_CHARS */
   1733 #undef OPT_WIDER_ICHAR
   1734 #define OPT_WIDER_ICHAR 0
   1735 #define is_NON_CHAR(c)          ((c) > 255)
   1736 #define if_OPT_WIDE_CHARS(screen, code) /* nothing */
   1737 #define if_WIDE_OR_NARROW(screen, wide, narrow) narrow
   1738 typedef unsigned char IChar;	/* for 8-bit characters */
   1739 #endif
   1740 
   1741 /***====================================================================***/
   1742 
   1743 #ifndef RES_OFFSET
   1744 #define RES_OFFSET(offset) XtOffsetOf(XtermWidgetRec, offset)
   1745 #endif
   1746 
   1747 #define RES_NAME(name) name
   1748 #define RES_CLASS(name) name
   1749 
   1750 #define Bres(name, class, offset, dftvalue) \
   1751 	{RES_NAME(name), RES_CLASS(class), XtRBoolean, sizeof(Boolean), \
   1752 	 RES_OFFSET(offset), XtRImmediate, (XtPointer) dftvalue}
   1753 
   1754 #define Cres(name, class, offset, dftvalue) \
   1755 	{RES_NAME(name), RES_CLASS(class), XtRPixel, sizeof(Pixel), \
   1756 	 RES_OFFSET(offset), XtRString, DECONST(char,dftvalue)}
   1757 
   1758 #define Tres(name, class, offset, dftvalue) \
   1759 	COLOR_RES2(name, class, screen.Tcolors[offset], dftvalue) \
   1760 
   1761 #define Fres(name, class, offset, dftvalue) \
   1762 	{RES_NAME(name), RES_CLASS(class), XtRFontStruct, sizeof(XFontStruct *), \
   1763 	 RES_OFFSET(offset), XtRString, DECONST(char,dftvalue)}
   1764 
   1765 #define Ires(name, class, offset, dftvalue) \
   1766 	{RES_NAME(name), RES_CLASS(class), XtRInt, sizeof(int), \
   1767 	 RES_OFFSET(offset), XtRImmediate, (XtPointer) dftvalue}
   1768 
   1769 #define Dres(name, class, offset, dftvalue) \
   1770 	{RES_NAME(name), RES_CLASS(class), XtRFloat, sizeof(float), \
   1771 	 RES_OFFSET(offset), XtRString, DECONST(char,dftvalue)}
   1772 
   1773 #define Sres(name, class, offset, dftvalue) \
   1774 	{RES_NAME(name), RES_CLASS(class), XtRString, sizeof(char *), \
   1775 	 RES_OFFSET(offset), XtRString, DECONST(char,dftvalue)}
   1776 
   1777 #define Wres(name, class, offset, dftvalue) \
   1778 	{RES_NAME(name), RES_CLASS(class), XtRWidget, sizeof(Widget), \
   1779 	 RES_OFFSET(offset), XtRWidget, (XtPointer) dftvalue}
   1780 
   1781 /***====================================================================***/
   1782 
   1783 #define FRG_SIZE resource.minBufSize
   1784 #define BUF_SIZE resource.maxBufSize
   1785 
   1786 typedef struct {
   1787 	Char    *next;
   1788 	Char    *last;
   1789 	int      update;	/* HandleInterpret */
   1790 #if OPT_WIDE_CHARS
   1791 	IChar    utf_data;	/* resulting character */
   1792 	size_t   utf_size;	/* ...number of bytes decoded */
   1793 	Char    *write_buf;
   1794 	size_t   write_len;
   1795 #endif
   1796 	Char     buffer[1];
   1797 } PtyData;
   1798 
   1799 /***====================================================================***/
   1800 
   1801 /*
   1802  * Pixel (and its components) are declared as unsigned long, but even for RGB
   1803  * we need no more than 32-bits.
   1804  */
   1805 typedef uint32_t MyPixel;
   1806 typedef int32_t MyColor;
   1807 
   1808 #if OPT_ISO_COLORS
   1809 #if OPT_DIRECT_COLOR
   1810 typedef struct {
   1811     MyColor fg;
   1812     MyColor bg;
   1813 } CellColor;
   1814 
   1815 #define isSameCColor(p,q) (!memcmp(&(p), &(q), sizeof(CellColor)))
   1816 
   1817 #elif OPT_256_COLORS || OPT_88_COLORS
   1818 
   1819 #define COLOR_BITS 8
   1820 typedef unsigned short CellColor;
   1821 
   1822 #else
   1823 
   1824 #define COLOR_BITS 4
   1825 typedef Char CellColor;
   1826 
   1827 #endif
   1828 #else
   1829 typedef unsigned CellColor;
   1830 #endif
   1831 
   1832 #define NO_COLOR		((unsigned)-1)
   1833 
   1834 #ifndef isSameCColor
   1835 #define isSameCColor(p,q)	((p) == (q))
   1836 #endif
   1837 
   1838 #define BITS2MASK(b)		(xBIT(b) - 1)
   1839 
   1840 #define COLOR_MASK		BITS2MASK(COLOR_BITS)
   1841 
   1842 #if OPT_DIRECT_COLOR
   1843 #define clrDirectFG(flags)	UIntClr(flags, ATR_DIRECT_FG)
   1844 #define clrDirectBG(flags)	UIntClr(flags, ATR_DIRECT_BG)
   1845 #define GetCellColorFG(data)	((data).fg)
   1846 #define GetCellColorBG(data)	((data).bg)
   1847 #define hasDirectFG(flags)	((flags) & ATR_DIRECT_FG)
   1848 #define hasDirectBG(flags)	((flags) & ATR_DIRECT_BG)
   1849 #define setDirectFG(flags,test)	if (test) UIntSet(flags, ATR_DIRECT_FG); else UIntClr(flags, ATR_DIRECT_FG)
   1850 #define setDirectBG(flags,test)	if (test) UIntSet(flags, ATR_DIRECT_BG); else UIntClr(flags, ATR_DIRECT_BG)
   1851 #elif OPT_ISO_COLORS
   1852 #define clrDirectFG(flags)	/* nothing */
   1853 #define clrDirectBG(flags)	/* nothing */
   1854 #define GetCellColorFG(data)	((data) & COLOR_MASK)
   1855 #define GetCellColorBG(data)	(((data) >> COLOR_BITS) & COLOR_MASK)
   1856 #define hasDirectFG(flags)	0
   1857 #define hasDirectBG(flags)	0
   1858 #define setDirectFG(flags,test)	(void)(test)
   1859 #define setDirectBG(flags,test)	(void)(test)
   1860 #else
   1861 #define GetCellColorFG(data)	7
   1862 #define GetCellColorBG(data)	0
   1863 #endif
   1864 extern CellColor blank_cell_color;
   1865 
   1866 typedef Char RowData;		/* wrap/blink, and DEC single-double chars */
   1867 
   1868 #define LINEFLAG_BITS		4
   1869 #define LINEFLAG_MASK		BITS2MASK(LINEFLAG_BITS)
   1870 
   1871 #define GetLineFlags(ld)	((ld)->bufHead & LINEFLAG_MASK)
   1872 
   1873 #if OPT_DEC_CHRSET
   1874 #define SetLineFlags(ld,xx)	(ld)->bufHead = (RowData) ((ld->bufHead & (DBLCS_MASK << LINEFLAG_BITS)) | (xx & LINEFLAG_MASK))
   1875 #else
   1876 #define SetLineFlags(ld,xx)	(ld)->bufHead = (RowData) (xx & LINEFLAG_MASK)
   1877 #endif
   1878 
   1879 typedef IChar CharData;
   1880 
   1881 /*
   1882  * This is the xterm line-data/scrollback structure.
   1883  */
   1884 typedef struct {
   1885 	Dimension lineSize;	/* number of columns in this row */
   1886 	RowData	 bufHead;	/* flag for wrapped lines */
   1887 #if OPT_WIDE_CHARS
   1888 	Char	 combSize;	/* number of items in combData[] */
   1889 #endif
   1890 #if OPT_DEC_RECTOPS
   1891 	Char	 *charSets;	/* SCS code (DECNRCM_codes) */
   1892 	Char     *charSeen;	/* pre-SCS value */
   1893 #endif
   1894 	IAttr	 *attribs;	/* video attributes */
   1895 #if OPT_ISO_COLORS
   1896 	CellColor *color;	/* foreground+background color numbers */
   1897 #endif
   1898 	CharData *charData;	/* cell's base character */
   1899 	CharData *combData[1];	/* first field past fixed-offsets */
   1900 } LineData;
   1901 
   1902 typedef const LineData CLineData;
   1903 
   1904 /*
   1905  * We use CellData in a few places, when copying a cell's data to a temporary
   1906  * variable.
   1907  */
   1908 typedef struct {
   1909 	IAttr    attribs;	/* video attributes */
   1910 #if OPT_WIDE_CHARS
   1911 	Char     combSize;	/* number of items in combData[] */
   1912 #endif
   1913 #if OPT_DEC_RECTOPS
   1914 	Char     charSets;	/* SCS code (DECNRCM_codes) */
   1915 	Char     charSeen;	/* pre-SCS value */
   1916 #endif
   1917 #if OPT_ISO_COLORS
   1918 	CellColor color;	/* foreground+background color numbers */
   1919 #endif
   1920 	CharData charData;	/* cell's base character */
   1921 	CharData combData[1];	/* array of combining chars */
   1922 } CellData;
   1923 
   1924 #define for_each_combData(off, ld) for (off = 0; off < ld->combSize; ++off)
   1925 
   1926 #define Clear1Cell(ld, x) \
   1927 	do { \
   1928 	    ld->charData[x] = ' '; \
   1929 	    do { \
   1930 	    if_OPT_WIDE_CHARS(screen, { \
   1931 		size_t z; \
   1932 		for_each_combData(z, ld) { \
   1933 		    ld->combData[z][x] = '\0'; \
   1934 		} \
   1935 	    }) } while (0); \
   1936 	} while (0)
   1937 
   1938 #define Clear2Cell(dst, src, x) \
   1939 	do { \
   1940 	    dst->charData[x] = ' '; \
   1941 	    dst->attribs[x] = src->attribs[x]; \
   1942 	    do { \
   1943 	    if_OPT_ISO_COLORS(screen, { \
   1944 		dst->color[x] = src->color[x]; \
   1945 	    }) } while (0); \
   1946 	    do { \
   1947 	    if_OPT_WIDE_CHARS(screen, { \
   1948 		size_t z; \
   1949 		for_each_combData(z, dst) { \
   1950 		    dst->combData[z][x] = '\0'; \
   1951 		} \
   1952 	    }) } while (0); \
   1953 	} while (0)
   1954 
   1955 /*
   1956  * Accommodate older compilers by not using variable-length arrays.
   1957  */
   1958 #define SizeOfLineData  offsetof(LineData, combData)
   1959 #define SizeOfCellData  offsetof(CellData, combData)
   1960 
   1961 	/*
   1962 	 * A "row" is the index within the visible part of the screen, and an
   1963 	 * "inx" is the index within the whole set of scrollable lines.
   1964 	 */
   1965 #define ROW2INX(screen, row)	((row) + (screen)->topline)
   1966 #define INX2ROW(screen, inx)	((inx) - (screen)->topline)
   1967 
   1968 /* these are unused but could be useful for debugging */
   1969 #if 0
   1970 #define ROW2ABS(screen, row)	((row) + (screen)->savedlines)
   1971 #define INX2ABS(screen, inx)	ROW2ABS(screen, INX2ROW(screen, inx))
   1972 #endif
   1973 
   1974 #define okScrnRow(screen, row) \
   1975 	((row) <= ((screen)->max_row - (screen)->topline) \
   1976       && (row) >= -((screen)->savedlines))
   1977 
   1978 	/*
   1979 	 * Cache data for "proportional" and other fonts containing a mixture
   1980 	 * of widths.
   1981 	 */
   1982 typedef struct {
   1983 	Bool		mixed;
   1984 	Dimension	min_width;	/* nominal cell width for 0..255 */
   1985 	Dimension	max_width;	/* maximum cell width */
   1986 } XTermFontInfo;
   1987 
   1988 	/*
   1989 	 * Map of characters to simplify/speed-up the checks for missing glyphs
   1990 	 * at runtime.
   1991 	 *
   1992 	 * FIXME: initially implement for Xft, but replace known_missing[] in
   1993 	 * X11 fonts as well.
   1994 	 */
   1995 typedef Char XTfontNum;
   1996 typedef struct {
   1997 	int		depth;		/* number of fonts merged for map */
   1998 	size_t		limit;		/* allocated size of per_font, etc */
   1999 	size_t		first_char;	/* merged first-character index */
   2000 	size_t		last_char;	/* merged last-character index */
   2001 	XTfontNum *	per_font;	/* index 1-n of first font with char */
   2002 } XTermFontMap;
   2003 
   2004 typedef enum {
   2005 	fwNever = 0,
   2006 	fwResource,
   2007 	fwAlways
   2008 } fontWarningTypes;
   2009 
   2010 typedef struct {
   2011 	unsigned	chrset;
   2012 	unsigned	flags;
   2013 	fontWarningTypes warn;
   2014 	XFontStruct *	fs;
   2015 	char *		fn;
   2016 	XTermFontInfo	font_info;
   2017 	Char		known_missing[MaxUChar + 1];
   2018 } XTermFonts;
   2019 
   2020 #if OPT_RENDERFONT
   2021 typedef enum {
   2022 	erFalse = 0
   2023 	, erTrue
   2024 	, erDefault
   2025 	, erDefaultOff
   2026 	, erLast
   2027 } RenderFont;
   2028 
   2029 #define DefaultRenderFont(xw) \
   2030 	if ((xw)->work.render_font == erDefault) \
   2031 	    (xw)->work.render_font = erFalse
   2032 
   2033 typedef enum {
   2034     	xcEmpty = 0			/* slot is unused */
   2035 	, xcBogus			/* ignore this pattern */
   2036 	, xcOpened			/* slot has open font descriptor */
   2037 	, xcUnused			/* opened, but unused so far */
   2038 } XTermXftState;
   2039 
   2040 typedef struct {
   2041 	XftFont *	font;
   2042 	XTermXftState	usage;
   2043 } XTermXftCache;
   2044 
   2045 #define MaxXftCache	MaxUChar
   2046 
   2047 typedef struct {
   2048 	XftPattern *	pattern;	/* pattern for main font */
   2049 	XftFontSet *	fontset;	/* ordered list of fallback patterns */
   2050 	XTermXftCache	cache[MaxXftCache + 1]; /* list of open font pointers */
   2051 	int		fs_size;	/* last usable index of cache[] */
   2052 	Char		opened;		/* number in cache[] with xcOpened */
   2053 	XTermFontInfo	font_info;	/* summary of font metrics */
   2054 	XTermFontMap	font_map;	/* map of glyphs provided in fontset */
   2055 } XTermXftFonts;
   2056 
   2057 #define XftFpN(p,n)	(p)->cache[(n)].font
   2058 #define XftIsN(p,n)	(p)->cache[(n)].usage
   2059 
   2060 #define XftFp(p)	XftFpN(p,0)
   2061 #define XftIs(p)	XftIsN(p,0)
   2062 
   2063 typedef	struct _ListXftFonts {
   2064 	struct _ListXftFonts *next;
   2065 	XftFont *	font;
   2066 } ListXftFonts;
   2067 #endif
   2068 
   2069 typedef struct {
   2070 	int		top;
   2071 	int		left;
   2072 	int		bottom;
   2073 	int		right;
   2074 } XTermRect;
   2075 
   2076 /***====================================================================***/
   2077 
   2078 	/* indices into save_modes[] */
   2079 typedef enum {
   2080 	DP_ALLOW_ALTBUF,
   2081 	DP_ALTERNATE_SCROLL,
   2082 	DP_ALT_SENDS_ESC,
   2083 	DP_BELL_IS_URGENT,
   2084 	DP_CRS_VISIBLE,
   2085 	DP_DECANM,
   2086 	DP_DECARM,
   2087 	DP_DECAWM,
   2088 	DP_DECBKM,
   2089 	DP_DECCKM,
   2090 	DP_DECCOLM,	/* IN132COLUMNS */
   2091 	DP_DECKPAM,
   2092 	DP_DECNRCM,
   2093 	DP_DECOM,
   2094 	DP_DECPEX,
   2095 	DP_DECPFF,
   2096 	DP_DECSCLM,
   2097 	DP_DECSCNM,
   2098 	DP_DECTCEM,
   2099 	DP_DELETE_IS_DEL,
   2100 	DP_EIGHT_BIT_META,
   2101 	DP_FAST_SCROLL,
   2102 	DP_KEEP_CLIPBOARD,
   2103 	DP_KEEP_SELECTION,
   2104 	DP_KEYBOARD_TYPE,
   2105 	DP_POP_ON_BELL,
   2106 	DP_PRN_EXTENT,
   2107 	DP_PRN_FORMFEED,
   2108 	DP_RXVT_SCROLLBAR,
   2109 	DP_RXVT_SCROLL_TTY_KEYPRESS,
   2110 	DP_RXVT_SCROLL_TTY_OUTPUT,
   2111 	DP_SELECT_TO_CLIPBOARD,
   2112 	DP_X_ALTBUF,
   2113 	DP_X_DECCOLM,
   2114 	DP_X_EXT_MOUSE,
   2115 	DP_X_LOGGING,
   2116 	DP_X_LRMM,
   2117 	DP_X_MARGIN,
   2118 	DP_X_MORE,
   2119 	DP_X_MOUSE,
   2120 	DP_X_NCSM,
   2121 	DP_X_REVWRAP,
   2122 	DP_X_REVWRAP2,
   2123 	DP_X_X10MSE,
   2124 #if OPT_BLINK_CURS
   2125 	DP_CRS_BLINK,
   2126 #endif
   2127 #if OPT_FOCUS_EVENT
   2128 	DP_X_FOCUS,
   2129 #endif
   2130 #if OPT_NUM_LOCK
   2131 	DP_REAL_NUMLOCK,
   2132 	DP_META_SENDS_ESC,
   2133 #endif
   2134 #if OPT_SHIFT_FONTS
   2135 	DP_RXVT_FONTSIZE,
   2136 #endif
   2137 #if OPT_SIXEL_GRAPHICS
   2138 	DP_DECSDM,
   2139 #endif
   2140 #if OPT_TEK4014
   2141 	DP_DECTEK,
   2142 #endif
   2143 #if OPT_TOOLBAR
   2144 	DP_TOOLBAR,
   2145 #endif
   2146 #if OPT_GRAPHICS
   2147 	DP_X_PRIVATE_COLOR_REGISTERS,
   2148 #endif
   2149 #if OPT_SIXEL_GRAPHICS
   2150 	DP_SIXEL_SCROLLS_RIGHT,
   2151 #endif
   2152 #if OPT_PRINT_GRAPHICS
   2153 	DP_DECGEPM,  /* Graphics Expanded Print Mode */
   2154 	DP_DECGPCM,  /* Graphics Print Color Mode */
   2155 	DP_DECGPCS,  /* Graphics Print Color Syntax */
   2156 	DP_DECGPBM,  /* Graphics Print Background Mode */
   2157 	DP_DECGRPM,  /* Graphics Rotated Print Mode */
   2158 #endif
   2159 	DP_LAST
   2160 } SaveModes;
   2161 
   2162 #define DoSM(code,value)  screen->save_modes[code] = (unsigned) (value)
   2163 #define DoRM(code,value)  value = (Boolean) screen->save_modes[code]
   2164 #define DoRM0(code,value) value = screen->save_modes[code]
   2165 
   2166 	/* index into vt_shell[] or tek_shell[] */
   2167 typedef enum {
   2168 	noMenu = -1
   2169 	,mainMenu
   2170 	,vtMenu
   2171 	,fontMenu
   2172 #if OPT_TEK4014
   2173 	,tekMenu
   2174 #endif
   2175 } MenuIndex;
   2176 
   2177 typedef enum {
   2178 	bvOff = -1,
   2179 	bvLow = 0,
   2180 	bvHigh
   2181 } BellVolume;
   2182 
   2183 #define NUM_POPUP_MENUS 4
   2184 
   2185 typedef struct {
   2186 	String		resource;
   2187 	Pixel		value;
   2188 	unsigned short red, green, blue;
   2189 	int		mode;		/* -1=invalid, 0=unset, 1=set   */
   2190 } ColorRes;
   2191 
   2192 /* these are set in getPrinterFlags */
   2193 typedef struct {
   2194 	int	printer_extent;		/* print complete page		*/
   2195 	int	printer_formfeed;	/* print formfeed per function	*/
   2196 	int	printer_newline;	/* print newline per function	*/
   2197 	int	print_attributes;	/* 0=off, 1=normal, 2=color	*/
   2198 	int	print_everything;	/* 0=all, 1=dft, 2=alt, 3=saved */
   2199 } PrinterFlags;
   2200 
   2201 typedef struct {
   2202 	FILE *	fp;			/* output file/pipe used	*/
   2203 	Boolean isOpen;			/* output was opened/tried	*/
   2204 	Boolean toFile;			/* true when directly to file	*/
   2205 	Boolean printer_checked;	/* printer_command is checked	*/
   2206 	String	printer_command;	/* pipe/shell command string	*/
   2207 	Boolean printer_autoclose;	/* close printer when offline	*/
   2208 	Boolean printer_extent;		/* print complete page		*/
   2209 	Boolean printer_formfeed;	/* print formfeed per function	*/
   2210 	Boolean printer_newline;	/* print newline per function	*/
   2211 	int	printer_controlmode;	/* 0=off, 1=auto, 2=controller	*/
   2212 	int	print_attributes;	/* 0=off, 1=normal, 2=color	*/
   2213 	int	print_everything;	/* 0=all, 1=dft, 2=alt, 3=saved */
   2214 } PrinterState;
   2215 
   2216 typedef struct {
   2217 	unsigned	which;		/* must have NCOLORS bits */
   2218 	Pixel		colors[NCOLORS];
   2219 	char		*names[NCOLORS];
   2220 } ScrnColors;
   2221 
   2222 #define NUM_GSETS 4
   2223 #define NUM_GSETS2 (NUM_GSETS + 1)	/* include user-preferred */
   2224 #define gsets_upss	gsets[4]
   2225 
   2226 #define SAVED_CURSORS 2
   2227 
   2228 typedef struct {
   2229 	Boolean		saved;
   2230 	int		row;
   2231 	int		col;
   2232 	IFlags		flags;		/* VTxxx saves graphics rendition */
   2233 	Char		curgl;
   2234 	Char		curgr;
   2235 	DECNRCM_codes	gsets[NUM_GSETS2];
   2236 	Boolean		wrap_flag;
   2237 #if OPT_ISO_COLORS
   2238 	int		cur_foreground;  /* current foreground color	*/
   2239 	int		cur_background;  /* current background color	*/
   2240 	int		sgr_foreground;  /* current SGR foreground color */
   2241 	int		sgr_background;  /* current SGR background color */
   2242 	Boolean		sgr_38_xcolors;  /* true if ISO 8613 extension	*/
   2243 #endif
   2244 } SavedCursor;
   2245 
   2246 typedef struct _SaveTitle {
   2247 	struct _SaveTitle *next;
   2248 	char		*iconName;
   2249 	char		*windowName;
   2250 } SaveTitle;
   2251 
   2252 #define MAX_SAVED_TITLES 10
   2253 
   2254 typedef struct {
   2255 	int		used;		/* index to current item	*/
   2256 	SaveTitle	data[MAX_SAVED_TITLES];
   2257 } SavedTitles;
   2258 
   2259 typedef struct {
   2260 	int		width;		/* if > 0, width of scrollbar,	*/
   2261 					/* and scrollbar is showing	*/
   2262 	Boolean		rv_cached;	/* see ScrollBarReverseVideo	*/
   2263 	int		rv_active;	/* ...current reverse-video	*/
   2264 	Pixel		bg;		/* ...cached background color	*/
   2265 	Pixel		fg;		/* ...cached foreground color	*/
   2266 	Pixel		bdr;		/* ...cached border color	*/
   2267 	Pixmap		bdpix;		/* ...cached border pixmap	*/
   2268 } SbInfo;
   2269 
   2270 #if OPT_TOOLBAR
   2271 typedef struct {
   2272 	Widget		menu_bar;	/* toolbar, if initialized	*/
   2273 	Dimension	menu_height;	/* ...and its height		*/
   2274 	Dimension	menu_border;	/* ...and its border		*/
   2275 } TbInfo;
   2276 #define VT100_TB_INFO(name) screen.fullVwin.tb_info.name
   2277 #endif
   2278 
   2279 typedef struct {
   2280 	Window		window;		/* X window id			*/
   2281 	int		width;		/* width of columns in pixels	*/
   2282 	int		height;		/* height of rows in pixels	*/
   2283 	Dimension	fullwidth;	/* full width of window		*/
   2284 	Dimension	fullheight;	/* full height of window	*/
   2285 	int		f_width;	/* width of fonts in pixels	*/
   2286 	int		f_height;	/* height of fonts in pixels	*/
   2287 	int		f_ascent;	/* ascent of font in pixels	*/
   2288 	int		f_descent;	/* descent of font in pixels	*/
   2289 	SbInfo		sb_info;
   2290 	GC		filler_gc;	/* filler's fg/bg		*/
   2291 	GC		border_gc;	/* inner border's fg/bg		*/
   2292 	GC		marker_gc[2];	/* wrap-marks			*/
   2293 #if USE_DOUBLE_BUFFER
   2294 	Drawable	drawable;	/* X drawable id                */
   2295 #endif
   2296 #if OPT_TOOLBAR
   2297 	Boolean		active;		/* true if toolbars are used	*/
   2298 	TbInfo		tb_info;	/* toolbar information		*/
   2299 #endif
   2300 } VTwin;
   2301 
   2302 typedef struct {
   2303 	Window		window;		/* X window id			*/
   2304 	int		width;		/* width of columns		*/
   2305 	int		height;		/* height of rows		*/
   2306 	Dimension	fullwidth;	/* full width of window		*/
   2307 	Dimension	fullheight;	/* full height of window	*/
   2308 	double		tekscale;	/* scale factor Tek -> vs100	*/
   2309 } TKwin;
   2310 
   2311 typedef struct {
   2312     char *f_n;			/* the normal font */
   2313     char *f_b;			/* the bold font */
   2314 #if OPT_WIDE_CHARS
   2315     char *f_w;			/* the normal wide font */
   2316     char *f_wb;			/* the bold wide font */
   2317 #endif
   2318 } VTFontNames;
   2319 
   2320 typedef struct {
   2321     char **list_n;		/* the normal font */
   2322     char **list_b;		/* the bold font */
   2323 #if OPT_WIDE_ATTRS || OPT_RENDERWIDE
   2324     char **list_i;		/* italic font (Xft only) */
   2325     char **list_bi;		/* bold-italic font (Xft only) */
   2326 #endif
   2327 #if OPT_WIDE_CHARS
   2328     char **list_w;		/* the normal wide font */
   2329     char **list_wb;		/* the bold wide font */
   2330     char **list_wi;		/* wide italic font (Xft only) */
   2331     char **list_wbi;		/* wide bold-italic font (Xft only) */
   2332 #endif
   2333 } VTFontList;
   2334 
   2335 typedef struct {
   2336     VTFontList x11;
   2337 #if OPT_RENDERFONT
   2338     VTFontList xft;
   2339 #endif
   2340 } XtermFontNames;
   2341 
   2342 typedef struct {
   2343     VTFontNames default_font;
   2344     String menu_font_names[NMENUFONTS][fMAX];
   2345     XtermFontNames fonts;
   2346 } SubResourceRec;
   2347 
   2348 #if OPT_INPUT_METHOD
   2349 #define NINPUTWIDGETS	3
   2350 typedef struct {
   2351 	Widget		w;
   2352 	XIM		xim;		/* input method attached to 'w' */
   2353 	XIC		xic;		/* input context attached to 'xim' */
   2354 } TInput;
   2355 #endif
   2356 
   2357 typedef enum {
   2358 	CURSOR_BLOCK = 2
   2359 	, CURSOR_UNDERLINE = 4
   2360 	, CURSOR_BAR = 6
   2361 } XtCursorShape;
   2362 
   2363 #define isCursorBlock(s)	((s)->cursor_shape == CURSOR_BLOCK)
   2364 #define isCursorUnderline(s)	((s)->cursor_shape == CURSOR_UNDERLINE)
   2365 #define isCursorBar(s)		((s)->cursor_shape == CURSOR_BAR)
   2366 
   2367 typedef enum {
   2368 	DEFAULT_STYLE = 0
   2369 	, BLINK_BLOCK
   2370 	, STEADY_BLOCK
   2371 	, BLINK_UNDERLINE
   2372 	, STEADY_UNDERLINE
   2373 	, BLINK_BAR
   2374 	, STEADY_BAR
   2375 } XtCursorStyle;
   2376 
   2377 #if OPT_GRAPHICS
   2378 #define GraphicsTermId(screen) (\
   2379 	(screen)->graphics_termid \
   2380 	 ? (screen)->graphics_termid \
   2381 	 : (screen)->terminal_id)
   2382 #else
   2383 #define GraphicsTermId(screen) (screen)->terminal_id
   2384 #endif
   2385 
   2386 #if OPT_REGIS_GRAPHICS
   2387 #define optRegisGraphics(screen) \
   2388 	(GraphicsTermId(screen) == 125 || \
   2389 	 GraphicsTermId(screen) == 240 || \
   2390 	 GraphicsTermId(screen) == 241 || \
   2391 	 GraphicsTermId(screen) == 330 || \
   2392 	 GraphicsTermId(screen) == 340)
   2393 #else
   2394 #define optRegisGraphics(screen) False
   2395 #endif
   2396 
   2397 #if OPT_SIXEL_GRAPHICS
   2398 #define optSixelGraphics(screen) \
   2399 	(GraphicsTermId(screen) == 240 || \
   2400 	 GraphicsTermId(screen) == 241 || \
   2401 	 GraphicsTermId(screen) == 330 || \
   2402 	 GraphicsTermId(screen) == 340 || \
   2403 	 GraphicsTermId(screen) == 382)
   2404 #else
   2405 #define optSixelGraphics(screen) False
   2406 #endif
   2407 
   2408 #if OPT_PRINT_GRAPHICS
   2409 #define if_PRINT_GRAPHICS2(statement) if (optRegisGraphics(screen)) { statement; } else
   2410 #else
   2411 #define if_PRINT_GRAPHICS2(statement) /* nothing */
   2412 #endif
   2413 
   2414 typedef struct {
   2415 /* These parameters apply to both windows */
   2416 	Display		*display;	/* X display for screen		*/
   2417 	int		respond;	/* socket for responses
   2418 					   (position report, etc.)	*/
   2419 	int		nextEventDelay;	/* msecs to delay for x-events  */
   2420 /* These parameters apply to VT100 window */
   2421 	IChar		*unparse_bfr;
   2422 	unsigned	unparse_len;
   2423 	unsigned	unparse_max;	/* limitResponse resource	*/
   2424 	unsigned	strings_max;	/* maxStringParse resource	*/
   2425 
   2426 #if OPT_TCAP_QUERY
   2427 	int		tc_query_code;
   2428 	Bool		tc_query_fkey;
   2429 #endif
   2430 	pid_t		pid;		/* pid of process on far side   */
   2431 	uid_t		uid;		/* user id of actual person	*/
   2432 	gid_t		gid;		/* group id of actual person	*/
   2433 	ColorRes	Tcolors[NCOLORS]; /* terminal colors		*/
   2434 #if OPT_HIGHLIGHT_COLOR
   2435 	Boolean		hilite_color;	/* hilite colors override	*/
   2436 	Boolean		hilite_reverse;	/* hilite overrides reverse	*/
   2437 #endif
   2438 #if OPT_ISO_COLORS
   2439 	XColor *	cmap_data;	/* color table			*/
   2440 	unsigned	cmap_size;
   2441 	ColorRes	Acolors[MAXCOLORS]; /* ANSI color emulation	*/
   2442 	int		veryBoldColors;	/* modifier for boldColors	*/
   2443 	Boolean		boldColors;	/* can we make bold colors?	*/
   2444 	Boolean		colorMode;	/* are we using color mode?	*/
   2445 	Boolean		colorULMode;	/* use color for underline?	*/
   2446 	Boolean		italicULMode;	/* italic font for underline?	*/
   2447 	Boolean		colorBDMode;	/* use color for bold?		*/
   2448 	Boolean		colorBLMode;	/* use color for blink?		*/
   2449 	Boolean		colorRVMode;	/* use color for reverse?	*/
   2450 	Boolean		colorAttrMode;	/* prefer colorUL/BD to SGR	*/
   2451 #if OPT_WIDE_ATTRS
   2452 	Boolean		colorITMode;	/* use color for italics?	*/
   2453 #endif
   2454 #if OPT_DIRECT_COLOR
   2455 	Boolean		direct_color;	/* direct-color enabled?	*/
   2456 #endif
   2457 #if OPT_WIDE_ATTRS && OPT_SGR2_HASH
   2458 	Boolean		faint_relative;	/* faint is relative?		*/
   2459 #endif
   2460 #if OPT_VT525_COLORS
   2461 	int		assigned_fg;	/* DECAC			*/
   2462 	int		assigned_bg;
   2463 	struct {
   2464 	    int fg;			/* 0..15			*/
   2465 	    int bg;			/* 0..15			*/
   2466 	} alt_colors[16];		/* DECATC if DECSTGLT is 1 or 2	*/
   2467 #endif
   2468 #endif /* OPT_ISO_COLORS */
   2469 #if OPT_DEC_CHRSET
   2470 	Boolean		font_doublesize;/* enable font-scaling		*/
   2471 	int		cache_doublesize;/* limit of our cache		*/
   2472 	Char		cur_chrset;	/* character-set index & code	*/
   2473 	int		fonts_used;	/* count items in double_fonts	*/
   2474 	XTermFonts	double_fonts[NUM_CHRSET];
   2475 #if OPT_RENDERFONT
   2476 	XTermXftFonts	double_xft_fonts[NUM_CHRSET];
   2477 #endif
   2478 #endif /* OPT_DEC_CHRSET */
   2479 #if OPT_DEC_RECTOPS
   2480 	int		cur_decsace;	/* parameter for DECSACE	*/
   2481 	int		checksum_ext;	/* extensions for DECRQCRA	*/
   2482 	int		checksum_ext0;	/* initial checksumExtension	*/
   2483 #endif
   2484 #if OPT_WIDE_CHARS
   2485 	Boolean		wide_chars;	/* true when 16-bit chars	*/
   2486 	Boolean		vt100_graphics;	/* true to allow vt100-graphics	*/
   2487 	Boolean		utf8_inparse;	/* true to enable UTF-8 parser	*/
   2488 	Boolean		normalized_c;	/* true to precompose to Form C */
   2489 	char *		utf8_mode_s;	/* use UTF-8 decode/encode	*/
   2490 	char *		utf8_fonts_s;	/* use UTF-8 decode/encode	*/
   2491 	char *		utf8_title_s;	/* use UTF-8 titles		*/
   2492 	int		utf8_nrc_mode;	/* saved UTF-8 mode for DECNRCM */
   2493 	Boolean		utf8_always;	/* special case for wideChars	*/
   2494 	int		utf8_mode;	/* use UTF-8 decode/encode: 0-2	*/
   2495 	int		utf8_fonts;	/* use UTF-8 fonts: 0-2		*/
   2496 	int		utf8_title;	/* use UTF-8 EWHM props: 0-2	*/
   2497 	int		max_combining;	/* maximum # of combining chars	*/
   2498 	Boolean		utf8_latin1;	/* use UTF-8 with Latin-1 bias	*/
   2499 	Boolean		utf8_weblike;	/* use UTF-8 with browser bias	*/
   2500 	int		latin9_mode;	/* poor man's luit, latin9	*/
   2501 	int		unicode_font;	/* font uses unicode encoding	*/
   2502 	int		utf_count;	/* state of utf_char		*/
   2503 	IChar		utf_char;	/* in-progress character	*/
   2504 	Boolean		char_was_written;
   2505 	int		last_written_col;
   2506 	int		last_written_row;
   2507 #endif
   2508 	TypedBuffer(IChar);
   2509 	TypedBuffer(Char);
   2510 	TypedBuffer(XChar2b);
   2511 #if OPT_BROKEN_OSC
   2512 	Boolean		brokenLinuxOSC; /* true to ignore Linux palette ctls */
   2513 #endif
   2514 #if OPT_BROKEN_ST
   2515 	Boolean		brokenStringTerm; /* true to match old OSC parse */
   2516 #endif
   2517 #if OPT_C1_PRINT || OPT_WIDE_CHARS
   2518 	Boolean		c1_printable;	/* true if we treat C1 as print	*/
   2519 #endif
   2520 	int		border;		/* inner border			*/
   2521 	int		scrollBarBorder; /* scrollBar border		*/
   2522 	long		event_mask;
   2523 	unsigned	send_mouse_pos;	/* user wants mouse transition  */
   2524 					/* and position information	*/
   2525 	int		extend_coords;	/* support large terminals	*/
   2526 #if OPT_FOCUS_EVENT
   2527 	Boolean		send_focus_pos; /* user wants focus in/out info */
   2528 #endif
   2529 	Boolean		quiet_grab;	/* true if no cursor change on focus */
   2530 #if OPT_PASTE64
   2531 	Cardinal	base64_paste;	/* set to send paste in base64	*/
   2532 	int		base64_final;	/* string-terminator for paste	*/
   2533 	/* _qWriteSelectionData expects these to be initialized to zero.
   2534 	 * base64_flush() is the last step of the conversion, it clears these
   2535 	 * variables.
   2536 	 */
   2537 	unsigned	base64_accu;
   2538 	unsigned	base64_count;
   2539 	unsigned	base64_pad;
   2540 #endif
   2541 #if OPT_PASTE64 || OPT_READLINE
   2542 	unsigned	paste_brackets;
   2543 	/* not part of bracketed-paste, these are here to simplify ifdefs */
   2544 	unsigned	dclick3_deletes;
   2545 	unsigned	paste_literal_nl;
   2546 #endif
   2547 #if OPT_READLINE
   2548 	unsigned	click1_moves;
   2549 	unsigned	paste_moves;
   2550 	unsigned	paste_quotes;
   2551 #endif	/* OPT_READLINE */
   2552 #if OPT_DEC_LOCATOR
   2553 	Boolean		locator_reset;	/* turn mouse off after 1 report? */
   2554 	Boolean		locator_pixels;	/* report in pixels?		*/
   2555 					/* if false, report in cells	*/
   2556 	unsigned	locator_events;	/* what events to report	*/
   2557 	Boolean		loc_filter;	/* is filter rectangle active?	*/
   2558 	int		loc_filter_top;	/* filter rectangle for DEC Locator */
   2559 	int		loc_filter_left;
   2560 	int		loc_filter_bottom;
   2561 	int		loc_filter_right;
   2562 #endif	/* OPT_DEC_LOCATOR */
   2563 	int		mouse_button;	/* current button pressed	*/
   2564 	int		mouse_row;	/* ...and its row		*/
   2565 	int		mouse_col;	/* ...and its column		*/
   2566 	int		select;		/* xterm selected		*/
   2567 	Boolean		bellOnReset;	/* bellOnReset			*/
   2568 	Boolean		visualbell;	/* visual bell mode		*/
   2569 	Boolean		poponbell;	/* pop on bell mode		*/
   2570 
   2571 	Boolean		eraseSavedLines; /* eraseSavedLines option	*/
   2572 	Boolean		eraseSavedLines0; /* initial eraseSavedLines	*/
   2573 	Boolean		tabCancelsWrap; /* tabCancelsWrap option	*/
   2574 
   2575 	Boolean		allowPasteControls; /* PasteControls mode	*/
   2576 	Boolean		allowColorOps;	/* ColorOps mode		*/
   2577 	Boolean		allowFontOps;	/* FontOps mode			*/
   2578 	Boolean		allowMouseOps;	/* MouseOps mode		*/
   2579 	Boolean		allowSendEvents;/* SendEvent mode		*/
   2580 	Boolean		allowTcapOps;	/* TcapOps mode			*/
   2581 	Boolean		allowTitleOps;	/* TitleOps mode		*/
   2582 	Boolean		allowWindowOps;	/* WindowOps mode		*/
   2583 
   2584 	Boolean		allowPasteControl0; /* PasteControls mode	*/
   2585 	Boolean		allowColorOp0;	/* initial ColorOps mode	*/
   2586 	Boolean		allowFontOp0;	/* initial FontOps mode		*/
   2587 	Boolean		allowMouseOp0;	/* initial MouseOps mode	*/
   2588 	Boolean		allowSendEvent0;/* initial SendEvent mode	*/
   2589 	Boolean		allowTcapOp0;	/* initial TcapOps mode		*/
   2590 	Boolean		allowTitleOp0;	/* initial TitleOps mode	*/
   2591 	Boolean		allowWindowOp0;	/* initial WindowOps mode	*/
   2592 
   2593 	String		disallowedColorOps;
   2594 	char		disallow_color_ops[ecLAST];
   2595 
   2596 	String		disallowedFontOps;
   2597 	char		disallow_font_ops[efLAST];
   2598 
   2599 	String		disallowedMouseOps;
   2600 	char		disallow_mouse_ops[emLAST];
   2601 
   2602 	String		disallowedPasteOps;
   2603 	char		disallow_paste_ops[epLAST];
   2604 
   2605 	String		disallowedTcapOps;
   2606 	char		disallow_tcap_ops[etLAST];
   2607 
   2608 	String		disallowedWinOps;
   2609 	char		disallow_win_ops[ewLAST];
   2610 
   2611 	Boolean		awaitInput;	/* select-timeout mode		*/
   2612 	Boolean		grabbedKbd;	/* keyboard is grabbed		*/
   2613 #ifdef ALLOWLOGGING
   2614 	int		logging;	/* logging mode			*/
   2615 	int		logfd;		/* file descriptor of log	*/
   2616 	char		*logfile;	/* log file name		*/
   2617 	Char		*logstart;	/* current start of log buffer	*/
   2618 #endif
   2619 	int		inhibit;	/* flags for inhibiting changes	*/
   2620 
   2621 /* VT window parameters */
   2622 	Boolean		Vshow;		/* VT window showing		*/
   2623 	VTwin		fullVwin;
   2624 	int		needSwap;
   2625 #ifndef NO_ACTIVE_ICON
   2626 	VTwin		iconVwin;
   2627 	VTwin		*whichVwin;
   2628 #endif /* NO_ACTIVE_ICON */
   2629 
   2630 	int		pointer_mode;	/* when to use hidden_cursor	*/
   2631 	int		pointer_mode0;	/* ...initial value             */
   2632 	Boolean 	hide_pointer;	/* true to use "hidden_cursor"  */
   2633 	String		pointer_shape;	/* name of shape in cursor font */
   2634 	Cursor		pointer_cursor;	/* current pointer cursor	*/
   2635 	Cursor		hidden_cursor;	/* hidden cursor in window	*/
   2636 
   2637 	String		answer_back;	/* response to ENQ		*/
   2638 	Boolean		prefer_latin1;	/* preference for UPSS		*/
   2639 
   2640 	PrinterState	printer_state;	/* actual printer state		*/
   2641 	PrinterFlags	printer_flags;	/* working copy of printer flags */
   2642 	Boolean		print_rawchars;	/* true to ignore printer check	*/
   2643 #if OPT_PRINT_ON_EXIT
   2644 	Boolean		write_error;
   2645 #endif
   2646 
   2647 	Boolean		fnt_prop;	/* true if proportional fonts	*/
   2648 	unsigned	fnt_boxes;	/* 0=no boxes, 1=old, 2=unicode */
   2649 	Boolean		force_packed;	/* true to override proportional */
   2650 #if OPT_BOX_CHARS
   2651 	Boolean		force_box_chars;/* true if we assume no boxchars */
   2652 	Boolean		broken_box_chars;/* true if broken boxchars	*/
   2653 	Boolean		assume_all_chars;/* true to allow missing chars */
   2654 	Boolean		allow_packing;	/* true to allow packed-fonts	*/
   2655 #endif
   2656 #if OPT_BOX_CHARS || OPT_WIDE_CHARS
   2657 	Boolean		force_all_chars;/* true to outline missing chars */
   2658 #endif
   2659 
   2660 	Dimension	fnt_wide;
   2661 	Dimension	fnt_high;
   2662 	float		scale_height;	/* scaling for font-height	*/
   2663 	XTermFonts	fnts[fMAX];	/* normal/bold/etc for terminal	*/
   2664 	Boolean		free_bold_box;	/* same_font_size's austerity	*/
   2665 	Boolean		allowBoldFonts;	/* do we use bold fonts at all? */
   2666 #if OPT_WIDE_ATTRS
   2667 	XTermFonts	ifnts[fMAX];	/* normal/bold/etc italic fonts */
   2668 	Boolean		ifnts_ok;	/* true if ifnts[] is cached	*/
   2669 #endif
   2670 #ifndef NO_ACTIVE_ICON
   2671 	XTermFonts	fnt_icon;	/* icon font			*/
   2672 	String		icon_fontname;	/* name of icon font		*/
   2673 	int		icon_fontnum;	/* number to use for icon font	*/
   2674 #endif /* NO_ACTIVE_ICON */
   2675 	int		enbolden;	/* overstrike for bold font	*/
   2676 	XPoint		*box;		/* draw unselected cursor	*/
   2677 
   2678 	int		cursor_state;	/* ON, OFF, or BLINKED_OFF	*/
   2679 	int		cursor_busy;	/* do not redraw...		*/
   2680 	Boolean		cursor_underline; /* true if cursor is in underline mode */
   2681 	Boolean         cursor_bar;     /* true if cursor is in bar mode */
   2682 	XtCursorShape	cursor_shape;
   2683 #if OPT_BLINK_CURS
   2684 	BlinkOps	cursor_blink;	/* cursor blink enable		*/
   2685 	BlinkOps	cursor_blink_i;	/* save cursor blink enable	*/
   2686 	char *		cursor_blink_s;	/* ...resource cursorBlink	*/
   2687 	int		cursor_blink_esc; /* cursor blink escape-state	*/
   2688 	Boolean		cursor_blink_xor; /* how to merge menu/escapes	*/
   2689 #endif
   2690 #if OPT_BLINK_TEXT
   2691 	Boolean		blink_as_bold;	/* text blink disable		*/
   2692 #endif
   2693 #if OPT_BLINK_CURS || OPT_BLINK_TEXT
   2694 	int		blink_state;	/* ON, OFF, or BLINKED_OFF	*/
   2695 	int		blink_on;	/* cursor on time (msecs)	*/
   2696 	int		blink_off;	/* cursor off time (msecs)	*/
   2697 	XtIntervalId	blink_timer;	/* timer-id for cursor-proc	*/
   2698 #endif
   2699 #if OPT_ZICONBEEP
   2700 	Boolean		zIconBeep_flagged; /* True if icon name was changed */
   2701 #endif /* OPT_ZICONBEEP */
   2702 	int		cursor_GC;	/* see ShowCursor()		*/
   2703 	int		cursor_set;	/* requested state		*/
   2704 	CELL		cursorp;	/* previous cursor row/column	*/
   2705 	int		cur_col;	/* current cursor column	*/
   2706 	int		cur_row;	/* current cursor row		*/
   2707 	int		max_col;	/* rightmost column		*/
   2708 	int		max_row;	/* bottom row			*/
   2709 	int		top_marg;	/* top line of scrolling region */
   2710 	int		bot_marg;	/* bottom line of  "	    "	*/
   2711 	int		lft_marg;	/* left column of "	    "	*/
   2712 	int		rgt_marg;	/* right column of "	    "	*/
   2713 	Widget		scrollWidget;	/* pointer to scrollbar struct	*/
   2714 #if USE_DOUBLE_BUFFER
   2715 	int		buffered_sb;	/* nonzero when pending update	*/
   2716 	struct timeval	buffered_at;	/* reference time, for FPS	*/
   2717 #define DbeMsecs(xw)	(1000L / (long) resource.buffered_fps)
   2718 #endif
   2719 	/*
   2720 	 * Indices used to keep track of the top of the vt100 window and
   2721 	 * the saved lines, taking scrolling into account.
   2722 	 */
   2723 	int		topline;	/* line number of top, <= 0	*/
   2724 	long		saved_fifo;     /* number of lines that've ever been saved */
   2725 	int		savedlines;     /* number of lines that've been saved */
   2726 	int		savelines;	/* number of lines off top to save */
   2727 	int		scroll_amt;	/* amount to scroll		*/
   2728 	int		refresh_amt;	/* amount to refresh		*/
   2729 	/*
   2730 	 * Working variables for getLineData().
   2731 	 */
   2732 	size_t		lineExtra;	/* extra space for combining chars */
   2733 	size_t		cellExtra;	/* extra space for combining chars */
   2734 	/*
   2735 	 * Pointer to the current visible buffer.
   2736 	 */
   2737 	ScrnBuf		visbuf;		/* ptr to visible screen buf (main) */
   2738 	/*
   2739 	 * Data for the normal buffer, which may have saved lines to which
   2740 	 * the user can scroll.
   2741 	 */
   2742 	ScrnBuf		saveBuf_index;
   2743 	Char		*saveBuf_data;
   2744 	/*
   2745 	 * Data for visible and alternate buffer.
   2746 	 */
   2747 	ScrnBuf		editBuf_index[2];
   2748 	Char		*editBuf_data[2];
   2749 	int		whichBuf;	/* 0/1 for normal/alternate buf */
   2750 	Boolean		is_running;	/* true when buffers are legal	*/
   2751 	/*
   2752 	 * Workspace used for screen operations.
   2753 	 */
   2754 	Char		**save_ptr;	/* workspace for save-pointers  */
   2755 	size_t		save_len;	/* ...and its length		*/
   2756 
   2757 	int		scrolllines;	/* number of lines to button scroll */
   2758 	Boolean		alternateScroll; /* scroll-actions become keys */
   2759 	Boolean		scrollttyoutput; /* scroll to bottom on tty output */
   2760 	Boolean		scrollkey;	/* scroll to bottom on key	*/
   2761 	Boolean		cursor_moved;	/* scrolling makes cursor move	*/
   2762 
   2763 	Boolean		do_wrap;	/* true if cursor in last column
   2764 					    and character just output    */
   2765 
   2766 	int		incopy;		/* 0 idle; 1 XCopyArea issued;
   2767 					    -1 first GraphicsExpose seen,
   2768 					    but last not seen		*/
   2769 	int		copy_src_x;	/* params from last XCopyArea ... */
   2770 	int		copy_src_y;
   2771 	unsigned int	copy_width;
   2772 	unsigned int	copy_height;
   2773 	int		copy_dest_x;
   2774 	int		copy_dest_y;
   2775 
   2776 	Dimension	embed_wide;
   2777 	Dimension	embed_high;
   2778 
   2779 	Boolean		c132;		/* allow change to 132 columns	*/
   2780 	Boolean		curses;		/* kludge line wrap for more	*/
   2781 	Boolean		hp_ll_bc;	/* kludge HP-style ll for xdb	*/
   2782 	Boolean		marginbell;	/* true if margin bell on	*/
   2783 	int		nmarginbell;	/* columns from right margin	*/
   2784 	int		bellArmed;	/* cursor below bell margin	*/
   2785 	BellVolume	marginVolume;	/* margin-bell volume           */
   2786 	BellVolume	warningVolume;	/* warning-bell volume          */
   2787 	Boolean		multiscroll;	/* true if multi-scroll		*/
   2788 	int		scrolls;	/* outstanding scroll count,
   2789 					    used only with multiscroll	*/
   2790 	SavedCursor	sc[SAVED_CURSORS]; /* data for restore cursor	*/
   2791 	IFlags		save_modes[DP_LAST]; /* save dec/xterm private modes */
   2792 
   2793 	int		title_modes;	/* control set/get of titles	*/
   2794 	int		title_modes0;	/* ...initial value         	*/
   2795 	SavedTitles	saved_titles;
   2796 
   2797 	/* Improved VT100 emulation stuff.				*/
   2798 	String		keyboard_dialect; /* default keyboard dialect	*/
   2799 	DECNRCM_codes	gsets[NUM_GSETS2]; /* G0 through G3, plus UPSS	*/
   2800 	Char		curgl;		/* Current GL setting.		*/
   2801 	Char		curgr;		/* Current GR setting.		*/
   2802 	Char		curss;		/* Current single shift.	*/
   2803 	String		term_id;	/* resource for terminal_id	*/
   2804 	int		terminal_id;	/* 100=vt100, 220=vt220, etc.	*/
   2805 	int		display_da1;	/* 100=vt100, 220=vt220, etc.	*/
   2806 	int		vtXX_level;	/* 0=vt52, 1,2,3 = vt100 ... vt320 */
   2807 	int		ansi_level;	/* dpANSI levels 1,2,3		*/
   2808 	int		protected_mode;	/* 0=off, 1=DEC, 2=ISO		*/
   2809 	Boolean		always_bold_mode; /* compare normal/bold font	*/
   2810 	Boolean		always_highlight; /* whether to highlight cursor */
   2811 	Boolean		bold_mode;	/* use bold font or overstrike	*/
   2812 	Boolean		delete_is_del;	/* true for compatible Delete key */
   2813 	Boolean		jumpscroll;	/* whether we should jumpscroll */
   2814 	Boolean		fastscroll;	/* whether we should fastscroll */
   2815 	Boolean		old_fkeys;	/* true for compatible fkeys	*/
   2816 	Boolean		old_fkeys0;	/* ...initial value         	*/
   2817 	Boolean		underline;	/* whether to underline text	*/
   2818 
   2819 #if OPT_MAXIMIZE
   2820 	Boolean		restore_data;
   2821 	int		restore_x;
   2822 	int		restore_y;
   2823 	unsigned	restore_width;
   2824 	unsigned	restore_height;
   2825 #endif
   2826 
   2827 #if OPT_REGIS_GRAPHICS
   2828 	String		graphics_regis_default_font; /* font for "builtin" */
   2829 
   2830 	String		graphics_regis_screensize; /* given a size in pixels */
   2831 	Dimension	graphics_regis_def_wide; /* ...corresponding width   */
   2832 	Dimension	graphics_regis_def_high; /* ...and height            */
   2833 #endif
   2834 
   2835 #if OPT_GRAPHICS
   2836 	String		graph_termid;		/* resource for graphics_termid */
   2837 	int		graphics_termid;	/* based on terminal_id   */
   2838 	String		graphics_max_size;	/* given a size in pixels */
   2839 	Dimension	graphics_max_wide;	/* ...corresponding width */
   2840 	Dimension	graphics_max_high;	/* ...and height          */
   2841 #endif
   2842 
   2843 #if OPT_SCROLL_LOCK
   2844 	Boolean		allowScrollLock;/* ScrollLock mode		*/
   2845 	Boolean		allowScrollLock0;/* initial ScrollLock mode	*/
   2846 	Boolean		autoScrollLock; /* Auto ScrollLock mode		*/
   2847 	Boolean		scroll_lock;	/* true to keep buffer in view	*/
   2848 	Boolean		scroll_dirty;	/* scrolling makes screen dirty	*/
   2849 #endif
   2850 
   2851 #if OPT_SIXEL_GRAPHICS
   2852 	Boolean		sixel_scrolling; /* sixel scrolling             */
   2853 	Boolean		sixel_scrolls_right; /* sixel scrolling moves cursor to right */
   2854 	Boolean		sixel_scrolls_right0; /* initial sixelScrolling mode */
   2855 #endif
   2856 
   2857 #if OPT_GRAPHICS
   2858 	int		numcolorregisters; /* number of supported color registers */
   2859 	Boolean		privatecolorregisters; /* private color registers for each graphic */
   2860 	Boolean		privatecolorregisters0; /* initial privateColorRegisters */
   2861 	Boolean		incremental_graphics; /* draw graphics incrementally */
   2862 #endif
   2863 
   2864 	/* Graphics Printing */
   2865 #if OPT_PRINT_GRAPHICS
   2866 	Boolean		graphics_print_to_host;
   2867 	Boolean		graphics_expanded_print_mode;
   2868 	Boolean		graphics_print_color_mode;
   2869 	Boolean		graphics_print_color_syntax;
   2870 	Boolean		graphics_print_background_mode;
   2871 	Boolean		graphics_rotated_print_mode;
   2872 #endif
   2873 
   2874 #define StatusLineRows	1		/* number of rows in status-line */
   2875 
   2876 #if OPT_STATUS_LINE
   2877 #define AddStatusLineRows(nrow)         nrow += StatusLineRows
   2878 #define LastRowNumber(screen) \
   2879 	( (screen)->max_row \
   2880 	 + (IsStatusShown(screen) ? StatusLineRows : 0) )
   2881 #define FirstRowNumber(screen) \
   2882 	( (screen)->status_active \
   2883 	   ? LastRowNumber(screen) \
   2884 	   : 0 )
   2885 #define IsStatusShown(screen) \
   2886 	( ( (screen)->status_type == 2) || \
   2887 	  ( (screen)->status_type == 1) )
   2888 #define PlusStatusLine(screen,expr) \
   2889 	( (screen)->status_shown \
   2890 	  ? (expr) + StatusLineRows \
   2891 	  : (expr) )
   2892 #define if_STATUS_LINE(screen,stmt) \
   2893 	if (IsStatusShown(screen) && (screen)->status_active) stmt
   2894 
   2895 	Boolean		status_timeout;	/* status timeout needs service	*/
   2896 	int		status_active;	/* DECSASD */
   2897 	int		status_type;	/* DECSSDT */
   2898 	int		status_shown;	/* last-displayed type */
   2899 	SavedCursor	status_data[2];	/* main- and status-cursors */
   2900 	char *		status_fmt;	/* format for indicator-status	*/
   2901 
   2902 #else /* !OPT_STATUS_LINE */
   2903 
   2904 #define AddStatusLineRows(nrow)         /* nothing */
   2905 #define LastRowNumber(screen)           (screen)->max_row
   2906 #define FirstRowNumber(screen)          0
   2907 #define IsStatusShown(screen) False
   2908 #define PlusStatusLine(screen,expr)     (expr)
   2909 #define if_STATUS_LINE(screen,stmt)	/* nothing */
   2910 
   2911 #endif /* OPT_STATUS_LINE */
   2912 
   2913 #if OPT_VT52_MODE
   2914 	IFlags		vt52_save_flags;
   2915 	Char		vt52_save_curgl;
   2916 	Char		vt52_save_curgr;
   2917 	Char		vt52_save_curss;
   2918 	DECNRCM_codes	vt52_save_gsets[NUM_GSETS2];
   2919 #endif
   2920 	/* Testing */
   2921 #if OPT_XMC_GLITCH
   2922 	unsigned	xmc_glitch;	/* # of spaces to pad on SGR's	*/
   2923 	IAttr		xmc_attributes;	/* attrs that make a glitch	*/
   2924 	Boolean		xmc_inline;	/* SGR's propagate only to eol	*/
   2925 	Boolean		move_sgr_ok;	/* SGR is reset on move		*/
   2926 #endif
   2927 
   2928 	/*
   2929 	 * Bell
   2930 	 */
   2931 	int		visualBellDelay; /* msecs to delay for visibleBell */
   2932 	int		bellSuppressTime; /* msecs after Bell before another allowed */
   2933 	Boolean		bellInProgress; /* still ringing/flashing prev bell? */
   2934 	Boolean		bellIsUrgent;	/* set XUrgency WM hint on bell */
   2935 	Boolean		flash_line;	/* show visualBell as current line */
   2936 	/*
   2937 	 * Select/paste state.
   2938 	 */
   2939 	Boolean		selectToClipboard; /* primary vs clipboard */
   2940 	String		*mappedSelect;	/* mapping for "SELECT" to "PRIMARY" */
   2941 
   2942 	Boolean		waitingForTrackInfo;
   2943 	int		numberOfClicks;
   2944 	int		maxClicks;
   2945 	int		multiClickTime;	/* time between multiclick selects */
   2946 	SelectUnit	selectUnit;
   2947 	SelectUnit	selectMap[NSELECTUNITS];
   2948 	String		onClick[NSELECTUNITS + 1];
   2949 
   2950 	char		*charClass;	/* for overriding word selection */
   2951 	Boolean		cutNewline;	/* whether or not line cut has \n */
   2952 	Boolean		cutToBeginningOfLine;  /* line cuts to BOL? */
   2953 	Boolean		highlight_selection; /* controls appearance of selection */
   2954 	Boolean		show_wrap_marks; /* show lines which are wrapped */
   2955 	Boolean		trim_selection; /* controls trimming of selection */
   2956 	Boolean		i18nSelections;
   2957 	Boolean		brokenSelections;
   2958 	Boolean		keepClipboard;	/* retain data sent to clipboard */
   2959 	Boolean		keepSelection;	/* do not lose selection on output */
   2960 	Boolean		replyToEmacs;	/* Send emacs escape code when done selecting or extending? */
   2961 
   2962 	SelectedCells	clipboard_data;	/* what we sent to the clipboard */
   2963 
   2964 	EventMode	eventMode;
   2965 	Time		selection_time;	/* latest event timestamp */
   2966 	Time		lastButtonUpTime;
   2967 	unsigned	lastButton;
   2968 
   2969 #define MAX_CUT_BUFFER  8		/* CUT_BUFFER0 to CUT_BUFFER7 */
   2970 #define MAX_SELECTIONS	(MAX_SELECTION_CODES + MAX_CUT_BUFFER)
   2971 	SelectedCells	selected_cells[MAX_SELECTIONS];
   2972 
   2973 	CELL		rawPos;		/* raw position for selection start */
   2974 	CELL		startRaw;	/* area before selectUnit processing */
   2975 	CELL		endRaw;		/* " " */
   2976 	CELL		startSel;	/* area after selectUnit processing */
   2977 	CELL		endSel;		/* " " */
   2978 	CELL		startH;		/* start highlighted text */
   2979 	CELL		endH;		/* end highlighted text */
   2980 	CELL		saveStartW;	/* saved WORD state, for LINE */
   2981 	CELL		startExt;	/* Start, end of extension */
   2982 	CELL		endExt;		/* " " */
   2983 	CELL		saveStartR;	/* Saved values of raw selection for extend to restore to */
   2984 	CELL		saveEndR;	/* " " */
   2985 	int		startHCoord, endHCoord;
   2986 	int		firstValidRow;	/* Valid rows for selection clipping */
   2987 	int		lastValidRow;	/* " " */
   2988 
   2989 #if OPT_BLOCK_SELECT
   2990 	int		lastSelectWasBlock;
   2991 	int		blockSelecting;	/* non-zero if block selection */
   2992 #endif
   2993 
   2994 	Boolean		selectToBuffer;	/* copy selection to buffer	*/
   2995 	InternalSelect	internal_select;
   2996 
   2997 	String		default_string;
   2998 	String		eightbit_select_types;
   2999 	Atom*		selection_targets_8bit;
   3000 #if OPT_WIDE_CHARS
   3001 	String		utf8_select_types;
   3002 	Atom*		selection_targets_utf8;
   3003 #endif
   3004 	Atom*		selection_atoms; /* which selections we own */
   3005 	Cardinal	sel_atoms_size;	 /* how many atoms allocated */
   3006 	Cardinal	selection_count; /* how many atoms in use */
   3007 #if OPT_SELECT_REGEX
   3008 	char *		selectExpr[NSELECTUNITS];
   3009 #endif
   3010 	/*
   3011 	 * Input/output state.
   3012 	 */
   3013 	Boolean		input_eight_bits;	/* do not send ESC when meta pressed */
   3014 	int		eight_bit_meta;		/* use 8th bit when meta pressed */
   3015 	char *		eight_bit_meta_s;	/* ...resource eightBitMeta */
   3016 	Boolean		output_eight_bits;	/* honor all bits or strip */
   3017 	Boolean		control_eight_bits;	/* send CSI as 8-bits */
   3018 	Boolean		backarrow_key;		/* backspace/delete */
   3019 	Boolean		alt_is_not_meta;	/* use both Alt- and Meta-key */
   3020 	Boolean		alt_sends_esc;		/* Alt-key sends ESC prefix */
   3021 	Boolean		meta_sends_esc;		/* Meta-key sends ESC prefix */
   3022 	/*
   3023 	 * Fonts
   3024 	 */
   3025 	Pixmap		menu_item_bitmap;	/* mask for checking items */
   3026 	String		initial_font;
   3027 	char *		menu_font_names[NMENUFONTS][fMAX];
   3028 #define MenuFontName(n) menu_font_names[n][fNorm]
   3029 #define EscapeFontName() MenuFontName(fontMenu_fontescape)
   3030 #define SelectFontName() MenuFontName(fontMenu_fontsel)
   3031 	long		menu_font_sizes[NMENUFONTS];
   3032 	int		menu_font_number;
   3033 #if OPT_LOAD_VTFONTS || OPT_WIDE_CHARS
   3034 	Boolean		savedVTFonts;
   3035 	Boolean		mergedVTFonts;
   3036 	SubResourceRec	cacheVTFonts;
   3037 #endif
   3038 #if OPT_CLIP_BOLD
   3039 	Boolean		use_border_clipping;
   3040 	Boolean		use_clipping;
   3041 #endif
   3042 	void *		main_cgs_cache;
   3043 #ifndef NO_ACTIVE_ICON
   3044 	void *		icon_cgs_cache;
   3045 #endif
   3046 #if OPT_RENDERFONT
   3047 	int		xft_max_glyph_memory;
   3048 	int		xft_max_unref_fonts;
   3049 	Boolean		xft_track_mem_usage;
   3050 	Boolean		force_xft_height;
   3051 	ListXftFonts	*list_xft_fonts;
   3052 	XTermXftFonts	renderFontNorm[NMENUFONTS];
   3053 	XTermXftFonts	renderFontBold[NMENUFONTS];
   3054 #if OPT_WIDE_ATTRS || OPT_RENDERWIDE
   3055 	XTermXftFonts	renderFontItal[NMENUFONTS];
   3056 	XTermXftFonts	renderFontBtal[NMENUFONTS];
   3057 #endif
   3058 #if OPT_RENDERWIDE
   3059 	XTermXftFonts	renderWideNorm[NMENUFONTS];
   3060 	XTermXftFonts	renderWideBold[NMENUFONTS];
   3061 	XTermXftFonts	renderWideItal[NMENUFONTS];
   3062 	XTermXftFonts	renderWideBtal[NMENUFONTS];
   3063 	TypedBuffer(XftCharSpec);
   3064 #else
   3065 	TypedBuffer(XftChar8);
   3066 #endif
   3067 	XftDraw *	renderDraw;
   3068 #endif
   3069 #if OPT_DABBREV
   3070 	Boolean		dabbrev_working;	/* nonzero during dabbrev process */
   3071 	unsigned char	dabbrev_erase_char;	/* used for deleting inserted completion */
   3072 #endif
   3073 	char		tcapbuf[TERMCAP_SIZE];
   3074 	char		tcap_area[TERMCAP_SIZE];
   3075 #if OPT_TCAP_FKEYS
   3076 	char **		tcap_fkeys;
   3077 #endif
   3078 	String		cursor_font_name;	/* alternate cursor font */
   3079 } TScreen;
   3080 
   3081 typedef XTermFonts *(*MyGetFont) (TScreen *, int);
   3082 
   3083 typedef struct _TekPart {
   3084 	XFontStruct *	Tfont[TEKNUMFONTS];
   3085 	int		tobaseline[TEKNUMFONTS]; /* top-baseline, each font */
   3086 	char *		initial_font;		/* large, 2, 3, small */
   3087 	char *		gin_terminator_str;	/* ginTerminator resource */
   3088 #if OPT_TOOLBAR
   3089 	TbInfo		tb_info;	/* toolbar information		*/
   3090 #endif
   3091 } TekPart;
   3092 
   3093 /* Tektronix window parameters */
   3094 typedef struct _TekScreen {
   3095 	GC		TnormalGC;	/* normal painting		*/
   3096 	GC		TcursorGC;	/* normal cursor painting	*/
   3097 
   3098 	Boolean		waitrefresh;	/* postpone refresh		*/
   3099 	TKwin		fullTwin;
   3100 #ifndef NO_ACTIVE_ICON
   3101 	TKwin		iconTwin;
   3102 	TKwin		*whichTwin;
   3103 #endif /* NO_ACTIVE_ICON */
   3104 
   3105 	Cursor		arrow;		/* arrow cursor			*/
   3106 	GC		linepat[TEKNUMLINES]; /* line patterns		*/
   3107 	int		cur_X;		/* current x			*/
   3108 	int		cur_Y;		/* current y			*/
   3109 	Tmodes		cur;		/* current tek modes		*/
   3110 	Tmodes		page;		/* starting tek modes on page	*/
   3111 	int		margin;		/* 0 -> margin 1, 1 -> margin 2	*/
   3112 	int		pen;		/* current Tektronix pen 0=up, 1=dn */
   3113 	char		*TekGIN;	/* nonzero if Tektronix GIN mode*/
   3114 	int		gin_terminator; /* Tek strap option */
   3115 	char		tcapbuf[TERMCAP_SIZE];
   3116 } TekScreen;
   3117 
   3118 #if OPT_PASTE64 || OPT_READLINE
   3119 #define SCREEN_FLAG(screenp,f)		(1&(screenp)->f)
   3120 #define SCREEN_FLAG_set(screenp,f)	((screenp)->f |= 1)
   3121 #define SCREEN_FLAG_unset(screenp,f)	((screenp)->f &= (unsigned) ~1L)
   3122 #define SCREEN_FLAG_save(screenp,f)	\
   3123 	((screenp)->f = (((screenp)->f)<<1) | SCREEN_FLAG(screenp,f))
   3124 #define SCREEN_FLAG_restore(screenp,f)	((screenp)->f = (((screenp)->f)>>1))
   3125 #else
   3126 #define SCREEN_FLAG(screenp,f)		(0)
   3127 #endif
   3128 
   3129 /*
   3130  * After screen-updates, reset the flag that tells us we should do wrapping.
   3131  * Likewise, reset (in wide-character mode) the flag that tells us where the
   3132  * "previous" character was written.
   3133  */
   3134 #if OPT_WIDE_CHARS
   3135 #define ResetWrap(screen) \
   3136     (screen)->do_wrap = \
   3137     (screen)->char_was_written = False
   3138 #else
   3139 #define ResetWrap(screen) \
   3140     (screen)->do_wrap = False
   3141 #endif
   3142 
   3143 /* meaning of bits in screen.select flag */
   3144 #define	INWINDOW	01	/* the mouse is in one of the windows */
   3145 #define	FOCUS		02	/* one of the windows is the focus window */
   3146 
   3147 #define MULTICLICKTIME 250	/* milliseconds */
   3148 
   3149 typedef struct {
   3150     const char *name;
   3151     int code;
   3152 } FlagList;
   3153 
   3154 typedef enum {
   3155     keyboardIsLegacy,		/* bogus vt220 codes for F1-F4, etc. */
   3156     keyboardIsDefault,
   3157     keyboardIsHP,
   3158     keyboardIsSCO,
   3159     keyboardIsSun,
   3160     keyboardIsTermcap,
   3161     keyboardIsVT220
   3162 } xtermKeyboardType;
   3163 
   3164 typedef enum {			/* legal values for screen.pointer_mode */
   3165     pNever = 0
   3166     , pNoMouse = 1
   3167     , pAlways = 2
   3168     , pFocused = 3
   3169 } pointerModeTypes;
   3170 
   3171 typedef enum {			/* legal values for screen.utf8_mode */
   3172     uFalse = 0
   3173     , uTrue = 1
   3174     , uAlways = 2
   3175     , uDefault = 3
   3176     , uLast
   3177 } utf8ModeTypes;
   3178 
   3179 typedef enum {			/* legal values for screen.eight_bit_meta */
   3180     ebFalse = 0
   3181     , ebTrue = 1
   3182     , ebNever = 2
   3183     , ebLocale = 3
   3184     , ebLast
   3185 } ebMetaModeTypes;
   3186 
   3187 typedef enum {			/* legal values for misc.cdXtraScroll */
   3188     edFalse = 0
   3189     , edTrue = 1
   3190     , edTrim = 2
   3191     , edLast
   3192 } edXtraScrollTypes;
   3193 
   3194 #define NAME_OLD_KT " legacy"
   3195 
   3196 #if OPT_HP_FUNC_KEYS
   3197 #define NAME_HP_KT " hp"
   3198 #else
   3199 #define NAME_HP_KT /*nothing*/
   3200 #endif
   3201 
   3202 #if OPT_SCO_FUNC_KEYS
   3203 #define NAME_SCO_KT " sco"
   3204 #else
   3205 #define NAME_SCO_KT /*nothing*/
   3206 #endif
   3207 
   3208 #if OPT_SUN_FUNC_KEYS
   3209 #define NAME_SUN_KT " sun"
   3210 #else
   3211 #define NAME_SUN_KT /*nothing*/
   3212 #endif
   3213 
   3214 #if OPT_SUNPC_KBD
   3215 #define NAME_VT220_KT " vt220"
   3216 #else
   3217 #define NAME_VT220_KT /*nothing*/
   3218 #endif
   3219 
   3220 #if OPT_TCAP_FKEYS
   3221 #define NAME_TCAP_KT " tcap"
   3222 #else
   3223 #define NAME_TCAP_KT /*nothing*/
   3224 #endif
   3225 
   3226 #define KEYBOARD_TYPES NAME_TCAP_KT NAME_HP_KT NAME_SCO_KT NAME_SUN_KT NAME_VT220_KT
   3227 
   3228 #if OPT_TRACE
   3229 #define TRACE_RC(code,func) code = func
   3230 #else
   3231 #define TRACE_RC(code,func) func
   3232 #endif
   3233 
   3234 extern	const char * visibleKeyboardType(xtermKeyboardType);
   3235 
   3236 typedef struct
   3237 {
   3238     int allow_keys;		/* how to handle legacy/vt220 keyboard */
   3239     int cursor_keys;		/* how to handle cursor-key modifiers */
   3240     int function_keys;		/* how to handle function-key modifiers */
   3241     int keypad_keys;		/* how to handle keypad key-modifiers */
   3242     int other_keys;		/* how to handle other key-modifiers */
   3243     int string_keys;		/* how to handle string() modifiers */
   3244 } TModify;
   3245 
   3246 typedef struct
   3247 {
   3248     xtermKeyboardType type;
   3249     IFlags flags;
   3250     char *shell_translations;	/* shell's translations, for input check */
   3251     char *xterm_translations;	/* xterm's translations, for input check */
   3252     char *extra_translations;
   3253     char *print_translations;	/* printable translations for buttons */
   3254     unsigned shift_buttons;	/* special shift-modifier for mouse-buttons */
   3255     int shift_escape;		/* working value of shiftEscape */
   3256     char * shift_escape_s;	/* resource for shiftEscape */
   3257 #if OPT_INITIAL_ERASE
   3258     int	reset_DECBKM;		/* reset should set DECBKM */
   3259 #endif
   3260 #if OPT_MOD_FKEYS
   3261     TModify modify_now;		/* current modifier value */
   3262     TModify modify_1st;		/* original modifier value, for resets */
   3263     int format_keys;		/* format of modifyOtherKeys */
   3264 #endif
   3265 } TKeyboard;
   3266 
   3267 #define GravityIsNorthWest(w) ((w)->misc.resizeGravity == NorthWestGravity)
   3268 #define GravityIsSouthWest(w) ((w)->misc.resizeGravity == SouthWestGravity)
   3269 
   3270 typedef struct _Misc {
   3271     VTFontNames default_font;
   3272     char *geo_metry;
   3273     char *T_geometry;
   3274 #if OPT_WIDE_CHARS
   3275     Boolean cjk_width;		/* true for built-in CJK wcwidth() */
   3276     Boolean mk_width;		/* true for simpler built-in wcwidth() */
   3277     int mk_samplesize;
   3278     int mk_samplepass;
   3279 #endif
   3280 #if OPT_LUIT_PROG
   3281     Boolean callfilter;		/* true to invoke luit */
   3282     Boolean use_encoding;	/* true to use -encoding option for luit */
   3283     char *locale_str;		/* "locale" resource */
   3284     char *localefilter;		/* path for luit */
   3285 #endif
   3286     fontWarningTypes fontWarnings;
   3287     int limit_resize;
   3288 #ifdef ALLOWLOGGING
   3289     Boolean log_on;
   3290 #endif
   3291     Boolean color_inner_border;
   3292     Boolean login_shell;
   3293     Boolean re_verse;
   3294     Boolean re_verse0;		/* initial value of "-rv" */
   3295     Boolean resizeByPixel;
   3296     XtGravity resizeGravity;
   3297     Boolean reverseWrap;
   3298     Boolean autoWrap;
   3299     Boolean logInhibit;
   3300     Boolean signalInhibit;
   3301 #if OPT_TEK4014
   3302     Boolean tekInhibit;
   3303     Boolean tekSmall;		/* start tek window in small size */
   3304     Boolean TekEmu;		/* true if Tektronix emulation	*/
   3305     Boolean Tshow;		/* Tek window showing		*/
   3306 #endif
   3307     Boolean scrollbar;
   3308 #ifdef SCROLLBAR_RIGHT
   3309     Boolean useRight;
   3310 #endif
   3311     Boolean titeInhibit;
   3312     Boolean appcursorDefault;
   3313     Boolean appkeypadDefault;
   3314     int cdXtraScroll;		/* scroll on cd (clear-display) */
   3315     char *cdXtraScroll_s;
   3316     int tiXtraScroll;		/* scroll on ti/te (init/end-cup) */
   3317     char *tiXtraScroll_s;
   3318 #if OPT_INPUT_METHOD
   3319     char* f_x;			/* font for XIM */
   3320     char* input_method;
   3321     char* preedit_type;
   3322     Boolean open_im;		/* true if input-method is opened */
   3323     int retry_im;
   3324 #endif
   3325     Boolean dynamicColors;
   3326 #ifndef NO_ACTIVE_ICON
   3327     char *active_icon_s;	/* use application icon window  */
   3328     unsigned icon_border_width;
   3329     Pixel icon_border_pixel;
   3330 #endif /* NO_ACTIVE_ICON */
   3331 #if OPT_DEC_SOFTFONT
   3332     Boolean font_loadable;
   3333 #endif
   3334 #if OPT_SHIFT_FONTS
   3335     Boolean shift_fonts;	/* true if we interpret fontsize-shifting */
   3336 #endif
   3337 #if OPT_SUNPC_KBD
   3338     int ctrl_fkeys;		/* amount to add to XK_F1 for ctrl modifier */
   3339 #endif
   3340 #if OPT_NUM_LOCK
   3341     Boolean real_NumLock;	/* true if we treat NumLock key specially */
   3342     Boolean alwaysUseMods;	/* true if we always want f-key modifiers */
   3343 #endif
   3344 #if OPT_RENDERFONT
   3345     VTFontNames default_xft;
   3346     float face_size[NMENUFONTS];
   3347     char *render_font_s;
   3348     int limit_fontsets;
   3349     int limit_fontheight;
   3350     int limit_fontwidth;
   3351 #endif
   3352 } Misc;
   3353 
   3354 typedef struct _Work {
   3355     int dummy;
   3356 #ifdef SunXK_F36
   3357 #define MAX_UDK 37
   3358 #else
   3359 #define MAX_UDK 35
   3360 #endif
   3361     struct {
   3362 	char *str;
   3363 	int len;
   3364     } user_keys[MAX_UDK];
   3365 #define MAX_POINTER (XC_num_glyphs/2)
   3366     Cursor pointer_cursors[MAX_POINTER]; /* saved cursors	*/
   3367 #ifndef NO_ACTIVE_ICON
   3368     int active_icon;		/* use application icon window  */
   3369     char *wm_name;
   3370 #endif /* NO_ACTIVE_ICON */
   3371 #if OPT_INPUT_METHOD
   3372     Boolean cannot_im;		/* true if we cannot use input-method */
   3373     XFontSet xim_fs;		/* fontset for XIM preedit */
   3374     int xim_fs_ascent;		/* ascent of fs */
   3375     TInput inputs[NINPUTWIDGETS];
   3376 #endif
   3377     Boolean doing_resize;	/* currently in RequestResize */
   3378 #if OPT_MAXIMIZE
   3379 #define MAX_EWMH_MODE 3
   3380 #define MAX_EWMH_DATA (1 + OPT_TEK4014)
   3381     struct {
   3382 	int mode;		/* fullscreen, etc.		*/
   3383 	Boolean checked[MAX_EWMH_MODE + 1];
   3384 	Boolean allowed[MAX_EWMH_MODE + 1];
   3385     } ewmh[MAX_EWMH_DATA];
   3386 #endif
   3387 #if OPT_NUM_LOCK
   3388     unsigned num_lock;		/* modifier for Num_Lock */
   3389     unsigned alt_mods;		/* modifier for Alt_L or Alt_R */
   3390     unsigned meta_mods;		/* modifier for Meta_L or Meta_R */
   3391 #endif
   3392     XtermFontNames fonts;
   3393     Boolean force_wideFont;	/* true to single-step wideFont	*/
   3394 #if OPT_RENDERFONT
   3395     Boolean render_font;
   3396     FcPattern *xft_defaults;
   3397     unsigned max_fontsets;
   3398 #endif
   3399 #if OPT_DABBREV
   3400 #define MAX_DABBREV	1024	/* maximum word length as in tcsh */
   3401     char dabbrev_data[MAX_DABBREV];
   3402 #endif
   3403     ScrnColors *oldColors;
   3404     Boolean palette_changed;
   3405     Boolean broken_box_chars;
   3406     /* data write dotext/WriteText */
   3407     IChar *write_text;		/* points to print_area */
   3408 #if OPT_DEC_RECTOPS
   3409     Char *write_sums;		/* if non-null, points to buffer_sums */
   3410     Char *buffer_sums;		/* data for ->charSeen[] */
   3411     Char *buffer_sets;		/* data for ->charSets[] */
   3412     size_t sizeof_sums;		/* allocated size of buffer_sums */
   3413 #endif
   3414 } Work;
   3415 
   3416 typedef struct {int foo;} XtermClassPart, TekClassPart;
   3417 
   3418 typedef struct _XtermClassRec {
   3419     CoreClassPart  core_class;
   3420     XtermClassPart xterm_class;
   3421 } XtermClassRec;
   3422 
   3423 extern WidgetClass xtermWidgetClass;
   3424 
   3425 #define IsXtermWidget(w) (XtClass(w) == xtermWidgetClass)
   3426 
   3427 #if OPT_TEK4014
   3428 typedef struct _TekClassRec {
   3429     CoreClassPart core_class;
   3430     TekClassPart tek_class;
   3431 } TekClassRec;
   3432 
   3433 extern WidgetClass tekWidgetClass;
   3434 
   3435 #define IsTekWidget(w) (XtClass(w) == tekWidgetClass)
   3436 
   3437 #endif
   3438 
   3439 /* define masks for keyboard.flags */
   3440 #define MODE_KAM	xBIT(0)	/* mode 2: keyboard action mode */
   3441 #define MODE_DECKPAM	xBIT(1)	/* keypad application mode */
   3442 #define MODE_DECCKM	xBIT(2)	/* private mode 1: cursor keys */
   3443 #define MODE_SRM	xBIT(3)	/* mode 12: send-receive mode */
   3444 #define MODE_DECBKM	xBIT(4)	/* private mode 67: backarrow */
   3445 #define MODE_DECSDM	xBIT(5)	/* private mode 80: sixel DISPLAY mode -- note, when SDM is off, the terminal is in sixel SCROLLING mode  */
   3446 
   3447 #define N_MARGINBELL	10
   3448 
   3449 #define TAB_BITS_SHIFT	5	/* FIXME: 2**5 == 32 (should derive) */
   3450 #define TAB_BITS_WIDTH	(1 << TAB_BITS_SHIFT)
   3451 #define TAB_ARRAY_SIZE	(1024 / TAB_BITS_WIDTH)
   3452 #define MAX_TABS	(TAB_BITS_WIDTH * TAB_ARRAY_SIZE)
   3453 
   3454 #define OkTAB(c)	((c) > 0 && (c) < MAX_TABS)
   3455 
   3456 typedef unsigned Tabs [TAB_ARRAY_SIZE];
   3457 
   3458 #if OPT_XTERM_SGR
   3459 #define MAX_SAVED_SGR	10
   3460 typedef	struct {
   3461     int		used;
   3462     struct	{
   3463 	IFlags	mask;
   3464 	IFlags	flags;
   3465 #if OPT_ISO_COLORS
   3466 	int	sgr_foreground;
   3467 	int	sgr_background;
   3468 	Boolean	sgr_38_xcolors;
   3469 #endif
   3470     } stack[MAX_SAVED_SGR];
   3471 } SavedSGR;
   3472 
   3473 typedef struct {
   3474     ScrnColors base;
   3475     ColorRes ansi[1];
   3476 } ColorSlot;
   3477 
   3478 typedef struct {
   3479     int		used;		/* currently saved or restored	*/
   3480     int		last;		/* maximum number of saved palettes */
   3481     ColorSlot	*palettes[MAX_SAVED_SGR];
   3482 } SavedColors;
   3483 #endif /* OPT_XTERM_SGR */
   3484 
   3485 typedef struct _XtermWidgetRec {
   3486     CorePart	core;
   3487     XSizeHints	hints;
   3488     XVisualInfo *visInfo;
   3489     int		numVisuals;
   3490     unsigned	rgb_shifts[3];
   3491     unsigned	rgb_widths[3];
   3492     Bool	has_rgb;
   3493     Bool	init_menu;
   3494     TKeyboard	keyboard;	/* terminal keyboard		*/
   3495     TScreen	screen;		/* terminal screen		*/
   3496     IFlags	flags;		/* mode flags			*/
   3497     int		cur_foreground; /* current foreground color	*/
   3498     int		cur_background; /* current background color	*/
   3499     Pixel	dft_foreground; /* default foreground color	*/
   3500     Pixel	dft_background; /* default background color	*/
   3501     Pixel	old_foreground; /* original foreground color	*/
   3502     Pixel	old_background; /* original background color	*/
   3503 #if OPT_ISO_COLORS
   3504     int		sgr_foreground; /* current SGR foreground color */
   3505     int		sgr_background; /* current SGR background color */
   3506     Boolean	sgr_38_xcolors;	/* true if ISO 8613 extension	*/
   3507 #endif
   3508     IFlags	initflags;	/* initial mode flags		*/
   3509     Tabs	tabs;		/* tabstops of the terminal	*/
   3510     Misc	misc;		/* miscellaneous parameters	*/
   3511     Work	work;		/* workspace (no resources)	*/
   3512 #if OPT_XTERM_SGR
   3513     SavedSGR	saved_sgr;
   3514     SavedColors	saved_colors;
   3515 #endif
   3516 } XtermWidgetRec, *XtermWidget;
   3517 
   3518 #if OPT_TEK4014
   3519 typedef struct _TekWidgetRec {
   3520     CorePart	core;
   3521     XtermWidget vt;		/* main widget has border, etc. */
   3522     TekPart	tek;		/* contains resources */
   3523     TekScreen	screen;		/* contains working data (no resources) */
   3524     Bool	init_menu;
   3525     XSizeHints	hints;
   3526 } TekWidgetRec, *TekWidget;
   3527 #endif /* OPT_TEK4014 */
   3528 
   3529 /*
   3530  * terminal flags
   3531  * There are actually two namespaces mixed together here:
   3532  * a) One is the set of flags that can go in screen->visbuf attributes and
   3533  *    which must fit in an IAttr (either a char or short, depending on whether
   3534  *    wide-attributes are used).
   3535  * b) The other is the global setting stored in term->flags and
   3536  *    screen->save_modes, which fits in an unsigned (IFlags).
   3537  */
   3538 
   3539 #define AttrBIT(n)	xBIT(n)		/* text-attributes */
   3540 #define MiscBIT(n)	xBIT(n + 16)	/* miscellaneous state flags */
   3541 
   3542 /* global flags and character flags (visible character attributes) */
   3543 #define INVERSE		AttrBIT(0)	/* invert the characters to be output */
   3544 #define UNDERLINE	AttrBIT(1)	/* true if underlining */
   3545 #define BOLD		AttrBIT(2)
   3546 #define BLINK		AttrBIT(3)
   3547 /* global flags (also character attributes) */
   3548 #define BG_COLOR	AttrBIT(4)	/* true if background set */
   3549 #define FG_COLOR	AttrBIT(5)	/* true if foreground set */
   3550 
   3551 /* character flags (internal attributes) */
   3552 #define PROTECTED	AttrBIT(6)	/* a character that cannot be erased */
   3553 #define CHARDRAWN	AttrBIT(7)	/* a character has been drawn here on
   3554 					   the screen.  Used to distinguish
   3555 					   blanks from empty parts of the
   3556 					   screen when selecting */
   3557 /*
   3558  * This does not fit in a byte with the other (more important) attributes, but
   3559  * if wide-attributes are configured, it is possible to maintain it there.
   3560  */
   3561 #define INVISIBLE	AttrBIT(8)	/* true if writing invisible text */
   3562 
   3563 #if OPT_WIDE_ATTRS
   3564 #define ATR_FAINT	AttrBIT(9)
   3565 #define ATR_ITALIC	AttrBIT(10)
   3566 #define ATR_STRIKEOUT	AttrBIT(11)
   3567 #define ATR_DBL_UNDER	AttrBIT(12)
   3568 #define ATR_DIRECT_FG	AttrBIT(13)
   3569 #define ATR_DIRECT_BG	AttrBIT(14)
   3570 #define SGR_MASK2       (ATR_FAINT | ATR_ITALIC | ATR_STRIKEOUT | ATR_DBL_UNDER | ATR_DIRECT_FG | ATR_DIRECT_BG)
   3571 #define AttrEND         15
   3572 #else
   3573 #define SGR_MASK2       0
   3574 #define AttrEND         9
   3575 #endif
   3576 
   3577 /*
   3578  * Other flags
   3579  */
   3580 #define REVERSE_VIDEO	MiscBIT(0)	/* true if screen white on black */
   3581 #define WRAPAROUND	MiscBIT(1)	/* true if auto wraparound mode */
   3582 #define	REVERSEWRAP	MiscBIT(2)	/* true if reverse wraparound mode */
   3583 #define	REVERSEWRAP2	MiscBIT(3)	/* true if extended reverse wraparound */
   3584 #define LINEFEED	MiscBIT(4)	/* true if in auto linefeed mode */
   3585 #define ORIGIN		MiscBIT(5)	/* true if in origin mode */
   3586 #define INSERT		MiscBIT(6)	/* true if in insert mode */
   3587 #define SMOOTHSCROLL	MiscBIT(7)	/* true if in smooth scroll mode */
   3588 #define IN132COLUMNS	MiscBIT(8)	/* true if in 132 column mode */
   3589 #define NATIONAL        MiscBIT(9)	/* true if writing national charset */
   3590 #define LEFT_RIGHT      MiscBIT(10)	/* true if left/right margin mode */
   3591 #define NOCLEAR_COLM    MiscBIT(11)	/* true if no clear on DECCOLM change */
   3592 
   3593 /*
   3594  * Drawing-bits start after the video/color attributes, and are independent
   3595  * of the miscellaneous flags.
   3596  */
   3597 #define DrawBIT(n)	xBIT(n + AttrEND) /* XTermDraw.draw_flags */
   3598 /* The following attributes are used in the argument of drawXtermText()  */
   3599 #define NOBACKGROUND	DrawBIT(0)	/* Used for overstrike */
   3600 #define NOTRANSLATION	DrawBIT(1)	/* No scan for chars missing in font */
   3601 #define DOUBLEWFONT	DrawBIT(2)	/* The actual X-font is double-width */
   3602 #define DOUBLEHFONT	DrawBIT(3)	/* The actual X-font is double-height */
   3603 #define DOUBLEFIRST	DrawBIT(4)	/* Draw chars one-by-one */
   3604 #define CHARBYCHAR	DrawBIT(5)	/* Draw chars one-by-one */
   3605 
   3606 /* The following attribute is used in the argument of xtermSpecialFont etc */
   3607 #define NORESOLUTION	DrawBIT(6)	/* find the font without resolution */
   3608 
   3609 /*
   3610  * Groups of attributes
   3611  */
   3612 			/* mask for video-attributes only */
   3613 #define SGR_MASK	(BOLD | BLINK | UNDERLINE | INVERSE)
   3614 
   3615 			/* mask: user-visible attributes */
   3616 #define	ATTRIBUTES	(SGR_MASK | SGR_MASK2 | BG_COLOR | FG_COLOR | INVISIBLE | PROTECTED)
   3617 
   3618 /* The toplevel-call to drawXtermText() should have text-attributes guarded: */
   3619 #define DRAWX_MASK	(ATTRIBUTES | CHARDRAWN)
   3620 
   3621 /*
   3622  * BOLDATTR is not only nonzero when we will use bold font, but uses the bits
   3623  * for BOLD/BLINK to match against the video attributes which were originally
   3624  * requested.
   3625  */
   3626 #define USE_BOLD(screen) ((screen)->allowBoldFonts)
   3627 
   3628 #if OPT_BLINK_TEXT
   3629 #define BOLDATTR(screen) (unsigned) (USE_BOLD(screen) ? (BOLD | ((screen)->blink_as_bold ? BLINK : 0)) : 0)
   3630 #else
   3631 #define BOLDATTR(screen) (unsigned) (USE_BOLD(screen) ? (BOLD | BLINK) : 0)
   3632 #endif
   3633 
   3634 /*
   3635  * Sixel scrolling is on when Sixel Display Mode is off, and vice versa.
   3636  * (Note: DEC erroneously conflates the two in the VT330/340 manual).
   3637  */
   3638 #define SixelScrolling(xw) (!((xw)->keyboard.flags & MODE_DECSDM))
   3639 
   3640 /*
   3641  * Per-line flags
   3642  */
   3643 #define LINEWRAPPED	AttrBIT(0)
   3644 /* used once per line to indicate that it wraps onto the next line so we can
   3645  * tell the difference between lines that have wrapped around and lines that
   3646  * have ended naturally with a CR at column max_col.
   3647  */
   3648 #define LINEBLINKED	AttrBIT(1)
   3649 /* set when the line contains blinking text.
   3650  */
   3651 
   3652 #if OPT_ZICONBEEP || OPT_TOOLBAR || (USE_DOUBLE_BUFFER && OPT_RENDERFONT)
   3653 #define HANDLE_STRUCT_NOTIFY 1
   3654 #else
   3655 #define HANDLE_STRUCT_NOTIFY 0
   3656 #endif
   3657 
   3658 /*
   3659  * If we've set protected attributes with the DEC-style DECSCA, then we'll have
   3660  * to use DECSED or DECSEL to erase preserving protected text.  (The normal ED,
   3661  * EL won't preserve protected-text).  If we've used SPA, then normal ED and EL
   3662  * will preserve protected-text.  To keep things simple, just remember the last
   3663  * control that was used to begin protected-text, and use that to determine how
   3664  * erases are performed (otherwise we'd need 2 bits per protected character).
   3665  */
   3666 #define OFF_PROTECT 0
   3667 #define DEC_PROTECT 1
   3668 #define ISO_PROTECT 2
   3669 
   3670 /***====================================================================***/
   3671 
   3672 /*
   3673  * Reduce parameter-count of drawXtermText by putting less-modified data here.
   3674  */
   3675 typedef struct {
   3676 	XtermWidget	xw;
   3677 	unsigned	attr_flags;
   3678 	unsigned	draw_flags;
   3679 	unsigned	this_chrset;
   3680 	unsigned	real_chrset;
   3681 	int		on_wide;
   3682 } XTermDraw;
   3683 
   3684 /***====================================================================***/
   3685 
   3686 #define TScreenOf(xw)	(&(xw)->screen)
   3687 #define TekScreenOf(tw) (&(tw)->screen)
   3688 
   3689 #define PrinterOf(screen) (screen)->printer_state
   3690 
   3691 #ifdef SCROLLBAR_RIGHT
   3692 #define OriginX(screen) (((term->misc.useRight)?0:ScrollbarWidth(screen)) + screen->border)
   3693 #else
   3694 #define OriginX(screen) (ScrollbarWidth(screen) + screen->border)
   3695 #endif
   3696 
   3697 #define OriginY(screen) (screen->border)
   3698 
   3699 #define CursorMoved(screen) \
   3700 		((screen)->cursor_moved || \
   3701 		    ((screen)->cursorp.col != (screen)->cur_col || \
   3702 		     (screen)->cursorp.row != (screen)->cur_row))
   3703 
   3704 #define CursorX2(screen,col,fw) ((col) * (int)(fw) + OriginX(screen))
   3705 #define CursorX(screen,col)     CursorX2(screen, col, FontWidth(screen))
   3706 #define CursorY2(screen,row)    (((row) * FontHeight(screen)) + screen->border)
   3707 #define CursorY(screen,row)     CursorY2(screen, INX2ROW(screen, row))
   3708 
   3709 /*
   3710  * These definitions depend on whether xterm supports active-icon.
   3711  */
   3712 #ifndef NO_ACTIVE_ICON
   3713 #define IsIconWin(screen,win)	((win) == &(screen)->iconVwin)
   3714 #define IsIcon(screen)		(WhichVWin(screen) == &(screen)->iconVwin)
   3715 #define WhichVWin(screen)	((screen)->whichVwin)
   3716 #define WhichTWin(screen)	((screen)->whichTwin)
   3717 
   3718 #define WhichVFont(screen,name)	(IsIcon(screen) ? getIconicFont(screen) \
   3719 						: getNormalFont(screen, (int)(name)))->fs
   3720 #define FontAscent(screen)	(IsIcon(screen) ? getIconicFont(screen)->fs->ascent \
   3721 						: WhichVWin(screen)->f_ascent)
   3722 #define FontDescent(screen)	(IsIcon(screen) ? getIconicFont(screen)->fs->descent \
   3723 						: WhichVWin(screen)->f_descent)
   3724 #else /* NO_ACTIVE_ICON */
   3725 
   3726 #define IsIconWin(screen,win)	(False)
   3727 #define IsIcon(screen)		(False)
   3728 #define WhichVWin(screen)	(&((screen)->fullVwin))
   3729 #define WhichTWin(screen)	(&((screen)->fullTwin))
   3730 
   3731 #define WhichVFont(screen,name)	getNormalFont(screen, (int)(name))->fs
   3732 #define FontAscent(screen)	WhichVWin(screen)->f_ascent
   3733 #define FontDescent(screen)	WhichVWin(screen)->f_descent
   3734 
   3735 #endif /* NO_ACTIVE_ICON */
   3736 
   3737 #define okFont(font) ((font) != NULL && (font)->fid != 0)
   3738 
   3739 /*
   3740  * Macro to check if we are iconified; do not use render for that case.
   3741  */
   3742 #define UsingRenderFont(xw)	(((xw)->work.render_font == True) && !IsIcon(TScreenOf(xw)))
   3743 
   3744 /*
   3745  * These definitions do not depend on whether xterm supports active-icon.
   3746  */
   3747 #define VWindow(screen)		WhichVWin(screen)->window
   3748 #define VShellWindow(xw)	XtWindow(SHELL_OF(xw))
   3749 #define TWindow(screen)		WhichTWin(screen)->window
   3750 #define TShellWindow		XtWindow(SHELL_OF(tekWidget))
   3751 
   3752 #if USE_DOUBLE_BUFFER
   3753 extern Window VDrawable(TScreen * /* screen */);
   3754 #else
   3755 #define VDrawable(screen)	VWindow(screen)
   3756 #endif
   3757 
   3758 #define Width(screen)		WhichVWin(screen)->width
   3759 #define Height(screen)		WhichVWin(screen)->height
   3760 #define FullWidth(screen)	WhichVWin(screen)->fullwidth
   3761 #define FullHeight(screen)	WhichVWin(screen)->fullheight
   3762 #define FontWidth(screen)	WhichVWin(screen)->f_width
   3763 #define FontHeight(screen)	WhichVWin(screen)->f_height
   3764 
   3765 #define NormalFont(screen)	WhichVFont(screen, fNorm)
   3766 #define BoldFont(screen)	WhichVFont(screen, fBold)
   3767 
   3768 #if OPT_WIDE_CHARS
   3769 #define NormalWFont(screen)	WhichVFont(screen, fWide)
   3770 #define BoldWFont(screen)	WhichVFont(screen, fWBold)
   3771 #endif
   3772 
   3773 #define ScrollbarWidth(screen)	WhichVWin(screen)->sb_info.width
   3774 
   3775 /* y -> y_shift, to center text versus the cursor */
   3776 #define ScaleShift(screen) \
   3777 	    (int) ((IsIcon(screen) || (screen->scale_height <= 1.0f)) \
   3778 	           ? 0.0f \
   3779 	           : ((float) WhichVWin(screen)->f_height \
   3780 		      * ((float) screen->scale_height - 1.0f) / 2.0f))
   3781 
   3782 #define BorderGC(w,sp)		WhichVWin(sp)->border_gc
   3783 #define FillerGC(w,sp)		WhichVWin(sp)->filler_gc
   3784 #define NormalGC(w,sp)		getCgsGC(w, WhichVWin(sp), gcNorm)
   3785 #define ReverseGC(w,sp)		getCgsGC(w, WhichVWin(sp), gcNormReverse)
   3786 #define NormalBoldGC(w,sp)	getCgsGC(w, WhichVWin(sp), gcBold)
   3787 #define ReverseBoldGC(w,sp)	getCgsGC(w, WhichVWin(sp), gcBoldReverse)
   3788 
   3789 #define TWidth(screen)		WhichTWin(screen)->width
   3790 #define THeight(screen)		WhichTWin(screen)->height
   3791 #define TFullWidth(screen)	WhichTWin(screen)->fullwidth
   3792 #define TFullHeight(screen)	WhichTWin(screen)->fullheight
   3793 #define TekScale(screen)	WhichTWin(screen)->tekscale
   3794 
   3795 /* use these before tek4014 is realized, good enough for default "9x15" font */
   3796 #define TDefaultRows		37
   3797 #define TDefaultCols		75
   3798 
   3799 #define BorderWidth(w)		((w)->core.border_width)
   3800 #define BorderPixel(w)		((w)->core.border_pixel)
   3801 
   3802 #define AllowXtermOps(w,name)	(TScreenOf(w)->name && !TScreenOf(w)->allowSendEvents)
   3803 
   3804 #define AllowColorOps(w,name)	(AllowXtermOps(w, allowColorOps) || \
   3805 				 !TScreenOf(w)->disallow_color_ops[name])
   3806 
   3807 #define AllowFontOps(w,name)	(AllowXtermOps(w, allowFontOps) || \
   3808 				 !TScreenOf(w)->disallow_font_ops[name])
   3809 
   3810 #define AllowMouseOps(w,name)	(AllowXtermOps(w, allowMouseOps) || \
   3811 				 !TScreenOf(w)->disallow_mouse_ops[name])
   3812 
   3813 #define AllowTcapOps(w,name)	(AllowXtermOps(w, allowTcapOps) || \
   3814 				 !TScreenOf(w)->disallow_tcap_ops[name])
   3815 
   3816 #define AllowTitleOps(w)	AllowXtermOps(w, allowTitleOps)
   3817 
   3818 #define AllowXResOps(w)		True
   3819 
   3820 #define SpecialWindowOps(w,name) (!TScreenOf(w)->disallow_win_ops[name])
   3821 #define AllowWindowOps(w,name)	(AllowXtermOps(w, allowWindowOps) || \
   3822 				 SpecialWindowOps(w,name))
   3823 
   3824 #if OPT_TOOLBAR
   3825 #define ToolbarHeight(w)	((resource.toolBar) \
   3826 				 ? ((w)->VT100_TB_INFO(menu_height) \
   3827 				  + (w)->VT100_TB_INFO(menu_border) * 2) \
   3828 				 : 0)
   3829 #else
   3830 #define ToolbarHeight(w) 0
   3831 #endif
   3832 
   3833 #if OPT_TEK4014
   3834 #define TEK_LINK_BLOCK_SIZE 1024
   3835 
   3836 typedef struct Tek_Link
   3837 {
   3838 	struct Tek_Link	*next;	/* pointer to next TekLink in list
   3839 				   NULL <=> this is last TekLink */
   3840 	unsigned short fontsize;/* character size, 0-3 */
   3841 	unsigned short count;	/* number of chars in data */
   3842 	char *ptr;		/* current pointer into data */
   3843 	char data [TEK_LINK_BLOCK_SIZE];
   3844 } TekLink;
   3845 #endif /* OPT_TEK4014 */
   3846 
   3847 /* flags for cursors */
   3848 #define	OFF		0
   3849 #define	ON		1
   3850 #define	BLINKED_OFF	2
   3851 #define	CLEAR		0
   3852 #define	TOGGLE		1
   3853 
   3854 /* flags for inhibit */
   3855 #ifdef ALLOWLOGGING
   3856 #define	I_LOG		0x01
   3857 #endif
   3858 #define	I_SIGNAL	0x02
   3859 #define	I_TEK		0x04
   3860 
   3861 /* *INDENT-ON* */
   3862 
   3863 #endif /* included_ptyx_h */
   3864