summaryrefslogtreecommitdiff
path: root/src/print_mem.c
diff options
context:
space:
mode:
authorFelix Buehler <account@buehler.rocks>2018-06-02 02:32:25 +0200
committerFelix Buehler <account@buehler.rocks>2018-07-13 15:03:31 +0200
commit52e9f6f63b74db2a6a1d67524851649b18794950 (patch)
tree5f6ab7b574e6fad71cdd2d8ac21c19ba0768d936 /src/print_mem.c
parent9aafc38370e5f2b337643d22aa04f4d34208fb03 (diff)
able to print percentage
its now possible to have percentage before and after a variable. except for the date. But percentage with dates does not make much sense to me, so i skipped it.
Diffstat (limited to 'src/print_mem.c')
-rw-r--r--src/print_mem.c32
1 files changed, 13 insertions, 19 deletions
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++) = '%';
}
}