summaryrefslogtreecommitdiff
path: root/src/package.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-13 09:32:04 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-13 09:32:04 +0200
commitca364e34e2f8bf60fa413410ac7b82c64e1758b7 (patch)
tree9ae0dbea7b261215a689d7828ff4925249856c91 /src/package.c
parentd16b42438599675da2e86201235bdaf4d3f59cca (diff)
downloadapk-tools-ca364e34e2f8bf60fa413410ac7b82c64e1758b7.tar.gz
apk-tools-ca364e34e2f8bf60fa413410ac7b82c64e1758b7.tar.bz2
apk-tools-ca364e34e2f8bf60fa413410ac7b82c64e1758b7.tar.xz
apk-tools-ca364e34e2f8bf60fa413410ac7b82c64e1758b7.zip
pkg: use generic blob functions to parse dependencies
Diffstat (limited to 'src/package.c')
-rw-r--r--src/package.c74
1 files changed, 36 insertions, 38 deletions
diff --git a/src/package.c b/src/package.c
index 6978ede..40fc871 100644
--- a/src/package.c
+++ b/src/package.c
@@ -72,32 +72,6 @@ static apk_blob_t trim(apk_blob_t str)
return str;
}
-static void parse_depend(struct apk_database *db,
- struct apk_dependency_array **depends,
- apk_blob_t blob)
-{
- struct apk_dependency *dep;
- struct apk_name *name;
-
- while (blob.len && blob.ptr[0] == ' ')
- blob.ptr++, blob.len--;
- while (blob.len && (blob.ptr[blob.len-1] == ' ' ||
- blob.ptr[blob.len-1] == 0))
- blob.len--;
-
- if (blob.len == 0)
- return;
-
- name = apk_db_get_name(db, blob);
- dep = apk_dependency_array_add(depends);
- *dep = (struct apk_dependency){
- .prefer_upgrade = 0,
- .version_mask = 0,
- .name = name,
- .version = NULL,
- };
-}
-
int apk_deps_add(struct apk_dependency_array **depends,
struct apk_dependency *dep)
{
@@ -115,24 +89,48 @@ int apk_deps_add(struct apk_dependency_array **depends,
return 0;
}
+struct parse_depend_ctx {
+ struct apk_database *db;
+ struct apk_dependency_array **depends;
+};
+
+static int parse_depend(void *ctx, apk_blob_t blob)
+{
+ struct parse_depend_ctx *pctx = (struct parse_depend_ctx *) ctx;
+ struct apk_dependency *dep;
+ struct apk_name *name;
+
+ if (blob.len == 0)
+ return 0;
+
+ name = apk_db_get_name(pctx->db, blob);
+ if (name == NULL)
+ return -1;
+
+ dep = apk_dependency_array_add(pctx->depends);
+ if (dep == NULL)
+ return -1;
+
+ *dep = (struct apk_dependency){
+ .prefer_upgrade = 0,
+ .version_mask = 0,
+ .name = name,
+ .version = NULL,
+ };
+
+ return 0;
+}
+
void apk_deps_parse(struct apk_database *db,
struct apk_dependency_array **depends,
apk_blob_t blob)
{
- char *start;
- int i;
+ struct parse_depend_ctx ctx = { db, depends };
- start = blob.ptr;
- for (i = 0; i < blob.len && blob.ptr[i] != '\n'; i++) {
- if (blob.ptr[i] != ' ')
- continue;
+ if (blob.len > 1 && blob.ptr[blob.len-1] == '\n')
+ blob.len--;
- parse_depend(db, depends,
- APK_BLOB_PTR_PTR(start, &blob.ptr[i-1]));
- start = &blob.ptr[i];
- }
- parse_depend(db, depends,
- APK_BLOB_PTR_PTR(start, &blob.ptr[i-1]));
+ apk_blob_for_each_segment(blob, " ", parse_depend, &ctx);
}
int apk_deps_format(char *buf, int size,