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