2 * collectd - src/utils_parse_option.c
3 * Copyright (C) 2008 Florian Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
25 #include "utils_parse_option.h"
30 * Parses an ``option'' as used with the unixsock and exec commands. An
31 * option is of the form:
33 * name1="value with \"quotes\""
34 * name2="value \\ backslash"
35 * However, if the value does *not* contain a space character, you can skip
38 int parse_option (char **ret_buffer, char **ret_key, char **ret_value)
46 /* Eat up leading spaces */
48 while (isspace ((int) *key))
53 /* Look for the equal sign */
55 while (isalnum ((int) *value))
57 if ((*value != '=') || (value == key))
61 /* Empty values must be written as "" */
62 if (isspace ((int) *value) || (*value == 0))
76 while ((*buffer != '"') && (*buffer != 0))
78 /* Un-escape backslashes */
82 /* Catch a backslash at the end of buffer */
90 /* No quote sign has been found */
96 /* Check for trailing spaces. */
97 if ((*buffer != 0) && !isspace ((int) *buffer))
100 else /* an unquoted value */
103 while ((*buffer != 0) && !isspace ((int) *buffer))
112 /* Eat up trailing spaces */
113 while (isspace ((int) *buffer))
116 *ret_buffer = buffer;
121 } /* int parse_option */
123 /* vim: set sw=2 ts=8 tw=78 et : */