Xinqi Bao's Git

Only variable declarations at top of block
[slstatus.git] / slstatus.c
index b4eb761..c1cf8ac 100644 (file)
@@ -1,6 +1,4 @@
 /* See LICENSE file for copyright and license details. */
-#include <err.h>
-#include <errno.h>
 #include <locale.h>
 #include <signal.h>
 #include <stdio.h>
@@ -10,6 +8,7 @@
 #include <X11/Xlib.h>
 
 #include "arg.h"
+#include "slstatus.h"
 #include "util.h"
 
 struct arg {
@@ -19,15 +18,17 @@ struct arg {
 };
 
 char *argv0;
+char buf[1024];
 static unsigned short int done;
 static Display *dpy;
 
-#include "slstatus.h"
 #include "config.h"
 
 static void
 terminate(const int signo)
 {
+       (void)signo;
+
        done = 1;
 }
 
@@ -52,9 +53,10 @@ main(int argc, char *argv[])
        struct sigaction act;
        struct timespec start, current, diff, intspec, wait;
        size_t i, len;
-       int sflag = 0;
+       int sflag;
        char status[MAXLEN];
 
+       sflag = 0;
        ARGBEGIN {
                case 's':
                        sflag = 1;
@@ -75,7 +77,7 @@ main(int argc, char *argv[])
        sigaction(SIGTERM, &act, NULL);
 
        if (!sflag && !(dpy = XOpenDisplay(NULL))) {
-               fprintf(stderr, "slstatus: cannot open display");
+               fprintf(stderr, "Cannot open display");
                return 1;
        }
 
@@ -84,8 +86,10 @@ main(int argc, char *argv[])
 
                status[0] = '\0';
                for (i = len = 0; i < LEN(args); i++) {
+                       const char * res = args[i].func(args[i].args);
+                       res = (res == NULL) ? unknown_str : res;
                        len += snprintf(status + len, sizeof(status) - len,
-                                       args[i].fmt, args[i].func(args[i].args));
+                                       args[i].fmt, res);
 
                        if (len >= sizeof(status)) {
                                status[sizeof(status) - 1] = '\0';