--- /dev/null
+#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 : */
--- /dev/null
+#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 : */