1 /*--------------------------------*-H-*---------------------------------*
2  * File:    rxvt.h
3  *----------------------------------------------------------------------*
4  *
5  * All portions of code are copyright by their respective author/s.
6  * Copyright (c) 1997-2001   Geoff Wing <gcw@pobox.com>
7  * Copyright (c) 2003-2004   Marc Lehmann <pcg@goof.com>
8  * Copyright (c) 2004        Terry Griffin <griffint@pobox.com>
9  * Copyright (c) 2005        Teun Burgers <burgers@ecn.nl>
10  * Copyright (c) 2004-2005   Jingmin Zhou <jimmyzhou@users.sourceforge.net>
11  * Copyright (c) 2005-2006   Gautam Iyer <gi1242@users.sourceforge.net>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26  *----------------------------------------------------------------------*/
27 
28 #ifndef __RXVT_H__	/* include once only */
29 #define __RXVT_H__
30 
31 #include "../config.h"
32 #include "feature.h"
33 
34 
35 /*
36  *****************************************************************************
37  * SYSTEM HACKS
38  *****************************************************************************
39  */
40 /* Consistent defines - please report on the necessity
41  * @ Unixware: defines (__svr4__)
42  */
43 #if defined (SVR4) && !defined (OS_SVR4)
44 # define OS_SVR4
45 #endif
46  /*
47 #if defined (sun) && !defined (__sun__)
48 # define __sun__
49 #endif
50 */
51 
52 #ifdef _SCO_DS
53 # define ALL_NUMERIC_PTYS
54 #endif
55 
56 
57 #include <stdio.h>
58 #include <stdint.h>
59 #include <ctype.h>
60 #include <errno.h>
61 #include <signal.h>
62 
63 #ifdef HAVE_SYS_TYPES_H
64 # include <sys/types.h>
65 #endif
66 
67 #ifdef HAVE_UNISTD_H
68 # include <unistd.h>
69 #endif
70 
71 #ifdef HAVE_ASSERT_H
72 # include <assert.h>
73 #endif
74 
75 #ifdef HAVE_STDARG_H
76 # include <stdarg.h>
77 #endif
78 
79 #ifdef HAVE_STDLIB_H
80 # include <stdlib.h>
81 #endif
82 
83 #if defined(HAVE_STRING_H) && !defined(OUR_STRINGS)
84 # include <string.h>
85 #endif
86 
87 #ifdef HAVE_LIMITS_H
88 # include <limits.h>
89 #endif
90 
91 #ifdef HAVE_WCHAR_H
92 # if defined(OS_OPENBSD) && (OS_OPENBSD_REL < 39)
93 typedef unsigned int    _our_wint_t;
94 typedef struct {
95     int __count;
96     union {
97 	_our_wint_t __wch;
98 	char	    __wchb[4]
99     } __value;
100 } mbstate_t;
101 # endif /* defined(OS_OPENBSD) &&... */
102 # include <wchar.h>
103 #endif
104 
105 #ifdef HAVE_FCNTL_H
106 # include <fcntl.h>
107 #endif
108 
109 #if defined(OS_SOLARIS) && defined(__SVR4)
110 # include <sys/strredir.h>
111 #endif
112 
113 #ifdef OS_SOLARIS
114 # include <sys/byteorder.h>
115 #endif
116 
117 #ifdef OS_SOLARIS
118 # include <sys/int_types.h>
119 # undef HAVE_SYS_IOCTL_H
120 #endif
121 
122 #ifdef HAVE_SYS_IOCTL_H
123 # include <sys/ioctl.h>
124 #endif
125 
126 #ifdef HAVE_SYS_SELECT_H
127 # include <sys/select.h>
128 #endif
129 
130 #ifdef HAVE_SYS_SOCKIO_H
131 # include <sys/sockio.h>
132 #endif
133 
134 #if defined(PTYS_ARE_PTMX) && defined(HAVE_SYS_STROPTS_H)
135 # include <sys/stropts.h>   /* for I_PUSH */
136 #endif
137 
138 #if defined(PTYS_ARE_PTMX) && !defined(OS_CYGWIN)
139 # include <sys/resource.h>
140 # define _NEW_TTY_CTRL	    /* get proper definition in <termios.h> */
141 #endif
142 
143 #ifdef HAVE_TIME_H
144 # include <time.h>
145 #endif
146 
147 #ifdef HAVE_SYS_TIME_H
148 # include <sys/time.h>
149 #endif
150 
151 #ifdef HAVE_SYS_TIMES_H
152 # include <sys/times.h>
153 #endif
154 
155 #ifdef HAVE_SYS_STRREDIR_H
156 # include <sys/strredir.h>
157 #endif
158 
159 #ifdef HAVE_SYS_SOCKET_H
160 # include <sys/socket.h>
161 #endif
162 
163 #ifdef HAVE_SYS_WAIT_H
164 # include <sys/wait.h>
165 #endif
166 
167 #ifdef HAVE_SYS_STAT_H
168 # include <sys/stat.h>
169 #endif
170 
171 #ifdef HAVE_ARPA_INET_H
172 # include <arpa/inet.h>
173 #endif
174 
175 #ifdef HAVE_NETINET_IN_H
176 # include <netinet/in.h>
177 #endif
178 
179 #ifdef HAVE_NET_IF_H
180 # include <net/if.h>
181 #endif
182 
183 #ifdef HAVE_NET_IF_ARP_H
184 # include <net/if_arp.h>
185 #endif
186 
187 #ifdef HAVE_PTY_H
188 # include <pty.h>
189 #endif
190 
191 #ifdef OS_DARWIN
192 # include <util.h>
193 #endif
194 
195 #ifdef OS_QNX
196 # include <process.h>
197 # include <sys/utsname.h>
198 # define ut_name    ut_user
199 #endif
200 
201 #ifdef TTY_GID_SUPPORT
202 # include <grp.h>
203 #endif
204 
205 #ifdef HAVE_TERMIOS_H
206 # include <termios.h>
207 typedef struct termios ttymode_t;
208 #else
209 # ifdef HAVE_SGTTY_H
210 #  include <sgtty.h>
211 # endif
212 typedef struct {
213     struct sgttyb   sg;
214     struct tchars   tc;
215     struct ltchars  lc;
216     int             line;
217     int             local;
218 } ttymode_t;
219 #endif
220 
221 
222 # include <X11/Xlib.h>
223 # include <X11/X.h>
224 # include <X11/Xutil.h>
225 # include <X11/Xlibint.h>
226 # include <X11/cursorfont.h>
227 # include <X11/keysym.h>
228 # include <X11/keysymdef.h>
229 # include <X11/Xmd.h>
230 # include <X11/Xatom.h>
231 # include <X11/Xresource.h>
232 
233 /*
234  * We really should include openmotif-X.X/Xm/MwmUtil.h, but that will add
235  * openmotif as a dependency. We dont' really need it, except to set WM hints,
236  * thus this ugly hack.
237  */
238 typedef struct {
239     int	flags;
240     int	functions;
241     int	decorations;
242     int	input_mode;
243     int	status;
244 } MWMHints;
245 # ifdef HAVE_X11_SM_SMLIB_H
246 #  include <X11/SM/SMlib.h>
247 # endif
248 
249 /* Macros to check X Window IDs. Notice that we can use only one macro
250 ** to check all different type of IDs such as Window and Pixmap. But it
251 ** lose the point that we can possibly check the type of those IDs.
252 */
253 #undef IS_WIN
254 #undef NOT_WIN
255 #undef UNSET_WIN
256 #define IS_WIN(WINDOW_ID)   \
257     (None != (WINDOW_ID))
258 #define NOT_WIN(WINDOW_ID)  \
259     (None == (WINDOW_ID))
260 #define UNSET_WIN(WINDOW_ID)	\
261     ((WINDOW_ID) = None)
262 
263 #undef IS_PIXMAP
264 #undef NOT_PIXMAP
265 #undef UNSET_PIXMAP
266 #define IS_PIXMAP(PIXMAP_ID)	\
267     (None != (PIXMAP_ID))
268 #define NOT_PIXMAP(PIXMAP_ID)	\
269     (None == (PIXMAP_ID))
270 #define UNSET_PIXMAP(PIXMAP_ID)	\
271     ((PIXMAP_ID) = None)
272 
273 #undef IS_ATOM
274 #undef NOT_ATOM
275 #undef UNSET_ATOM
276 #define IS_ATOM(ATOM_ID)    \
277     (None != (ATOM_ID))
278 #define NOT_ATOM(ATOM_ID)   \
279     (None == (ATOM_ID))
280 #define UNSET_ATOM(ATOM_ID) \
281     ((ATOM_ID) = None)
282 
283 #undef IS_GC
284 #undef NOT_GC
285 #undef UNSET_GC
286 #define IS_GC(GC_ID)	\
287     (None != (GC_ID))
288 #define NOT_GC(GC_ID)	\
289     (None == (GC_ID))
290 #define UNSET_GC(GC_ID)	\
291     ((GC_ID) = None)
292 
293 #undef IS_CURSOR
294 #undef NOT_CURSOR
295 #undef UNSET_CURSOR
296 #define IS_CURSOR(CURSOR_ID)	\
297     (None != (CURSOR_ID))
298 #define NOT_CURSOR(CURSOR_ID)	\
299     (None == (CURSOR_ID))
300 #define UNSET_CURSOR(CURSOR_ID)	\
301     ((CURSOR_ID) = None)
302 
303 #undef IS_REGION
304 #undef NOT_REGION
305 #undef UNSET_REGION
306 #define IS_REGION(REGION_ID)	\
307     (None != (REGION_ID))
308 #define NOT_REGION(REGION_ID)	\
309     (None == (REGION_ID))
310 #define UNSET_REGION(REGION_ID)	\
311     ((REGION_ID) = None)
312 
313 #undef IS_KEYSYM
314 #undef NOT_KEYSYM
315 #undef UNSET_KEYSYM
316 #define IS_KEYSYM(KEYSYM_ID)	\
317     (None != (KEYSYM_ID))
318 #define NOT_KEYSYM(KEYSYM_ID)	\
319     (None == (KEYSYM_ID))
320 #define UNSET_KEYSYM(KEYSYM_ID)	\
321     ((KEYSYM_ID) = None)
322 
323 
324 #ifndef HAVE_XPOINTER
325 typedef char*	    XPointer;
326 #endif
327 
328 
329 #ifdef HAVE_LIBXPM
330 # include <X11/xpm.h>
331 #endif
332 
333 #if defined(BACKGROUND_IMAGE) || defined(TRANSPARENT)
334 # ifdef USE_JPEG
335 #  include <jpeglib.h>
336 # endif
337 # ifdef USE_PNG
338 #  ifdef OS_OPENBSD
339 #   include <libpng/png.h>
340 #  else
341 #   include <png.h>
342 #  endif    /* OS_OPENBSD */
343 # endif	/* USE_PNG */
344 #endif
345 
346 #ifdef HAVE_LIBXRENDER
347 # include <X11/extensions/Xrender.h>
348 #endif
349 
350 /* Xft.h seems to conflict with png.h. So we must include it
351 ** after pnt.h */
352 # ifdef XFT_SUPPORT
353 #  include <X11/Xft/Xft.h>
354 # endif
355 # ifdef HAVE_ICONV_H
356 #  include <iconv.h>
357 # endif
358 
359 /*
360 ** It seems Mac OS X's fontconfig does not have following definitions
361 */
362 #ifdef XFT_SUPPORT
363 # ifndef FC_WIDTH
364 #  define FC_WIDTH		    "width"
365 #  define FC_WIDTH_ULTRACONDENSED   (50)
366 #  define FC_WIDTH_EXTRACONDENSED   (63)
367 #  define FC_WIDTH_CONDENSED	    (75)
368 #  define FC_WIDTH_SEMICONDENSED    (87)
369 #  define FC_WIDTH_NORMAL	    (100)
370 #  define FC_WIDTH_SEMIEXPANDED	    (113)
371 #  define FC_WIDTH_EXPANDED	    (125)
372 #  define FC_WIDTH_EXTRAEXPANDED    (150)
373 #  define FC_WIDTH_ULTRAEXPANDED    (200)
374 # endif
375 #endif
376 
377 
378 #ifdef HAVE_XSETLOCALE
379 # define X_LOCALE
380 # include <X11/Xlocale.h>
381 #else
382 # ifdef HAVE_LOCALE_H
383 #  include <locale.h>
384 # endif
385 #endif
386 
387 
388 #ifdef HAVE_NL_LANGINFO
389 # include <langinfo.h>
390 #endif
391 
392 
393 #ifdef UTMP_SUPPORT
394 # ifdef UTEMPTER_SUPPORT
395 #  include <utempter.h>
396 # endif
397 # ifdef HAVE_UTMP_H
398 #  include <utmp.h>
399 #  ifdef HAVE_SETUTENT
400 #   define RXVT_UTMP_SYSV
401 #  endif
402 # endif
403 # if defined(HAVE_UTMPX_H) && !defined(HAVE_UTMP_H)
404 #  include <utmpx.h>
405 #  define RXVT_UTMP_SYSV
406 # endif
407 # ifdef HAVE_LASTLOG_H
408 #  include <lastlog.h>
409 # endif
410 #endif
411 
412 
413 #if defined(UTMP_SUPPORT) || defined(HAVE_GETPWUID)
414 # include <pwd.h>
415 #endif
416 
417 
418 #ifdef UTMP_SUPPORT
419 # if defined(HAVE_UTMPX_H) && !defined(HAVE_UTMP_H)
420 #  define UTMP_FILENAME	UTMPX_FILE
421 # endif
422 # if !defined(UTMP_FILE) && defined(_PATH_UTMP)
423 #  define UTMP_FILE     _PATH_UTMP
424 # endif
425 # if !defined(UTMP_FILENAME) && defined(UTMP_FILE)
426 #  define UTMP_FILENAME UTMP_FILE
427 # endif
428 # define RXVT_UTMP_FILE	UTMP_FILENAME
429 #endif
430 
431 #ifdef WTMP_SUPPORT
432 # if defined(HAVE_WTMPX_H) && !defined(HAVE_WTMP_H)
433 #  define WTMP_FILENAME	WTMPX_FILE
434 # endif
435 # if !defined(WTMP_FILE) && defined(_PATH_WTMP)
436 #  define WTMP_FILE     _PATH_WTMP
437 # endif
438 # if !defined(WTMP_FILENAME) && defined(WTMP_FILE)
439 #  define WTMP_FILENAME WTMP_FILE
440 # endif
441 # define RXVT_WTMP_FILE	WTMP_FILENAME
442 #endif
443 
444 #ifdef _PATH_WTMPX
445 # define RXVT_WTMPX_FILE	_PATH_WTMPX
446 #endif
447 
448 #ifdef LASTLOG_SUPPORT
449 # ifdef OS_SOLARIS
450 #  define LASTLOG_FILE	    "/var/adm/lastlog"
451 # endif
452 # ifdef OS_OSF
453 #  define LASTLOG_FILE	    "/var/adm/lastlog"
454 # endif
455 # if !defined(LASTLOG_FILE) && defined(_PATH_LASTLOG)
456 #  define LASTLOG_FILE     _PATH_LASTLOG
457 # endif
458 # if !defined(LASTLOG_FILENAME) && defined(LASTLOG_FILE)
459 #  define LASTLOG_FILENAME LASTLOG_FILE
460 # endif
461 # define RXVT_LASTLOG_FILE  LASTLOG_FILENAME
462 #endif
463 
464 #ifdef UTMP_SUPPORT
465 # ifdef RXVT_UTMP_SYSV
466 #  ifndef USER_PROCESS
467 #   define USER_PROCESS	    (7)
468 #  endif
469 #  ifndef DEAD_PROCESS
470 #   define DEAD_PROCESS	    (8)
471 #  endif
472 # endif
473 #endif
474 
475 
476 
477 #ifdef NO_SECONDARY_SCREEN
478 # define NSCREENS	0
479 #else
480 # define NSCREENS	1
481 #endif
482 
483 
484 /*
485  * Let's try some interesting static program analysis tools. Refer to
486  * http://www.cs.umd.edu/~jfoster/cqual/
487  *
488  * Tainted defines the type of data that is fetchted from user input, which in
489  * turn is unsafe without checking. Untainted defines the type of data that is
490  * safe.
491  */
492 #ifdef __GNUC__
493 # define $tainted
494 # define $untainted
495 # define TAINTED    $tainted
496 # define UNTAINTED  $untainted
497 #else
498 # define TAINTED
499 # define UNTAINTED
500 #endif
501 
502 
503 /*
504 *********************************************************
505 ** The following are internal includes
506 *********************************************************
507 */
508 #include "debug.h"
509 #include "encoding.h"
510 #include "rxvtlib.h"
511 
512 
513 #ifdef GREEK_SUPPORT
514 # include "grkelot.h"
515 #endif
516 
517 #ifdef HAVE_MENUBAR
518 # include "menubar.h"
519 #endif
520 
521 #include "command.h"
522 #include "init.h"
523 
524 
525 #ifndef STDIN_FILENO
526 # define STDIN_FILENO	0
527 # define STDOUT_FILENO	1
528 # define STDERR_FILENO	2
529 #endif
530 
531 #if defined(HAVE_GRANTPT) && defined(HAVE_UNLOCKPT)
532 # if defined(PTYS_ARE_GETPT) || defined(PTYS_ARE_PTMX)
533 #  define NO_SETOWNER_TTYDEV
534 # endif
535 #endif
536 #if defined(OS_CYGWIN) || defined(PTYS_ARE_OPENPTY)
537 # define NO_SETOWNER_TTYDEV
538 #endif
539 
540 
541 /* Macros to check NULL pointers. This is solely to make the code more
542 ** readable/pretty
543 */
544 #define IS_NULL(PTR)	(NULL == (PTR))
545 #define NOT_NULL(PTR)	(NULL != (PTR))
546 #define SET_NULL(PTR)	((PTR) = NULL)
547 
548 /*
549  *****************************************************************************
550  * STRUCTURES AND TYPEDEFS
551  *****************************************************************************
552  */
553 struct rxvt_vars;	/* Later REDEFINED and typedef'd to rxvt_t */
554 struct rxvt_hidden;
555 
556 
557 /* Motif window hints, MwmHints.flags */
558 #define MWM_HINTS_FUNCTIONS     (1L << 0)
559 #define MWM_HINTS_DECORATIONS   (1L << 1)
560 #define MWM_HINTS_INPUT_MODE    (1L << 2)
561 #define MWM_HINTS_STATUS        (1L << 3)
562 /* bit definitions for MwmHints.functions */
563 #define MWM_FUNC_ALL            (1L << 0)
564 #define MWM_FUNC_RESIZE         (1L << 1)
565 #define MWM_FUNC_MOVE           (1L << 2)
566 #define MWM_FUNC_MINIMIZE       (1L << 3)
567 #define MWM_FUNC_MAXIMIZE       (1L << 4)
568 #define MWM_FUNC_CLOSE          (1L << 5)
569 /* bit definitions for MwmHints.decorations */
570 #define MWM_DECOR_ALL           (1L << 0)
571 #define MWM_DECOR_BORDER        (1L << 1)
572 #define MWM_DECOR_RESIZEH       (1L << 2)
573 #define MWM_DECOR_TITLE         (1L << 3)
574 #define MWM_DECOR_MENU          (1L << 4)
575 #define MWM_DECOR_MINIMIZE      (1L << 5)
576 #define MWM_DECOR_MAXIMIZE      (1L << 6)
577 /* bit definitions for MwmHints.inputMode */
578 #define MWM_INPUT_MODELESS                  0
579 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
580 #define MWM_INPUT_SYSTEM_MODAL              2
581 #define MWM_INPUT_FULL_APPLICATION_MODAL    3
582 #define PROP_MWM_HINTS_ELEMENTS             5
583 
584 
585 /*
586  * If we're using either the rxvt scrollbar or menu bars, keep the
587  * scrollColor resource.
588  */
589 #if defined(RXVT_SCROLLBAR) || defined(PLAIN_SCROLLBAR) || defined(HAVE_MENUBAR)
590 # define KEEP_SCROLLCOLOR 1
591 #else
592 # undef KEEP_SCROLLCOLOR
593 #endif
594 
595 
596 /*
597  * the 'essential' information for reporting Mouse Events
598  * pared down from XButtonEvent
599  */
600 struct mouse_event {
601     int             clicks;
602     Time            time;   /* milliseconds */
603     unsigned int    state;  /* key or button mask */
604     unsigned int    button; /* detail */
605 };
606 
607 #ifndef min
608 # define min(a,b)   (((a) < (b)) ? (a) : (b))
609 # define max(a,b)   (((a) > (b)) ? (a) : (b))
610 #endif
611 
612 #define MAX_IT(current, other)	if ((other) > (current)) (current) = (other)
613 #define MIN_IT(current, other)	if ((other) < (current)) (current) = (other)
614 #define SWAP_IT(one, two, typeof)				    \
615     {								    \
616 	typeof          swapittmp;				    \
617 	(swapittmp) = (one); (one) = (two); (two) = (swapittmp);    \
618     }
619 
620 #define BOUND_POSITIVE_INT16(val)				    \
621     (int16_t)( (val) <= 0 ? 0 : min( (val), (((uint16_t)-1)>>1) )  )
622 
623 /*
624  *****************************************************************************
625  * NORMAL DEFINES
626  *****************************************************************************
627  */
628 
629 #if defined (NO_OLD_SELECTION) && defined(NO_NEW_SELECTION)
630 # error if you disable both selection styles, how can you select, silly?
631 #endif
632 
633 #define APL_CLASS	"XTerm"	    /* class name */
634 #define APL_SUBCLASS	"Mrxvt"	/* also check resources under this name */
635 #define APL_NAME	"mrxvt"	/* normal name */
636 
637 /* COLORTERM, TERM environment variables */
638 #define COLORTERMENV	"rxvt"
639 #ifdef BACKGROUND_IMAGE
640 # define COLORTERMENVFULL COLORTERMENV "-xpm"
641 #else
642 # define COLORTERMENVFULL COLORTERMENV
643 #endif
644 #ifndef TERMENV
645 # define TERMENV	"xterm"
646 #endif
647 
648 #define TABTITLEENV	"MRXVT_TABTITLE="
649 
650 
651 #if defined (NO_MOUSE_REPORT) && !defined (NO_MOUSE_REPORT_SCROLLBAR)
652 # define NO_MOUSE_REPORT_SCROLLBAR
653 #endif
654 
655 #ifdef NO_RESOURCES
656 # undef USE_XGETDEFAULT
657 #endif
658 
659 /* now look for other badly set stuff */
660 
661 #if !defined (EACCESS) && defined(EAGAIN)
662 # define EACCESS EAGAIN
663 #endif
664 
665 #ifndef EXIT_SUCCESS	    /* missing from <stdlib.h> */
666 # define EXIT_SUCCESS	    0	/* exit function success */
667 # define EXIT_FAILURE	    1	/* exit function failure */
668 #endif
669 
670 #define menuBar_esc	    (10)
671 #define scrollBar_esc	    (30)
672 #define MENUBAR_MARGIN	    (2)	/* margin below text */
673 
674 /* width of scrollBar, menuBar shadow, must be 1 or 2 */
675 #ifdef HALFSHADOW
676 # define SHADOW		    (1)
677 #else
678 # define SHADOW		    (2)
679 #endif
680 
681 #define R_SB_ALIGN_CENTRE   (0)
682 #define R_SB_ALIGN_TOP	    (1)
683 #define R_SB_ALIGN_BOTTOM   (2)
684 
685 #define R_SB_UNKNOWN	    (-1)
686 #define R_SB_RXVT	    (0)
687 #define R_SB_NEXT	    (1)
688 #define R_SB_XTERM	    (2)
689 #define R_SB_SGI	    (3)
690 #define R_SB_PLAIN	    (4)
691 
692 #define SB_WIDTH_PLAIN	    (15)
693 #define SB_WIDTH_XTERM	    (15)
694 #define SB_WIDTH_RXVT	    (10)
695 #define SB_WIDTH_NEXT	    (17)
696 #define SB_WIDTH_SGI	    (16)
697 
698 
699 #ifdef NEXT_SCROLLBAR
700 /*
701 ** NeXT scrollbar definitions
702 */
703 #define NEXT_SB_WIDTH		(SB_WIDTH_NEXT)
704 #define NEXT_SB_PAD		(1)
705 #define NEXT_SB_BD_WIDTH	(1)
706 #define NEXT_BEVEL_ULEFT_WIDTH	(1)
707 #define NEXT_BEVEL_LRIGHT_WIDTH	(2)
708 #define NEXT_SB_LPAD		(NEXT_SB_PAD + NEXT_SB_BD_WIDTH)
709 #define NEXT_SB_MARGIN		(NEXT_SB_PAD<<1)
710 #define NEXT_SB_BTN_WIDTH	(NEXT_SB_WIDTH - NEXT_SB_MARGIN - NEXT_SB_BD_WIDTH)
711 /* button height */
712 #define NEXT_SB_BTN_HEIGHT	(NEXT_SB_BTN_WIDTH)
713 /* single button height */
714 #define NEXT_SB_SBTN_HEIGHT	(NEXT_SB_BTN_HEIGHT + NEXT_SB_PAD)
715 /* double button height */
716 #define NEXT_SB_DBTN_HEIGHT	(NEXT_SB_SBTN_HEIGHT<<1)
717 /* total button height */
718 #define NEXT_SB_TBTN_HEIGHT	(NEXT_SB_DBTN_HEIGHT + NEXT_SB_PAD)
719 #define NEXT_BEVEL_X		(NEXT_SB_LPAD)
720 #define NEXT_BTN_FACE_X		(NEXT_BEVEL_X + NEXT_BEVEL_ULEFT_WIDTH)
721 #define NEXT_SB_MIN_HEIGHT	(NEXT_SB_BTN_WIDTH - (NEXT_SB_PAD<<1))
722  /*
723   *    +-------------+
724   *    |             | <---< NEXT_SB_PAD
725   *    | ::::::::::: |
726   *    | ::::::::::: |
727   *   '''''''''''''''''
728   *   ,,,,,,,,,,,,,,,,,
729   *    | ::::::::::: |
730   *    | ::::::::::: |
731   *    |  +---------------< NEXT_BEVEL_ULEFT_WIDTH
732   *    |  | :::::::: |
733   *    |  V :::: vv-------< NEXT_BEVEL_LRIGHT_WIDTH
734   *    | +---------+ |
735   *    | | ......%%| |
736   *    | | ......%%| |
737   *    | | ..()..%%| |
738   *    | | ......%%| |
739   *    | | %%%%%%%%| |
740   *    | +---------+ | <.........................
741   *    |             | <---< NEXT_SB_PAD         :
742   *    | +---------+ | <-+..........            :---< NEXT_SB_TBTN_HEIGHT
743   *    | | ......%%| |   |         :            :
744   *    | | ../\..%%| |   |---< NEXT_SB_BTN_HEIGHT :
745   *    | | %%%%%%%%| |   |         :            :
746   *    | +---------+ | <-+         :            :
747   *    |             |             :            :
748   *    | +---------+ | <-+         :---< NEXT_SB_DBTN_HEIGHT
749   *    | | ......%%| |   |         :            :
750   *    | | ..\/..%%| |   |         :            :
751   *    | | %%%%%%%%| |   |---< NEXT_SB_SBTN_HEIGHT
752   *    | +---------+ |   |         :            :
753   *    |             |   |         :            :
754   *    +-------------+ <-+.........:............:
755   *    ^^|_________| :
756   *    ||     |      :
757   *    ||     +---< NEXT_SB_BTN_WIDTH
758   *    ||            :
759   *    |+------< NEXT_SB_PAD
760   *    |:            :
761   *    +----< NEXT_SB_BD_WIDTH
762   *     :            :
763   *     :............:
764   *           |
765   *           +---< NEXT_SB_WIDTH
766   */
767 #endif	/* NEXT_SCROLLBAR */
768 
769 
770 #ifdef SGI_SCROLLBAR
771 /*
772 ** SGI IRIX scrollbar definitions
773 */
774 #define SGI_ARROW_SOURCE_WIDTH	(14)
775 #define SGI_ARROW_SOURCE_HEIGHT	(14)
776 #define SGI_BEVEL_HI_WIDTH	(1)
777 #define SGI_BEVEL_LO_WIDTH	(1)
778 #define SGI_BEVEL_SIZE		(SGI_BEVEL_HI_WIDTH+SGI_BEVEL_LO_WIDTH)
779 
780 #define SGI_ARROW_WIDTH		(SB_WIDTH_SGI-(SGI_BEVEL_SIZE<<1))
781 #define SGI_ARROW_HEIGHT	(SGI_ARROW_SOURCE_HEIGHT)
782 
783 #define SGI_SB_BUTTON_HEIGHT	((SGI_BEVEL_SIZE<<1)+SGI_ARROW_WIDTH)
784 #define SGI_SB_BUTTONS_HEIGHT	(SGI_SB_BUTTON_HEIGHT<<1)
785 #endif
786 
787 
788 
789 /*
790  * Options for r->h->refresh_type.
791  */
792 #define NO_REFRESH	    (0)	    /* Window not visible at all! */
793 #define FAST_REFRESH	    (1<<0)  /* Fully exposed window */
794 #define SLOW_REFRESH	    (1<<1)  /* Partially exposed window */
795 #define SMOOTH_REFRESH	    (1<<2)  /* Do sync'ing to make it smooth */
796 #define REFRESH_BOUNDS	    (1<<3)  /* Refresh window borders */
797 #define CLIPPED_REFRESH	    (1<<4)  /* Honor clipping in GC while refreshing */
798 
799 /*
800  * Options for r->h->want_resize
801  */
802 #define FORCE_RESIZE	    (1U << 0)
803 #define FORCE_REFRESH	    (1U << 1)
804 
805 /*
806  * Continue undocumented mrxvt code
807  */
808 #define IGNORE		0
809 #define SAVE		's'
810 #define RESTORE		'r'
811 
812 /* special (internal) prefix for font commands */
813 #define FONT_CMD	'#'
814 #define FONT_DN		"#-"
815 #define FONT_UP		"#+"
816 
817 /* flags for rxvt_scr_gotorc() */
818 #define C_RELATIVE	1   /* col movement is relative */
819 #define R_RELATIVE	2   /* row movement is relative */
820 #define RELATIVE	(R_RELATIVE|C_RELATIVE)
821 
822 /* modes for rxvt_scr_insdel_chars(), rxvt_scr_insdel_lines() */
823 #define INSERT		-1  /* don't change these values */
824 #define DELETE		+1
825 #define ERASE		+2
826 
827 /* modes for rxvt_scr_page() - scroll page. used by scrollbar window */
828 enum page_dirn {
829     UP,
830     DN,
831     NO_DIR
832 };
833 
834 /* arguments for rxvt_scr_change_screen() */
835 #define PRIMARY	    (0)
836 #define SECONDARY   (1)
837 
838 enum {
839     SBYTE = 0,
840     WBYTE
841 };
842 
843 
844 #define RS_None		0   /* Normal */
845 
846 #if defined(TTY_256COLOR)
847 /* have at least 32 bits to use */
848 # define RS_fgMask	    0x000001FFu	/* 512 colors */
849 # define RS_bgMask	    0x0003FE00u	/* 512 colors */
850 # define RS_Bold	    0x00040000u	/* bold */
851 # define RS_Blink	    0x00080000u	/* blink */
852 # define RS_RVid	    0x00100000u	/* reverse video */
853 # define RS_Uline	    0x00200000u	/* underline */
854 # define RS_acsFont	    0x00400000u	/* ACS graphics char set */
855 # define RS_ukFont	    0x00800000u	/* UK character set */
856 #else
857 /* may only have 16 bits to use so squash them in */
858 # define RS_fgMask	    0x0000001Fu	/* 32 colors */
859 # define RS_bgMask	    0x000003E0u	/* 32 colors */
860 # define RS_Bold	    0x00000400u	/* bold */
861 # define RS_Blink	    0x00000800u	/* blink */
862 # define RS_RVid	    0x00001000u	/* reverse video */
863 # define RS_Uline	    0x00002000u	/* underline */
864 # define RS_acsFont	    0x00004000u	/* ACS graphics char set */
865 # define RS_ukFont	    0x00008000u	/* UK character set */
866 #endif
867 
868 #ifdef MULTICHAR_SET
869 # define RS_multi0	    0x10000000u	/* only multibyte characters */
870 # define RS_multi1	    0x20000000u	/* multibyte 1st byte */
871 /* multibyte 2nd byte */
872 # define RS_multi2	    (RS_multi0|RS_multi1)
873 /* multibyte mask */
874 # define RS_multiMask	    (RS_multi0|RS_multi1)
875 # define IS_MULTI1(R)	    (((R) & RS_multiMask) == RS_multi1)
876 # define IS_MULTI2(R)	    (((R) & RS_multiMask) == RS_multi2)
877 #else
878 # define RS_multiMask	    (0)
879 # define IS_MULTI1(r)	    (0)
880 # define IS_MULTI2(r)	    (0)
881 #endif
882 
883 
884 #define UNICODE_MASK 0x1fffffUL
885 
886 #if UNICODE3
887 # define COMPOSE_LO 0x40000000UL
888 # define COMPOSE_HI 0x400fffffUL
889 # define IS_COMPOSE(n) ((int32_t)(n) >= COMPOSE_LO)
890 #else
891 # define COMPOSE_LO 0xd800UL
892 # define COMPOSE_HI 0xf8ffUL /* dfff should be safer, but... */
893 # define IS_COMPOSE(n) (COMPOSE_LO <= (n) && (n) <= COMPOSE_HI)
894 #endif
895 
896 
897 #define RS_fontMask	    (RS_acsFont|RS_ukFont)
898 #define RS_baseattrMask	    (RS_Bold|RS_Blink|RS_RVid|RS_Uline)
899 #define RS_attrMask	    (RS_baseattrMask|RS_fontMask|RS_multiMask)
900 
901 #define Sel_none	    0	/* Not waiting */
902 #define Sel_normal	    0x01    /* normal selection */
903 #define Sel_incr	    0x02    /* incremental selection */
904 #define Sel_direct	    0x00
905 #define Sel_Primary	    0x01
906 #define Sel_Secondary	    0x02
907 #define Sel_Clipboard	    0x03
908 #define Sel_whereMask	    0x0f
909 #define Sel_CompoundText    0x10    /* last request was Compound */
910 
911 enum {
912     C0_NUL = 0x00,
913             C0_SOH, C0_STX, C0_ETX, C0_EOT, C0_ENQ, C0_ACK, C0_BEL,
914     C0_BS , C0_HT , C0_LF , C0_VT , C0_FF , C0_CR , C0_SO , C0_SI ,
915     C0_DLE, C0_DC1, C0_DC2, D0_DC3, C0_DC4, C0_NAK, C0_SYN, C0_ETB,
916     C0_CAN, C0_EM , C0_SUB, C0_ESC, C0_IS4, C0_IS3, C0_IS2, C0_IS1
917 };
918 #define CHAR_ST		0x9c	/* 0234 */
919 
920 
921 /*
922 ** Xwsh escape sequences: ESC P Ps .y Pt ESC
923 */
924 #define Xwsh_title		(1)
925 #define Xwsh_iconName		(3)
926 #define Xwsh_textColor		(4)
927 #define Xwsh_pageColor		(5)
928 #define Xwsh_selTextColor	(6)
929 #define Xwsh_selPageColor	(7)
930 #define Xwsh_cursorTextColor	(8)
931 #define Xwsh_cursorPageColor	(9)
932 #define Xwsh_halfIntColor	(10)
933 #define Xwsh_boldIntColor	(11)
934 #define Xwsh_bindStrKeyVal	(101) /* not implemented */
935 #define Xwsh_bindStrKeyFunc	(103) /* not implemented */
936 
937 
938 /*
939 ** XTerm Operating System Commands: ESC ] Ps;Pt (ST|BEL)
940 ** colour extensions by Christian W. Zuckschwerdt <zany@triq.net>
941 */
942 #define XTerm_name	    (0)
943 #define XTerm_iconName	    (1)
944 #define XTerm_title	    (2)
945 #define XTerm_Color	    (4)  /* change colors */
946 #define XTerm_Color_cursor  (12) /* change actual 'Cursor' color */
947 #define XTerm_Color_pointer (13) /* change actual 'Pointer' color */
948 #define XTerm_Color_RV	    (17) /* change actual 'Highlight' color */
949 #define XTerm_Color_BD	    (18) /* change actual 'Bold' color */
950 #define XTerm_Color_UL	    (19) /* change actual 'Underline' color */
951 #define XTerm_logfile	    (46) /* not implemented */
952 #define XTerm_font	    (50)
953 
954 
955 /*
956 ** rxvt extensions of XTerm OSCs: ESC ] Ps;Pt (ST|BEL)
957 */
958 #define XTerm_Menu	    (10) /* set menu item */
959 #define XTerm_Pixmap	    (20) /* new bg pixmap */
960 #define XTerm_restoreFG	    (39) /* change default fg color */
961 #define XTerm_restoreBG	    (49) /* change default bg color */
962 #define XTerm_dumpscreen    (55) /* dump scrollback and all screen */
963 
964 
965 /*
966  * mrxvt extensions of XTerm OSCs: ESC ] Ps;Pt (ST|BEL)
967  * Example: echo "\e]61;newtitle\a"
968  */
969 #define MRxvt_term	    (60) /* Change window title */
970 #define MRxvt_tab	    (61) /* change tab title */
971 #define MRxvt_tabterm	    (62) /* change tab and terminal title */
972 #define MRxvt_wformat	    (63) /* Change window title format */
973 #define MRxvt_tformat	    (64) /* Change tab title format */
974 /* #define MRxvt_newtab	    (63) ** DISABLED create a new tab with title */
975 /* #define MRxvt_prevtab    (64) ** DISABLED switch to previous tab */
976 /* #define MRxvt_nexttab    (65) ** DISABLED switch to next tab */
977 #define MRxvt_tint	    (66) /* change tinting color */
978 #define MRxvt_shade	    (67) /* change shade level */
979 #define MRxvt_encode	    (68) /* change encoding */
980 /* #define MRxvt_hide	    (69) ** DISABLED hide/show tabbar */
981 #define MRxvt_opacity	    (70) /* set opacity level */
982 /* #define MRxvt_tabbtn	    (71) ** DISABLED hide/show tabbar buttons */
983 #define MRxvt_tabfg	    (72) /* change active tab fg */
984 #define MRxvt_tabbg	    (73) /* change tabbar/active tab bg */
985 #define MRxvt_itabfg	    (74) /* change inactive tab fg */
986 #define MRxvt_itabbg	    (75) /* change inactive tab bg */
987 /* #define MRxvt_trans	    (76) ** DISABLED toggle transparency */
988 /* #define MRxvt_moveleft   (77) ** DISABLED move active tab to left */
989 /* #define MRxvt_moveright  (78) ** DISABLED move active tab to right */
990 /* #define MRxvt_verybold   (79) ** DISABLED toggle bold font for color text */
991 /* #define MRxvt_hotkeys    (80) ** DISABLED toggle hotkeys */
992 /* #define MRxvt_saveconfig (81) ** DISABLED save configuration */
993 #define MRxvt_bgfade	    (82) /* set bgfade degree (Obsolete) */
994 #define MRxvt_termenv	    (83) /* set TERMENV type */
995 /* #define MRxvt_closewin   (84) ** DISABLED Close all tabs and exit */
996 /* #define MRxvt_switchtab  (85) ** DISABLED Switch to tab N */
997 
998 
999 
1000 /* Words starting with `Color_' are colours.  Others are counts */
1001 /*
1002 ** The following comment is mostly obsolete since pixcolor_set was
1003 ** expanded:
1004 ** We're currently upto 30 colours.  Only 2 more available.  The
1005 ** PixColor and rendition colour usage should probably be decoupled
1006 ** on the unnecessary items, e.g. Color_pointer, but won't bother
1007 ** until we need to.  Also, be aware of usage in pixcolor_set
1008 */
1009 
1010 enum colour_list {
1011     Color_fg = 0,
1012     Color_bg,
1013     minCOLOR,		/* 2 */
1014     Color_Black = minCOLOR,
1015     Color_Red3,
1016     Color_Green3,
1017     Color_Yellow3,
1018     Color_Blue3,
1019     Color_Magenta3,
1020     Color_Cyan3,
1021     maxCOLOR,		/* minCOLOR + 7 */
1022 #ifndef NO_BRIGHTCOLOR
1023     Color_AntiqueWhite = maxCOLOR,
1024     minBrightCOLOR,	/* maxCOLOR + 1 */
1025     Color_Grey25 = minBrightCOLOR,
1026     Color_Red,
1027     Color_Green,
1028     Color_Yellow,
1029     Color_Blue,
1030     Color_Magenta,
1031     Color_Cyan,
1032     maxBrightCOLOR,	/* minBrightCOLOR + 7 */
1033     Color_White = maxBrightCOLOR,
1034 #else
1035     Color_White = maxCOLOR,
1036 #endif
1037 #ifdef TTY_256COLOR
1038     min256COLOR = Color_White + 1,
1039     max256COLOR = minCOLOR + 255,
1040 #endif
1041 #ifndef NO_CURSORCOLOR
1042     Color_cursor,
1043     Color_cursor2,
1044 #endif
1045     Color_pointer,
1046     Color_border,
1047     Color_ufbg,
1048 #ifndef NO_BOLD_UNDERLINE_REVERSE
1049     Color_BD,
1050     Color_UL,
1051     Color_RV,
1052 #endif
1053 #ifdef OPTION_HC
1054     Color_HC,
1055 #endif
1056 #ifdef KEEP_SCROLLCOLOR
1057     Color_scroll,
1058     Color_trough,
1059 #endif
1060 #if defined(BACKGROUND_IMAGE) || defined(TRANSPARENT)
1061 # ifdef TINTING_SUPPORT
1062     Color_tint,
1063 # endif
1064 #endif	/* BACKGROUND_IMAGE || TRANSPARENT */
1065     NRS_COLORS,		/* */
1066 #ifdef KEEP_SCROLLCOLOR
1067     Color_topShadow = NRS_COLORS,
1068     Color_bottomShadow,
1069     TOTAL_COLORS	/* upto 31 */
1070 #else
1071     TOTAL_COLORS = NRS_COLORS	/* */
1072 #endif
1073 };
1074 
1075 #ifdef TTY_256COLOR
1076 # define Color_Bits 9
1077 # define NPIXCLR_SETS	9   /* (256 + 14) bits / 32 bits */
1078 #else
1079 # define Color_Bits 5
1080 # define NPIXCLR_SETS	1   /* (16 + 14) bits / 32 bits */
1081 #endif
1082 #define NPIXCLR_BITS	32
1083 
1084 #define DEFAULT_RSTYLE	    (RS_None | (Color_fg) | (Color_bg<<Color_Bits))
1085 
1086 
1087 
1088 /*
1089  * Resource list
1090  */
1091 enum {
1092     Rs_display_name = 0,
1093     Rs_debug_masks,
1094     Rs_debug_level,
1095     Rs_container_window,
1096     Rs_term_name,
1097     Rs_iconName,
1098     Rs_geometry,
1099     Rs_color,
1100     _Rs_color = Rs_color + TOTAL_COLORS, /*+ 2 * MAX_PAGES - 1,*/
1101     Rs_font,
1102     _Rs_font = Rs_font + MAX_NFONTS - 1,
1103 #ifdef MULTICHAR_SET
1104     Rs_mfont,
1105     _Rs_mfont = Rs_mfont + MAX_NFONTS - 1,
1106     Rs_multichar_encoding,
1107 #endif
1108     Rs_name,
1109     Rs_title,
1110     Rs_maxTabWidth,
1111     Rs_minVisibleTabs,
1112 #if defined (BACKGROUND_IMAGE) || defined(HAVE_MENUBAR)
1113     Rs_path,
1114 #endif
1115 
1116 #ifdef BACKGROUND_IMAGE
1117     Rs_tabbarPixmap,	/* tabbar background pixmap */
1118     Rs_appIcon,		/* use pixmap as application icon */
1119 #endif
1120 
1121 #ifdef HAVE_MENUBAR
1122     Rs_menu,
1123 # ifdef BACKGROUND_IMAGE
1124     Rs_menubarPixmap,
1125 # endif
1126 #endif
1127 
1128 #ifndef NO_BOLDFONT
1129     Rs_boldFont,
1130     _Rs_boldFont = Rs_boldFont + MAX_NFONTS - 1,
1131 #endif
1132 #ifdef GREEK_SUPPORT
1133     Rs_greek_keyboard,
1134     Rs_greektoggle_key,
1135 #endif
1136 #ifdef XFT_SUPPORT
1137     Rs_xftfont,	/* Font name, family */
1138 # ifdef MULTICHAR_SET
1139     Rs_xftmfont,/* Multichar font name, family */
1140     Rs_xftmsz,	/* Multichar font size */
1141 # endif
1142     Rs_xftwt,	/* Font weight */
1143     Rs_xftBwt,	/* Bold font weight */
1144     Rs_xftst,	/* Font slant */
1145     Rs_xftsz,	/* Font size */
1146     Rs_xftwd,	/* Font width style */
1147     Rs_xftrgb,	/* Font sub-pixel order */
1148     Rs_xftpfn,	/* Propotionally spaced Xft font (for tabbar / menubar) */
1149     Rs_xftpsz,	/* Size of propotionally spaced Xft font */
1150 #endif
1151 #ifdef HAVE_SCROLLBARS
1152     Rs_scrollBar_align,
1153 # ifdef BACKGROUND_IMAGE
1154     Rs_scrollbarPixmap,
1155 # endif
1156 #endif	/* HAVE_SCROLLBARS */
1157     Rs_scrollBar_style,
1158 
1159     Rs_tabfg,	/* active tab foreground */
1160     Rs_tabbg,	/* active tab background */
1161     Rs_itabfg,	/* inactive tab foreground */
1162     Rs_itabbg,	/* inactive tab background */
1163 
1164     Rs_fade,	/* fade percentage */
1165 
1166 #ifdef TEXT_SHADOW
1167     Rs_textShadow,	/* text shadow color */
1168     Rs_textShadowMode,	/* text shadow color mode */
1169 #endif
1170 
1171     Rs_skipPages,	/* Number of pages to skip when jump scrolling */
1172     Rs_refreshLimit,	/* Number of chars to tolerate when refreshing */
1173 #ifdef TINTING_SUPPORT
1174     Rs_shade,	/* shade percentage */
1175     Rs_tint,	/* tinting color */
1176 #endif
1177 #ifdef TRANSPARENT
1178     Rs_bgRefreshInterval,
1179 #endif
1180 
1181     Rs_focusDelay,
1182 
1183 #ifndef NO_BELL
1184     Rs_bellCommand,
1185     Rs_vBellDuration,
1186 #endif
1187     Rs_monitorCommand,
1188     Rs_monitorTimeout,
1189     Rs_desktop,
1190 #ifndef NO_BACKSPACE_KEY
1191     Rs_backspace_key,
1192 #endif
1193 #ifndef NO_DELETE_KEY
1194     Rs_delete_key,
1195 #endif
1196     Rs_selectstyle,
1197 #ifdef PRINTPIPE
1198     Rs_print_pipe,
1199 #endif
1200 #ifdef USE_XIM
1201     Rs_preeditType,
1202     Rs_inputMethod,
1203 #endif
1204     Rs_opacity,		/* transluscent window opacity degree */
1205     Rs_opacityDegree,	/* opacity change degree */
1206 #ifndef NO_FRILLS
1207     Rs_ext_bwidth,
1208     Rs_int_bwidth,
1209 #endif
1210     Rs_scrollBar_thickness,
1211 #ifndef NO_LINESPACE
1212     Rs_lineSpace,
1213 #endif
1214     Rs_cutchars,
1215 #ifdef ACS_ASCII
1216     Rs_acs_chars,
1217 #endif
1218     Rs_modifier,
1219     Rs_confFile,
1220     Rs_answerbackstring,
1221     Rs_cursorBlinkInterval,
1222     Rs_pointerBlankDelay,
1223     Rs_smClientID,
1224     Rs_initProfiles,
1225     Rs_init_term_num,	    /* OBSOLETE */
1226 
1227     /*
1228      * Options for multiple profiles.
1229      */
1230 #ifdef BACKGROUND_IMAGE
1231     Rs_backgroundPixmap,/* terminal background pixmap for each tab */
1232     _Rs_backgroundPixmap = Rs_backgroundPixmap + MAX_PROFILES - 1,
1233 #endif
1234     Rs_tabtitle,	_Rs_tabtitle	= MAX_PROFILES - 1 + Rs_tabtitle,
1235     Rs_command,		_Rs_command	= MAX_PROFILES - 1 + Rs_command,
1236     Rs_saveLines,	_Rs_saveLines	= MAX_PROFILES - 1 + Rs_saveLines,
1237     Rs_foreground,	_Rs_foreground	= MAX_PROFILES - 1 + Rs_foreground,
1238     Rs_background,	_Rs_background	= MAX_PROFILES - 1 + Rs_background,
1239     Rs_cwd,		_Rs_cwd		= MAX_PROFILES - 1 + Rs_cwd,
1240     Rs_holdExit,	_Rs_holdExit	= MAX_PROFILES - 1 + Rs_holdExit,
1241     Rs_holdExitTxt,	_Rs_holdExitTxt = MAX_PROFILES - 1 + Rs_holdExitTxt,
1242     Rs_holdExitTtl,	_Rs_holdExitTtl = MAX_PROFILES - 1 + Rs_holdExitTtl,
1243     Rs_titleFormat,	_Rs_titleFormat = MAX_PROFILES - 1 + Rs_titleFormat,
1244     Rs_winTitleFormat,	_Rs_winTitleFormat = MAX_PROFILES - 1 + Rs_winTitleFormat,
1245 
1246     NUM_RESOURCES
1247 } ;
1248 
1249 enum {
1250     TIMEOUT_INCR = 0,
1251     NUM_TIMEOUTS
1252 } ;
1253 
1254 
1255 /*
1256 ** MUST sync with init.c:xa_names
1257 */
1258 enum {
1259     XA_COMPOUND_TEXT = 0,
1260     XA_UTF8_STRING,
1261     XA_TEXT,
1262     XA_MULTIPLE,
1263     XA_TARGETS,
1264     XA_TIMESTAMP,
1265     XA_VT_SELECTION,
1266     XA_INCR,
1267     XA_WMDELETEWINDOW,
1268     XA_NET_WM_DESKTOP,
1269     XA_WIN_WORKSPACE,
1270     XA_NET_WM_NAME,
1271     XA_NET_WM_ICON_NAME,
1272     XA_WM_CLIENT_LEADER,
1273     XA_NET_WM_WINDOW_OPACITY,
1274 #ifndef NO_FRILLS
1275     XA_NET_WM_PID,
1276 #endif
1277 #ifdef HAVE_X11_SM_SMLIB_H
1278     XA_SM_CLIENT_ID,
1279 #endif
1280 #ifdef USE_XIM
1281     XA_WM_LOCALE_NAME,
1282 #endif
1283 #ifdef TRANSPARENT
1284     XA_XROOTPMAPID,
1285     XA_XSETROOTID,
1286 #endif
1287 #ifdef OFFIX_DND	/* OffiX Dnd (drag 'n' drop) support */
1288     XA_DNDPROTOCOL,
1289     XA_DNDSELECTION,
1290 #endif		    /* OFFIX_DND */
1291     XA_CLIPBOARD,
1292     NUM_XA
1293 } ;
1294 
1295 /*
1296  * number of graphics points
1297  * divisible by 2 (num lines)
1298  * divisible by 4 (num rect)
1299  */
1300 #define	NGRX_PTS    1000
1301 
1302 /* DEC private modes */
1303 #define PrivMode_132		(1LU<<0)
1304 #define PrivMode_132OK		(1LU<<1)
1305 #define PrivMode_rVideo		(1LU<<2)
1306 #define PrivMode_relOrigin	(1LU<<3)
1307 #define PrivMode_Screen		(1LU<<4)
1308 #define PrivMode_Autowrap	(1LU<<5)
1309 #define PrivMode_aplCUR		(1LU<<6)
1310 #define PrivMode_aplKP		(1LU<<7)
1311 #define PrivMode_HaveBackSpace	(1LU<<8)
1312 #define PrivMode_BackSpace	(1LU<<9)
1313 #define PrivMode_ShiftKeys	(1LU<<10)
1314 #define PrivMode_VisibleCursor	(1LU<<11)
1315 #define PrivMode_MouseX10	(1LU<<12)
1316 #define PrivMode_MouseX11	(1LU<<13)
1317 #define PrivMode_scrollBar	(1LU<<14)
1318 #define PrivMode_menuBar	(1LU<<15)
1319 #define PrivMode_TtyOutputInh	(1LU<<16)
1320 #define PrivMode_Keypress	(1LU<<17)
1321 #define PrivMode_smoothScroll	(1LU<<18)
1322 #define PrivMode_vt52		(1LU<<19)
1323 /* too annoying to implement X11 highlight tracking */
1324 /* #define PrivMode_MouseX11Track       (1LU<<18) */
1325 
1326 #define PrivMode_mouse_report	(PrivMode_MouseX10|PrivMode_MouseX11)
1327 #define PrivMode(test,bit,page)			\
1328     if (test)					\
1329 	r->vts[page]->PrivateModes |= (bit);	\
1330     else					\
1331 	r->vts[page]->PrivateModes &= ~(bit)
1332 
1333 #ifdef ALLOW_132_MODE
1334 # define PrivMode_Default			 \
1335 (PrivMode_Autowrap|PrivMode_aplKP|PrivMode_ShiftKeys|PrivMode_VisibleCursor|PrivMode_132OK)
1336 #else
1337 # define PrivMode_Default			 \
1338 (PrivMode_Autowrap|PrivMode_ShiftKeys|PrivMode_VisibleCursor)
1339 /*
1340 (PrivMode_Autowrap|PrivMode_aplKP|PrivMode_ShiftKeys|PrivMode_VisibleCursor)
1341 */
1342 #endif
1343 
1344 
1345 #define XSCREEN		DefaultScreen(r->Xdisplay)
1346 #define XROOT		DefaultRootWindow(r->Xdisplay)
1347 
1348 #ifdef PREFER_24BIT
1349 # define XDEPTH		(r->Xdepth)
1350 # define XCMAP		(r->Xcmap)
1351 # define XVISUAL	(r->h->Xvisual)
1352 #else
1353 # ifdef DEBUG_DEPTH
1354 #  define XDEPTH	DEBUG_DEPTH
1355 # else
1356 #  define XDEPTH	DefaultDepth(r->Xdisplay, XSCREEN)
1357 #  define XCMAP		DefaultColormap(r->Xdisplay, XSCREEN)
1358 #  define XVISUAL	DefaultVisual(r->Xdisplay, XSCREEN)
1359 # endif
1360 #endif
1361 
1362 
1363 #define IMBUFSIZ	128 /* input modifier buffer sizes */
1364 #ifndef BUFSIZ
1365 # define BUFSIZ		4096
1366 #endif
1367 #define KBUFSZ		512 /* size of keyboard mapping buffer */
1368 
1369 /*
1370  *****************************************************************************
1371  * MACRO DEFINES
1372  *****************************************************************************
1373  */
1374 
1375 /* convert pixel dimensions to row/column values.  Everything as int32_t */
1376 #define Pixel2Width(x)	    ((int32_t)(x) / (int32_t)r->TermWin.fwidth)
1377 #define Pixel2Height(y)	    ((int32_t)(y) / (int32_t)r->TermWin.fheight)
1378 #define Width2Pixel(n)	    ((int32_t)(n) * (int32_t)r->TermWin.fwidth)
1379 #define Height2Pixel(n)	    ((int32_t)(n) * (int32_t)r->TermWin.fheight)
1380 #define Pixel2Col(x)	    Pixel2Width((int32_t)(x) - (int32_t)r->TermWin.int_bwidth)
1381 #define Pixel2Row(y)	    Pixel2Height((int32_t)(y) - (int32_t)r->TermWin.int_bwidth)
1382 #define Col2Pixel(col)	    ((int32_t)Width2Pixel(col) + (int32_t)r->TermWin.int_bwidth)
1383 #define Row2Pixel(row)	    ((int32_t)Height2Pixel(row) + (int32_t)r->TermWin.int_bwidth)
1384 
1385 /*
1386 #define TermWin_TotalWidth()	((int32_t)r->TermWin.width  + 2 * (int32_t)r->TermWin.int_bwidth)
1387 #define TermWin_TotalHeight()	((int32_t)r->TermWin.height + 2 * (int32_t)r->TermWin.int_bwidth)
1388 */
1389 
1390 /* how to build & extract colors and attributes */
1391 #define GET_BASEFG(x)	    (((x) & RS_fgMask))
1392 #define GET_BASEBG(x)	    (((x) & RS_bgMask)>>Color_Bits)
1393 #if 0 /* Was ifndef NO_BRIGHTCOLOR */
1394 # define GET_FGCOLOR(x)						    \
1395     ((((x) & RS_Bold) == 0		    	    		    \
1396       || GET_BASEFG(x) < minCOLOR		    		    \
1397       || GET_BASEFG(x) >= minBrightCOLOR)	    		    \
1398      ? GET_BASEFG(x)				    		    \
1399      : (GET_BASEFG(x) + (minBrightCOLOR - minCOLOR)))
1400 # define GET_BGCOLOR(x)						    \
1401     ((((x) & RS_Blink) == 0		    			    \
1402       || GET_BASEBG(x) < minCOLOR				    \
1403       || GET_BASEBG(x) >= minBrightCOLOR)			    \
1404      ? GET_BASEBG(x)						    \
1405      : (GET_BASEBG(x) + (minBrightCOLOR - minCOLOR)))
1406 #else
1407 # define GET_FGCOLOR(x)	    GET_BASEFG(x)
1408 # define GET_BGCOLOR(x)	    GET_BASEBG(x)
1409 #endif
1410 
1411 #define GET_ATTR(x)	(((x) & RS_attrMask))
1412 #define GET_BGATTR(x)				\
1413     (((x) & RS_RVid) ? (((x) & (RS_attrMask & ~RS_RVid))	\
1414 	    | (((x) & RS_fgMask)<<Color_Bits))	    \
1415 	     : ((x) & (RS_attrMask | RS_bgMask)))
1416 #define SET_FGCOLOR(x,fg)   (((x) & ~RS_fgMask)  | (fg))
1417 #define SET_BGCOLOR(x,bg)   (((x) & ~RS_bgMask)  | ((bg)<<Color_Bits))
1418 #define SET_ATTR(x,a)	    (((x) & ~RS_attrMask)| (a))
1419 
1420 #define SET_PIXCOLOR(h, x)	((h)->pixcolor_set[(x) / NPIXCLR_BITS] |= (1 << ((x) % NPIXCLR_BITS)))
1421 #define ISSET_PIXCOLOR(h, x)	((h)->pixcolor_set[(x) / NPIXCLR_BITS] & (1 << ((x) % NPIXCLR_BITS)))
1422 
1423 #define scrollbar_isMotion()	(r->scrollBar.state == 'm')
1424 #define scrollbar_isUp()	(r->scrollBar.state == 'U')
1425 #define scrollbar_isDn()	(r->scrollBar.state == 'D')
1426 #define scrollbar_isUpDn()	isupper ((int) r->scrollBar.state)
1427 
1428 #define scrollbar_setIdle()	r->scrollBar.state = (char) 1
1429 #define scrollbar_setMotion()	r->scrollBar.state = 'm'
1430 #define scrollbar_setUp()	r->scrollBar.state = 'U'
1431 #define scrollbar_setDn()	r->scrollBar.state = 'D'
1432 
1433 
1434 #define scrollbarnext_dnval()	    (r->scrollBar.end + (r->scrollBar.width + 1))
1435 #define scrollbarnext_upButton(y)   ((y) > r->scrollBar.end \
1436 		     && (y) <= scrollbarnext_dnval())
1437 #define scrollbarnext_dnButton(y)   ((y) > scrollbarnext_dnval())
1438 
1439 #define scrollbarrxvt_upButton(y)   ((y) < r->scrollBar.beg)
1440 #define scrollbarrxvt_dnButton(y)   ((y) > r->scrollBar.end)
1441 
1442 
1443 #define scrollbarsgi_dnval()	    (r->scrollBar.end + 1)
1444 #define scrollbarsgi_upButton(y)    ((y) < r->scrollBar.beg)
1445 #define scrollbarsgi_dnButton(y)    ((y) > r->scrollBar.end)
1446 
1447 #ifdef NEXT_SCROLLBAR
1448 # define SCROLLNEXT_MINHEIGHT	    (NEXT_SB_MIN_HEIGHT)
1449 #else
1450 # define SCROLLNEXT_MINHEIGHT	    (0)
1451 #endif	/* NEXT_SCROLLBAR */
1452 #ifdef SGI_SCROLLBAR
1453 # define SCROLLSGI_MINHEIGHT	    (10)
1454 #else
1455 # define SCROLLSGI_MINHEIGHT	    (0)
1456 #endif	/* SGI_SCROLLBAR */
1457 #define SCROLL_MINHEIGHT	    (10)
1458 #define scrollbar_minheight()	(   \
1459     (r->scrollBar.style == R_SB_NEXT) ? SCROLLNEXT_MINHEIGHT :	\
1460     (r->scrollBar.style == R_SB_SGI) ? SCROLLSGI_MINHEIGHT :	\
1461 	SCROLL_MINHEIGHT)
1462 #define scrollbar_above_slider(y)   ((y) < r->scrollBar.top)
1463 #define scrollbar_below_slider(y)   ((y) > r->scrollBar.bot)
1464 #define scrollbar_position(y)	    ((y) - r->scrollBar.beg)
1465 #define scrollbar_size()	(r->scrollBar.end - r->scrollBar.beg \
1466 		     - scrollbar_minheight())
1467 
1468 
1469 
1470 #ifdef BACKGROUND_IMAGE
1471 # define XPMClearArea(a, b, c, d, e, f, g)  XClearArea((a), (b), (c), (d), (e), (f), (g))
1472 #else
1473 # define XPMClearArea(a, b, c, d, e, f, g)
1474 #endif
1475 
1476 #ifndef STRICT_FONT_CHECKING
1477 # define rxvt_get_fontwidest(font)  ((font)->max_bounds.width)
1478 #endif
1479 
1480 #define rxvt_Gr_ButtonPress(x,y)    rxvt_Gr_ButtonReport (r, 'P',(x),(y))
1481 #define rxvt_Gr_ButtonRelease(x,y)  rxvt_Gr_ButtonReport (r, 'R',(x),(y))
1482 
1483 
1484 /*
1485  * When sending a client message to an EWMH compatible window manager
1486  * e.g. calls to ewmh_message().
1487  */
1488 #define _NET_WM_STATE_REMOVE	0
1489 #define _NET_WM_STATE_ADD	1
1490 #define _NET_WM_STATE_TOGGLE	2
1491 
1492 /* Values for holdOption */
1493 #define HOLD_ALWAYSBIT		(1u << 0)
1494 #define HOLD_NORMALBIT		(1u << 1)
1495 #define HOLD_STATUSBIT		(1u << 2)
1496 
1497 /*
1498  *****************************************************************************
1499  * VARIABLES
1500  *****************************************************************************
1501  */
1502 struct rxvt_hidden {
1503     unsigned char   BOOLVAR( want_clip_refresh, 1),	/* Only refresh region
1504 							   specified by
1505 							   refreshRegion */
1506 		    BOOLVAR( want_resize, 2),		/* perform resize even
1507 							   if window size has
1508 							   not changed */
1509 #if defined(BACKGROUND_IMAGE) || defined(TRANSPARENT)
1510 		    BOOLVAR( am_transparent, 1),	/* is transparent */
1511 		    BOOLVAR( am_pixmap_trans, 1),	/* transparency without
1512 							   known root pixmap */
1513 # endif
1514 #ifdef CURSOR_BLINK
1515 		    BOOLVAR( hidden_cursor, 1),
1516 #endif
1517 		    BOOLVAR( hate_those_clicks, 1),	/* a.k.a. keep mark
1518 							   position */
1519 		    BOOLVAR( num_scr_allow, 1),
1520 		    BOOLVAR( bypass_keystate, 1);
1521 
1522 #ifdef TRANSPARENT
1523     unsigned char   BOOLVAR( want_full_refresh, 1);	/* awaiting full screen
1524 							   refresh, including
1525 							   borders. */
1526 #endif
1527 
1528     Region	    refreshRegion;			/* Region for
1529 							   CLIPPED_REFRESH */
1530 
1531     int		    skip_pages,				/* Number of pages to
1532 							   skip when jump
1533 							   scrolling */
1534 		    refresh_limit;			/* Request screen
1535 							   refresh only if ATAB
1536 							   produces <= these
1537 							   many chars */
1538     unsigned char   BOOLVAR( refresh_type, 5),
1539 #ifdef META8_OPTION
1540 		    meta_char,				/* Alt-key prefix */
1541 #endif
1542 		    scrollbar_align,
1543 		    selection_wait,
1544 		    selection_type;
1545 
1546 #ifdef GREEK_SUPPORT
1547     short	    greek_mode;				/* Greek keyboard
1548 							   mode */
1549     KeySym	    ks_greekmodeswith;
1550 #endif
1551 
1552     uint16_t	    prev_ncol,
1553 		    prev_nrow;				/* screen: previous
1554 							   number of columns and
1555 							   rows */
1556     uint32_t	    pixcolor_set[NPIXCLR_SETS];
1557 
1558 #ifdef SELECTION_SCROLLING
1559     int		    scroll_selection_delay,
1560 		    scroll_selection_lines;
1561     enum page_dirn  scroll_selection_dir;
1562     int		    selection_save_x,
1563 		    selection_save_y,
1564 		    selection_save_state,
1565 		    pending_scroll_selection;
1566 #endif
1567 
1568     int		    csrO,				/* Hops - csr offset in
1569 							   thumb/slider to give
1570 							   proper Scroll
1571 							   behaviour */
1572 #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1573 		    scroll_arrow_delay,
1574 #endif
1575 #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1576 		    mouse_slip_wheel_delay,
1577 		    mouse_slip_wheel_speed,
1578 #endif
1579 		    max_skipped_pages,
1580 		    fnum,				/* logical font
1581 							   number */
1582 		    last_bot,				/* scrollbar last bottom
1583 							   position */
1584 		    last_top,				/* scrollbar last top
1585 							   position */
1586 		    last_state,				/* scrollbar last
1587 							   state */
1588 		    scroller_len,
1589 		    currmaxcol,
1590 		    window_vt_x,
1591 		    window_vt_y;
1592 # ifdef POINTER_BLANK
1593     int		    pointerBlankDelay;
1594 # endif
1595 
1596     unsigned char   BOOLVAR( allowedxerror, 1);		/* Be silent when
1597 							   reporting XErrors */
1598     int		    xerror_return;			/* ErrorCode of caught
1599 							   XError */
1600 
1601     unsigned int    ModMetaMask,
1602 		    ModNumLockMask;
1603 #ifndef NO_BRIGHTCOLOR
1604     unsigned long   colorfgbg;
1605 #endif
1606 
1607     gid_t	    ttygid;
1608 
1609 #ifdef PREFER_24BIT
1610     Visual*	    Xvisual;
1611 #endif
1612 
1613     Atom	    xa[NUM_XA];
1614 
1615     Time            selection_time,
1616                     selection_request_time;
1617 
1618     Cursor          bar_pointer;
1619 #ifdef POINTER_BLANK
1620     Cursor          blank_pointer;
1621 #endif
1622 
1623 #ifndef NO_BACKSPACE_KEY
1624     const char*	    key_backspace;
1625 #endif
1626 #ifndef NO_DELETE_KEY
1627     const char*	    key_delete;
1628 #endif
1629 #ifdef USE_XIM
1630     XIC		    Input_Context;
1631     XIMStyle	    input_style;
1632     int		    event_type;
1633 #endif
1634     struct mouse_event	MEvent;
1635     row_col_t	    oldcursor;
1636 #ifdef MULTICHAR_SET
1637     signed int	    oldcursormulti;
1638 #endif
1639     void	    (*multichar_decode)(unsigned char *str, int len);
1640 #ifdef HAVE_MENUBAR
1641     menu_t*	    ActiveMenu;				/* currently active
1642 							   menu */
1643     menu_t*	    BuildMenu;				/* the menu currently
1644 							   being built */
1645     menu_t*	    popupMenu[3];			/* Menus to popup on
1646 							   ctrl clicks */
1647 
1648     unsigned char   BOOLVAR( showingMenu, 1);		/* The type of menu
1649 							   currently being
1650 							   shown */
1651 
1652     bar_t	    MenuBar;
1653     int		    Arrows_x;
1654 #endif
1655 #ifdef CURSOR_BLINK
1656     long	    blinkInterval;
1657     struct timeval  lastcursorchange;
1658 #endif
1659 #ifdef POINTER_BLANK
1660     struct timeval  lastmotion;
1661 #endif
1662 #ifdef TRANSPARENT
1663     unsigned long   bgRefreshInterval;
1664     struct timeval  lastCNotify;			/* Time of the last
1665 							   CNotify event */
1666 #endif
1667     struct timeval  timeout[NUM_TIMEOUTS];
1668 
1669     /*
1670      * These three don't need to be kept but do so to placate some memory
1671      * checkers
1672      */
1673     char*	    env_windowid;			/* environmental
1674 							   variable WINDOWID */
1675     char*	    env_display;			/* environmental
1676 							   variable DISPLAY */
1677     char*	    env_term;				/* environmental
1678 							   variable TERM */
1679     char*	    env_tabtitle;			/* environmental
1680 							   variable
1681 							   MRXVT_TABTITLE*/
1682     char*	    env_colorfgbg;
1683     char*	    buffer;
1684     char*	    locale;
1685 
1686 #if 0
1687     unsigned char*  v_buffer;
1688     unsigned char*  v_bufstr;
1689     unsigned char*  v_bufptr;
1690     unsigned char*  v_bufend;
1691 #endif
1692 
1693     char*	    newfont[MAX_NFONTS];
1694     const char*	    rs[NUM_RESOURCES];
1695 
1696 #if 0    /* command input buffering */
1697     unsigned char*  cmdbuf_ptr, *cmdbuf_endp;
1698     unsigned char   cmdbuf_base[BUFSIZ];
1699     unsigned char   kbuf[KBUFSZ];
1700 #endif
1701 
1702 #ifdef TRANSPARENT
1703     Pixmap	rootPixmap;				/* Pixmap ID of the root
1704 							   pixmap */
1705     unsigned	rpWidth,				/* Dimensions of the
1706 							   root pixmap */
1707 		rpHeight;
1708     XRectangle	prevPos;				/* Previous onscreen
1709 							   position */
1710     Bool	bgGrabbed;				/* whether the bg was
1711 							   succesfully grabbed
1712 							   at prevPos */
1713 #endif
1714 };
1715 
1716 #ifndef __attribute__
1717 # ifdef __GNUC__
1718 #  if (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || (__GNUC__ < 2)
1719 #   define __attribute__(x)
1720 #  endif
1721 # endif
1722 # define __attribute__(x)
1723 #endif
1724 
1725 /*
1726  *****************************************************************************
1727  * PROTOTYPES
1728  *****************************************************************************
1729  */
1730 #define __PROTO(p)  p
1731 #include "protos.h"
1732 
1733 #ifdef OUR_STRINGS
1734 # define MEMSET(x, y, z)	ma_memset((x), (y), (size_t)(z))
1735 # define MEMCPY(x, y, z)	ma_memcpy((void *)(x), (const void *)(y), (z))
1736 # define MEMMOVE(x, y, z)	ma_memmove((void *)(x), (const void *)(y), (z))
1737 # define STRCASECMP(x, y)	ma_strcasecmp((x), (y))
1738 # define STRNCASECMP(x, y, z)	ma_strncasecmp((x), (y), (z))
1739 # define STRCPY(x, y)		ma_strcpy((char *)(x), (const char *)(y))
1740 # define STRNCPY(x, y, z)	ma_strncpy((char *)(x), (const char *)(y), (z))
1741 # define STRCMP(x, y)		ma_strcmp((const char *)(x), (const char *)(y))
1742 # define STRNCMP(x, y, z)	ma_strncmp((const char *)(x), (const char *)(y), (z))
1743 # define STRCAT(x, y)		ma_strcat((char *)(x), (const char *)(y))
1744 # define STRNCAT(x, y, z)	ma_strncat((char *)(x), (const char *)(y), (z))
1745 # define STRDUP(x)		ma_strdup((const char *)(x))
1746 # define STRNDUP(x, z)		ma_strndup((const char TAINTED *)(x), (size_t) (z))
1747 # define STRLEN(x)		ma_strlen((const char *)(x))
1748 # define STRCHR(x, y)		ma_strchr((const char *)(x), (int)(y))
1749 # define STRRCHR(x, y)		ma_strrchr((const char *)(x), (int)(y))
1750 
1751 #else /* OUR_STRINGS */
1752 
1753 # define MEMSET(x, y, z)	memset((x), (y), (size_t)(z))
1754 # define MEMCPY(x, y, z)	memcpy((void *)(x), (const void *)(y), (z))
1755 # define MEMMOVE(x, y, z)	memmove((void *)(x), (const void *)(y), (z))
1756 # define STRCASECMP(x, y)	strcasecmp((x), (y))
1757 # define STRNCASECMP(x, y, z)	strncasecmp((x), (y), (z))
1758 # define STRCPY(x, y)		strcpy((char *)(x), (const char *)(y))
1759 # define STRNCPY(x, y, z)	strncpy((char *)(x), (const char *)(y), (z))
1760 # define STRCMP(x, y)		strcmp((const char *)(x), (const char *)(y))
1761 # define STRNCMP(x, y, z)	strncmp((const char *)(x), (const char *)(y), (z))
1762 # define STRCAT(x, y)		strcat((char *)(x), (const char *)(y))
1763 # define STRLEN(x)		strlen((const char *)(x))
1764 # define STRNCAT(x, y, z)	strncat((char *)(x), (const char *)(y), (z))
1765 
1766 /* if use our own malloc function, we must NOT use system provided
1767  * strdup or strndup because we want to free the memory allocated
1768  * by strdup/strndup using our free function
1769  */
1770 # if defined(HAVE_STRDUP) && !defined(OUR_MALLOC)
1771 #  define STRDUP(x)		strdup((const char *)(x))
1772 # else
1773 #  define STRDUP(x)		ma_strdup((const char *)(x))
1774 # endif
1775 
1776 # if defined(HAVE_STRNDUP) && !defined(OUR_MALLOC)
1777 #  define STRNDUP(x, z)		strndup((const char TAINTED *)(x), (size_t) (z))
1778 # else
1779 #  define STRNDUP(x, z)		ma_strndup((const char TAINTED *)(x), (size_t) (z))
1780 # endif
1781 
1782 # ifdef HAVE_STRCHR
1783 #  define STRCHR(x, y)		strchr((const char *)(x), (int)(y))
1784 # else
1785 #  define STRCHR(x, y)		ma_strchr((const char *)(x), (int)(y))
1786 # endif
1787 
1788 # ifdef HAVE_STRRCHR
1789 #  define STRRCHR(x, y)		strrchr((const char *)(x), (int)(y))
1790 # else
1791 #  define STRRCHR(x, y)		ma_strrchr((const char *)(x), (int)(y))
1792 # endif
1793 #endif	/* OUR_STRINGS */
1794 
1795 # define STRSTR(x, y)		strstr((const char *)(x), (const char*)(y))
1796 /*
1797  * strcasestr is not provided by Cygwin's libraries, so we have to check for it
1798  * here. Thanks to Teun Burgers for pointing this out.
1799  */
1800 # ifdef HAVE_STRCASESTR
1801 #  define STRCASESTR( x, y)	strcasestr( (x), (y) )
1802 # else
1803 #  define STRCASESTR( x, y)	ma_strcasestr( (x), (y))
1804 # endif
1805 
1806 
1807 #define TWIN_WIDTH(R)	((R)->szHint.width)
1808 #define TWIN_HEIGHT(R)	((R)->szHint.height)
1809 #define VT_WIDTH(R)	((R)->szHint.width - \
1810 	(R)->szHint.base_width + 2*(R)->TermWin.int_bwidth)
1811 #define VT_HEIGHT(R)	((R)->szHint.height - \
1812 	(R)->szHint.base_height + 2*(R)->TermWin.int_bwidth)
1813 /*
1814 #define TWIN_WIDTH(R)	\
1815     ((R)->szHint.width - 2*(R)->TermWin.int_bwidth)
1816 #define TWIN_HEIGHT(R)	\
1817     ((R)->szHint.height - 2*(R)->TermWin.int_bwidth)
1818 #define VT_WIDTH(R)	\
1819     ((R)->szHint.width - (R)->szHint.base_width)
1820 #define VT_HEIGHT(R)	\
1821     ((R)->szHint.height - (R)->szHint.base_height)
1822 */
1823 
1824 
1825 #ifndef XTERM_COLOR_CHANGE
1826 # define rxvt_set_window_color(r, page, idx, color) ()
1827 #endif
1828 
1829 /* This comes last */
1830 /*
1831 #ifdef DEBUG_malloc
1832 # include "dmalloc.h"
1833 #endif
1834 */
1835 
1836 #endif		    /* __RXVT_H__ */
1837 /*----------------------- end-of-file (H source) -----------------------*/
1838