]> git.sur5r.net Git - i3/i3status/blob - src/print_run_watch.c
fix: use SYSCONFDIR in error message
[i3/i3status] / src / print_run_watch.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 "i3status.h"
8
9 void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format, const char *format_down) {
10     bool running = process_runs(pidfile);
11     const char *walk;
12     char *outwalk = buffer;
13
14     if (running || format_down == NULL) {
15         walk = format;
16     } else {
17         walk = format_down;
18     }
19
20     INSTANCE(pidfile);
21
22     START_COLOR((running ? "color_good" : "color_bad"));
23
24     for (; *walk != '\0'; walk++) {
25         if (*walk != '%') {
26             *(outwalk++) = *walk;
27
28         } else if (BEGINS_WITH(walk + 1, "title")) {
29             outwalk += sprintf(outwalk, "%s", title);
30             walk += strlen("title");
31
32         } else if (BEGINS_WITH(walk + 1, "status")) {
33             outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
34             walk += strlen("status");
35
36         } else {
37             *(outwalk++) = '%';
38         }
39     }
40
41     END_COLOR;
42     OUTPUT_FULL_TEXT(buffer);
43 }