summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libopkg/Makefile.am1
-rw-r--r--libopkg/parse_util.c88
-rw-r--r--libopkg/parse_util.h25
-rw-r--r--libopkg/pkg_parse.c73
4 files changed, 122 insertions, 65 deletions
diff --git a/libopkg/Makefile.am b/libopkg/Makefile.am
index 6be44ad..5ca55a0 100644
--- a/libopkg/Makefile.am
+++ b/libopkg/Makefile.am
@@ -26,6 +26,7 @@ opkg_list_sources = conffile.c conffile.h conffile_list.c conffile_list.h \
str_list.c str_list.h void_list.c void_list.h \
active_list.c active_list.h list.h
opkg_util_sources = file_util.c file_util.h opkg_message.h opkg_message.c md5.c md5.h \
+ parse_util.c parse_util.h \
sprintf_alloc.c sprintf_alloc.h \
xregex.c xregex.h xsystem.c xsystem.h
if HAVE_PATHFINDER
diff --git a/libopkg/parse_util.c b/libopkg/parse_util.c
new file mode 100644
index 0000000..e01b124
--- /dev/null
+++ b/libopkg/parse_util.c
@@ -0,0 +1,88 @@
+/* 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;
+}
diff --git a/libopkg/parse_util.h b/libopkg/parse_util.h
new file mode 100644
index 0000000..e4e2abe
--- /dev/null
+++ b/libopkg/parse_util.h
@@ -0,0 +1,25 @@
+/* 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
diff --git a/libopkg/pkg_parse.c b/libopkg/pkg_parse.c
index ba64269..e0d7fce 100644
--- a/libopkg/pkg_parse.c
+++ b/libopkg/pkg_parse.c
@@ -26,64 +26,7 @@
#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)
@@ -194,7 +137,7 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask)
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':
@@ -204,7 +147,7 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask)
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':
@@ -250,16 +193,16 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask)
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;
@@ -279,7 +222,7 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask)
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':