xbps-query/search.c: simplify regex matching code.
This commit is contained in:
		@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user