]> git.sur5r.net Git - i3/i3status/blob - src/print_path_exists.c
fix: use SYSCONFDIR in error message
[i3/i3status] / src / print_path_exists.c
1 // vim:ts=4:sw=4:expandtab
2 #include <config.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <yajl/yajl_gen.h>
6 #include <yajl/yajl_version.h>
7 #include <sys/stat.h>
8 #include "i3status.h"
9
10 void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format, const char *format_down) {
11     const char *walk;
12     char *outwalk = buffer;
13     struct stat st;
14     const bool exists = (stat(path, &st) == 0);
15
16     if (exists || format_down == NULL) {
17         walk = format;
18     } else {
19         walk = format_down;
20     }
21
22     INSTANCE(path);
23
24     START_COLOR((exists ? "color_good" : "color_bad"));
25
26     for (; *walk != '\0'; walk++) {
27         if (*walk != '%') {
28             *(outwalk++) = *walk;
29
30         } else if (BEGINS_WITH(walk + 1, "title")) {
31             outwalk += sprintf(outwalk, "%s", title);
32             walk += strlen("title");
33
34         } else if (BEGINS_WITH(walk + 1, "status")) {
35             outwalk += sprintf(outwalk, "%s", (exists ? "yes" : "no"));
36             walk += strlen("status");
37
38         } else {
39             *(outwalk++) = '%';
40         }
41     }
42
43     END_COLOR;
44     OUTPUT_FULL_TEXT(buffer);
45 }