Merge pull request #399 from Stunkymonkey/format_placeholder-path_exists

use format_placeholder for path_exists
This commit is contained in:
Ingo Bürk 2020-04-03 08:37:05 +02:00 committed by GitHub
commit ffa429d145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "i3status.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) { 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; const char *walk;
char *outwalk = buffer; 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")); START_COLOR((exists ? "color_good" : "color_bad"));
for (; *walk != '\0'; walk++) { char string_status[STRING_SIZE];
if (*walk != '%') {
*(outwalk++) = *walk;
} else if (BEGINS_WITH(walk + 1, "title")) { snprintf(string_status, STRING_SIZE, "%s", (exists ? "yes" : "no"));
outwalk += sprintf(outwalk, "%s", title);
walk += strlen("title");
} else if (BEGINS_WITH(walk + 1, "status")) { placeholder_t placeholders[] = {
outwalk += sprintf(outwalk, "%s", (exists ? "yes" : "no")); {.name = "%title", .value = title},
walk += strlen("status"); {.name = "%status", .value = string_status}};
} else { const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
*(outwalk++) = '%'; buffer = format_placeholders(walk, &placeholders[0], num);
}
}
END_COLOR; END_COLOR;
OUTPUT_FULL_TEXT(buffer); OUTPUT_FULL_TEXT(buffer);
free(buffer);
} }