#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 '?';
/****************************************************************************
* RRDtool 1.4.8 Copyright by Tobi Oetiker, 1997-2013
****************************************************************************
- * rrd_xport.c export RRD data
+ * rrd_xport.c export RRD data
****************************************************************************/
#include <sys/stat.h>
time_t *start,
time_t *end, /* which time frame do you want ?
* will be changed to represent reality */
- unsigned long *step, /* which stepsize do you want?
+ unsigned long *step, /* which stepsize do you want?
* will be changed to represent reality */
unsigned long *col_cnt, /* number of data columns in the result */
char ***legend_v, /* legend entries */
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},
time_t *start,
time_t *end, /* which time frame do you want ?
* will be changed to represent reality */
- unsigned long *step, /* which stepsize do you want?
+ unsigned long *step, /* which stepsize do you want?
* will be changed to represent reality */
unsigned long *col_cnt, /* number of data columns in the result */
char ***legend_v, /* legend entries */
unsigned long xport_counter = 0;
int *ref_list;
long *step_list;
- long *step_list_ptr;
+ long *step_list_ptr;
char **legend_list;
return -1;
/* how many xports? */
- *col_cnt = 0;
+ *col_cnt = 0;
for (i = 0; i < im->gdes_c; i++) {
switch (im->gdes[i].gf) {
case GF_XPORT:
legend_list[j++][0] = '\0';
break;
default:
- break;
+ break;
}
}
- *step_list_ptr=0;
+ *step_list_ptr=0;
/* find a common step */
*step = lcd(step_list);
/* printf("step: %lu\n",*step); */
free(step_list);
-
+
*start = im->start - im->start % (*step);
*end = im->end - im->end % (*step) + (*step);
-
+
/* room for rearranged data */
/* this is a return value! */