diff --git a/src/rrd_tool.c b/src/rrd_tool.c
index e481fa352bfb42bcd2218c272a4089543285087f..24abcdce9c36a4ad445e4cc9ddd3bd8509fbdf45 100644 (file)
--- a/src/rrd_tool.c
+++ b/src/rrd_tool.c
}
} else if (strcmp("xport", argv[1]) == 0) {
#ifdef HAVE_RRD_GRAPH
}
} else if (strcmp("xport", argv[1]) == 0) {
#ifdef HAVE_RRD_GRAPH
- int xxsize;
- unsigned long int j = 0;
- time_t start, end, ti;
- unsigned long step, col_cnt, row_cnt;
- rrd_value_t *data, *ptr;
- char **legend_v;
- int enumds = 0;
- int json = 0;
- int i;
- size_t vtag_s = strlen(COL_DATA_TAG) + 10;
- char *vtag = malloc(vtag_s);
-
- for (i = 2; i < argc; i++) {
- if (strcmp("--enumds", argv[i]) == 0)
- enumds = 1;
- if (strcmp("--json", argv[i]) == 0)
- json = 1;
- }
-
- if (rrd_xport
- (argc - 1, &argv[1], &xxsize, &start, &end, &step, &col_cnt,
- &legend_v, &data) == 0) {
- char *old_locale = setlocale(LC_NUMERIC,NULL);
- setlocale(LC_NUMERIC, "C");
- row_cnt = (end - start) / step;
- ptr = data;
- if (json == 0){
- printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n\n",
- XML_ENCODING);
- printf("<%s>\n", ROOT_TAG);
- printf(" <%s>\n", META_TAG);
- }
- else {
- printf("{ about: 'RRDtool xport JSON output',\n meta: {\n");
- }
-
-
-#define pXJV(indent,fmt,tag,value) \
- if (json) { \
- printf(indent "%s: " fmt ",\n",tag,value); \
- } else { \
- printf(indent "<%s>" fmt "</%s>\n",tag,value,tag); \
- }
-
- pXJV(" ","%lld",META_START_TAG,(long long int) start + step);
- pXJV(" ","%lu", META_STEP_TAG, step);
- pXJV(" ","%lld",META_END_TAG,(long long int) start + step);
- if (! json){
- pXJV(" ","%lu", META_ROWS_TAG, row_cnt);
- pXJV(" ","%lu", META_COLS_TAG, col_cnt);
- }
-
- if (json){
- printf(" %s: [\n", LEGEND_TAG);
- }
- else {
- printf(" <%s>\n", LEGEND_TAG);
- }
- for (j = 0; j < col_cnt; j++) {
- char *entry = NULL;
- entry = legend_v[j];
- if (json){
- printf(" '%s'", entry);
- if (j < col_cnt -1){
- printf(",");
- }
- printf("\n");
- }
- else {
- printf(" <%s>%s</%s>\n", LEGEND_ENTRY_TAG, entry,
- LEGEND_ENTRY_TAG);
- }
- free(entry);
- }
- free(legend_v);
- if (json){
- printf(" ]\n },\n");
- }
- else {
- printf(" </%s>\n", LEGEND_TAG);
- printf(" </%s>\n", META_TAG);
- }
-
- if (json){
- printf(" %s: [\n",DATA_TAG);
- } else {
- printf(" <%s>\n", DATA_TAG);
- }
- for (ti = start + step; ti <= end; ti += step) {
- if (json){
- printf(" [ ");
- }
- else {
- printf(" <%s>", DATA_ROW_TAG);
- printf("<%s>%lld</%s>", COL_TIME_TAG, (long long int)ti, COL_TIME_TAG);
- }
- for (j = 0; j < col_cnt; j++) {
- rrd_value_t newval = DNAN;
- newval = *ptr;
- if (json){
- if (isnan(newval)){
- printf("null");
- } else {
- printf("%0.10e",newval);
- }
- if (j < col_cnt -1){
- printf(", ");
- }
- }
- else {
- if (enumds == 1)
- snprintf(vtag, vtag_s, "%s%lu", COL_DATA_TAG, j);
- else
- snprintf(vtag, vtag_s, "%s", COL_DATA_TAG);
- if (isnan(newval)) {
- printf("<%s>NaN</%s>", vtag, vtag);
- } else {
- printf("<%s>%0.10e</%s>", vtag, newval, vtag);
- };
- }
- ptr++;
- }
- if (json){
- printf(ti < end ? " ],\n" : " ]\n");
- }
- else {
- printf("</%s>\n", DATA_ROW_TAG);
- }
- }
- free(data);
- if (json){
- printf(" ]\n}\n");
- }
- else {
- printf(" </%s>\n", DATA_TAG);
- printf("</%s>\n", ROOT_TAG);
- }
- setlocale(LC_NUMERIC, old_locale);
- }
- free(vtag);
+ time_t start, end;
+ unsigned long step, col_cnt;
+ rrd_value_t *data;
+ char **legend_v;
+ rrd_xport
+ (argc - 1, &argv[1], NULL, &start, &end, &step, &col_cnt,
+ &legend_v, &data);
#else
rrd_set_error("the instance of rrdtool has been compiled without graphics");
#endif
#else
rrd_set_error("the instance of rrdtool has been compiled without graphics");
#endif