diff options
author | Felix Buehler <account@buehler.rocks> | 2020-03-31 15:47:39 +0200 |
---|---|---|
committer | Felix Buehler <account@buehler.rocks> | 2020-03-31 16:01:17 +0200 |
commit | 84c0eddd660705b09ae4d7b08b26220e19bc94f7 (patch) | |
tree | 2f44f5466b57b4eb17fba1a5c30bb0b9f179c99a /src/print_path_exists.c | |
parent | 101215bbc83b97de30b6b535bbe2e93d2e913804 (diff) |
use format_placeholder for path_exists
Diffstat (limited to 'src/print_path_exists.c')
-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); } |