diff options
author | Ingo Bürk <admin@airblader.de> | 2020-04-03 08:38:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 08:38:04 +0200 |
commit | 4980193dc7be7ef78f3bc51cf1432a1e5a37d37e (patch) | |
tree | 17676a0e8bdf308476119ad26ac1b1af88580448 /src/print_run_watch.c | |
parent | ffa429d145a7259f0c98dd7674fc972ce91a88de (diff) | |
parent | dd683f618a0b038dcda58b909f3fd6cf5805f377 (diff) |
Merge pull request #400 from Stunkymonkey/format_placeholder-run_watch
use format_placeholder for run_watch
Diffstat (limited to 'src/print_run_watch.c')
-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); |