]> git.sur5r.net Git - i3/i3status/commitdiff
Remove statusbuf from print_battery_info.
authorTommie Gannert <tommie@gannert.se>
Sun, 31 Jul 2016 23:24:40 +0000 (00:24 +0100)
committerTommie Gannert <tommie@gannert.se>
Sun, 31 Jul 2016 23:24:40 +0000 (00:24 +0100)
src/print_battery_info.c

index 7fb2ab5afb9572739d7e86d905703cdd1d8555de..802424d9f12e75a596af3d8eb401bbeb1a849da7 100644 (file)
@@ -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);