Xinqi Bao's Git

moved headers to extern
[slstatus.git] / slstatus.c
index e1d271f..99ef720 100644 (file)
 #undef strlcat
 #undef strlcpy
 
 #undef strlcat
 #undef strlcpy
 
-#include "arg.h"
-#include "strlcat.h"
-#include "strlcpy.h"
-#include "concat.h"
+#include "extern/arg.h"
+#include "extern/strlcat.h"
+#include "extern/strlcpy.h"
+#include "extern/concat.h"
 
 struct arg {
        char *(*func)();
 
 struct arg {
        char *(*func)();
-       const char *format;
+       const char *fmt;
        const char *args;
 };
 
        const char *args;
 };
 
@@ -633,7 +633,9 @@ main(int argc, char *argv[])
        sigaction(SIGINT,  &act, 0);
        sigaction(SIGTERM, &act, 0);
 
        sigaction(SIGINT,  &act, 0);
        sigaction(SIGTERM, &act, 0);
 
-       dpy = XOpenDisplay(NULL);
+       if (!oflag) {
+               dpy = XOpenDisplay(NULL);
+       }
 
        while (!done) {
                status_string[0] = '\0';
 
        while (!done) {
                status_string[0] = '\0';
@@ -645,7 +647,7 @@ main(int argc, char *argv[])
                        } else {
                                res = argument.func(argument.args);
                        }
                        } else {
                                res = argument.func(argument.args);
                        }
-                       element = smprintf(argument.format, res);
+                       element = smprintf(argument.fmt, res);
                        if (element == NULL) {
                                element = smprintf(UNKNOWN_STR);
                                warnx("Failed to format output");
                        if (element == NULL) {
                                element = smprintf(UNKNOWN_STR);
                                warnx("Failed to format output");
@@ -671,9 +673,8 @@ main(int argc, char *argv[])
 
        if (!oflag) {
                set_status(NULL);
 
        if (!oflag) {
                set_status(NULL);
+               XCloseDisplay(dpy);
        }
 
        }
 
-       XCloseDisplay(dpy);
-
        return 0;
 }
        return 0;
 }