2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 #ifdef VERBOSE_REV_INFO
25 static char rcs_id[] = "$XConsortium: TermPrimDebug.c /main/4 1996/11/21 19:58:15 drk $";
26 #endif /* VERBOSE_REV_INFO */
30 * (c) Copyright 1993, 1994, 1996 Hewlett-Packard Company *
31 * (c) Copyright 1993, 1994, 1996 International Business Machines Corp. *
32 * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc. *
33 * (c) Copyright 1993, 1994, 1996 Novell, Inc. *
34 * (c) Copyright 1996 Digital Equipment Corporation. *
35 * (c) Copyright 1996 FUJITSU LIMITED. *
36 * (c) Copyright 1996 Hitachi. *
43 #include "TermHeader.h"
44 #include "TermPrimDebug.h"
47 #define X_INCLUDE_STRING_H
48 #define XOS_USE_NO_LOCKING
49 #include <X11/Xos_r.h>
51 unsigned char *debugLevel[256] = { NULL }; /* debug level */
57 isDebugFSet(int c, int f)
62 i = ((f < _TERM_MAX_DEBUG_FLAG) ?
63 debugLevel[c % 256] &&
64 (debugLevel[c % 256][__TERM_DEBUG_BYTE(f)] & __TERM_DEBUG_BIT(f)) :
66 _DtTermProcessUnlock();
86 typedef struct _argArray {
88 struct _argArray *next;
95 setDebugFlags(char *c1)
105 char charArray[BUFSIZ];
106 unsigned char theseFlags[_TERM_DEBUG_NUM_BYTES];
112 static Boolean catchExitRegistered = False;
113 _Xstrtokparams strtok_buf;
115 /* ignore null or empty strings... */
120 /* register our catchExit() function... */
121 _DtTermProcessLock();
122 if (!catchExitRegistered) {
123 (void) atexit(catchExit);
124 catchExitRegistered = True;
130 /* don't destroy the original string... */
131 c2 = malloc(strlen(c1) + 1);
132 (void) strcpy(c2, c1);
135 argHead.next = (argArray *) 0;
137 while (c3 = _XStrtok(c2, " \t\n", strtok_buf)) {
138 /* null out c2 so we won't restart strtok... */
140 argPtr->next = (argArray *) malloc(sizeof(argArray));
141 argPtr = argPtr->next;
142 argPtr->next = (argArray *) 0;
146 /* run through the linked list and parse each string... */
147 for (argPtr = argHead.next; argPtr; argPtr = argPtr->next) {
148 charList = argPtr->str;
149 flagList = (char *) 0;
150 if (c2 = strchr(argPtr->str, ':')) {
151 /* null out the ':'... */
156 /* fill out the char array... */
157 for (c2 = charArray; *charList; ) {
159 if (isalpha(*charList)) {
161 startChar = *charList++;
166 if (*charList == '-') {
169 if (isalpha(*charList)) {
170 endChar = *charList++;
179 while (startChar <= endChar) {
189 /* fill out theseFlags... */
190 (void) memset(theseFlags, '\0', sizeof(theseFlags));
191 if (!flagList || !*flagList) {
192 flagList = strdup("-");
196 while (flagList = _XStrtok(c3, ",", strtok_buf)) {
197 /* null out c3 so we won't restart strtok... */
199 if (!flagList || !*flagList) {
202 if (isdigit(*flagList)) {
203 startFlag = strtol(flagList, &flagList, 0);
209 if (*flagList == '-') {
210 /* we have a range... */
211 /* skip over the '-'... */
213 if (isdigit(*flagList)) {
214 endFlag = strtol(flagList, (char **) 0, 0);
216 endFlag = _TERM_MAX_DEBUG_FLAG - 1;
223 if (endFlag > (_TERM_MAX_DEBUG_FLAG - 1)) {
224 endFlag = _TERM_MAX_DEBUG_FLAG - 1;
226 for (; startFlag <= endFlag; startFlag++) {
227 theseFlags[__TERM_DEBUG_BYTE(startFlag)] |=
228 __TERM_DEBUG_BIT(startFlag);
232 /* now run through the the char array and or in these flags... */
233 for (c2 = charArray; *c2; c2++) {
235 if (!debugLevel[*c2]) {
237 (unsigned char *) malloc(_TERM_DEBUG_NUM_BYTES);
238 (void) memset(debugLevel[*c2], '\0', _TERM_DEBUG_NUM_BYTES);
240 for (i1 = 0; i1 < _TERM_DEBUG_NUM_BYTES; i1++) {
241 debugLevel[*c2][i1] |= theseFlags[i1];
247 /* dump out a list of set flags... */
248 if (isDebugFSet('v', 0)) {
249 for (i1 = 0; i1 < 256; i1++) {
250 if (debugLevel[i1]) {
251 (void) fprintf(stderr, "debug flag '%c' ", i1);
252 for (i2 = 0; i2 < _TERM_MAX_DEBUG_FLAG; i2++) {
253 if (i2 > 0 && (0 == i2 % 50)) {
254 (void) fputs("\n ", stderr);
256 if (debugLevel[i1][__TERM_DEBUG_BYTE(i2)] &
257 __TERM_DEBUG_BIT(i2)) {
258 (void) putc('X', stderr);
260 (void) putc('.', stderr);
263 (void) putc('\n', stderr);
267 _DtTermProcessUnlock();
270 static Boolean timedOut;
288 struct sigaction action;
289 struct sigaction oldAction;
292 struct itimerval itime;
293 struct itimerval oldItime;
295 _DtTermProcessLock();
298 /* block SIGALRM... */
299 (void) sigemptyset(&sigset);
300 (void) sigaddset(&sigset, SIGALRM);
301 (void) sigprocmask(SIG_BLOCK, &sigset, &oldSigset);
303 /* set up a singnal handler for SIGALRM... */
304 action.sa_handler = ding;
306 (void) sigemptyset(&action.sa_mask);
307 (void) sigaction(SIGALRM, &action, &oldAction);
309 /* set an alarm... */
310 timerclear(&itime.it_interval);
311 itime.it_value.tv_usec = msec % 1000000;
312 itime.it_value.tv_sec = msec / 1000000;
313 (void) setitimer(ITIMER_REAL, &itime, &oldItime);
315 /* unblock SIGALRM and wait for a signal... */
316 (void) sigprocmask(SIG_BLOCK, (sigset_t *) 0, &sigset);
317 (void) sigdelset(&sigset, SIGALRM);
322 /* restore old handler... */
323 (void) sigaction(SIGALRM, &oldAction, (struct sigaction *) 0);
325 /* restore old signal mask... */
326 (void) sigprocmask(SIG_SETMASK, &oldSigset, (sigset_t *) 0);
327 _DtTermProcessUnlock();
330 static FILE *timeStampFile = (FILE *) 0;
341 _DtTermProcessLock();
342 if (!timeStampFile) {
346 if (!(c = getenv("timeStampFileName"))) {
347 (void) sprintf(buffer, "timeStamp-%d", getpid());
351 if (!(timeStampFile = fopen(c, "a"))) {
352 _DtTermProcessUnlock();
356 (void) setvbuf(timeStampFile, (char *) 0, _IOLBF, 0);
358 _DtTermProcessUnlock();
360 (void) gettimeofday(&tv, &tz);
361 (void) fprintf(timeStampFile, "%lu %ld %s\n", tv.tv_sec, tv.tv_usec,
362 (msg && *msg) ? msg : "");
370 static enumName eventTypes[] = {
374 {"ButtonRelease", 5},
380 {"KeymapNotify", 11},
382 {"GraphicsExpose", 13},
384 {"VisibilityNotify", 15},
385 {"CreateNotify", 16},
386 {"DestroyNotify", 17},
390 {"ReparentNotify", 21},
391 {"ConfigureNotify", 22},
392 {"ConfigureRequest", 23},
393 {"GravityNotify", 24},
394 {"ResizeRequest", 25},
395 {"CirculateNotify", 26},
396 {"CirculateRequest", 27},
397 {"PropertyNotify", 28},
398 {"SelectionClear", 29},
399 {"SelectionRequest", 30},
400 {"SelectionNotify", 31},
401 {"ColormapNotify", 32},
402 {"ClientMessage", 33},
403 {"MappingNotify", 34},
408 static enumName notifyModes[] = {
412 {"NotifyWhileGrabbed", 3},
416 static enumName notifyDetails[] = {
417 {"NotifyAncestor", 0},
418 {"NotifyVirtual", 1},
419 {"NotifyInferior", 2},
420 {"NotifyNonlinear", 3},
421 {"NotifyNonlinearVirtual", 4},
422 {"NotifyPointer", 5},
423 {"NotifyPointerRoot", 6},
424 {"NotifyDetailNone", 7},
428 static enumName boolTypes[] = {
443 static char *retBuffer = (char *) 0;
445 for (i1 = 0; list[i1].string; i1++) {
446 if (list[i1].value == value) {
447 return(list[i1].string);
450 (void) sprintf(buffer, "Unknown Value %d", value);
451 retBuffer = realloc(retBuffer, strlen(buffer));
452 (void) strcpy(retBuffer, buffer);
457 _DtTermPrimDebugDumpEvent
464 _DtTermProcessLock();
465 (void) fprintf(f, ">> widget: name=\"%s\" widget=0x%lx window=0x%lx\n",
466 XtName(w), w, XtWindow(w));
467 (void) fprintf(f, ">> event {\n");
468 (void) fprintf(f, ">> type=%s;\n",
469 enumToName(eventTypes, ev->xany.type));
470 (void) fprintf(f, ">> serial=%lu\n", ev->xany.serial);
471 (void) fprintf(f, ">> send_event=%s\n",
472 enumToName(boolTypes, ev->xany.send_event));
473 (void) fprintf(f, ">> display=0x%lx\n", ev->xany.display);
474 (void) fprintf(f, ">> window=0x%lx\n", ev->xany.window);
478 (void) fprintf(f, ">> root=0x%lx\n", ev->xcrossing.root);
479 (void) fprintf(f, ">> subwindow=0x%lx\n", ev->xcrossing.subwindow);
480 (void) fprintf(f, ">> mode=%s\n",
481 enumToName(notifyModes, ev->xcrossing.mode));
482 (void) fprintf(f, ">> detail=%s\n",
483 enumToName(notifyDetails, ev->xcrossing.detail));
484 (void) fprintf(f, ">> focus=%s\n",
485 enumToName(boolTypes, ev->xcrossing.focus));
490 (void) fprintf(f, ">> mode=%s\n",
491 enumToName(notifyModes, ev->xcrossing.mode));
492 (void) fprintf(f, ">> detail=%s\n",
493 enumToName(notifyDetails, ev->xcrossing.detail));
496 (void) fprintf(f, ">> }\n");
497 _DtTermProcessUnlock();