X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_dump.c;h=a32f4fb32768dd75c4ef94592b252d5c062dcffb;hb=a12627275ff8487174cbb907a066f62a00b6ae44;hp=707789ca5ecbbb8aece996583a1900056312e77c;hpb=161ecf9c20dbf285f7746aad42327edb8bfeeccc;p=rrdtool.git diff --git a/src/rrd_dump.c b/src/rrd_dump.c index 707789c..a32f4fb 100644 --- a/src/rrd_dump.c +++ b/src/rrd_dump.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.3rc2 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008 ***************************************************************************** * rrd_dump Display a RRD ***************************************************************************** @@ -43,69 +43,17 @@ *****************************************************************************/ #include "rrd_tool.h" #include "rrd_rpncalc.h" +#include "rrd_client.h" #if !(defined(NETWARE) || defined(WIN32)) extern char *tzname[2]; #endif -int rrd_dump( - int argc, - char **argv) -{ - int rc; - int opt_noheader = 0; - /* init rrd clean */ - - optind = 0; - opterr = 0; /* initialize getopt */ - - while (42) { - int opt; - int option_index = 0; - static struct option long_options[] = { - {"no-header", no_argument, 0, 'n'}, - {0, 0, 0, 0} - }; - - opt = getopt_long(argc, argv, "n", long_options, &option_index); - - if (opt == EOF) - break; - - switch (opt) { - case 'n': - opt_range_check = 1; - break; - - default: - rrd_set_error("usage rrdtool %s [--no-header|-n] " - "file.rrd [file.xml]", argv[0]); - return (-1); - break; - } - } /* while (42) */ - - if ((argc - optind) < 2) { - rrd_set_error("usage rrdtool %s [--no-header|-n] " - "file.rrd [file.xml]", argv[0]); - return (-1); - } - - if (argc == 3) { - rc = rrd_dump_opt_r(argv[1], argv[2],opt_noheader); - } else { - rc = rrd_dump_opt_r(argv[1], NULL,opt_noheader); - } - - return rc; -} - int rrd_dump_opt_r( const char *filename, char *outname, - int opt_noheader -) + int opt_noheader) { unsigned int i, ii, ix, iii = 0; time_t now; @@ -133,11 +81,11 @@ int rrd_dump_opt_r( out_file = stdout; } - if (opt_noheader){ - fputs("\n", out_file); - fputs - ("\n", - out_file); + if (!opt_noheader) { + fputs("\n", out_file); + fputs + ("\n", + out_file); } fputs("", out_file); fputs("", out_file); @@ -485,5 +433,75 @@ int rrd_dump_r( const char *filename, char *outname) { - rrd_dump_opt_r(filename,outname,0); + return rrd_dump_opt_r(filename, outname, 0); +} + +int rrd_dump( + int argc, + char **argv) +{ + int rc; + int opt_noheader = 0; + char *opt_daemon = NULL; + + /* init rrd clean */ + + optind = 0; + opterr = 0; /* initialize getopt */ + + while (42) { + int opt; + int option_index = 0; + static struct option long_options[] = { + {"daemon", required_argument, 0, 'd'}, + {"no-header", no_argument, 0, 'n'}, + {0, 0, 0, 0} + }; + + opt = getopt_long(argc, argv, "d:n", long_options, &option_index); + + if (opt == EOF) + break; + + switch (opt) { + case 'd': + if (opt_daemon != NULL) + free (opt_daemon); + opt_daemon = strdup (optarg); + if (opt_daemon == NULL) + { + rrd_set_error ("strdup failed."); + return (-1); + } + break; + + case 'n': + opt_noheader = 1; + break; + + default: + rrd_set_error("usage rrdtool %s [--no-header|-n] " + "file.rrd [file.xml]", argv[0]); + return (-1); + break; + } + } /* while (42) */ + + if ((argc - optind) < 1 || (argc - optind) > 2) { + rrd_set_error("usage rrdtool %s [--no-header|-n] " + "file.rrd [file.xml]", argv[0]); + return (-1); + } + + rc = rrdc_flush_if_daemon(opt_daemon, argv[optind]); + if (opt_daemon) free(opt_daemon); + if (rc) return (rc); + + if ((argc - optind) == 2) { + rc = rrd_dump_opt_r(argv[optind], argv[optind + 1], opt_noheader); + } else { + rc = rrd_dump_opt_r(argv[optind], NULL, opt_noheader); + } + + return rc; }