Commit ca364e34 authored by Timo Teräs's avatar Timo Teräs

pkg: use generic blob functions to parse dependencies

parent d16b4243
...@@ -72,32 +72,6 @@ static apk_blob_t trim(apk_blob_t str) ...@@ -72,32 +72,6 @@ static apk_blob_t trim(apk_blob_t str)
return 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, int apk_deps_add(struct apk_dependency_array **depends,
struct apk_dependency *dep) struct apk_dependency *dep)
{ {
...@@ -115,24 +89,48 @@ int apk_deps_add(struct apk_dependency_array **depends, ...@@ -115,24 +89,48 @@ int apk_deps_add(struct apk_dependency_array **depends,
return 0; 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, void apk_deps_parse(struct apk_database *db,
struct apk_dependency_array **depends, struct apk_dependency_array **depends,
apk_blob_t blob) apk_blob_t blob)
{ {
char *start; struct parse_depend_ctx ctx = { db, depends };
int i;
start = blob.ptr; if (blob.len > 1 && blob.ptr[blob.len-1] == '\n')
for (i = 0; i < blob.len && blob.ptr[i] != '\n'; i++) { blob.len--;
if (blob.ptr[i] != ' ')
continue;
parse_depend(db, depends, apk_blob_for_each_segment(blob, " ", parse_depend, &ctx);
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]));
} }
int apk_deps_format(char *buf, int size, int apk_deps_format(char *buf, int size,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment