]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_mem.c
fix: use SYSCONFDIR in error message
[i3/i3status] / src / print_mem.c
index 46523d6ce67c48560622eb0d787bd2e798e6feca..840f997eea99659fc53c9f1509cf4847877980d9 100644 (file)
@@ -1,4 +1,5 @@
 // vim:ts=4:sw=4:expandtab
+#include <config.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -39,10 +40,9 @@ static int print_bytes_human(char *outwalk, uint64_t bytes) {
  *
  */
 static long memory_absolute(const long mem_total, const char *size) {
-    long mem_absolute = -1;
     char *endptr = NULL;
 
-    mem_absolute = strtol(size, &endptr, 10);
+    long mem_absolute = strtol(size, &endptr, 10);
 
     if (endptr) {
         while (endptr[0] != '\0' && isspace(endptr[0]))
@@ -160,51 +160,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++) = '%';
         }
     }