aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2013-01-20 21:07:46 +0000
committerThierry Vignaud <tv@mageia.org>2013-01-20 21:07:46 +0000
commita856d78fd3f7d006398d6a147cb1fcb2cc7cca8d (patch)
tree079531172c0ce17365f86c22b25bc0c15337a8b6
parentc93e7a95b17d143a9e0ef2f8cd55d577cd9bf80f (diff)
downloadperl-URPM-a856d78fd3f7d006398d6a147cb1fcb2cc7cca8d.tar
perl-URPM-a856d78fd3f7d006398d6a147cb1fcb2cc7cca8d.tar.gz
perl-URPM-a856d78fd3f7d006398d6a147cb1fcb2cc7cca8d.tar.bz2
perl-URPM-a856d78fd3f7d006398d6a147cb1fcb2cc7cca8d.tar.xz
perl-URPM-a856d78fd3f7d006398d6a147cb1fcb2cc7cca8d.zip
(parse_line) simplify
-rw-r--r--URPM.xs31
1 files changed, 18 insertions, 13 deletions
diff --git a/URPM.xs b/URPM.xs
index 8f19511..4e90a1b 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -1039,19 +1039,24 @@ parse_line(AV *depslist, HV *provides, HV *obsoletes, URPM__Package pkg, char *b
memset(pkg, 0, sizeof(struct s_Package));
} else if (!strcmp(tag, "filesize"))
pkg->filesize = atoi(data);
- else if (!strcmp(tag, "requires"))
- free(pkg->requires), pkg->requires = memcpy(malloc(data_len), data, data_len);
- else if (!strcmp(tag, "suggests"))
- free(pkg->suggests), pkg->suggests = memcpy(malloc(data_len), data, data_len);
- else if (!strcmp(tag, "obsoletes"))
- free(pkg->obsoletes), pkg->obsoletes = memcpy(malloc(data_len), data, data_len);
- else if (!strcmp(tag, "conflicts"))
- free(pkg->conflicts), pkg->conflicts = memcpy(malloc(data_len), data, data_len);
- else if (!strcmp(tag, "provides"))
- free(pkg->provides), pkg->provides = memcpy(malloc(data_len), data, data_len);
- else if (!strcmp(tag, "summary"))
- free(pkg->summary), pkg->summary = memcpy(malloc(data_len), data, data_len);
-
+ else {
+ char **ptr = NULL;
+ if (!strcmp(tag, "requires"))
+ ptr = &pkg->requires;
+ else if (!strcmp(tag, "suggests"))
+ ptr = &pkg->suggests;
+ else if (!strcmp(tag, "obsoletes"))
+ ptr = &pkg->obsoletes;
+ else if (!strcmp(tag, "conflicts"))
+ ptr = &pkg->conflicts;
+ else if (!strcmp(tag, "provides"))
+ ptr = &pkg->provides;
+ else if (!strcmp(tag, "summary"))
+ ptr = &pkg->summary;
+
+ if (ptr)
+ free(*ptr), *ptr = memcpy(malloc(data_len), data, data_len);
+ }
return 1;
} else {
fprintf(stderr, "bad line <%s>\n", buff);