be_package: be more explicit parsing key/value pairs

This eliminates the need for strtrim() usage completely, instead relying
on the fact that the only allowed delimiter between key and value is the
" = " string.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-12-23 14:32:01 -06:00
parent e28f321a48
commit a7cb150931

View file

@ -171,18 +171,21 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
size_t len = _alpm_strip_newline(buf.line); size_t len = _alpm_strip_newline(buf.line);
linenum++; linenum++;
if(len == 0 || buf.line[0] == '#') { key = buf.line;
if(len == 0 || key[0] == '#') {
continue; continue;
} }
ptr = buf.line; /* line is always in this format: "key = value"
key = strsep(&ptr, "="); * we can be sure the " = " exists, so look for that */
if(key == NULL || ptr == NULL) { ptr = memchr(key, ' ', len);
_alpm_log(handle, ALPM_LOG_DEBUG, "%s: syntax error in description file line %d\n", if(!ptr || ptr - key + 2 > len || memcmp(ptr, " = ", 3) != 0) {
_alpm_log(handle, ALPM_LOG_DEBUG,
"%s: syntax error in description file line %d\n",
newpkg->name ? newpkg->name : "error", linenum); newpkg->name ? newpkg->name : "error", linenum);
} else { } else {
key = _alpm_strtrim(key); /* NULL the end of the key portion, move ptr to start of value */
while(*ptr == ' ') ptr++; *ptr = '\0';
ptr = _alpm_strtrim(ptr); ptr += 3;
if(strcmp(key, "pkgname") == 0) { if(strcmp(key, "pkgname") == 0) {
STRDUP(newpkg->name, ptr, return -1); STRDUP(newpkg->name, ptr, return -1);
newpkg->name_hash = _alpm_hash_sdbm(newpkg->name); newpkg->name_hash = _alpm_hash_sdbm(newpkg->name);