]> git.sur5r.net Git - i3/i3status/blob - src/print_run_watch.c
clang-format-3.5 -i **/*.[ch], update modeline
[i3/i3status] / src / print_run_watch.c
1 // vim:ts=4:sw=4:expandtab
2 #include <stdio.h>
3 #include <string.h>
4 #include <yajl/yajl_gen.h>
5 #include <yajl/yajl_version.h>
6 #include "i3status.h"
7
8 void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format) {
9     bool running = process_runs(pidfile);
10     const char *walk;
11     char *outwalk = buffer;
12
13     INSTANCE(pidfile);
14
15     START_COLOR((running ? "color_good" : "color_bad"));
16
17     for (walk = format; *walk != '\0'; walk++) {
18         if (*walk != '%') {
19             *(outwalk++) = *walk;
20             continue;
21         }
22
23         if (BEGINS_WITH(walk + 1, "title")) {
24             outwalk += sprintf(outwalk, "%s", title);
25             walk += strlen("title");
26         } else if (BEGINS_WITH(walk + 1, "status")) {
27             outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
28             walk += strlen("status");
29         }
30     }
31
32     END_COLOR;
33     OUTPUT_FULL_TEXT(buffer);
34 }