From 84c0eddd660705b09ae4d7b08b26220e19bc94f7 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Tue, 31 Mar 2020 15:47:39 +0200 Subject: [PATCH] use format_placeholder for path_exists --- src/print_path_exists.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/print_path_exists.c b/src/print_path_exists.c index 87601b4..504eb6c 100644 --- a/src/print_path_exists.c +++ b/src/print_path_exists.c @@ -7,6 +7,8 @@ #include #include "i3status.h" +#define STRING_SIZE 5 + void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format, const char *format_down) { const char *walk; char *outwalk = buffer; @@ -23,23 +25,18 @@ void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const START_COLOR((exists ? "color_good" : "color_bad")); - for (; *walk != '\0'; walk++) { - if (*walk != '%') { - *(outwalk++) = *walk; + char string_status[STRING_SIZE]; - } else if (BEGINS_WITH(walk + 1, "title")) { - outwalk += sprintf(outwalk, "%s", title); - walk += strlen("title"); + snprintf(string_status, STRING_SIZE, "%s", (exists ? "yes" : "no")); - } else if (BEGINS_WITH(walk + 1, "status")) { - outwalk += sprintf(outwalk, "%s", (exists ? "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); + free(buffer); }