Skip to content

Commit

Permalink
error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
TrilbyWhite committed Apr 11, 2013
1 parent 4dcc51c commit c4159f1
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions interrobang.c
Expand Up @@ -21,6 +21,7 @@

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <locale.h>
#include <string.h>
#include <X11/Xlib.h>
Expand Down Expand Up @@ -145,14 +146,19 @@ static int config(int argc, const char **argv) {
return 0;
}

static int die(const char *msg,...) {
fprintf(stderr,"INTERROBANG: Error ");
va_list arg; va_start(arg,msg);
vfprintf(stderr,msg,arg);
va_end(arg);
exit(1);
}

static int init_X() {
/* locale, open connection, basic info */
if ( !setlocale(LC_CTYPE,"") ) exit(2);
if ( !XSupportsLocale() ) exit(3);
if (XSetLocaleModifiers("") == NULL) exit(4);
// if ( !(setlocale(LC_CTYPE,"") && XSupportsLocale()) ) exit(-1);
// if (XSetLocaleModifiers("") == NULL) exit(-1);
if (!(dpy=XOpenDisplay(0x0))) exit(1);
if ( !(setlocale(LC_CTYPE,"") && XSupportsLocale()) ) die("setting locale\n");
if (XSetLocaleModifiers("") == NULL) die("setting modifiers\n");
if (!(dpy=XOpenDisplay(0x0))) die("opening display\n");
scr = DefaultScreen(dpy);
root = RootWindow(dpy,scr);
w = (w ? w : DisplayWidth(dpy,scr) - (strlen(colBD)?2:0));
Expand All @@ -161,7 +167,7 @@ static int init_X() {
/* fonts */
char **missing, **names, *def; int nmiss, i;
xfs = XCreateFontSet(dpy,font,&missing,&nmiss,&def);
if (!xfs) exit(-1);
if (!xfs) die("loading font \"%s\"\n",font);
XFontStruct **fss;
XFontsOfFontSet(xfs,&fss,&names);
if (missing) XFreeStringList(missing);
Expand All @@ -181,7 +187,7 @@ static int init_X() {
CurrentTime) == GrabSuccess) break;
usleep(1000);
}
if (i == 1000) exit(1);
if (i == 1000) die("grabbing keyboard\n");
/* create window and buffer */
XSetWindowAttributes wa;
wa.override_redirect = True;
Expand Down

0 comments on commit c4159f1

Please sign in to comment.