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