diff options
author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2009-05-14 00:04:34 +0200 |
---|---|---|
committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2009-05-14 00:04:34 +0200 |
commit | ccafacb3ff22c85516ff46a88275097936dfe442 (patch) | |
tree | cb903821e5bdf342a85ae1834fe688da2bf33992 | |
parent | fd281ad336166de21c9d8652f465ab40a0f12468 (diff) | |
download | st-ccafacb3ff22c85516ff46a88275097936dfe442.tar.gz st-ccafacb3ff22c85516ff46a88275097936dfe442.zip |
added some error checking in xinit (fixed the segfault caused by a missing font)
-rw-r--r-- | st.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -703,18 +703,25 @@ xinit(void) { | |||
703 | 703 | ||
704 | xw.dis = XOpenDisplay(NULL); | 704 | xw.dis = XOpenDisplay(NULL); |
705 | xw.scr = XDefaultScreen(xw.dis); | 705 | xw.scr = XDefaultScreen(xw.dis); |
706 | if(!(xw.dis && xw.scr)) | ||
707 | die("can not open display"); | ||
708 | |||
706 | /* font */ | 709 | /* font */ |
707 | dc.font = XLoadQueryFont(xw.dis, FONT); | 710 | if(!(dc.font = XLoadQueryFont(xw.dis, FONT))) |
711 | die("can not find font " FONT); | ||
712 | |||
708 | xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing; | 713 | xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing; |
709 | xw.ch = dc.font->ascent + dc.font->descent + LINESPACE; | 714 | xw.ch = dc.font->ascent + dc.font->descent + LINESPACE; |
715 | |||
710 | /* colors */ | 716 | /* colors */ |
711 | for(i = 0; i < LEN(colorname); i++) | 717 | for(i = 0; i < LEN(colorname); i++) |
712 | dc.col[i] = xgetcol(colorname[i]); | 718 | dc.col[i] = xgetcol(colorname[i]); |
719 | |||
713 | term.c.attr.fg = DefaultFG; | 720 | term.c.attr.fg = DefaultFG; |
714 | term.c.attr.bg = DefaultBG; | 721 | term.c.attr.bg = DefaultBG; |
715 | term.c.attr.mode = ATnone; | 722 | term.c.attr.mode = ATnone; |
716 | /* windows */ | 723 | /* windows */ |
717 | xw.h = term.row * xw.ch; | 724 | xw.h = term.row * xw.ch; |
718 | xw.w = term.col * xw.cw; | 725 | xw.w = term.col * xw.cw; |
719 | /* XXX: this BORDER is useless after the first resize, handle it in xdraws() */ | 726 | /* XXX: this BORDER is useless after the first resize, handle it in xdraws() */ |
720 | xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0, | 727 | xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0, |
@@ -736,6 +743,7 @@ xinit(void) { | |||
736 | XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint); | 743 | XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint); |
737 | XStoreName(xw.dis, xw.win, TNAME); | 744 | XStoreName(xw.dis, xw.win, TNAME); |
738 | XSync(xw.dis, 0); | 745 | XSync(xw.dis, 0); |
746 | |||
739 | } | 747 | } |
740 | 748 | ||
741 | void | 749 | void |
@@ -908,13 +916,13 @@ run(void) { | |||
908 | int | 916 | int |
909 | main(int argc, char *argv[]) { | 917 | main(int argc, char *argv[]) { |
910 | if(argc == 2 && !strncmp("-v", argv[1], 3)) | 918 | if(argc == 2 && !strncmp("-v", argv[1], 3)) |
911 | die("st-"VERSION", © 2009 st engineers\n"); | 919 | die("st-"", © 2009 st engineers\n"); |
912 | else if(argc != 1) | 920 | else if(argc != 1) |
913 | die("usage: st [-v]\n"); | 921 | die("usage: st [-v]\n"); |
914 | setlocale(LC_CTYPE, ""); | 922 | setlocale(LC_CTYPE, ""); |
915 | tnew(80, 24); | 923 | tnew(80, 24); |
916 | ttynew(); | 924 | ttynew(); |
917 | xinit(); | 925 | xinit(); |
918 | run(); | 926 | run(); |
919 | return 0; | 927 | return 0; |
920 | } | 928 | } |