"Fossies" - the Fresh Open Source Software Archive

Member "xterm-379/ptyx.h" (14 Feb 2023, 108193 Bytes) of package /linux/misc/xterm-379.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ptyx.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 377_vs_379.

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