xbps-query/search.c: simplify regex matching code.
This commit is contained in:
parent
1f0605810c
commit
0fbab93383
@ -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(®ex, sd->patterns[x], REG_EXTENDED);
|
regcomp(®ex, sd->patterns[x], REG_EXTENDED|REG_NOSUB);
|
||||||
if ((regexec(®ex, pkgver, 1, regmatches, REG_EXTENDED) == 0) ||
|
if ((regexec(®ex, pkgver, 0, 0, 0) == 0) ||
|
||||||
(regexec(®ex, desc, 1, regmatches, REG_EXTENDED) == 0)) {
|
(regexec(®ex, 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(®ex);
|
||||||
} 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(®ex, sd->patterns[x], REG_EXTENDED);
|
regcomp(®ex, sd->patterns[x], REG_EXTENDED|REG_NOSUB);
|
||||||
if (regexec(®ex, str, 1, regmatches, 0) == 0) {
|
if (regexec(®ex, 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(®ex);
|
||||||
} 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(®ex, sd->patterns[x], REG_EXTENDED);
|
regcomp(®ex, sd->patterns[x], REG_EXTENDED|REG_NOSUB);
|
||||||
if (regexec(®ex, str, 1, regmatches, 0) == 0) {
|
if (regexec(®ex, 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(®ex);
|
||||||
} 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);
|
||||||
|
Loading…
Reference in New Issue
Block a user