Add brief mode of JSON generation for blerglatest
[blerg.git] / common / json.c
index 5494e4a..eebea2c 100644 (file)
@@ -8,7 +8,7 @@
 #include "database.h"
 #include "json.h"
 
-void json_generate_one_record(yajl_gen g, const char *author, struct blerg *b, uint64_t record) {
+void json_generate_one_record(yajl_gen g, const char *author, struct blerg *b, uint64_t record, int brief) {
        char *data;
        char number[21];
        int len;
@@ -18,6 +18,16 @@ void json_generate_one_record(yajl_gen g, const char *author, struct blerg *b, u
                return;
        }
 
+       if (brief && len > 150) {
+               len = 150;
+               /* This is a bit of a hackish way to add an ellipsis, and will
+                * probably cause weird results if we overwrite part of a UTF-8
+                * char */
+               data[149] = '.';
+               data[148] = '.';
+               data[147] = '.';
+       }
+
        yajl_gen_map_open(g);
        if (author != NULL) {
                yajl_gen_string(g, "author", 6);