ptyx.h revision 712a7ff4
1/* $XTermId: ptyx.h,v 1.700 2011/07/12 08:33:58 tom Exp $ */
2
3/*
4 * Copyright 1999-2010,2011 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/Xfuncs.h>
71#include <X11/Xosdefs.h>
72#include <X11/Xmu/Converters.h>
73#ifdef XRENDERFONT
74#include <X11/Xft/Xft.h>
75#endif
76
77#include <stdio.h>
78
79/* adapted from IntrinsicI.h */
80#define MyStackAlloc(size, stack_cache_array)     \
81    ((size) <= sizeof(stack_cache_array)	  \
82    ?  (XtPointer)(stack_cache_array)		  \
83    :  (XtPointer)malloc((size_t)(size)))
84
85#define MyStackFree(pointer, stack_cache_array) \
86    if ((pointer) != ((char *)(stack_cache_array))) free(pointer)
87
88/* adapted from vile (vi-like-emacs) */
89#define TypeCallocN(type,n)	(type *)calloc((size_t) (n), sizeof(type))
90#define TypeCalloc(type)	TypeCallocN(type, 1)
91
92#define TypeMallocN(type,n)	(type *)malloc(sizeof(type) * (size_t) (n))
93#define TypeMalloc(type)	TypeMallocN(type, 1)
94
95#define TypeRealloc(type,n,p)	(type *)realloc(p, (n) * sizeof(type))
96
97#define TypeXtReallocN(t,p,n)	(t *)(void *)XtRealloc((char *)(p), (Cardinal)(sizeof(t) * (size_t) (n)))
98
99#define TypeXtMallocX(type,n)	(type *)(void *)XtMalloc((Cardinal)(sizeof(type) + (size_t) (n)))
100#define TypeXtMallocN(type,n)	(type *)(void *)XtMalloc((Cardinal)(sizeof(type) * (size_t) (n)))
101#define TypeXtMalloc(type)	TypeXtMallocN(type, 1)
102
103/* use these to allocate partly-structured data */
104#define CastMallocN(type,n)	(type *)malloc(sizeof(type) + (size_t) (n))
105#define CastMalloc(type)	CastMallocN(type,0)
106
107#define BumpBuffer(type, buffer, size, want) \
108	if (want >= size) { \
109	    size = 1 + (want * 2); \
110	    buffer = TypeRealloc(type, size, buffer); \
111	}
112
113#define BfBuf(type) screen->bf_buf_##type
114#define BfLen(type) screen->bf_len_##type
115
116#define TypedBuffer(type) \
117	type		*bf_buf_##type; \
118	Cardinal	bf_len_##type
119
120#define BumpTypedBuffer(type, want) \
121	BumpBuffer(type, BfBuf(type), BfLen(type), want)
122
123#define FreeTypedBuffer(type) \
124	if (BfBuf(type) != 0) { \
125	    free(BfBuf(type)); \
126	    BfBuf(type) = 0; \
127	} \
128	BfLen(type) = 0
129
130/*
131** System V definitions
132*/
133
134#ifdef att
135#define ATT
136#endif
137
138#ifdef SVR4
139#undef  SYSV			/* predefined on Solaris 2.4 */
140#define SYSV			/* SVR4 is (approx) superset of SVR3 */
141#define ATT
142#endif
143
144#ifdef SYSV
145#ifdef X_NOT_POSIX
146#if !defined(CRAY) && !defined(SVR4)
147#define	dup2(fd1,fd2)	((fd1 == fd2) ? fd1 : \
148				(close(fd2), fcntl(fd1, F_DUPFD, fd2)))
149#endif
150#endif
151#endif /* SYSV */
152
153/*
154 * Newer versions of <X11/Xft/Xft.h> have a version number.  We use certain
155 * features from that.
156 */
157#if defined(XRENDERFONT) && defined(XFT_VERSION) && XFT_VERSION >= 20100
158#define HAVE_TYPE_FCCHAR32	1	/* compatible: XftChar16 */
159#define HAVE_TYPE_XFTCHARSPEC	1	/* new type XftCharSpec */
160#endif
161
162/*
163** Definitions to simplify ifdef's for pty's.
164*/
165#define USE_PTY_DEVICE 1
166#define USE_PTY_SEARCH 1
167
168#if defined(__osf__) || (defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
169#undef USE_PTY_DEVICE
170#undef USE_PTY_SEARCH
171#define USE_PTS_DEVICE 1
172#elif defined(VMS)
173#undef USE_PTY_DEVICE
174#undef USE_PTY_SEARCH
175#elif defined(PUCC_PTYD)
176#undef USE_PTY_SEARCH
177#elif (defined(sun) && defined(SVR4)) || defined(_ALL_SOURCE) || defined(__CYGWIN__)
178#undef USE_PTY_SEARCH
179#endif
180
181#if defined(SYSV) && defined(i386) && !defined(SVR4)
182#define ATT
183#define USE_HANDSHAKE 1
184#define USE_ISPTS_FLAG 1
185#endif
186
187#if (defined (__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)))
188#define USE_USG_PTYS
189#define USE_HANDSHAKE 0	/* "recent" Linux systems do not require handshaking */
190#elif (defined(ATT) && !defined(__sgi)) || defined(__MVS__) || (defined(SYSV) && defined(i386))
191#define USE_USG_PTYS
192#else
193#define USE_HANDSHAKE 1
194#endif
195
196/*
197 * More systems than not require pty-handshaking.
198 */
199#ifndef USE_HANDSHAKE
200#define USE_HANDSHAKE 1
201#endif
202
203/*
204** allow for mobility of the pty master/slave directories
205*/
206#ifndef PTYDEV
207#if defined(__hpux)
208#define	PTYDEV		"/dev/ptym/ptyxx"
209#elif defined(__MVS__)
210#define	PTYDEV		"/dev/ptypxxxx"
211#else
212#define	PTYDEV		"/dev/ptyxx"
213#endif
214#endif	/* !PTYDEV */
215
216#ifndef TTYDEV
217#if defined(__hpux)
218#define TTYDEV		"/dev/pty/ttyxx"
219#elif defined(__MVS__)
220#define TTYDEV		"/dev/ptypxxxx"
221#elif defined(USE_PTS_DEVICE)
222#define TTYDEV		"/dev/pts/0"
223#else
224#define	TTYDEV		"/dev/ttyxx"
225#endif
226#endif	/* !TTYDEV */
227
228#ifndef PTYCHAR1
229#ifdef __hpux
230#define PTYCHAR1	"zyxwvutsrqp"
231#else	/* !__hpux */
232#ifdef __UNIXOS2__
233#define PTYCHAR1	"pq"
234#else
235#define	PTYCHAR1	"pqrstuvwxyzPQRSTUVWXYZ"
236#endif  /* !__UNIXOS2__ */
237#endif	/* !__hpux */
238#endif	/* !PTYCHAR1 */
239
240#ifndef PTYCHAR2
241#ifdef __hpux
242#define	PTYCHAR2	"fedcba9876543210"
243#else	/* !__hpux */
244#if defined(__DragonFly__) || defined(__FreeBSD__)
245#define	PTYCHAR2	"0123456789abcdefghijklmnopqrstuv"
246#else /* !__FreeBSD__ */
247#define	PTYCHAR2	"0123456789abcdef"
248#endif /* !__FreeBSD__ */
249#endif	/* !__hpux */
250#endif	/* !PTYCHAR2 */
251
252#ifndef TTYFORMAT
253#if defined(CRAY)
254#define TTYFORMAT "/dev/ttyp%03d"
255#elif defined(__MVS__)
256#define TTYFORMAT "/dev/ttyp%04d"
257#else
258#define TTYFORMAT "/dev/ttyp%d"
259#endif
260#endif /* TTYFORMAT */
261
262#ifndef PTYFORMAT
263#ifdef CRAY
264#define PTYFORMAT "/dev/pty/%03d"
265#elif defined(__MVS__)
266#define PTYFORMAT "/dev/ptyp%04d"
267#else
268#define PTYFORMAT "/dev/ptyp%d"
269#endif
270#endif /* PTYFORMAT */
271
272#ifndef PTYCHARLEN
273#ifdef CRAY
274#define PTYCHARLEN 3
275#elif defined(__MVS__)
276#define PTYCHARLEN 8     /* OS/390 stores, e.g. ut_id="ttyp1234"  */
277#else
278#define PTYCHARLEN 2
279#endif
280#endif
281
282#ifndef MAXPTTYS
283#ifdef CRAY
284#define MAXPTTYS 256
285#else
286#define MAXPTTYS 2048
287#endif
288#endif
289
290/* Until the translation manager comes along, I have to do my own translation of
291 * mouse events into the proper routines. */
292
293typedef enum {
294    NORMAL = 0
295    , LEFTEXTENSION
296    , RIGHTEXTENSION
297} EventMode;
298
299/*
300 * The origin of a screen is 0, 0.  Therefore, the number of rows
301 * on a screen is screen->max_row + 1, and similarly for columns.
302 */
303#define MaxCols(screen)		((screen)->max_col + 1)
304#define MaxRows(screen)		((screen)->max_row + 1)
305
306typedef unsigned char Char;		/* to support 8 bit chars */
307typedef Char *ScrnPtr;
308typedef ScrnPtr *ScrnBuf;
309
310/*
311 * Declare an X String, but for unsigned chars.
312 */
313#ifdef _CONST_X_STRING
314typedef const Char *UString;
315#else
316typedef Char *UString;
317#endif
318
319#define IsEmpty(s) ((s) == 0 || *(s) == '\0')
320
321#define CharOf(n) ((unsigned char)(n))
322
323typedef struct {
324    int row;
325    int col;
326} CELL;
327
328#define isSameRow(a,b)		((a)->row == (b)->row)
329#define isSameCol(a,b)		((a)->col == (b)->col)
330#define isSameCELL(a,b)		(isSameRow(a,b) && isSameCol(a,b))
331
332#define xBIT(n)         (1 << (n))
333
334/*
335 * ANSI emulation, special character codes
336 */
337#define ANSI_EOT	0x04
338#define ANSI_BEL	0x07
339#define ANSI_BS		0x08
340#define ANSI_HT		0x09
341#define ANSI_LF		0x0A
342#define ANSI_VT		0x0B
343#define	ANSI_FF		0x0C		/* C0, C1 control names		*/
344#define ANSI_CR		0x0D
345#define ANSI_SO		0x0E
346#define ANSI_SI		0x0F
347#define	ANSI_XON	0x11		/* DC1 */
348#define	ANSI_XOFF	0x13		/* DC3 */
349#define	ANSI_NAK	0x15
350#define	ANSI_CAN	0x18
351#define	ANSI_ESC	0x1B
352#define	ANSI_SPA	0x20
353#define XTERM_POUND	0x1E		/* internal mapping for '#'	*/
354#define	ANSI_DEL	0x7F
355#define	ANSI_SS2	0x8E
356#define	ANSI_SS3	0x8F
357#define	ANSI_DCS	0x90
358#define	ANSI_SOS	0x98
359#define	ANSI_CSI	0x9B
360#define	ANSI_ST		0x9C
361#define	ANSI_OSC	0x9D
362#define	ANSI_PM		0x9E
363#define	ANSI_APC	0x9F
364
365#define MIN_DECID  52			/* can emulate VT52 */
366#define MAX_DECID 420			/* ...through VT420 */
367
368#ifndef DFT_DECID
369#define DFT_DECID "vt100"		/* default VT100 */
370#endif
371
372#ifndef DFT_KBD_DIALECT
373#define DFT_KBD_DIALECT "B"		/* default USASCII */
374#endif
375
376/* constants used for utf8 mode */
377#define UCS_REPL	0xfffd
378#define UCS_LIMIT	0x80000000U	/* both limit and flag for non-UCS */
379
380#define TERMCAP_SIZE 1500		/* 1023 is standard; 'screen' exceeds */
381
382#define NMENUFONTS 9			/* font entries in fontMenu */
383
384#define	NBOX	5			/* Number of Points in box	*/
385#define	NPARAM	30			/* Max. parameters		*/
386
387typedef struct {
388	String opt;
389	String desc;
390} OptionHelp;
391
392typedef short ParmType;
393
394typedef struct {
395	Char		a_type;		/* CSI, etc., see unparseq()	*/
396	Char		a_pintro;	/* private-mode char, if any	*/
397	Char		a_inters;	/* special (before final-char)	*/
398	Char		a_final;	/* final-char			*/
399	ParmType	a_nparam;	/* # of parameters		*/
400	ParmType	a_param[NPARAM]; /* Parameters			*/
401} ANSI;
402
403#define TEK_FONT_LARGE 0
404#define TEK_FONT_2 1
405#define TEK_FONT_3 2
406#define TEK_FONT_SMALL 3
407#define	TEKNUMFONTS 4
408
409/* Actually there are 5 types of lines, but four are non-solid lines */
410#define	TEKNUMLINES	4
411
412typedef struct {
413	int	x;
414	int	y;
415	int	fontsize;
416	unsigned linetype;
417} Tmodes;
418
419typedef struct {
420	int Twidth;
421	int Theight;
422} T_fontsize;
423
424typedef struct {
425	short *bits;
426	int x;
427	int y;
428	int width;
429	int height;
430} BitmapBits;
431
432#define	SAVELINES		64      /* default # lines to save      */
433#define SCROLLLINES 1			/* default # lines to scroll    */
434
435#define EXCHANGE(a,b,tmp) tmp = a; a = b; b = tmp
436
437/***====================================================================***/
438
439#if (XtSpecificationRelease < 6)
440#ifndef NO_ACTIVE_ICON
441#define NO_ACTIVE_ICON 1 /* Note: code relies on an X11R6 function */
442#endif
443#endif
444
445#ifndef OPT_AIX_COLORS
446#define OPT_AIX_COLORS  1 /* true if xterm is configured with AIX (16) colors */
447#endif
448
449#ifndef OPT_ALLOW_XXX_OPS
450#define OPT_ALLOW_XXX_OPS 1 /* true if xterm adds "Allow XXX Ops" submenu */
451#endif
452
453#ifndef OPT_BLINK_CURS
454#define OPT_BLINK_CURS  1 /* true if xterm has blinking cursor capability */
455#endif
456
457#ifndef OPT_BLINK_TEXT
458#define OPT_BLINK_TEXT  OPT_BLINK_CURS /* true if xterm has blinking text capability */
459#endif
460
461#ifndef OPT_BOX_CHARS
462#define OPT_BOX_CHARS	1 /* true if xterm can simulate box-characters */
463#endif
464
465#ifndef OPT_BROKEN_OSC
466#ifdef linux
467#define OPT_BROKEN_OSC	1 /* man console_codes, 1st paragraph - cf: ECMA-48 */
468#else
469#define OPT_BROKEN_OSC	0 /* true if xterm allows Linux's broken OSC parsing */
470#endif
471#endif
472
473#ifndef OPT_BROKEN_ST
474#define OPT_BROKEN_ST	1 /* true if xterm allows old/broken OSC parsing */
475#endif
476
477#ifndef OPT_C1_PRINT
478#define OPT_C1_PRINT	1 /* true if xterm allows C1 controls to be printable */
479#endif
480
481#ifndef OPT_CLIP_BOLD
482#define OPT_CLIP_BOLD	1 /* true if xterm uses clipping to avoid bold-trash */
483#endif
484
485#ifndef OPT_COLOR_CLASS
486#define OPT_COLOR_CLASS 1 /* true if xterm uses separate color-resource classes */
487#endif
488
489#ifndef OPT_COLOR_RES
490#define OPT_COLOR_RES   1 /* true if xterm delays color-resource evaluation */
491#endif
492
493#ifndef OPT_DABBREV
494#define OPT_DABBREV 0	/* dynamic abbreviations */
495#endif
496
497#ifndef OPT_DEC_CHRSET
498#define OPT_DEC_CHRSET  1 /* true if xterm is configured for DEC charset */
499#endif
500
501#ifndef OPT_DEC_LOCATOR
502#define	OPT_DEC_LOCATOR 0 /* true if xterm supports VT220-style mouse events */
503#endif
504
505#ifndef OPT_DEC_RECTOPS
506#define OPT_DEC_RECTOPS 0 /* true if xterm is configured for VT420 rectangles */
507#endif
508
509#ifndef OPT_DEC_SOFTFONT
510#define OPT_DEC_SOFTFONT 0 /* true if xterm is configured for VT220 softfonts */
511#endif
512
513#ifndef OPT_EBCDIC
514#ifdef __MVS__
515#define OPT_EBCDIC 1
516#else
517#define OPT_EBCDIC 0
518#endif
519#endif
520
521#ifndef OPT_EXEC_XTERM
522#define OPT_EXEC_XTERM 0 /* true if xterm can fork/exec copies of itself */
523#endif
524
525#ifndef OPT_EXTRA_PASTE
526#define OPT_EXTRA_PASTE 1
527#endif
528
529#ifndef OPT_FIFO_LINES
530#define OPT_FIFO_LINES 0 /* optimize save-lines feature using FIFO */
531#endif
532
533#ifndef OPT_FOCUS_EVENT
534#define OPT_FOCUS_EVENT	1 /* focus in/out events */
535#endif
536
537#ifndef OPT_HP_FUNC_KEYS
538#define OPT_HP_FUNC_KEYS 0 /* true if xterm supports HP-style function keys */
539#endif
540
541#ifndef OPT_I18N_SUPPORT
542#if (XtSpecificationRelease >= 5)
543#define OPT_I18N_SUPPORT 1 /* true if xterm uses internationalization support */
544#else
545#define OPT_I18N_SUPPORT 0
546#endif
547#endif
548
549#ifndef OPT_INITIAL_ERASE
550#define OPT_INITIAL_ERASE 1 /* use pty's erase character if it's not 128 */
551#endif
552
553#ifndef OPT_INPUT_METHOD
554#if (XtSpecificationRelease >= 6)
555#define OPT_INPUT_METHOD 1 /* true if xterm uses input-method support */
556#else
557#define OPT_INPUT_METHOD 0
558#endif
559#endif
560
561#ifndef OPT_ISO_COLORS
562#define OPT_ISO_COLORS  1 /* true if xterm is configured with ISO colors */
563#endif
564
565#ifndef OPT_256_COLORS
566#define OPT_256_COLORS  0 /* true if xterm is configured with 256 colors */
567#endif
568
569#ifndef OPT_88_COLORS
570#define OPT_88_COLORS	0 /* true if xterm is configured with 88 colors */
571#endif
572
573#ifndef OPT_HIGHLIGHT_COLOR
574#define OPT_HIGHLIGHT_COLOR 1 /* true if xterm supports color highlighting */
575#endif
576
577#ifndef OPT_LOAD_VTFONTS
578#define OPT_LOAD_VTFONTS 0 /* true if xterm has load-vt-fonts() action */
579#endif
580
581#ifndef OPT_LUIT_PROG
582#define OPT_LUIT_PROG   0 /* true if xterm supports luit */
583#endif
584
585#ifndef OPT_MAXIMIZE
586#define OPT_MAXIMIZE	1 /* add actions for iconify ... maximize */
587#endif
588
589#ifndef OPT_MINI_LUIT
590#define OPT_MINI_LUIT   0 /* true if xterm supports built-in mini-luit */
591#endif
592
593#ifndef OPT_MOD_FKEYS
594#define OPT_MOD_FKEYS	1 /* modify cursor- and function-keys in normal mode */
595#endif
596
597#ifndef OPT_NUM_LOCK
598#define OPT_NUM_LOCK	1 /* use NumLock key only for numeric-keypad */
599#endif
600
601#ifndef OPT_PASTE64
602#define OPT_PASTE64	0 /* program control of select/paste via base64 */
603#endif
604
605#ifndef OPT_PC_COLORS
606#define OPT_PC_COLORS   1 /* true if xterm supports PC-style (bold) colors */
607#endif
608
609#ifndef OPT_PRINT_ON_EXIT
610#define OPT_PRINT_ON_EXIT 1 /* true allows xterm to dump screen on X error */
611#endif
612
613#ifndef OPT_PTY_HANDSHAKE
614#define OPT_PTY_HANDSHAKE USE_HANDSHAKE	/* avoid pty races on older systems */
615#endif
616
617#ifndef OPT_PRINT_COLORS
618#define OPT_PRINT_COLORS 1 /* true if we print color information */
619#endif
620
621#ifndef OPT_READLINE
622#define OPT_READLINE	0 /* mouse-click/paste support for readline */
623#endif
624
625#ifndef OPT_RENDERFONT
626#ifdef XRENDERFONT
627#define OPT_RENDERFONT 1
628#else
629#define OPT_RENDERFONT 0
630#endif
631#endif
632
633#ifndef OPT_RENDERWIDE
634#if OPT_RENDERFONT && OPT_WIDE_CHARS && defined(HAVE_TYPE_XFTCHARSPEC)
635#define OPT_RENDERWIDE 1
636#else
637#define OPT_RENDERWIDE 0
638#endif
639#endif
640
641#ifndef OPT_SAME_NAME
642#define OPT_SAME_NAME   1 /* suppress redundant updates of title, icon, etc. */
643#endif
644
645#ifndef OPT_SAVE_LINES
646#define OPT_SAVE_LINES OPT_FIFO_LINES /* optimize save-lines feature */
647#endif
648
649#ifndef OPT_SCO_FUNC_KEYS
650#define OPT_SCO_FUNC_KEYS 0 /* true if xterm supports SCO-style function keys */
651#endif
652
653#ifndef OPT_SUN_FUNC_KEYS
654#define OPT_SUN_FUNC_KEYS 1 /* true if xterm supports Sun-style function keys */
655#endif
656
657#ifndef OPT_SCROLL_LOCK
658#define OPT_SCROLL_LOCK 1 /* true if xterm interprets fontsize-shifting */
659#endif
660
661#ifndef OPT_SELECT_REGEX
662#define OPT_SELECT_REGEX 0 /* true if xterm supports regular-expression selects */
663#endif
664
665#ifndef OPT_SESSION_MGT
666#if defined(XtNdieCallback) && defined(XtNsaveCallback)
667#define OPT_SESSION_MGT 1
668#else
669#define OPT_SESSION_MGT 0
670#endif
671#endif
672
673#ifndef OPT_SHIFT_FONTS
674#define OPT_SHIFT_FONTS 0 /* true if xterm interprets fontsize-shifting */
675#endif
676
677#ifndef OPT_SUNPC_KBD
678#define OPT_SUNPC_KBD	1 /* true if xterm supports Sun/PC keyboard map */
679#endif
680
681#ifndef OPT_TCAP_FKEYS
682#define OPT_TCAP_FKEYS	0 /* true for experimental termcap function-keys */
683#endif
684
685#ifndef OPT_TCAP_QUERY
686#define OPT_TCAP_QUERY	0 /* true for experimental termcap query */
687#endif
688
689#ifndef OPT_TEK4014
690#define OPT_TEK4014     1 /* true if we're using tek4014 emulation */
691#endif
692
693#ifndef OPT_TOOLBAR
694#define OPT_TOOLBAR	0 /* true if xterm supports toolbar menus */
695#endif
696
697#ifndef OPT_TRACE
698#define OPT_TRACE       0 /* true if we're using debugging traces */
699#endif
700
701#ifndef OPT_TRACE_FLAGS
702#define OPT_TRACE_FLAGS 0 /* additional tracing used for SCRN_BUF_FLAGS */
703#endif
704
705#ifndef OPT_VT52_MODE
706#define OPT_VT52_MODE   1 /* true if xterm supports VT52 emulation */
707#endif
708
709#ifndef OPT_WIDE_CHARS
710#define OPT_WIDE_CHARS  0 /* true if xterm supports 16-bit characters */
711#endif
712
713#ifndef OPT_WIDER_ICHAR
714#define OPT_WIDER_ICHAR 1 /* true if xterm uses 32-bits for wide-chars */
715#endif
716
717#ifndef OPT_XMC_GLITCH
718#define OPT_XMC_GLITCH	0 /* true if xterm supports xmc (magic cookie glitch) */
719#endif
720
721#ifndef OPT_ZICONBEEP
722#define OPT_ZICONBEEP   1 /* true if xterm supports "-ziconbeep" option */
723#endif
724
725/***====================================================================***/
726
727#if OPT_AIX_COLORS && !OPT_ISO_COLORS
728/* You must have ANSI/ISO colors to support AIX colors */
729#undef  OPT_AIX_COLORS
730#define OPT_AIX_COLORS 0
731#endif
732
733#if OPT_COLOR_RES && !OPT_ISO_COLORS
734/* You must have ANSI/ISO colors to support ColorRes logic */
735#undef  OPT_COLOR_RES
736#define OPT_COLOR_RES 0
737#endif
738
739#if OPT_256_COLORS && (OPT_WIDE_CHARS || OPT_RENDERFONT || OPT_XMC_GLITCH)
740/* It's actually more complicated than that - but by trimming options you can
741 * have 256 color resources though.
742 */
743#define OPT_COLOR_RES2 1
744#else
745#define OPT_COLOR_RES2 0
746#endif
747
748#if OPT_PASTE64 && !OPT_READLINE
749/* OPT_PASTE64 uses logic from OPT_READLINE */
750#undef  OPT_READLINE
751#define OPT_READLINE 1
752#endif
753
754#if OPT_PC_COLORS && !OPT_ISO_COLORS
755/* You must have ANSI/ISO colors to support PC colors */
756#undef  OPT_PC_COLORS
757#define OPT_PC_COLORS 0
758#endif
759
760#if OPT_PRINT_COLORS && !OPT_ISO_COLORS
761/* You must have ANSI/ISO colors to be able to print them */
762#undef  OPT_PRINT_COLORS
763#define OPT_PRINT_COLORS 0
764#endif
765
766#if OPT_256_COLORS && !OPT_ISO_COLORS
767/* You must have ANSI/ISO colors to support 256 colors */
768#undef  OPT_256_COLORS
769#define OPT_256_COLORS 0
770#endif
771
772#if OPT_88_COLORS && !OPT_ISO_COLORS
773/* You must have ANSI/ISO colors to support 88 colors */
774#undef  OPT_88_COLORS
775#define OPT_88_COLORS 0
776#endif
777
778#if OPT_88_COLORS && OPT_256_COLORS
779/* 256 colors supersedes 88 colors */
780#undef  OPT_88_COLORS
781#define OPT_88_COLORS 0
782#endif
783
784/***====================================================================***/
785
786/*
787 * Indices for menu_font_names[][]
788 */
789typedef enum {
790    fNorm = 0			/* normal font */
791    , fBold			/* bold font */
792#if OPT_WIDE_CHARS
793    , fWide			/* double-width font */
794    , fWBold			/* double-width bold font */
795#endif
796    , fMAX
797} VTFontEnum;
798
799/*
800 * Indices for cachedGCs.c (unrelated to VTFontEnum).
801 */
802typedef enum {
803    gcNorm = 0
804    , gcBold
805    , gcNormReverse
806    , gcBoldReverse
807#if OPT_BOX_CHARS
808    , gcLine
809    , gcDots
810#endif
811#if OPT_DEC_CHRSET
812    , gcCNorm
813    , gcCBold
814#endif
815#if OPT_WIDE_CHARS
816    , gcWide
817    , gcWBold
818    , gcWideReverse
819    , gcWBoldReverse
820#endif
821    , gcVTcursNormal
822    , gcVTcursFilled
823    , gcVTcursReverse
824    , gcVTcursOutline
825#if OPT_TEK4014
826    , gcTKcurs
827#endif
828    , gcMAX
829} CgsEnum;
830
831#define for_each_text_gc(n) for (n = gcNorm; n < gcVTcursNormal; ++n)
832#define for_each_curs_gc(n) for (n = gcVTcursNormal; n <= gcVTcursOutline; ++n)
833#define for_each_gc(n)      for (n = gcNorm; n < gcMAX; ++n)
834
835/*
836 * Indices for the normal terminal colors in screen.Tcolors[].
837 * See also OscTextColors, which has corresponding values.
838 */
839typedef enum {
840    TEXT_FG = 0			/* text foreground */
841    , TEXT_BG			/* text background */
842    , TEXT_CURSOR		/* text cursor */
843    , MOUSE_FG			/* mouse foreground */
844    , MOUSE_BG			/* mouse background */
845#if OPT_TEK4014
846    , TEK_FG			/* tektronix foreground */
847    , TEK_BG			/* tektronix background */
848    , TEK_CURSOR		/* tektronix cursor */
849#endif
850#if OPT_HIGHLIGHT_COLOR
851    , HIGHLIGHT_BG		/* highlight background */
852    , HIGHLIGHT_FG		/* highlight foreground */
853#endif
854    , NCOLORS			/* total number of colors */
855} TermColors;
856
857/*
858 * Constants for titleModes resource
859 */
860typedef enum {
861    tmSetBase16 = 1		/* set title using hex-string */
862    , tmGetBase16 = 2		/* get title using hex-string */
863#if OPT_WIDE_CHARS
864    , tmSetUtf8 = 4		/* like utf8Title, but controllable */
865    , tmGetUtf8 = 8		/* retrieve title encoded as UTF-8 */
866#endif
867} TitleModes;
868
869#define IsTitleMode(xw,mode) (((xw)->screen.title_modes & mode) != 0)
870
871/* indices for mapping multiple clicks to selection types */
872typedef enum {
873    Select_CHAR=0
874    ,Select_WORD
875    ,Select_LINE
876    ,Select_GROUP
877    ,Select_PAGE
878    ,Select_ALL
879#if OPT_SELECT_REGEX
880    ,Select_REGEX
881#endif
882    ,NSELECTUNITS
883} SelectUnit;
884
885typedef enum {
886    ecSetColor = 1
887    , ecGetColor
888    , ecGetAnsiColor
889    , ecLAST
890} ColorOps;
891
892typedef enum {
893    efSetFont = 1
894    , efGetFont
895    , efLAST
896} FontOps;
897
898typedef enum {
899    esFalse = 0
900    , esTrue
901    , esAlways
902    , esNever
903} FullscreenOps;
904
905typedef enum {
906    etSetTcap = 1
907    , etGetTcap
908    , etLAST
909} TcapOps;
910
911typedef enum {
912    /* 1-21 are chosen to be the same as the control-sequence coding */
913    ewRestoreWin = 1
914    , ewMinimizeWin = 2
915    , ewSetWinPosition = 3
916    , ewSetWinSizePixels = 4
917    , ewRaiseWin = 5
918    , ewLowerWin = 6
919    , ewRefreshWin = 7
920    , ewSetWinSizeChars = 8
921#if OPT_MAXIMIZE
922    , ewMaximizeWin = 9
923    , ewFullscreenWin = 10
924#endif
925    , ewGetWinState = 11
926    , ewGetWinPosition = 13
927    , ewGetWinSizePixels = 14
928    , ewGetWinSizeChars = 18
929#if OPT_MAXIMIZE
930    , ewGetScreenSizeChars = 19
931#endif
932    , ewGetIconTitle = 20
933    , ewGetWinTitle = 21
934    , ewPushTitle = 22
935    , ewPopTitle = 23
936    /* these do not fit into that scheme, which is why we use an array */
937    , ewSetWinLines
938    , ewSetXprop
939    , ewGetSelection
940    , ewSetSelection
941    /* get the size of the array... */
942    , ewLAST
943} WindowOps;
944
945#define	COLOR_DEFINED(s,w)	((s)->which & (unsigned) (1<<(w)))
946#define	COLOR_VALUE(s,w)	((s)->colors[w])
947#define	SET_COLOR_VALUE(s,w,v)	(((s)->colors[w] = (v)), UIntSet((s)->which, (1<<(w))))
948
949#define	COLOR_NAME(s,w)		((s)->names[w])
950#define	SET_COLOR_NAME(s,w,v)	(((s)->names[w] = (v)), ((s)->which |= (unsigned) (1<<(w))))
951
952#define	UNDEFINE_COLOR(s,w)	((s)->which &= (~((w)<<1)))
953
954/***====================================================================***/
955
956#if OPT_ISO_COLORS
957#define TERM_COLOR_FLAGS(xw)	((xw)->flags & (FG_COLOR|BG_COLOR))
958#define COLOR_0		0
959#define COLOR_1		1
960#define COLOR_2		2
961#define COLOR_3		3
962#define COLOR_4		4
963#define COLOR_5		5
964#define COLOR_6		6
965#define COLOR_7		7
966#define COLOR_8		8
967#define COLOR_9		9
968#define COLOR_10	10
969#define COLOR_11	11
970#define COLOR_12	12
971#define COLOR_13	13
972#define COLOR_14	14
973#define COLOR_15	15
974#define MIN_ANSI_COLORS 16
975
976#if OPT_256_COLORS
977# define NUM_ANSI_COLORS 256
978#elif OPT_88_COLORS
979# define NUM_ANSI_COLORS 88
980#else
981# define NUM_ANSI_COLORS MIN_ANSI_COLORS
982#endif
983
984#if NUM_ANSI_COLORS > MIN_ANSI_COLORS
985# define OPT_EXT_COLORS  1
986#else
987# define OPT_EXT_COLORS  0
988#endif
989
990#define COLOR_BD	(NUM_ANSI_COLORS)	/* BOLD */
991#define COLOR_UL	(NUM_ANSI_COLORS+1)	/* UNDERLINE */
992#define COLOR_BL	(NUM_ANSI_COLORS+2)	/* BLINK */
993#define COLOR_RV	(NUM_ANSI_COLORS+3)	/* REVERSE */
994#define MAXCOLORS	(NUM_ANSI_COLORS+4)
995#ifndef DFT_COLORMODE
996#define DFT_COLORMODE True	/* default colorMode resource */
997#endif
998
999#define ReverseOrHilite(screen,flags,hilite) \
1000		(( screen->colorRVMode && hilite ) || \
1001		    ( !screen->colorRVMode && \
1002		      (( (flags & INVERSE) && !hilite) || \
1003		       (!(flags & INVERSE) &&  hilite)) ))
1004
1005/* Define a fake XK code, we need it for the fake color response in
1006 * xtermcapKeycode(). */
1007#if OPT_TCAP_QUERY && OPT_ISO_COLORS
1008# define XK_COLORS 0x0003
1009#endif
1010
1011#else	/* !OPT_ISO_COLORS */
1012
1013#define TERM_COLOR_FLAGS(xw) 0
1014
1015#define ReverseOrHilite(screen,flags,hilite) \
1016		      (( (flags & INVERSE) && !hilite) || \
1017		       (!(flags & INVERSE) &&  hilite))
1018
1019#endif	/* OPT_ISO_COLORS */
1020
1021# define XK_TCAPNAME 0x0004
1022
1023#if OPT_AIX_COLORS
1024#define if_OPT_AIX_COLORS(screen, code) if(screen->colorMode) code
1025#else
1026#define if_OPT_AIX_COLORS(screen, code) /* nothing */
1027#endif
1028
1029#if OPT_256_COLORS || OPT_88_COLORS || OPT_ISO_COLORS
1030# define if_OPT_ISO_COLORS(screen, code) if (screen->colorMode) code
1031#else
1032# define if_OPT_ISO_COLORS(screen, code) /* nothing */
1033#endif
1034
1035#define COLOR_RES_NAME(root) "color" root
1036
1037#if OPT_COLOR_CLASS
1038#define COLOR_RES_CLASS(root) "Color" root
1039#else
1040#define COLOR_RES_CLASS(root) XtCForeground
1041#endif
1042
1043#if OPT_COLOR_RES
1044#define COLOR_RES(root,offset,value) Sres(COLOR_RES_NAME(root), COLOR_RES_CLASS(root), offset.resource, value)
1045#define COLOR_RES2(name,class,offset,value) Sres(name, class, offset.resource, value)
1046#else
1047#define COLOR_RES(root,offset,value) Cres(COLOR_RES_NAME(root), COLOR_RES_CLASS(root), offset, value)
1048#define COLOR_RES2(name,class,offset,value) Cres(name, class, offset, value)
1049#endif
1050
1051#define CLICK_RES_NAME(count)  "on" count "Clicks"
1052#define CLICK_RES_CLASS(count) "On" count "Clicks"
1053#define CLICK_RES(count,offset,value) Sres(CLICK_RES_NAME(count), CLICK_RES_CLASS(count), offset, value)
1054
1055/***====================================================================***/
1056
1057#if OPT_DEC_CHRSET
1058#define if_OPT_DEC_CHRSET(code) code
1059	/* Use 2 bits for encoding the double high/wide sense of characters */
1060#define CSET_SWL        0
1061#define CSET_DHL_TOP    1
1062#define CSET_DHL_BOT    2
1063#define CSET_DWL        3
1064#define NUM_CHRSET      8	/* normal/bold and 4 CSET_xxx values */
1065
1066	/* Use remaining bits for encoding the other character-sets */
1067#define CSET_NORMAL(code)  ((code) == CSET_SWL)
1068#define CSET_DOUBLE(code)  (!CSET_NORMAL(code) && !CSET_EXTEND(code))
1069#define CSET_EXTEND(code)  ((int)(code) > CSET_DWL)
1070
1071#define DBLCS_BITS            4
1072#define DBLCS_MASK            BITS2MASK(DBLCS_BITS)
1073
1074#define GetLineDblCS(ld)      (((ld)->bufHead >> LINEFLAG_BITS) & DBLCS_MASK)
1075#define SetLineDblCS(ld,cs)   (ld)->bufHead = (RowData) ((ld->bufHead & LINEFLAG_MASK) | (cs << LINEFLAG_BITS))
1076
1077#define LineCharSet(screen, ld) \
1078	((CSET_DOUBLE(GetLineDblCS(ld))) \
1079		? GetLineDblCS(ld) \
1080		: (screen)->cur_chrset)
1081#define LineMaxCol(screen, ld) \
1082	(CSET_DOUBLE(GetLineDblCS(ld)) \
1083	 ? (screen->max_col / 2) \
1084	 : (screen->max_col))
1085#define LineCursorX(screen, ld, col) \
1086	(CSET_DOUBLE(GetLineDblCS(ld)) \
1087	 ? CursorX(screen, 2*(col)) \
1088	 : CursorX(screen, (col)))
1089#define LineFontWidth(screen, ld) \
1090	(CSET_DOUBLE(GetLineDblCS(ld)) \
1091	 ? 2*FontWidth(screen) \
1092	 : FontWidth(screen))
1093#else
1094
1095#define if_OPT_DEC_CHRSET(code) /*nothing*/
1096
1097#define GetLineDblCS(ld)       0
1098
1099#define LineCharSet(screen, ld)         0
1100#define LineMaxCol(screen, ld)          screen->max_col
1101#define LineCursorX(screen, ld, col)    CursorX(screen, col)
1102#define LineFontWidth(screen, ld)       FontWidth(screen)
1103
1104#endif
1105
1106#if OPT_LUIT_PROG && !OPT_WIDE_CHARS
1107#error Luit requires the wide-chars configuration
1108#endif
1109
1110/***====================================================================***/
1111
1112#if OPT_EBCDIC
1113extern int E2A(int);
1114extern int A2E(int);
1115#else
1116#define E2A(a) (a)
1117#define A2E(a) (a)
1118#endif
1119
1120#define CONTROL(a) (A2E(E2A(a)&037))
1121
1122/***====================================================================***/
1123
1124#if OPT_TEK4014
1125#define TEK4014_ACTIVE(xw)      ((xw)->misc.TekEmu)
1126#define TEK4014_SHOWN(xw)       ((xw)->misc.Tshow)
1127#define CURRENT_EMU_VAL(tek,vt) (TEK4014_ACTIVE(term) ? tek : vt)
1128#define CURRENT_EMU()           CURRENT_EMU_VAL((Widget)tekWidget, (Widget)term)
1129#else
1130#define TEK4014_ACTIVE(screen)  0
1131#define TEK4014_SHOWN(xw)       0
1132#define CURRENT_EMU_VAL(tek,vt) (vt)
1133#define CURRENT_EMU()           ((Widget)term)
1134#endif
1135
1136/***====================================================================***/
1137
1138#if OPT_TOOLBAR
1139#define SHELL_OF(widget) XtParent(XtParent(widget))
1140#else
1141#define SHELL_OF(widget) XtParent(widget)
1142#endif
1143
1144/***====================================================================***/
1145
1146#if OPT_VT52_MODE
1147#define if_OPT_VT52_MODE(screen, code) if(screen->vtXX_level == 0) code
1148#else
1149#define if_OPT_VT52_MODE(screen, code) /* nothing */
1150#endif
1151
1152/***====================================================================***/
1153
1154#if OPT_XMC_GLITCH
1155#define if_OPT_XMC_GLITCH(screen, code) if(screen->xmc_glitch) code
1156#define XMC_GLITCH 1	/* the character we'll show */
1157#define XMC_FLAGS (INVERSE|UNDERLINE|BOLD|BLINK)
1158#else
1159#define if_OPT_XMC_GLITCH(screen, code) /* nothing */
1160#endif
1161
1162/***====================================================================***/
1163
1164#define LO_BYTE(ch) CharOf((ch) & 0xff)
1165#define HI_BYTE(ch) CharOf((ch) >> 8)
1166
1167#if OPT_WIDE_CHARS
1168#define if_OPT_WIDE_CHARS(screen, code) if(screen->wide_chars) code
1169#define if_WIDE_OR_NARROW(screen, wide, narrow) if(screen->wide_chars) wide else narrow
1170#if OPT_WIDER_ICHAR
1171typedef unsigned IChar;		/* for 8-21 bit characters */
1172#else
1173typedef unsigned short IChar;	/* for 8-16 bit characters */
1174#endif
1175#else
1176#define if_OPT_WIDE_CHARS(screen, code) /* nothing */
1177#define if_WIDE_OR_NARROW(screen, wide, narrow) narrow
1178typedef unsigned char IChar;	/* for 8-bit characters */
1179#endif
1180
1181/***====================================================================***/
1182
1183#ifndef RES_OFFSET
1184#define RES_OFFSET(offset) XtOffsetOf(XtermWidgetRec, offset)
1185#endif
1186
1187#define RES_NAME(name) name
1188#define RES_CLASS(name) name
1189
1190#define Bres(name, class, offset, dftvalue) \
1191	{RES_NAME(name), RES_CLASS(class), XtRBoolean, sizeof(Boolean), \
1192	 RES_OFFSET(offset), XtRImmediate, (XtPointer) dftvalue}
1193
1194#define Cres(name, class, offset, dftvalue) \
1195	{RES_NAME(name), RES_CLASS(class), XtRPixel, sizeof(Pixel), \
1196	 RES_OFFSET(offset), XtRString, (XtPointer) dftvalue}
1197
1198#define Tres(name, class, offset, dftvalue) \
1199	COLOR_RES2(name, class, screen.Tcolors[offset], dftvalue) \
1200
1201#define Fres(name, class, offset, dftvalue) \
1202	{RES_NAME(name), RES_CLASS(class), XtRFontStruct, sizeof(XFontStruct *), \
1203	 RES_OFFSET(offset), XtRString, (XtPointer) dftvalue}
1204
1205#define Ires(name, class, offset, dftvalue) \
1206	{RES_NAME(name), RES_CLASS(class), XtRInt, sizeof(int), \
1207	 RES_OFFSET(offset), XtRImmediate, (XtPointer) dftvalue}
1208
1209#define Dres(name, class, offset, dftvalue) \
1210	{RES_NAME(name), RES_CLASS(class), XtRFloat, sizeof(float), \
1211	 RES_OFFSET(offset), XtRString, (XtPointer) dftvalue}
1212
1213#define Sres(name, class, offset, dftvalue) \
1214	{RES_NAME(name), RES_CLASS(class), XtRString, sizeof(char *), \
1215	 RES_OFFSET(offset), XtRString, (XtPointer) dftvalue}
1216
1217#define Wres(name, class, offset, dftvalue) \
1218	{RES_NAME(name), RES_CLASS(class), XtRWidget, sizeof(Widget), \
1219	 RES_OFFSET(offset), XtRWidget, (XtPointer) dftvalue}
1220
1221/***====================================================================***/
1222
1223#define FRG_SIZE resource.minBufSize
1224#define BUF_SIZE resource.maxBufSize
1225
1226typedef struct {
1227	Char *	next;
1228	Char *	last;
1229	int	update;		/* HandleInterpret */
1230#if OPT_WIDE_CHARS
1231	IChar	utf_data;	/* resulting character */
1232	int	utf_size;	/* ...number of bytes decoded */
1233	Char	*write_buf;
1234	unsigned write_len;
1235#endif
1236	Char	buffer[1];
1237} PtyData;
1238
1239/***====================================================================***/
1240
1241#if OPT_ISO_COLORS
1242#if OPT_256_COLORS || OPT_88_COLORS
1243#define COLOR_BITS 8
1244typedef unsigned short CellColor;
1245#else
1246#define COLOR_BITS 4
1247typedef Char CellColor;
1248#endif
1249#else
1250typedef int CellColor;
1251#endif
1252
1253#define BITS2MASK(b)          ((1 << b) - 1)
1254
1255#define COLOR_MASK            BITS2MASK(COLOR_BITS)
1256
1257#define GetCellColorFG(src)   ((src) & COLOR_MASK)
1258#define GetCellColorBG(src)   (((src) >> COLOR_BITS) & COLOR_MASK)
1259
1260typedef Char RowData;		/* wrap/blink, and DEC single-double chars */
1261
1262#define LINEFLAG_BITS         4
1263#define LINEFLAG_MASK         BITS2MASK(LINEFLAG_BITS)
1264
1265#define GetLineFlags(ld)      ((ld)->bufHead & LINEFLAG_MASK)
1266
1267#if OPT_DEC_CHRSET
1268#define SetLineFlags(ld,xx)   (ld)->bufHead = (RowData) ((ld->bufHead & (DBLCS_MASK << LINEFLAG_BITS)) | (xx & LINEFLAG_MASK))
1269#else
1270#define SetLineFlags(ld,xx)   (ld)->bufHead = (RowData) (xx & LINEFLAG_MASK)
1271#endif
1272
1273typedef IChar CharData;
1274
1275/*
1276 * This is the xterm line-data/scrollback structure.
1277 */
1278typedef struct {
1279	Dimension lineSize;	/* number of columns in this row */
1280	RowData bufHead;	/* flag for wrapped lines */
1281#if OPT_WIDE_CHARS
1282	Char combSize;		/* number of items in combData[] */
1283#endif
1284	Char *attribs;		/* video attributes */
1285#if OPT_ISO_COLORS
1286	CellColor *color;	/* foreground+background color numbers */
1287#endif
1288	CharData *charData;	/* cell's base character */
1289	CharData *combData[1];	/* first enum past fixed-offsets */
1290} LineData;
1291
1292/*
1293 * We use CellData in a few places, when copying a cell's data to a temporary
1294 * variable.
1295 */
1296typedef struct {
1297	Char attribs;
1298#if OPT_WIDE_CHARS
1299	Char combSize;		/* number of items in combData[] */
1300#endif
1301#if OPT_ISO_COLORS
1302	CellColor color;	/* color-array */
1303#endif
1304	CharData charData;	/* cell's base character */
1305	CharData combData[1];	/* array of combining chars */
1306} CellData;
1307
1308#define for_each_combData(off, ld) for (off = 0; off < ld->combSize; ++off)
1309
1310/*
1311 * Accommodate older compilers by not using variable-length arrays.
1312 */
1313#define SizeOfLineData  offsetof(LineData, combData)
1314#define SizeOfCellData  offsetof(CellData, combData)
1315
1316	/*
1317	 * A "row" is the index within the visible part of the screen, and an
1318	 * "inx" is the index within the whole set of scrollable lines.
1319	 */
1320#define ROW2INX(screen, row)	((row) + (screen)->topline)
1321#define INX2ROW(screen, inx)	((inx) - (screen)->topline)
1322
1323#define ROW2ABS(screen, row)	((row) + (screen)->savedlines)
1324#define INX2ABS(screen, inx)	ROW2ABS(screen, INX2ROW(screen, inx))
1325
1326#define okScrnRow(screen, row) \
1327	((row) <= ((screen)->max_row - (screen)->topline) \
1328      && (row) >= -((screen)->savedlines))
1329
1330	/*
1331	 * Cache data for "proportional" and other fonts containing a mixture
1332	 * of widths.
1333	 */
1334typedef struct {
1335    	Bool		mixed;
1336	Dimension	min_width;	/* nominal cell width for 0..255 */
1337	Dimension	max_width;	/* maximum cell width */
1338} FontMap;
1339
1340typedef struct {
1341	unsigned	chrset;
1342	unsigned	flags;
1343	XFontStruct *	fs;
1344	char *		fn;
1345	FontMap		map;
1346	Char		known_missing[256];
1347} XTermFonts;
1348
1349#if OPT_RENDERFONT
1350typedef enum {
1351	erFalse = 0
1352	, erTrue
1353	, erDefault
1354	, erLast
1355} RenderFont;
1356
1357#define DefaultRenderFont(xw) \
1358	if ((xw)->misc.render_font == erDefault) \
1359	    (xw)->misc.render_font = erFalse
1360
1361typedef struct {
1362	XftFont *	font;
1363	FontMap		map;
1364} XTermXftFonts;
1365#endif
1366
1367typedef struct {
1368	int		top;
1369	int		left;
1370	int		bottom;
1371	int		right;
1372} XTermRect;
1373
1374	/* indices into save_modes[] */
1375typedef enum {
1376	DP_CRS_VISIBLE,
1377	DP_DECANM,
1378	DP_DECARM,
1379	DP_DECAWM,
1380	DP_DECBKM,
1381	DP_DECCKM,
1382	DP_DECCOLM,	/* IN132COLUMNS */
1383	DP_DECOM,
1384	DP_DECPEX,
1385	DP_DECPFF,
1386	DP_DECSCLM,
1387	DP_DECSCNM,
1388	DP_DECTCEM,
1389	DP_DECTEK,
1390	DP_PRN_EXTENT,
1391	DP_PRN_FORMFEED,
1392	DP_X_ALTSCRN,
1393	DP_X_DECCOLM,
1394	DP_X_LOGGING,
1395	DP_X_MARGIN,
1396	DP_X_MORE,
1397	DP_X_MOUSE,
1398	DP_X_EXT_MOUSE,
1399	DP_X_REVWRAP,
1400	DP_X_X10MSE,
1401#if OPT_BLINK_CURS
1402	DP_CRS_BLINK,
1403#endif
1404#if OPT_FOCUS_EVENT
1405	DP_X_FOCUS,
1406#endif
1407#if OPT_TOOLBAR
1408	DP_TOOLBAR,
1409#endif
1410	DP_LAST
1411} SaveModes;
1412
1413#define DoSM(code,value)  screen->save_modes[code] = (unsigned) (value)
1414#define DoRM(code,value)  value = (Boolean) screen->save_modes[code]
1415#define DoRM0(code,value) value = screen->save_modes[code]
1416
1417	/* index into vt_shell[] or tek_shell[] */
1418typedef enum {
1419	noMenu = -1,
1420	mainMenu,
1421	vtMenu,
1422	fontMenu,
1423#if OPT_TEK4014
1424	tekMenu
1425#endif
1426} MenuIndex;
1427
1428typedef enum {
1429	bvOff = -1,
1430	bvLow = 0,
1431	bvHigh
1432} BellVolume;
1433
1434#define NUM_POPUP_MENUS 4
1435
1436#if OPT_COLOR_RES
1437typedef struct {
1438	String		resource;
1439	Pixel		value;
1440	int		mode;		/* -1=invalid, 0=unset, 1=set   */
1441} ColorRes;
1442#else
1443#define ColorRes Pixel
1444#endif
1445
1446/* these are set in getPrinterFlags */
1447typedef struct {
1448	int	printer_extent;		/* print complete page		*/
1449	int	printer_formfeed;	/* print formfeed per function	*/
1450	int	printer_newline;	/* print newline per function	*/
1451	int	print_attributes;	/* 0=off, 1=normal, 2=color	*/
1452	int	print_everything;	/* 0=all, 1=dft, 2=alt, 3=saved */
1453} PrinterFlags;
1454
1455typedef struct {
1456	FILE *	fp;			/* output file/pipe used	*/
1457	Boolean isOpen;			/* output was opened/tried	*/
1458	Boolean toFile;			/* true when directly to file	*/
1459	String	printer_command;	/* pipe/shell command string	*/
1460	Boolean printer_autoclose;	/* close printer when offline	*/
1461	Boolean printer_extent;		/* print complete page		*/
1462	Boolean printer_formfeed;	/* print formfeed per function	*/
1463	Boolean printer_newline;	/* print newline per function	*/
1464	int	printer_controlmode;	/* 0=off, 1=auto, 2=controller	*/
1465	int	print_attributes;	/* 0=off, 1=normal, 2=color	*/
1466	int	print_everything;	/* 0=all, 1=dft, 2=alt, 3=saved */
1467} PrinterState;
1468
1469typedef struct {
1470	unsigned	which;		/* must have NCOLORS bits */
1471	Pixel		colors[NCOLORS];
1472	char		*names[NCOLORS];
1473} ScrnColors;
1474
1475typedef struct {
1476	Boolean		saved;
1477	int		row;
1478	int		col;
1479	unsigned	flags;		/* VTxxx saves graphics rendition */
1480	Char		curgl;
1481	Char		curgr;
1482	Char		gsets[4];
1483#if OPT_ISO_COLORS
1484	int		cur_foreground; /* current foreground color	*/
1485	int		cur_background; /* current background color	*/
1486	int		sgr_foreground; /* current SGR foreground color */
1487	int		sgr_background; /* current SGR background color */
1488	Boolean		sgr_extended;	/* SGR set with extended codes? */
1489#endif
1490} SavedCursor;
1491
1492typedef struct _SaveTitle {
1493    	struct _SaveTitle *next;
1494	char		*iconName;
1495	char		*windowName;
1496} SaveTitle;
1497
1498#define SAVED_CURSORS 2
1499
1500typedef struct {
1501	int		width;		/* if > 0, width of scrollbar,	*/
1502					/* and scrollbar is showing	*/
1503	Boolean		rv_cached;	/* see ScrollBarReverseVideo	*/
1504	int		rv_active;	/* ...current reverse-video	*/
1505	Pixel		bg;		/* ...cached background color	*/
1506	Pixel		fg;		/* ...cached foreground color	*/
1507	Pixel		bdr;		/* ...cached border color	*/
1508	Pixmap		bdpix;		/* ...cached border pixmap	*/
1509} SbInfo;
1510
1511#if OPT_TOOLBAR
1512typedef struct {
1513	Widget		menu_bar;	/* toolbar, if initialized	*/
1514	Dimension	menu_height;	/* ...and its height		*/
1515	Dimension	menu_border;	/* ...and its border		*/
1516} TbInfo;
1517#define VT100_TB_INFO(name) screen.fullVwin.tb_info.name
1518#endif
1519
1520typedef struct {
1521	Window		window;		/* X window id			*/
1522	int		width;		/* width of columns		*/
1523	int		height;		/* height of rows		*/
1524	Dimension	fullwidth;	/* full width of window		*/
1525	Dimension	fullheight;	/* full height of window	*/
1526	int		f_width;	/* width of fonts in pixels	*/
1527	int		f_height;	/* height of fonts in pixels	*/
1528	int		f_ascent;	/* ascent of font in pixels	*/
1529	int		f_descent;	/* descent of font in pixels	*/
1530	SbInfo		sb_info;
1531#if OPT_TOOLBAR
1532	Boolean		active;		/* true if toolbars are used	*/
1533	TbInfo		tb_info;	/* toolbar information		*/
1534#endif
1535} VTwin;
1536
1537typedef struct {
1538	Window		window;		/* X window id			*/
1539	int		width;		/* width of columns		*/
1540	int		height;		/* height of rows		*/
1541	Dimension	fullwidth;	/* full width of window		*/
1542	Dimension	fullheight;	/* full height of window	*/
1543	double		tekscale;	/* scale factor Tek -> vs100	*/
1544} TKwin;
1545
1546typedef struct {
1547    String f_n;			/* the normal font */
1548    String f_b;			/* the bold font */
1549#if OPT_WIDE_CHARS
1550    String f_w;			/* the normal wide font */
1551    String f_wb;		/* the bold wide font */
1552#endif
1553} VTFontNames;
1554
1555typedef struct {
1556    VTFontNames default_font;
1557    String menu_font_names[NMENUFONTS][fMAX];
1558} SubResourceRec;
1559
1560typedef struct {
1561/* These parameters apply to both windows */
1562	Display		*display;	/* X display for screen		*/
1563	int		respond;	/* socket for responses
1564					   (position report, etc.)	*/
1565/* These parameters apply to VT100 window */
1566	IChar		unparse_bfr[256];
1567	unsigned	unparse_len;
1568
1569#if OPT_TCAP_QUERY
1570	int		tc_query_code;
1571	Bool		tc_query_fkey;
1572#endif
1573	pid_t		pid;		/* pid of process on far side   */
1574	uid_t		uid;		/* user id of actual person	*/
1575	gid_t		gid;		/* group id of actual person	*/
1576	ColorRes	Tcolors[NCOLORS]; /* terminal colors		*/
1577#if OPT_HIGHLIGHT_COLOR
1578	Boolean		hilite_color;	/* hilite colors override	*/
1579	Boolean		hilite_reverse;	/* hilite overrides reverse	*/
1580#endif
1581#if OPT_ISO_COLORS
1582	ColorRes	Acolors[MAXCOLORS]; /* ANSI color emulation	*/
1583	int		veryBoldColors;	/* modifier for boldColors	*/
1584	Boolean		boldColors;	/* can we make bold colors?	*/
1585	Boolean		colorMode;	/* are we using color mode?	*/
1586	Boolean		colorULMode;	/* use color for underline?	*/
1587	Boolean		italicULMode;	/* italic font for underline?	*/
1588	Boolean		colorBDMode;	/* use color for bold?		*/
1589	Boolean		colorBLMode;	/* use color for blink?		*/
1590	Boolean		colorRVMode;	/* use color for reverse?	*/
1591	Boolean		colorAttrMode;	/* prefer colorUL/BD to SGR	*/
1592#endif
1593#if OPT_DEC_CHRSET
1594	Boolean		font_doublesize;/* enable font-scaling		*/
1595	int		cache_doublesize;/* limit of our cache		*/
1596	Char		cur_chrset;	/* character-set index & code	*/
1597	int		fonts_used;	/* count items in double_fonts	*/
1598	XTermFonts	double_fonts[NUM_CHRSET];
1599#endif
1600#if OPT_DEC_RECTOPS
1601	int		cur_decsace;	/* parameter for DECSACE	*/
1602#endif
1603#if OPT_WIDE_CHARS
1604	Boolean		wide_chars;	/* true when 16-bit chars	*/
1605	Boolean		vt100_graphics;	/* true to allow vt100-graphics	*/
1606	Boolean		utf8_inparse;	/* true to enable UTF-8 parser	*/
1607	char *		utf8_mode_s;	/* use UTF-8 decode/encode	*/
1608	char *		utf8_fonts_s;	/* use UTF-8 decode/encode	*/
1609	int		utf8_mode;	/* use UTF-8 decode/encode: 0-2	*/
1610	int		utf8_fonts;	/* use UTF-8 decode/encode: 0-2	*/
1611	int		max_combining;	/* maximum # of combining chars	*/
1612	Boolean		utf8_latin1;	/* use UTF-8 with Latin-1 bias	*/
1613	Boolean		utf8_title;	/* use UTF-8 titles		*/
1614	int		latin9_mode;	/* poor man's luit, latin9	*/
1615	int		unicode_font;	/* font uses unicode encoding	*/
1616	int		utf_count;	/* state of utf_char		*/
1617	IChar		utf_char;	/* in-progress character	*/
1618	int		last_written_col;
1619	int		last_written_row;
1620	TypedBuffer(XChar2b);
1621	TypedBuffer(char);
1622#endif
1623#if OPT_BROKEN_OSC
1624	Boolean		brokenLinuxOSC; /* true to ignore Linux palette ctls */
1625#endif
1626#if OPT_BROKEN_ST
1627	Boolean		brokenStringTerm; /* true to match old OSC parse */
1628#endif
1629#if OPT_C1_PRINT || OPT_WIDE_CHARS
1630	Boolean		c1_printable;	/* true if we treat C1 as print	*/
1631#endif
1632	int		border;		/* inner border			*/
1633	int		scrollBarBorder; /* scrollBar border		*/
1634	long		event_mask;
1635	unsigned	send_mouse_pos;	/* user wants mouse transition  */
1636					/* and position information	*/
1637	Boolean		ext_mode_mouse; /* support large terminals      */
1638	Boolean		send_focus_pos; /* user wants focus in/out info */
1639	Boolean		quiet_grab;	/* true if no cursor change on focus */
1640#if OPT_PASTE64
1641	Cardinal	base64_paste;	/* set to send paste in base64	*/
1642	int		base64_final;	/* string-terminator for paste	*/
1643	/* _qWriteSelectionData expects these to be initialized to zero.
1644	 * base64_flush() is the last step of the conversion, it clears these
1645	 * variables.
1646	 */
1647	unsigned	base64_accu;
1648	unsigned	base64_count;
1649	unsigned	base64_pad;
1650#endif
1651#if OPT_READLINE
1652	unsigned	click1_moves;
1653	unsigned	paste_moves;
1654	unsigned	dclick3_deletes;
1655	unsigned	paste_brackets;
1656	unsigned	paste_quotes;
1657	unsigned	paste_literal_nl;
1658#endif	/* OPT_READLINE */
1659#if OPT_DEC_LOCATOR
1660	Boolean		locator_reset;	/* turn mouse off after 1 report? */
1661	Boolean		locator_pixels;	/* report in pixels?		*/
1662					/* if false, report in cells	*/
1663	unsigned	locator_events;	/* what events to report	*/
1664	Boolean		loc_filter;	/* is filter rectangle active?	*/
1665	int		loc_filter_top;	/* filter rectangle for DEC Locator */
1666	int		loc_filter_left;
1667	int		loc_filter_bottom;
1668	int		loc_filter_right;
1669#endif	/* OPT_DEC_LOCATOR */
1670	int		mouse_button;	/* current button pressed	*/
1671	int		mouse_row;	/* ...and its row		*/
1672	int		mouse_col;	/* ...and its column		*/
1673	int		select;		/* xterm selected		*/
1674	Boolean		bellOnReset;	/* bellOnReset			*/
1675	Boolean		visualbell;	/* visual bell mode		*/
1676	Boolean		poponbell;	/* pop on bell mode		*/
1677
1678	Boolean		allowColorOps;	/* ColorOps mode		*/
1679	Boolean		allowFontOps;	/* FontOps mode			*/
1680	Boolean		allowSendEvents;/* SendEvent mode		*/
1681	Boolean		allowTcapOps;	/* TcapOps mode			*/
1682	Boolean		allowTitleOps;	/* TitleOps mode		*/
1683	Boolean		allowWindowOps;	/* WindowOps mode		*/
1684
1685	Boolean		allowColorOp0;	/* initial ColorOps mode	*/
1686	Boolean		allowFontOp0;	/* initial FontOps mode		*/
1687	Boolean		allowSendEvent0;/* initial SendEvent mode	*/
1688	Boolean		allowTcapOp0;	/* initial TcapOps mode		*/
1689	Boolean		allowTitleOp0;	/* initial TitleOps mode	*/
1690	Boolean		allowWindowOp0;	/* initial WindowOps mode	*/
1691
1692	String		disallowedColorOps;
1693	char		disallow_color_ops[ecLAST];
1694
1695	String		disallowedFontOps;
1696	char		disallow_font_ops[efLAST];
1697
1698	String		disallowedTcapOps;
1699	char		disallow_tcap_ops[etLAST];
1700
1701	String		disallowedWinOps;
1702	char		disallow_win_ops[ewLAST];
1703
1704	Boolean		awaitInput;	/* select-timeout mode		*/
1705	Boolean		grabbedKbd;	/* keyboard is grabbed		*/
1706#if OPT_MAXIMIZE
1707	Boolean		fullscreen;	/* window is fullscreen		*/
1708#endif
1709#ifdef ALLOWLOGGING
1710	int		logging;	/* logging mode			*/
1711	int		logfd;		/* file descriptor of log	*/
1712	char		*logfile;	/* log file name		*/
1713	Char		*logstart;	/* current start of log buffer	*/
1714#endif
1715	int		inhibit;	/* flags for inhibiting changes	*/
1716
1717/* VT window parameters */
1718	Boolean		Vshow;		/* VT window showing		*/
1719	VTwin		fullVwin;
1720#ifndef NO_ACTIVE_ICON
1721	VTwin		iconVwin;
1722	VTwin		*whichVwin;
1723#endif /* NO_ACTIVE_ICON */
1724
1725	int		pointer_mode;	/* when to use hidden_cursor	*/
1726	Boolean 	hide_pointer;	/* true to use "hidden_cursor"  */
1727	Cursor		pointer_cursor;	/* pointer cursor in window	*/
1728	Cursor		hidden_cursor;	/* hidden cursor in window	*/
1729
1730	String	answer_back;		/* response to ENQ		*/
1731
1732	PrinterState	printer_state;	/* actual printer state		*/
1733	PrinterFlags	printer_flags;	/* working copy of printer flags */
1734#if OPT_PRINT_ON_EXIT
1735	Boolean		write_error;
1736#endif
1737
1738	Boolean		fnt_prop;	/* true if proportional fonts	*/
1739	Boolean		fnt_boxes;	/* true if font has box-chars	*/
1740	Boolean		force_packed;	/* true to override proportional */
1741#if OPT_BOX_CHARS
1742	Boolean		force_box_chars;/* true if we assume that	*/
1743	Boolean		force_all_chars;/* true to outline missing chars */
1744	Boolean		allow_packing;	/* true to allow packed-fonts	*/
1745#endif
1746	Dimension	fnt_wide;
1747	Dimension	fnt_high;
1748	XTermFonts	fnts[fMAX];	/* normal/bold/etc for terminal	*/
1749	Boolean		free_bold_box;	/* same_font_size's austerity	*/
1750	Boolean		allowBoldFonts;	/* do we use bold fonts at all? */
1751#ifndef NO_ACTIVE_ICON
1752	XTermFonts	fnt_icon;	/* icon font			*/
1753	String		icon_fontname;	/* name of icon font		*/
1754	int		icon_fontnum;	/* number to use for icon font	*/
1755#endif /* NO_ACTIVE_ICON */
1756	int		enbolden;	/* overstrike for bold font	*/
1757	XPoint		*box;		/* draw unselected cursor	*/
1758
1759	int		cursor_state;	/* ON, OFF, or BLINKED_OFF	*/
1760	int		cursor_busy;	/* do not redraw...		*/
1761	Boolean		cursor_underline; /* true if cursor is in underline mode */
1762#if OPT_BLINK_CURS
1763	Boolean		cursor_blink;	/* cursor blink enable		*/
1764	Boolean		cursor_blink_res; /* initial cursor blink value	*/
1765	Boolean		cursor_blink_esc; /* cursor blink escape-state	*/
1766#endif
1767#if OPT_BLINK_TEXT
1768	Boolean		blink_as_bold;	/* text blink disable		*/
1769#endif
1770#if OPT_BLINK_CURS || OPT_BLINK_TEXT
1771	int		blink_state;	/* ON, OFF, or BLINKED_OFF	*/
1772	int		blink_on;	/* cursor on time (msecs)	*/
1773	int		blink_off;	/* cursor off time (msecs)	*/
1774	XtIntervalId	blink_timer;	/* timer-id for cursor-proc	*/
1775#endif
1776#if OPT_ZICONBEEP
1777	Boolean		zIconBeep_flagged; /* True if icon name was changed */
1778#endif /* OPT_ZICONBEEP */
1779	int		cursor_GC;	/* see ShowCursor()		*/
1780	int		cursor_set;	/* requested state		*/
1781	CELL		cursorp;	/* previous cursor row/column	*/
1782	int		cur_col;	/* current cursor column	*/
1783	int		cur_row;	/* current cursor row		*/
1784	int		max_col;	/* rightmost column		*/
1785	int		max_row;	/* bottom row			*/
1786	int		top_marg;	/* top line of scrolling region */
1787	int		bot_marg;	/* bottom line of  "	    "	*/
1788	Widget		scrollWidget;	/* pointer to scrollbar struct	*/
1789	/*
1790	 * Indices used to keep track of the top of the vt100 window and
1791	 * the saved lines, taking scrolling into account.
1792	 */
1793	int		topline;	/* line number of top, <= 0	*/
1794	long		saved_fifo;     /* number of lines that've been saved */
1795	int		savedlines;     /* number of lines that've been saved */
1796	int		savelines;	/* number of lines off top to save */
1797	int		scroll_amt;	/* amount to scroll		*/
1798	int		refresh_amt;	/* amount to refresh		*/
1799	/*
1800	 * Working variables for getLineData().
1801	 */
1802	size_t		lineExtra;	/* extra space for combining chars */
1803	/*
1804	 * Pointer to the current visible buffer.
1805	 */
1806	ScrnBuf		visbuf;		/* ptr to visible screen buf (main) */
1807	/*
1808	 * Data for the normal buffer, which may have saved lines to which
1809	 * the user can scroll.
1810	 */
1811	ScrnBuf		saveBuf_index;
1812	Char		*saveBuf_data;
1813	/*
1814	 * Data for visible and alternate buffer.
1815	 */
1816	ScrnBuf		editBuf_index[2];
1817	Char		*editBuf_data[2];
1818	int		whichBuf;	/* 0/1 for normal/alternate buf */
1819	Boolean		is_running;	/* true when buffers are legal	*/
1820	/*
1821	 * Workspace used for screen operations.
1822	 */
1823	Char		**save_ptr;	/* workspace for save-pointers  */
1824	size_t		save_len;	/* ...and its length		*/
1825
1826	int		scrolllines;	/* number of lines to button scroll */
1827	Boolean		scrollttyoutput; /* scroll to bottom on tty output */
1828	Boolean		scrollkey;	/* scroll to bottom on key	*/
1829	Boolean		cursor_moved;	/* scrolling makes cursor move	*/
1830
1831	Boolean		do_wrap;	/* true if cursor in last column
1832					    and character just output    */
1833
1834	int		incopy;		/* 0 idle; 1 XCopyArea issued;
1835					    -1 first GraphicsExpose seen,
1836					    but last not seen		*/
1837	int		copy_src_x;	/* params from last XCopyArea ... */
1838	int		copy_src_y;
1839	unsigned int	copy_width;
1840	unsigned int	copy_height;
1841	int		copy_dest_x;
1842	int		copy_dest_y;
1843
1844	Boolean		c132;		/* allow change to 132 columns	*/
1845	Boolean		curses;		/* kludge line wrap for more	*/
1846	Boolean		hp_ll_bc;	/* kludge HP-style ll for xdb	*/
1847	Boolean		marginbell;	/* true if margin bell on	*/
1848	int		nmarginbell;	/* columns from right margin	*/
1849	int		bellArmed;	/* cursor below bell margin	*/
1850	BellVolume	marginVolume;	/* margin-bell volume           */
1851	BellVolume	warningVolume;	/* warning-bell volume          */
1852	Boolean		multiscroll;	/* true if multi-scroll		*/
1853	int		scrolls;	/* outstanding scroll count,
1854					    used only with multiscroll	*/
1855	SavedCursor	sc[SAVED_CURSORS]; /* data for restore cursor	*/
1856	unsigned 	save_modes[DP_LAST]; /* save dec/xterm private modes */
1857
1858	int		title_modes;	/* control set/get of titles	*/
1859	SaveTitle	*save_title;
1860
1861	/* Improved VT100 emulation stuff.				*/
1862	String		keyboard_dialect; /* default keyboard dialect	*/
1863	Char		gsets[4];	/* G0 through G3.		*/
1864	Char		curgl;		/* Current GL setting.		*/
1865	Char		curgr;		/* Current GR setting.		*/
1866	Char		curss;		/* Current single shift.	*/
1867	String		term_id;	/* resource for terminal_id	*/
1868	int		terminal_id;	/* 100=vt100, 220=vt220, etc.	*/
1869	int		vtXX_level;	/* 0=vt52, 1,2,3 = vt100 ... vt320 */
1870	int		ansi_level;	/* levels 1,2,3			*/
1871	int		protected_mode;	/* 0=off, 1=DEC, 2=ISO		*/
1872	Boolean		always_bold_mode; /* compare normal/bold font	*/
1873	Boolean		always_highlight; /* whether to highlight cursor */
1874	Boolean		bold_mode;	/* use bold font or overstrike	*/
1875	Boolean		delete_is_del;	/* true for compatible Delete key */
1876	Boolean		jumpscroll;	/* whether we should jumpscroll */
1877	Boolean		fastscroll;	/* whether we should fastscroll */
1878	Boolean		old_fkeys;	/* true for compatible fkeys	*/
1879	Boolean		underline;	/* whether to underline text	*/
1880
1881#if OPT_MAXIMIZE
1882	Boolean		restore_data;
1883	int		restore_x;
1884	int		restore_y;
1885	unsigned	restore_width;
1886	unsigned	restore_height;
1887#endif
1888
1889#if OPT_SCROLL_LOCK
1890	Boolean		allowScrollLock;/* ScrollLock mode		*/
1891	Boolean		allowScrollLock0;/* initial ScrollLock mode	*/
1892	Boolean		scroll_lock;	/* true to keep buffer in view	*/
1893	Boolean		scroll_dirty;	/* scrolling makes screen dirty	*/
1894#endif
1895
1896#if OPT_VT52_MODE
1897	int		vt52_save_level; /* save-area for DECANM	*/
1898	Char		vt52_save_curgl;
1899	Char		vt52_save_curgr;
1900	Char		vt52_save_curss;
1901	Char		vt52_save_gsets[4];
1902#endif
1903	/* Testing */
1904#if OPT_XMC_GLITCH
1905	unsigned	xmc_glitch;	/* # of spaces to pad on SGR's	*/
1906	int		xmc_attributes;	/* attrs that make a glitch	*/
1907	Boolean		xmc_inline;	/* SGR's propagate only to eol	*/
1908	Boolean		move_sgr_ok;	/* SGR is reset on move		*/
1909#endif
1910
1911	/*
1912	 * Bell
1913	 */
1914	int		visualBellDelay; /* msecs to delay for visibleBell */
1915	int		bellSuppressTime; /* msecs after Bell before another allowed */
1916	Boolean		bellInProgress; /* still ringing/flashing prev bell? */
1917	Boolean		bellIsUrgent;	/* set XUrgency WM hint on bell */
1918	/*
1919	 * Select/paste state.
1920	 */
1921	Boolean		selectToClipboard; /* primary vs clipboard */
1922	String		*mappedSelect;	/* mapping for "SELECT" to "PRIMARY" */
1923
1924	Boolean		waitingForTrackInfo;
1925	int		numberOfClicks;
1926	int		maxClicks;
1927	int		multiClickTime;	/* time between multiclick selects */
1928	SelectUnit	selectUnit;
1929	SelectUnit	selectMap[NSELECTUNITS];
1930	String		onClick[NSELECTUNITS + 1];
1931
1932	char		*charClass;	/* for overriding word selection */
1933	Boolean		cutNewline;	/* whether or not line cut has \n */
1934	Boolean		cutToBeginningOfLine;  /* line cuts to BOL? */
1935	Boolean		highlight_selection; /* controls appearance of selection */
1936	Boolean		show_wrap_marks; /* show lines which are wrapped */
1937	Boolean		trim_selection; /* controls trimming of selection */
1938	Boolean		i18nSelections;
1939	Boolean		brokenSelections;
1940	Boolean		keepSelection;	/* do not lose selection on output */
1941	Boolean		replyToEmacs;	/* Send emacs escape code when done selecting or extending? */
1942	Char		*selection_data; /* the current selection */
1943	int		selection_size; /* size of allocated buffer */
1944	unsigned long	selection_length; /* number of significant bytes */
1945	EventMode	eventMode;
1946	Time		selection_time;	/* latest event timestamp */
1947	Time		lastButtonUpTime;
1948	unsigned	lastButton;
1949
1950	CELL		rawPos;		/* raw position for selection start */
1951	CELL		startRaw;	/* area before selectUnit processing */
1952	CELL		endRaw;		/* " " */
1953	CELL		startSel;	/* area after selectUnit processing */
1954	CELL		endSel;		/* " " */
1955	CELL		startH;		/* start highlighted text */
1956	CELL		endH;		/* end highlighted text */
1957	CELL		saveStartW;	/* saved WORD state, for LINE */
1958	CELL		startExt;	/* Start, end of extension */
1959	CELL		endExt;		/* " " */
1960	CELL		saveStartR;	/* Saved values of raw selection for extend to restore to */
1961	CELL		saveEndR;	/* " " */
1962	int		startHCoord, endHCoord;
1963	int		firstValidRow;	/* Valid rows for selection clipping */
1964	int		lastValidRow;	/* " " */
1965
1966	String		default_string;
1967	String		eightbit_select_types;
1968	Atom*		selection_targets_8bit;
1969#if OPT_WIDE_CHARS
1970	String		utf8_select_types;
1971	Atom*		selection_targets_utf8;
1972#endif
1973	Atom*		selection_atoms; /* which selections we own */
1974	Cardinal	sel_atoms_size;	/*  how many atoms allocated */
1975	Cardinal	selection_count; /* how many atoms in use */
1976#if OPT_SELECT_REGEX
1977	char *		selectExpr[NSELECTUNITS];
1978#endif
1979	/*
1980	 * Input/output state.
1981	 */
1982	Boolean		input_eight_bits;/* use 8th bit instead of ESC prefix */
1983	Boolean		output_eight_bits; /* honor all bits or strip */
1984	Boolean		control_eight_bits; /* send CSI as 8-bits */
1985	Boolean		backarrow_key;		/* backspace/delete */
1986	Boolean		alt_is_not_meta;	/* use both Alt- and Meta-key */
1987	Boolean		alt_sends_esc;		/* Alt-key sends ESC prefix */
1988	Boolean		meta_sends_esc;		/* Meta-key sends ESC prefix */
1989	/*
1990	 * Fonts
1991	 */
1992	Pixmap		menu_item_bitmap;	/* mask for checking items */
1993	String		initial_font;
1994	String		menu_font_names[NMENUFONTS][fMAX];
1995#define MenuFontName(n) menu_font_names[n][fNorm]
1996	long		menu_font_sizes[NMENUFONTS];
1997	int		menu_font_number;
1998#if OPT_WIDE_CHARS
1999	Boolean		savedVTFonts;
2000	Boolean		mergedVTFonts;
2001	SubResourceRec	cacheVTFonts;
2002#endif
2003#if OPT_CLIP_BOLD
2004	Boolean		use_clipping;
2005#endif
2006	void *		main_cgs_cache;
2007#ifndef NO_ACTIVE_ICON
2008	void *		icon_cgs_cache;
2009#endif
2010#if OPT_RENDERFONT
2011	XTermXftFonts	renderFontNorm[NMENUFONTS];
2012	XTermXftFonts	renderFontBold[NMENUFONTS];
2013	XTermXftFonts	renderFontItal[NMENUFONTS];
2014#if OPT_RENDERWIDE
2015	XTermXftFonts	renderWideNorm[NMENUFONTS];
2016	XTermXftFonts	renderWideBold[NMENUFONTS];
2017	XTermXftFonts	renderWideItal[NMENUFONTS];
2018	TypedBuffer(XftCharSpec);
2019#else
2020	TypedBuffer(XftChar8);
2021#endif
2022	XftDraw *	renderDraw;
2023#endif
2024#if OPT_INPUT_METHOD
2025	XIM		xim;
2026	XFontSet	fs;		/* fontset for XIM preedit */
2027	int		fs_ascent;	/* ascent of fs */
2028#endif
2029	XIC		xic;		/* this is used even without XIM */
2030#if OPT_DABBREV
2031	Boolean		dabbrev_working;	/* nonzero during dabbrev process */
2032	unsigned char	dabbrev_erase_char;	/* used for deleting inserted completion */
2033#endif
2034	char		tcapbuf[TERMCAP_SIZE];
2035	char		tcap_area[TERMCAP_SIZE];
2036#if OPT_TCAP_FKEYS
2037	char **		tcap_fkeys;
2038#endif
2039} TScreen;
2040
2041typedef struct _TekPart {
2042	XFontStruct *	Tfont[TEKNUMFONTS];
2043	int		tobaseline[TEKNUMFONTS]; /* top-baseline, each font */
2044	char *		initial_font;		/* large, 2, 3, small */
2045	char *		gin_terminator_str;	/* ginTerminator resource */
2046#if OPT_TOOLBAR
2047	TbInfo		tb_info;	/* toolbar information		*/
2048#endif
2049} TekPart;
2050
2051/* Tektronix window parameters */
2052typedef struct _TekScreen {
2053	GC		TnormalGC;	/* normal painting		*/
2054	GC		TcursorGC;	/* normal cursor painting	*/
2055
2056	Boolean		waitrefresh;	/* postpone refresh		*/
2057	TKwin		fullTwin;
2058#ifndef NO_ACTIVE_ICON
2059	TKwin		iconTwin;
2060	TKwin		*whichTwin;
2061#endif /* NO_ACTIVE_ICON */
2062
2063	Cursor		arrow;		/* arrow cursor			*/
2064	GC		linepat[TEKNUMLINES]; /* line patterns		*/
2065	int		cur_X;		/* current x			*/
2066	int		cur_Y;		/* current y			*/
2067	Tmodes		cur;		/* current tek modes		*/
2068	Tmodes		page;		/* starting tek modes on page	*/
2069	int		margin;		/* 0 -> margin 1, 1 -> margin 2	*/
2070	int		pen;		/* current Tektronix pen 0=up, 1=dn */
2071	char		*TekGIN;	/* nonzero if Tektronix GIN mode*/
2072	int		gin_terminator; /* Tek strap option */
2073	char		tcapbuf[TERMCAP_SIZE];
2074} TekScreen;
2075
2076#if OPT_READLINE
2077#define SCREEN_FLAG(screenp,f)		(1&(screenp)->f)
2078#define SCREEN_FLAG_set(screenp,f)	((screenp)->f |= 1)
2079#define SCREEN_FLAG_unset(screenp,f)	((screenp)->f &= (unsigned) ~1L)
2080#define SCREEN_FLAG_save(screenp,f)	\
2081	((screenp)->f = (((screenp)->f)<<1) | SCREEN_FLAG(screenp,f))
2082#define SCREEN_FLAG_restore(screenp,f)	((screenp)->f = (((screenp)->f)>>1))
2083#else
2084#define SCREEN_FLAG(screenp,f)		(0)
2085#endif
2086
2087/* meaning of bits in screen.select flag */
2088#define	INWINDOW	01	/* the mouse is in one of the windows */
2089#define	FOCUS		02	/* one of the windows is the focus window */
2090
2091#define MULTICLICKTIME 250	/* milliseconds */
2092
2093typedef struct {
2094    const char *name;
2095    int code;
2096} FlagList;
2097
2098typedef enum {
2099    fwNever = 0,
2100    fwResource,
2101    fwAlways
2102} fontWarningTypes;
2103
2104typedef enum {
2105    keyboardIsLegacy,		/* bogus vt220 codes for F1-F4, etc. */
2106    keyboardIsDefault,
2107    keyboardIsHP,
2108    keyboardIsSCO,
2109    keyboardIsSun,
2110    keyboardIsTermcap,
2111    keyboardIsVT220
2112} xtermKeyboardType;
2113
2114typedef enum {			/* legal values for screen.pointer_mode */
2115    pNever = 0,
2116    pNoMouse = 1,
2117    pAlways = 2
2118} pointerModeTypes;
2119
2120typedef enum {			/* legal values for screen.utf8_mode */
2121    uFalse = 0
2122    , uTrue = 1
2123    , uAlways = 2
2124    , uDefault = 3
2125    , uLast
2126} utf8ModeTypes;
2127
2128#if OPT_HP_FUNC_KEYS
2129#define NAME_HP_KT " hp"
2130#else
2131#define NAME_HP_KT /*nothing*/
2132#endif
2133
2134#if OPT_SCO_FUNC_KEYS
2135#define NAME_SCO_KT " sco"
2136#else
2137#define NAME_SCO_KT /*nothing*/
2138#endif
2139
2140#if OPT_SUN_FUNC_KEYS
2141#define NAME_SUN_KT " sun"
2142#else
2143#define NAME_SUN_KT /*nothing*/
2144#endif
2145
2146#if OPT_SUNPC_KBD
2147#define NAME_VT220_KT " vt220"
2148#else
2149#define NAME_VT220_KT /*nothing*/
2150#endif
2151
2152#if OPT_TCAP_FKEYS
2153#define NAME_TCAP_KT " tcap"
2154#else
2155#define NAME_TCAP_KT /*nothing*/
2156#endif
2157
2158#define KEYBOARD_TYPES NAME_TCAP_KT NAME_HP_KT NAME_SCO_KT NAME_SUN_KT NAME_VT220_KT
2159
2160#if OPT_TRACE
2161#define TRACE_RC(code,func) code = func
2162#else
2163#define TRACE_RC(code,func) func
2164#endif
2165
2166#if OPT_TRACE
2167extern	const char * visibleKeyboardType(xtermKeyboardType);
2168#endif
2169
2170typedef struct
2171{
2172    int cursor_keys;		/* how to handle cursor-key modifiers */
2173    int function_keys;		/* how to handle function-key modifiers */
2174    int keypad_keys;		/* how to handle keypad key-modifiers */
2175    int other_keys;		/* how to handle other key-modifiers */
2176    int string_keys;		/* how to handle string() modifiers */
2177} TModify;
2178
2179typedef struct
2180{
2181    xtermKeyboardType type;
2182    unsigned flags;
2183    char *shell_translations;
2184    char *xterm_translations;
2185    char *extra_translations;
2186#if OPT_INITIAL_ERASE
2187    int	reset_DECBKM;		/* reset should set DECBKM */
2188#endif
2189#if OPT_MOD_FKEYS
2190    TModify modify_now;		/* current modifier value */
2191    TModify modify_1st;		/* original modifier value, for resets */
2192    int format_keys;		/* format of modifyOtherKeys */
2193#endif
2194} TKeyboard;
2195
2196#define GravityIsNorthWest(w) ((w)->misc.resizeGravity == NorthWestGravity)
2197#define GravityIsSouthWest(w) ((w)->misc.resizeGravity == SouthWestGravity)
2198
2199typedef struct _Misc {
2200    VTFontNames default_font;
2201    char *geo_metry;
2202    char *T_geometry;
2203#if OPT_WIDE_CHARS
2204    Boolean cjk_width;		/* true for built-in CJK wcwidth() */
2205    Boolean mk_width;		/* true for simpler built-in wcwidth() */
2206    int mk_samplesize;
2207    int mk_samplepass;
2208#endif
2209#if OPT_LUIT_PROG
2210    Boolean callfilter;		/* true to invoke luit */
2211    Boolean use_encoding;	/* true to use -encoding option for luit */
2212    char *locale_str;		/* "locale" resource */
2213    char *localefilter;		/* path for luit */
2214#endif
2215    fontWarningTypes fontWarnings;
2216    int limit_resize;
2217#ifdef ALLOWLOGGING
2218    Boolean log_on;
2219#endif
2220    Boolean login_shell;
2221    Boolean re_verse;
2222    Boolean re_verse0;		/* initial value of "-rv" */
2223    XtGravity resizeGravity;
2224    Boolean reverseWrap;
2225    Boolean autoWrap;
2226    Boolean logInhibit;
2227    Boolean signalInhibit;
2228#if OPT_TEK4014
2229    Boolean tekInhibit;
2230    Boolean tekSmall;		/* start tek window in small size */
2231    Boolean TekEmu;		/* true if Tektronix emulation	*/
2232    Boolean Tshow;		/* Tek window showing		*/
2233#endif
2234    Boolean scrollbar;
2235#ifdef SCROLLBAR_RIGHT
2236    Boolean useRight;
2237#endif
2238    Boolean titeInhibit;
2239    Boolean tiXtraScroll;
2240    Boolean appcursorDefault;
2241    Boolean appkeypadDefault;
2242#if OPT_INPUT_METHOD
2243    char* f_x;			/* font for XIM */
2244    char* input_method;
2245    char* preedit_type;
2246    Boolean open_im;		/* true if input-method is opened */
2247    Boolean cannot_im;		/* true if we cannot use input-method */
2248    int retry_im;
2249#endif
2250    Boolean dynamicColors;
2251    Boolean shared_ic;
2252#ifndef NO_ACTIVE_ICON
2253    Boolean active_icon;	/* use application icon window  */
2254    unsigned icon_border_width;
2255    Pixel icon_border_pixel;
2256#endif /* NO_ACTIVE_ICON */
2257#if OPT_DEC_SOFTFONT
2258    Boolean font_loadable;
2259#endif
2260#if OPT_SHIFT_FONTS
2261    Boolean shift_fonts;	/* true if we interpret fontsize-shifting */
2262#endif
2263#if OPT_SUNPC_KBD
2264    int ctrl_fkeys;		/* amount to add to XK_F1 for ctrl modifier */
2265#endif
2266#if OPT_NUM_LOCK
2267    Boolean real_NumLock;	/* true if we treat NumLock key specially */
2268    Boolean alwaysUseMods;	/* true if we always want f-key modifiers */
2269    unsigned num_lock;		/* modifier for Num_Lock */
2270    unsigned alt_mods;		/* modifier for Alt_L or Alt_R */
2271    unsigned meta_mods;		/* modifier for Meta_L or Meta_R */
2272    unsigned other_mods;	/* conflicting modifiers, e.g., Mode_Switch */
2273#endif
2274#if OPT_RENDERFONT
2275    char *face_name;
2276    char *face_wide_name;
2277    float face_size[NMENUFONTS];
2278    char *render_font_s;
2279    Boolean render_font;
2280#endif
2281} Misc;
2282
2283typedef struct {int foo;} XtermClassPart, TekClassPart;
2284
2285typedef struct _XtermClassRec {
2286    CoreClassPart  core_class;
2287    XtermClassPart xterm_class;
2288} XtermClassRec;
2289
2290extern WidgetClass xtermWidgetClass;
2291
2292#define IsXtermWidget(w) (XtClass(w) == xtermWidgetClass)
2293
2294#if OPT_TEK4014
2295typedef struct _TekClassRec {
2296    CoreClassPart core_class;
2297    TekClassPart tek_class;
2298} TekClassRec;
2299
2300extern WidgetClass tekWidgetClass;
2301
2302#define IsTekWidget(w) (XtClass(w) == tekWidgetClass)
2303
2304#endif
2305
2306/* define masks for keyboard.flags */
2307#define MODE_KAM	xBIT(0)	/* keyboard action mode */
2308#define MODE_DECKPAM	xBIT(1)	/* keypad application mode */
2309#define MODE_DECCKM	xBIT(2)	/* cursor keys */
2310#define MODE_SRM	xBIT(3)	/* send-receive mode */
2311#define MODE_DECBKM	xBIT(4)	/* backarrow */
2312
2313
2314#define N_MARGINBELL	10
2315
2316#define TAB_BITS_SHIFT	5	/* FIXME: 2**5 == 32 (should derive) */
2317#define TAB_BITS_WIDTH	(1 << TAB_BITS_SHIFT)
2318#define TAB_ARRAY_SIZE	(1024 / TAB_BITS_WIDTH)
2319#define MAX_TABS	(TAB_BITS_WIDTH * TAB_ARRAY_SIZE)
2320
2321typedef unsigned Tabs [TAB_ARRAY_SIZE];
2322
2323typedef struct _XtermWidgetRec {
2324    CorePart	core;
2325    XSizeHints	hints;
2326    Bool	init_menu;
2327    TKeyboard	keyboard;	/* terminal keyboard		*/
2328    TScreen	screen;		/* terminal screen		*/
2329    unsigned	flags;		/* mode flags			*/
2330    int		cur_foreground; /* current foreground color	*/
2331    int		cur_background; /* current background color	*/
2332    Pixel	dft_foreground; /* default foreground color	*/
2333    Pixel	dft_background; /* default background color	*/
2334    Pixel	old_foreground; /* original foreground color	*/
2335    Pixel	old_background; /* original background color	*/
2336#if OPT_ISO_COLORS
2337    int		sgr_foreground; /* current SGR foreground color */
2338    int		sgr_background; /* current SGR background color */
2339    Boolean	sgr_extended;	/* SGR set with extended codes? */
2340#endif
2341    unsigned	initflags;	/* initial mode flags		*/
2342    Tabs	tabs;		/* tabstops of the terminal	*/
2343    Misc	misc;		/* miscellaneous parameters	*/
2344} XtermWidgetRec, *XtermWidget;
2345
2346#if OPT_TEK4014
2347typedef struct _TekWidgetRec {
2348    CorePart	core;
2349    TekPart	tek;		/* contains resources */
2350    TekScreen	screen;		/* contains working data (no resources) */
2351    Bool	init_menu;
2352    XSizeHints	hints;
2353} TekWidgetRec, *TekWidget;
2354#endif /* OPT_TEK4014 */
2355
2356/*
2357 * terminal flags
2358 * There are actually two namespaces mixed together here.
2359 * One is the set of flags that can go in screen->visbuf attributes
2360 * and which must fit in a char (see OFF_ATTRS).
2361 * The other is the global setting stored in
2362 * term->flags and screen->save_modes.  This need only fit in an unsigned.
2363 */
2364
2365#define AttrBIT(n)	xBIT(n)		/* text-attributes */
2366#define DrawBIT(n)	xBIT(n + 8)	/* drawXtermText flags */
2367#define MiscBIT(n)	xBIT(n + 16)	/* miscellaneous state flags */
2368
2369/* global flags and character flags (visible character attributes) */
2370#define INVERSE		AttrBIT(0)	/* invert the characters to be output */
2371#define UNDERLINE	AttrBIT(1)	/* true if underlining */
2372#define BOLD		AttrBIT(2)
2373#define BLINK		AttrBIT(3)
2374/* global flags (also character attributes) */
2375#define BG_COLOR	AttrBIT(4)	/* true if background set */
2376#define FG_COLOR	AttrBIT(5)	/* true if foreground set */
2377
2378/* character flags (internal attributes) */
2379#define PROTECTED	AttrBIT(6)	/* a character that cannot be erased */
2380#define CHARDRAWN	AttrBIT(7)	/* a character has been drawn here on
2381					   the screen.  Used to distinguish
2382					   blanks from empty parts of the
2383					   screen when selecting */
2384
2385/* The following attributes are used in the argument of drawXtermText()  */
2386#define NOBACKGROUND	DrawBIT(0)	/* Used for overstrike */
2387#define NOTRANSLATION	DrawBIT(1)	/* No scan for chars missing in font */
2388#define DOUBLEWFONT	DrawBIT(2)	/* The actual X-font is double-width */
2389#define DOUBLEHFONT	DrawBIT(3)	/* The actual X-font is double-height */
2390#define CHARBYCHAR	DrawBIT(4)	/* Draw chars one-by-one */
2391
2392/* The following attribute is used in the argument of xtermSpecialFont etc */
2393#define NORESOLUTION	DrawBIT(5)	/* find the font without resolution */
2394
2395/*
2396 * Other flags
2397 */
2398#define WRAPAROUND	MiscBIT(0)	/* true if auto wraparound mode */
2399#define	REVERSEWRAP	MiscBIT(1)	/* true if reverse wraparound mode */
2400#define REVERSE_VIDEO	MiscBIT(2)	/* true if screen white on black */
2401#define LINEFEED	MiscBIT(3)	/* true if in auto linefeed mode */
2402#define ORIGIN		MiscBIT(4)	/* true if in origin mode */
2403#define INSERT		MiscBIT(5)	/* true if in insert mode */
2404#define SMOOTHSCROLL	MiscBIT(6)	/* true if in smooth scroll mode */
2405#define IN132COLUMNS	MiscBIT(7)	/* true if in 132 column mode */
2406#define INVISIBLE	MiscBIT(8)	/* true if writing invisible text */
2407#define NATIONAL        MiscBIT(9)	/* true if writing national charset */
2408
2409/*
2410 * Groups of attributes
2411 */
2412			/* mask for video-attributes only */
2413#define SGR_MASK	(BOLD | BLINK | UNDERLINE | INVERSE)
2414
2415			/* mask: user-visible attributes */
2416#define	ATTRIBUTES	(SGR_MASK | BG_COLOR | FG_COLOR | INVISIBLE | PROTECTED)
2417
2418/* The toplevel-call to drawXtermText() should have text-attributes guarded: */
2419#define DRAWX_MASK	(ATTRIBUTES | CHARDRAWN)
2420
2421/*
2422 * BOLDATTR is not only nonzero when we will use bold font, but uses the bits
2423 * for BOLD/BLINK to match against the video attributes which were originally
2424 * requested.
2425 */
2426#define USE_BOLD(screen) ((screen)->allowBoldFonts)
2427
2428#if OPT_BLINK_TEXT
2429#define BOLDATTR(screen) (unsigned) (USE_BOLD(screen) ? (BOLD | ((screen)->blink_as_bold ? BLINK : 0)) : 0)
2430#else
2431#define BOLDATTR(screen) (unsigned) (USE_BOLD(screen) ? (BOLD | BLINK) : 0)
2432#endif
2433
2434/*
2435 * Per-line flags
2436 */
2437#define LINEWRAPPED	AttrBIT(0)
2438/* used once per line to indicate that it wraps onto the next line so we can
2439 * tell the difference between lines that have wrapped around and lines that
2440 * have ended naturally with a CR at column max_col.
2441 */
2442#define LINEBLINKED	AttrBIT(1)
2443/* set when the line contains blinking text.
2444 */
2445
2446#if OPT_ZICONBEEP || OPT_TOOLBAR
2447#define HANDLE_STRUCT_NOTIFY 1
2448#else
2449#define HANDLE_STRUCT_NOTIFY 0
2450#endif
2451
2452/*
2453 * If we've set protected attributes with the DEC-style DECSCA, then we'll have
2454 * to use DECSED or DECSEL to erase preserving protected text.  (The normal ED,
2455 * EL won't preserve protected-text).  If we've used SPA, then normal ED and EL
2456 * will preserve protected-text.  To keep things simple, just remember the last
2457 * control that was used to begin protected-text, and use that to determine how
2458 * erases are performed (otherwise we'd need 2 bits per protected character).
2459 */
2460#define OFF_PROTECT 0
2461#define DEC_PROTECT 1
2462#define ISO_PROTECT 2
2463
2464#define TScreenOf(xw)	(&(xw)->screen)
2465#define TekScreenOf(tw) (&(tw)->screen)
2466
2467#define PrinterOf(screen) (screen)->printer_state
2468
2469#ifdef SCROLLBAR_RIGHT
2470#define OriginX(screen) (((term->misc.useRight)?0:ScrollbarWidth(screen)) + screen->border)
2471#else
2472#define OriginX(screen) (ScrollbarWidth(screen) + screen->border)
2473#endif
2474
2475#define OriginY(screen) (screen->border)
2476
2477#define CursorMoved(screen) \
2478		((screen)->cursor_moved || \
2479		    ((screen)->cursorp.col != (screen)->cur_col || \
2480		     (screen)->cursorp.row != (screen)->cur_row))
2481
2482#define CursorX(screen,col) ((col) * FontWidth(screen) + OriginX(screen))
2483#define CursorY(screen,row) ((INX2ROW(screen, row) * FontHeight(screen)) \
2484			+ screen->border)
2485
2486/*
2487 * These definitions depend on whether xterm supports active-icon.
2488 */
2489#ifndef NO_ACTIVE_ICON
2490#define IsIconWin(screen,win)	((win) == &(screen)->iconVwin)
2491#define IsIcon(screen)		(WhichVWin(screen) == &(screen)->iconVwin)
2492#define WhichVWin(screen)	((screen)->whichVwin)
2493#define WhichTWin(screen)	((screen)->whichTwin)
2494
2495#define WhichVFont(screen,name)	(IsIcon(screen) ? (screen)->fnt_icon.fs \
2496						: (screen)->name)
2497#define FontAscent(screen)	(IsIcon(screen) ? (screen)->fnt_icon.fs->ascent \
2498						: WhichVWin(screen)->f_ascent)
2499#define FontDescent(screen)	(IsIcon(screen) ? (screen)->fnt_icon.fs->descent \
2500						: WhichVWin(screen)->f_descent)
2501#else /* NO_ACTIVE_ICON */
2502
2503#define IsIconWin(screen,win)	(False)
2504#define IsIcon(screen)		(False)
2505#define WhichVWin(screen)	(&((screen)->fullVwin))
2506#define WhichTWin(screen)	(&((screen)->fullTwin))
2507
2508#define WhichVFont(screen,name)	((screen)->name)
2509#define FontAscent(screen)	WhichVWin(screen)->f_ascent
2510#define FontDescent(screen)	WhichVWin(screen)->f_descent
2511
2512#endif /* NO_ACTIVE_ICON */
2513
2514#define okFont(font) ((font) != 0 && (font)->fid != 0)
2515
2516/*
2517 * Macro to check if we are iconified; do not use render for that case.
2518 */
2519#define UsingRenderFont(xw)	(((xw)->misc.render_font == True) && !IsIcon(TScreenOf(xw)))
2520
2521/*
2522 * These definitions do not depend on whether xterm supports active-icon.
2523 */
2524#define VWindow(screen)		WhichVWin(screen)->window
2525#define VShellWindow(xw)	XtWindow(SHELL_OF(xw))
2526#define TWindow(screen)		WhichTWin(screen)->window
2527#define TShellWindow		XtWindow(SHELL_OF(tekWidget))
2528
2529#define Width(screen)		WhichVWin(screen)->width
2530#define Height(screen)		WhichVWin(screen)->height
2531#define FullWidth(screen)	WhichVWin(screen)->fullwidth
2532#define FullHeight(screen)	WhichVWin(screen)->fullheight
2533#define FontWidth(screen)	WhichVWin(screen)->f_width
2534#define FontHeight(screen)	WhichVWin(screen)->f_height
2535
2536#define NormalFont(screen)	WhichVFont(screen, fnts[fNorm].fs)
2537#define BoldFont(screen)	WhichVFont(screen, fnts[fBold].fs)
2538
2539#if OPT_WIDE_CHARS
2540#define NormalWFont(screen)	WhichVFont(screen, fnts[fWide].fs)
2541#define BoldWFont(screen)	WhichVFont(screen, fnts[fWBold].fs)
2542#endif
2543
2544#define ScrollbarWidth(screen)	WhichVWin(screen)->sb_info.width
2545
2546#define NormalGC(w,sp)		getCgsGC(w, WhichVWin(sp), gcNorm)
2547#define ReverseGC(w,sp)		getCgsGC(w, WhichVWin(sp), gcNormReverse)
2548#define NormalBoldGC(w,sp)	getCgsGC(w, WhichVWin(sp), gcBold)
2549#define ReverseBoldGC(w,sp)	getCgsGC(w, WhichVWin(sp), gcBoldReverse)
2550
2551#define TWidth(screen)		WhichTWin(screen)->width
2552#define THeight(screen)		WhichTWin(screen)->height
2553#define TFullWidth(screen)	WhichTWin(screen)->fullwidth
2554#define TFullHeight(screen)	WhichTWin(screen)->fullheight
2555#define TekScale(screen)	WhichTWin(screen)->tekscale
2556
2557#define BorderWidth(w)		((w)->core.border_width)
2558#define BorderPixel(w)		((w)->core.border_pixel)
2559
2560#define AllowXtermOps(w,name)	(TScreenOf(w)->name && !TScreenOf(w)->allowSendEvents)
2561
2562#define AllowColorOps(w,name)	(AllowXtermOps(w, allowColorOps) || \
2563				 !TScreenOf(w)->disallow_color_ops[name])
2564
2565#define AllowFontOps(w,name)	(AllowXtermOps(w, allowFontOps) || \
2566				 !TScreenOf(w)->disallow_font_ops[name])
2567
2568#define AllowTcapOps(w,name)	(AllowXtermOps(w, allowTcapOps) || \
2569				 !TScreenOf(w)->disallow_tcap_ops[name])
2570
2571#define AllowTitleOps(w)	AllowXtermOps(w, allowTitleOps)
2572
2573#define AllowWindowOps(w,name)	(AllowXtermOps(w, allowWindowOps) || \
2574				 !TScreenOf(w)->disallow_win_ops[name])
2575
2576#if OPT_TOOLBAR
2577#define ToolbarHeight(w)	((resource.toolBar) \
2578				 ? ((w)->VT100_TB_INFO(menu_height) \
2579				  + (w)->VT100_TB_INFO(menu_border) * 2) \
2580				 : 0)
2581#else
2582#define ToolbarHeight(w) 0
2583#endif
2584
2585#if OPT_TEK4014
2586#define TEK_LINK_BLOCK_SIZE 1024
2587
2588typedef struct Tek_Link
2589{
2590	struct Tek_Link	*next;	/* pointer to next TekLink in list
2591				   NULL <=> this is last TekLink */
2592	unsigned short fontsize;/* character size, 0-3 */
2593	unsigned short count;	/* number of chars in data */
2594	char *ptr;		/* current pointer into data */
2595	char data [TEK_LINK_BLOCK_SIZE];
2596} TekLink;
2597#endif /* OPT_TEK4014 */
2598
2599/* flags for cursors */
2600#define	OFF		0
2601#define	ON		1
2602#define	BLINKED_OFF	2
2603#define	CLEAR		0
2604#define	TOGGLE		1
2605
2606/* flags for inhibit */
2607#ifdef ALLOWLOGGING
2608#define	I_LOG		0x01
2609#endif
2610#define	I_SIGNAL	0x02
2611#define	I_TEK		0x04
2612
2613/***====================================================================***/
2614
2615#if OPT_TRACE
2616#undef NDEBUG			/* turn on assert's */
2617#else
2618#ifndef NDEBUG
2619#define NDEBUG			/* not debugging, don't do assert's */
2620#endif
2621#endif
2622
2623#include <trace.h>
2624
2625#ifndef TRACE
2626#define TRACE(p) /*nothing*/
2627#endif
2628
2629#ifndef TRACE_CLOSE
2630#define TRACE_CLOSE() /*nothing*/
2631#endif
2632
2633#ifndef TRACE_ARGV
2634#define TRACE_ARGV(tag,argv) /*nothing*/
2635#endif
2636
2637#ifndef TRACE_CHILD
2638#define TRACE_CHILD /*nothing*/
2639#endif
2640
2641#ifndef TRACE_FOCUS
2642#define TRACE_FOCUS(w,e) /*nothing*/
2643#endif
2644
2645#ifndef TRACE_HINTS
2646#define TRACE_HINTS(hints) /*nothing*/
2647#endif
2648
2649#ifndef TRACE_IDS
2650#define TRACE_IDS /*nothing*/
2651#endif
2652
2653#ifndef TRACE_OPTS
2654#define TRACE_OPTS(opts,ress,lens) /*nothing*/
2655#endif
2656
2657#ifndef TRACE_TRANS
2658#define TRACE_TRANS(name,w) /*nothing*/
2659#endif
2660
2661#ifndef TRACE_WM_HINTS
2662#define TRACE_WM_HINTS(w) /*nothing*/
2663#endif
2664
2665#ifndef TRACE_XRES
2666#define TRACE_XRES() /*nothing*/
2667#endif
2668
2669#ifndef TRACE2
2670#define TRACE2(p) /*nothing*/
2671#endif
2672
2673/* *INDENT-ON* */
2674
2675#endif /* included_ptyx_h */
2676