From edf03b155ba419b00dde585b3d35969621a024df Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Fri, 14 Jun 2013 20:26:48 +0300 Subject: audit, index, search, upgrade: use foreach_array_item --- src/audit.c | 7 +++---- src/index.c | 7 ++++--- src/search.c | 12 +++++------- src/upgrade.c | 6 +++--- 4 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/audit.c b/src/audit.c index d28883f..3e08930 100644 --- a/src/audit.c +++ b/src/audit.c @@ -195,12 +195,11 @@ recurse_check: atctx->pathlen--; } else { struct apk_db_file *dbf; - struct apk_protected_path_array *ppaths = dir->protected_paths; - int i, protected = dir->protected, symlinks_only = dir->symlinks_only; + struct apk_protected_path *ppath; + int protected = dir->protected, symlinks_only = dir->symlinks_only; /* inherit file's protection mask */ - for (i = 0; i < ppaths->num; i++) { - struct apk_protected_path *ppath = &ppaths->item[i]; + foreach_array_item(ppath, dir->protected_paths) { char *slash = strchr(ppath->relative_pattern, '/'); if (slash == NULL) { if (fnmatch(ppath->relative_pattern, name, FNM_PATHNAME) != 0) diff --git a/src/index.c b/src/index.c index 26cbe72..2e93209 100644 --- a/src/index.c +++ b/src/index.c @@ -92,7 +92,7 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv) struct counts counts = {0}; struct apk_ostream *os; struct apk_file_info fi; - int total, r, i, j, found, newpkgs = 0, errors = 0; + int total, r, i, found, newpkgs = 0, errors = 0; struct index_ctx *ictx = (struct index_ctx *) ctx; struct apk_package *pkg; @@ -119,6 +119,7 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv) found = FALSE; do { + struct apk_provider *p; struct apk_name *name; char *fname, *fend; apk_blob_t bname, bver; @@ -145,8 +146,8 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv) if (name == NULL) break; - for (j = 0; j < name->providers->num; j++) { - pkg = name->providers->item[j].pkg; + foreach_array_item(p, name->providers) { + pkg = p->pkg; if (pkg->name != name) continue; if (apk_blob_compare(bver, *pkg->version) != 0) diff --git a/src/search.c b/src/search.c index 9ef61a1..2f39f38 100644 --- a/src/search.c +++ b/src/search.c @@ -119,16 +119,14 @@ static void print_result_pkg(struct search_ctx *ctx, struct apk_package *pkg) static void print_result(struct search_ctx *ctx, struct apk_name *name) { - int i; + struct apk_provider *p; + struct apk_package *pkg = NULL; + apk_blob_t *version = NULL; if (ctx->show_all) { - for (i = 0; i < name->providers->num; i++) - print_result_pkg(ctx, name->providers->item[i].pkg); + foreach_array_item(p, name->providers) + print_result_pkg(ctx, p->pkg); } else { - struct apk_package *pkg = NULL; - struct apk_provider *p; - apk_blob_t *version = NULL; - foreach_array_item(p, name->providers) { if (version == NULL || apk_version_compare_blob(*p->version, *version) == APK_VERSION_GREATER) diff --git a/src/upgrade.c b/src/upgrade.c index 8c8284d..335afa6 100644 --- a/src/upgrade.c +++ b/src/upgrade.c @@ -89,8 +89,9 @@ static int upgrade_main(void *ctx, struct apk_database *db, int argc, char **arg { struct upgrade_ctx *uctx = (struct upgrade_ctx *) ctx; unsigned short solver_flags; + struct apk_dependency *dep; struct apk_dependency_array *world = NULL; - int i, r; + int r; if (apk_db_check_world(db, db->world) != 0) { apk_error("Not continuing with upgrade due to missing repository tags. Use --force to override."); @@ -106,8 +107,7 @@ static int upgrade_main(void *ctx, struct apk_database *db, int argc, char **arg if (solver_flags & APK_SOLVERF_AVAILABLE) { apk_dependency_array_copy(&world, db->world); - for (i = 0; i < world->num; i++) { - struct apk_dependency *dep = &world->item[i]; + foreach_array_item(dep, world) { if (dep->result_mask == APK_DEPMASK_CHECKSUM) { dep->result_mask = APK_DEPMASK_ANY; dep->version = apk_blob_atomize(APK_BLOB_NULL); -- cgit v1.2.3-60-g2f50