diff options
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | man/i3status.man | 4 | ||||
-rw-r--r-- | src/first_network_device.c | 33 | ||||
-rw-r--r-- | src/print_battery_info.c | 76 | ||||
-rw-r--r-- | src/print_cpu_temperature.c | 8 | ||||
-rw-r--r-- | src/print_cpu_usage.c | 9 | ||||
-rw-r--r-- | src/print_disk_info.c | 28 | ||||
-rw-r--r-- | src/print_eth_info.c | 8 | ||||
-rw-r--r-- | src/print_ipv6_addr.c | 7 | ||||
-rw-r--r-- | src/print_load.c | 14 | ||||
-rw-r--r-- | src/print_mem.c | 32 | ||||
-rw-r--r-- | src/print_path_exists.c | 8 | ||||
-rw-r--r-- | src/print_run_watch.c | 8 | ||||
-rw-r--r-- | src/print_time.c | 7 | ||||
-rw-r--r-- | src/print_volume.c | 14 | ||||
-rw-r--r-- | src/print_wireless_info.c | 26 |
16 files changed, 181 insertions, 106 deletions
@@ -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 $<" diff --git a/man/i3status.man b/man/i3status.man index 38c834a..f22e479 100644 --- a/man/i3status.man +++ b/man/i3status.man @@ -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*: --------------------------------------------------------------------- diff --git a/src/first_network_device.c b/src/first_network_device.c index b930f53..93626a2 100644 --- a/src/first_network_device.c +++ b/src/first_network_device.c @@ -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)); diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 04b5a25..8c85192 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -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> @@ -16,16 +16,20 @@ #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++) = '%'; } } diff --git a/src/print_cpu_temperature.c b/src/print_cpu_temperature.c index feae3ec..569ea60 100644 --- a/src/print_cpu_temperature.c +++ b/src/print_cpu_temperature.c @@ -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++) = '%'; } } diff --git a/src/print_cpu_usage.c b/src/print_cpu_usage.c index c1ea3fd..615fe5d 100644 --- a/src/print_cpu_usage.c +++ b/src/print_cpu_usage.c @@ -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++) diff --git a/src/print_disk_info.c b/src/print_disk_info.c index 770e718..bc43da0 100644 --- a/src/print_disk_info.c +++ b/src/print_disk_info.c @@ -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++) = '%'; } } diff --git a/src/print_eth_info.c b/src/print_eth_info.c index 996ce3b..2fc25a1 100644 --- a/src/print_eth_info.c +++ b/src/print_eth_info.c @@ -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++) = '%'; } } diff --git a/src/print_ipv6_addr.c b/src/print_ipv6_addr.c index a24119f..a50bf39 100644 --- a/src/print_ipv6_addr.c +++ b/src/print_ipv6_addr.c @@ -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; diff --git a/src/print_load.c b/src/print_load.c index 6da2519..e0ba677 100644 --- a/src/print_load.c +++ b/src/print_load.c @@ -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++) = '%'; } } diff --git a/src/print_mem.c b/src/print_mem.c index a37fa29..f9284f3 100644 --- a/src/print_mem.c +++ b/src/print_mem.c @@ -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++) = '%'; } } diff --git a/src/print_path_exists.c b/src/print_path_exists.c index 65bc9c8..7bdbe30 100644 --- a/src/print_path_exists.c +++ b/src/print_path_exists.c @@ -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++) = '%'; } } diff --git a/src/print_run_watch.c b/src/print_run_watch.c index b108f8f..0887521 100644 --- a/src/print_run_watch.c +++ b/src/print_run_watch.c @@ -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++) = '%'; } } diff --git a/src/print_time.c b/src/print_time.c index 3ed32b0..3a6c4cc 100644 --- a/src/print_time.c +++ b/src/print_time.c @@ -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++) = '%'; } } } diff --git a/src/print_volume.c b/src/print_volume.c index e28a132..4c0fbde 100644 --- a/src/print_volume.c +++ b/src/print_volume.c @@ -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 diff --git a/src/print_wireless_info.c b/src/print_wireless_info.c index dcfde52..1d87c79 100644 --- a/src/print_wireless_info.c +++ b/src/print_wireless_info.c @@ -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: |