-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.c
1136 lines (1052 loc) · 24.9 KB
/
trace.c
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
/* $XTermId: trace.c,v 1.166 2016/10/05 09:16:01 tom Exp $ */
/*
* Copyright 1997-2015,2016 by Thomas E. Dickey
*
* All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name(s) of the above copyright
* holders shall not be used in advertising or otherwise to promote the
* sale, use or other dealings in this Software without prior written
* authorization.
*/
/*
* debugging support via TRACE macro.
*/
#include <xterm.h> /* for definition of GCC_UNUSED */
#include <version.h>
#if OPT_TRACE
#include <data.h>
#include <trace.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
#include <X11/Xatom.h>
#include <X11/Xmu/Atoms.h>
#ifdef HAVE_X11_TRANSLATEI_H
#include <X11/ConvertI.h>
#include <X11/TranslateI.h>
#else
#ifdef __cplusplus
extern "C" {
#endif
extern String _XtPrintXlations(Widget w,
XtTranslations xlations,
Widget accelWidget,
_XtBoolean includeRHS);
#ifdef __cplusplus
}
#endif
#endif
const char *trace_who = "parent";
static FILE *trace_fp;
void
Trace(const char *fmt,...)
{
static const char *trace_out;
va_list ap;
if (trace_fp != 0
&& trace_who != trace_out) {
fclose(trace_fp);
trace_fp = 0;
}
trace_out = trace_who;
if (!trace_fp) {
unsigned oldmask = (unsigned) umask(077);
char name[BUFSIZ];
#if 0 /* usually I do not want unique names */
int unique;
for (unique = 0;; ++unique) {
if (unique)
sprintf(name, "Trace-%s.out-%d", trace_who, unique);
else
sprintf(name, "Trace-%s.out", trace_who);
if ((trace_fp = fopen(name, "r")) == 0) {
break;
}
fclose(trace_fp);
}
#else
sprintf(name, "Trace-%s.out", trace_who);
#endif
trace_fp = fopen(name, "w");
/*
* Try to put the trace-file in user's home-directory if the current
* directory is not writable.
*/
if (trace_fp == 0) {
char *home = getenv("HOME");
if (home != 0) {
sprintf(name, "%.*s/Trace-%.8s.out",
(BUFSIZ - 21), home,
trace_who);
trace_fp = fopen(name, "w");
}
}
if (trace_fp != 0) {
fprintf(trace_fp, "%s\n", xtermVersion());
TraceIds(NULL, 0);
}
if (!trace_fp) {
xtermWarning("Cannot open \"%s\"\n", name);
exit(EXIT_FAILURE);
}
(void) umask(oldmask);
}
va_start(ap, fmt);
vfprintf(trace_fp, fmt, ap);
(void) fflush(trace_fp);
va_end(ap);
}
void
TraceClose(void)
{
if (trace_fp != 0) {
(void) fclose(trace_fp);
(void) fflush(stdout);
(void) fflush(stderr);
(void) visibleChars(NULL, 0);
(void) visibleIChars(NULL, 0);
trace_fp = 0;
}
}
void
TraceIds(const char *fname, int lnum)
{
Trace("process %d ", (int) getpid());
#ifdef HAVE_UNISTD_H
Trace("real (%u/%u) effective (%u/%u)",
(unsigned) getuid(), (unsigned) getgid(),
(unsigned) geteuid(), (unsigned) getegid());
#endif
if (fname != 0) {
Trace(" (%s@%d)\n", fname, lnum);
} else {
time_t now = time((time_t *) 0);
Trace("-- %s", ctime(&now));
}
}
void
TraceTime(const char *fname, int lnum)
{
time_t now;
if (fname != 0) {
Trace("datetime (%s@%d) ", fname, lnum);
}
now = time((time_t *) 0);
Trace("-- %s", ctime(&now));
}
static void
formatAscii(char *dst, unsigned value)
{
switch (value) {
case '\\':
sprintf(dst, "\\\\");
break;
case '\b':
sprintf(dst, "\\b");
break;
case '\n':
sprintf(dst, "\\n");
break;
case '\r':
sprintf(dst, "\\r");
break;
case '\t':
sprintf(dst, "\\t");
break;
default:
if (E2A(value) < 32 || (E2A(value) >= 127 && E2A(value) < 160))
sprintf(dst, "\\%03o", value & 0xff);
else
sprintf(dst, "%c", CharOf(value));
break;
}
}
#if OPT_DEC_CHRSET
const char *
visibleDblChrset(unsigned chrset)
{
const char *result = "?";
switch (chrset) {
case CSET_SWL:
result = "CSET_SWL";
break;
case CSET_DHL_TOP:
result = "CSET_DHL_TOP";
break;
case CSET_DHL_BOT:
result = "CSET_DHL_BOT";
break;
case CSET_DWL:
result = "CSET_DWL";
break;
}
return result;
}
#endif
const char *
visibleScsCode(int chrset)
{
#define MAP(to,from) case from: result = to; break
const char *result = "<ERR>";
switch ((DECNRCM_codes) chrset) {
MAP("B", nrc_ASCII);
MAP("A", nrc_British);
MAP("A", nrc_British_Latin_1);
MAP("&4", nrc_Cyrillic);
MAP("0", nrc_DEC_Spec_Graphic);
MAP("1", nrc_DEC_Alt_Chars);
MAP("2", nrc_DEC_Alt_Graphics);
MAP("<", nrc_DEC_Supp);
MAP("%5", nrc_DEC_Supp_Graphic);
MAP(">", nrc_DEC_Technical);
MAP("4", nrc_Dutch);
MAP("5", nrc_Finnish);
MAP("C", nrc_Finnish2);
MAP("R", nrc_French);
MAP("f", nrc_French2);
MAP("Q", nrc_French_Canadian);
MAP("9", nrc_French_Canadian2);
MAP("K", nrc_German);
MAP("\"?", nrc_Greek);
MAP("F", nrc_Greek_Supp);
MAP("\"4", nrc_Hebrew);
MAP("%=", nrc_Hebrew2);
MAP("H", nrc_Hebrew_Supp);
MAP("Y", nrc_Italian);
MAP("M", nrc_Latin_5_Supp);
MAP("L", nrc_Latin_Cyrillic);
MAP("`", nrc_Norwegian_Danish);
MAP("E", nrc_Norwegian_Danish2);
MAP("6", nrc_Norwegian_Danish3);
MAP("%6", nrc_Portugese);
MAP("&5", nrc_Russian);
MAP("%3", nrc_SCS_NRCS);
MAP("Z", nrc_Spanish);
MAP("7", nrc_Swedish);
MAP("H", nrc_Swedish2);
MAP("=", nrc_Swiss);
MAP("%0", nrc_Turkish);
MAP("%2", nrc_Turkish2);
MAP("<UNK>", nrc_Unknown);
}
#undef MAP
return result;
}
const char *
visibleChars(const Char *buf, unsigned len)
{
static char *result;
static unsigned used;
if (buf != 0) {
unsigned limit = ((len + 1) * 8) + 1;
if (limit > used) {
used = limit;
result = XtRealloc(result, used);
}
if (result != 0) {
char *dst = result;
*dst = '\0';
while (len--) {
unsigned value = *buf++;
formatAscii(dst, value);
dst += strlen(dst);
}
}
} else if (result != 0) {
free(result);
result = 0;
used = 0;
}
return NonNull(result);
}
const char *
visibleIChars(const IChar *buf, unsigned len)
{
static char *result;
static unsigned used;
if (buf != 0) {
unsigned limit = ((len + 1) * 8) + 1;
if (limit > used) {
used = limit;
result = XtRealloc(result, used);
}
if (result != 0) {
char *dst = result;
*dst = '\0';
while (len--) {
unsigned value = *buf++;
#if OPT_WIDE_CHARS
if (value > 255)
sprintf(dst, "\\u+%04X", value);
else
#endif
formatAscii(dst, value);
dst += strlen(dst);
}
}
} else if (result != 0) {
free(result);
result = 0;
used = 0;
}
return NonNull(result);
}
const char *
visibleUChar(unsigned chr)
{
IChar buf[1];
buf[0] = chr;
return visibleIChars(buf, 1);
}
const char *
visibleEventType(int type)
{
const char *result = "?";
switch (type) {
CASETYPE(KeyPress);
CASETYPE(KeyRelease);
CASETYPE(ButtonPress);
CASETYPE(ButtonRelease);
CASETYPE(MotionNotify);
CASETYPE(EnterNotify);
CASETYPE(LeaveNotify);
CASETYPE(FocusIn);
CASETYPE(FocusOut);
CASETYPE(KeymapNotify);
CASETYPE(Expose);
CASETYPE(GraphicsExpose);
CASETYPE(NoExpose);
CASETYPE(VisibilityNotify);
CASETYPE(CreateNotify);
CASETYPE(DestroyNotify);
CASETYPE(UnmapNotify);
CASETYPE(MapNotify);
CASETYPE(MapRequest);
CASETYPE(ReparentNotify);
CASETYPE(ConfigureNotify);
CASETYPE(ConfigureRequest);
CASETYPE(GravityNotify);
CASETYPE(ResizeRequest);
CASETYPE(CirculateNotify);
CASETYPE(CirculateRequest);
CASETYPE(PropertyNotify);
CASETYPE(SelectionClear);
CASETYPE(SelectionRequest);
CASETYPE(SelectionNotify);
CASETYPE(ColormapNotify);
CASETYPE(ClientMessage);
CASETYPE(MappingNotify);
}
return result;
}
const char *
visibleNotifyMode(int code)
{
const char *result = "?";
switch (code) {
CASETYPE(NotifyNormal);
CASETYPE(NotifyGrab);
CASETYPE(NotifyUngrab);
CASETYPE(NotifyWhileGrabbed);
}
return result;
}
const char *
visibleNotifyDetail(int code)
{
const char *result = "?";
switch (code) {
CASETYPE(NotifyAncestor);
CASETYPE(NotifyVirtual);
CASETYPE(NotifyInferior);
CASETYPE(NotifyNonlinear);
CASETYPE(NotifyNonlinearVirtual);
CASETYPE(NotifyPointer);
CASETYPE(NotifyPointerRoot);
CASETYPE(NotifyDetailNone);
}
return result;
}
const char *
visibleSelectionTarget(Display *d, Atom a)
{
const char *result = "?";
if (a == XA_STRING) {
result = "XA_STRING";
} else if (a == XA_TEXT(d)) {
result = "XA_TEXT()";
} else if (a == XA_COMPOUND_TEXT(d)) {
result = "XA_COMPOUND_TEXT()";
} else if (a == XA_UTF8_STRING(d)) {
result = "XA_UTF8_STRING()";
} else if (a == XA_TARGETS(d)) {
result = "XA_TARGETS()";
}
return result;
}
const char *
visibleTekparse(int code)
{
static const struct {
int code;
const char *name;
} table[] = {
#include "Tekparse.cin"
};
const char *result = "?";
Cardinal n;
for (n = 0; n < XtNumber(table); ++n) {
if (table[n].code == code) {
result = table[n].name;
break;
}
}
return result;
}
const char *
visibleVTparse(int code)
{
static const struct {
int code;
const char *name;
} table[] = {
#include "VTparse.cin"
};
const char *result = "?";
Cardinal n;
for (n = 0; n < XtNumber(table); ++n) {
if (table[n].code == code) {
result = table[n].name;
break;
}
}
return result;
}
const char *
visibleXError(int code)
{
static char temp[80];
const char *result = "?";
switch (code) {
CASETYPE(Success);
CASETYPE(BadRequest);
CASETYPE(BadValue);
CASETYPE(BadWindow);
CASETYPE(BadPixmap);
CASETYPE(BadAtom);
CASETYPE(BadCursor);
CASETYPE(BadFont);
CASETYPE(BadMatch);
CASETYPE(BadDrawable);
CASETYPE(BadAccess);
CASETYPE(BadAlloc);
CASETYPE(BadColor);
CASETYPE(BadGC);
CASETYPE(BadIDChoice);
CASETYPE(BadName);
CASETYPE(BadLength);
CASETYPE(BadImplementation);
default:
sprintf(temp, "%d", code);
result = temp;
break;
}
return result;
}
#if OPT_TRACE_FLAGS
#define isScrnFlag(flag) ((flag) == LINEWRAPPED)
static char *
ScrnText(LineData *ld)
{
return visibleIChars(ld->charData, ld->lineSize);
}
#define SHOW_BAD_LINE(name, ld) \
Trace("OOPS " #name " bad row\n")
#define SHOW_SCRN_FLAG(name,code) \
Trace(#name " %s:%s\n", \
code ? "*" : "", \
ScrnText(ld))
void
LineClrFlag(LineData *ld, int flag)
{
if (ld == 0) {
SHOW_BAD_LINE(LineClrFlag, ld);
assert(0);
} else if (isScrnFlag(flag)) {
SHOW_SCRN_FLAG(LineClrFlag, 0);
}
LineFlags(ld) &= ~flag;
}
void
LineSetFlag(LineData *ld, int flag)
{
if (ld == 0) {
SHOW_BAD_LINE(LineSetFlag, ld);
assert(0);
} else if (isScrnFlag(flag)) {
SHOW_SCRN_FLAG(LineSetFlag, 1);
}
LineFlags(ld) |= flag;
}
int
LineTstFlag(LineData ld, int flag)
{
int code = 0;
if (ld == 0) {
SHOW_BAD_LINE(LineTstFlag, ld);
} else {
code = LineFlags(ld);
if (isScrnFlag(flag)) {
SHOW_SCRN_FLAG(LineTstFlag, code);
}
}
return code;
}
#endif /* OPT_TRACE_FLAGS */
/*
* Trace the normal or alternate screen, showing color values up to 16, e.g.,
* for debugging with vttest.
*/
void
TraceScreen(XtermWidget xw, int whichBuf)
{
TScreen *screen = TScreenOf(xw);
if (screen->editBuf_index[whichBuf]) {
int row;
TRACE(("TraceScreen %d:\n", whichBuf));
for (row = 0; row <= screen->max_row; ++row) {
LineData *ld = getLineData(screen, row);
TRACE((" %3d:", row));
if (ld != 0) {
int col;
for (col = 0; col < ld->lineSize; ++col) {
int ch = (int) ld->charData[col];
if (ch < ' ')
ch = ' ';
if (ch >= 127)
ch = '#';
TRACE(("%c", ch));
}
TRACE((":\n"));
TRACE((" xx:"));
for (col = 0; col < ld->lineSize; ++col) {
unsigned attrs = ld->attribs[col];
char ch;
if (attrs & PROTECTED) {
ch = '*';
} else if (attrs & BLINK) {
ch = 'B';
} else if (attrs & CHARDRAWN) {
ch = '+';
} else {
ch = ' ';
}
TRACE(("%c", ch));
}
TRACE((":\n"));
#if 0
TRACE((" fg:"));
for (col = 0; col < ld->lineSize; ++col) {
unsigned fg = extract_fg(xw, ld->color[col], ld->attribs[col]);
if (fg > 15)
fg = 15;
TRACE(("%1x", fg));
}
TRACE((":\n"));
TRACE((" bg:"));
for (col = 0; col < ld->lineSize; ++col) {
unsigned bg = extract_bg(xw, ld->color[col], ld->attribs[col]);
if (bg > 15)
bg = 15;
TRACE(("%1x", bg));
}
TRACE((":\n"));
#endif
} else {
TRACE(("null lineData\n"));
}
}
} else {
TRACE(("TraceScreen %d is nil\n", whichBuf));
}
}
void
TraceFocus(Widget w, XEvent *ev)
{
TRACE(("trace_focus event type %d:%s\n",
ev->type, visibleEventType(ev->type)));
switch (ev->type) {
case FocusIn:
case FocusOut:
{
XFocusChangeEvent *event = (XFocusChangeEvent *) ev;
TRACE(("\tdetail: %s\n", visibleNotifyDetail(event->detail)));
TRACE(("\tmode: %s\n", visibleNotifyMode(event->mode)));
TRACE(("\twindow: %#lx\n", event->window));
}
break;
case EnterNotify:
case LeaveNotify:
{
XCrossingEvent *event = (XCrossingEvent *) ev;
TRACE(("\tdetail: %s\n", visibleNotifyDetail(event->detail)));
TRACE(("\tmode: %s\n", visibleNotifyMode(event->mode)));
TRACE(("\twindow: %#lx\n", event->window));
TRACE(("\tfocus: %d\n", event->focus));
TRACE(("\troot: %#lx\n", event->root));
TRACE(("\tsubwindow: %#lx\n", event->subwindow));
}
break;
}
while (w != 0) {
TRACE(("w %p -> %#lx\n", (void *) w, XtWindow(w)));
w = XtParent(w);
}
}
void
TraceSizeHints(XSizeHints * hints)
{
TRACE(("size hints:\n"));
if (hints->flags & (USPosition | PPosition))
TRACE((" position %d,%d%s%s\n", hints->y, hints->x,
(hints->flags & USPosition) ? " user" : "",
(hints->flags & PPosition) ? " prog" : ""));
if (hints->flags & (USSize | PSize))
TRACE((" size %d,%d%s%s\n", hints->height, hints->width,
(hints->flags & USSize) ? " user" : "",
(hints->flags & PSize) ? " prog" : ""));
if (hints->flags & PMinSize)
TRACE((" min %d,%d\n", hints->min_height, hints->min_width));
if (hints->flags & PMaxSize)
TRACE((" max %d,%d\n", hints->max_height, hints->max_width));
if (hints->flags & PResizeInc)
TRACE((" inc %d,%d\n", hints->height_inc, hints->width_inc));
else
TRACE((" inc NONE!\n"));
if (hints->flags & PAspect)
TRACE((" min aspect %d/%d\n", hints->min_aspect.y, hints->min_aspect.y));
if (hints->flags & PAspect)
TRACE((" max aspect %d/%d\n", hints->max_aspect.y, hints->max_aspect.y));
if (hints->flags & PBaseSize)
TRACE((" base %d,%d\n", hints->base_height, hints->base_width));
if (hints->flags & PWinGravity)
TRACE((" gravity %d\n", hints->win_gravity));
}
static void
TraceEventMask(const char *tag, long mask)
{
#define DATA(name) { name##Mask, #name }
/* *INDENT-OFF* */
static struct {
long mask;
const char *name;
} table[] = {
DATA(KeyPress),
DATA(KeyRelease),
DATA(ButtonPress),
DATA(ButtonRelease),
DATA(EnterWindow),
DATA(LeaveWindow),
DATA(PointerMotion),
DATA(PointerMotionHint),
DATA(Button1Motion),
DATA(Button2Motion),
DATA(Button3Motion),
DATA(Button4Motion),
DATA(Button5Motion),
DATA(ButtonMotion),
DATA(KeymapState),
DATA(Exposure),
DATA(VisibilityChange),
DATA(StructureNotify),
DATA(ResizeRedirect),
DATA(SubstructureNotify),
DATA(SubstructureRedirect),
DATA(FocusChange),
DATA(PropertyChange),
DATA(ColormapChange),
DATA(OwnerGrabButton),
};
#undef DATA
Cardinal n;
/* *INDENT-ON* */
for (n = 0; n < XtNumber(table); ++n) {
if (table[n].mask & mask) {
TRACE(("%s %s\n", tag, table[n].name));
}
}
}
void
TraceWindowAttributes(XWindowAttributes * attrs)
{
TRACE(("window attributes:\n"));
TRACE((" position %d,%d\n", attrs->y, attrs->x));
TRACE((" size %dx%d\n", attrs->height, attrs->width));
TRACE((" border %d\n", attrs->border_width));
TRACE((" depth %d\n", attrs->depth));
TRACE((" bit_gravity %d\n", attrs->bit_gravity));
TRACE((" win_gravity %d\n", attrs->win_gravity));
TRACE((" root %#lx\n", (long) attrs->root));
TRACE((" class %s\n", ((attrs->class == InputOutput)
? "InputOutput"
: ((attrs->class == InputOnly)
? "InputOnly"
: "unknown"))));
TRACE((" map_state %s\n", ((attrs->map_state == IsUnmapped)
? "IsUnmapped"
: ((attrs->map_state == IsUnviewable)
? "IsUnviewable"
: ((attrs->map_state == IsViewable)
? "IsViewable"
: "unknown")))));
TRACE((" all_events\n"));
TraceEventMask(" ", attrs->all_event_masks);
TRACE((" your_events\n"));
TraceEventMask(" ", attrs->your_event_mask);
TRACE((" no_propagate\n"));
TraceEventMask(" ", attrs->do_not_propagate_mask);
}
void
TraceWMSizeHints(XtermWidget xw)
{
XSizeHints sizehints = xw->hints;
getXtermSizeHints(xw);
TraceSizeHints(&xw->hints);
xw->hints = sizehints;
}
/*
* Some calls to XGetAtom() will fail, and we don't want to stop. So we use
* our own error-handler.
*/
/* ARGSUSED */
static int
no_error(Display *dpy GCC_UNUSED, XErrorEvent *event GCC_UNUSED)
{
return 1;
}
const char *
ModifierName(unsigned modifier)
{
const char *s = "";
if (modifier & ShiftMask)
s = " Shift";
else if (modifier & LockMask)
s = " Lock";
else if (modifier & ControlMask)
s = " Control";
else if (modifier & Mod1Mask)
s = " Mod1";
else if (modifier & Mod2Mask)
s = " Mod2";
else if (modifier & Mod3Mask)
s = " Mod3";
else if (modifier & Mod4Mask)
s = " Mod4";
else if (modifier & Mod5Mask)
s = " Mod5";
return s;
}
void
TraceTranslations(const char *name, Widget w)
{
String result;
XErrorHandler save = XSetErrorHandler(no_error);
XtTranslations xlations;
Widget xcelerat;
TRACE(("TraceTranslations for %s (widget %#lx) {{\n", name, (long) w));
if (w) {
XtVaGetValues(w,
XtNtranslations, &xlations,
XtNaccelerators, &xcelerat,
(XtPointer) 0);
TRACE(("... xlations %#08lx\n", (long) xlations));
TRACE(("... xcelerat %#08lx\n", (long) xcelerat));
result = _XtPrintXlations(w, xlations, xcelerat, True);
TRACE(("%s\n", NonNull(result)));
if (result)
XFree((char *) result);
} else {
TRACE(("none (widget is null)\n"));
}
TRACE(("}}\n"));
XSetErrorHandler(save);
}
XtGeometryResult
TraceResizeRequest(const char *fn, int ln, Widget w,
unsigned reqwide,
unsigned reqhigh,
Dimension *gotwide,
Dimension *gothigh)
{
XtGeometryResult rc;
TRACE(("%s@%d ResizeRequest %ux%u\n", fn, ln, reqhigh, reqwide));
rc = XtMakeResizeRequest((Widget) w,
(Dimension) reqwide,
(Dimension) reqhigh,
gotwide, gothigh);
TRACE(("... ResizeRequest -> "));
if (gothigh && gotwide)
TRACE(("%dx%d ", *gothigh, *gotwide));
TRACE(("(%d)\n", rc));
return rc;
}
#define XRES_S(name) Trace(#name " = %s\n", NonNull(resp->name))
#define XRES_B(name) Trace(#name " = %s\n", MtoS(resp->name))
#define XRES_I(name) Trace(#name " = %d\n", resp->name)
void
TraceXtermResources(void)
{
XTERM_RESOURCE *resp = &resource;
Trace("XTERM_RESOURCE settings:\n");
XRES_S(icon_geometry);
XRES_S(title);
XRES_S(icon_hint);
XRES_S(icon_name);
XRES_S(term_name);
XRES_S(tty_modes);
XRES_I(minBufSize);
XRES_I(maxBufSize);
XRES_B(hold_screen);
XRES_B(utmpInhibit);
XRES_B(utmpDisplayId);
XRES_B(messages);
XRES_S(menuLocale);
XRES_S(omitTranslation);
XRES_S(keyboardType);
#if OPT_PRINT_ON_EXIT
XRES_I(printModeNow);
XRES_I(printModeOnXError);
XRES_I(printOptsNow);
XRES_I(printOptsOnXError);
XRES_S(printFileNow);
XRES_S(printFileOnXError);
#endif
#if OPT_SUNPC_KBD
XRES_B(sunKeyboard);
#endif
#if OPT_HP_FUNC_KEYS
XRES_B(hpFunctionKeys);
#endif
#if OPT_SCO_FUNC_KEYS
XRES_B(scoFunctionKeys);
#endif
#if OPT_SUN_FUNC_KEYS
XRES_B(sunFunctionKeys);
#endif
#if OPT_INITIAL_ERASE
XRES_B(ptyInitialErase);
XRES_B(backarrow_is_erase);
#endif
XRES_B(useInsertMode);
#if OPT_ZICONBEEP
XRES_I(zIconBeep);
XRES_S(zIconFormat);
#endif
#if OPT_PTY_HANDSHAKE
XRES_B(wait_for_map);
XRES_B(ptyHandshake);
XRES_B(ptySttySize);
#endif
#if OPT_REPORT_COLORS
XRES_B(reportColors);
#endif
#if OPT_REPORT_FONTS
XRES_B(reportFonts);
#endif
#if OPT_SAME_NAME
XRES_B(sameName);
#endif
#if OPT_SESSION_MGT
XRES_B(sessionMgt);
#endif
#if OPT_TOOLBAR
XRES_B(toolBar);
#endif
#if OPT_MAXIMIZE
XRES_B(maximized);
XRES_S(fullscreen_s);
#endif
}
void
TraceArgv(const char *tag, char **argv)
{
int n = 0;
TRACE(("%s:\n", tag));
while (*argv != 0) {
TRACE((" %d:%s\n", n++, *argv++));
}
}
static char *
parse_option(char *dst, String src, int first)
{
char *s;
if (!strncmp(src, "-/+", (size_t) 3)) {
dst[0] = (char) first;
strcpy(dst + 1, src + 3);
} else {
strcpy(dst, src);
}
for (s = dst; *s != '\0'; s++) {
if (*s == '#' || *s == '%' || *s == 'S') {
s[1] = '\0';
} else if (*s == ' ') {
*s = '\0';
break;
}
}
return dst;
}
static Bool