summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b7d53a7)
raw | patch | inline | side by side (parent: b7d53a7)
author | Florian Forster <ff@octo.it> | |
Fri, 2 Jul 2010 17:27:44 +0000 (19:27 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 2 Jul 2010 17:27:44 +0000 (19:27 +0200) |
src/action_graph.c | patch | blob | history | |
src/graph.c | patch | blob | history | |
src/graph.h | patch | blob | history | |
src/graph_def.c | patch | blob | history | |
src/graph_def.h | patch | blob | history | |
src/graph_instance.c | patch | blob | history | |
src/graph_instance.h | patch | blob | history | |
src/rrd_args.c | patch | blob | history | |
src/rrd_args.h | patch | blob | history |
diff --git a/src/action_graph.c b/src/action_graph.c
index d496a242e55cb97bcbcfe29cf13a8579455f0610..878973099edcdf8bef31a4c9809d7c9d547cbe11 100644 (file)
--- a/src/action_graph.c
+++ b/src/action_graph.c
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);
diff --git a/src/graph.c b/src/graph.c
index 01f0791dfa8ac7ea7fd761ced83c3070216fde45..8d12a25a1606d397d4ac20e66cb91fe9b45af9ee 100644 (file)
--- a/src/graph.c
+++ b/src/graph.c
} /* }}} 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);
diff --git a/src/graph.h b/src/graph.h
index 0cb45d7133a579092e2974a1237bc54d1900633c..ddfbda6a7ae09637008181bf8706e59b348a1cb8 100644 (file)
--- a/src/graph.h
+++ b/src/graph.h
#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 : */
diff --git a/src/graph_def.c b/src/graph_def.c
index cecc8f029f4ade02594704c3bcbcd19b0730f4ec..197c6b50fb55074185045ec2fb8c158ebe1071e7 100644 (file)
--- a/src/graph_def.c
+++ b/src/graph_def.c
} /* }}} 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);
diff --git a/src/graph_def.h b/src/graph_def.h
index a4bb7fde579b6844f3b691894de4d628f072abe3..456602b6004fb2f9331fe081fc0ce0c0da02cfeb 100644 (file)
--- a/src/graph_def.h
+++ b/src/graph_def.h
#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
diff --git a/src/graph_instance.c b/src/graph_instance.c
index 5431589cfa9f4ed4f1c3074c8734f0065f8cc7be..317c381f77f7c48aad0dd664d4279161290ed032 100644 (file)
--- a/src/graph_instance.c
+++ b/src/graph_instance.c
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;
@@ -124,7 +124,7 @@ static int gl_instance_get_rrdargs_cb (graph_def_t *def, void *user_data) /* {{{
{
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;
diff --git a/src/graph_instance.h b/src/graph_instance.h
index fa08dcdae86a86bca3e7012460c5bb251f041a46..61d5ea43f67bc05dd187ac24030e12fd3cbd3715 100644 (file)
--- a/src/graph_instance.h
+++ b/src/graph_instance.h
#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);
diff --git a/src/rrd_args.c b/src/rrd_args.c
index f5358c8bbc8cdda2add775b6e67799c3ec777d60..f9137332276faf7a7fb89d3d86035f99b162deaf 100644 (file)
--- a/src/rrd_args.c
+++ b/src/rrd_args.c
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 : */
diff --git a/src/rrd_args.h b/src/rrd_args.h
index 4bfeea7e5d342f27c239db06515ebdc3e59da7a6..b3ef34adcbd974c106716be65def7ebce7d08868 100644 (file)
--- a/src/rrd_args.h
+++ b/src/rrd_args.h
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 : */