radical re-formatting 2/3: Fix blocks
authordrkhsh <me@drkhsh.at>
Thu, 27 Oct 2022 22:51:34 +0000 (00:51 +0200)
committerdrkhsh <me@drkhsh.at>
Thu, 27 Oct 2022 23:03:38 +0000 (01:03 +0200)
Fixes coding style. Formatting commits suck, incoherent coding style
sucks more.
https://suckless.org/coding_style/

14 files changed:
components/battery.c
components/cpu.c
components/ip.c
components/keyboard_indicators.c
components/keymap.c
components/netspeeds.c
components/num_files.c
components/ram.c
components/run_command.c
components/swap.c
components/temperature.c
components/wifi.c
slstatus.c
util.c

index 00ae70a9f5bff276232566bbd7e944d9eb4f534f..b12c59e7d19f48533c69eb69e68ccc340597316f 100644 (file)
             size_t length)
        {
                if (esnprintf(path, length, f1, bat) > 0 &&
-                   access(path, R_OK) == 0) {
+                   access(path, R_OK) == 0)
                        return f1;
-               }
 
                if (esnprintf(path, length, f2, bat) > 0 &&
-                   access(path, R_OK) == 0) {
+                   access(path, R_OK) == 0)
                        return f2;
-               }
 
                return NULL;
        }
@@ -42,9 +40,8 @@
 
                if (esnprintf(path, sizeof(path), POWER_SUPPLY_CAPACITY, bat) < 0)
                        return NULL;
-               if (pscanf(path, "%d", &perc) != 1) {
+               if (pscanf(path, "%d", &perc) != 1)
                        return NULL;
-               }
 
                return bprintf("%d", perc);
        }
 
                if (esnprintf(path, sizeof(path), POWER_SUPPLY_STATUS, bat) < 0)
                        return NULL;
-               if (pscanf(path, "%12[a-zA-Z ]", state) != 1) {
+               if (pscanf(path, "%12[a-zA-Z ]", state) != 1)
                        return NULL;
-               }
 
-               for (i = 0; i < LEN(map); i++) {
-                       if (!strcmp(map[i].state, state)) {
+               for (i = 0; i < LEN(map); i++)
+                       if (!strcmp(map[i].state, state))
                                break;
-                       }
-               }
+
                return (i == LEN(map)) ? "?" : map[i].symbol;
        }
 
@@ -87,9 +82,8 @@
 
                if (esnprintf(path, sizeof(path), POWER_SUPPLY_STATUS, bat) < 0)
                        return NULL;
-               if (pscanf(path, "%12[a-zA-Z ]", state) != 1) {
+               if (pscanf(path, "%12[a-zA-Z ]", state) != 1)
                        return NULL;
-               }
 
                if (!pick(bat, POWER_SUPPLY_CHARGE, POWER_SUPPLY_ENERGY, path,
                          sizeof(path)) ||
                            pscanf(path, "%ju", &current_now) < 0)
                                return NULL;
 
-                       if (current_now == 0) {
+                       if (current_now == 0)
                                return NULL;
-                       }
 
                        timeleft = (double)charge_now / (double)current_now;
                        h = timeleft;
        {
                struct apm_power_info apm_info;
 
-               if (load_apm_power_info(&apm_info)) {
+               if (load_apm_power_info(&apm_info))
                        return bprintf("%d", apm_info.battery_life);
-               }
 
                return NULL;
        }
                size_t i;
 
                if (load_apm_power_info(&apm_info)) {
-                       for (i = 0; i < LEN(map); i++) {
-                               if (map[i].state == apm_info.ac_state) {
+                       for (i = 0; i < LEN(map); i++)
+                               if (map[i].state == apm_info.ac_state)
                                        break;
-                               }
-                       }
+
                        return (i == LEN(map)) ? "?" : map[i].symbol;
                }
 
index 20354c0b966b567e251de7547da44d79138931fe..10d25c0408cea3f19e63e2b36125881c426c6bda 100644 (file)
                /* cpu user nice system idle iowait irq softirq */
                if (pscanf("/proc/stat", "%*s %Lf %Lf %Lf %Lf %Lf %Lf %Lf",
                           &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6])
-                   != 7) {
+                   != 7)
                        return NULL;
-               }
-               if (b[0] == 0) {
+
+               if (b[0] == 0)
                        return NULL;
-               }
 
                sum = (b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6]) -
                      (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6]);
 
-               if (sum == 0) {
+               if (sum == 0)
                        return NULL;
-               }
 
                return bprintf("%d", (int)(100 *
                               ((b[0] + b[1] + b[2] + b[5] + b[6]) -
                        warn("sysctl 'KERN_CPTIME':");
                        return NULL;
                }
-               if (b[0] == 0) {
+               if (b[0] == 0)
                        return NULL;
-               }
 
                sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE]) -
                      (b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]);
 
-               if (sum == 0) {
+               if (sum == 0)
                        return NULL;
-               }
 
                return bprintf("%d", 100 *
                               ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
                        warn("sysctlbyname 'kern.cp_time':");
                        return NULL;
                }
-               if (b[0] == 0) {
+               if (b[0] == 0)
                        return NULL;
-               }
 
                sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE]) -
                      (b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]);
 
-               if (sum == 0) {
+               if (sum == 0)
                        return NULL;
-               }
 
                return bprintf("%d", 100 *
                               ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
index a954ae13650ebc3d9127bc90a1f1be73b05b3d46..947654944f28c1e5cefcee0cad4bde0ae5902cf5 100644 (file)
@@ -27,9 +27,9 @@ ip(const char *interface, unsigned short sa_family)
        }
 
        for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
-               if (!ifa->ifa_addr) {
+               if (!ifa->ifa_addr)
                        continue;
-               }
+
                s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
                                host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
                if (!strcmp(ifa->ifa_name, interface) &&
index 4a815395a991d4aa1978e97ca2bb30dad73d1f79..5f62bb75eb9330933f8e85b1b4353225a0448c4e 100644 (file)
@@ -33,17 +33,18 @@ keyboard_indicators(const char *fmt)
        fmtlen = strnlen(fmt, 4);
        for (i = n = 0; i < fmtlen; i++) {
                key = tolower(fmt[i]);
-               if (key != 'c' && key != 'n') {
+               if (key != 'c' && key != 'n')
                        continue;
-               }
+
                togglecase = (i + 1 >= fmtlen || fmt[i + 1] != '?');
                isset = (state.led_mask & (1 << (key == 'n')));
-               if (togglecase) {
+
+               if (togglecase)
                        buf[n++] = isset ? toupper(key) : key;
-               } else if (isset) {
+               else if (isset)
                        buf[n++] = fmt[i];
-               }
        }
+
        buf[n] = 0;
        return buf;
 }
index e2dbc6f8d128c9d6fe1bbe0e6c2251f3bc0f3c4a..47404311c397390622b63f1abdc4d269049869d2 100644 (file)
@@ -15,11 +15,9 @@ valid_layout_or_variant(char *sym)
        /* invalid symbols from xkb rules config */
        static const char *invalid[] = { "evdev", "inet", "pc", "base" };
 
-       for (i = 0; i < LEN(invalid); i++) {
-               if (!strncmp(sym, invalid[i], strlen(invalid[i]))) {
+       for (i = 0; i < LEN(invalid); i++)
+               if (!strncmp(sym, invalid[i], strlen(invalid[i])))
                        return 0;
-               }
-       }
 
        return 1;
 }
@@ -80,9 +78,8 @@ keymap(const char *unused)
        XFree(symbols);
 end:
        XkbFreeKeyboard(desc, XkbSymbolsNameMask, 1);
-       if (XCloseDisplay(dpy)) {
+       if (XCloseDisplay(dpy))
                warn("XCloseDisplay: Failed to close display");
-       }
 
        return layout;
 }
index 18aa09737299ceac8a3ac46674d6cce1978e8ae0..97e565b842a3e1b93981f0fc9b95252d0835b110 100644 (file)
 
                if (esnprintf(path, sizeof(path), NET_RX_BYTES, interface) < 0)
                        return NULL;
-               if (pscanf(path, "%ju", &rxbytes) != 1) {
+               if (pscanf(path, "%ju", &rxbytes) != 1)
                        return NULL;
-               }
-               if (oldrxbytes == 0) {
+               if (oldrxbytes == 0)
                        return NULL;
-               }
 
                return fmt_human((rxbytes - oldrxbytes) * 1000 / interval,
                                 1024);
 
                if (esnprintf(path, sizeof(path), NET_TX_BYTES, interface) < 0)
                        return NULL;
-               if (pscanf(path, "%ju", &txbytes) != 1) {
+               if (pscanf(path, "%ju", &txbytes) != 1)
                        return NULL;
-               }
-               if (oldtxbytes == 0) {
+               if (oldtxbytes == 0)
                        return NULL;
-               }
 
                return fmt_human((txbytes - oldtxbytes) * 1000 / interval,
                                 1024);
                        return NULL;
                }
                rxbytes = 0;
-               for (ifa = ifal; ifa; ifa = ifa->ifa_next) {
+               for (ifa = ifal; ifa; ifa = ifa->ifa_next)
                        if (!strcmp(ifa->ifa_name, interface) &&
-                          (ifd = (struct if_data *)ifa->ifa_data)) {
+                          (ifd = (struct if_data *)ifa->ifa_data))
                                rxbytes += ifd->ifi_ibytes, if_ok = 1;
-                       }
-               }
+
                freeifaddrs(ifal);
                if (!if_ok) {
                        warn("reading 'if_data' failed");
                        return NULL;
                }
-               if (oldrxbytes == 0) {
+               if (oldrxbytes == 0)
                        return NULL;
-               }
 
                return fmt_human((rxbytes - oldrxbytes) * 1000 / interval,
                                 1024);
                        return NULL;
                }
                txbytes = 0;
-               for (ifa = ifal; ifa; ifa = ifa->ifa_next) {
+               for (ifa = ifal; ifa; ifa = ifa->ifa_next)
                        if (!strcmp(ifa->ifa_name, interface) &&
-                          (ifd = (struct if_data *)ifa->ifa_data)) {
+                          (ifd = (struct if_data *)ifa->ifa_data))
                                txbytes += ifd->ifi_obytes, if_ok = 1;
-                       }
-               }
+
                freeifaddrs(ifal);
                if (!if_ok) {
                        warn("reading 'if_data' failed");
                        return NULL;
                }
-               if (oldtxbytes == 0) {
+               if (oldtxbytes == 0)
                        return NULL;
-               }
 
                return fmt_human((txbytes - oldtxbytes) * 1000 / interval,
                                 1024);
index 820556261ad1e083a82343dc93bbb73dddecf903..e4b428170d0e39586e794fc9d4e4ebf35ed24dbd 100644 (file)
@@ -20,9 +20,9 @@ num_files(const char *path)
 
        num = 0;
        while ((dp = readdir(fd))) {
-               if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
+               if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
                        continue; /* skip self and parent */
-               }
+
                num++;
        }
 
index 518c18ccb3836482e39b59e7e386e02d74e30ce4..326153f5fe1345183a80a846da0540b8a2eb0afc 100644 (file)
@@ -16,9 +16,8 @@
                           "MemTotal: %ju kB\n"
                           "MemFree: %ju kB\n"
                           "MemAvailable: %ju kB\n",
-                          &free, &free, &free) != 3) {
+                          &free, &free, &free) != 3)
                        return NULL;
-               }
 
                return fmt_human(free * 1024, 1024);
        }
                           "MemAvailable: %ju kB\n"
                           "Buffers: %ju kB\n"
                           "Cached: %ju kB\n",
-                          &total, &free, &buffers, &buffers, &cached) != 5) {
+                          &total, &free, &buffers, &buffers, &cached) != 5)
                        return NULL;
-               }
 
-               if (total == 0) {
+               if (total == 0)
                        return NULL;
-               }
 
                percent = 100 * ((total - free) - (buffers + cached)) / total;
                return bprintf("%d", percent);
@@ -53,9 +50,8 @@
                uintmax_t total;
 
                if (pscanf("/proc/meminfo", "MemTotal: %ju kB\n", &total)
-                   != 1) {
+                   != 1)
                        return NULL;
-               }
 
                return fmt_human(total * 1024, 1024);
        }
@@ -94,9 +90,8 @@
 
                size = sizeof(*uvmexp);
 
-               if (sysctl(uvmexp_mib, 2, uvmexp, &size, NULL, 0) >= 0) {
+               if (sysctl(uvmexp_mib, 2, uvmexp, &size, NULL, 0) >= 0)
                        return 1;
-               }
 
                return 0;
        }
index 942f3c46353cc58f18b0c04a180a5ca76494fcde..93bf6da7cca2a07eda436d75ff460c845197a85e 100644 (file)
@@ -15,17 +15,17 @@ run_command(const char *cmd)
                warn("popen '%s':", cmd);
                return NULL;
        }
+
        p = fgets(buf, sizeof(buf) - 1, fp);
        if (pclose(fp) < 0) {
                warn("pclose '%s':", cmd);
                return NULL;
        }
-       if (!p) {
+       if (!p)
                return NULL;
-       }
-       if ((p = strrchr(buf, '\n'))) {
+
+       if ((p = strrchr(buf, '\n')))
                p[0] = '\0';
-       }
 
        return buf[0] ? buf : NULL;
 }
index af05e0159da0385283bb559d2c370a35ffdc7738..6ae054234031aa01ed7d31d9730a89ff03d9a79c 100644 (file)
                char *line = NULL;
 
                /* get number of fields we want to extract */
-               for (i = 0, left = 0; i < LEN(ent); i++) {
-                       if (ent[i].var) {
+               for (i = 0, left = 0; i < LEN(ent); i++)
+                       if (ent[i].var)
                                left++;
-                       }
-               }
 
                if (!(fp = fopen("/proc/meminfo", "r"))) {
                        warn("fopen '/proc/meminfo':");
@@ -63,9 +61,8 @@
        {
                long free;
 
-               if (get_swap_info(NULL, &free, NULL)) {
+               if (get_swap_info(NULL, &free, NULL))
                        return NULL;
-               }
 
                return fmt_human(free * 1024, 1024);
        }
@@ -75,9 +72,8 @@
        {
                long total, free, cached;
 
-               if (get_swap_info(&total, &free, &cached) || total == 0) {
+               if (get_swap_info(&total, &free, &cached) || total == 0)
                        return NULL;
-               }
 
                return bprintf("%d", 100 * (total - free - cached) / total);
        }
@@ -87,9 +83,8 @@
        {
                long total;
 
-               if (get_swap_info(&total, NULL, NULL)) {
+               if (get_swap_info(&total, NULL, NULL))
                        return NULL;
-               }
 
                return fmt_human(total * 1024, 1024);
        }
@@ -99,9 +94,8 @@
        {
                long total, free, cached;
 
-               if (get_swap_info(&total, &free, &cached)) {
+               if (get_swap_info(&total, &free, &cached))
                        return NULL;
-               }
 
                return fmt_human((total - free - cached) * 1024, 1024);
        }
        {
                int total, used;
 
-               if (getstats(&total, &used)) {
+               if (getstats(&total, &used))
                        return NULL;
-               }
 
                return fmt_human((total - used) * 1024, 1024);
        }
        {
                int total, used;
 
-               if (getstats(&total, &used)) {
+               if (getstats(&total, &used))
                        return NULL;
-               }
 
-               if (total == 0) {
+               if (total == 0)
                        return NULL;
-               }
 
                return bprintf("%d", 100 * used / total);
        }
        {
                int total, used;
 
-               if (getstats(&total, &used)) {
+               if (getstats(&total, &used))
                        return NULL;
-               }
 
                return fmt_human(total * 1024, 1024);
        }
        {
                int total, used;
 
-               if (getstats(&total, &used)) {
+               if (getstats(&total, &used))
                        return NULL;
-               }
 
                return fmt_human(used * 1024, 1024);
        }
index c61a574c1d3b6f37174c0ec299eaa0d6dd9e0b00..7cf139444a2bdde0c3c52a4ca254a1211d4a0cfe 100644 (file)
@@ -13,9 +13,8 @@
        {
                uintmax_t temp;
 
-               if (pscanf(file, "%ju", &temp) != 1) {
+               if (pscanf(file, "%ju", &temp) != 1)
                        return NULL;
-               }
 
                return bprintf("%ju", temp / 1000);
        }
index a20e8d480640378815d85606958f0d24fe5def72..4543d322517aebb3bb2c76e5a2ab0d43df2f8f02 100644 (file)
                }
                p = fgets(status, 5, fp);
                fclose(fp);
-               if (!p || strcmp(status, "up\n") != 0) {
+               if (!p || strcmp(status, "up\n") != 0)
                        return NULL;
-               }
 
                if (!(fp = fopen("/proc/net/wireless", "r"))) {
                        warn("fopen '/proc/net/wireless':");
                        return NULL;
                }
 
-               for (i = 0; i < 3; i++) {
+               for (i = 0; i < 3; i++)
                        if (!(p = fgets(buf, sizeof(buf) - 1, fp)))
                                break;
-               }
+
                fclose(fp);
-               if (i < 2 || !p) {
+               if (i < 2 || !p)
                        return NULL;
-               }
 
-               if (!(datastart = strstr(buf, interface))) {
+               if (!(datastart = strstr(buf, interface)))
                        return NULL;
-               }
 
                datastart = (datastart+(strlen(interface)+1));
                sscanf(datastart + 1, " %*d   %d  %*d  %*d\t\t  %*d\t   "
@@ -78,9 +75,8 @@
                memset(&wreq, 0, sizeof(struct iwreq));
                wreq.u.essid.length = IW_ESSID_MAX_SIZE+1;
                if (esnprintf(wreq.ifr_name, sizeof(wreq.ifr_name), "%s",
-                             interface) < 0) {
+                             interface) < 0)
                        return NULL;
-               }
 
                if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
                        warn("socket 'AF_INET':");
@@ -95,9 +91,8 @@
 
                close(sockfd);
 
-               if (!strcmp(id, "")) {
+               if (!strcmp(id, ""))
                        return NULL;
-               }
 
                return id;
        }
                int q;
 
                if (load_ieee80211_nodereq(interface, &nr)) {
-                       if (nr.nr_max_rssi) {
+                       if (nr.nr_max_rssi)
                                q = IEEE80211_NODEREQ_RSSI(&nr);
-                       } else {
+                       else
                                q = RSSI_TO_PERC(nr.nr_rssi);
-                       }
+
                        return bprintf("%d", q);
                }
 
        {
                struct ieee80211_nodereq nr;
 
-               if (load_ieee80211_nodereq(interface, &nr)) {
+               if (load_ieee80211_nodereq(interface, &nr))
                        return bprintf("%s", nr.nr_nwid);
-               }
 
                return NULL;
        }
index a8ac28ea02b66aa0305c672528acfee86178ddaa..cb54f2982ac09ff544e20c84961e12de63babfbb 100644 (file)
@@ -66,9 +66,8 @@ main(int argc, char *argv[])
                usage();
        } ARGEND
 
-       if (argc) {
+       if (argc)
                usage();
-       }
 
        memset(&act, 0, sizeof(act));
        act.sa_handler = terminate;
@@ -77,24 +76,22 @@ main(int argc, char *argv[])
        act.sa_flags |= SA_RESTART;
        sigaction(SIGUSR1, &act, NULL);
 
-       if (!sflag && !(dpy = XOpenDisplay(NULL))) {
+       if (!sflag && !(dpy = XOpenDisplay(NULL)))
                die("XOpenDisplay: Failed to open display");
-       }
 
        do {
-               if (clock_gettime(CLOCK_MONOTONIC, &start) < 0) {
+               if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
                        die("clock_gettime:");
-               }
 
                status[0] = '\0';
                for (i = len = 0; i < LEN(args); i++) {
-                       if (!(res = args[i].func(args[i].args))) {
+                       if (!(res = args[i].func(args[i].args)))
                                res = unknown_str;
-                       }
+
                        if ((ret = esnprintf(status + len, sizeof(status) - len,
-                                           args[i].fmt, res)) < 0) {
+                                            args[i].fmt, res)) < 0)
                                break;
-                       }
+
                        len += ret;
                }
 
@@ -104,37 +101,31 @@ main(int argc, char *argv[])
                        if (ferror(stdout))
                                die("puts:");
                } else {
-                       if (XStoreName(dpy, DefaultRootWindow(dpy), status)
-                            < 0) {
+                       if (XStoreName(dpy, DefaultRootWindow(dpy), status) < 0)
                                die("XStoreName: Allocation failed");
-                       }
                        XFlush(dpy);
                }
 
                if (!done) {
-                       if (clock_gettime(CLOCK_MONOTONIC, &current) < 0) {
+                       if (clock_gettime(CLOCK_MONOTONIC, &current) < 0)
                                die("clock_gettime:");
-                       }
                        difftimespec(&diff, &current, &start);
 
                        intspec.tv_sec = interval / 1000;
                        intspec.tv_nsec = (interval % 1000) * 1E6;
                        difftimespec(&wait, &intspec, &diff);
 
-                       if (wait.tv_sec >= 0) {
-                               if (nanosleep(&wait, NULL) < 0 &&
-                                   errno != EINTR) {
+                       if (wait.tv_sec >= 0 &&
+                           nanosleep(&wait, NULL) < 0 &&
+                           errno != EINTR)
                                        die("nanosleep:");
-                               }
-                       }
                }
        } while (!done);
 
        if (!sflag) {
                XStoreName(dpy, DefaultRootWindow(dpy), NULL);
-               if (XCloseDisplay(dpy) < 0) {
+               if (XCloseDisplay(dpy) < 0)
                        die("XCloseDisplay: Failed to close display");
-               }
        }
 
        return 0;
diff --git a/util.c b/util.c
index 85366bf8679f191475d360fbbfbb9d7ab9ecf0de..d1f6077e5e2dd310bd754ae825bc7e9f7a46e9f6 100644 (file)
--- a/util.c
+++ b/util.c
@@ -13,9 +13,8 @@ char *argv0;
 static void
 verr(const char *fmt, va_list ap)
 {
-       if (argv0 && strncmp(fmt, "usage", sizeof("usage") - 1)) {
+       if (argv0 && strncmp(fmt, "usage", sizeof("usage") - 1))
                fprintf(stderr, "%s: ", argv0);
-       }
 
        vfprintf(stderr, fmt, ap);
 
@@ -119,9 +118,8 @@ fmt_human(uintmax_t num, int base)
        }
 
        scaled = num;
-       for (i = 0; i < prefixlen && scaled >= base; i++) {
+       for (i = 0; i < prefixlen && scaled >= base; i++)
                scaled /= base;
-       }
 
        return bprintf("%.1f %s", scaled, prefix[i]);
 }