File: rxvt.h

package info (click to toggle)
mrxvt 0.5.4-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 3,056 kB
  • ctags: 3,446
  • sloc: ansic: 30,620; sh: 3,345; makefile: 294; perl: 198
file content (1833 lines) | stat: -rw-r--r-- 50,571 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
/*--------------------------------*-H-*---------------------------------*
 * File:    rxvt.h
 *----------------------------------------------------------------------*
 *
 * All portions of code are copyright by their respective author/s.
 * Copyright (c) 1997-2001   Geoff Wing <gcw@pobox.com>
 * Copyright (c) 2003-2004   Marc Lehmann <pcg@goof.com>
 * Copyright (c) 2004        Terry Griffin <griffint@pobox.com>
 * Copyright (c) 2005        Teun Burgers <burgers@ecn.nl>
 * Copyright (c) 2004-2005   Jingmin Zhou <jimmyzhou@users.sourceforge.net>
 * Copyright (c) 2005-2006   Gautam Iyer <gi1242@users.sourceforge.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *----------------------------------------------------------------------*/

#ifndef __RXVT_H__	/* include once only */
#define __RXVT_H__

#include "../config.h"
#include "feature.h"


/*
 *****************************************************************************
 * SYSTEM HACKS
 *****************************************************************************
 */
/* Consistent defines - please report on the necessity
 * @ Unixware: defines (__svr4__)
 */
#if defined (SVR4) && !defined (OS_SVR4)
# define OS_SVR4
#endif
 /*
#if defined (sun) && !defined (__sun__)
# define __sun__
#endif
*/

#ifdef _SCO_DS
# define ALL_NUMERIC_PTYS
#endif


#include <stdio.h>
#include <stdint.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>

#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif

#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

#ifdef HAVE_ASSERT_H
# include <assert.h>
#endif

#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif

#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif

#if defined(HAVE_STRING_H) && !defined(OUR_STRINGS)
# include <string.h>
#endif

#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif

#ifdef HAVE_WCHAR_H
# if defined(OS_OPENBSD) && (OS_OPENBSD_REL < 39)
typedef unsigned int    _our_wint_t;
typedef struct {
    int __count;
    union {
	_our_wint_t __wch;
	char	    __wchb[4]
    } __value;
} mbstate_t;
# endif /* defined(OS_OPENBSD) &&... */
# include <wchar.h>
#endif

#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif

#if defined(OS_SOLARIS) && defined(__SVR4)
# include <sys/strredir.h>
#endif

#ifdef OS_SOLARIS
# include <sys/byteorder.h>
#endif

#ifdef OS_SOLARIS
# include <sys/int_types.h>
# undef HAVE_SYS_IOCTL_H
#endif

#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif

#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif

#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif

#if defined(PTYS_ARE_PTMX) && defined(HAVE_SYS_STROPTS_H)
# include <sys/stropts.h>   /* for I_PUSH */
#endif

#if defined(PTYS_ARE_PTMX) && !defined(OS_CYGWIN)
# include <sys/resource.h>
# define _NEW_TTY_CTRL	    /* get proper definition in <termios.h> */
#endif

#ifdef HAVE_TIME_H
# include <time.h>
#endif

#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif

#ifdef HAVE_SYS_TIMES_H
# include <sys/times.h>
#endif

#ifdef HAVE_SYS_STRREDIR_H
# include <sys/strredir.h>
#endif

#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif

#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif

#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif

#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif

#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif

#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif

#ifdef HAVE_NET_IF_ARP_H
# include <net/if_arp.h>
#endif

#ifdef HAVE_PTY_H
# include <pty.h>
#endif

#ifdef OS_DARWIN
# include <util.h>
#endif

#ifdef OS_QNX
# include <process.h>
# include <sys/utsname.h>
# define ut_name    ut_user
#endif

#ifdef TTY_GID_SUPPORT
# include <grp.h>
#endif

#ifdef HAVE_TERMIOS_H
# include <termios.h>
typedef struct termios ttymode_t;
#else
# ifdef HAVE_SGTTY_H
#  include <sgtty.h>
# endif
typedef struct {
    struct sgttyb   sg;
    struct tchars   tc;
    struct ltchars  lc;
    int             line;
    int             local;
} ttymode_t;
#endif


# include <X11/Xlib.h>
# include <X11/X.h>
# include <X11/Xutil.h>
# include <X11/Xlibint.h>
# include <X11/cursorfont.h>
# include <X11/keysym.h>
# include <X11/keysymdef.h>
# include <X11/Xmd.h>
# include <X11/Xatom.h>
# include <X11/Xresource.h>

/*
 * We really should include openmotif-X.X/Xm/MwmUtil.h, but that will add
 * openmotif as a dependency. We dont' really need it, except to set WM hints,
 * thus this ugly hack.
 */
typedef struct {
    int	flags;
    int	functions;
    int	decorations;
    int	input_mode;
    int	status;
} MWMHints;
# ifdef HAVE_X11_SM_SMLIB_H
#  include <X11/SM/SMlib.h>
# endif

/* Macros to check X Window IDs. Notice that we can use only one macro
** to check all different type of IDs such as Window and Pixmap. But it
** lose the point that we can possibly check the type of those IDs.
*/
#undef IS_WIN
#undef NOT_WIN
#undef UNSET_WIN
#define IS_WIN(WINDOW_ID)   \
    (None != (WINDOW_ID))
#define NOT_WIN(WINDOW_ID)  \
    (None == (WINDOW_ID))
#define UNSET_WIN(WINDOW_ID)	\
    ((WINDOW_ID) = None)

#undef IS_PIXMAP
#undef NOT_PIXMAP
#undef UNSET_PIXMAP
#define IS_PIXMAP(PIXMAP_ID)	\
    (None != (PIXMAP_ID))
#define NOT_PIXMAP(PIXMAP_ID)	\
    (None == (PIXMAP_ID))
#define UNSET_PIXMAP(PIXMAP_ID)	\
    ((PIXMAP_ID) = None)

#undef IS_ATOM
#undef NOT_ATOM
#undef UNSET_ATOM
#define IS_ATOM(ATOM_ID)    \
    (None != (ATOM_ID))
#define NOT_ATOM(ATOM_ID)   \
    (None == (ATOM_ID))
#define UNSET_ATOM(ATOM_ID) \
    ((ATOM_ID) = None)

#undef IS_GC
#undef NOT_GC
#undef UNSET_GC
#define IS_GC(GC_ID)	\
    (None != (GC_ID))
#define NOT_GC(GC_ID)	\
    (None == (GC_ID))
#define UNSET_GC(GC_ID)	\
    ((GC_ID) = None)

#undef IS_CURSOR
#undef NOT_CURSOR
#undef UNSET_CURSOR
#define IS_CURSOR(CURSOR_ID)	\
    (None != (CURSOR_ID))
#define NOT_CURSOR(CURSOR_ID)	\
    (None == (CURSOR_ID))
#define UNSET_CURSOR(CURSOR_ID)	\
    ((CURSOR_ID) = None)

#undef IS_REGION
#undef NOT_REGION
#undef UNSET_REGION
#define IS_REGION(REGION_ID)	\
    (None != (REGION_ID))
#define NOT_REGION(REGION_ID)	\
    (None == (REGION_ID))
#define UNSET_REGION(REGION_ID)	\
    ((REGION_ID) = None)

#undef IS_KEYSYM
#undef NOT_KEYSYM
#undef UNSET_KEYSYM
#define IS_KEYSYM(KEYSYM_ID)	\
    (None != (KEYSYM_ID))
#define NOT_KEYSYM(KEYSYM_ID)	\
    (None == (KEYSYM_ID))
#define UNSET_KEYSYM(KEYSYM_ID)	\
    ((KEYSYM_ID) = None)


#ifndef HAVE_XPOINTER
typedef char*	    XPointer;
#endif


#ifdef HAVE_LIBXPM
# include <X11/xpm.h>
#endif

#if defined(BACKGROUND_IMAGE) || defined(TRANSPARENT)
# ifdef USE_JPEG
#  include <jpeglib.h>
# endif
# ifdef USE_PNG
#  ifdef OS_OPENBSD
#   include <libpng/png.h>
#  else
#   include <png.h>
#  endif    /* OS_OPENBSD */
# endif	/* USE_PNG */
#endif

#ifdef HAVE_LIBXRENDER
# include <X11/extensions/Xrender.h>
#endif

/* Xft.h seems to conflict with png.h. So we must include it
** after pnt.h */
# ifdef XFT_SUPPORT
#  include <X11/Xft/Xft.h>
# endif
# ifdef HAVE_ICONV_H
#  include <iconv.h>
# endif

/*
** It seems Mac OS X's fontconfig does not have following definitions
*/
#ifdef XFT_SUPPORT
# ifndef FC_WIDTH
#  define FC_WIDTH		    "width"
#  define FC_WIDTH_ULTRACONDENSED   (50)
#  define FC_WIDTH_EXTRACONDENSED   (63)
#  define FC_WIDTH_CONDENSED	    (75)
#  define FC_WIDTH_SEMICONDENSED    (87)
#  define FC_WIDTH_NORMAL	    (100)
#  define FC_WIDTH_SEMIEXPANDED	    (113)
#  define FC_WIDTH_EXPANDED	    (125)
#  define FC_WIDTH_EXTRAEXPANDED    (150)
#  define FC_WIDTH_ULTRAEXPANDED    (200)
# endif
#endif


#ifdef HAVE_XSETLOCALE
# define X_LOCALE
# include <X11/Xlocale.h>
#else
# ifdef HAVE_LOCALE_H
#  include <locale.h>
# endif
#endif


#ifdef HAVE_NL_LANGINFO
# include <langinfo.h>
#endif


#ifdef UTMP_SUPPORT
# ifdef UTEMPTER_SUPPORT
#  include <utempter.h>
# endif
# ifdef HAVE_UTMP_H
#  include <utmp.h>
#  ifdef HAVE_SETUTENT
#   define RXVT_UTMP_SYSV
#  endif
# endif
# if defined(HAVE_UTMPX_H) && !defined(HAVE_UTMP_H)
#  include <utmpx.h>
#  define RXVT_UTMP_SYSV
# endif
# ifdef HAVE_LASTLOG_H
#  include <lastlog.h>
# endif
#endif


#if defined(UTMP_SUPPORT) || defined(HAVE_GETPWUID)
# include <pwd.h>
#endif


#ifdef UTMP_SUPPORT
# if defined(HAVE_UTMPX_H) && !defined(HAVE_UTMP_H)
#  define UTMP_FILENAME	UTMPX_FILE
# endif
# if !defined(UTMP_FILE) && defined(_PATH_UTMP)
#  define UTMP_FILE     _PATH_UTMP
# endif
# if !defined(UTMP_FILENAME) && defined(UTMP_FILE)
#  define UTMP_FILENAME UTMP_FILE
# endif
# define RXVT_UTMP_FILE	UTMP_FILENAME
#endif

#ifdef WTMP_SUPPORT
# if defined(HAVE_WTMPX_H) && !defined(HAVE_WTMP_H)
#  define WTMP_FILENAME	WTMPX_FILE
# endif
# if !defined(WTMP_FILE) && defined(_PATH_WTMP)
#  define WTMP_FILE     _PATH_WTMP
# endif
# if !defined(WTMP_FILENAME) && defined(WTMP_FILE)
#  define WTMP_FILENAME WTMP_FILE
# endif
# define RXVT_WTMP_FILE	WTMP_FILENAME
#endif

#ifdef LASTLOG_SUPPORT
# ifdef OS_SOLARIS
#  define LASTLOG_FILE	    "/var/adm/lastlog"
# endif
# ifdef OS_OSF
#  define LASTLOG_FILE	    "/var/adm/lastlog"
# endif
# if !defined(LASTLOG_FILE) && defined(_PATH_LASTLOG)
#  define LASTLOG_FILE     _PATH_LASTLOG
# endif
# if !defined(LASTLOG_FILENAME) && defined(LASTLOG_FILE)
#  define LASTLOG_FILENAME LASTLOG_FILE
# endif
# define RXVT_LASTLOG_FILE  LASTLOG_FILENAME
#endif

#ifdef UTMP_SUPPORT
# ifdef RXVT_UTMP_SYSV
#  ifndef USER_PROCESS
#   define USER_PROCESS	    (7)
#  endif
#  ifndef DEAD_PROCESS
#   define DEAD_PROCESS	    (8)
#  endif
# endif
#endif



#ifdef NO_SECONDARY_SCREEN
# define NSCREENS	0
#else
# define NSCREENS	1
#endif


/*
 * Let's try some interesting static program analysis tools. Refer to
 * http://www.cs.umd.edu/~jfoster/cqual/
 *
 * Tainted defines the type of data that is fetchted from user input, which in
 * turn is unsafe without checking. Untainted defines the type of data that is
 * safe.
 */
#if defined(__GNUC__) && !defined(__arm__)
# define $tainted
# define $untainted
# define TAINTED    $tainted
# define UNTAINTED  $untainted
#else
# define TAINTED
# define UNTAINTED
#endif


/*
*********************************************************
** The following are internal includes
*********************************************************
*/
#include "debug.h"
#include "encoding.h"
#include "rxvtlib.h"


#ifdef GREEK_SUPPORT
# include "grkelot.h"
#endif

#ifdef HAVE_MENUBAR
# include "menubar.h"
#endif

#include "command.h"
#include "init.h"


#ifndef STDIN_FILENO
# define STDIN_FILENO	0
# define STDOUT_FILENO	1
# define STDERR_FILENO	2
#endif

#if defined(HAVE_GRANTPT) && defined(HAVE_UNLOCKPT)
# if defined(PTYS_ARE_GETPT) || defined(PTYS_ARE_PTMX)
#  define NO_SETOWNER_TTYDEV
# endif
#endif
#if defined(OS_CYGWIN) || defined(PTYS_ARE_OPENPTY)
# define NO_SETOWNER_TTYDEV
#endif


/* Macros to check NULL pointers. This is solely to make the code more
** readable/pretty
*/
#define IS_NULL(PTR)	(NULL == (PTR))
#define NOT_NULL(PTR)	(NULL != (PTR))
#define SET_NULL(PTR)	((PTR) = NULL)

/*
 *****************************************************************************
 * STRUCTURES AND TYPEDEFS
 *****************************************************************************
 */
struct rxvt_vars;	/* Later REDEFINED and typedef'd to rxvt_t */
struct rxvt_hidden;


/* Motif window hints, MwmHints.flags */
#define MWM_HINTS_FUNCTIONS     (1L << 0)
#define MWM_HINTS_DECORATIONS   (1L << 1)
#define MWM_HINTS_INPUT_MODE    (1L << 2)
#define MWM_HINTS_STATUS        (1L << 3)
/* bit definitions for MwmHints.functions */
#define MWM_FUNC_ALL            (1L << 0)
#define MWM_FUNC_RESIZE         (1L << 1)
#define MWM_FUNC_MOVE           (1L << 2)
#define MWM_FUNC_MINIMIZE       (1L << 3)
#define MWM_FUNC_MAXIMIZE       (1L << 4)
#define MWM_FUNC_CLOSE          (1L << 5)
/* bit definitions for MwmHints.decorations */
#define MWM_DECOR_ALL           (1L << 0)
#define MWM_DECOR_BORDER        (1L << 1)
#define MWM_DECOR_RESIZEH       (1L << 2)
#define MWM_DECOR_TITLE         (1L << 3)
#define MWM_DECOR_MENU          (1L << 4)
#define MWM_DECOR_MINIMIZE      (1L << 5)
#define MWM_DECOR_MAXIMIZE      (1L << 6)
/* bit definitions for MwmHints.inputMode */
#define MWM_INPUT_MODELESS                  0
#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
#define MWM_INPUT_SYSTEM_MODAL              2
#define MWM_INPUT_FULL_APPLICATION_MODAL    3
#define PROP_MWM_HINTS_ELEMENTS             5


/*
 * If we're using either the rxvt scrollbar or menu bars, keep the
 * scrollColor resource.
 */
#if defined(RXVT_SCROLLBAR) || defined(PLAIN_SCROLLBAR) || defined(HAVE_MENUBAR)
# define KEEP_SCROLLCOLOR 1
#else
# undef KEEP_SCROLLCOLOR
#endif


/*
 * the 'essential' information for reporting Mouse Events
 * pared down from XButtonEvent
 */
struct mouse_event {
    int             clicks;
    Time            time;   /* milliseconds */
    unsigned int    state;  /* key or button mask */
    unsigned int    button; /* detail */
};

#ifndef min
# define min(a,b)   (((a) < (b)) ? (a) : (b))
# define max(a,b)   (((a) > (b)) ? (a) : (b))
#endif

#define MAX_IT(current, other)	if ((other) > (current)) (current) = (other)
#define MIN_IT(current, other)	if ((other) < (current)) (current) = (other)
#define SWAP_IT(one, two, typeof)				    \
    {								    \
	typeof          swapittmp;				    \
	(swapittmp) = (one); (one) = (two); (two) = (swapittmp);    \
    }

#define BOUND_POSITIVE_INT16(val)				    \
    (int16_t)( (val) <= 0 ? 0 : min( (val), (((uint16_t)-1)>>1) )  )

/*
 *****************************************************************************
 * NORMAL DEFINES
 *****************************************************************************
 */

#if defined (NO_OLD_SELECTION) && defined(NO_NEW_SELECTION)
# error if you disable both selection styles, how can you select, silly?
#endif

#define APL_CLASS	"XTerm"	    /* class name */
#define APL_SUBCLASS	"Mrxvt"	/* also check resources under this name */
#define APL_NAME	"mrxvt"	/* normal name */

/* COLORTERM, TERM environment variables */
#define COLORTERMENV	"rxvt"
#ifdef BACKGROUND_IMAGE
# define COLORTERMENVFULL COLORTERMENV "-xpm"
#else
# define COLORTERMENVFULL COLORTERMENV
#endif
#ifndef TERMENV
# define TERMENV	"xterm"
#endif

#define TABTITLEENV	"MRXVT_TABTITLE="


#if defined (NO_MOUSE_REPORT) && !defined (NO_MOUSE_REPORT_SCROLLBAR)
# define NO_MOUSE_REPORT_SCROLLBAR
#endif

#ifdef NO_RESOURCES
# undef USE_XGETDEFAULT
#endif

/* now look for other badly set stuff */

#if !defined (EACCESS) && defined(EAGAIN)
# define EACCESS EAGAIN
#endif

#ifndef EXIT_SUCCESS	    /* missing from <stdlib.h> */
# define EXIT_SUCCESS	    0	/* exit function success */
# define EXIT_FAILURE	    1	/* exit function failure */
#endif

#define menuBar_esc	    (10)
#define scrollBar_esc	    (30)
#define MENUBAR_MARGIN	    (2)	/* margin below text */

/* width of scrollBar, menuBar shadow, must be 1 or 2 */
#ifdef HALFSHADOW
# define SHADOW		    (1)
#else
# define SHADOW		    (2)
#endif

#define R_SB_ALIGN_CENTRE   (0)
#define R_SB_ALIGN_TOP	    (1)
#define R_SB_ALIGN_BOTTOM   (2)

#define R_SB_UNKNOWN	    (-1)
#define R_SB_RXVT	    (0)
#define R_SB_NEXT	    (1)
#define R_SB_XTERM	    (2)
#define R_SB_SGI	    (3)
#define R_SB_PLAIN	    (4)

#define SB_WIDTH_PLAIN	    (15)
#define SB_WIDTH_XTERM	    (15)
#define SB_WIDTH_RXVT	    (10)
#define SB_WIDTH_NEXT	    (17)
#define SB_WIDTH_SGI	    (16)


#ifdef NEXT_SCROLLBAR
/*
** NeXT scrollbar definitions
*/
#define NEXT_SB_WIDTH		(SB_WIDTH_NEXT)
#define NEXT_SB_PAD		(1)
#define NEXT_SB_BD_WIDTH	(1)
#define NEXT_BEVEL_ULEFT_WIDTH	(1)
#define NEXT_BEVEL_LRIGHT_WIDTH	(2)
#define NEXT_SB_LPAD		(NEXT_SB_PAD + NEXT_SB_BD_WIDTH)
#define NEXT_SB_MARGIN		(NEXT_SB_PAD<<1)
#define NEXT_SB_BTN_WIDTH	(NEXT_SB_WIDTH - NEXT_SB_MARGIN - NEXT_SB_BD_WIDTH)
/* button height */
#define NEXT_SB_BTN_HEIGHT	(NEXT_SB_BTN_WIDTH)
/* single button height */
#define NEXT_SB_SBTN_HEIGHT	(NEXT_SB_BTN_HEIGHT + NEXT_SB_PAD)
/* double button height */
#define NEXT_SB_DBTN_HEIGHT	(NEXT_SB_SBTN_HEIGHT<<1)
/* total button height */
#define NEXT_SB_TBTN_HEIGHT	(NEXT_SB_DBTN_HEIGHT + NEXT_SB_PAD)
#define NEXT_BEVEL_X		(NEXT_SB_LPAD)
#define NEXT_BTN_FACE_X		(NEXT_BEVEL_X + NEXT_BEVEL_ULEFT_WIDTH)
#define NEXT_SB_MIN_HEIGHT	(NEXT_SB_BTN_WIDTH - (NEXT_SB_PAD<<1))
 /*
  *    +-------------+
  *    |             | <---< NEXT_SB_PAD
  *    | ::::::::::: |
  *    | ::::::::::: |
  *   '''''''''''''''''
  *   ,,,,,,,,,,,,,,,,,
  *    | ::::::::::: |
  *    | ::::::::::: |
  *    |  +---------------< NEXT_BEVEL_ULEFT_WIDTH
  *    |  | :::::::: |
  *    |  V :::: vv-------< NEXT_BEVEL_LRIGHT_WIDTH
  *    | +---------+ |
  *    | | ......%%| |
  *    | | ......%%| |
  *    | | ..()..%%| |
  *    | | ......%%| |
  *    | | %%%%%%%%| |
  *    | +---------+ | <.........................
  *    |             | <---< NEXT_SB_PAD         :
  *    | +---------+ | <-+..........            :---< NEXT_SB_TBTN_HEIGHT
  *    | | ......%%| |   |         :            :
  *    | | ../\..%%| |   |---< NEXT_SB_BTN_HEIGHT :
  *    | | %%%%%%%%| |   |         :            :
  *    | +---------+ | <-+         :            :
  *    |             |             :            :
  *    | +---------+ | <-+         :---< NEXT_SB_DBTN_HEIGHT
  *    | | ......%%| |   |         :            :
  *    | | ..\/..%%| |   |         :            :
  *    | | %%%%%%%%| |   |---< NEXT_SB_SBTN_HEIGHT
  *    | +---------+ |   |         :            :
  *    |             |   |         :            :
  *    +-------------+ <-+.........:............:
  *    ^^|_________| :
  *    ||     |      :
  *    ||     +---< NEXT_SB_BTN_WIDTH
  *    ||            :
  *    |+------< NEXT_SB_PAD
  *    |:            :
  *    +----< NEXT_SB_BD_WIDTH
  *     :            :
  *     :............:
  *           |
  *           +---< NEXT_SB_WIDTH
  */
#endif	/* NEXT_SCROLLBAR */


#ifdef SGI_SCROLLBAR
/*
** SGI IRIX scrollbar definitions
*/
#define SGI_ARROW_SOURCE_WIDTH	(14)
#define SGI_ARROW_SOURCE_HEIGHT	(14)
#define SGI_BEVEL_HI_WIDTH	(1)
#define SGI_BEVEL_LO_WIDTH	(1)
#define SGI_BEVEL_SIZE		(SGI_BEVEL_HI_WIDTH+SGI_BEVEL_LO_WIDTH)

#define SGI_ARROW_WIDTH		(SB_WIDTH_SGI-(SGI_BEVEL_SIZE<<1))
#define SGI_ARROW_HEIGHT	(SGI_ARROW_SOURCE_HEIGHT)

#define SGI_SB_BUTTON_HEIGHT	((SGI_BEVEL_SIZE<<1)+SGI_ARROW_WIDTH)
#define SGI_SB_BUTTONS_HEIGHT	(SGI_SB_BUTTON_HEIGHT<<1)
#endif



/*
 * Options for r->h->refresh_type.
 */
#define NO_REFRESH	    (0)	    /* Window not visible at all! */
#define FAST_REFRESH	    (1<<0)  /* Fully exposed window */
#define SLOW_REFRESH	    (1<<1)  /* Partially exposed window */
#define SMOOTH_REFRESH	    (1<<2)  /* Do sync'ing to make it smooth */
#define REFRESH_BOUNDS	    (1<<3)  /* Refresh window borders */
#define CLIPPED_REFRESH	    (1<<4)  /* Honor clipping in GC while refreshing */

/*
 * Options for r->h->want_resize
 */
#define FORCE_RESIZE	    (1U << 0)
#define FORCE_REFRESH	    (1U << 1)

/*
 * Continue undocumented mrxvt code
 */
#define IGNORE		0
#define SAVE		's'
#define RESTORE		'r'

/* special (internal) prefix for font commands */
#define FONT_CMD	'#'
#define FONT_DN		"#-"
#define FONT_UP		"#+"

/* flags for rxvt_scr_gotorc() */
#define C_RELATIVE	1   /* col movement is relative */
#define R_RELATIVE	2   /* row movement is relative */
#define RELATIVE	(R_RELATIVE|C_RELATIVE)

/* modes for rxvt_scr_insdel_chars(), rxvt_scr_insdel_lines() */
#define INSERT		-1  /* don't change these values */
#define DELETE		+1
#define ERASE		+2

/* modes for rxvt_scr_page() - scroll page. used by scrollbar window */
enum page_dirn {
    UP,
    DN,
    NO_DIR
};

/* arguments for rxvt_scr_change_screen() */
#define PRIMARY	    (0)
#define SECONDARY   (1)

enum {
    SBYTE = 0,
    WBYTE
};


#define RS_None		0   /* Normal */

#if defined(TTY_256COLOR)
/* have at least 32 bits to use */
# define RS_fgMask	    0x000001FFu	/* 512 colors */
# define RS_bgMask	    0x0003FE00u	/* 512 colors */
# define RS_Bold	    0x00040000u	/* bold */
# define RS_Blink	    0x00080000u	/* blink */
# define RS_RVid	    0x00100000u	/* reverse video */
# define RS_Uline	    0x00200000u	/* underline */
# define RS_acsFont	    0x00400000u	/* ACS graphics char set */
# define RS_ukFont	    0x00800000u	/* UK character set */
#else
/* may only have 16 bits to use so squash them in */
# define RS_fgMask	    0x0000001Fu	/* 32 colors */
# define RS_bgMask	    0x000003E0u	/* 32 colors */
# define RS_Bold	    0x00000400u	/* bold */
# define RS_Blink	    0x00000800u	/* blink */
# define RS_RVid	    0x00001000u	/* reverse video */
# define RS_Uline	    0x00002000u	/* underline */
# define RS_acsFont	    0x00004000u	/* ACS graphics char set */
# define RS_ukFont	    0x00008000u	/* UK character set */
#endif

#ifdef MULTICHAR_SET
# define RS_multi0	    0x10000000u	/* only multibyte characters */
# define RS_multi1	    0x20000000u	/* multibyte 1st byte */
/* multibyte 2nd byte */
# define RS_multi2	    (RS_multi0|RS_multi1)
/* multibyte mask */
# define RS_multiMask	    (RS_multi0|RS_multi1)
# define IS_MULTI1(R)	    (((R) & RS_multiMask) == RS_multi1)
# define IS_MULTI2(R)	    (((R) & RS_multiMask) == RS_multi2)
#else
# define RS_multiMask	    (0)
# define IS_MULTI1(r)	    (0)
# define IS_MULTI2(r)	    (0)
#endif


#define UNICODE_MASK 0x1fffffUL

#if UNICODE3
# define COMPOSE_LO 0x40000000UL
# define COMPOSE_HI 0x400fffffUL
# define IS_COMPOSE(n) ((int32_t)(n) >= COMPOSE_LO)
#else
# define COMPOSE_LO 0xd800UL
# define COMPOSE_HI 0xf8ffUL /* dfff should be safer, but... */
# define IS_COMPOSE(n) (COMPOSE_LO <= (n) && (n) <= COMPOSE_HI)
#endif


#define RS_fontMask	    (RS_acsFont|RS_ukFont)
#define RS_baseattrMask	    (RS_Bold|RS_Blink|RS_RVid|RS_Uline)
#define RS_attrMask	    (RS_baseattrMask|RS_fontMask|RS_multiMask)

#define Sel_none	    0	/* Not waiting */
#define Sel_normal	    0x01    /* normal selection */
#define Sel_incr	    0x02    /* incremental selection */
#define Sel_direct	    0x00
#define Sel_Primary	    0x01
#define Sel_Secondary	    0x02
#define Sel_Clipboard	    0x03
#define Sel_whereMask	    0x0f
#define Sel_CompoundText    0x10    /* last request was Compound */

enum {
    C0_NUL = 0x00,
            C0_SOH, C0_STX, C0_ETX, C0_EOT, C0_ENQ, C0_ACK, C0_BEL,
    C0_BS , C0_HT , C0_LF , C0_VT , C0_FF , C0_CR , C0_SO , C0_SI ,
    C0_DLE, C0_DC1, C0_DC2, D0_DC3, C0_DC4, C0_NAK, C0_SYN, C0_ETB,
    C0_CAN, C0_EM , C0_SUB, C0_ESC, C0_IS4, C0_IS3, C0_IS2, C0_IS1
}; 
#define CHAR_ST		0x9c	/* 0234 */


/*
** Xwsh escape sequences: ESC P Ps .y Pt ESC
*/
#define Xwsh_title		(1)
#define Xwsh_iconName		(3)
#define Xwsh_textColor		(4)
#define Xwsh_pageColor		(5)
#define Xwsh_selTextColor	(6)
#define Xwsh_selPageColor	(7)
#define Xwsh_cursorTextColor	(8)
#define Xwsh_cursorPageColor	(9)
#define Xwsh_halfIntColor	(10)
#define Xwsh_boldIntColor	(11)
#define Xwsh_bindStrKeyVal	(101) /* not implemented */
#define Xwsh_bindStrKeyFunc	(103) /* not implemented */


/*
** XTerm Operating System Commands: ESC ] Ps;Pt (ST|BEL)
** colour extensions by Christian W. Zuckschwerdt <zany@triq.net>
*/
#define XTerm_name	    (0)
#define XTerm_iconName	    (1)
#define XTerm_title	    (2)
#define XTerm_Color	    (4)  /* change colors */
#define XTerm_Color_cursor  (12) /* change actual 'Cursor' color */
#define XTerm_Color_pointer (13) /* change actual 'Pointer' color */
#define XTerm_Color_RV	    (17) /* change actual 'Highlight' color */
#define XTerm_Color_BD	    (18) /* change actual 'Bold' color */
#define XTerm_Color_UL	    (19) /* change actual 'Underline' color */
#define XTerm_logfile	    (46) /* not implemented */
#define XTerm_font	    (50)


/*
** rxvt extensions of XTerm OSCs: ESC ] Ps;Pt (ST|BEL)
*/
#define XTerm_Menu	    (10) /* set menu item */
#define XTerm_Pixmap	    (20) /* new bg pixmap */
#define XTerm_restoreFG	    (39) /* change default fg color */
#define XTerm_restoreBG	    (49) /* change default bg color */
#define XTerm_dumpscreen    (55) /* dump scrollback and all screen */


/*
 * mrxvt extensions of XTerm OSCs: ESC ] Ps;Pt (ST|BEL)
 * Example: echo "\e]61;newtitle\a"
 */
#define MRxvt_term	    (60) /* Change window title */
#define MRxvt_tab	    (61) /* change tab title */
#define MRxvt_tabterm	    (62) /* change tab and terminal title */
#define MRxvt_wformat	    (63) /* Change window title format */
#define MRxvt_tformat	    (64) /* Change tab title format */
/* #define MRxvt_newtab	    (63) ** DISABLED create a new tab with title */
/* #define MRxvt_prevtab    (64) ** DISABLED switch to previous tab */
/* #define MRxvt_nexttab    (65) ** DISABLED switch to next tab */
#define MRxvt_tint	    (66) /* change tinting color */
#define MRxvt_shade	    (67) /* change shade level */
#define MRxvt_encode	    (68) /* change encoding */
/* #define MRxvt_hide	    (69) ** DISABLED hide/show tabbar */
#define MRxvt_opacity	    (70) /* set opacity level */
/* #define MRxvt_tabbtn	    (71) ** DISABLED hide/show tabbar buttons */
#define MRxvt_tabfg	    (72) /* change active tab fg */
#define MRxvt_tabbg	    (73) /* change tabbar/active tab bg */
#define MRxvt_itabfg	    (74) /* change inactive tab fg */
#define MRxvt_itabbg	    (75) /* change inactive tab bg */
/* #define MRxvt_trans	    (76) ** DISABLED toggle transparency */
/* #define MRxvt_moveleft   (77) ** DISABLED move active tab to left */
/* #define MRxvt_moveright  (78) ** DISABLED move active tab to right */
/* #define MRxvt_verybold   (79) ** DISABLED toggle bold font for color text */
/* #define MRxvt_hotkeys    (80) ** DISABLED toggle hotkeys */
/* #define MRxvt_saveconfig (81) ** DISABLED save configuration */
#define MRxvt_bgfade	    (82) /* set bgfade degree (Obsolete) */
#define MRxvt_termenv	    (83) /* set TERMENV type */
/* #define MRxvt_closewin   (84) ** DISABLED Close all tabs and exit */
/* #define MRxvt_switchtab  (85) ** DISABLED Switch to tab N */



/* Words starting with `Color_' are colours.  Others are counts */
/*
** The following comment is mostly obsolete since pixcolor_set was
** expanded:
** We're currently upto 30 colours.  Only 2 more available.  The
** PixColor and rendition colour usage should probably be decoupled
** on the unnecessary items, e.g. Color_pointer, but won't bother
** until we need to.  Also, be aware of usage in pixcolor_set
*/

enum colour_list {
    Color_fg = 0,
    Color_bg,
    minCOLOR,		/* 2 */
    Color_Black = minCOLOR,
    Color_Red3,
    Color_Green3,
    Color_Yellow3,
    Color_Blue3,
    Color_Magenta3,
    Color_Cyan3,
    maxCOLOR,		/* minCOLOR + 7 */
#ifndef NO_BRIGHTCOLOR
    Color_AntiqueWhite = maxCOLOR,
    minBrightCOLOR,	/* maxCOLOR + 1 */
    Color_Grey25 = minBrightCOLOR,
    Color_Red,
    Color_Green,
    Color_Yellow,
    Color_Blue,
    Color_Magenta,
    Color_Cyan,
    maxBrightCOLOR,	/* minBrightCOLOR + 7 */
    Color_White = maxBrightCOLOR,
#else
    Color_White = maxCOLOR,
#endif
#ifdef TTY_256COLOR
    min256COLOR = Color_White + 1,
    max256COLOR = minCOLOR + 255,
#endif
#ifndef NO_CURSORCOLOR
    Color_cursor,
    Color_cursor2,
#endif
    Color_pointer,
    Color_border,
    Color_ufbg,
#ifndef NO_BOLD_UNDERLINE_REVERSE
    Color_BD,
    Color_UL,
    Color_RV,
#endif
#ifdef OPTION_HC
    Color_HC,
#endif
#ifdef KEEP_SCROLLCOLOR
    Color_scroll,
    Color_trough,
#endif
#if defined(BACKGROUND_IMAGE) || defined(TRANSPARENT)
# ifdef TINTING_SUPPORT
    Color_tint,
# endif
#endif	/* BACKGROUND_IMAGE || TRANSPARENT */
    NRS_COLORS,		/* */
#ifdef KEEP_SCROLLCOLOR
    Color_topShadow = NRS_COLORS,
    Color_bottomShadow,
    TOTAL_COLORS	/* upto 31 */
#else
    TOTAL_COLORS = NRS_COLORS	/* */
#endif
};

#ifdef TTY_256COLOR
# define Color_Bits 9
# define NPIXCLR_SETS	9   /* (256 + 14) bits / 32 bits */
#else
# define Color_Bits 5
# define NPIXCLR_SETS	1   /* (16 + 14) bits / 32 bits */
#endif
#define NPIXCLR_BITS	32

#define DEFAULT_RSTYLE	    (RS_None | (Color_fg) | (Color_bg<<Color_Bits))



/*
 * Resource list
 */
enum {
    Rs_display_name = 0,
    Rs_debug_masks,
    Rs_debug_level,
    Rs_container_window,
    Rs_term_name,
    Rs_iconName,
    Rs_geometry,
    Rs_color,
    _Rs_color = Rs_color + TOTAL_COLORS, /*+ 2 * MAX_PAGES - 1,*/
    Rs_font,
    _Rs_font = Rs_font + MAX_NFONTS - 1,
#ifdef MULTICHAR_SET
    Rs_mfont,
    _Rs_mfont = Rs_mfont + MAX_NFONTS - 1,
    Rs_multichar_encoding,
#endif
    Rs_name,
    Rs_title,
    Rs_maxTabWidth,
    Rs_minVisibleTabs,
#if defined (BACKGROUND_IMAGE) || defined(HAVE_MENUBAR)
    Rs_path,
#endif

#ifdef BACKGROUND_IMAGE
    Rs_tabbarPixmap,	/* tabbar background pixmap */
    Rs_appIcon,		/* use pixmap as application icon */
#endif

#ifdef HAVE_MENUBAR
    Rs_menu,
# ifdef BACKGROUND_IMAGE
    Rs_menubarPixmap,
# endif
#endif

#ifndef NO_BOLDFONT
    Rs_boldFont,
    _Rs_boldFont = Rs_boldFont + MAX_NFONTS - 1,
#endif
#ifdef GREEK_SUPPORT
    Rs_greek_keyboard,
    Rs_greektoggle_key,
#endif
#ifdef XFT_SUPPORT
    Rs_xftfont,	/* Font name, family */
# ifdef MULTICHAR_SET
    Rs_xftmfont,/* Multichar font name, family */
    Rs_xftmsz,	/* Multichar font size */
# endif
    Rs_xftwt,	/* Font weight */
    Rs_xftBwt,	/* Bold font weight */
    Rs_xftst,	/* Font slant */
    Rs_xftsz,	/* Font size */
    Rs_xftwd,	/* Font width style */
    Rs_xftrgb,	/* Font sub-pixel order */
    Rs_xftpfn,	/* Propotionally spaced Xft font (for tabbar / menubar) */
    Rs_xftpsz,	/* Size of propotionally spaced Xft font */
#endif
#ifdef HAVE_SCROLLBARS
    Rs_scrollBar_align,
# ifdef BACKGROUND_IMAGE
    Rs_scrollbarPixmap,
# endif
#endif	/* HAVE_SCROLLBARS */
    Rs_scrollBar_style,

    Rs_tabfg,	/* active tab foreground */
    Rs_tabbg,	/* active tab background */
    Rs_itabfg,	/* inactive tab foreground */
    Rs_itabbg,	/* inactive tab background */

    Rs_fade,	/* fade percentage */

#ifdef TEXT_SHADOW
    Rs_textShadow,	/* text shadow color */
    Rs_textShadowMode,	/* text shadow color mode */
#endif

    Rs_skipPages,	/* Number of pages to skip when jump scrolling */
    Rs_refreshLimit,	/* Number of chars to tolerate when refreshing */
#ifdef TINTING_SUPPORT
    Rs_shade,	/* shade percentage */
    Rs_tint,	/* tinting color */
#endif
#ifdef TRANSPARENT
    Rs_bgRefreshInterval,
#endif

    Rs_focusDelay,

#ifndef NO_BELL
    Rs_bellCommand,
    Rs_vBellDuration,
#endif
    Rs_monitorCommand,
    Rs_monitorTimeout,
    Rs_desktop,
#ifndef NO_BACKSPACE_KEY
    Rs_backspace_key,
#endif
#ifndef NO_DELETE_KEY
    Rs_delete_key,
#endif
    Rs_selectstyle,
#ifdef PRINTPIPE
    Rs_print_pipe,
#endif
#ifdef USE_XIM
    Rs_preeditType,
    Rs_inputMethod,
#endif
    Rs_opacity,		/* transluscent window opacity degree */
    Rs_opacityDegree,	/* opacity change degree */
#ifndef NO_FRILLS
    Rs_ext_bwidth,
    Rs_int_bwidth,
#endif
    Rs_scrollBar_thickness,
#ifndef NO_LINESPACE
    Rs_lineSpace,
#endif
    Rs_cutchars,
#ifdef ACS_ASCII
    Rs_acs_chars,
#endif
    Rs_modifier,
    Rs_confFile,
    Rs_answerbackstring,
    Rs_cursorBlinkInterval,
    Rs_pointerBlankDelay,
    Rs_smClientID,
    Rs_initProfiles,
    Rs_init_term_num,	    /* OBSOLETE */

    /*
     * Options for multiple profiles.
     */
#ifdef BACKGROUND_IMAGE
    Rs_backgroundPixmap,/* terminal background pixmap for each tab */
    _Rs_backgroundPixmap = Rs_backgroundPixmap + MAX_PROFILES - 1,
#endif
    Rs_tabtitle,	_Rs_tabtitle	= MAX_PROFILES - 1 + Rs_tabtitle,
    Rs_command,		_Rs_command	= MAX_PROFILES - 1 + Rs_command,
    Rs_saveLines,	_Rs_saveLines	= MAX_PROFILES - 1 + Rs_saveLines,
    Rs_foreground,	_Rs_foreground	= MAX_PROFILES - 1 + Rs_foreground,
    Rs_background,	_Rs_background	= MAX_PROFILES - 1 + Rs_background,
    Rs_cwd,		_Rs_cwd		= MAX_PROFILES - 1 + Rs_cwd,
    Rs_holdExit,	_Rs_holdExit	= MAX_PROFILES - 1 + Rs_holdExit,
    Rs_holdExitTxt,	_Rs_holdExitTxt = MAX_PROFILES - 1 + Rs_holdExitTxt,
    Rs_holdExitTtl,	_Rs_holdExitTtl = MAX_PROFILES - 1 + Rs_holdExitTtl,
    Rs_titleFormat,	_Rs_titleFormat = MAX_PROFILES - 1 + Rs_titleFormat,
    Rs_winTitleFormat,	_Rs_winTitleFormat = MAX_PROFILES - 1 + Rs_winTitleFormat,

    NUM_RESOURCES
} ;

enum {
    TIMEOUT_INCR = 0,
    NUM_TIMEOUTS
} ;


/*
** MUST sync with init.c:xa_names
*/
enum {
    XA_COMPOUND_TEXT = 0,
    XA_UTF8_STRING,
    XA_TEXT,
    XA_MULTIPLE,
    XA_TARGETS,
    XA_TIMESTAMP,
    XA_VT_SELECTION,
    XA_INCR,
    XA_WMDELETEWINDOW,
    XA_NET_WM_DESKTOP,
    XA_WIN_WORKSPACE,
    XA_NET_WM_NAME,
    XA_NET_WM_ICON_NAME,
    XA_WM_CLIENT_LEADER,
    XA_NET_WM_WINDOW_OPACITY,
#ifndef NO_FRILLS
    XA_NET_WM_PID,
#endif
#ifdef HAVE_X11_SM_SMLIB_H
    XA_SM_CLIENT_ID,
#endif
#ifdef USE_XIM
    XA_WM_LOCALE_NAME,
#endif
#ifdef TRANSPARENT
    XA_XROOTPMAPID,
    XA_XSETROOTID,
#endif
#ifdef OFFIX_DND	/* OffiX Dnd (drag 'n' drop) support */
    XA_DNDPROTOCOL,
    XA_DNDSELECTION,
#endif		    /* OFFIX_DND */
    XA_CLIPBOARD,
    NUM_XA
} ;

/*
 * number of graphics points
 * divisible by 2 (num lines)
 * divisible by 4 (num rect)
 */
#define	NGRX_PTS    1000

/* DEC private modes */
#define PrivMode_132		(1LU<<0)
#define PrivMode_132OK		(1LU<<1)
#define PrivMode_rVideo		(1LU<<2)
#define PrivMode_relOrigin	(1LU<<3)
#define PrivMode_Screen		(1LU<<4)
#define PrivMode_Autowrap	(1LU<<5)
#define PrivMode_aplCUR		(1LU<<6)
#define PrivMode_aplKP		(1LU<<7)
#define PrivMode_HaveBackSpace	(1LU<<8)
#define PrivMode_BackSpace	(1LU<<9)
#define PrivMode_ShiftKeys	(1LU<<10)
#define PrivMode_VisibleCursor	(1LU<<11)
#define PrivMode_MouseX10	(1LU<<12)
#define PrivMode_MouseX11	(1LU<<13)
#define PrivMode_scrollBar	(1LU<<14)
#define PrivMode_menuBar	(1LU<<15)
#define PrivMode_TtyOutputInh	(1LU<<16)
#define PrivMode_Keypress	(1LU<<17)
#define PrivMode_smoothScroll	(1LU<<18)
#define PrivMode_vt52		(1LU<<19)
/* too annoying to implement X11 highlight tracking */
/* #define PrivMode_MouseX11Track       (1LU<<18) */

#define PrivMode_mouse_report	(PrivMode_MouseX10|PrivMode_MouseX11)
#define PrivMode(test,bit,page)			\
    if (test)					\
	r->vts[page]->PrivateModes |= (bit);	\
    else					\
	r->vts[page]->PrivateModes &= ~(bit)

#ifdef ALLOW_132_MODE
# define PrivMode_Default			 \
(PrivMode_Autowrap|PrivMode_aplKP|PrivMode_ShiftKeys|PrivMode_VisibleCursor|PrivMode_132OK)
#else
# define PrivMode_Default			 \
(PrivMode_Autowrap|PrivMode_ShiftKeys|PrivMode_VisibleCursor)
/*
(PrivMode_Autowrap|PrivMode_aplKP|PrivMode_ShiftKeys|PrivMode_VisibleCursor)
*/
#endif


#define XSCREEN		DefaultScreen(r->Xdisplay)
#define XROOT		DefaultRootWindow(r->Xdisplay)

#ifdef PREFER_24BIT
# define XDEPTH		(r->Xdepth)
# define XCMAP		(r->Xcmap)
# define XVISUAL	(r->h->Xvisual)
#else
# ifdef DEBUG_DEPTH
#  define XDEPTH	DEBUG_DEPTH
# else
#  define XDEPTH	DefaultDepth(r->Xdisplay, XSCREEN)
#  define XCMAP		DefaultColormap(r->Xdisplay, XSCREEN)
#  define XVISUAL	DefaultVisual(r->Xdisplay, XSCREEN)
# endif
#endif


#define IMBUFSIZ	128 /* input modifier buffer sizes */
#ifndef BUFSIZ
# define BUFSIZ		4096
#endif
#define KBUFSZ		512 /* size of keyboard mapping buffer */

/*
 *****************************************************************************
 * MACRO DEFINES
 *****************************************************************************
 */

/* convert pixel dimensions to row/column values.  Everything as int32_t */
#define Pixel2Width(x)	    ((int32_t)(x) / (int32_t)r->TermWin.fwidth)
#define Pixel2Height(y)	    ((int32_t)(y) / (int32_t)r->TermWin.fheight)
#define Width2Pixel(n)	    ((int32_t)(n) * (int32_t)r->TermWin.fwidth)
#define Height2Pixel(n)	    ((int32_t)(n) * (int32_t)r->TermWin.fheight)
#define Pixel2Col(x)	    Pixel2Width((int32_t)(x) - (int32_t)r->TermWin.int_bwidth)
#define Pixel2Row(y)	    Pixel2Height((int32_t)(y) - (int32_t)r->TermWin.int_bwidth)
#define Col2Pixel(col)	    ((int32_t)Width2Pixel(col) + (int32_t)r->TermWin.int_bwidth)
#define Row2Pixel(row)	    ((int32_t)Height2Pixel(row) + (int32_t)r->TermWin.int_bwidth)

/*
#define TermWin_TotalWidth()	((int32_t)r->TermWin.width  + 2 * (int32_t)r->TermWin.int_bwidth)
#define TermWin_TotalHeight()	((int32_t)r->TermWin.height + 2 * (int32_t)r->TermWin.int_bwidth)
*/

/* how to build & extract colors and attributes */
#define GET_BASEFG(x)	    (((x) & RS_fgMask))
#define GET_BASEBG(x)	    (((x) & RS_bgMask)>>Color_Bits)
#if 0 /* Was ifndef NO_BRIGHTCOLOR */
# define GET_FGCOLOR(x)						    \
    ((((x) & RS_Bold) == 0		    	    		    \
      || GET_BASEFG(x) < minCOLOR		    		    \
      || GET_BASEFG(x) >= minBrightCOLOR)	    		    \
     ? GET_BASEFG(x)				    		    \
     : (GET_BASEFG(x) + (minBrightCOLOR - minCOLOR)))
# define GET_BGCOLOR(x)						    \
    ((((x) & RS_Blink) == 0		    			    \
      || GET_BASEBG(x) < minCOLOR				    \
      || GET_BASEBG(x) >= minBrightCOLOR)			    \
     ? GET_BASEBG(x)						    \
     : (GET_BASEBG(x) + (minBrightCOLOR - minCOLOR)))
#else
# define GET_FGCOLOR(x)	    GET_BASEFG(x)
# define GET_BGCOLOR(x)	    GET_BASEBG(x)
#endif

#define GET_ATTR(x)	(((x) & RS_attrMask))
#define GET_BGATTR(x)				\
    (((x) & RS_RVid) ? (((x) & (RS_attrMask & ~RS_RVid))	\
	    | (((x) & RS_fgMask)<<Color_Bits))	    \
	     : ((x) & (RS_attrMask | RS_bgMask)))
#define SET_FGCOLOR(x,fg)   (((x) & ~RS_fgMask)  | (fg))
#define SET_BGCOLOR(x,bg)   (((x) & ~RS_bgMask)  | ((bg)<<Color_Bits))
#define SET_ATTR(x,a)	    (((x) & ~RS_attrMask)| (a))

#define SET_PIXCOLOR(h, x)	((h)->pixcolor_set[(x) / NPIXCLR_BITS] |= (1 << ((x) % NPIXCLR_BITS)))
#define ISSET_PIXCOLOR(h, x)	((h)->pixcolor_set[(x) / NPIXCLR_BITS] & (1 << ((x) % NPIXCLR_BITS)))

#define scrollbar_isMotion()	(r->scrollBar.state == 'm')
#define scrollbar_isUp()	(r->scrollBar.state == 'U')
#define scrollbar_isDn()	(r->scrollBar.state == 'D')
#define scrollbar_isUpDn()	isupper ((int) r->scrollBar.state)

#define scrollbar_setIdle()	r->scrollBar.state = (char) 1
#define scrollbar_setMotion()	r->scrollBar.state = 'm'
#define scrollbar_setUp()	r->scrollBar.state = 'U'
#define scrollbar_setDn()	r->scrollBar.state = 'D'


#define scrollbarnext_dnval()	    (r->scrollBar.end + (r->scrollBar.width + 1))
#define scrollbarnext_upButton(y)   ((y) > r->scrollBar.end \
		     && (y) <= scrollbarnext_dnval())
#define scrollbarnext_dnButton(y)   ((y) > scrollbarnext_dnval())

#define scrollbarrxvt_upButton(y)   ((y) < r->scrollBar.beg)
#define scrollbarrxvt_dnButton(y)   ((y) > r->scrollBar.end)


#define scrollbarsgi_dnval()	    (r->scrollBar.end + 1)
#define scrollbarsgi_upButton(y)    ((y) < r->scrollBar.beg)
#define scrollbarsgi_dnButton(y)    ((y) > r->scrollBar.end)

#ifdef NEXT_SCROLLBAR
# define SCROLLNEXT_MINHEIGHT	    (NEXT_SB_MIN_HEIGHT)
#else
# define SCROLLNEXT_MINHEIGHT	    (0)
#endif	/* NEXT_SCROLLBAR */
#ifdef SGI_SCROLLBAR
# define SCROLLSGI_MINHEIGHT	    (10)
#else
# define SCROLLSGI_MINHEIGHT	    (0)
#endif	/* SGI_SCROLLBAR */
#define SCROLL_MINHEIGHT	    (10)
#define scrollbar_minheight()	(   \
    (r->scrollBar.style == R_SB_NEXT) ? SCROLLNEXT_MINHEIGHT :	\
    (r->scrollBar.style == R_SB_SGI) ? SCROLLSGI_MINHEIGHT :	\
	SCROLL_MINHEIGHT)
#define scrollbar_above_slider(y)   ((y) < r->scrollBar.top)
#define scrollbar_below_slider(y)   ((y) > r->scrollBar.bot)
#define scrollbar_position(y)	    ((y) - r->scrollBar.beg)
#define scrollbar_size()	(r->scrollBar.end - r->scrollBar.beg \
		     - scrollbar_minheight())



#ifdef BACKGROUND_IMAGE
# define XPMClearArea(a, b, c, d, e, f, g)  XClearArea((a), (b), (c), (d), (e), (f), (g))
#else
# define XPMClearArea(a, b, c, d, e, f, g)
#endif

#ifndef STRICT_FONT_CHECKING
# define rxvt_get_fontwidest(font)  ((font)->max_bounds.width)
#endif

#define rxvt_Gr_ButtonPress(x,y)    rxvt_Gr_ButtonReport (r, 'P',(x),(y))
#define rxvt_Gr_ButtonRelease(x,y)  rxvt_Gr_ButtonReport (r, 'R',(x),(y))


/*
 * When sending a client message to an EWMH compatible window manager
 * e.g. calls to ewmh_message().
 */
#define _NET_WM_STATE_REMOVE	0
#define _NET_WM_STATE_ADD	1
#define _NET_WM_STATE_TOGGLE	2

/* Values for holdOption */
#define HOLD_ALWAYSBIT		(1u << 0)
#define HOLD_NORMALBIT		(1u << 1)
#define HOLD_STATUSBIT		(1u << 2)

/*
 *****************************************************************************
 * VARIABLES
 *****************************************************************************
 */
struct rxvt_hidden {
    unsigned char   BOOLVAR( want_clip_refresh, 1),	/* Only refresh region
							   specified by
							   refreshRegion */
		    BOOLVAR( want_resize, 2),		/* perform resize even
							   if window size has
							   not changed */
#if defined(BACKGROUND_IMAGE) || defined(TRANSPARENT)
		    BOOLVAR( am_transparent, 1),	/* is transparent */
		    BOOLVAR( am_pixmap_trans, 1),	/* transparency without
							   known root pixmap */
# endif
#ifdef CURSOR_BLINK
		    BOOLVAR( hidden_cursor, 1),
#endif
		    BOOLVAR( hate_those_clicks, 1),	/* a.k.a. keep mark
							   position */
		    BOOLVAR( num_scr_allow, 1),
		    BOOLVAR( bypass_keystate, 1);

#ifdef TRANSPARENT
    unsigned char   BOOLVAR( want_full_refresh, 1);	/* awaiting full screen
							   refresh, including
							   borders. */
#endif

    Region	    refreshRegion;			/* Region for
							   CLIPPED_REFRESH */

    int		    skip_pages,				/* Number of pages to
							   skip when jump
							   scrolling */
		    refresh_limit;			/* Request screen
							   refresh only if ATAB
							   produces <= these
							   many chars */
    unsigned char   BOOLVAR( refresh_type, 5),
#ifdef META8_OPTION
		    meta_char,				/* Alt-key prefix */
#endif
		    scrollbar_align,
		    selection_wait,
		    selection_type;

#ifdef GREEK_SUPPORT
    short	    greek_mode;				/* Greek keyboard
							   mode */
    KeySym	    ks_greekmodeswith;
#endif

    uint16_t	    prev_ncol,
		    prev_nrow;				/* screen: previous
							   number of columns and
							   rows */
    uint32_t	    pixcolor_set[NPIXCLR_SETS];

#ifdef SELECTION_SCROLLING
    int		    scroll_selection_delay,
		    scroll_selection_lines;
    enum page_dirn  scroll_selection_dir;
    int		    selection_save_x,
		    selection_save_y,
		    selection_save_state,
		    pending_scroll_selection;
#endif

    int		    csrO,				/* Hops - csr offset in
							   thumb/slider to give
							   proper Scroll
							   behaviour */
#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
		    scroll_arrow_delay,
#endif
#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
		    mouse_slip_wheel_delay,
		    mouse_slip_wheel_speed,
#endif
		    max_skipped_pages,
		    fnum,				/* logical font
							   number */
		    last_bot,				/* scrollbar last bottom
							   position */
		    last_top,				/* scrollbar last top
							   position */
		    last_state,				/* scrollbar last
							   state */
		    scroller_len,
		    currmaxcol,
		    window_vt_x,
		    window_vt_y;
# ifdef POINTER_BLANK
    int		    pointerBlankDelay;
# endif

    unsigned char   BOOLVAR( allowedxerror, 1);		/* Be silent when
							   reporting XErrors */
    int		    xerror_return;			/* ErrorCode of caught
							   XError */

    unsigned int    ModMetaMask,
		    ModNumLockMask;
#ifndef NO_BRIGHTCOLOR
    unsigned long   colorfgbg;
#endif

    gid_t	    ttygid;

#ifdef PREFER_24BIT
    Visual*	    Xvisual;
#endif

    Atom	    xa[NUM_XA];

    Time            selection_time,
                    selection_request_time;

    Cursor          bar_pointer;
#ifdef POINTER_BLANK
    Cursor          blank_pointer;
#endif

#ifndef NO_BACKSPACE_KEY
    const char*	    key_backspace;
#endif
#ifndef NO_DELETE_KEY
    const char*	    key_delete;
#endif
#ifdef USE_XIM
    XIC		    Input_Context;
    XIMStyle	    input_style;
    int		    event_type;
#endif
    struct mouse_event	MEvent;
    row_col_t	    oldcursor;
#ifdef MULTICHAR_SET
    signed int	    oldcursormulti;
#endif
    void	    (*multichar_decode)(unsigned char *str, int len);
#ifdef HAVE_MENUBAR
    menu_t*	    ActiveMenu;				/* currently active
							   menu */
    menu_t*	    BuildMenu;				/* the menu currently
							   being built */
    menu_t*	    popupMenu[3];			/* Menus to popup on
							   ctrl clicks */

    unsigned char   BOOLVAR( showingMenu, 1);		/* The type of menu
							   currently being
							   shown */

    bar_t	    MenuBar;
    int		    Arrows_x;
#endif
#ifdef CURSOR_BLINK
    long	    blinkInterval;
    struct timeval  lastcursorchange;
#endif
#ifdef POINTER_BLANK
    struct timeval  lastmotion;
#endif
#ifdef TRANSPARENT
    unsigned long   bgRefreshInterval;
    struct timeval  lastCNotify;			/* Time of the last
							   CNotify event */
#endif
    struct timeval  timeout[NUM_TIMEOUTS];

    /*
     * These three don't need to be kept but do so to placate some memory
     * checkers
     */
    char*	    env_windowid;			/* environmental
							   variable WINDOWID */
    char*	    env_display;			/* environmental
							   variable DISPLAY */
    char*	    env_term;				/* environmental
							   variable TERM */
    char*	    env_tabtitle;			/* environmental
							   variable
							   MRXVT_TABTITLE*/
    char*	    env_colorfgbg;
    char*	    buffer;
    char*	    locale;

#if 0
    unsigned char*  v_buffer;
    unsigned char*  v_bufstr;
    unsigned char*  v_bufptr;
    unsigned char*  v_bufend;
#endif

    char*	    newfont[MAX_NFONTS];
    const char*	    rs[NUM_RESOURCES];

#if 0    /* command input buffering */
    unsigned char*  cmdbuf_ptr, *cmdbuf_endp;
    unsigned char   cmdbuf_base[BUFSIZ];
    unsigned char   kbuf[KBUFSZ];
#endif

#ifdef TRANSPARENT
    Pixmap	rootPixmap;				/* Pixmap ID of the root
							   pixmap */
    unsigned	rpWidth,				/* Dimensions of the
							   root pixmap */
		rpHeight;
    XRectangle	prevPos;				/* Previous onscreen
							   position */
    Bool	bgGrabbed;				/* whether the bg was
							   succesfully grabbed
							   at prevPos */
#endif
};

#ifndef __attribute__
# ifdef __GNUC__
#  if (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || (__GNUC__ < 2)
#   define __attribute__(x)
#  endif
# endif
# define __attribute__(x)
#endif

/*
 *****************************************************************************
 * PROTOTYPES
 *****************************************************************************
 */
#define __PROTO(p)  p
#include "protos.h"

#ifdef OUR_STRINGS
# define MEMSET(x, y, z)	ma_memset((x), (y), (size_t)(z))
# define MEMCPY(x, y, z)	ma_memcpy((void *)(x), (const void *)(y), (z))
# define MEMMOVE(x, y, z)	ma_memmove((void *)(x), (const void *)(y), (z))
# define STRCASECMP(x, y)	ma_strcasecmp((x), (y))
# define STRNCASECMP(x, y, z)	ma_strncasecmp((x), (y), (z))
# define STRCPY(x, y)		ma_strcpy((char *)(x), (const char *)(y))
# define STRNCPY(x, y, z)	ma_strncpy((char *)(x), (const char *)(y), (z))
# define STRCMP(x, y)		ma_strcmp((const char *)(x), (const char *)(y))
# define STRNCMP(x, y, z)	ma_strncmp((const char *)(x), (const char *)(y), (z))
# define STRCAT(x, y)		ma_strcat((char *)(x), (const char *)(y))
# define STRNCAT(x, y, z)	ma_strncat((char *)(x), (const char *)(y), (z))
# define STRDUP(x)		ma_strdup((const char *)(x))
# define STRNDUP(x, z)		ma_strndup((const char TAINTED *)(x), (size_t) (z))
# define STRLEN(x)		ma_strlen((const char *)(x))
# define STRCHR(x, y)		ma_strchr((const char *)(x), (int)(y))
# define STRRCHR(x, y)		ma_strrchr((const char *)(x), (int)(y))

#else /* OUR_STRINGS */

# define MEMSET(x, y, z)	memset((x), (y), (size_t)(z))
# define MEMCPY(x, y, z)	memcpy((void *)(x), (const void *)(y), (z))
# define MEMMOVE(x, y, z)	memmove((void *)(x), (const void *)(y), (z))
# define STRCASECMP(x, y)	strcasecmp((x), (y))
# define STRNCASECMP(x, y, z)	strncasecmp((x), (y), (z))
# define STRCPY(x, y)		strcpy((char *)(x), (const char *)(y))
# define STRNCPY(x, y, z)	strncpy((char *)(x), (const char *)(y), (z))
# define STRCMP(x, y)		strcmp((const char *)(x), (const char *)(y))
# define STRNCMP(x, y, z)	strncmp((const char *)(x), (const char *)(y), (z))
# define STRCAT(x, y)		strcat((char *)(x), (const char *)(y))
# define STRLEN(x)		strlen((const char *)(x))
# define STRNCAT(x, y, z)	strncat((char *)(x), (const char *)(y), (z))

/* if use our own malloc function, we must NOT use system provided
 * strdup or strndup because we want to free the memory allocated
 * by strdup/strndup using our free function
 */
# if defined(HAVE_STRDUP) && !defined(OUR_MALLOC)
#  define STRDUP(x)		strdup((const char *)(x))
# else
#  define STRDUP(x)		ma_strdup((const char *)(x))
# endif

# if defined(HAVE_STRNDUP) && !defined(OUR_MALLOC)
#  define STRNDUP(x, z)		strndup((const char TAINTED *)(x), (size_t) (z))
# else
#  define STRNDUP(x, z)		ma_strndup((const char TAINTED *)(x), (size_t) (z))
# endif

# ifdef HAVE_STRCHR
#  define STRCHR(x, y)		strchr((const char *)(x), (int)(y))
# else
#  define STRCHR(x, y)		ma_strchr((const char *)(x), (int)(y))
# endif

# ifdef HAVE_STRRCHR
#  define STRRCHR(x, y)		strrchr((const char *)(x), (int)(y))
# else
#  define STRRCHR(x, y)		ma_strrchr((const char *)(x), (int)(y))
# endif
#endif	/* OUR_STRINGS */

# define STRSTR(x, y)		strstr((const char *)(x), (const char*)(y))
/*
 * strcasestr is not provided by Cygwin's libraries, so we have to check for it
 * here. Thanks to Teun Burgers for pointing this out.
 */
# ifdef HAVE_STRCASESTR
#  define STRCASESTR( x, y)	strcasestr( (x), (y) )
# else
#  define STRCASESTR( x, y)	ma_strcasestr( (x), (y))
# endif


#define TWIN_WIDTH(R)	((R)->szHint.width)
#define TWIN_HEIGHT(R)	((R)->szHint.height)
#define VT_WIDTH(R)	((R)->szHint.width - \
	(R)->szHint.base_width + 2*(R)->TermWin.int_bwidth)
#define VT_HEIGHT(R)	((R)->szHint.height - \
	(R)->szHint.base_height + 2*(R)->TermWin.int_bwidth)
/*
#define TWIN_WIDTH(R)	\
    ((R)->szHint.width - 2*(R)->TermWin.int_bwidth)
#define TWIN_HEIGHT(R)	\
    ((R)->szHint.height - 2*(R)->TermWin.int_bwidth)
#define VT_WIDTH(R)	\
    ((R)->szHint.width - (R)->szHint.base_width)
#define VT_HEIGHT(R)	\
    ((R)->szHint.height - (R)->szHint.base_height)
*/


#ifndef XTERM_COLOR_CHANGE
# define rxvt_set_window_color(r, page, idx, color) ()
#endif

/* This comes last */
/*
#ifdef DEBUG_malloc
# include "dmalloc.h"
#endif
*/

#endif		    /* __RXVT_H__ */
/*----------------------- end-of-file (H source) -----------------------*/