2 * collection4 - rrd_args.c
3 * Copyright (C) 2010 Florian octo Forster
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 * Florian octo Forster <ff at octo.it>
30 rrd_args_t *ra_create (void) /* {{{ */
34 ra = malloc (sizeof (*ra));
37 memset (ra, 0, sizeof (*ra));
39 ra->options = array_create ();
40 ra->data = array_create ();
41 ra->calc = array_create ();
42 ra->areas = array_create ();
43 ra->lines = array_create ();
45 if ((ra->options == NULL)
48 || (ra->areas == NULL)
49 || (ra->lines == NULL))
56 } /* }}} rrd_args_t *ra_create */
58 void ra_destroy (rrd_args_t *ra) /* {{{ */
63 array_destroy (ra->options);
64 array_destroy (ra->data);
65 array_destroy (ra->calc);
66 array_destroy (ra->areas);
67 array_destroy (ra->lines);
70 } /* }}} void ra_destroy */
72 int ra_argc (rrd_args_t *ra)
77 return (array_argc (ra->options)
78 + array_argc (ra->data)
79 + array_argc (ra->calc)
80 + array_argc (ra->areas)
81 + array_argc (ra->lines));
82 } /* }}} int ra_argc */
84 char **ra_argv (rrd_args_t *ra) /* {{{ */
100 argv = calloc (argc + 1, sizeof (*argv));
107 #define APPEND_FIELD(field) do \
112 ary_argc = (size_t) array_argc (ra->field); \
113 ary_argv = array_argv (ra->field); \
114 if ((ary_argc > 0) && (ary_argv != NULL)) \
116 memcpy (argv + pos, ary_argv, ary_argc * sizeof (*ary_argv)); \
122 APPEND_FIELD (options);
125 APPEND_FIELD (areas);
126 APPEND_FIELD (lines);
131 } /* }}} char **ra_argv */
133 void ra_argv_free (char **argv) /* {{{ */
135 /* The pointers contained in the "argv" come from "array_argv". We don't need
136 * to free them. We only need to free what we actually alloced directly in
139 } /* }}} void ra_argv_free */
141 /* vim: set sw=2 sts=2 et fdm=marker : */