2001-05-08 10:21:00 -04:00
|
|
|
#include "xlib.h"
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value V_X_Error_Handler, V_X_Fatal_Error_Handler;
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
/* Default error handlers of the Xlib */
|
|
|
|
extern int _XDefaultIOError();
|
|
|
|
extern int _XDefaultError();
|
|
|
|
|
|
|
|
static X_Fatal_Error (d) Display *d; {
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value args, fun;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
Reset_IO (0);
|
|
|
|
args = Make_Display (0, d);
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_GC_PROTECT_1 (args);
|
|
|
|
args = s48_cons (args, S48_NULL);
|
|
|
|
S48_GC_UNPROTECT;
|
2001-05-08 10:21:00 -04:00
|
|
|
fun = Var_Get (V_X_Fatal_Error_Handler);
|
|
|
|
if (TYPE(fun) == T_Compound)
|
|
|
|
(void)Funcall (fun, args, 0);
|
|
|
|
_XDefaultIOError (d);
|
|
|
|
exit (1); /* In case the default handler doesn't exit() */
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
|
|
|
static X_Error (d, ep) Display *d; XErrorEvent *ep; {
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value args, a, fun;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
Reset_IO (0);
|
2001-05-14 09:48:37 -04:00
|
|
|
args = s48_enter_integer ((unsigned long)ep->resourceid);
|
|
|
|
S48_GC_PROTECT_1 (args);
|
|
|
|
args = s48_cons (args, S48_NULL);
|
|
|
|
a = s48_enter_integer (ep->minor_code);
|
|
|
|
args = s48_cons (a, args);
|
|
|
|
a = s48_enter_integer (ep->request_code);
|
|
|
|
args = s48_cons (a, args);
|
2001-05-08 10:21:00 -04:00
|
|
|
a = Bits_To_Symbols ((unsigned long)ep->error_code, 0, Error_Syms);
|
2001-05-14 09:48:37 -04:00
|
|
|
if (S48_NULL_P (a))
|
|
|
|
a = s48_enter_integer (ep->error_code);
|
|
|
|
args = s48_cons (a, args);
|
|
|
|
a = s48_enter_integer (ep->serial);
|
|
|
|
args = s48_cons (a, args);
|
2001-05-08 10:21:00 -04:00
|
|
|
a = Make_Display (0, ep->display);
|
2001-05-14 09:48:37 -04:00
|
|
|
args = s48_cons (a, args);
|
|
|
|
S48_GC_UNPROTECT;
|
2001-05-08 10:21:00 -04:00
|
|
|
fun = Var_Get (V_X_Error_Handler);
|
|
|
|
if (TYPE(fun) == T_Compound)
|
|
|
|
(void)Funcall (fun, args, 0);
|
|
|
|
else
|
|
|
|
_XDefaultError (d, ep);
|
|
|
|
}
|
|
|
|
|
|
|
|
static X_After_Function (d) Display *d; {
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value args;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
args = Make_Display (0, d);
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_GC_PROTECT_1 (args);
|
|
|
|
args = s48_cons (args, S48_NULL);
|
|
|
|
S48_GC_UNPROTECT;
|
|
|
|
(void)Funcall (DISPLAY(S48_CAR (args))->after, args, 0);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Set_After_Function (d, f) s48_value d, f; {
|
|
|
|
s48_value old;
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
2001-05-14 09:48:37 -04:00
|
|
|
if (S48_EQ_P(f, S48_FALSE)) {
|
2001-05-08 10:21:00 -04:00
|
|
|
(void)XSetAfterFunction (DISPLAY(d)->dpy, (int (*)())0);
|
|
|
|
} else {
|
|
|
|
Check_Procedure (f);
|
|
|
|
(void)XSetAfterFunction (DISPLAY(d)->dpy, X_After_Function);
|
|
|
|
}
|
|
|
|
old = DISPLAY(d)->after;
|
|
|
|
DISPLAY(d)->after = f;
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_After_Function (d) s48_value d; {
|
2001-05-08 10:21:00 -04:00
|
|
|
Check_Type (d, T_Display);
|
|
|
|
return DISPLAY(d)->after;
|
|
|
|
}
|
|
|
|
|
|
|
|
elk_init_xlib_error () {
|
2001-05-14 09:48:37 -04:00
|
|
|
Define_Variable (&V_X_Fatal_Error_Handler, "x-fatal-error-handler", S48_NULL);
|
|
|
|
Define_Variable (&V_X_Error_Handler, "x-error-handler", S48_NULL);
|
2001-05-08 10:21:00 -04:00
|
|
|
(void)XSetIOErrorHandler (X_Fatal_Error);
|
|
|
|
(void)XSetErrorHandler (X_Error);
|
|
|
|
Define_Primitive (P_Set_After_Function, "set-after-function!", 2, 2, EVAL);
|
|
|
|
Define_Primitive (P_After_Function, "after-function", 1, 1, EVAL);
|
|
|
|
}
|