diff options
author | Guillem Jover <guillem@debian.org> | 2014-06-29 03:14:27 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2014-08-09 22:38:07 +0200 |
commit | 78c18f294df6956eac2bba8af31a26cfc1f24381 (patch) | |
tree | 502978e6e71160999ac30ab500631597b2084770 /lib | |
parent | f7e10180d3ead4f3187ab48557d8aee3bd85ea4a (diff) | |
download | dpkg-78c18f294df6956eac2bba8af31a26cfc1f24381.tar.gz |
libdpkg: Refactor field search functions
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dpkg/dpkg-db.h | 6 | ||||
-rw-r--r-- | lib/dpkg/parsehelp.c | 24 | ||||
-rw-r--r-- | lib/dpkg/pkg-format.c | 28 |
3 files changed, 37 insertions, 21 deletions
diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h index 9c46fa912..2dfe264b7 100644 --- a/lib/dpkg/dpkg-db.h +++ b/lib/dpkg/dpkg-db.h @@ -328,6 +328,12 @@ enum parsedbflags { }; const char *pkg_name_is_illegal(const char *p); + +const struct fieldinfo * +find_field_info(const struct fieldinfo *fields, const char *fieldname); +const struct arbitraryfield * +find_arbfield_info(const struct arbitraryfield *arbs, const char *fieldname); + int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep); void copy_dependency_links(struct pkginfo *pkg, struct dependency **updateme, diff --git a/lib/dpkg/parsehelp.c b/lib/dpkg/parsehelp.c index 662a4738f..e091f6723 100644 --- a/lib/dpkg/parsehelp.c +++ b/lib/dpkg/parsehelp.c @@ -74,6 +74,30 @@ parse_warn(struct parsedb_state *ps, const char *fmt, ...) va_end(args); } +const struct fieldinfo * +find_field_info(const struct fieldinfo *fields, const char *fieldname) +{ + const struct fieldinfo *field; + + for (field = fields; field->name; field++) + if (strcasecmp(field->name, fieldname) == 0) + return field; + + return NULL; +} + +const struct arbitraryfield * +find_arbfield_info(const struct arbitraryfield *arbs, const char *fieldname) +{ + const struct arbitraryfield *arbfield; + + for (arbfield = arbs; arbfield; arbfield = arbfield->next) + if (strcasecmp(arbfield->name, fieldname) == 0) + return arbfield; + + return NULL; +} + const char * pkg_name_is_illegal(const char *p) { diff --git a/lib/dpkg/pkg-format.c b/lib/dpkg/pkg-format.c index 6fb9aef33..8e1c3b0b7 100644 --- a/lib/dpkg/pkg-format.c +++ b/lib/dpkg/pkg-format.c @@ -302,19 +302,6 @@ const struct fieldinfo virtinfos[] = { { NULL }, }; -static const struct fieldinfo * -find_field_info(const struct fieldinfo *fields_head, - const struct pkg_format_node *fmt_node) -{ - const struct fieldinfo *fip; - - for (fip = fields_head; fip->name; fip++) - if (strcasecmp(fmt_node->data, fip->name) == 0) - return fip; - - return NULL; -} - void pkg_format_show(const struct pkg_format_node *head, struct pkginfo *pkg, struct pkgbin *pkgbin) @@ -340,9 +327,9 @@ pkg_format_show(const struct pkg_format_node *head, } else if (node->type == PKG_FORMAT_FIELD) { const struct fieldinfo *fip; - fip = find_field_info(fieldinfos, node); + fip = find_field_info(fieldinfos, node->data); if (fip == NULL) - fip = find_field_info(virtinfos, node); + fip = find_field_info(virtinfos, node->data); if (fip) { fip->wcall(&wb, pkg, pkgbin, 0, fip); @@ -354,12 +341,11 @@ pkg_format_show(const struct pkg_format_node *head, } else { const struct arbitraryfield *afp; - for (afp = pkgbin->arbs; afp; afp = afp->next) - if (strcasecmp(node->data, afp->name) == 0) { - varbuf_printf(&fb, fmt, afp->value); - ok = true; - break; - } + afp = find_arbfield_info(pkgbin->arbs, node->data); + if (afp) { + varbuf_printf(&fb, fmt, afp->value); + ok = true; + } } } |