URI:
       terror.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       terror.c (2133B)
       ---
            1 /* Copyright (c) 1994-1996 David Hogan, see README for licence details */
            2 #include <stdio.h>
            3 #include <stdlib.h>
            4 #include <X11/X.h>
            5 #include <X11/Xlib.h>
            6 #include <X11/Xutil.h>
            7 #include <X11/Xproto.h>
            8 #include "dat.h"
            9 #include "fns.h"
           10 
           11 int         ignore_badwindow;
           12 
           13 void
           14 fatal(char *s)
           15 {
           16         fprintf(stderr, "rio: ");
           17         perror(s);
           18         fprintf(stderr, "\n");
           19         exit(1);
           20 }
           21 
           22 int
           23 handler(Display *d, XErrorEvent *e)
           24 {
           25         char msg[80], req[80], number[80];
           26 
           27         if(initting && (e->request_code == X_ChangeWindowAttributes) && (e->error_code == BadAccess)){
           28                 fprintf(stderr, "rio: it looks like there's already a window manager running;  rio not started\n");
           29                 exit(1);
           30         }
           31 
           32         if(ignore_badwindow && (e->error_code == BadWindow || e->error_code == BadColor))
           33                 return 0;
           34 
           35         XGetErrorText(d, e->error_code, msg, sizeof(msg));
           36         sprintf(number, "%d", e->request_code);
           37         XGetErrorDatabaseText(d, "XRequest", number, "", req, sizeof(req));
           38         if(req[0] == '\0')
           39                 sprintf(req, "<request-code-%d>", (int)e->request_code);
           40 
           41         fprintf(stderr, "rio: %s(0x%x): %s\n", req, (int)e->resourceid, msg);
           42 
           43         if(initting){
           44                 fprintf(stderr, "rio: failure during initialisation; aborting\n");
           45                 exit(1);
           46         }
           47         return 0;
           48 }
           49 
           50 void
           51 graberror(char *f, int err)
           52 {
           53 #ifdef        DEBUG        /* sick of "bug" reports; grab errors "just happen" */
           54         char *s;
           55 
           56         switch (err){
           57         case GrabNotViewable:
           58                 s = "not viewable";
           59                 break;
           60         case AlreadyGrabbed:
           61                 s = "already grabbed";
           62                 break;
           63         case GrabFrozen:
           64                 s = "grab frozen";
           65                 break;
           66         case GrabInvalidTime:
           67                 s = "invalid time";
           68                 break;
           69         case GrabSuccess:
           70                 return;
           71         default:
           72                 fprintf(stderr, "rio: %s: grab error: %d\n", f, err);
           73                 return;
           74         }
           75         fprintf(stderr, "rio: %s: grab error: %s\n", f, s);
           76 #endif
           77 }
           78 
           79 #ifdef        DEBUG_EV
           80 #include "showevent/ShowEvent.c"
           81 #endif
           82 
           83 #ifdef        DEBUG
           84 
           85 void
           86 dotrace(char *s, Client *c, XEvent *e)
           87 {
           88         if(debug == 0)
           89                 return;
           90 setbuf(stdout, 0);
           91         fprintf(stderr, "rio: %s: c=%p", s, (void*)c);
           92         if(c)
           93                 fprintf(stderr, " x %d y %d dx %d dy %d w 0x%x parent 0x%x", c->x, c->y, c->dx, c->dy, (int)c->window, (int)c->parent);
           94 #ifdef        DEBUG_EV
           95         if(e){
           96                 fprintf(stderr, "\n\t");
           97                 ShowEvent(e);
           98         }
           99 #endif
          100         fprintf(stderr, "\n");
          101 }
          102 #endif