summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/print_run_watch.c23
1 files 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 <yajl/yajl_version.h>
#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);