scx/c/xlib/error.c

93 lines
2.7 KiB
C

#include "xlib.h"
static s48_value V_X_Error_Handler, V_X_Fatal_Error_Handler;
/* Default error handlers of the Xlib */
extern int _XDefaultIOError();
extern int _XDefaultError();
static X_Fatal_Error (d) Display *d; {
s48_value args, fun;
S48_DECLARE_GC_PROTECT(1);
Reset_IO (0);
args = Make_Display (0, d);
S48_GC_PROTECT_1 (args);
args = s48_cons (args, S48_NULL);
S48_GC_UNPROTECT;
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; {
s48_value args, a, fun;
S48_DECLARE_GC_PROTECT(1);
Reset_IO (0);
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);
a = Bits_To_Symbols ((unsigned long)ep->error_code, 0, Error_Syms);
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);
a = Make_Display (0, ep->display);
args = s48_cons (a, args);
S48_GC_UNPROTECT;
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; {
s48_value args;
S48_DECLARE_GC_PROTECT(1);
args = Make_Display (0, d);
S48_GC_PROTECT_1 (args);
args = s48_cons (args, S48_NULL);
S48_GC_UNPROTECT;
(void)Funcall (DISPLAY(S48_CAR (args))->after, args, 0);
}
static s48_value P_Set_After_Function (d, f) s48_value d, f; {
s48_value old;
Check_Type (d, T_Display);
if (S48_EQ_P(f, S48_FALSE)) {
(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;
}
static s48_value P_After_Function (d) s48_value d; {
Check_Type (d, T_Display);
return DISPLAY(d)->after;
}
elk_init_xlib_error () {
Define_Variable (&V_X_Fatal_Error_Handler, "x-fatal-error-handler", S48_NULL);
Define_Variable (&V_X_Error_Handler, "x-error-handler", S48_NULL);
(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);
}