1 /**
2 *
3 * $Id: DebugUtil.c,v 1.14 2006/04/19 18:42:22 dannybackx Exp $
4 *
5 * Copyright (C) 1995 Free Software Foundation, Inc.
6 * Copyright � 1995-2002, 2004, 2005 LessTif Development Team
7 *
8 * This file is part of the GNU LessTif Library.
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 **/
25
26 static const char rcsid[] = "$Id: DebugUtil.c,v 1.14 2006/04/19 18:42:22 dannybackx Exp $";
27
28 #include <LTconfig.h>
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <stdarg.h>
33 #include <string.h>
34 #include <signal.h>
35 #ifdef HAVE_SYS_TYPES_H
36 #include <sys/types.h>
37 #endif
38 #include <unistd.h>
39
40 #ifdef HAVE_BACKTRACE
41 #include <execinfo.h>
42 #endif
43
44 #include <X11/Intrinsic.h>
45 #include <X11/IntrinsicP.h>
46 #include <X11/Xresource.h>
47
48 #include <XmI/XmI.h>
49 #include <Xm/XmP.h>
50 #include <Xm/DrawingAP.h>
51 #include <Xm/Display.h>
52 #include <Xm/MwmUtil.h>
53
54 /* for strcasecmp(), etc. */
55 #include <XmI/LTmisc.h>
56
57 /* This includes <dmalloc.h> if required */
58 #include <XmI/DebugUtil.h>
59
60
61 #ifdef WITH_DMALLOC
62 /* internal interface from Intrinsics.
63 * The "const" is probably not in the real sources...
64 */
65 extern void _XtAllocError(const char *);
66
67 #else
68
69 /* Our Xt*alloc() replacements for dmalloc. To keep the public/external
70 library entries unchanged we also supply stubs for those if
71 not using dmalloc. */
72 XtPointer _LtDebugMalloc(const char *f, int l, Cardinal size);
73 XtPointer _LtDebugCalloc(const char *f, int l, Cardinal count, Cardinal size);
74 XtPointer _LtDebugRealloc(const char *f, int l, XtPointer p, Cardinal size);
75 void _LtDebugFree(const char *f, int l, XtPointer p);
76 #endif
77
78 /* "Correct" some defines: */
79 #ifdef _LtDebugInDebug
80 #undef _LtDebugInDebug
81 #endif
82
83 Boolean _LtDebugInDebug(const char *fn, Widget w);
84
85
86 #ifndef LESSTIF_PRODUCTION
87 /* All external interfaces need to be in place for both,
88 debug and production build. We may just reduce them
89 to empty stubs ... */
90 static void _LtDebugOpenFile(void);
91 static Boolean __LtDebugPrintWidgetID(void);
92 static void sighandler(int signo);
93 static Boolean siginstall(void);
94 #endif
95
96 /*
97 * some #defines being used here
98 */
99 #undef DEBUGSIG /* debug the 'signal feature' */
100 #undef DEBUGVALIDATE /* debug the ValidateSource(), etc. routines */
101 #undef PRINT_STATE /* add info to __LtDebugPrintTree() output */
102
103
104 /*
105 * Functionality in this file is influenced at run time by these
106 * environment variables :
107 *
108 * - DEBUG_SOURCES : colon-separated list of files from which debug output
109 * is generated.
110 * Special values "all" and "none" have obvious meaning.
111 * You may block file from the list by adding a "-" prefix,
112 * this is obviously only useful in conjunction with "all",
113 * e.g. DEBUG_SOURCES=all:-Vendor.c:-XmString
114 * Using an asterisk as a wildcard is also supported, e.g.
115 * DEBUG_SOURCES=Text*
116 * The code may not be failsafe for some pathological combinations,
117 * but we don't expect anyone to debug the debugging code ... ;-)
118 *
119 * - DEBUG_PRINT_WIDGETID : if this variable exists, then all widgets printed
120 * with _LtDebug etc. will also print their widget ID. If the variable
121 * doesn't exist, then they only print their name for identification.
122 *
123 * - DEBUG_FILE : if this variable exists, then the file is used for output.
124 * If "%p" is part of the value of DEBUG_FILE, then it is replaced by the
125 * process id.
126 * "stdout" and "stderr" are recognized and have their special
127 * obvious meaning.
128 *
129 * - DEBUG_SIGNAL: define to the macro which belongs to the signal which
130 * should be accepted by the program as a switch to toggle
131 * debugging on/off. No value or "none" will turn the feature off.
132 * Valid values are compile time dependent (WRT libXm),
133 * check below what's actually supported.
134 *
135 * - DEBUG_TOGGLE: initial value whether debugging should be
136 * enabled or disabled upon program start. Valid Values are on/off.
137 * e.g. DEBUG_TOGGLE=off
138 *
139 * If the C macro LESSTIF_PRODUCTION is defined, then _LtDebug etc. don't
140 * work. Note: this is a compile time option.
141 * To have maximum performance, sequences of _LtDebug statements should be
142 * surrounded by an if (_LtDebugInDebug(__FILE__, w)) statement.
143 * _LtDebugInDebug is False when LESSTIF_PRODUCTION is defined.
144 */
145
146
147
148 #ifndef LESSTIF_PRODUCTION
149 static Boolean _LtDebugFlag = True;
150 static FILE *_LtDebugFile = NULL;
151 typedef void (*sighandler_t)(int);
152 #endif
153
154
155 #define _LtDebugNONE 0
156 #define _LtDebugINT 1
157 #define _LtDebugSTRING 2
158 #define _LtDebugXMSTRING 3
159 #define _LtDebugCHAR 4
160 #define _LtDebugSHORT 5
161 #define _LtDebugATTACHMENT 6
162 #define _LtDebugWIDGET 7
163 #define _LtDebugBOOLEAN 8
164 #define _LtDebugSELECTION_POLICY 9
165 #define _LtDebugXMSTRING_LIST 10 /* bingo */
166 #define _LtDebugDIALOG_STYLE 11
167 #define _LtDebugEDIT_MODE 12
168 #define _LtDebugALIGNMENT 13
169 #define _LtDebugSB_DISPLAY_POLICY 14
170 #define _LtDebugLIST_SIZE_POLICY 15
171 #define _LtDebugSB_PLACEMENT 16
172 #define _LtDebugRESIZE_POLICY 17
173 #define _LtDebugCOMBOBOX_TYPE 18
174 #define _LtDebugSCROLLING_POLICY 19
175 #define _LtDebugDRAG_TYPE 20
176 #define _LtDebugMWM_INPUT_MODE 21
177 #define _LtDebugDELETE_RESPONSE 22
178 #define _LtDebugRENDERTABLE 23
179
180
181
182 static const struct
183 {
184 const char *name;
185 int t;
186 const char *related;
187 } _LtDebugTypes[] =
188 {
189 { XmNdragInitiatorProtocolStyle, _LtDebugDRAG_TYPE, NULL } ,
190 { XmNdragReceiverProtocolStyle, _LtDebugDRAG_TYPE, NULL } ,
191 { XmNscrollingPolicy, _LtDebugSCROLLING_POLICY, NULL } ,
192 { XmNmaximum, _LtDebugINT, NULL } ,
193 { XmNminimum, _LtDebugINT, NULL } ,
194 { XmNsliderSize, _LtDebugINT, NULL } ,
195 { XmNpageIncrement, _LtDebugINT, NULL } ,
196 { XmNincrement, _LtDebugINT, NULL } ,
197 { XmNx, _LtDebugINT, NULL } ,
198 { XmNy, _LtDebugINT, NULL } ,
199 { XmNwidth, _LtDebugINT, NULL } ,
200 { XmNheight, _LtDebugINT, NULL } ,
201 { XmNlabelString, _LtDebugXMSTRING, NULL } ,
202 { XmNmessageString, _LtDebugXMSTRING, NULL } ,
203 { XmNrowColumnType, _LtDebugNONE, NULL } ,
204 { XmNbuttonSet, _LtDebugNONE, NULL } ,
205 { XmNbuttonCount, _LtDebugINT, NULL } ,
206 { XmNoptionLabel, _LtDebugXMSTRING, NULL } ,
207 { XmNdirectory, _LtDebugXMSTRING, NULL } ,
208 { XmNoptionMnemonic, _LtDebugCHAR, NULL } ,
209 { XmNrows, _LtDebugSHORT, NULL } ,
210 { XmNcolumns, _LtDebugSHORT, NULL } ,
211 { XmNmarginWidth, _LtDebugINT, NULL } ,
212 { XmNmarginHeight, _LtDebugINT, NULL } ,
213 { XmNmarginTop, _LtDebugINT, NULL } ,
214 { XmNmarginBottom, _LtDebugINT, NULL } ,
215 { XmNmarginLeft, _LtDebugINT, NULL } ,
216 { XmNmarginRight, _LtDebugINT, NULL } ,
217 { XmNselectionArrayCount, _LtDebugINT, NULL } ,
218 { XmNshadowThickness, _LtDebugINT, NULL } ,
219 { XmNhighlightThickness, _LtDebugINT, NULL } ,
220 { XmNtopAttachment, _LtDebugATTACHMENT, NULL } ,
221 { XmNbottomAttachment, _LtDebugATTACHMENT, NULL } ,
222 { XmNleftAttachment, _LtDebugATTACHMENT, NULL } ,
223 { XmNrightAttachment, _LtDebugATTACHMENT, NULL } ,
224 { XmNtopOffset, _LtDebugINT, NULL } ,
225 { XmNbottomOffset, _LtDebugINT, NULL } ,
226 { XmNleftOffset, _LtDebugINT, NULL } ,
227 { XmNrightOffset, _LtDebugINT, NULL } ,
228 { XmNtopPosition, _LtDebugINT, NULL } ,
229 { XmNbottomPosition, _LtDebugINT, NULL } ,
230 { XmNleftPosition, _LtDebugINT, NULL } ,
231 { XmNrightPosition, _LtDebugINT, NULL } ,
232 { XmNdefaultButton, _LtDebugWIDGET, NULL } ,
233 { XmNmessageWindow, _LtDebugWIDGET, NULL } ,
234 { XmNtopWidget, _LtDebugWIDGET, NULL } ,
235 { XmNbottomWidget, _LtDebugWIDGET, NULL } ,
236 { XmNleftWidget, _LtDebugWIDGET, NULL } ,
237 { XmNrightWidget, _LtDebugWIDGET, NULL } ,
238 { XmNsensitive, _LtDebugBOOLEAN, NULL } ,
239 { XmNresizable, _LtDebugBOOLEAN, NULL } ,
240 { XmNmustMatch, _LtDebugBOOLEAN, NULL } ,
241 { XmNresizeHeight, _LtDebugBOOLEAN, NULL } ,
242 { XmNresizeWidth, _LtDebugBOOLEAN, NULL } ,
243 { XmNfractionBase, _LtDebugINT, NULL } ,
244 { XmNhorizontalSpacing, _LtDebugINT, NULL } ,
245 { XmNverticalSpacing, _LtDebugINT, NULL } ,
246 { XmNrubberPositioning, _LtDebugBOOLEAN, NULL } ,
247 { XmNitemCount, _LtDebugINT, NULL } ,
248 { XmNfileListItemCount, _LtDebugINT, NULL } ,
249 { XmNtextString, _LtDebugXMSTRING, NULL } ,
250 { XmNdirSpec, _LtDebugXMSTRING, NULL } ,
251 { XmNdirMask, _LtDebugXMSTRING, NULL } ,
252 { XmNitems, _LtDebugXMSTRING_LIST, XmNitemCount } , /* bingo */
253 { XmNselectionPolicy, _LtDebugSELECTION_POLICY, NULL } ,
254 { XmNautoUnmanage, _LtDebugBOOLEAN, NULL } ,
255 { XmNdialogStyle, _LtDebugDIALOG_STYLE, NULL } ,
256 { XmNshowAsDefault, _LtDebugSHORT, NULL } ,
257 { XmNeditable, _LtDebugBOOLEAN, NULL } ,
258 { XmNmaxLength, _LtDebugINT, NULL } ,
259 { XmNdirListItemCount, _LtDebugINT, NULL } ,
260 { XmNfileListItemCount, _LtDebugINT, NULL } ,
261 { XmNeditMode, _LtDebugEDIT_MODE, NULL } ,
262 { XmNalignment, _LtDebugALIGNMENT, NULL } ,
263 { XmNrecomputeSize, _LtDebugBOOLEAN, NULL } ,
264 { XmNdirectoryValid, _LtDebugBOOLEAN, NULL } ,
265 { XmNlistUpdated, _LtDebugBOOLEAN, NULL } ,
266 { XmNhorizontalScrollBar, _LtDebugWIDGET, NULL } ,
267 { XmNverticalScrollBar, _LtDebugWIDGET, NULL } ,
268 { XmNworkWindow, _LtDebugWIDGET, NULL } ,
269 { XmNmenuBar, _LtDebugWIDGET, NULL } ,
270 { XmNcommandWindow, _LtDebugWIDGET, NULL } ,
271 { XmNvisibleItemCount, _LtDebugSHORT, NULL } ,
272 { XmNdefaultButtonShadowThickness, _LtDebugSHORT, NULL } ,
273 { XmNset, _LtDebugBOOLEAN, NULL } ,
274 { XmNtraversalOn, _LtDebugBOOLEAN, NULL } ,
275 { XmNspacing, _LtDebugSHORT, NULL } ,
276 { XmNscrollBarDisplayPolicy, _LtDebugSB_DISPLAY_POLICY, NULL } ,
277 { XmNlistSizePolicy, _LtDebugLIST_SIZE_POLICY, NULL } ,
278 { XmNscrollBarPlacement, _LtDebugSB_PLACEMENT, NULL } ,
279 { XmNuserData, _LtDebugNONE, NULL } ,
280 { XmNallowShellResize, _LtDebugBOOLEAN, NULL } ,
281 { XmNresizePolicy, _LtDebugRESIZE_POLICY, NULL } ,
282 { XmNradioBehavior, _LtDebugBOOLEAN, NULL } ,
283 { XmNradioAlwaysOne, _LtDebugBOOLEAN, NULL } ,
284 { XmNnumColumns, _LtDebugSHORT, NULL } ,
285 { XmNinitialFocus, _LtDebugWIDGET, NULL } ,
286 { XmNmwmInputMode, _LtDebugMWM_INPUT_MODE, NULL } ,
287 { XmNmappedWhenManaged, _LtDebugBOOLEAN, NULL } ,
288 { XmNdeleteResponse, _LtDebugDELETE_RESPONSE, NULL } ,
289 { XmNwidthInc, _LtDebugSHORT, NULL } ,
290 { XmNheightInc, _LtDebugSHORT, NULL } ,
291 { XmNbaseWidth, _LtDebugSHORT, NULL } ,
292 { XmNbaseHeight, _LtDebugSHORT, NULL } ,
293 { XmNminWidth, _LtDebugSHORT, NULL } ,
294 { XmNminHeight, _LtDebugSHORT, NULL } ,
295 { XmNtitle, _LtDebugSTRING, NULL } ,
296 { XmNiconName, _LtDebugSTRING, NULL } ,
297 { XmNcancelLabelString, _LtDebugXMSTRING, NULL } ,
298 { XmNcomboBoxType, _LtDebugCOMBOBOX_TYPE, NULL } ,
299 { XmNlargeCellWidth, _LtDebugINT, NULL } ,
300 { XmNlargeCellHeight, _LtDebugINT, NULL } ,
301 { XmNacceleratorText, _LtDebugXMSTRING, NULL },
302 { XmNrenderTable, _LtDebugRENDERTABLE, NULL },
303 { XmNfontList, _LtDebugRENDERTABLE, NULL },
304 { XmNborderWidth, _LtDebugSHORT, NULL },
305 { NULL, 0, NULL }
306 /* the end */
307 };
308
309
310
311
312 #ifndef LESSTIF_PRODUCTION
313 /* catches the signal defined by DEBUG_SIGNAL and toggles the
314 global debugging flag.
315 Avoid calling C-runtime functions from within here if possible
316 (which in turn might also raise signals) */
317 static void
sighandler(int signo)318 sighandler (int signo)
319 {
320
321 #ifdef DEBUGSIG
322 fputs ("sighandler(): signal caught\n", stderr);
323 #endif
324
325 /* switch debugging on/off */
326 _LtDebugToggle();
327 /* re-install ourselves: perhaps not always necessary, but OTOH
328 it shouldn't hurt!? */
329 signal (signo, sighandler);
330 }
331
332
333 static Boolean
siginstall(void)334 siginstall (void)
335 {
336 const char *ptr;
337 #define NOSIG -1
338 static int signo = NOSIG;
339
340 ptr = getenv ("DEBUG_SIGNAL");
341 if (ptr)
342 {
343 #ifdef DEBUGSIG
344 fprintf (stderr, "siginstall(): trying to catch %s\n", ptr);
345 #endif
346 if ((*ptr == '\0')||(strcasecmp(ptr, "none")==0))
347 {
348 fprintf(stderr, "siginstall(): empty value for DEBUG_SIGNAL\n");
349 }
350 #if defined(SIGBREAK)
351 else if (strcmp (ptr, "SIGBREAK") == 0)
352 signo = SIGBREAK;
353 #endif
354 #if defined(SIGUNUSED)
355 else if (strcmp (ptr, "SIGUNUSED") == 0)
356 signo = SIGUNUSED;
357 #endif
358 #if defined(SIGUSR1)
359 else if (strcmp (ptr, "SIGUSR1") == 0)
360 signo = SIGUSR1;
361 #endif
362 #if defined(SIGUSR2)
363 else if (strcmp (ptr, "SIGUSR2") == 0)
364 signo = SIGUSR2;
365 #endif
366 #if defined(SIGUSR3)
367 else if (strcmp (ptr, "SIGUSR3") == 0)
368 signo = SIGUSR3;
369 #endif
370 else
371 fprintf(stderr, "siginstall(): unknown signal in DEBUG_SIGNAL: %s\n",
372 ptr);
373 } /* if (ptr) */
374
375 if (signo == NOSIG)
376 {
377 return False;
378 }
379 else
380 {
381 sighandler_t sigrc;
382
383 #ifdef DEBUGSIG
384 fprintf (stderr, "siginstall(): installing %p on signal %i\n", sighandler, signo);
385 #endif
386 sigrc=signal (signo, sighandler);
387 if (sigrc == SIG_ERR)
388 return False;
389 else
390 return True;
391 } /* signo != NOSIG */
392 } /* siginstall() */
393 #endif /* LESSTIF_PRODUCTION */
394
395
396 /* some initialization.
397 Does never fail; return value indicates whether debugging
398 is en- or disabled currently */
399 extern Boolean
_LtDebugInit(void)400 _LtDebugInit(void) {
401 #ifdef LESSTIF_PRODUCTION
402 return False;
403 #else
404 static Boolean init=False;
405
406 if (init)
407 return _LtDebugFlag;
408 else
409 {
410
411 const char *ptr;
412
413 ptr=getenv("DEBUG_TOGGLE");
414 if (ptr && (strcmp(ptr, "off")==0))
415 _LtDebugFlag=False;
416
417 _LtDebugOpenFile();
418 siginstall();
419 init = True;
420 return _LtDebugFlag;
421 }
422 #endif
423 }
424
425 #ifndef LESSTIF_PRODUCTION
426 static void
_LtDebugOpenFile(void)427 _LtDebugOpenFile(void)
428 {
429 const char *s;
430 char *fn;
431
432 if (_LtDebugFile)
433 {
434 /* already done */
435 return;
436 }
437
438 /* The rest here is the initialization code.
439 Might be slow and long, since it's done only once */
440
441 s = getenv("DEBUG_FILE");
442 if ((s == NULL)||(*s=='\0')||((strcmp(s, "stderr") == 0)))
443 _LtDebugFile = stderr; /* default/fallback value */
444 else if (strcmp(s, "stdout") == 0)
445 /* the user wants to mix our output with the stdout of the
446 * user application.
447 */
448 _LtDebugFile = stdout;
449
450 if (_LtDebugFile)
451 {
452 /* disable buffering for stdout/stderr */
453 setbuf(_LtDebugFile, NULL);
454 return;
455 }
456
457
458 #ifdef HAVE_GETPID
459 if (strstr(s, "%p"))
460 {
461 char *formatstr, *p;
462
463 fn = XtMalloc(strlen(s) + 10);
464 formatstr=XtMalloc(strlen(s)+1);
465 strcpy(formatstr, s);
466 p = strstr(formatstr, "%p");
467 *(p + 1) = 'd';
468 sprintf(fn, s, getpid());
469 XtFree(formatstr);
470 }
471 else
472 #endif /* HAVE_GETPID */
473 {
474 fn = XtMalloc(strlen(s) + 1);
475 strcpy(fn, s);
476 }
477
478 /* "a" means append, create if doesn't exist */
479 _LtDebugFile = fopen(fn, "a");
480 if (_LtDebugFile == NULL)
481 {
482 /* if fopen() fails do something reasonable */
483 fprintf(stderr, "_LtDebugOpenFile(): Can't open file %s\n", fn);
484 _LtDebugFile = stderr;
485 /* disable buffering */
486 setbuf(_LtDebugFile, NULL);
487 }
488 else
489 {
490 /* disable buffering for file */
491 setbuf(_LtDebugFile, NULL);
492 }
493 XtFree(fn);
494 }
495
496 /*
497 * See if 'fn' refers to a source file which is allowed to produce
498 * debugging output.
499 * The ".c" suffix for sources is not required (i.e. Form is equivalent
500 * to Form.c).
501 */
502 static Boolean
ValidateSource(const char * fn)503 ValidateSource(const char *fn)
504 {
505 static Boolean init=False;
506 static const char *sourcelist;
507 typedef struct {
508 char *fn;
509 Boolean shortmatch;
510 size_t len;
511 } list_entry_t;
512 static list_entry_t **poslist=NULL, **neglist=NULL;
513 static int positems=0, negitems=0;
514 static Boolean flag_all=False, flag_none=False;
515
516
517 if (!init)
518 {
519 /* Do initialization once and for all.
520 Might be a long, slow procedure, but should speed all
521 upcoming calls to this routine! */
522 sourcelist = getenv("DEBUG_SOURCES");
523 if (sourcelist==NULL) {
524 /* for compatibility with earlier versions */
525 sourcelist = getenv("DEBUGSOURCES");
526 }
527 /* No keyword "all" or "none" */
528 if ( sourcelist && (strcasecmp(sourcelist, "all")!=0) && (strcasecmp(sourcelist, "none")!=0) )
529 {
530 const char *s, *p;
531
532 s = sourcelist;
533 while (s && *s)
534 {
535 char *dotptr, *asteriskptr;
536 list_entry_t *newitem;
537 Cardinal len;
538
539 p = strchr(s, ':');
540 if (p)
541 len=(p-s);
542 else
543 len=strlen(s);
544
545 newitem=(list_entry_t *)XtMalloc(sizeof(list_entry_t));
546 if (*s=='-')
547 {
548 /* cut the '-' out: */
549 len--;
550 s++;
551
552 neglist=(list_entry_t **)XtRealloc((char *)neglist, sizeof (list_entry_t*) * (negitems+1));
553 neglist[negitems]=newitem;
554 negitems++;
555 }
556 else
557 {
558 poslist=(list_entry_t **)XtRealloc((char *)poslist, sizeof (list_entry_t*) * (positems+1));
559 poslist[positems]=newitem;
560 positems++;
561 }
562 newitem->fn=XtMalloc(len+1);
563 strncpy(newitem->fn, s, len);
564 newitem->fn[len]='\0';
565 /* Cut the file extensions */
566 if ((dotptr=strrchr(newitem->fn, '.')))
567 *dotptr='\0';
568
569 /* Check for shortmatch, asterisk */
570 if ((asteriskptr=strchr(newitem->fn, '*')))
571 {
572 *asteriskptr='\0';
573 newitem->shortmatch=True;
574 newitem->len=strlen(newitem->fn);
575 }
576 else
577 {
578 newitem->shortmatch=False;
579 newitem->len=0;
580 }
581 /* proceed to next entry */
582 if (p)
583 s = p+1;
584 else
585 s = p;
586 } /* while() */
587 }
588
589 /* set some flags to indicate situations where no explicit
590 search is later on required: */
591
592 /* list does not exist, is empty or set to "none" */
593 if ((!sourcelist) || (!*sourcelist) || (strcasecmp(sourcelist, "none")==0) )
594 flag_none = True;
595 /* "all" Sources */
596 else if (strcasecmp(sourcelist, "all") == 0)
597 flag_all = True;
598
599 init = True;
600
601 #ifdef DEBUGVALIDATE
602 {
603 int i;
604 fprintf(stderr, "VS() init\n");
605 for (i=0;i<positems;i++)
606 {
607 fprintf(stderr, "positem[%i]=%s # Short=%i\n",
608 i, poslist[i].fn, poslist[i].shortmatch);
609 }
610 for (i=0;i<negitems;i++)
611 {
612 fprintf(stderr, "negitem[%i]=%s # Short=%i\n",
613 i, neglist[i].fn, neglist[i].fn.shortmatch);
614 }
615 }
616 #endif
617 } /* if (!init) */
618
619 /* the most simple cases: */
620 if (flag_none)
621 return False;
622 else if (flag_all)
623 return True;
624 else
625 {
626 /* OK, we need to check explicitly ... */
627 const char *lastslash;
628 char *lastdot;
629 char shortfn[256]; /* dynamic memory would be too 'expensive' */
630
631 /* First we have to prepare the file name as passed to this routine:
632 the __FILE__ macro as inserted from CPP may contain an optional path
633 and certainly features a file extension (".c").
634 Our DEBUG_SOURCES shouldn't have this, so we have to strip that. */
635
636 lastslash = strrchr(fn, '/');
637 if (lastslash && *(lastslash+1)!='\0')
638 strncpy(shortfn, lastslash+1, sizeof(shortfn)-1);
639 else
640 strncpy(shortfn, fn, sizeof(shortfn)-1);
641 lastdot=strrchr(shortfn, '.');
642 if (lastdot)
643 *lastdot='\0';
644
645 /* we might have a negative list */
646 if (strcmp(poslist[0]->fn, "all")==0)
647 {
648 int i;
649 for (i=0; i<negitems; i++)
650 {
651 if (neglist[i]->shortmatch)
652 {
653 if (strncmp(shortfn, neglist[i]->fn, neglist[i]->len)==0)
654 return False;
655 }
656 else
657 if (strcmp(shortfn, neglist[i]->fn)==0)
658 return False;
659 }
660 return True;
661 }
662 else /* now check in the positive list */
663 {
664 int i;
665 for (i=0; i<positems; i++)
666 {
667 if (poslist[i]->shortmatch)
668 {
669 if (strncmp(shortfn, poslist[i]->fn, poslist[i]->len)==0)
670 return True;
671 }
672 else
673 {
674 if (strcmp(shortfn, poslist[i]->fn)==0)
675 return True;
676 }
677 }
678 return False; /* no matching entry found */
679 }
680 }
681 } /* ValidateSource() */
682
683 #endif /* !LESSTIF_PRODUCTION */
684
685
686 extern void
_LtDebug(const char * fn,Widget w,const char * fmt,...)687 _LtDebug(const char *fn, Widget w, const char *fmt, ...)
688 {
689 #ifndef LESSTIF_PRODUCTION
690 va_list ap;
691
692 #ifdef DEBUGVALIDATE
693 fprintf(stderr, "ValidateSource(%s)=%s\n",
694 fn, _LtDebugBoolean2String(ValidateSource(fn)));
695 #endif
696 if (_LtDebugInit() && ValidateSource(fn))
697 {
698 if (w)
699 {
700 if (__LtDebugPrintWidgetID())
701 {
702 fprintf(_LtDebugFile, "%s %s [%p]: ",
703 w->core.widget_class->core_class.class_name,
704 XtName(w), w);
705 }
706 else
707 {
708 fprintf(_LtDebugFile, "%s %s: ",
709 w->core.widget_class->core_class.class_name, XtName(w));
710 }
711 }
712 else
713 {
714 fprintf(_LtDebugFile, "(null widget): ");
715 }
716
717 va_start(ap, fmt);
718 vfprintf(_LtDebugFile, fmt, ap);
719 va_end(ap);
720
721 fflush(_LtDebugFile);
722 }
723 #endif /* !LESSTIF_PRODUCTION */
724 }
725
726
727 extern void
_LtDebug2(const char * fn,Widget w,Widget c,const char * fmt,...)728 _LtDebug2(const char *fn, Widget w, Widget c, const char *fmt, ...)
729 {
730 #ifndef LESSTIF_PRODUCTION
731 va_list ap;
732
733 if (_LtDebugInit() && ValidateSource(fn))
734 {
735 if (w && c)
736 {
737 if (__LtDebugPrintWidgetID())
738 {
739 fprintf(_LtDebugFile, "%s %s [%p] (child %s [%p]): ",
740 w->core.widget_class->core_class.class_name,
741 XtName(w), w, XtName(c), c);
742 }
743 else
744 {
745 fprintf(_LtDebugFile, "%s %s (child %s): ",
746 w->core.widget_class->core_class.class_name,
747 XtName(w), XtName(c));
748 }
749 }
750 else if (w)
751 {
752 if (__LtDebugPrintWidgetID())
753 {
754 fprintf(_LtDebugFile, "%s %s [%p] (child NULL): ",
755 w->core.widget_class->core_class.class_name,
756 XtName(w), w);
757 }
758 else
759 {
760 fprintf(_LtDebugFile, "%s %s (child NULL): ",
761 w->core.widget_class->core_class.class_name,
762 XtName(w));
763 }
764 }
765 else
766 {
767 fprintf(_LtDebugFile, "(null widget): ");
768 }
769
770 va_start(ap, fmt);
771 vfprintf(_LtDebugFile, fmt, ap);
772 va_end(ap);
773 }
774 #endif /* !LESSTIF_PRODUCTION */
775 }
776
777
778 extern void
_LtDebug0(const char * fn,Widget w,const char * fmt,...)779 _LtDebug0(const char *fn, Widget w, const char *fmt, ...)
780 {
781 #ifndef LESSTIF_PRODUCTION
782 va_list ap;
783
784 if (_LtDebugInit() && ValidateSource(fn))
785 {
786 va_start(ap, fmt);
787 vfprintf(_LtDebugFile, fmt, ap);
788 va_end(ap);
789 }
790 #endif /* !LESSTIF_PRODUCTION */
791 }
792
793
794 /* amai: why does it take a widget here as an argument; any good
795 reason for it?? */
796 extern Boolean
_LtDebugInDebug(const char * fn,Widget w)797 _LtDebugInDebug(const char *fn, Widget w)
798 {
799 #ifdef LESSTIF_PRODUCTION
800 return False;
801 #else
802 return ValidateSource(fn);
803 #endif
804 }
805
806
807 extern const char *
_LtDebugState(Widget w)808 _LtDebugState(Widget w)
809 {
810 if (XtIsRealized(w))
811 {
812 if (XtIsManaged(w))
813 {
814 return "realized, managed";
815 }
816 else
817 {
818 return "realized, not managed";
819 }
820 }
821 else
822 {
823 if (XtIsManaged(w))
824 {
825 return "not realized, managed";
826 }
827 else
828 {
829 return "not realized, not managed";
830 }
831 }
832 }
833
834
835 /* extern interface to turn on/off debugging output */
836 extern void
_LtDebugSet(Boolean flag)837 _LtDebugSet(Boolean flag)
838 {
839 #ifndef LESSTIF_PRODUCTION
840 if (flag)
841 _LtDebugFlag = True;
842 else
843 _LtDebugFlag = False;
844 #endif
845 }
846
847
848 /* In rare circumstances when one can't afford to code in
849 arguments to a function call for _LtSetDebug() here's
850 an alternative call */
851 extern void
_LtDebugToggle(void)852 _LtDebugToggle(void)
853 {
854 #ifndef LESSTIF_PRODUCTION
855 _LtDebugFlag = !_LtDebugFlag;
856 #endif
857 }
858
859
860 /* Allow user to query the state of Debugging System */
861 extern Boolean
_LtDebugQueryState(void)862 _LtDebugQueryState(void)
863 {
864 #ifndef LESSTIF_PRODUCTION
865 return _LtDebugFlag;
866 #else
867 return False;
868 #endif
869 }
870
871
872 #ifndef LESSTIF_PRODUCTION
873 static Boolean
__LtDebugPrintWidgetID(void)874 __LtDebugPrintWidgetID(void)
875 {
876 static const char *env;
877 static int checked=False;
878
879 if (!checked) {
880 env = getenv("DEBUG_PRINT_WIDGETID");
881 checked=True;
882 }
883 if (env)
884 return True;
885 else
886 return False;
887 }
888
889
890 static void
__LtDebugPrintTree(Widget w,int level)891 __LtDebugPrintTree(Widget w, int level)
892 {
893 int i;
894 Cardinal c;
895 CompositeWidget cw = (CompositeWidget)w;
896
897 if (w == NULL)
898 {
899 return;
900 }
901
902 _LtDebugOpenFile();
903
904 for (i = 0; i < level; i++)
905 {
906 fprintf(_LtDebugFile, "\t");
907 }
908
909 fprintf(_LtDebugFile, "%s : %p/%ld", XtName(w), w, XtWindow(w));
910 fprintf(_LtDebugFile, "(%s) geo %d %d %d %d",
911 w->core.widget_class->core_class.class_name,
912 XtX(w), XtY(w), XtWidth(w), XtHeight(w));
913 #ifdef PRINT_STATE
914 fprintf(_LtDebugFile, " state: %s %s",
915 _LtDebugState(w), w->core.mapped_when_managed ? "mwm" : "");
916 #endif
917 fprintf(_LtDebugFile, "\n");
918 if (XtIsSubclass(w, compositeWidgetClass))
919 {
920 for (c = 0; c < cw->composite.num_children; c++)
921 {
922 __LtDebugPrintTree(cw->composite.children[c], level + 1);
923 }
924 }
925
926 for (c = 0; c < cw->core.num_popups; c++)
927 {
928 __LtDebugPrintTree(cw->core.popup_list[c], level + 1);
929 }
930 }
931 #endif
932
933
934 extern void
_LtDebugPrintTree(Widget w)935 _LtDebugPrintTree(Widget w)
936 {
937 #ifndef LESSTIF_PRODUCTION
938 __LtDebugPrintTree(w, 0);
939 #endif
940 }
941
942
943 extern void
_LtDebugPrintCompleteTree(Widget w)944 _LtDebugPrintCompleteTree(Widget w)
945 {
946 #ifndef LESSTIF_PRODUCTION
947 Widget ww = w;
948
949 while (ww)
950 {
951 w = ww;
952 ww = XtParent(w);
953 }
954
955 __LtDebugPrintTree(w, 0);
956 #endif
957 }
958
959 extern const char *
_LtDebugDeleteResponse2String(int d)960 _LtDebugDeleteResponse2String(int d)
961 {
962 switch (d) {
963 case XmDESTROY:
964 return "XmDESTROY";
965 case XmUNMAP:
966 return "XmUNMAP";
967 case XmDO_NOTHING:
968 return "XmDO_NOTHING";
969 default:
970 return "??";
971 }
972 }
973
974 extern void
_LtDebugPrintArgList(const char * fn,Widget w,ArgList al,int n,Boolean Get)975 _LtDebugPrintArgList(const char *fn, Widget w, ArgList al, int n, Boolean Get)
976 {
977 #ifndef LESSTIF_PRODUCTION
978 int i;
979 unsigned num;
980
981 if (_LtDebugFlag && ValidateSource(fn))
982 {
983 _LtDebugOpenFile();
984
985 for (i = 0; i < n; i++)
986 {
987 int at;
988
989 for (at = 0; _LtDebugTypes[at].name; at++)
990 {
991 if (strcmp(al[i].name, _LtDebugTypes[at].name) == 0)
992 {
993 break;
994 }
995 }
996
997 if (_LtDebugTypes[at].name == NULL)
998 {
999 fprintf(_LtDebugFile, "Arg[%d] : %s (not handled FIX ME)\n", i, al[i].name);
1000 continue;
1001 }
1002
1003 switch (_LtDebugTypes[at].t)
1004 {
1005 case _LtDebugNONE:
1006 fprintf(_LtDebugFile, "Arg[%d] : %s\n", i, al[i].name);
1007 break;
1008
1009 case _LtDebugINT:
1010 fprintf(_LtDebugFile, "Arg[%d] : %s %d\n", i, al[i].name,
1011 (Get) ? *(int *)al[i].value
1012 : (int)al[i].value);
1013 break;
1014
1015 case _LtDebugSHORT:
1016 fprintf(_LtDebugFile, "Arg[%d] : %s %d\n", i, al[i].name,
1017 (Get) ? *(short *)al[i].value
1018 : (short)al[i].value);
1019 break;
1020
1021 case _LtDebugSTRING:
1022 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name, (char *)al[i].value);
1023 break;
1024
1025 case _LtDebugXMSTRING:
1026 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1027 _LtDebugXmString2String((XmString)al[i].value));
1028 break;
1029
1030 case _LtDebugCHAR:
1031 fprintf(_LtDebugFile, "Arg[%d] : %s %c\n", i, al[i].name, (char)al[i].value);
1032 break;
1033
1034 case _LtDebugALIGNMENT:
1035 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1036 (Get) ? _LtDebugAlignment2String(*(unsigned char *)al[i].value)
1037 : _LtDebugAlignment2String((unsigned char)al[i].value));
1038 break;
1039
1040 case _LtDebugRESIZE_POLICY:
1041 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1042 (Get) ? _LtDebugResizePolicy2String(*(unsigned char *)al[i].value)
1043 : _LtDebugResizePolicy2String((unsigned char)al[i].value));
1044 break;
1045
1046 case _LtDebugSB_DISPLAY_POLICY:
1047 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1048 (Get) ? _LtDebugSBDisplayPolicy2String(*(unsigned char *)al[i].value)
1049 : _LtDebugSBDisplayPolicy2String((unsigned char)al[i].value));
1050 break;
1051
1052 case _LtDebugDRAG_TYPE:
1053 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1054 (Get) ? _LtDebugDragType2String(*(unsigned char *)al[i].value)
1055 : _LtDebugDragType2String((unsigned char)al[i].value));
1056 break;
1057
1058 case _LtDebugSCROLLING_POLICY:
1059 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1060 (Get) ? _LtDebugScrollingPolicy2String(*(unsigned char *)al[i].value)
1061 : _LtDebugScrollingPolicy2String((unsigned char)al[i].value));
1062 break;
1063
1064 case _LtDebugSB_PLACEMENT:
1065 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1066 (Get) ? _LtDebugSBPlacement2String(*(unsigned char *)al[i].value)
1067 : _LtDebugSBPlacement2String((unsigned char)al[i].value));
1068 break;
1069
1070 case _LtDebugLIST_SIZE_POLICY:
1071 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1072 (Get) ? _LtDebugListSizePolicy2String(*(unsigned char *)al[i].value)
1073 : _LtDebugListSizePolicy2String((unsigned char)al[i].value));
1074 break;
1075
1076 case _LtDebugATTACHMENT:
1077 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1078 (Get) ? _LtDebugAttachment2String(*(unsigned char *)al[i].value)
1079 : _LtDebugAttachment2String((unsigned char)al[i].value));
1080 break;
1081
1082 case _LtDebugDIALOG_STYLE:
1083 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1084 (Get) ? _LtDebugDialogStyle2String(*(unsigned char *)al[i].value)
1085 : _LtDebugDialogStyle2String((unsigned char)al[i].value));
1086 break;
1087
1088 case _LtDebugWIDGET:
1089 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1090 (Get)
1091 ? ((al[i].value && *(Widget *)al[i].value)
1092 ? XtName(*(Widget *)al[i].value)
1093 : "(null)")
1094 : (al[i].value
1095 ? XtName((Widget)al[i].value)
1096 : "(null)"));
1097 break;
1098
1099 case _LtDebugEDIT_MODE:
1100 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1101 (Get) ? _LtDebugEditMode2String(*(Boolean *)al[i].value)
1102 : _LtDebugEditMode2String((Boolean)al[i].value));
1103 break;
1104
1105 case _LtDebugBOOLEAN:
1106 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1107 (Get) ? _LtDebugBoolean2String(*(Boolean *)al[i].value)
1108 : _LtDebugBoolean2String((Boolean)al[i].value));
1109 break;
1110
1111 case _LtDebugSELECTION_POLICY:
1112 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1113 _LtDebugSelectionPolicy2String(al[i].value));
1114 break;
1115
1116 case _LtDebugXMSTRING_LIST: /* Need related info !! */
1117 num = 0xdeadbeef;
1118
1119 XtVaGetValues(w, _LtDebugTypes[at].related, &num, NULL);
1120
1121 if (num != 0xdeadbeef)
1122 {
1123 int j;
1124
1125 fprintf(_LtDebugFile, "Arg[%d] : %s(%d):\n", i, al[i].name, num);
1126 for (j = 0; j < (int)num; j++)
1127 {
1128 fprintf(_LtDebugFile, "\tItem %d '%s'\n", j,
1129 _LtDebugXmString2String(((XmString *)(al[i].value))[j]));
1130 }
1131 }
1132
1133 break;
1134
1135 case _LtDebugMWM_INPUT_MODE:
1136 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1137 (Get) ? _LtDebugMwmInput2String(*(int *)al[i].value)
1138 : _LtDebugMwmInput2String((int)al[i].value));
1139 break;
1140
1141 case _LtDebugDELETE_RESPONSE:
1142 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1143 (Get) ? _LtDebugDeleteResponse2String(*(int *)al[i].value) :
1144 _LtDebugDeleteResponse2String((int)al[i].value));
1145 break;
1146
1147 case _LtDebugCOMBOBOX_TYPE:
1148 fprintf(_LtDebugFile, "Arg[%d] : %s %s\n", i, al[i].name,
1149 _LtDebugComboBoxType2String(al[i].value));
1150 break;
1151
1152 case _LtDebugRENDERTABLE:
1153 {
1154 XmRenderTable rt = (XmRenderTable)al[i].value;
1155 char s[80];
1156 sprintf(s, "Arg[%d] : %s", i, al[i].name);
1157 _LtDebugPrintRenderTable(fn, w, s, rt);
1158 }
1159 break;
1160
1161 }
1162 }
1163 }
1164 #endif/* !LESSTIF_PRODUCTION */
1165 }
1166
1167 void
_LtDebugPrintRenderTable(const char * fn,Widget w,char * s,XmRenderTable rt)1168 _LtDebugPrintRenderTable(const char *fn, Widget w, char *s, XmRenderTable rt)
1169 {
1170 #ifndef LESSTIF_PRODUCTION
1171 int x;
1172
1173 if (_LtDebugFlag && ValidateSource(fn)) {
1174 _LtDebugOpenFile();
1175 fprintf(_LtDebugFile, "%s %p (%d renditions)\n", s, rt, rt->count);
1176
1177 for (x=0; x<rt->count; x++) {
1178 switch (rt->renditions[x]->type) {
1179 case XmFONT_IS_FONT:
1180 fprintf(_LtDebugFile, "\t%d - %s [%s], %p\n",
1181 x,
1182 "XmFONT_IS_FONT",
1183 rt->renditions[x]->font_name ?
1184 rt->renditions[x]->font_name : "(null font name)",
1185 rt->renditions[x]->font);
1186 break;
1187 case XmFONT_IS_FONTSET:
1188 fprintf(_LtDebugFile, "\t%d - %s [%s], %p\n",
1189 x,
1190 "XmFONT_IS_FONTSET",
1191 rt->renditions[x]->font_name ?
1192 rt->renditions[x]->font_name : "(null font name)",
1193 rt->renditions[x]->font);
1194 break;
1195 #ifdef USE_XFT
1196 case XmFONT_IS_XFT:
1197 fprintf(_LtDebugFile, "\t%d - %s [%s/%s/%s/%s,%d], %p\n",
1198 x,
1199 "XmFONT_IS_XFT",
1200 rt->renditions[x]->font_name,
1201 rt->renditions[x]->font_style,
1202 rt->renditions[x]->font_foundry,
1203 rt->renditions[x]->font_encoding,
1204 rt->renditions[x]->font_size,
1205 rt->renditions[x]->font);
1206 break;
1207 #endif
1208 #ifdef USE_BIDI
1209 case XmFONT_IS_XOC:
1210 fprintf(_LtDebugFile, "\t%d - %s\n",
1211 x,
1212 "XmFONT_IS_XOC");
1213 break;
1214 #endif
1215 default:
1216 break;
1217 }
1218 }
1219 }
1220 #endif/* !LESSTIF_PRODUCTION */
1221 }
1222
1223 /*
1224 * Allow unconditional printing to the _LtDebugFile
1225 */
1226 extern void
_LtDebugPrintString(const char * s)1227 _LtDebugPrintString(const char *s)
1228 {
1229 #ifndef LESSTIF_PRODUCTION
1230 _LtDebugOpenFile();
1231 fprintf(_LtDebugFile, "%s", s);
1232 #endif
1233 }
1234
1235
1236
1237 /* The following calls shouldn't depend on the complete debugging
1238 subsystem, i.e. things like _LtDebugFile, etc. */
1239
1240 extern const char *
_LtDebugComboBoxType2String(unsigned char type)1241 _LtDebugComboBoxType2String(unsigned char type)
1242 {
1243 switch(type)
1244 {
1245 case XmDROP_DOWN_LIST:
1246 return("XmDROP_DOWN_LIST");
1247 case XmDROP_DOWN_COMBO_BOX:
1248 return("XmDROP_DOWN_COMBO_BOX");
1249 case XmCOMBO_BOX:
1250 return("XmCOMBO_BOX");
1251 default:
1252 return("UNKNOWN");
1253 }
1254 }
1255
1256 extern const char *
_LtDebugGeoAction2String(int action)1257 _LtDebugGeoAction2String(int action)
1258 {
1259 switch(action)
1260 {
1261 case XmGET_ACTUAL_SIZE:
1262 return("XmGET_ACTUAL_SIZE");
1263 case XmGET_PREFERRED_SIZE:
1264 return("XmGET_PREFERRED_SIZE");
1265 case XmGEO_PRE_SET:
1266 return("XmGEO_PRE_SET");
1267 case XmGEO_POST_SET:
1268 return("XmGEO_POST_SET");
1269 default:
1270 return("Unknown geo action");
1271 }
1272 }
1273
1274
1275 extern const char *
_LtDebugGeometryResult2String(XtGeometryResult r)1276 _LtDebugGeometryResult2String(XtGeometryResult r)
1277 {
1278 switch (r)
1279 {
1280 case XtGeometryYes:
1281 return "Yes";
1282
1283 case XtGeometryNo:
1284 return "No";
1285
1286 case XtGeometryAlmost:
1287 return "Almost";
1288
1289 case XtGeometryDone:
1290 return "Done";
1291
1292 default:
1293 return "(invalid geometry result)";
1294 }
1295 }
1296
1297
1298 extern const char *
_LtDebugDragAndDropMessageType2String(unsigned char r)1299 _LtDebugDragAndDropMessageType2String(unsigned char r)
1300 {
1301 switch (r)
1302 {
1303 case XmTOP_LEVEL_ENTER:
1304 return "TOP_LEVEL_ENTER";
1305
1306 case XmTOP_LEVEL_LEAVE:
1307 return "TOP_LEVEL_LEAVE";
1308
1309 case XmDRAG_MOTION:
1310 return "DRAG_MOTION";
1311
1312 case XmDROP_SITE_ENTER:
1313 return "DROP_SITE_ENTER";
1314
1315 case XmDROP_SITE_LEAVE:
1316 return "DROP_SITE_LEAVE";
1317
1318 case XmDROP_START:
1319 return "DROP_START";
1320
1321 case XmDROP_FINISH:
1322 return "DROP_FINISH";
1323
1324 case XmDRAG_DROP_FINISH:
1325 return "DRAG_DROP_FINISH";
1326
1327 case XmOPERATION_CHANGED:
1328 return "OPERATION_CHANGED";
1329
1330 default:
1331 return "UNKNOWN";
1332 }
1333 }
1334
1335
1336 extern const char *
_LtDebugDragType2String(unsigned char r)1337 _LtDebugDragType2String(unsigned char r)
1338 {
1339 switch (r)
1340 {
1341 case XmDRAG_NONE:
1342 return "XmDRAG_NONE";
1343
1344 case XmDRAG_DROP_ONLY:
1345 return "XmDRAG_DROP_ONLY";
1346
1347 case XmDRAG_PREFER_PREREGISTER:
1348 return "XmDRAG_PREFER_PREREGISTER";
1349
1350 case XmDRAG_PREREGISTER:
1351 return "XmDRAG_PREREGISTER";
1352
1353 case XmDRAG_PREFER_DYNAMIC:
1354 return "XmDRAG_PREFER_DYNAMIC";
1355
1356 case XmDRAG_PREFER_RECEIVER:
1357 return "XmDRAG_PREFER_RECEIVER";
1358
1359 case XmDRAG_DYNAMIC:
1360 return "XmDRAG_DYNAMIC";
1361
1362 default:
1363 return "UNKNOWN";
1364 }
1365 }
1366
1367
1368 extern const char *
_LtDebugScrollingPolicy2String(unsigned char r)1369 _LtDebugScrollingPolicy2String(unsigned char r)
1370 {
1371 switch (r)
1372 {
1373 case XmAUTOMATIC:
1374 return "XmAUTOMATIC";
1375
1376 case XmCONSTANT:
1377 return "XmCONSTANT";
1378
1379 default:
1380 return "UNKNOWN";
1381 }
1382 }
1383
1384 extern const char *
_LtDebugMwmInput2String(int a)1385 _LtDebugMwmInput2String(int a)
1386 {
1387 switch (a)
1388 {
1389 case MWM_INPUT_MODELESS:
1390 return "MWM_INPUT_MODELESS";
1391
1392 case MWM_INPUT_PRIMARY_APPLICATION_MODAL:
1393 return "MWM_INPUT_PRIMARY_APPLICATION_MODAL or MWM_INPUT_APPLICATION_MODAL";
1394
1395 case MWM_INPUT_FULL_APPLICATION_MODAL:
1396 return "MWM_INPUT_FULL_APPLICATION_MODAL";
1397
1398 case MWM_INPUT_SYSTEM_MODAL:
1399 return "MWM_INPUT_SYSTEM_MODAL";
1400 #if 0
1401 case MWM_INPUT_APPLICATION_MODAL:
1402 return "MWM_INPUT_APPLICATION_MODAL";
1403 #endif
1404 default:
1405 return "(invalid input style)";
1406 }
1407 }
1408
1409 extern const char *
_LtDebugDialogStyle2String(int a)1410 _LtDebugDialogStyle2String(int a)
1411 {
1412 switch (a)
1413 {
1414 case XmDIALOG_WORK_AREA:
1415 return "XmDIALOG_WORK_AREA or XmDIALOG_MODELESS";
1416
1417 /*
1418 case XmDIALOG_MODELESS:
1419 return "XmDIALOG_MODELESS";
1420 */
1421
1422 case XmDIALOG_PRIMARY_APPLICATION_MODAL:
1423 return "XmDIALOG_PRIMARY_APPLICATION_MODAL or XmDIALOG_APPLICATION_MODAL";
1424
1425 case XmDIALOG_FULL_APPLICATION_MODAL:
1426 return "XmDIALOG_FULL_APPLICATION_MODAL";
1427
1428 case XmDIALOG_SYSTEM_MODAL:
1429 return "XmDIALOG_SYSTEM_MODAL";
1430
1431 /*
1432 case XmDIALOG_APPLICATION_MODAL:
1433 return "XmDIALOG_APPLICATION_MODAL";
1434 */
1435
1436 default:
1437 return "(invalid dialog style)";
1438 }
1439 }
1440
1441
1442 extern const char *
_LtDebugAttachment2String(int a)1443 _LtDebugAttachment2String(int a)
1444 {
1445 switch (a)
1446 {
1447 case XmATTACH_FORM:
1448 return "XmATTACH_FORM";
1449
1450 case XmATTACH_OPPOSITE_FORM:
1451 return "XmATTACH_OPPOSITE_FORM";
1452
1453 case XmATTACH_WIDGET:
1454 return "XmATTACH_WIDGET";
1455
1456 case XmATTACH_OPPOSITE_WIDGET:
1457 return "XmATTACH_OPPOSITE_WIDGET";
1458
1459 case XmATTACH_NONE:
1460 return "XmATTACH_NONE";
1461
1462 case XmATTACH_POSITION:
1463 return "XmATTACH_POSITION";
1464
1465 case XmATTACH_SELF:
1466 return "XmATTACH_SELF";
1467
1468 default:
1469 return "(invalid attachment)";
1470 }
1471 }
1472
1473
1474 extern const char *
_LtDebugMenuFocusOp2String(int f)1475 _LtDebugMenuFocusOp2String(int f)
1476 {
1477 switch (f)
1478 {
1479 case XmMENU_FOCUS_SAVE:
1480 return ("XmMENU_FOCUS_SAVE");
1481 case XmMENU_FOCUS_RESTORE:
1482 return ("XmMENU_FOCUS_RESTORE");
1483 case XmMENU_FOCUS_SET:
1484 return ("XmMENU_FOCUS_SET");
1485 default:
1486 return("Unknown focus op");
1487 }
1488 }
1489
1490
1491 extern const char *
_LtDebugMenuEnum2String(int f)1492 _LtDebugMenuEnum2String(int f)
1493 {
1494 switch (f)
1495 {
1496 case XmMENU_POPDOWN:
1497 return "XmMENU_POPDOWN";
1498
1499 case XmMENU_PROCESS_TREE:
1500 return "XmMENU_PROCESS_TREE";
1501
1502 case XmMENU_TRAVERSAL:
1503 return "XmMENU_TRAVERSAL";
1504
1505 case XmMENU_SHELL_POPDOWN:
1506 return "XmMENU_SHELL_POPDOWN";
1507
1508 case XmMENU_CALLBACK:
1509 return "XmMENU_CALLBACK";
1510
1511 case XmMENU_BUTTON:
1512 return "XmMENU_BUTTON";
1513
1514 case XmMENU_CASCADING:
1515 return "XmMENU_CASCADING";
1516
1517 case XmMENU_SUBMENU:
1518 return "XmMENU_SUBMENU";
1519
1520 case XmMENU_ARM:
1521 return "XmMENU_ARM";
1522
1523 case XmMENU_DISARM:
1524 return "XmMENU_DISARM";
1525
1526 case XmMENU_BAR_CLEANUP:
1527 return "XmMENU_BAR_CLEANUP";
1528
1529 case XmMENU_STATUS:
1530 return "XmMENU_STATUS";
1531
1532 case XmMENU_MEMWIDGET_UPDATE:
1533 return "XmMENU_MEMWIDGET_UPDATE";
1534
1535 case XmMENU_BUTTON_POPDOWN:
1536 return "XmMENU_BUTTON_POPDOWN";
1537
1538 case XmMENU_RESTORE_EXCLUDED_TEAROFF_TO_TOPLEVEL_SHELL:
1539 return "XmMENU_RESTORE_EXCLUDED_TEAROFF_TO_TOPLEVEL_SHELL";
1540
1541 case XmMENU_RESTORE_TEAROFF_TO_TOPLEVEL_SHELL:
1542 return "XmMENU_RESTORE_TEAROFF_TO_TOPLEVEL_SHELL";
1543
1544 case XmMENU_RESTORE_TEAROFF_TO_MENUSHELL:
1545 return "XmMENU_RESTORE_TEAROFF_TO_MENUSHELL";
1546
1547 case XmMENU_GET_LAST_SELECT_TOPLEVEL:
1548 return "XmMENU_GET_LAST_SELECT_TOPLEVEL";
1549
1550 case XmMENU_TEAR_OFF_ARM:
1551 return "XmMENU_TEAR_OFF_ARM";
1552
1553 default:
1554 return "??";
1555 }
1556 }
1557
1558
1559 extern const char *
_LtDebugBoolean2String(Boolean b)1560 _LtDebugBoolean2String(Boolean b)
1561 {
1562 if (b)
1563 return "True";
1564 else
1565 return "False";
1566 }
1567
1568
1569 extern const char *
_LtDebugXmString2String(XmString xms)1570 _LtDebugXmString2String(XmString xms)
1571 {
1572 static char *s = NULL;
1573
1574 if (s) {
1575 XtFree(s);
1576 s=NULL;
1577 }
1578 if (xms == (XmString)XmUNSPECIFIED)
1579 {
1580 return "XmUNSPECIFIED";
1581 }
1582 if ( ! XmStringGetLtoR(xms, XmFONTLIST_DEFAULT_TAG, &s) || s == NULL )
1583 {
1584 return "(null)";
1585 }
1586
1587 return s;
1588 }
1589
1590
1591 extern const char *
_LtDebugPacking2String(unsigned char p)1592 _LtDebugPacking2String(unsigned char p)
1593 {
1594 static char res[40];
1595
1596 switch (p)
1597 {
1598 case XmPACK_COLUMN:
1599 return "XmPACK_COLUMN";
1600
1601 case XmPACK_TIGHT:
1602 return "XmPACK_TIGHT";
1603
1604 case XmPACK_NONE:
1605 return "XmPACK_NONE";
1606
1607 default:
1608 sprintf(res, "Invalid packing %d", p);
1609 return res;
1610 }
1611 }
1612
1613
1614 extern const char *
_LtDebugRcType2String(unsigned char t)1615 _LtDebugRcType2String(unsigned char t)
1616 {
1617 static char res[40];
1618
1619 switch (t)
1620 {
1621 case XmWORK_AREA:
1622 return "XmWORK_AREA";
1623
1624 case XmMENU_BAR:
1625 return "XmMENU_BAR";
1626
1627 case XmMENU_PULLDOWN:
1628 return "XmMENU_PULLDOWN";
1629
1630 case XmMENU_POPUP:
1631 return "XmMENU_POPUP";
1632
1633 case XmMENU_OPTION:
1634 return "XmMENU_OPTION";
1635
1636 default:
1637 sprintf(res, "Invalid RC Type %d", t);
1638 return res;
1639 }
1640 }
1641
1642
1643 extern const char *
_LtDebugWidgetGeometry2String(XtWidgetGeometry * g)1644 _LtDebugWidgetGeometry2String(XtWidgetGeometry *g)
1645 {
1646 static char o1[128], o2[128], b[20];
1647 static char *out = NULL;
1648 int i;
1649
1650 if (g == NULL)
1651 {
1652 return "NULL_GEOMETRY";
1653 }
1654
1655 if (g->request_mode == 0)
1656 {
1657 return "GEOMETRY_NO_FIELDS";
1658 }
1659
1660 /* Some magic to ensure you can call this sucker twice in one C function call */
1661 if (out == &o1[0])
1662 {
1663 out = &o2[0];
1664 }
1665 else
1666 {
1667 out = &o1[0];
1668 }
1669
1670 out[0] = '\0';
1671 #if 0
1672 {
1673 char t[16];
1674 strcat(out, "{");
1675 sprintf(t, "%d,", g->request_mode);
1676 strcat(out, t);
1677 if (g->request_mode & CWX) strcat(out, "x");
1678 if (g->request_mode & CWY) strcat(out, "y");
1679 if (g->request_mode & CWWidth) strcat(out, "w");
1680 if (g->request_mode & CWHeight) strcat(out, "h");
1681 if (g->request_mode & CWBorderWidth) strcat(out, "b");
1682 strcat(out, "} ");
1683 }
1684 #endif
1685
1686 if (g->request_mode & CWX)
1687 {
1688 sprintf(b, "x %d ", g->x);
1689 strcat(out, b);
1690 }
1691 if (g->request_mode & CWY)
1692 {
1693 sprintf(b, "y %d ", g->y);
1694 strcat(out, b);
1695 }
1696 if (g->request_mode & CWWidth)
1697 {
1698 sprintf(b, "w %d ", g->width);
1699 strcat(out, b);
1700 }
1701 if (g->request_mode & CWHeight)
1702 {
1703 sprintf(b, "h %d ", g->height);
1704 strcat(out, b);
1705 }
1706 if (g->request_mode & CWBorderWidth)
1707 {
1708 sprintf(b, "bw %d ", g->border_width);
1709 strcat(out, b);
1710 }
1711
1712 for (i = 0; out[i]; i++)
1713 {
1714 }
1715
1716 if (i > 0 && out[i - 1] == ' ')
1717 {
1718 out[i - 1] = '\0';
1719 }
1720
1721 return out;
1722 }
1723
1724
1725 extern const char *
_LtDebugEditMode2String(int n)1726 _LtDebugEditMode2String(int n)
1727 {
1728 switch (n)
1729 {
1730 case XmMULTI_LINE_EDIT:
1731 return "XmMULTI_LINE_EDIT";
1732
1733 case XmSINGLE_LINE_EDIT:
1734 return "XmSINGLE_LINE_EDIT";
1735
1736 default:
1737 return "???";
1738 }
1739 }
1740
1741
1742 extern const char *
_LtDebugSelectionPolicy2String(int n)1743 _LtDebugSelectionPolicy2String(int n)
1744 {
1745 switch (n)
1746 {
1747 case XmSINGLE_SELECT:
1748 return "XmSINGLE_SELECT";
1749
1750 case XmBROWSE_SELECT:
1751 return "XmBROWSE_SELECT";
1752
1753 case XmMULTIPLE_SELECT:
1754 return "XmMULTIPLE_SELECT";
1755
1756 case XmEXTENDED_SELECT:
1757 return "XmEXTENDED_SELECT";
1758
1759 default:
1760 return "???";
1761 }
1762 }
1763
1764
1765 extern const char *
_LtDebugResizePolicy2String(int n)1766 _LtDebugResizePolicy2String(int n)
1767 {
1768 switch (n) {
1769 case XmRESIZE_NONE: return "XmRESIZE_NONE";
1770 case XmRESIZE_GROW: return "XmRESIZE_GROW";
1771 case XmRESIZE_ANY: return "XmRESIZE_ANY";
1772 case XmRESIZE_SWINDOW: return "XmRESIZE_SWINDOW";
1773 default: return "XmNscrollBarDisplayPolicy - illegal";
1774 }
1775 }
1776
1777
1778 extern const char *
_LtDebugSBDisplayPolicy2String(int n)1779 _LtDebugSBDisplayPolicy2String(int n)
1780 {
1781 switch (n)
1782 {
1783 case XmSTATIC:
1784 return "XmSTATIC";
1785
1786 case XmAS_NEEDED:
1787 return "XmAS_NEEDED";
1788
1789 default:
1790 return "XmNscrollBarDisplayPolicy - illegal";
1791 }
1792 }
1793
1794
1795 extern const char *
_LtDebugSBPlacement2String(int n)1796 _LtDebugSBPlacement2String(int n)
1797 {
1798 switch (n)
1799 {
1800 case XmTOP_LEFT:
1801 return "XmTOP_LEFT";
1802
1803 case XmBOTTOM_LEFT:
1804 return "XmBOTTOM_LEFT";
1805
1806 case XmTOP_RIGHT:
1807 return "XmTOP_RIGHT";
1808
1809 case XmBOTTOM_RIGHT:
1810 return "XmBOTTOM_RIGHT";
1811
1812 default:
1813 return "XmNscrollBarPlacement - illegal";
1814 }
1815 }
1816
1817
1818 extern const char *
_LtDebugListSizePolicy2String(int n)1819 _LtDebugListSizePolicy2String(int n)
1820 {
1821 switch (n)
1822 {
1823 case XmVARIABLE:
1824 return "XmVARIABLE";
1825
1826 case XmCONSTANT:
1827 return "XmCONSTANT";
1828
1829 case XmRESIZE_IF_POSSIBLE:
1830 return "XmRESIZE_IF_POSSIBLE";
1831
1832 default:
1833 return "XmNlistSizePolicy - illegal";
1834 }
1835 }
1836
1837
1838 extern const char *
_LtDebugAlignment2String(int n)1839 _LtDebugAlignment2String(int n)
1840 {
1841 switch (n)
1842 {
1843 case XmALIGNMENT_BEGINNING:
1844 return "XmALIGNMENT_BEGINNING";
1845
1846 case XmALIGNMENT_CENTER:
1847 return "XmALIGNMENT_CENTER";
1848
1849 case XmALIGNMENT_END:
1850 return "XmALIGNMENT_END";
1851
1852 default:
1853 return "XmALIGNMENT - illegal";
1854 }
1855 }
1856
1857
1858 extern const char *
_LtDebugMenuType2String(int n)1859 _LtDebugMenuType2String(int n)
1860 {
1861 switch (n)
1862 {
1863 case XmMENU_OPTION:
1864 return "XmMENU_OPTION";
1865
1866 case XmMENU_POPUP:
1867 return "XmMENU_POPUP";
1868
1869 case XmMENU_PULLDOWN:
1870 return "XmMENU_PULLDOWN";
1871
1872 default:
1873 return "???";
1874 }
1875 }
1876
1877
1878 extern const char *
_LtDebugNavigability2String(unsigned char n)1879 _LtDebugNavigability2String(unsigned char n)
1880 {
1881 switch (n)
1882 {
1883 case XmDESCENDANTS_NAVIGABLE:
1884 return "XmDESCENDANTS_NAVIGABLE";
1885
1886 case XmDESCENDANTS_TAB_NAVIGABLE:
1887 return "XmDESCENDANTS_TAB_NAVIGABLE";
1888
1889 case XmCONTROL_NAVIGABLE:
1890 return "XmCONTROL_NAVIGABLE";
1891
1892 case XmNOT_NAVIGABLE:
1893 return "XmNOT_NAVIGABLE";
1894
1895 case XmTAB_NAVIGABLE:
1896 return "XmTAB_NAVIGABLE";
1897
1898 default:
1899 return "???";
1900 }
1901 }
1902
1903
1904 extern const char *
_LtDebugHighlightMode2String(int mode)1905 _LtDebugHighlightMode2String(int mode)
1906 {
1907 switch (mode)
1908 {
1909 case XmHIGHLIGHT_NORMAL:
1910 return "NORMAL";
1911
1912 case XmHIGHLIGHT_SELECTED:
1913 return "SELECTED";
1914
1915 case XmHIGHLIGHT_SECONDARY_SELECTED:
1916 return "SECONDARY_SELECTED";
1917
1918 default:
1919 return "???";
1920 }
1921 }
1922
1923
1924 extern const char *
_LtDebugReason2String(int reason)1925 _LtDebugReason2String(int reason)
1926 {
1927 switch (reason) {
1928 case XmCR_NONE: return "XmCR_NONE";
1929 case XmCR_HELP: return "XmCR_HELP";
1930 case XmCR_VALUE_CHANGED: return "XmCR_VALUE_CHANGED";
1931 case XmCR_INCREMENT: return "XmCR_INCREMENT";
1932 case XmCR_DECREMENT: return "XmCR_DECREMENT";
1933 case XmCR_PAGE_INCREMENT: return "XmCR_PAGE_INCREMENT";
1934 case XmCR_PAGE_DECREMENT: return "XmCR_PAGE_DECREMENT";
1935 case XmCR_TO_TOP: return "XmCR_TO_TOP";
1936 case XmCR_TO_BOTTOM: return "XmCR_TO_BOTTOM";
1937 case XmCR_DRAG: return "XmCR_DRAG";
1938 case XmCR_ACTIVATE: return "XmCR_ACTIVATE";
1939 case XmCR_ARM: return "XmCR_ARM";
1940 case XmCR_DISARM: return "XmCR_DISARM";
1941 case XmCR_DUMMY13: return "XmCR_DUMMY13";
1942 case XmCR_DUMMY14: return "XmCR_DUMMY14";
1943 case XmCR_DUMMY15: return "XmCR_DUMMY15";
1944 case XmCR_MAP: return "XmCR_MAP";
1945 case XmCR_UNMAP: return "XmCR_UNMAP";
1946 case XmCR_FOCUS: return "XmCR_FOCUS";
1947 case XmCR_LOSING_FOCUS: return "XmCR_LOSING_FOCUS";
1948 case XmCR_MODIFYING_TEXT_VALUE: return "XmCR_MODIFYING_TEXT_VALUE";
1949 case XmCR_MOVING_INSERT_CURSOR: return "XmCR_MOVING_INSERT_CURSOR";
1950 case XmCR_EXECUTE: return "XmCR_EXECUTE";
1951 case XmCR_SINGLE_SELECT: return "XmCR_SINGLE_SELECT";
1952 case XmCR_MULTIPLE_SELECT: return "XmCR_MULTIPLE_SELECT";
1953 case XmCR_EXTENDED_SELECT: return "XmCR_EXTENDED_SELECT";
1954 case XmCR_BROWSE_SELECT: return "XmCR_BROWSE_SELECT";
1955 case XmCR_DEFAULT_ACTION: return "XmCR_DEFAULT_ACTION";
1956 case XmCR_CLIPBOARD_DATA_REQUEST: return "XmCR_CLIPBOARD_DATA_REQUEST";
1957 case XmCR_CLIPBOARD_DATA_DELETE: return "XmCR_CLIPBOARD_DATA_DELETE";
1958 case XmCR_CASCADING: return "XmCR_CASCADING";
1959 case XmCR_OK: return "XmCR_OK";
1960 case XmCR_CANCEL: return "XmCR_CANCEL";
1961 case XmCR_DUMMY33: return "XmCR_DUMMY33";
1962 case XmCR_APPLY: return "XmCR_APPLY";
1963 case XmCR_NO_MATCH: return "XmCR_NO_MATCH";
1964 case XmCR_COMMAND_ENTERED: return "XmCR_COMMAND_ENTERED";
1965 case XmCR_COMMAND_CHANGED: return "XmCR_COMMAND_CHANGED";
1966 case XmCR_EXPOSE: return "XmCR_EXPOSE";
1967 case XmCR_RESIZE: return "XmCR_RESIZE";
1968 case XmCR_INPUT: return "XmCR_INPUT";
1969 case XmCR_GAIN_PRIMARY: return "XmCR_GAIN_PRIMARY";
1970 case XmCR_LOSE_PRIMARY: return "XmCR_LOSE_PRIMARY";
1971 case XmCR_CREATE: return "XmCR_CREATE";
1972 case XmCR_TEAR_OFF_ACTIVATE: return "XmCR_TEAR_OFF_ACTIVATE";
1973 case XmCR_TEAR_OFF_DEACTIVATE: return "XmCR_TEAR_OFF_DEACTIVATE";
1974 case XmCR_OBSCURED_TRAVERSAL: return "XmCR_OBSCURED_TRAVERSAL";
1975 case XmCR_FOCUS_MOVED: return "XmCR_FOCUS_MOVED";
1976 case XmCR_DUMMY48: return "XmCR_DUMMY48";
1977 case XmCR_DUMMY49: return "XmCR_DUMMY49";
1978 case XmCR_DUMMY50: return "XmCR_DUMMY50";
1979 case XmCR_DUMMY51: return "XmCR_DUMMY51";
1980 case XmCR_DUMMY52: return "XmCR_DUMMY52";
1981 case XmCR_DUMMY53: return "XmCR_DUMMY53";
1982 case XmCR_REPOST: return "XmCR_REPOST";
1983 case XmCR_COLLAPSED: return "XmCR_COLLAPSED";
1984 case XmCR_EXPANDED: return "XmCR_EXPANDED";
1985 case XmCR_SELECT: return "XmCR_SELECT";
1986 case XmCR_DRAG_START: return "XmCR_DRAG_START";
1987 case XmCR_NO_FONT: return "XmCR_NO_FONT";
1988 case XmCR_NO_RENDITION: return "XmCR_NO_RENDITION";
1989 case XmCR_POST: return "XmCR_POST";
1990 case XmCR_SPIN_NEXT: return "XmCR_SPIN_NEXT";
1991 case XmCR_SPIN_PRIOR: return "XmCR_SPIN_PRIOR";
1992 case XmCR_SPIN_FIRST: return "XmCR_SPIN_FIRST";
1993 case XmCR_SPIN_LAST: return "XmCR_SPIN_LAST";
1994 case XmCR_PAGE_SCROLLER_INCREMENT: return "XmCR_PAGE_SCROLLER_INCREMENT";
1995 case XmCR_PAGE_SCROLLER_DECREMENT: return "XmCR_PAGE_SCROLLER_DECREMENT";
1996 case XmCR_MAJOR_TAB: return "XmCR_MAJOR_TAB";
1997 case XmCR_MINOR_TAB: return "XmCR_MINOR_TAB";
1998 case XmCR_PDM_NONE: return "XmCR_PDM_NONE";
1999 case XmCR_PDM_START_VXAUTH: return "XmCR_PDM_START_VXAUTH";
2000 case XmCR_PDM_START_PXAUTH: return "XmCR_PDM_START_PXAUTH";
2001 case XmCR_PDM_UP: return "XmCR_PDM_UP";
2002 case XmCR_PDM_OK: return "XmCR_PDM_OK";
2003 case XmCR_PDM_CANCEL: return "XmCR_PDM_CANCEL";
2004 case XmCR_PDM_START_ERROR: return "XmCR_PDM_START_ERROR";
2005 case XmCR_PDM_EXIT_ERROR: return "XmCR_PDM_EXIT_ERROR";
2006 case XmCR_PROTOCOLS: return "XmCR_PROTOCOLS";
2007 default: return "???";
2008 }
2009 }
2010
2011
2012 extern const char *
_LtDebugFocusChange2String(XmFocusChange c)2013 _LtDebugFocusChange2String(XmFocusChange c)
2014 {
2015 switch (c) {
2016 case XmFOCUS_IN: return "XmFOCUS_IN";
2017 case XmFOCUS_OUT: return "XmFOCUS_OUT";
2018 case XmENTER: return "XmENTER";
2019 case XmLEAVE: return "XmLEAVE";
2020 default: return "???";
2021 }
2022 }
2023
2024
2025 extern const char *
_LtDebugNavigationType2String(XmNavigationType nt)2026 _LtDebugNavigationType2String(XmNavigationType nt)
2027 {
2028 switch (nt) {
2029 case XmNONE: return "XmNONE";
2030 case XmTAB_GROUP: return "XmTAB_GROUP";
2031 case XmSTICKY_TAB_GROUP: return "XmSTICKY_TAB_GROUP";
2032 case XmEXCLUSIVE_TAB_GROUP: return "XmEXCLUSIVE_TAB_GROUP";
2033 default: return "???";
2034 }
2035 }
2036
2037
2038 extern const char *
_LtDebugEventType2String(int type)2039 _LtDebugEventType2String(int type)
2040 {
2041 switch (type)
2042 {
2043 case KeyPress: return("KeyPress");
2044 case KeyRelease: return("KeyRelease");
2045 case ButtonPress: return("ButtonPress");
2046 case ButtonRelease: return("ButtonRelease");
2047 case KeymapNotify: return("KeymapNotify");
2048 case MotionNotify: return("MotionNotify");
2049 case EnterNotify: return("EnterNotify");
2050 case LeaveNotify: return("LeaveNotify");
2051 case FocusIn: return("FocusIn");
2052 case FocusOut: return("FocusOut");
2053 case Expose: return("Expose");
2054 case GraphicsExpose: return("GraphicsExpose");
2055 case NoExpose: return("NoExpose");
2056 case ColormapNotify: return("ColormapNotify");
2057 case PropertyNotify: return("PropertyNotify");
2058 case VisibilityNotify: return("VisibilityNotify");
2059 case ResizeRequest: return("ResizeRequest");
2060 case CirculateNotify: return("CirculateNotify");
2061 case ConfigureNotify: return("ConfigureNotify");
2062 case DestroyNotify: return("DestroyNotify");
2063 case GravityNotify: return("GravityNotify");
2064 case MapNotify: return("MapNotify");
2065 case ReparentNotify: return("ReparentNotify");
2066 case UnmapNotify: return("UnmapNotify");
2067 case CreateNotify: return("CreateNotify");
2068 case CirculateRequest: return("CirculateRequest");
2069 case ConfigureRequest: return("ConfigureRequest");
2070 case MapRequest: return("MapRequest");
2071 case MappingNotify: return("MappingNotify");
2072 case ClientMessage: return("ClientMessage");
2073 case SelectionClear: return("SelectionClear");
2074 case SelectionNotify: return("SelectionNotify");
2075 case SelectionRequest: return("SelectionRequest");
2076 default: return("UNKNOWN");
2077 }
2078 }
2079
2080
2081 extern const char *
_LtDebugFocusMode2String(int type)2082 _LtDebugFocusMode2String(int type)
2083 {
2084 switch (type)
2085 {
2086 case NotifyNormal: return("NotifyNormal");
2087 case NotifyGrab: return("NotifyGrab");
2088 case NotifyUngrab: return("NotifyUngrab");
2089 case NotifyWhileGrabbed: return("NotifyWhileGrabbed");
2090 default: return("UNKNOWN");
2091 }
2092 }
2093
2094
2095 extern const char *
_LtDebugFocusDetail2String(int type)2096 _LtDebugFocusDetail2String(int type)
2097 {
2098 switch (type)
2099 {
2100 case NotifyAncestor: return("NotifyAncestor");
2101 case NotifyDetailNone: return("NotifyDetailNone");
2102 case NotifyInferior: return("NotifyInferior");
2103 case NotifyNonlinear: return("NotifyNonlinear");
2104 case NotifyNonlinearVirtual: return("NotifyNonlinearVirtual");
2105 case NotifyPointer: return("NotifyPointer");
2106 case NotifyPointerRoot: return("NotifyPointerRoot");
2107 case NotifyVirtual: return("NotifyVirtual");
2108 default: return("UNKNOWN");
2109 }
2110 }
2111
2112 extern const char *
_LtDebugFrameChildType2String(int action)2113 _LtDebugFrameChildType2String(int action)
2114 {
2115 switch(action)
2116 {
2117 case XmFRAME_GENERIC_CHILD:
2118 return("XmFRAME_GENERIC_CHILD");
2119 case XmFRAME_WORKAREA_CHILD:
2120 return("XmFRAME_WORKAREA_CHILD");
2121 case XmFRAME_TITLE_CHILD:
2122 return("XmFRAME_TITLE_CHILD");
2123 default:
2124 return("Unknown frame childtype");
2125 }
2126 }
2127
2128 extern void
_LtDebugAction(const char * fn,Widget w,const String action,const String * params,const Cardinal * num_params)2129 _LtDebugAction(const char *fn, Widget w, const String action,
2130 const String *params, const Cardinal *num_params)
2131 {
2132 #ifndef LESSTIF_PRODUCTION
2133
2134 if (_LtDebugInit() && ValidateSource(fn)) {
2135 int i;
2136
2137 if (w) {
2138 if (__LtDebugPrintWidgetID()) {
2139 fprintf(_LtDebugFile, "%s %s [%p]: ",
2140 w->core.widget_class->core_class.class_name,
2141 XtName(w), w);
2142 } else {
2143 fprintf(_LtDebugFile, "%s %s: ",
2144 w->core.widget_class->core_class.class_name, XtName(w));
2145 }
2146 } else {
2147 fprintf(_LtDebugFile, "(null widget): ");
2148 }
2149
2150 fprintf(_LtDebugFile, "Action %s(", action);
2151 if (*num_params) {
2152 fprintf(_LtDebugFile, "%s", params[0]);
2153 }
2154 for (i=1; i<(int)*num_params; i++) {
2155 fprintf(_LtDebugFile, ", %s", params[i]);
2156 }
2157 fprintf(_LtDebugFile, ")\n");
2158
2159 fflush(_LtDebugFile);
2160 }
2161 #endif /* !LESSTIF_PRODUCTION */
2162 }
2163
2164 /*
2165 * For use with dmalloc, a malloc debugging package.
2166 * Mimick Xt behaviour ...
2167 * NEVER call them directly!
2168 */
2169
2170 extern XtPointer
_LtDebugMalloc(const char * f,int l,Cardinal size)2171 _LtDebugMalloc(const char *f, int l, Cardinal size)
2172 {
2173 XtPointer r=NULL;
2174 #ifdef WITH_DMALLOC
2175 if (size == 0)
2176 {
2177 size = 1;
2178 }
2179
2180 r = _malloc_leap(f, l, size);
2181
2182 if (r == NULL)
2183 {
2184 _XtAllocError("malloc");
2185 }
2186 #endif
2187 return r;
2188 }
2189
2190
2191 extern XtPointer
_LtDebugCalloc(const char * f,int l,Cardinal count,Cardinal size)2192 _LtDebugCalloc(const char *f, int l, Cardinal count, Cardinal size)
2193 {
2194 XtPointer p=NULL;
2195 #ifdef WITH_DMALLOC
2196 if (!size)
2197 {
2198 count = size = 1;
2199 }
2200
2201 p = _calloc_leap(f, l, count, size);
2202
2203 if (p == NULL)
2204 {
2205 _XtAllocError("calloc");
2206 }
2207 #endif
2208 return p;
2209 }
2210
2211
2212 extern XtPointer
_LtDebugRealloc(const char * f,int l,XtPointer p,Cardinal size)2213 _LtDebugRealloc(const char *f, int l, XtPointer p, Cardinal size)
2214 {
2215 XtPointer r=NULL;
2216 #ifdef WITH_DMALLOC
2217 if (p == NULL)
2218 {
2219 return _malloc_leap(f, l, size);
2220 }
2221
2222 r = _realloc_leap(f, l, p, size);
2223 if (r == NULL)
2224 {
2225 _XtAllocError("realloc");
2226 }
2227 #endif
2228 return r;
2229 }
2230
2231 extern void
_LtDebugFree(const char * f,int l,XtPointer p)2232 _LtDebugFree(const char *f, int l, XtPointer p)
2233 {
2234 #ifdef WITH_DMALLOC
2235 if (p)
2236 {
2237 _free_leap(f, l, p);
2238 }
2239 #endif
2240 }
2241
2242 /*
2243 * Only include this when necessary.
2244 * What is this really dependent on ?
2245 */
2246 extern void
_LtDebugPrintStackTrace()2247 _LtDebugPrintStackTrace()
2248 {
2249 #ifndef LESSTIF_PRODUCTION
2250 #ifdef HAVE_BACKTRACE
2251 void *trace[32];
2252 char **messages = (char **)0;
2253 int i, trace_size = 0;
2254
2255 _LtDebugInit();
2256 trace_size = backtrace(trace, 32);
2257 messages = (char **)backtrace_symbols(trace, trace_size);
2258 fprintf(_LtDebugFile, "[bt] Stack trace\n");
2259 for (i=0; i<trace_size; i++)
2260 fprintf(_LtDebugFile, "\t[%s]\n", messages[i]);
2261 fflush(_LtDebugFile);
2262 #endif
2263 #endif
2264 }
2265
2266 extern void
_LtDebugPrintManagedChildren(const char * fn,Widget w,const char * title)2267 _LtDebugPrintManagedChildren(const char *fn, Widget w, const char *title)
2268 {
2269 #ifndef LESSTIF_PRODUCTION
2270 int i;
2271
2272 _LtDebugInit();
2273 if (! ValidateSource(fn))
2274 return;
2275
2276 for (i=0; i<MGR_NumChildren(w); i++) {
2277 Widget c = MGR_Children(w)[i];
2278 fprintf(_LtDebugFile, "\t%s %d - %s - managed %d\n",
2279 title, i, XtName(c),
2280 XtIsManaged(c) ? 1 : 0);
2281
2282 }
2283 #endif
2284 }
2285
2286 extern const char *
_LtDebugVisualPolicy2String(int vp)2287 _LtDebugVisualPolicy2String(int vp)
2288 {
2289 switch (vp) {
2290 case XmCONSTANT: return "XmCONSTANT";
2291 case XmVARIABLE: return "XmVARIABLE";
2292 case XmRESIZE_IF_POSSIBLE: return "XmRESIZE_IF_POSSIBLE";
2293 default: return "???";
2294 }
2295 }
2296
2297 extern const char *
_LtDebugScrollPolicy2String(int vp)2298 _LtDebugScrollPolicy2String(int vp)
2299 {
2300 switch (vp) {
2301 case XmAPPLICATION_DEFINED: return "XmAPPLICATION_DEFINED";
2302 case XmAUTOMATIC: return "XmAUTOMATIC";
2303 default: return "???";
2304 }
2305 }
2306
2307 extern const char *
_LtDebugXmStringComponentType2String(int ct)2308 _LtDebugXmStringComponentType2String(int ct)
2309 {
2310 switch (ct) {
2311 case XmSTRING_COMPONENT_UNKNOWN: return "XmSTRING_COMPONENT_UNKNOWN";
2312 case XmSTRING_COMPONENT_CHARSET: return "XmSTRING_COMPONENT_CHARSET";
2313 case XmSTRING_COMPONENT_TEXT: return "XmSTRING_COMPONENT_TEXT";
2314 case XmSTRING_COMPONENT_DIRECTION: return "XmSTRING_COMPONENT_DIRECTION";
2315 case XmSTRING_COMPONENT_SEPARATOR: return "XmSTRING_COMPONENT_SEPARATOR";
2316 case XmSTRING_COMPONENT_LOCALE_TEXT: return "XmSTRING_COMPONENT_LOCALE_TEXT";
2317 case XmSTRING_COMPONENT_LOCALE: return "XmSTRING_COMPONENT_LOCALE";
2318 case XmSTRING_COMPONENT_WIDECHAR_TEXT: return "XmSTRING_COMPONENT_WIDECHAR_TEXT";
2319 case XmSTRING_COMPONENT_LAYOUT_PUSH: return "XmSTRING_COMPONENT_LAYOUT_PUSH";
2320 case XmSTRING_COMPONENT_LAYOUT_POP: return "XmSTRING_COMPONENT_LAYOUT_POP";
2321 case XmSTRING_COMPONENT_RENDITION_BEGIN: return "XmSTRING_COMPONENT_RENDITION_BEGIN";
2322 case XmSTRING_COMPONENT_RENDITION_END: return "XmSTRING_COMPONENT_RENDITION_END";
2323 case XmSTRING_COMPONENT_TAB: return "XmSTRING_COMPONENT_TAB";
2324 default: return "??";
2325 }
2326 }
2327