+/**
+ * Free an array of words created by create_argv().
+ *
+ * \param argv A pointer previously obtained by \ref create_argv().
+ */
+void free_argv(char **argv)
+{
+ int i;
+
+ for (i = 0; argv[i]; i++)
+ free(argv[i]);
+ free(argv);
+}
+
+/**
+ * Split a line into words which are separated by whitespace.
+ *
+ * In contrast to gengetopt's string parser, double quotes, backslash-escaped
+ * characters and special characters like \p \\n are honored. The result
+ * contains pointers to copies of the words contained in \line and has to be
+ * freed by using \ref free_argv().
+ *
+ * \param line The line to be split.
+ * \param result The array of words is returned here.
+ *
+ * \return Number of words in \a line, negative on errors.
+ */
+int create_argv(const char *line, char ***result)
+{
+ char *word, **argv = adu_malloc(2 * sizeof(char *));
+ const char *p;
+ int ret, num_words;
+
+ argv[0] = adu_strdup(line);
+ for (p = line, num_words = 1; ; p += ret, num_words++) {
+ ret = get_next_word(p, &word);
+ if (ret < 0)
+ goto err;
+ if (!ret)
+ break;
+ argv = adu_realloc(argv, (num_words + 2) * sizeof(char*));
+ argv[num_words] = word;
+ }
+ argv[num_words] = NULL;
+ *result = argv;
+ return num_words;
+err:
+ while (num_words > 0)
+ free(argv[--num_words]);
+ free(argv);
+ return ret;
+}