From 4afd4c9a29d89c8af4b6d3eb8aeefc9f895ea5f9 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Sun, 3 Feb 2013 22:16:36 +0000 Subject: (mask_from_string) factorize code --- URPM.xs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/URPM.xs b/URPM.xs index 3d43a34..657a51a 100644 --- a/URPM.xs +++ b/URPM.xs @@ -1358,6 +1358,18 @@ rpmtag_from_string(char *tag) else croak("unknown tag [%s]", tag); } +static unsigned mask_from_string(char *name) { + unsigned mask; + if (!strcmp(name, "skip")) mask = FLAG_SKIP; + else if (!strcmp(name, "disable_obsolete")) mask = FLAG_DISABLE_OBSOLETE; + else if (!strcmp(name, "installed")) mask = FLAG_INSTALLED; + else if (!strcmp(name, "requested")) mask = FLAG_REQUESTED; + else if (!strcmp(name, "required")) mask = FLAG_REQUIRED; + else if (!strcmp(name, "upgrade")) mask = FLAG_UPGRADE; + else croak("unknown flag: %s", name); + return mask; +} + static int compare_evrs(int lepoch, char*lversion, char*lrelease, int repoch, char*rversion, char*rrelease) { int compare; compare = lepoch - repoch; @@ -2155,13 +2167,7 @@ Pkg_flag(pkg, name) PREINIT: unsigned mask; CODE: - if (!strcmp(name, "skip")) mask = FLAG_SKIP; - else if (!strcmp(name, "disable_obsolete")) mask = FLAG_DISABLE_OBSOLETE; - else if (!strcmp(name, "installed")) mask = FLAG_INSTALLED; - else if (!strcmp(name, "requested")) mask = FLAG_REQUESTED; - else if (!strcmp(name, "required")) mask = FLAG_REQUIRED; - else if (!strcmp(name, "upgrade")) mask = FLAG_UPGRADE; - else croak("unknown flag: %s", name); + mask = mask_from_string(name); RETVAL = pkg->flag & mask; OUTPUT: RETVAL @@ -2174,13 +2180,7 @@ Pkg_set_flag(pkg, name, value=1) PREINIT: unsigned mask; CODE: - if (!strcmp(name, "skip")) mask = FLAG_SKIP; - else if (!strcmp(name, "disable_obsolete")) mask = FLAG_DISABLE_OBSOLETE; - else if (!strcmp(name, "installed")) mask = FLAG_INSTALLED; - else if (!strcmp(name, "requested")) mask = FLAG_REQUESTED; - else if (!strcmp(name, "required")) mask = FLAG_REQUIRED; - else if (!strcmp(name, "upgrade")) mask = FLAG_UPGRADE; - else croak("unknown flag: %s", name); + mask = mask_from_string(name); RETVAL = pkg->flag & mask; if (value) pkg->flag |= mask; else pkg->flag &= ~mask; -- cgit v1.2.1