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