diff options
author | Mateusz Loskot <mateusz@loskot.net> | 2012-06-11 00:32:30 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2012-06-11 12:00:24 +0200 |
commit | 10ed9efff45c3d267f0602f1f2310d2a35b18853 (patch) | |
tree | 8a9320a6b24f2585dfbf117fcdcb5e173466040b | |
parent | 2e3490141d49680e317c5a66de1ccb2d8b8634d1 (diff) |
Moved translation of wireless status code to text from multiple places into single BATT_STATUS_NAME macro. It simplifies customisation of the hard-wired status text.
-rw-r--r-- | src/print_battery_info.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c index cc7c5fe..f6f238c 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -20,6 +20,9 @@ #include <machine/apmvar.h> #endif +#define BATT_STATUS_NAME(status) \ + (status == CS_CHARGING ? "CHR" : \ + (status == CS_DISCHARGING ? "BAT" : "FULL")) /* * Get battery information from /sys. Note that it uses the design capacity to * calculate the percentage, not the last full capacity, so you can see how @@ -97,9 +100,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char return; } - (void)snprintf(statusbuf, sizeof(statusbuf), "%s", - (status == CS_CHARGING ? "CHR" : - (status == CS_DISCHARGING ? "BAT" : "FULL"))); + (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status)); (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", (((float)remaining / (float)full_design) * 100)); @@ -167,9 +168,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char full_design = sysctl_rslt; - (void)snprintf(statusbuf, sizeof(statusbuf), "%s", - (status == CS_CHARGING ? "CHR" : - (status == CS_DISCHARGING ? "BAT" : "FULL"))); + (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status)); (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%%", present_rate); @@ -221,10 +220,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char break; } - (void)snprintf(statusbuf, sizeof(statusbuf), "%s", - (ac_status == CS_CHARGING ? "CHR" : - (ac_status == CS_DISCHARGING ? "BAT" : "FULL"))); - + (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status)); (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%%", apm_info.battery_life); /* Can't give a meaningful value for remaining minutes if we're charging. */ |