From 0fbab9338364acd48dd7c3d85075836e6ec1019d Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 26 May 2014 08:36:33 +0200 Subject: [PATCH] xbps-query/search.c: simplify regex matching code. --- bin/xbps-query/search.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/xbps-query/search.c b/bin/xbps-query/search.c index fd976e82..ebd827cb 100644 --- a/bin/xbps-query/search.c +++ b/bin/xbps-query/search.c @@ -121,14 +121,14 @@ search_array_cb(struct xbps_handle *xhp _unused, if (sd->regex) { regex_t regex; - regmatch_t regmatches[1]; - regcomp(®ex, sd->patterns[x], REG_EXTENDED); - if ((regexec(®ex, pkgver, 1, regmatches, REG_EXTENDED) == 0) || - (regexec(®ex, desc, 1, regmatches, REG_EXTENDED) == 0)) { + regcomp(®ex, sd->patterns[x], REG_EXTENDED|REG_NOSUB); + if ((regexec(®ex, pkgver, 0, 0, 0) == 0) || + (regexec(®ex, desc, 0, 0, 0) == 0)) { xbps_array_add_cstring_nocopy(sd->results, pkgver); xbps_array_add_cstring_nocopy(sd->results, desc); } + regfree(®ex); } else { if ((xbps_pkgpattern_match(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++) { if (sd->regex) { regex_t regex; - regmatch_t regmatches[1]; - regcomp(®ex, sd->patterns[x], REG_EXTENDED); - if (regexec(®ex, str, 1, regmatches, 0) == 0) { + regcomp(®ex, sd->patterns[x], REG_EXTENDED|REG_NOSUB); + if (regexec(®ex, str, 0, 0, 0) == 0) { xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); printf("%s: %s (%s)\n", pkgver, str, sd->repourl); } + regfree(®ex); } else { if ((strcasestr(str, sd->patterns[x])) || (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++) { if (sd->regex) { regex_t regex; - regmatch_t regmatches[1]; - regcomp(®ex, sd->patterns[x], REG_EXTENDED); - if (regexec(®ex, str, 1, regmatches, 0) == 0) { + regcomp(®ex, sd->patterns[x], REG_EXTENDED|REG_NOSUB); + if (regexec(®ex, str, 0, 0, 0) == 0) { xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); printf("%s: %s (%s)\n", pkgver, str, sd->repourl); } + regfree(®ex); } else { if (strcasestr(str, sd->patterns[x])) { xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);