summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommie Gannert <tommie@gannert.se>2016-08-01 00:24:40 +0100
committerTommie Gannert <tommie@gannert.se>2016-08-01 00:24:40 +0100
commit88a0c6923c29b810e906d30e091aaf22bfed02cb (patch)
tree123c2d9854cf392d4e505a13dfb9512da3ad038d
parent8e852fa94554f4caa162256e5f6ce2413027100b (diff)
Remove statusbuf from print_battery_info.
-rw-r--r--src/print_battery_info.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c
index 7fb2ab5..802424d 100644
--- a/src/print_battery_info.c
+++ b/src/print_battery_info.c
@@ -38,7 +38,6 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
time_t empty_time;
struct tm *empty_tm;
char buf[1024];
- char statusbuf[16];
char percentagebuf[16];
char remainingbuf[256];
char emptytimebuf[256];
@@ -53,7 +52,6 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
voltage = -1;
charging_status_t status = CS_DISCHARGING;
- memset(statusbuf, '\0', sizeof(statusbuf));
memset(percentagebuf, '\0', sizeof(percentagebuf));
memset(remainingbuf, '\0', sizeof(remainingbuf));
memset(emptytimebuf, '\0', sizeof(emptytimebuf));
@@ -63,9 +61,6 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
sprintf(batpath, path, number);
INSTANCE(batpath);
-#define BATT_STATUS_NAME(status) \
- (status == CS_CHARGING ? status_chr : (status == CS_DISCHARGING ? status_bat : (status == CS_UNKNOWN ? status_unk : status_full)))
-
#if defined(LINUX)
if (!slurp(batpath, buf, sizeof(buf))) {
OUTPUT_FULL_TEXT(format_down);
@@ -139,8 +134,6 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
return;
}
- (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
-
float percentage_remaining = (((float)remaining / (float)full_design) * 100);
/* Some batteries report POWER_SUPPLY_CHARGE_NOW=<full_design> when fully
* charged, even though that’s plainly wrong. For people who chose to see
@@ -248,8 +241,6 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
full_design = sysctl_rslt;
- (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
-
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%s",
present_rate, pct_mark);
@@ -307,7 +298,6 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
break;
}
- (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
/* integer_battery_capacity is implied as battery_life is already in whole numbers. */
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%s", apm_info.battery_life, pct_mark);
@@ -519,9 +509,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
}
if (is_full)
- (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(CS_FULL));
- else
- (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
+ status = CS_FULL;
/*
* The envsys(4) ACPI routines do not appear to provide a 'time
@@ -602,7 +590,22 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
}
if (BEGINS_WITH(walk + 1, "status")) {
- outwalk += sprintf(outwalk, "%s", statusbuf);
+ const char *statusstr;
+ switch (status) {
+ case CS_CHARGING:
+ statusstr = status_chr;
+ break;
+ case CS_DISCHARGING:
+ statusstr = status_bat;
+ break;
+ case CS_FULL:
+ statusstr = status_full;
+ break;
+ default:
+ statusstr = status_unk;
+ }
+
+ outwalk += sprintf(outwalk, "%s", statusstr);
walk += strlen("status");
} else if (BEGINS_WITH(walk + 1, "percentage")) {
outwalk += sprintf(outwalk, "%s", percentagebuf);