diff options
author | Felix Buehler <account@buehler.rocks> | 2020-03-31 16:08:07 +0200 |
---|---|---|
committer | Felix Buehler <account@buehler.rocks> | 2020-03-31 16:08:07 +0200 |
commit | dd683f618a0b038dcda58b909f3fd6cf5805f377 (patch) | |
tree | 34158c1bb7a9506ab36c34490a94464b8a63a503 | |
parent | 101215bbc83b97de30b6b535bbe2e93d2e913804 (diff) |
use format_placeholder for run_watch
-rw-r--r-- | src/print_run_watch.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/print_run_watch.c b/src/print_run_watch.c index f0a0746..d153da4 100644 --- a/src/print_run_watch.c +++ b/src/print_run_watch.c @@ -6,6 +6,8 @@ #include <yajl/yajl_version.h> #include "i3status.h" +#define STRING_SIZE 5 + void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format, const char *format_down) { bool running = process_runs(pidfile); const char *walk; @@ -21,22 +23,15 @@ void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const c START_COLOR((running ? "color_good" : "color_bad")); - for (; *walk != '\0'; walk++) { - if (*walk != '%') { - *(outwalk++) = *walk; - - } else if (BEGINS_WITH(walk + 1, "title")) { - outwalk += sprintf(outwalk, "%s", title); - walk += strlen("title"); + char string_status[STRING_SIZE]; + snprintf(string_status, STRING_SIZE, "%s", (running ? "yes" : "no")); - } else if (BEGINS_WITH(walk + 1, "status")) { - outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no")); - walk += strlen("status"); + placeholder_t placeholders[] = { + {.name = "%title", .value = title}, + {.name = "%status", .value = string_status}}; - } else { - *(outwalk++) = '%'; - } - } + const size_t num = sizeof(placeholders) / sizeof(placeholder_t); + buffer = format_placeholders(walk, &placeholders[0], num); END_COLOR; OUTPUT_FULL_TEXT(buffer); |