struct graph_data_s
{
- str_array_t *args;
+ rrd_args_t *args;
rrd_info_t *info;
time_t mtime;
time_t expires;
data->begin = begin;
data->end = end;
- array_append (data->args, "-s");
- array_append_format (data->args, "%li", begin);
- array_append (data->args, "-e");
- array_append_format (data->args, "%li", end);
+ array_append (data->args->options, "-s");
+ array_append_format (data->args->options, "%li", begin);
+ array_append (data->args->options, "-e");
+ array_append_format (data->args->options, "%li", end);
return (0);
} /* }}} int get_time_args */
graph_instance_t *inst;
int status;
+ int argc;
+ char **argv;
+
cfg = gl_graph_get_selected ();
if (cfg == NULL)
OUTPUT_ERROR ("gl_graph_get_selected () failed.\n");
if (inst == NULL)
OUTPUT_ERROR ("inst_get_selected (%p) failed.\n", (void *) cfg);
- data.args = array_create ();
+ data.args = ra_create ();
if (data.args == NULL)
return (ENOMEM);
- array_append (data.args, "graph");
- array_append (data.args, "-");
- array_append (data.args, "--imgformat");
- array_append (data.args, "PNG");
+ array_append (data.args->options, "graph");
+ array_append (data.args->options, "-");
+ array_append (data.args->options, "--imgformat");
+ array_append (data.args->options, "PNG");
get_time_args (&data);
status = inst_get_rrdargs (cfg, inst, data.args);
if (status != 0)
{
- array_destroy (data.args);
+ ra_destroy (data.args);
OUTPUT_ERROR ("inst_get_rrdargs failed with status %i.\n", status);
}
+ argc = ra_argc (data.args);
+ argv = ra_argv (data.args);
+ if ((argc < 0) || (argv == NULL))
+ {
+ ra_destroy (data.args);
+ return (-1);
+ }
+
rrd_clear_error ();
- data.info = rrd_graph_v (array_argc (data.args), array_argv (data.args));
+ data.info = rrd_graph_v (argc, argv);
if ((data.info == NULL) || rrd_test_error ())
{
printf ("Content-Type: text/plain\n\n");
printf ("rrd_graph_v failed: %s\n", rrd_get_error ());
- emulate_graph (array_argc (data.args), array_argv (data.args));
+ emulate_graph (argc, argv);
}
else
{
if (data.info != NULL)
rrd_info_free (data.info);
- array_destroy (data.args);
+ ra_argv_free (argv);
+ ra_destroy (data.args);
data.args = NULL;
return (0);
} /* }}} int graph_clear_instances */
int graph_get_rrdargs (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
- str_array_t *args)
+ rrd_args_t *args)
{
if ((cfg == NULL) || (inst == NULL) || (args == NULL))
return (EINVAL);
if (cfg->title != NULL)
{
- array_append (args, "-t");
- array_append (args, cfg->title);
+ array_append (args->options, "-t");
+ array_append (args->options, cfg->title);
}
if (cfg->vertical_label != NULL)
{
- array_append (args, "-v");
- array_append (args, cfg->vertical_label);
+ array_append (args->options, "-v");
+ array_append (args->options, cfg->vertical_label);
}
if (cfg->show_zero)
{
- array_append (args, "-l");
- array_append (args, "0");
+ array_append (args->options, "-l");
+ array_append (args->options, "0");
}
return (0);
#include "graph_types.h"
#include "graph_ident.h"
#include "oconfig.h"
+#include "rrd_args.h"
#include "utils_array.h"
/*
int graph_clear_instances (graph_config_t *cfg);
int graph_get_rrdargs (graph_config_t *cfg, graph_instance_t *inst,
- str_array_t *args);
+ rrd_args_t *args);
#endif /* GRAPH_H */
/* vim: set sw=2 sts=2 et fdm=marker : */
} /* }}} int def_foreach */
int def_get_rrdargs (graph_def_t *def, graph_ident_t *ident, /* {{{ */
- str_array_t *args)
+ rrd_args_t *args)
{
char *file;
int index;
DEBUG ("gl_ident_get_rrdargs: file = %s;\n", file);
- index = array_argc (args);
+ index = args->index;
+ args->index++;
/* CDEFs */
- array_append_format (args, "DEF:def_%04i_min=%s:%s:MIN",
+ array_append_format (args->data, "DEF:def_%04i_min=%s:%s:MIN",
index, file, def->ds_name);
- array_append_format (args, "DEF:def_%04i_avg=%s:%s:AVERAGE",
+ array_append_format (args->data, "DEF:def_%04i_avg=%s:%s:AVERAGE",
index, file, def->ds_name);
- array_append_format (args, "DEF:def_%04i_max=%s:%s:MAX",
+ array_append_format (args->data, "DEF:def_%04i_max=%s:%s:MAX",
index, file, def->ds_name);
/* VDEFs */
- array_append_format (args, "VDEF:vdef_%04i_min=def_%04i_min,MINIMUM",
+ array_append_format (args->data, "VDEF:vdef_%04i_min=def_%04i_min,MINIMUM",
index, index);
- array_append_format (args, "VDEF:vdef_%04i_avg=def_%04i_avg,AVERAGE",
+ array_append_format (args->data, "VDEF:vdef_%04i_avg=def_%04i_avg,AVERAGE",
index, index);
- array_append_format (args, "VDEF:vdef_%04i_max=def_%04i_max,MAXIMUM",
+ array_append_format (args->data, "VDEF:vdef_%04i_max=def_%04i_max,MAXIMUM",
index, index);
- array_append_format (args, "VDEF:vdef_%04i_lst=def_%04i_avg,LAST",
+ array_append_format (args->data, "VDEF:vdef_%04i_lst=def_%04i_avg,LAST",
index, index);
/* Graph part */
- array_append_format (args, "%s:def_%04i_avg#%06"PRIx32":%s%s",
+ array_append_format (args->draw, "%s:def_%04i_avg#%06"PRIx32":%s%s",
def->area ? "AREA" : "LINE1",
index, def->color,
(def->legend != NULL) ? def->legend : def->ds_name,
def->stack ? ":STACK" : "");
- array_append_format (args, "GPRINT:vdef_%04i_min:%s min,",
+ array_append_format (args->draw, "GPRINT:vdef_%04i_min:%s min,",
index, (def->format != NULL) ? def->format : "%6.2lf");
- array_append_format (args, "GPRINT:vdef_%04i_avg:%s avg,",
+ array_append_format (args->draw, "GPRINT:vdef_%04i_avg:%s avg,",
index, (def->format != NULL) ? def->format : "%6.2lf");
- array_append_format (args, "GPRINT:vdef_%04i_max:%s max,",
+ array_append_format (args->draw, "GPRINT:vdef_%04i_max:%s max,",
index, (def->format != NULL) ? def->format : "%6.2lf");
- array_append_format (args, "GPRINT:vdef_%04i_lst:%s last\\l",
+ array_append_format (args->draw, "GPRINT:vdef_%04i_lst:%s last\\l",
index, (def->format != NULL) ? def->format : "%6.2lf");
free (file);
#include "graph_types.h"
#include "utils_array.h"
#include "oconfig.h"
+#include "rrd_args.h"
graph_def_t *def_create (graph_config_t *cfg, graph_ident_t *ident,
const char *ds_name);
int def_foreach (graph_def_t *def, def_callback_t callback, void *user_data);
int def_get_rrdargs (graph_def_t *def, graph_ident_t *ident,
- str_array_t *args);
+ rrd_args_t *args);
/* vim: set sw=2 sts=2 et fdm=marker : */
#endif
struct def_callback_data_s
{
graph_instance_t *inst;
- str_array_t *args;
+ rrd_args_t *args;
};
typedef struct def_callback_data_s def_callback_data_t;
{
def_callback_data_t *data = user_data;
graph_instance_t *inst = data->inst;
- str_array_t *args = data->args;
+ rrd_args_t *args = data->args;
size_t i;
int inst_get_rrdargs (graph_config_t *cfg, /* {{{ */
graph_instance_t *inst,
- str_array_t *args)
+ rrd_args_t *args)
{
def_callback_data_t data = { inst, args };
graph_def_t *defs;
#include "graph_types.h"
#include "graph_ident.h"
+#include "rrd_args.h"
#include "utils_array.h"
/*
char *buffer, size_t buffer_size);
int inst_get_rrdargs (graph_config_t *cfg, graph_instance_t *inst,
- str_array_t *args);
+ rrd_args_t *args);
graph_ident_t *inst_get_selector (graph_instance_t *inst);
return (NULL);
pos = 0;
+ argv[0] = NULL;
#define APPEND_FIELD(field) do \
{ \
pos += ary_argc; \
argv[pos] = NULL; \
} \
- free (ary_argv); \
} while (0)
APPEND_FIELD (options);
return (argv);
} /* }}} char **ra_argv */
+void ra_argv_free (char **argv) /* {{{ */
+{
+ /* The pointers contained in the "argv" come from "array_argv". We don't need
+ * to free them. We only need to free what we actually alloced directly in
+ * "ra_argv". */
+ free (argv);
+} /* }}} void ra_argv_free */
+
/* vim: set sw=2 sts=2 et fdm=marker : */
str_array_t *calc;
str_array_t *draw;
+ int index;
char last_stack_cdef[64];
};
typedef struct rrd_args_s rrd_args_t;
int ra_argc (rrd_args_t *ra);
char **ra_argv (rrd_args_t *ra);
+void ra_argv_free (char **argv);
#endif /* RRD_ARGS_H */
/* vim: set sw=2 sts=2 et fdm=marker : */