summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIngo Bürk <admin@airblader.de>2020-04-03 08:37:05 +0200
committerGitHub <noreply@github.com>2020-04-03 08:37:05 +0200
commitffa429d145a7259f0c98dd7674fc972ce91a88de (patch)
treed0506ab81122757a0f989e3ab8eb60ff24eb4a28 /src
parent7f58f262ba1c4ded305d54b96efb0727d67cb41b (diff)
parent84c0eddd660705b09ae4d7b08b26220e19bc94f7 (diff)
Merge pull request #399 from Stunkymonkey/format_placeholder-path_exists
use format_placeholder for path_exists
Diffstat (limited to 'src')
-rw-r--r--src/print_path_exists.c23
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);
}