From 42cd12e606db733d23606480a1ece262ebba77ed Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 24 Oct 2007 13:55:55 +0000 Subject: [PATCH] Using yaz_match_glob from YAZ. --- include/Makefile.am | 4 +-- include/rob_regexp.h | 56 ------------------------------ util/Makefile.am | 4 +-- util/index_rules.c | 28 +++++---------- util/rob_regexp.c | 89 ------------------------------------------------ util/tst_index_rules.c | 18 +++++----- 6 files changed, 21 insertions(+), 178 deletions(-) delete mode 100644 include/rob_regexp.h delete mode 100644 util/rob_regexp.c diff --git a/include/Makefile.am b/include/Makefile.am index f176108..a89e1d5 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,7 +1,7 @@ -# $Id: Makefile.am,v 1.26 2007-10-23 12:26:25 adam Exp $ +# $Id: Makefile.am,v 1.27 2007-10-24 13:55:55 adam Exp $ noinst_HEADERS = bset.h charmap.h \ direntz.h passwddb.h dfa.h zebra_xpath.h d1_absyn.h \ rset.h dfaset.h sortidx.h zebra-lock.h attrfind.h zebramap.h \ - it_key.h su_codec.h index_rules.h rob_regexp.h + it_key.h su_codec.h index_rules.h SUBDIRS = idzebra diff --git a/include/rob_regexp.h b/include/rob_regexp.h deleted file mode 100644 index 7d81e1c..0000000 --- a/include/rob_regexp.h +++ /dev/null @@ -1,56 +0,0 @@ -/* $Id: rob_regexp.h,v 1.2 2007-10-23 12:36:22 adam Exp $ - Copyright (C) 1995-2007 - Index Data ApS - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -/** - \file rob_regexp.h - \brief Rob Pike's regular expression matcher -*/ - -#ifndef ZEBRA_ROB_REGEXP_H -#define ZEBRA_ROB_REGEXP_H - -#include - -YAZ_BEGIN_CDECL - -/** \brief matches a regular expression against text - \param regexp regular expression - \param text the text - \retval 0 no match - \retval 1 match - - Operators: c (literal char), . (any char), ^ (begin), $ (end), - * (zero or more) -*/ -int zebra_rob_regexp(const char *regexp, const char *text); - -YAZ_END_CDECL - -#endif -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/util/Makefile.am b/util/Makefile.am index 620121a..449f6ec 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.34 2007-10-23 12:26:26 adam Exp $ +## $Id: Makefile.am,v 1.35 2007-10-24 13:55:55 adam Exp $ noinst_LTLIBRARIES = libidzebra-util.la @@ -18,7 +18,7 @@ LDADD = libidzebra-util.la $(YAZLALIB) libidzebra_util_la_SOURCES = version.c zint.c res.c charmap.c zebramap.c \ passwddb.c zebra-lock.c dirent.c xpath.c atoi_zn.c snippet.c flock.c \ - attrfind.c exit.c it_key.c su_codec.c index_rules.c rob_regexp.c + attrfind.c exit.c it_key.c su_codec.c index_rules.c tstpass_SOURCES = tstpass.c diff --git a/util/index_rules.c b/util/index_rules.c index 8f2fad3..50cc465 100644 --- a/util/index_rules.c +++ b/util/index_rules.c @@ -1,4 +1,4 @@ -/* $Id: index_rules.c,v 1.1 2007-10-23 12:26:26 adam Exp $ +/* $Id: index_rules.c,v 1.2 2007-10-24 13:55:55 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -26,16 +26,14 @@ #include #include "index_rules.h" -#include "rob_regexp.h" +#include #include #include #include struct zebra_index_rules_s { - WRBUF last_id; #if YAZ_HAVE_XML2 struct zebra_index_rule *rules; - struct zebra_index_rule *last_rule_match; xmlDocPtr doc; #endif }; @@ -112,8 +110,6 @@ zebra_index_rules_t zebra_index_rules_create_doc(xmlDocPtr doc) const xmlNode *top = xmlDocGetRootElement(doc); r->doc = doc; - r->last_rule_match = 0; - r->last_id = wrbuf_alloc(); *rp = 0; if (top && top->type == XML_ELEMENT_NODE && !strcmp((const char *) top->name, "indexrules")) @@ -161,27 +157,19 @@ void zebra_index_rules_destroy(zebra_index_rules_t r) xmlFreeDoc(r->doc); #endif - wrbuf_destroy(r->last_id); xfree(r); } const char *zebra_index_rule_lookup_str(zebra_index_rules_t r, const char *id) { #if YAZ_HAVE_XML2 - if (r->last_rule_match && !strcmp(wrbuf_cstr(r->last_id), id)) - return r->last_rule_match->id; - else - { - struct zebra_index_rule *rule = r->rules; + + struct zebra_index_rule *rule = r->rules; - wrbuf_rewind(r->last_id); - wrbuf_puts(r->last_id, id); - while (rule && !zebra_rob_regexp(rule->id, id)) - rule = rule->next; - r->last_rule_match = rule; - if (rule) - return rule->id; - } + while (rule && !yaz_match_glob(rule->id, id)) + rule = rule->next; + if (rule) + return rule->id; #endif return 0; } diff --git a/util/rob_regexp.c b/util/rob_regexp.c deleted file mode 100644 index 93b0f78..0000000 --- a/util/rob_regexp.c +++ /dev/null @@ -1,89 +0,0 @@ -/* $Id: rob_regexp.c,v 1.2 2007-10-23 12:36:22 adam Exp $ - Copyright (C) 1995-2007 - Index Data ApS - - This file is part of the Zebra server. - - Zebra is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2, or (at your option) any later - version. - - Zebra is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with Zebra; see the file LICENSE.zebra. If not, write to the - Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. -*/ - -/** - \file rob_regexp.c - \brief Rob Pike's regular expression matcher - - Taken verbatim from Beautiful code.. ANSIfied a bit. - */ - - -#include -#include -#include -#include - -#include "rob_regexp.h" -#include -#include -#include - -static int matchhere(const char *regexp, const char *text); -static int matchstar(int c, const char *regexp, const char *text); - -int zebra_rob_regexp(const char *regexp, const char *text) -{ - if (regexp[0] == '^') - return matchhere(regexp+1, text); - do - { - if (matchhere(regexp, text)) - return 1; - } - while (*text++); - return 0; -} - -static int matchhere(const char *regexp, const char *text) -{ - if (regexp[0] == '\0') - return 1; - if (regexp[1] == '*') - return matchstar(regexp[0], regexp+2, text); - if (regexp[0] == '$' && regexp[1] == '\0') - return *text == '\0'; - if (*text && (regexp[0] == '.' || regexp[0] == *text)) - return matchhere(regexp+1, text+1); - return 0; -} - -static int matchstar(int c, const char *regexp, const char *text) -{ - do - { - if (matchhere(regexp, text)) - return 1; - } - while (*text && (*text++ == c || c == '.')); - return 0; -} - - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/util/tst_index_rules.c b/util/tst_index_rules.c index 710ff31..eaef68c 100644 --- a/util/tst_index_rules.c +++ b/util/tst_index_rules.c @@ -1,4 +1,4 @@ -/* $Id: tst_index_rules.c,v 1.1 2007-10-23 12:26:26 adam Exp $ +/* $Id: tst_index_rules.c,v 1.2 2007-10-24 13:55:55 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -28,19 +28,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA const char *xml_str = " " -" \n" " \n" " \n" -" \n" " \n" " \n" -" \n" " \n" " \n" -" \n" " \n" " \n" @@ -72,18 +72,18 @@ void tst1(void) if (!rules) return ; - YAZ_CHECK(compare_lookup(rules, "title:s", "^.*:s$")); + YAZ_CHECK(compare_lookup(rules, "title:s", "*:s")); YAZ_CHECK(compare_lookup(rules, "title:sx", 0)); YAZ_CHECK(compare_lookup(rules, "title:Sx", 0)); - YAZ_CHECK(compare_lookup(rules, "any:w", "^.*:w$")); + YAZ_CHECK(compare_lookup(rules, "any:w", "*:w")); YAZ_CHECK(compare_lookup(rules, "any:w:en", 0)); - YAZ_CHECK(compare_lookup(rules, "any:w:el", "^.*:w:el$")); + YAZ_CHECK(compare_lookup(rules, "any:w:el", "*:w:el")); { int i, iter = 3333; for (i = 0; i < iter; i++) { - compare_lookup(rules, "title:s", "^.*:s$"); + compare_lookup(rules, "title:s", "*:s"); compare_lookup(rules, "title:sx", 0); compare_lookup(rules, "title:Sx", 0); } -- 1.7.10.4