--- /dev/null
+/* parse_util.c - the opkg package management system
+
+ Copyright (C) 2009 Ubiq Technologies <graham.gower@gmail.com>
+
+ Steven M. Ayer
+ Copyright (C) 2002 Compaq Computer Corporation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+*/
+
+#include <ctype.h>
+
+#include "opkg_utils.h"
+#include "libbb/libbb.h"
+
+#include "parse_util.h"
+
+int
+is_field(const char *type, const char *line)
+{
+ if (!strncmp(line, type, strlen(type)))
+ return 1;
+ return 0;
+}
+
+char *
+parse_simple(const char *type, const char *line)
+{
+ return trim_xstrdup(line + strlen(type) + 1);
+}
+
+/*
+ * Parse a comma separated string into an array.
+ */
+char **
+parse_list(const char *raw, unsigned int *count, const char sep, int skip_field)
+{
+ char **depends = NULL;
+ const char *start, *end;
+ int line_count = 0;
+
+ /* skip past the "Field:" marker */
+ if (!skip_field) {
+ while (*raw && *raw != ':')
+ raw++;
+ raw++;
+ }
+
+ if (line_is_blank(raw)) {
+ *count = line_count;
+ return NULL;
+ }
+
+ while (*raw) {
+ depends = xrealloc(depends, sizeof(char *) * (line_count + 1));
+
+ while (isspace(*raw))
+ raw++;
+
+ start = raw;
+ while (*raw != sep && *raw)
+ raw++;
+ end = raw;
+
+ while (end > start && isspace(*end))
+ end--;
+
+ if (sep == ' ')
+ end++;
+
+ depends[line_count] = xstrndup(start, end-start);
+
+ line_count++;
+ if (*raw == sep)
+ raw++;
+ }
+
+ *count = line_count;
+ return depends;
+}
--- /dev/null
+/* parse_util.h - the opkg package management system
+
+ Steven M. Ayer
+
+ Copyright (C) 2002 Compaq Computer Corporation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+*/
+
+#ifndef PARSE_UTIL_H
+#define PARSE_UTIL_H
+
+int is_field(const char *type, const char *line);
+char *parse_simple(const char *type, const char *line);
+char **parse_list(const char *raw, unsigned int *count, const char sep, int skip_field);
+
+#endif
#include "pkg_parse.h"
#include "libbb/libbb.h"
-static int
-is_field(const char *type, const char *line)
-{
- if (!strncmp(line, type, strlen(type)))
- return 1;
- return 0;
-}
-
-static char *
-parse_simple(const char *type, const char *line)
-{
- return trim_xstrdup(line + strlen(type) + 1);
-}
-
-/*
- * Parse a comma separated string into an array.
- */
-static char **
-parse_comma_separated(const char *raw, unsigned int *count)
-{
- char **depends = NULL;
- const char *start, *end;
- int line_count = 0;
-
- /* skip past the "Field:" marker */
- while (*raw && *raw != ':')
- raw++;
- raw++;
-
- if (line_is_blank(raw)) {
- *count = line_count;
- return NULL;
- }
-
- while (*raw) {
- depends = xrealloc(depends, sizeof(char *) * (line_count + 1));
-
- while (isspace(*raw))
- raw++;
-
- start = raw;
- while (*raw != ',' && *raw)
- raw++;
- end = raw;
-
- while (end > start && isspace(*end))
- end--;
-
- depends[line_count] = xstrndup(start, end-start);
-
- line_count++;
- if (*raw == ',')
- raw++;
- }
-
- *count = line_count;
- return depends;
-}
+#include "parse_util.h"
static void
parse_status(pkg_t *pkg, const char *sstr)
goto dont_reset_flags;
}
else if ((mask & PFM_CONFLICTS) && is_field("Conflicts", line))
- pkg->conflicts_str = parse_comma_separated(line, &pkg->conflicts_count);
+ pkg->conflicts_str = parse_list(line, &pkg->conflicts_count, ',', 0);
break;
case 'D':
reading_description = 1;
goto dont_reset_flags;
} else if ((mask & PFM_DEPENDS) && is_field("Depends", line))
- pkg->depends_str = parse_comma_separated(line, &pkg->depends_count);
+ pkg->depends_str = parse_list(line, &pkg->depends_count, ',', 0);
break;
case 'E':
else if ((mask & PFM_PRIORITY) && is_field("Priority", line))
pkg->priority = parse_simple("Priority", line);
else if ((mask & PFM_PROVIDES) && is_field("Provides", line))
- pkg->provides_str = parse_comma_separated(line, &pkg->provides_count);
+ pkg->provides_str = parse_list(line, &pkg->provides_count, ',', 0);
else if ((mask & PFM_PRE_DEPENDS) && is_field("Pre-Depends", line))
- pkg->pre_depends_str = parse_comma_separated(line, &pkg->pre_depends_count);
+ pkg->pre_depends_str = parse_list(line, &pkg->pre_depends_count, ',', 0);
break;
case 'R':
if ((mask & PFM_RECOMMENDS) && is_field("Recommends", line))
- pkg->recommends_str = parse_comma_separated(line, &pkg->recommends_count);
+ pkg->recommends_str = parse_list(line, &pkg->recommends_count, ',', 0);
else if ((mask & PFM_REPLACES) && is_field("Replaces", line))
- pkg->replaces_str = parse_comma_separated(line, &pkg->replaces_count);
+ pkg->replaces_str = parse_list(line, &pkg->replaces_count, ',', 0);
break;
else if ((mask & PFM_STATUS) && is_field("Status", line))
parse_status(pkg, line);
else if ((mask & PFM_SUGGESTS) && is_field("Suggests", line))
- pkg->suggests_str = parse_comma_separated(line, &pkg->suggests_count);
+ pkg->suggests_str = parse_list(line, &pkg->suggests_count, ',', 0);
break;
case 'T':