diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2012-03-25 20:55:55 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2012-03-25 22:05:00 +0200 |
commit | 12b1bfa9b8485de88b0bda82821c021aee197673 (patch) | |
tree | b6d87f7ed5876109863a6599992e351509a30d58 /src/print_load.c | |
parent | afb0525235c57fc4896633003a45bfb013af38d2 (diff) |
Properly output JSON with libyajl
Diffstat (limited to 'src/print_load.c')
-rw-r--r-- | src/print_load.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/print_load.c b/src/print_load.c index 8c2343b..181773b 100644 --- a/src/print_load.c +++ b/src/print_load.c @@ -3,11 +3,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <yajl/yajl_gen.h> -void print_load(const char *format) { -/* Get load */ - if (output_format == O_I3BAR) - printf("{\"name\":\"load\", \"full_text\":\""); +void print_load(yajl_gen json_gen, char *buffer, const char *format) { + char *outwalk = buffer; + /* Get load */ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(sun) double loadavg[3]; @@ -18,28 +18,28 @@ void print_load(const char *format) { for (walk = format; *walk != '\0'; walk++) { if (*walk != '%') { - putchar(*walk); + *(outwalk++) = *walk; continue; } if (BEGINS_WITH(walk+1, "1min")) { - (void)printf("%1.2f", loadavg[0]); + outwalk += sprintf(outwalk, "%1.2f", loadavg[0]); walk += strlen("1min"); } if (BEGINS_WITH(walk+1, "5min")) { - (void)printf("%1.2f", loadavg[1]); + outwalk += sprintf(outwalk, "%1.2f", loadavg[1]); walk += strlen("5min"); } if (BEGINS_WITH(walk+1, "15min")) { - (void)printf("%1.2f", loadavg[2]); + outwalk += sprintf(outwalk, "%1.2f", loadavg[2]); walk += strlen("15min"); } } - if (output_format == O_I3BAR) - printf("\"}"); + *outwalk = '\0'; + OUTPUT_FULL_TEXT(buffer); return; error: |