From: Jan Kupec Date: Wed, 9 Apr 2008 14:09:26 +0000 (+0000) Subject: - enable regex matching in Dataiterator X-Git-Tag: BASE-SuSE-Code-12_1-Branch~737 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28850286878bf78d37f2702238efe688ef5c78cf;p=platform%2Fupstream%2Flibsolv.git - enable regex matching in Dataiterator --- diff --git a/src/repo.h b/src/repo.h index ef46002..435c706 100644 --- a/src/repo.h +++ b/src/repo.h @@ -13,6 +13,8 @@ #ifndef SATSOLVER_REPO_H #define SATSOLVER_REPO_H +#include + #include "pooltypes.h" #include "pool.h" #if 0 @@ -188,6 +190,8 @@ typedef struct _Dataiterator unsigned flags; unsigned state; KeyValue kv; + regex_t regex; + int regex_err; } Dataiterator; /* Use these like: diff --git a/src/repodata.c b/src/repodata.c index ec819f0..1c2161c 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -667,7 +667,35 @@ dataiterator_init(Dataiterator *di, Repo *repo, Id p, Id keyname, di->data = repo->repodata + repo->nrepodata - 1; di->state = 0; } + di->match = match; + if ((di->flags & SEARCH_STRINGMASK) == SEARCH_REGEX) + { + if (di->match) + { + /* We feed multiple lines eventually (e.g. authors or descriptions), + so set REG_NEWLINE. */ + di->regex_err = + regcomp(&di->regex, di->match, + REG_EXTENDED | REG_NOSUB | REG_NEWLINE + | ((di->flags & SEARCH_NOCASE) ? REG_ICASE : 0)); +#if 0 + if (di->regex_err != 0) + { + fprintf(stderr, "Given regex failed to compile: %s\n", di->match); + fprintf(stderr, "regcomp error code: %d\n", di->regex_err); + exit(1); + } +#else + } + else + { + di->flags |= (di->flags & SEARCH_STRINGMASK) | SEARCH_STRING; + di->regex_err = 0; +#endif + } + } + di->keyname = keyname; static Id zeroid = 0; di->keyp = &zeroid; @@ -728,11 +756,10 @@ dataiterator_match_int_real(Dataiterator *di, int flags, const void *vmatch) if (fnmatch(match, kv->str, (flags & SEARCH_NOCASE) ? FNM_CASEFOLD : 0)) return 0; break; -#if 0 case SEARCH_REGEX: if (regexec((const regex_t *)vmatch, kv->str, 0, NULL, 0)) return 0; -#endif + break; default: return 0; } @@ -743,7 +770,10 @@ dataiterator_match_int_real(Dataiterator *di, int flags, const void *vmatch) static int dataiterator_match_int(Dataiterator *di) { - return dataiterator_match_int_real(di, di->flags, di->match); + if ((di->flags & SEARCH_STRINGMASK) == SEARCH_REGEX) + return dataiterator_match_int_real(di, di->flags, &di->regex); + else + return dataiterator_match_int_real(di, di->flags, di->match); } int