diff options
author | Thierry Vignaud <tv@mageia.org> | 2013-01-20 21:07:46 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2013-01-20 21:07:46 +0000 |
commit | a856d78fd3f7d006398d6a147cb1fcb2cc7cca8d (patch) | |
tree | 079531172c0ce17365f86c22b25bc0c15337a8b6 | |
parent | c93e7a95b17d143a9e0ef2f8cd55d577cd9bf80f (diff) | |
download | perl-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.xs | 31 |
1 files changed, 18 insertions, 13 deletions
@@ -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); |