File: error.c

package info (click to toggle)
gwm 1.8d-2
  • links: PTS
  • area: main
  • in suites: potato, woody
  • size: 5,120 kB
  • ctags: 3,030
  • sloc: ansic: 19,617; makefile: 1,763; lisp: 437; sh: 321; ml: 21
file content (200 lines) | stat: -rw-r--r-- 4,474 bytes parent folder | download | duplicates (2)
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
/* Copyright 1989 GROUPE BULL -- See license conditions in file COPYRIGHT
 * Copyright 1989 Massachusetts Institute of Technology
 */
/**************************************\
*   				       *
* 	BULL WINDOW MANAGER for X11    *
* 				       *
* 		error handling.	       *
* 				       *
\**************************************/

/*  include  */
#include 	<stdio.h>
#include	<errno.h>
#include 	"EXTERN.h"
#include 	"gwm.h"
#include	"wl_atom.h"
#include	"yacc.h"

/*  external  */

extern void     UserMessage();

/*  global  */

/* request error codes */

#define MAX_X_EVENT 64

#ifdef SECURE
char *eventtype[MAX_X_EVENT] = {
	"zero",
	"one",
	"KeyPress",
	"KeyRelease",
	"ButtonPress",
	"ButtonRelease",
	"MotionNotify",
	"EnterNotify",
	"LeaveNotify",
	"FocusIn",
	"FocusOut",
	"KeymapNotify",
	"Expose",
	"GraphicsExpose",
	"NoExpose",
	"VisibilityNotify",
	"CreateNotify",
	"DestroyNotify",
	"UnmapNotify",
	"MapNotify",
	"MapRequest",
	"ReparentNotify",
	"ConfigureNotify",
	"ConfigureRequest",
	"GravityNotify",
	"ResizeRequest",
	"CirculateNotify",
	"CirculateRequest",
	"PropertyNotify",
	"SelectionClear",
	"SelectionRequest",
	"SelectionNotify",
	"ColormapNotify",
	"ClientMessage",
	"MappingNotify",
	"LASTEvent",
	"GWMUserEvent"
};

#endif /* SECURE */

#ifdef DO_BUS_ERROR
#define DoABusError() *((int *)0) = 1
#else /* DO_BUS_ERROR */
#define DoABusError()
#endif /* DO_BUS_ERROR */

/*  routines  */

/* purposeful silent error handler */

NoXError(display, error)
Display        *display;
XErrorEvent    *error;
{
    ErrorStatus = error -> error_code;
}

/*
 * Normal verbose error handler 
 */

XError(display, error)
Display        *display;
XErrorEvent    *error;
{
    char            msg[MAX_TEMP_STRING_SIZE], buffer[MAX_TEMP_STRING_SIZE];
    char            number[32];

    /* aborts if anything occurs while decorating */

    if (GWM_window_being_decorated
	&& error -> error_code == BadWindow
	&& error -> resourceid == GWM_window_being_decorated -> client) {
	ClientWindowClose(GWM_window_being_decorated);
	GWM_window_being_decorated = 0;
	/* flush errors, there are surely more coming along! */
	FlushXErrors();
	longjmp(wool_goes_here_on_error, 1);
    } else if (wool_do_print_errors
#ifndef DEBUG
	       && error -> error_code != BadWindow
	       && error -> error_code != BadDrawable
#endif
	       ) {
	if (GWM_Synchronize) {		/* only meaningful when sync */
	    if (wool_is_reading_file) {
		wool_printf("\"%s\"", wool_is_reading_file);
		wool_printf(": line %d, ", yylineno);
	    }
	    wool_stack_dump(0);
	}
	wool_puts("Gwm X error: ");
	sprintf(number, "%d", error -> request_code);
	XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer,
			      MAX_TEMP_STRING_SIZE);
	sprintf(msg, "%s(0x%x): ", buffer, error -> resourceid);
	wool_puts(msg);
	XGetErrorText(display, error -> error_code, msg,
		      MAX_TEMP_STRING_SIZE);
	wool_puts(msg);
	if (error -> minor_code)
	    sprintf(msg, " (minor = %d)", error -> minor_code);
	wool_newline();
	yyoutflush();
    }
    ErrorStatus = error -> error_code;
    stop_if_in_dbx();
    DoABusError();
}

Error(s1, s2)
char           *s1, *s2;
{
    UserMessage(s1, s2);
}

void
UserMessage(s1, s2)
char           *s1, *s2;
{
    wool_puts(s1);
    wool_puts(s2);
    wool_newline();
}

/* what to do when a wool-error occurs?
 */

wool_error_handler()
{
    if (GWM_ServerGrabbed)
	remove_grab(0);
    if (GWM_is_restarting || GWM_is_ending)
	GWM_BusErrorSignalHandler(0);	/* skip wool when error in ending */
    if (GWM_Window_being_opened)
    	XMapWindow(dpy, GWM_Window_being_opened -> hook);
}

/* some silent X primitives */

int
GwmSilentXGetWindowProperty(display,w,property,long_offset,long_length,
			    delete,req_type,actual_type_return,
			    actual_format_return,nitems_return,
			    bytes_after_return,prop_return)
    Display*		 display;
    Window		 w;
    Atom		 property;
    long		 long_offset;
    long		 long_length;
    Bool		 delete;
    Atom		 req_type;
    Atom*		 actual_type_return;
    int*		 actual_format_return;
    unsigned long*	 nitems_return;
    unsigned long*	 bytes_after_return;
    unsigned char**	 prop_return;
{
    int result;
    XSetErrorHandler(NoXError);
    result = XGetWindowProperty(display,w,property,long_offset,long_length,
			    delete,req_type,actual_type_return,
			    actual_format_return,nitems_return,
			    bytes_after_return,prop_return);
    XSync(dpy, 0);
    XSetErrorHandler(XError);
    return result;
}