summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 55187f5)
raw | patch | inline | side by side (parent: 55187f5)
author | Florian Forster <ff@octo.it> | |
Fri, 2 Jul 2010 17:08:13 +0000 (19:08 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 2 Jul 2010 17:08:13 +0000 (19:08 +0200) |
src/Makefile.am | patch | blob | history | |
src/rrd_args.c | [new file with mode: 0644] | patch | blob |
src/rrd_args.h | [new file with mode: 0644] | patch | blob |
diff --git a/src/Makefile.am b/src/Makefile.am
index ed5393aed2006ac1838c421ed1ddaff193ad0c8e..0f86311239971785895a0ba04097693fad7cb2ea 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
graph_ident.c graph_ident.h \
graph_instance.c graph_instance.h \
graph_list.c graph_list.h \
+ rrd_args.c rrd_args.h \
utils_array.c utils_array.h \
utils_cgi.c utils_cgi.h
diff --git a/src/rrd_args.c b/src/rrd_args.c
--- /dev/null
+++ b/src/rrd_args.c
@@ -0,0 +1,105 @@
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "rrd_args.h"
+
+rrd_args_t *ra_create (void) /* {{{ */
+{
+ rrd_args_t *ra;
+
+ ra = malloc (sizeof (*ra));
+ if (ra == NULL)
+ return (NULL);
+ memset (ra, 0, sizeof (*ra));
+
+ ra->options = array_create ();
+ ra->data = array_create ();
+ ra->calc = array_create ();
+ ra->draw = array_create ();
+
+ if ((ra->options == NULL)
+ || (ra->data == NULL)
+ || (ra->calc == NULL)
+ || (ra->draw == NULL))
+ {
+ ra_destroy (ra);
+ return (NULL);
+ }
+
+ return (ra);
+} /* }}} rrd_args_t *ra_create */
+
+void ra_destroy (rrd_args_t *ra) /* {{{ */
+{
+ if (ra == NULL)
+ return;
+
+ array_destroy (ra->options);
+ array_destroy (ra->data);
+ array_destroy (ra->calc);
+ array_destroy (ra->draw);
+
+ free (ra);
+} /* }}} void ra_destroy */
+
+int ra_argc (rrd_args_t *ra)
+{
+ if (ra == NULL)
+ return (-EINVAL);
+
+ return (array_argc (ra->options)
+ + array_argc (ra->data)
+ + array_argc (ra->calc)
+ + array_argc (ra->draw));
+} /* }}} int ra_argc */
+
+char **ra_argv (rrd_args_t *ra) /* {{{ */
+{
+ size_t argc;
+ char **argv;
+
+ size_t pos;
+ int tmp;
+
+ if (ra == NULL)
+ return (NULL);
+
+ tmp = ra_argc (ra);
+ if (tmp < 0)
+ return (NULL);
+ argc = (size_t) tmp;
+
+ argv = calloc (argc + 1, sizeof (*argv));
+ if (argv == NULL)
+ return (NULL);
+
+ pos = 0;
+
+#define APPEND_FIELD(field) do \
+{ \
+ size_t ary_argc; \
+ char **ary_argv; \
+ \
+ ary_argc = (size_t) array_argc (ra->field); \
+ ary_argv = array_argv (ra->field); \
+ if ((ary_argc > 0) && (ary_argv != NULL)) \
+ { \
+ memcpy (argv + pos, ary_argv, ary_argc * sizeof (*ary_argv)); \
+ pos += ary_argc; \
+ argv[pos] = NULL; \
+ } \
+ free (ary_argv); \
+} while (0)
+
+ APPEND_FIELD (options);
+ APPEND_FIELD (data);
+ APPEND_FIELD (calc);
+ APPEND_FIELD (draw);
+
+#undef APPEND_FIELD
+
+ return (argv);
+} /* }}} char **ra_argv */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/rrd_args.h b/src/rrd_args.h
--- /dev/null
+++ b/src/rrd_args.h
@@ -0,0 +1,24 @@
+#ifndef RRD_ARGS_H
+#define RRD_ARGS_H
+
+#include "utils_array.h"
+
+struct rrd_args_s
+{
+ str_array_t *options;
+ str_array_t *data;
+ str_array_t *calc;
+ str_array_t *draw;
+
+ char last_stack_cdef[64];
+};
+typedef struct rrd_args_s rrd_args_t;
+
+rrd_args_t *ra_create (void);
+void ra_destroy (rrd_args_t *ra);
+
+int ra_argc (rrd_args_t *ra);
+char **ra_argv (rrd_args_t *ra);
+
+#endif /* RRD_ARGS_H */
+/* vim: set sw=2 sts=2 et fdm=marker : */