delta: use regex substring matching
Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
2a4df070c3
commit
4c5e7af32f
|
@ -282,14 +282,17 @@ alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(alpm_pkg_t *pkg)
|
||||||
alpm_delta_t *_alpm_delta_parse(char *line)
|
alpm_delta_t *_alpm_delta_parse(char *line)
|
||||||
{
|
{
|
||||||
alpm_delta_t *delta;
|
alpm_delta_t *delta;
|
||||||
char *tmp = line, *tmp2;
|
char *tmp;
|
||||||
|
const int num_matches = 6;
|
||||||
|
size_t len;
|
||||||
regex_t reg;
|
regex_t reg;
|
||||||
|
regmatch_t pmatch[num_matches];
|
||||||
|
|
||||||
regcomp(®,
|
regcomp(®,
|
||||||
"^[^[:space:]]* [[:xdigit:]]{32} [[:digit:]]*"
|
"^([^[:space:]]*) ([[:xdigit:]]{32}) ([[:digit:]]*)"
|
||||||
" [^[:space:]]* [^[:space:]]*$",
|
" ([^[:space:]]*) ([^[:space:]]*)$",
|
||||||
REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
|
REG_EXTENDED | REG_NEWLINE);
|
||||||
if(regexec(®, line, 0, 0, 0) != 0) {
|
if(regexec(®, line, num_matches, pmatch, 0) != 0) {
|
||||||
/* delta line is invalid, return NULL */
|
/* delta line is invalid, return NULL */
|
||||||
regfree(®);
|
regfree(®);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -298,28 +301,22 @@ alpm_delta_t *_alpm_delta_parse(char *line)
|
||||||
|
|
||||||
CALLOC(delta, 1, sizeof(alpm_delta_t), return NULL);
|
CALLOC(delta, 1, sizeof(alpm_delta_t), return NULL);
|
||||||
|
|
||||||
tmp2 = tmp;
|
/* start at index 1 -- match 0 is the entire match */
|
||||||
tmp = strchr(tmp, ' ');
|
len = pmatch[1].rm_eo - pmatch[1].rm_so;
|
||||||
*(tmp++) = '\0';
|
STRNDUP(tmp, &line[pmatch[1].rm_so], len, return NULL);
|
||||||
STRDUP(delta->delta, tmp2, return NULL);
|
|
||||||
|
|
||||||
tmp2 = tmp;
|
len = pmatch[2].rm_eo - pmatch[2].rm_so;
|
||||||
tmp = strchr(tmp, ' ');
|
STRNDUP(delta->delta_md5, &line[pmatch[2].rm_so], len, return NULL);
|
||||||
*(tmp++) = '\0';
|
|
||||||
STRDUP(delta->delta_md5, tmp2, return NULL);
|
|
||||||
|
|
||||||
tmp2 = tmp;
|
len = pmatch[3].rm_eo - pmatch[3].rm_so;
|
||||||
tmp = strchr(tmp, ' ');
|
STRNDUP(tmp, &line[pmatch[3].rm_so], len, return NULL);
|
||||||
*(tmp++) = '\0';
|
delta->delta_size = _alpm_strtoofft(tmp);
|
||||||
delta->delta_size = _alpm_strtoofft(tmp2);
|
|
||||||
|
|
||||||
tmp2 = tmp;
|
len = pmatch[4].rm_eo - pmatch[4].rm_so;
|
||||||
tmp = strchr(tmp, ' ');
|
STRNDUP(delta->from, &line[pmatch[4].rm_so], len, return NULL);
|
||||||
*(tmp++) = '\0';
|
|
||||||
STRDUP(delta->from, tmp2, return NULL);
|
|
||||||
|
|
||||||
tmp2 = tmp;
|
len = pmatch[5].rm_eo - pmatch[5].rm_so;
|
||||||
STRDUP(delta->to, tmp2, return NULL);
|
STRNDUP(delta->to, &line[pmatch[5].rm_so], len, return NULL);
|
||||||
|
|
||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue