From 43a46d664496dba16281cf89b96b3550d7c080e2 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Mon, 13 Oct 2008 10:09:47 +0000 Subject: [PATCH] - also use matcher in repo_solv --- src/repo.c | 68 ++++++---------------------------------------------------- src/repo.h | 9 +++++--- src/repodata.c | 1 + src/repopage.c | 2 +- 4 files changed, 15 insertions(+), 65 deletions(-) diff --git a/src/repo.c b/src/repo.c index 32ed192..af7c402 100644 --- a/src/repo.c +++ b/src/repo.c @@ -569,11 +569,8 @@ repo_fix_conflicts(Repo *repo, Offset conflicts) struct matchdata { Pool *pool; - const char *match; int flags; -#if 0 - regex_t regex; -#endif + Datamatcher matcher; int stop; int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv); void *callback_data; @@ -583,63 +580,9 @@ int repo_matchvalue(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv) { struct matchdata *md = cbdata; - int flags = md->flags; - if ((flags & SEARCH_STRINGMASK) != 0) - { - switch (key->type) - { - case REPOKEY_TYPE_ID: - case REPOKEY_TYPE_IDARRAY: - if (data && data->localpool) - kv->str = stringpool_id2str(&data->spool, kv->id); - else - kv->str = id2str(s->repo->pool, kv->id); - break; - case REPOKEY_TYPE_STR: - break; - default: - return 0; - } - switch ((flags & SEARCH_STRINGMASK)) - { - case SEARCH_SUBSTRING: - if (flags & SEARCH_NOCASE) - { - if (!strcasestr(kv->str, md->match)) - return 0; - } - else - { - if (!strstr(kv->str, md->match)) - return 0; - } - break; - case SEARCH_STRING: - if (flags & SEARCH_NOCASE) - { - if (strcasecmp(md->match, kv->str)) - return 0; - } - else - { - if (strcmp(md->match, kv->str)) - return 0; - } - break; - case SEARCH_GLOB: - if (fnmatch(md->match, kv->str, (flags & SEARCH_NOCASE) ? FNM_CASEFOLD : 0)) - return 0; - break; -#if 0 - case SEARCH_REGEX: - if (regexec(&md->regexp, kv->str, 0, NULL, 0)) - return 0; -#endif - default: - return 0; - } - } + if (md->matcher.match && !datamatcher_match(&md->matcher, data, key, kv)) + return 0; md->stop = md->callback(md->callback_data, s, data, key, kv); return md->stop; } @@ -832,11 +775,14 @@ repo_search(Repo *repo, Id p, Id keyname, const char *match, int flags, int (*ca memset(&md, 0, sizeof(md)); md.pool = repo->pool; - md.match = match; md.flags = flags; md.callback = callback; md.callback_data = cbdata; + if (match) + datamatcher_init(&md.matcher, md.pool, match, flags); repo_search_md(repo, p, keyname, &md); + if (match) + datamatcher_free(&md.matcher); } const char * diff --git a/src/repo.h b/src/repo.h index 628abfd..2aed77d 100644 --- a/src/repo.h +++ b/src/repo.h @@ -13,8 +13,6 @@ #ifndef SATSOLVER_REPO_H #define SATSOLVER_REPO_H -#include - #include "pooltypes.h" #include "pool.h" #include "repodata.h" @@ -270,11 +268,16 @@ typedef struct _Dataiterator #endif +void datamatcher_init(Datamatcher *ma, Pool *pool, const char *match, int flags); +void datamatcher_free(Datamatcher *ma); +int datamatcher_match(Datamatcher *ma, Repodata *data, Repokey *key, KeyValue *kv); + /* Use these like: Dataiterator di; dataiterator_init(&di, repo, 0, 0, "bla", SEARCH_SUBSTRING); while (dataiterator_step(&di)) - dosomething(di.solvid, di.key, di.kv); */ + dosomething(di.solvid, di.key, di.kv); + dataiterator_free(&di); */ void dataiterator_init(Dataiterator *di, Repo *repo, Id p, Id keyname, const char *match, int flags); void dataiterator_free(Dataiterator *di); diff --git a/src/repodata.c b/src/repodata.c index 6734824..2e17137 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "repo.h" #include "pool.h" diff --git a/src/repopage.c b/src/repopage.c index d35d7b8..1e5abb6 100644 --- a/src/repopage.c +++ b/src/repopage.c @@ -782,7 +782,7 @@ repopagestore_read_or_setup_pages(Repopagestore *store, FILE *fp, unsigned int p /* If we can't seek on our input we have to slurp in everything. */ if (!can_seek) - store->blob_store = sat_malloc(npages * BLOB_PAGESIZE); + store->blob_store = sat_malloc2(npages, BLOB_PAGESIZE); for (i = 0; i < npages; i++) { unsigned int in_len = read_u32(fp); -- 2.7.4