Xinqi Bao's Git

Only variable declarations at top of block
[slstatus.git] / slstatus.c
index c7e9303..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 {
@@ -18,44 +17,8 @@ struct arg {
        const char *args;
 };
 
-static const char *battery_perc(const char *bat);
-static const char *battery_power(const char *bat);
-static const char *battery_state(const char *bat);
-static const char *cpu_freq(void);
-static const char *cpu_perc(void);
-static const char *cpu_iowait(void);
-static const char *datetime(const char *fmt);
-static const char *disk_free(const char *mnt);
-static const char *disk_perc(const char *mnt);
-static const char *disk_total(const char *mnt);
-static const char *disk_used(const char *mnt);
-static const char *entropy(void);
-static const char *gid(void);
-static const char *hostname(void);
-static const char *ipv4(const char *iface);
-static const char *ipv6(const char *iface);
-static const char *kernel_release(void);
-static const char *keyboard_indicators(void);
-static const char *load_avg(const char *fmt);
-static const char *num_files(const char *dir);
-static const char *ram_free(void);
-static const char *ram_perc(void);
-static const char *ram_used(void);
-static const char *ram_total(void);
-static const char *run_command(const char *cmd);
-static const char *swap_free(void);
-static const char *swap_perc(void);
-static const char *swap_used(void);
-static const char *swap_total(void);
-static const char *temp(const char *file);
-static const char *uid(void);
-static const char *uptime(void);
-static const char *username(void);
-static const char *vol_perc(const char *card);
-static const char *wifi_perc(const char *iface);
-static const char *wifi_essid(const char *iface);
-
 char *argv0;
+char buf[1024];
 static unsigned short int done;
 static Display *dpy;
 
@@ -64,6 +27,8 @@ static Display *dpy;
 static void
 terminate(const int signo)
 {
+       (void)signo;
+
        done = 1;
 }
 
@@ -88,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;
@@ -111,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;
        }
 
@@ -120,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';