aboutsummaryrefslogtreecommitdiffstats
path: root/URPM.xs
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2013-02-03 22:16:36 +0000
committerThierry Vignaud <tv@mageia.org>2013-02-03 22:16:36 +0000
commit4afd4c9a29d89c8af4b6d3eb8aeefc9f895ea5f9 (patch)
tree7fbd39277ebee2c83236d6e64426385013888925 /URPM.xs
parentb63123ae911969db1ca64ef804803936b3bbf62d (diff)
downloadperl-URPM-4afd4c9a29d89c8af4b6d3eb8aeefc9f895ea5f9.tar
perl-URPM-4afd4c9a29d89c8af4b6d3eb8aeefc9f895ea5f9.tar.gz
perl-URPM-4afd4c9a29d89c8af4b6d3eb8aeefc9f895ea5f9.tar.bz2
perl-URPM-4afd4c9a29d89c8af4b6d3eb8aeefc9f895ea5f9.tar.xz
perl-URPM-4afd4c9a29d89c8af4b6d3eb8aeefc9f895ea5f9.zip
(mask_from_string) factorize code
Diffstat (limited to 'URPM.xs')
-rw-r--r--URPM.xs28
1 files 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;