#! /usr/bin/perl
-BEGIN { $| = 1; print "1..7\n"; }
+BEGIN { $| = 1; print "1..8\n"; }
END {
print "not ok 1\n" unless $loaded;
unlink "demo.rrd";
}
+ok("graph",!$ERROR); # 3
+
+
my ($start,$step,$names,$array) = RRDs::fetch $RRD1, "AVERAGE";
$ERROR = RRDs::error;
}
print "\n";
}
+
+my ($start,$end,$step,$col_cnt,$legend,$data) =
+ RRDs::xport ("-m", 400,
+ "--start", "now-1day",
+ "--end", "now",
+ "DEF:alpha=$RRD1:a:AVERAGE",
+ "DEF:beta=$RRD1:d:AVERAGE",
+ "CDEF:calc=alpha,beta,+,2,/,100,*,102,/",
+ "XPORT:alpha:original ds",
+ "XPORT:calc:calculated values",
+ );
+
+my $ERROR = RRDs::error;
+
+ok("xport",!$ERROR); # 3
+
+print "\nrrdxport test:\n\n";
+print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n";
+print "<xport>\n";
+print " <meta>\n";
+print " <start>$start</start>\n";
+print " <step>$step</step>\n";
+print " <end>$end</end>\n";
+print " <rows>", $#$data + 1, "</rows>\n";
+print " <columns>$col_cnt</columns>\n";
+print " <legend>\n";
+foreach my $entry (@$legend) {
+ print " <entry>$entry</entry>\n";
+}
+print " </legend>\n";
+print " </meta>\n";
+print " <data>\n";
+my $row_counter = 0;
+foreach my $row (@$data) {
+ $row_counter++;
+ print " <row id=\"$row_counter\"><t is=\"", scalar localtime($start), "\">$start</t>";
+ $start += $step;
+ foreach my $val (@$row) {
+ printf ("<v>%1.10e</v>",$val) if $val ne '';
+ print "<v>NaN</v>" if $val eq '';
+ }
+ print "</row>\n";
+}
+print " </data>\n";
+print "</xport>\n";
#define opterror(options, format, args...) \
snprintf(options->errmsg, sizeof(options->errmsg), format, args);
-void optparse_init(struct optparse *options, char **argv)
+#define options_argv(i) \
+ (i) < options->argc ? options->argv[i] : 0;
+
+void optparse_init(struct optparse *options, int argc, char **argv)
{
options->argv = argv;
+ options->argc = argc;
options->permute = 1;
options->optind = 1;
options->subopt = 0;
options->errmsg[0] = '\0';
options->optopt = 0;
options->optarg = NULL;
- char *option = options->argv[options->optind];
+ char *option = options_argv(options->optind);
if (option == NULL) {
return -1;
} else if (is_dashdash(option)) {
option += options->subopt + 1;
options->optopt = option[0];
int type = argtype(optstring, option[0]);
- char *next = options->argv[options->optind + 1];
+ char *next = options_argv(options->optind + 1);
switch (type) {
case -1:
opterror(options, "invalid option -- '%c'", option[0]);
const struct optparse_long *longopts,
int *longindex)
{
- char *option = options->argv[options->optind];
+ char *option = options_argv(options->optind);
if (option == NULL) {
return -1;
} else if (is_shortopt(option)) {
} if (arg != NULL) {
options->optarg = arg;
} else if (longopts[i].argtype == OPTPARSE_REQUIRED) {
- options->optarg = options->argv[options->optind++];
+ options->optarg = options_argv(options->optind);
+ options->optind++;
if (options->optarg == NULL) {
opterror(options, "option requires argument -- '%s'", name);
return '?';
struct optparse {
char **argv;
+ int argc;
int permute;
int optind;
int optopt;
/**
* Initializes the parser state.
*/
-void optparse_init(struct optparse *options, char **argv);
+void optparse_init(struct optparse *options, int argc, char **argv);
/**
* Read the next option in the argv array.
rrd_time_value_t start_tv, end_tv;
char *parsetime_error = NULL;
struct optparse options;
- optparse_init(&options, argv);
+ optparse_init(&options, argc, argv);
struct optparse_long longopts[] = {
{"start", 's', OPTPARSE_REQUIRED},