From: Florian Forster Date: Wed, 8 Sep 2010 09:25:49 +0000 (+0200) Subject: src/graph.[ch]: Implement "graph_def_to_json". X-Git-Tag: v4.0.0~44 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6b69fb3290de5d4208dc751f2fdbf8a37212fed8;p=collection4.git src/graph.[ch]: Implement "graph_def_to_json". --- diff --git a/src/graph.c b/src/graph.c index ad47e46..fdbf713 100644 --- a/src/graph.c +++ b/src/graph.c @@ -649,6 +649,35 @@ int graph_to_json (const graph_config_t *cfg, /* {{{ */ return (0); } /* }}} int graph_to_json */ +int graph_def_to_json (const graph_config_t *cfg, /* {{{ */ + yajl_gen handler) +{ +#define yajl_gen_string_cast(h,p,l) \ + yajl_gen_string (h, (unsigned char *) p, (unsigned int) l) + + if ((cfg == NULL) || (handler == NULL)) + return (EINVAL); + + yajl_gen_map_open (handler); + + yajl_gen_string_cast (handler, "select", strlen ("select")); + ident_to_json (cfg->select, handler); + yajl_gen_string_cast (handler, "title", strlen ("title")); + yajl_gen_string_cast (handler, cfg->title, strlen (cfg->title)); + yajl_gen_string_cast (handler, "vertical_label", strlen ("vertical_label")); + yajl_gen_string_cast (handler, cfg->vertical_label, strlen (cfg->vertical_label)); + yajl_gen_string_cast (handler, "show_zero", strlen ("show_zero")); + yajl_gen_bool (handler, cfg->show_zero); + + yajl_gen_string_cast (handler, "defs", strlen ("defs")); + def_to_json (cfg->defs, handler); + + yajl_gen_map_close (handler); + + return (0); +#undef yajl_gen_string_cast +} /* }}} int graph_def_to_json */ + static int graph_sort_instances_cb (const void *v0, const void *v1) /* {{{ */ { return (inst_compare (*(graph_instance_t * const *) v0, diff --git a/src/graph.h b/src/graph.h index e9c603a..2873103 100644 --- a/src/graph.h +++ b/src/graph.h @@ -112,6 +112,7 @@ int graph_inst_search_field (graph_config_t *cfg, int graph_compare (graph_config_t *cfg, const graph_ident_t *ident); int graph_to_json (const graph_config_t *cfg, yajl_gen handler); +int graph_def_to_json (const graph_config_t *cfg, yajl_gen handler); size_t graph_num_instances (graph_config_t *cfg);