Merge pull request #399 from Stunkymonkey/format_placeholder-path_exists
use format_placeholder for path_exists
This commit is contained in:
commit
ffa429d145
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user