added some error checking in xinit (fixed the segfault caused by a missing font)

This commit is contained in:
Aurélien Aptel 2009-05-14 00:04:34 +02:00
parent da01ce7465
commit e6b37f2f87

12
st.c
View File

@ -703,13 +703,20 @@ xinit(void) {
xw.dis = XOpenDisplay(NULL); xw.dis = XOpenDisplay(NULL);
xw.scr = XDefaultScreen(xw.dis); xw.scr = XDefaultScreen(xw.dis);
if(!(xw.dis && xw.scr))
die("can not open display");
/* font */ /* font */
dc.font = XLoadQueryFont(xw.dis, FONT); if(!(dc.font = XLoadQueryFont(xw.dis, FONT)))
die("can not find font " FONT);
xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing; xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing;
xw.ch = dc.font->ascent + dc.font->descent + LINESPACE; xw.ch = dc.font->ascent + dc.font->descent + LINESPACE;
/* colors */ /* colors */
for(i = 0; i < LEN(colorname); i++) for(i = 0; i < LEN(colorname); i++)
dc.col[i] = xgetcol(colorname[i]); dc.col[i] = xgetcol(colorname[i]);
term.c.attr.fg = DefaultFG; term.c.attr.fg = DefaultFG;
term.c.attr.bg = DefaultBG; term.c.attr.bg = DefaultBG;
term.c.attr.mode = ATnone; term.c.attr.mode = ATnone;
@ -736,6 +743,7 @@ xinit(void) {
XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint); XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint);
XStoreName(xw.dis, xw.win, TNAME); XStoreName(xw.dis, xw.win, TNAME);
XSync(xw.dis, 0); XSync(xw.dis, 0);
} }
void void
@ -908,7 +916,7 @@ run(void) {
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
if(argc == 2 && !strncmp("-v", argv[1], 3)) if(argc == 2 && !strncmp("-v", argv[1], 3))
die("st-"VERSION", © 2009 st engineers\n"); die("st-"", © 2009 st engineers\n");
else if(argc != 1) else if(argc != 1)
die("usage: st [-v]\n"); die("usage: st [-v]\n");
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");