]> git.sur5r.net Git - i3/i3status/commitdiff
Merge pull request #296 from Stunkymonkey/include-order
authorIngo Bürk <admin@airblader.de>
Mon, 16 Jul 2018 14:18:06 +0000 (16:18 +0200)
committerGitHub <noreply@github.com>
Mon, 16 Jul 2018 14:18:06 +0000 (16:18 +0200)
switch to clang 3.8 & ignore include sort order

16 files changed:
Makefile
man/i3status.man
src/first_network_device.c
src/print_battery_info.c
src/print_cpu_temperature.c
src/print_cpu_usage.c
src/print_disk_info.c
src/print_eth_info.c
src/print_ipv6_addr.c
src/print_load.c
src/print_mem.c
src/print_path_exists.c
src/print_run_watch.c
src/print_time.c
src/print_volume.c
src/print_wireless_info.c

index c5427b9995b473780afc5ed077c095efdfa8d515..904b3d037f3e380f0a60beb891d85d91f7cab751 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -85,6 +85,11 @@ OBJS:=$(filter-out src/pulse.o, $(OBJS))
 LIBS:=$(filter-out -lpulse, $(LIBS))
 endif
 
+ifeq ($(OS),DragonFly)
+OBJS:=$(filter-out src/pulse.o, $(OBJS))
+LIBS:=$(filter-out -lpulse, $(LIBS)) -lpthread
+endif
+
 src/%.o: src/%.c include/i3status.h
        $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
        @echo " CC $<"
index 38c834a8ac35bdbe821723b2c3d4af4b65ed34b2..f22e4792720b4b9027d18bd21b4be035ae6ecbf4 100644 (file)
@@ -650,7 +650,7 @@ disk "/" {
 == Using i3status with dzen2
 
 After installing dzen2, you can directly use it with i3status. Just ensure that
-+output_format+ is set to +dzen2+.
++output_format+ is set to +dzen2+. *Note*: +min_width+ is not supported.
 
 *Example for usage of i3status with dzen2*:
 --------------------------------------------------------------
@@ -662,7 +662,7 @@ i3status | dzen2 -fg white -ta r -w 1280 \
 
 To get xmobar to start, you might need to copy the default configuration
 file to +~/.xmobarrc+. Also, ensure that the +output_format+ option for i3status
-is set to +xmobar+.
+is set to +xmobar+. *Note*: +min_width+ is not supported.
 
 *Example for usage of i3status with xmobar*:
 ---------------------------------------------------------------------
index b930f5357a709e803c635b499132b6cd160a5cb1..93626a266c68ec411c48f971caf557b92a18229d 100644 (file)
@@ -3,13 +3,17 @@
 #include <sys/stat.h>
 #include <stdlib.h>
 #include <ifaddrs.h>
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__) || defined(__DragonFly__)
 #include <sys/types.h>
 #include <sys/sockio.h>
 #include <sys/ioctl.h>
 #include <net/if.h>
+#endif
+#if defined(__OpenBSD__)
 #include <net80211/ieee80211.h>
 #include <net80211/ieee80211_ioctl.h>
+#elif defined(__DragonFly__)
+#include <netproto/802_11/ieee80211_ioctl.h>
 #endif
 
 #include "i3status.h"
@@ -67,7 +71,7 @@ static bool is_virtual(const char *ifname) {
 }
 
 static net_type_t iface_type(const char *ifname) {
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__)
     /*
      *First determine if the device is a wireless device by trying two ioctl(2)
      * commands against it. If either succeeds we can be sure it's a wireless
@@ -78,14 +82,23 @@ static net_type_t iface_type(const char *ifname) {
     struct ifreq ifr;
     struct ieee80211_bssid bssid;
     struct ieee80211_nwid nwid;
+#elif defined(__DragonFly__)
+    struct ieee80211req ifr;
+#endif
+#if defined(__OpenBSD__) || defined(__DragonFly__)
     struct ifmediareq ifmr;
-
-    int s, ibssid, inwid;
-
+    int s;
+#endif
+#if defined(__OpenBSD__)
+    int ibssid, inwid;
+#endif
+#if defined(__OpenBSD__) || defined(__DragonFly__)
     if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
         return NET_TYPE_OTHER;
 
     memset(&ifr, 0, sizeof(ifr));
+#endif
+#if defined(__OpenBSD__)
     ifr.ifr_data = (caddr_t)&nwid;
     (void)strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
     inwid = ioctl(s, SIOCG80211NWID, (caddr_t)&ifr);
@@ -98,7 +111,15 @@ static net_type_t iface_type(const char *ifname) {
         close(s);
         return NET_TYPE_WIRELESS;
     }
-
+#elif defined(__DragonFly__)
+    (void)strlcpy(ifr.i_name, ifname, sizeof(ifr.i_name));
+    ifr.i_type = IEEE80211_IOC_NUMSSIDS;
+    if (ioctl(s, SIOCG80211, &ifr) == 0) {
+        close(s);
+        return NET_TYPE_WIRELESS;
+    }
+#endif
+#if defined(__OpenBSD__) || defined(__DragonFly__)
     (void)memset(&ifmr, 0, sizeof(ifmr));
     (void)strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
 
index 04b5a251feb6f0c7eb8674b4fd7ad095dd9079cf..8c85192f20f916b6544921e2740b0e0ce0424f58 100644 (file)
@@ -1,9 +1,9 @@
 // vim:ts=4:sw=4:expandtab
 #include <ctype.h>
-#include <time.h>
-#include <string.h>
-#include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
 #include <yajl/yajl_gen.h>
 #include <yajl/yajl_version.h>
 
 #endif
 
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-#include <sys/types.h>
-#include <sys/sysctl.h>
 #include <dev/acpica/acpiio.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
 #endif
 
-#if defined(__OpenBSD__)
-#include <sys/types.h>
-#include <sys/ioctl.h>
+#if defined(__DragonFly__)
 #include <sys/fcntl.h>
+#endif
+
+#if defined(__OpenBSD__)
 #include <machine/apmvar.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
 #endif
 
 #if defined(__NetBSD__)
@@ -55,6 +59,22 @@ struct battery_info {
     charging_status_t status;
 };
 
+#if defined(__DragonFly__)
+#define ACPIDEV "/dev/acpi"
+static int acpifd;
+
+static bool acpi_init(void) {
+    if (acpifd == 0) {
+        acpifd = open(ACPIDEV, O_RDWR);
+        if (acpifd == -1)
+            acpifd = open(ACPIDEV, O_RDONLY);
+        if (acpifd == -1)
+            return false;
+    }
+    return true;
+}
+#endif
+
 #if defined(LINUX) || defined(__NetBSD__)
 /*
  * Add batt_info data to acc.
@@ -189,7 +209,34 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen
             batt_info->full_last = (((float)voltage / 1000.0) * ((float)batt_info->full_last / 1000.0));
         }
     }
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
+#elif defined(__DragonFly__)
+    union acpi_battery_ioctl_arg battio;
+    if (acpi_init()) {
+        battio.unit = number;
+        ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio);
+        batt_info->full_design = battio.bif.dcap;
+        batt_info->full_last = battio.bif.lfcap;
+        battio.unit = number;
+        ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio);
+        batt_info->percentage_remaining = battio.battinfo.cap;
+        batt_info->present_rate = battio.battinfo.rate;
+        batt_info->seconds_remaining = battio.battinfo.min * 60;
+        switch (battio.battinfo.state) {
+            case 0:
+                batt_info->status = CS_FULL;
+                break;
+            case ACPI_BATT_STAT_CHARGING:
+                batt_info->status = CS_CHARGING;
+                break;
+            case ACPI_BATT_STAT_DISCHARG:
+                batt_info->status = CS_DISCHARGING;
+                break;
+            default:
+                batt_info->status = CS_UNKNOWN;
+        }
+        OUTPUT_FULL_TEXT(format_down);
+    }
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
     int state;
     int sysctl_rslt;
     size_t sysctl_size = sizeof(sysctl_rslt);
@@ -575,10 +622,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
 
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "status")) {
+        } else if (BEGINS_WITH(walk + 1, "status")) {
             const char *statusstr;
             switch (batt_info.status) {
                 case CS_CHARGING:
@@ -596,6 +641,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
 
             outwalk += sprintf(outwalk, "%s", statusstr);
             walk += strlen("status");
+
         } else if (BEGINS_WITH(walk + 1, "percentage")) {
             if (integer_battery_capacity) {
                 outwalk += sprintf(outwalk, "%.00f%s", batt_info.percentage_remaining, pct_mark);
@@ -603,6 +649,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
                 outwalk += sprintf(outwalk, "%.02f%s", batt_info.percentage_remaining, pct_mark);
             }
             walk += strlen("percentage");
+
         } else if (BEGINS_WITH(walk + 1, "remaining")) {
             if (batt_info.seconds_remaining >= 0) {
                 int seconds, hours, minutes;
@@ -621,6 +668,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
             }
             walk += strlen("remaining");
             EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
+
         } else if (BEGINS_WITH(walk + 1, "emptytime")) {
             if (batt_info.seconds_remaining >= 0) {
                 time_t empty_time = time(NULL) + batt_info.seconds_remaining;
@@ -636,12 +684,16 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
             }
             walk += strlen("emptytime");
             EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
+
         } else if (BEGINS_WITH(walk + 1, "consumption")) {
             if (batt_info.present_rate >= 0)
                 outwalk += sprintf(outwalk, "%1.2fW", batt_info.present_rate / 1e6);
 
             walk += strlen("consumption");
             EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index feae3ec8a8cb388fc3e8717554d4f851303d65ef..569ea6064e4aa234a2e157f68037610ffd01517a 100644 (file)
@@ -250,11 +250,13 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
-        if (BEGINS_WITH(walk + 1, "degrees")) {
+
+        } else if (BEGINS_WITH(walk + 1, "degrees")) {
             outwalk += sprintf(outwalk, "%s", temperature.formatted_value);
             walk += strlen("degrees");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index c1ea3fd4b1576cfa0c5a0d69014f7d25dfc0d971..615fe5dc276140a196070972d91ed98b16b47a78 100644 (file)
@@ -144,15 +144,13 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "usage")) {
+        } else if (BEGINS_WITH(walk + 1, "usage")) {
             outwalk += sprintf(outwalk, "%02d%s", diff_usage, pct_mark);
             walk += strlen("usage");
         }
 #if defined(LINUX)
-        if (BEGINS_WITH(walk + 1, "cpu")) {
+        else if (BEGINS_WITH(walk + 1, "cpu")) {
             int number = 0;
             sscanf(walk + 1, "cpu%d", &number);
             if (number < 0 || number >= cpu_count) {
@@ -172,6 +170,9 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const
             walk += strlen("cpu") + padding;
         }
 #endif
+        else {
+            *(outwalk++) = '%';
+        }
     }
 
     for (int i = 0; i < cpu_count; i++)
index 770e7186840959198efd89b114e7fc809b3bd2cf..bc43da0348bd5081946e712190bd459760a44715 100644 (file)
@@ -172,47 +172,41 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "free")) {
+        } else if (BEGINS_WITH(walk + 1, "free")) {
             outwalk += print_bytes_human(outwalk, (uint64_t)buf.f_bsize * (uint64_t)buf.f_bfree, prefix_type);
             walk += strlen("free");
-        }
 
-        if (BEGINS_WITH(walk + 1, "used")) {
+        } else if (BEGINS_WITH(walk + 1, "used")) {
             outwalk += print_bytes_human(outwalk, (uint64_t)buf.f_bsize * ((uint64_t)buf.f_blocks - (uint64_t)buf.f_bfree), prefix_type);
             walk += strlen("used");
-        }
 
-        if (BEGINS_WITH(walk + 1, "total")) {
+        } else if (BEGINS_WITH(walk + 1, "total")) {
             outwalk += print_bytes_human(outwalk, (uint64_t)buf.f_bsize * (uint64_t)buf.f_blocks, prefix_type);
             walk += strlen("total");
-        }
 
-        if (BEGINS_WITH(walk + 1, "avail")) {
+        } else if (BEGINS_WITH(walk + 1, "avail")) {
             outwalk += print_bytes_human(outwalk, (uint64_t)buf.f_bsize * (uint64_t)buf.f_bavail, prefix_type);
             walk += strlen("avail");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_free")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_free")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bfree / (double)buf.f_blocks, pct_mark);
             walk += strlen("percentage_free");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_used_of_avail")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_used_of_avail")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bavail) / (double)buf.f_blocks, pct_mark);
             walk += strlen("percentage_used_of_avail");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_used")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_used")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bfree) / (double)buf.f_blocks, pct_mark);
             walk += strlen("percentage_used");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_avail")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_avail")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks, pct_mark);
             walk += strlen("percentage_avail");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index 996ce3b6606eea86e6d89de5a6fd005182ae32b3..2fc25a180b30f5134b23064049335054fd0ed9e5 100644 (file)
@@ -175,15 +175,17 @@ void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, cons
     for (walk = format_up; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "ip")) {
+        } else if (BEGINS_WITH(walk + 1, "ip")) {
             outwalk += sprintf(outwalk, "%s", ip_address);
             walk += strlen("ip");
+
         } else if (BEGINS_WITH(walk + 1, "speed")) {
             outwalk += print_eth_speed(outwalk, interface);
             walk += strlen("speed");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index a24119f74797a5414653745043a73c49114595fd..a50bf398e8ef1e5080abb3bae299b0cc92928d2e 100644 (file)
@@ -133,12 +133,13 @@ void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, con
     for (walk = format_up; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "ip")) {
+        } else if (BEGINS_WITH(walk + 1, "ip")) {
             outwalk += sprintf(outwalk, "%s", addr_string);
             walk += strlen("ip");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
     END_COLOR;
index 6da2519c3d58496e58ecfac1491b767dd7fd17d3..e0ba6771f710b1bbaa1d8d2694b7c7318be6b4a9 100644 (file)
@@ -29,21 +29,21 @@ void print_load(yajl_gen json_gen, char *buffer, const char *format, const char
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
-        if (BEGINS_WITH(walk + 1, "1min")) {
+
+        } else if (BEGINS_WITH(walk + 1, "1min")) {
             outwalk += sprintf(outwalk, "%1.2f", loadavg[0]);
             walk += strlen("1min");
-        }
 
-        if (BEGINS_WITH(walk + 1, "5min")) {
+        } else if (BEGINS_WITH(walk + 1, "5min")) {
             outwalk += sprintf(outwalk, "%1.2f", loadavg[1]);
             walk += strlen("5min");
-        }
 
-        if (BEGINS_WITH(walk + 1, "15min")) {
+        } else if (BEGINS_WITH(walk + 1, "15min")) {
             outwalk += sprintf(outwalk, "%1.2f", loadavg[2]);
             walk += strlen("15min");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index a37fa2905c142fd9c65925b0cd83ca86e5faded8..f9284f35c6c92fa6724f91d653136dc99fe94fc5 100644 (file)
@@ -159,51 +159,45 @@ void print_memory(yajl_gen json_gen, char *buffer, const char *format, const cha
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
-        if (BEGINS_WITH(walk + 1, "total")) {
+
+        } else if (BEGINS_WITH(walk + 1, "total")) {
             outwalk += print_bytes_human(outwalk, ram_total);
             walk += strlen("total");
-        }
 
-        if (BEGINS_WITH(walk + 1, "used")) {
+        } else if (BEGINS_WITH(walk + 1, "used")) {
             outwalk += print_bytes_human(outwalk, ram_used);
             walk += strlen("used");
-        }
 
-        if (BEGINS_WITH(walk + 1, "free")) {
+        } else if (BEGINS_WITH(walk + 1, "free")) {
             outwalk += print_bytes_human(outwalk, ram_free);
             walk += strlen("free");
-        }
 
-        if (BEGINS_WITH(walk + 1, "available")) {
+        } else if (BEGINS_WITH(walk + 1, "available")) {
             outwalk += print_bytes_human(outwalk, ram_available);
             walk += strlen("available");
-        }
 
-        if (BEGINS_WITH(walk + 1, "shared")) {
+        } else if (BEGINS_WITH(walk + 1, "shared")) {
             outwalk += print_bytes_human(outwalk, ram_shared);
             walk += strlen("shared");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_free")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_free")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * ram_free / ram_total, pct_mark);
             walk += strlen("percentage_free");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_available")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_available")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * ram_available / ram_total, pct_mark);
             walk += strlen("percentage_available");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_used")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_used")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * ram_used / ram_total, pct_mark);
             walk += strlen("percentage_used");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_shared")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_shared")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * ram_shared / ram_total, pct_mark);
             walk += strlen("percentage_shared");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index 65bc9c85028a35aa7283f9bea31afd90c0b98d85..7bdbe30cf4b392421baa6c92a36764d8e231037f 100644 (file)
@@ -25,15 +25,17 @@ void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const
     for (; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "title")) {
+        } else if (BEGINS_WITH(walk + 1, "title")) {
             outwalk += sprintf(outwalk, "%s", title);
             walk += strlen("title");
+
         } else if (BEGINS_WITH(walk + 1, "status")) {
             outwalk += sprintf(outwalk, "%s", (exists ? "yes" : "no"));
             walk += strlen("status");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index b108f8fef85b728ac2d388b6055744c6c13bd400..0887521f5b71c8cd5da0b78168595b72f1755ae3 100644 (file)
@@ -23,15 +23,17 @@ void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const c
     for (; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "title")) {
+        } else if (BEGINS_WITH(walk + 1, "title")) {
             outwalk += sprintf(outwalk, "%s", title);
             walk += strlen("title");
+
         } else if (BEGINS_WITH(walk + 1, "status")) {
             outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
             walk += strlen("status");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index 3ed32b0157ca15810e830c6af38ead375ae73d63..3a6c4cc0752757aa77170500baf4b9e6e1aa2b37 100644 (file)
@@ -57,13 +57,14 @@ void print_time(yajl_gen json_gen, char *buffer, const char *title, const char *
         for (walk = format; *walk != '\0'; walk++) {
             if (*walk != '%') {
                 *(outwalk++) = *walk;
-                continue;
-            }
 
-            if (BEGINS_WITH(walk + 1, "time")) {
+            } else if (BEGINS_WITH(walk + 1, "time")) {
                 strftime(timebuf, sizeof(timebuf), format_time, &tm);
                 maybe_escape_markup(timebuf, &outwalk);
                 walk += strlen("time");
+
+            } else {
+                *(outwalk++) = '%';
             }
         }
     }
index e28a132fdb3ba5ad76710f6c4c342315c19aa4ae..4c0fbdea67970277c1a75dc98868675af06cc930 100644 (file)
@@ -35,15 +35,17 @@ static char *apply_volume_format(const char *fmt, char *outwalk, int ivolume) {
     for (; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
-        if (BEGINS_WITH(walk + 1, "%")) {
+
+        } else if (BEGINS_WITH(walk + 1, "%")) {
             outwalk += sprintf(outwalk, "%s", pct_mark);
             walk += strlen("%");
-        }
-        if (BEGINS_WITH(walk + 1, "volume")) {
+
+        } else if (BEGINS_WITH(walk + 1, "volume")) {
             outwalk += sprintf(outwalk, "%d%s", ivolume, pct_mark);
             walk += strlen("volume");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
     return outwalk;
@@ -61,7 +63,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *
         free(instance);
     }
 
-#ifndef __OpenBSD__
+#if !defined(__DragonFly__) && !defined(__OpenBSD__)
     /* Try PulseAudio first */
 
     /* If the device name has the format "pulse[:N]" where N is the
index dcfde528a0a846cc04a63235775f4724a5e0b2ed..1d87c790ab86e77f8c6d9cc54f831a5dfe8f5d6a 100644 (file)
@@ -38,6 +38,7 @@
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <ifaddrs.h>
+#include <stdlib.h>
 #include <net/if.h>
 #include <net/if_media.h>
 #include <netproto/802_11/ieee80211.h>
@@ -534,10 +535,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
     for (; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "quality")) {
+        } else if (BEGINS_WITH(walk + 1, "quality")) {
             if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) {
                 if (info.quality_max)
                     outwalk += sprintf(outwalk, format_quality, PERCENT_VALUE(info.quality, info.quality_max), pct_mark);
@@ -547,9 +546,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
                 *(outwalk++) = '?';
             }
             walk += strlen("quality");
-        }
 
-        if (BEGINS_WITH(walk + 1, "signal")) {
+        } else if (BEGINS_WITH(walk + 1, "signal")) {
             if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) {
                 if (info.signal_level_max)
                     outwalk += sprintf(outwalk, "%3d%s", PERCENT_VALUE(info.signal_level, info.signal_level_max), pct_mark);
@@ -559,9 +557,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
                 *(outwalk++) = '?';
             }
             walk += strlen("signal");
-        }
 
-        if (BEGINS_WITH(walk + 1, "noise")) {
+        } else if (BEGINS_WITH(walk + 1, "noise")) {
             if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) {
                 if (info.noise_level_max)
                     outwalk += sprintf(outwalk, "%3d%s", PERCENT_VALUE(info.noise_level, info.noise_level_max), pct_mark);
@@ -571,9 +568,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
                 *(outwalk++) = '?';
             }
             walk += strlen("noise");
-        }
 
-        if (BEGINS_WITH(walk + 1, "essid")) {
+        } else if (BEGINS_WITH(walk + 1, "essid")) {
 #ifdef IW_ESSID_MAX_SIZE
             if (info.flags & WIRELESS_INFO_FLAG_HAS_ESSID)
                 maybe_escape_markup(info.essid, &outwalk);
@@ -581,23 +577,20 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
 #endif
                 *(outwalk++) = '?';
             walk += strlen("essid");
-        }
 
-        if (BEGINS_WITH(walk + 1, "frequency")) {
+        } else if (BEGINS_WITH(walk + 1, "frequency")) {
             if (info.flags & WIRELESS_INFO_FLAG_HAS_FREQUENCY)
                 outwalk += sprintf(outwalk, "%1.1f GHz", info.frequency / 1e9);
             else
                 *(outwalk++) = '?';
             walk += strlen("frequency");
-        }
 
-        if (BEGINS_WITH(walk + 1, "ip")) {
+        } else if (BEGINS_WITH(walk + 1, "ip")) {
             outwalk += sprintf(outwalk, "%s", ip_address);
             walk += strlen("ip");
         }
-
 #ifdef LINUX
-        if (BEGINS_WITH(walk + 1, "bitrate")) {
+        else if (BEGINS_WITH(walk + 1, "bitrate")) {
             char br_buffer[128];
 
             print_bitrate(br_buffer, sizeof(br_buffer), info.bitrate);
@@ -606,6 +599,9 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
             walk += strlen("bitrate");
         }
 #endif
+        else {
+            *(outwalk++) = '%';
+        }
     }
 
 out: