2009-10-11 22:11:09 +02:00
|
|
|
#include <stdio.h>
|
2009-10-16 20:31:20 +02:00
|
|
|
#include <string.h>
|
2012-03-25 20:55:55 +02:00
|
|
|
#include <yajl/yajl_gen.h>
|
2012-04-08 14:05:47 +02:00
|
|
|
#include <yajl/yajl_version.h>
|
2009-10-11 22:11:09 +02:00
|
|
|
#include "i3status.h"
|
|
|
|
|
2012-03-25 20:55:55 +02:00
|
|
|
void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format) {
|
2009-10-11 22:11:09 +02:00
|
|
|
bool running = process_runs(pidfile);
|
2009-10-16 20:31:20 +02:00
|
|
|
const char *walk;
|
2012-03-25 20:55:55 +02:00
|
|
|
char *outwalk = buffer;
|
2009-10-16 20:31:20 +02:00
|
|
|
|
2012-03-25 20:55:55 +02:00
|
|
|
INSTANCE(pidfile);
|
2012-02-16 23:29:29 +00:00
|
|
|
|
2012-03-25 20:55:55 +02:00
|
|
|
START_COLOR((running ? "color_good" : "color_bad"));
|
2012-02-16 23:29:29 +00:00
|
|
|
|
2009-10-16 20:31:20 +02:00
|
|
|
for (walk = format; *walk != '\0'; walk++) {
|
|
|
|
if (*walk != '%') {
|
2012-03-25 20:55:55 +02:00
|
|
|
*(outwalk++) = *walk;
|
2009-10-16 20:31:20 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-03-11 20:15:36 +01:00
|
|
|
if (BEGINS_WITH(walk+1, "title")) {
|
2012-03-25 20:55:55 +02:00
|
|
|
outwalk += sprintf(outwalk, "%s", title);
|
2009-10-16 20:31:20 +02:00
|
|
|
walk += strlen("title");
|
2014-03-11 20:15:36 +01:00
|
|
|
} else if (BEGINS_WITH(walk+1, "status")) {
|
2012-03-25 20:55:55 +02:00
|
|
|
outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
|
2009-10-16 20:31:20 +02:00
|
|
|
walk += strlen("status");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:55:55 +02:00
|
|
|
END_COLOR;
|
|
|
|
OUTPUT_FULL_TEXT(buffer);
|
2009-10-11 22:11:09 +02:00
|
|
|
}
|