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