From f80e1e5fb4b1f04e6d4cd2955d648f97b12837a1 Mon Sep 17 00:00:00 2001 From: Jonathan Perkin Date: Tue, 26 May 2020 13:23:41 +0100 Subject: [PATCH] Rename map_pkg_to_dep() to find_pkg_match(). The latter is a bit more descriptive and easier to follow. Update the function documentation while here, and convert a DEBUG printf to a TRACE(). --- depends.c | 4 ++-- impact.c | 2 +- pkg_str.c | 17 +++++++++-------- pkgin.h | 2 +- sqlite_callbacks.c | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/depends.c b/depends.c index 2417c34..e341b57 100644 --- a/depends.c +++ b/depends.c @@ -165,7 +165,7 @@ show_direct_depends(const char *pkgarg) printf(MSG_DIRECT_DEPS_FOR, pkgname); SLIST_FOREACH(pdp, deptreehead, next) { if (package_version && - (rpkg = map_pkg_to_dep(&r_plisthead, pdp->depend)) + (rpkg = find_pkg_match(&r_plisthead, pdp->depend)) != NULL) printf("\t%s\n", rpkg->full); else @@ -208,7 +208,7 @@ show_full_dep_tree(const char *pkgarg, const char *depquery, const char *msg) SLIST_FOREACH(pdp, deptreehead, next) { if (package_version && - (rpkg = map_pkg_to_dep(plisthead, pdp->depend)) != NULL) + (rpkg = find_pkg_match(plisthead, pdp->depend)) != NULL) printf("\t%s\n", rpkg->full); else printf("\t%s\n", pdp->depend); diff --git a/impact.c b/impact.c index 803d63c..da5aad1 100644 --- a/impact.c +++ b/impact.c @@ -194,7 +194,7 @@ deps_impact(Plisthead *impacthead, Pkglist *pdp) return 1; /* record corresponding package on remote list*/ - if ((rpkg = map_pkg_to_dep(&r_plisthead, pdp->depend)) == NULL) + if ((rpkg = find_pkg_match(&r_plisthead, pdp->depend)) == NULL) return 1; /* no corresponding package in list */ XSTRCPY(remotepkg, rpkg->full); diff --git a/pkg_str.c b/pkg_str.c index 8883192..0e53219 100644 --- a/pkg_str.c +++ b/pkg_str.c @@ -133,19 +133,20 @@ unique_pkg(const char *pkgname, const char *dest) return u_pkg; } -/* return a pkgname corresponding to a dependency */ +/* + * Return first matching SLIST entry in package list, or NULL if no match. + */ Pkglist * -map_pkg_to_dep(Plisthead *plisthead, char *depname) +find_pkg_match(Plisthead *plisthead, char *match) { Pkglist *plist; - SLIST_FOREACH(plist, plisthead, next) - if (pkg_match(depname, plist->full)) { -#ifdef DEBUG - printf("match ! %s -> %s\n", depname, plist->full); -#endif + SLIST_FOREACH(plist, plisthead, next) { + if (pkg_match(match, plist->full)) { + TRACE("Matched %s with %s\n", match, plist->full); return plist; } + } return NULL; } @@ -332,7 +333,7 @@ glob_to_pkgarg(char **globpkg, int *rc) if (strpbrk(globpkg[i], GLOBCHARS) == NULL) pkgargs[count] = xstrdup(globpkg[i]); else { - if ((plist = map_pkg_to_dep(&r_plisthead, + if ((plist = find_pkg_match(&r_plisthead, globpkg[i])) == NULL) { fprintf(stderr, MSG_PKG_NOT_AVAIL, globpkg[i]); count--; diff --git a/pkgin.h b/pkgin.h index d147640..b9ed7c4 100644 --- a/pkgin.h +++ b/pkgin.h @@ -263,7 +263,7 @@ char *read_repos(void); /* pkg_str.c */ int find_preferred_pkg(const char *, char **); char *unique_pkg(const char *, const char *); -Pkglist *map_pkg_to_dep(Plisthead *, char *); +Pkglist *find_pkg_match(Plisthead *, char *); uint8_t non_trivial_glob(char *); char *get_pkgname_from_depend(char *); int exact_pkgfmt(const char *); diff --git a/sqlite_callbacks.c b/sqlite_callbacks.c index f9abc45..f579036 100644 --- a/sqlite_callbacks.c +++ b/sqlite_callbacks.c @@ -124,7 +124,7 @@ pdb_rec_depends(void *param, int argc, char **argv, char **colname) plisthead = &r_plisthead; /* map corresponding pkgname */ - if ((pkg_map = map_pkg_to_dep(plisthead, deptree->depend)) != NULL) + if ((pkg_map = find_pkg_match(plisthead, deptree->depend)) != NULL) deptree->name = xstrdup(pkg_map->name); else /* some dependencies just don't match anything */