From dd683f618a0b038dcda58b909f3fd6cf5805f377 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Tue, 31 Mar 2020 16:08:07 +0200 Subject: use format_placeholder for run_watch --- src/print_run_watch.c | 23 +++++++++-------------- 1 file 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 #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); -- cgit v1.2.3