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