xbps-query/search.c: simplify regex matching code.

This commit is contained in:
Juan RP 2014-05-26 08:36:33 +02:00
parent 1f0605810c
commit 0fbab93383

View File

@ -121,14 +121,14 @@ search_array_cb(struct xbps_handle *xhp _unused,
if (sd->regex) { if (sd->regex) {
regex_t regex; regex_t regex;
regmatch_t regmatches[1];
regcomp(&regex, sd->patterns[x], REG_EXTENDED); regcomp(&regex, sd->patterns[x], REG_EXTENDED|REG_NOSUB);
if ((regexec(&regex, pkgver, 1, regmatches, REG_EXTENDED) == 0) || if ((regexec(&regex, pkgver, 0, 0, 0) == 0) ||
(regexec(&regex, desc, 1, regmatches, REG_EXTENDED) == 0)) { (regexec(&regex, desc, 0, 0, 0) == 0)) {
xbps_array_add_cstring_nocopy(sd->results, pkgver); xbps_array_add_cstring_nocopy(sd->results, pkgver);
xbps_array_add_cstring_nocopy(sd->results, desc); xbps_array_add_cstring_nocopy(sd->results, desc);
} }
regfree(&regex);
} else { } else {
if ((xbps_pkgpattern_match(pkgver, sd->patterns[x])) || if ((xbps_pkgpattern_match(pkgver, sd->patterns[x])) ||
(strcasestr(pkgver, sd->patterns[x])) || (strcasestr(pkgver, sd->patterns[x])) ||
@ -149,13 +149,13 @@ search_array_cb(struct xbps_handle *xhp _unused,
for (x = 0; x < sd->npatterns; x++) { for (x = 0; x < sd->npatterns; x++) {
if (sd->regex) { if (sd->regex) {
regex_t regex; regex_t regex;
regmatch_t regmatches[1];
regcomp(&regex, sd->patterns[x], REG_EXTENDED); regcomp(&regex, sd->patterns[x], REG_EXTENDED|REG_NOSUB);
if (regexec(&regex, str, 1, regmatches, 0) == 0) { if (regexec(&regex, str, 0, 0, 0) == 0) {
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
printf("%s: %s (%s)\n", pkgver, str, sd->repourl); printf("%s: %s (%s)\n", pkgver, str, sd->repourl);
} }
regfree(&regex);
} else { } else {
if ((strcasestr(str, sd->patterns[x])) || if ((strcasestr(str, sd->patterns[x])) ||
(fnmatch(sd->patterns[x], str, FNM_PERIOD)) == 0) { (fnmatch(sd->patterns[x], str, FNM_PERIOD)) == 0) {
@ -175,13 +175,13 @@ search_array_cb(struct xbps_handle *xhp _unused,
for (x = 0; x < sd->npatterns; x++) { for (x = 0; x < sd->npatterns; x++) {
if (sd->regex) { if (sd->regex) {
regex_t regex; regex_t regex;
regmatch_t regmatches[1];
regcomp(&regex, sd->patterns[x], REG_EXTENDED); regcomp(&regex, sd->patterns[x], REG_EXTENDED|REG_NOSUB);
if (regexec(&regex, str, 1, regmatches, 0) == 0) { if (regexec(&regex, str, 0, 0, 0) == 0) {
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
printf("%s: %s (%s)\n", pkgver, str, sd->repourl); printf("%s: %s (%s)\n", pkgver, str, sd->repourl);
} }
regfree(&regex);
} else { } else {
if (strcasestr(str, sd->patterns[x])) { if (strcasestr(str, sd->patterns[x])) {
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);