diff options
-rw-r--r-- | src/print_path_exists.c | 23 |
1 files 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 <sys/stat.h> #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); } |