From: Adam Dickmeiss Date: Thu, 25 Oct 2007 09:22:36 +0000 (+0000) Subject: Renamed index_rule to index_type. X-Git-Tag: ZEBRA.2.0.20~104 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=f4767dc0b946394baeeaed3fea5b8579d170ab5e;p=idzebra-moved-to-github.git Renamed index_rule to index_type. --- diff --git a/include/Makefile.am b/include/Makefile.am index a89e1d5..d60ed90 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,7 +1,7 @@ -# $Id: Makefile.am,v 1.27 2007-10-24 13:55:55 adam Exp $ +# $Id: Makefile.am,v 1.28 2007-10-25 09:22:36 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 + it_key.h su_codec.h index_types.h SUBDIRS = idzebra diff --git a/include/index_rules.h b/include/index_rules.h deleted file mode 100644 index 32cbd7d..0000000 --- a/include/index_rules.h +++ /dev/null @@ -1,97 +0,0 @@ -/* $Id: index_rules.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 index_rules.h - \brief Definitions for Zebra's index rules system -*/ - -#ifndef ZEBRA_INDEX_RULES_H -#define ZEBRA_INDEX_RULES_H - -#include -#include - -YAZ_BEGIN_CDECL - -/** - \brief zebra index rules handle (ptr) -*/ -typedef struct zebra_index_rules_s *zebra_index_rules_t; - -/** \brief creates index rules handler/object from file - \param fname filename - \returns handle (NULL if unsuccessful) - - Config file format: - \verbatim - - - - - - - - - - - - \endverbatim - */ -zebra_index_rules_t zebra_index_rules_create(const char *fname); - -/** \brief destroys index rules object - \param r handle - */ -void zebra_index_rules_destroy(zebra_index_rules_t r); - - -/** \brief creates index rules handler/object from xml Doc - \param doc Libxml2 document - \returns handle (NULL if unsuccessful) - - Similar to zebra_index_rules_create -*/ -zebra_index_rules_t zebra_index_rules_create_doc(xmlDocPtr doc); - - -/** \brief lookup of indexrule - \param r rules - \param id id to search for - \returns pattern ID -*/ -const char *zebra_index_rule_lookup_str(zebra_index_rules_t r, const char *id); - -YAZ_END_CDECL - -#endif -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/include/index_types.h b/include/index_types.h new file mode 100644 index 0000000..389b316 --- /dev/null +++ b/include/index_types.h @@ -0,0 +1,97 @@ +/* $Id: index_types.h,v 1.1 2007-10-25 09:22:36 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 + +*/ + +/** + \files + \brief Definitions for Zebra's index types +*/ + +#ifndef ZEBRA_INDEX_TYPES_H +#define ZEBRA_INDEX_TYPES_H + +#include +#include + +YAZ_BEGIN_CDECL + +/** + \brief zebra index rules handle (ptr) +*/ +typedef struct zebra_index_types_s *zebra_index_types_t; + +/** \brief creates index rules handler/object from file + \param fname filename + \returns handle (NULL if unsuccessful) + + Config file format: + \verbatim + + + + + + + + + + + + \endverbatim + */ +zebra_index_types_t zebra_index_types_create(const char *fname); + +/** \brief destroys index rules object + \param r handle + */ +void zebra_index_types_destroy(zebra_index_types_t r); + + +/** \brief creates index types handler/object from xml Doc + \param doc Libxml2 document + \returns handle (NULL if unsuccessful) + + Similar to zebra_index_types_create +*/ +zebra_index_types_t zebra_index_types_create_doc(xmlDocPtr doc); + + +/** \brief lookup of index type + \param r rules + \param id id to search for + \returns pattern ID +*/ +const char *zebra_index_type_lookup_str(zebra_index_types_t r, const char *id); + +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/.cvsignore b/util/.cvsignore index 186ba78..2ae39fe 100644 --- a/util/.cvsignore +++ b/util/.cvsignore @@ -14,3 +14,4 @@ tstflock.out tstlockscope tstpass tstres +tst_index_types diff --git a/util/Makefile.am b/util/Makefile.am index 449f6ec..4575ff9 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,9 +1,9 @@ -## $Id: Makefile.am,v 1.35 2007-10-24 13:55:55 adam Exp $ +## $Id: Makefile.am,v 1.36 2007-10-25 09:22:36 adam Exp $ noinst_LTLIBRARIES = libidzebra-util.la check_PROGRAMS = tstcharmap tstflock tstlockscope tstpass tstres \ - tst_index_rules + tst_index_types TESTS = $(check_PROGRAMS) @@ -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 + attrfind.c exit.c it_key.c su_codec.c index_types.c tstpass_SOURCES = tstpass.c @@ -30,7 +30,7 @@ tstlockscope_SOURCES = tstlockscope.c tstres_SOURCES = tstres.c -tst_index_rules_SOURCES = tst_index_rules.c +tst_index_types_SOURCES = tst_index_types.c clean-local: -rm -rf *.LCK diff --git a/util/index_rules.c b/util/index_rules.c deleted file mode 100644 index 50cc465..0000000 --- a/util/index_rules.c +++ /dev/null @@ -1,184 +0,0 @@ -/* $Id: index_rules.c,v 1.2 2007-10-24 13:55:55 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. -*/ - -#include -#include -#include -#include - -#include "index_rules.h" -#include -#include -#include -#include - -struct zebra_index_rules_s { -#if YAZ_HAVE_XML2 - struct zebra_index_rule *rules; - xmlDocPtr doc; -#endif -}; - -#if YAZ_HAVE_XML2 -struct zebra_index_rule { - const xmlNode *ptr; - const char *id; - const char *locale; - const char *position; - const char *alwaysmatches; - const char *firstinfield; - const char *sort; - struct zebra_index_rule *next; -}; - -struct zebra_index_rule *parse_index_rule(const xmlNode *ptr) -{ - struct _xmlAttr *attr; - struct zebra_index_rule *rule; - - rule = xmalloc(sizeof(*rule)); - rule->next = 0; - rule->ptr = ptr; - rule->locale = 0; - rule->id = 0; - rule->position = 0; - rule->alwaysmatches = 0; - rule->firstinfield = 0; - rule->sort = 0; - for (attr = ptr->properties; attr; attr = attr->next) - { - if (attr->children && attr->children->type == XML_TEXT_NODE) - { - if (!strcmp((const char *) attr->name, "id")) - rule->id = (const char *) attr->children->content; - else if (!strcmp((const char *) attr->name, "locale")) - rule->locale = (const char *) attr->children->content; - else if (!strcmp((const char *) attr->name, "position")) - rule->position = (const char *) attr->children->content; - else if (!strcmp((const char *) attr->name, "alwaysmatches")) - rule->alwaysmatches = (const char *) attr->children->content; - else if (!strcmp((const char *) attr->name, "firstinfield")) - rule->firstinfield = (const char *) attr->children->content; - else if (!strcmp((const char *) attr->name, "sort")) - rule->sort = (const char *) attr->children->content; - else - { - yaz_log(YLOG_WARN, "Unsupport attribute '%s' for indexrule", - attr->name); - xfree(rule); - return 0; - } - } - } - return rule; -} -/* YAZ_HAVE_XML2 */ -#endif - -zebra_index_rules_t zebra_index_rules_create(const char *fname) -{ - xmlDocPtr doc = xmlParseFile(fname); - if (!doc) - return 0; - return zebra_index_rules_create_doc(doc); -} - -zebra_index_rules_t zebra_index_rules_create_doc(xmlDocPtr doc) -{ -#if YAZ_HAVE_XML2 - zebra_index_rules_t r = xmalloc(sizeof(*r)); - struct zebra_index_rule **rp = &r->rules; - const xmlNode *top = xmlDocGetRootElement(doc); - - r->doc = doc; - *rp = 0; - if (top && top->type == XML_ELEMENT_NODE - && !strcmp((const char *) top->name, "indexrules")) - { - const xmlNode *ptr = top->children; - for (; ptr; ptr = ptr->next) - { - if (ptr->type == XML_ELEMENT_NODE - && !strcmp((const char *) ptr->name, "indexrule")) - { - *rp = parse_index_rule(ptr); - if (!*rp) - { - zebra_index_rules_destroy(r); - return 0; - } - rp = &(*rp)->next; - } - } - } - else - { - zebra_index_rules_destroy(r); - r = 0; - } - return r; -#else - yaz_log(YLOG_WARN, "Cannot read index rules %s because YAZ is without XML " - "support", fname); - return 0; -/* YAZ_HAVE_XML2 */ -#endif -} - -void zebra_index_rules_destroy(zebra_index_rules_t r) -{ -#if YAZ_HAVE_XML2 - struct zebra_index_rule *rule; - while (r->rules) - { - rule = r->rules; - r->rules = rule->next; - xfree(rule); - } - xmlFreeDoc(r->doc); - -#endif - xfree(r); -} - -const char *zebra_index_rule_lookup_str(zebra_index_rules_t r, const char *id) -{ -#if YAZ_HAVE_XML2 - - struct zebra_index_rule *rule = r->rules; - - while (rule && !yaz_match_glob(rule->id, id)) - rule = rule->next; - if (rule) - return rule->id; -#endif - return 0; -} - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/util/index_types.c b/util/index_types.c new file mode 100644 index 0000000..edd4024 --- /dev/null +++ b/util/index_types.c @@ -0,0 +1,184 @@ +/* $Id: index_types.c,v 1.1 2007-10-25 09:22:36 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. +*/ + +#include +#include +#include +#include + +#include "index_types.h" +#include +#include +#include +#include + +struct zebra_index_types_s { +#if YAZ_HAVE_XML2 + struct zebra_index_type *rules; + xmlDocPtr doc; +#endif +}; + +#if YAZ_HAVE_XML2 +struct zebra_index_type { + const xmlNode *ptr; + const char *id; + const char *locale; + const char *position; + const char *alwaysmatches; + const char *firstinfield; + const char *sort; + struct zebra_index_type *next; +}; + +struct zebra_index_type *parse_index_type(const xmlNode *ptr) +{ + struct _xmlAttr *attr; + struct zebra_index_type *rule; + + rule = xmalloc(sizeof(*rule)); + rule->next = 0; + rule->ptr = ptr; + rule->locale = 0; + rule->id = 0; + rule->position = 0; + rule->alwaysmatches = 0; + rule->firstinfield = 0; + rule->sort = 0; + for (attr = ptr->properties; attr; attr = attr->next) + { + if (attr->children && attr->children->type == XML_TEXT_NODE) + { + if (!strcmp((const char *) attr->name, "id")) + rule->id = (const char *) attr->children->content; + else if (!strcmp((const char *) attr->name, "locale")) + rule->locale = (const char *) attr->children->content; + else if (!strcmp((const char *) attr->name, "position")) + rule->position = (const char *) attr->children->content; + else if (!strcmp((const char *) attr->name, "alwaysmatches")) + rule->alwaysmatches = (const char *) attr->children->content; + else if (!strcmp((const char *) attr->name, "firstinfield")) + rule->firstinfield = (const char *) attr->children->content; + else if (!strcmp((const char *) attr->name, "sort")) + rule->sort = (const char *) attr->children->content; + else + { + yaz_log(YLOG_WARN, "Unsupport attribute '%s' for indexrule", + attr->name); + xfree(rule); + return 0; + } + } + } + return rule; +} +/* YAZ_HAVE_XML2 */ +#endif + +zebra_index_types_t zebra_index_types_create(const char *fname) +{ + xmlDocPtr doc = xmlParseFile(fname); + if (!doc) + return 0; + return zebra_index_types_create_doc(doc); +} + +zebra_index_types_t zebra_index_types_create_doc(xmlDocPtr doc) +{ +#if YAZ_HAVE_XML2 + zebra_index_types_t r = xmalloc(sizeof(*r)); + struct zebra_index_type **rp = &r->rules; + const xmlNode *top = xmlDocGetRootElement(doc); + + r->doc = doc; + *rp = 0; + if (top && top->type == XML_ELEMENT_NODE + && !strcmp((const char *) top->name, "indextypes")) + { + const xmlNode *ptr = top->children; + for (; ptr; ptr = ptr->next) + { + if (ptr->type == XML_ELEMENT_NODE + && !strcmp((const char *) ptr->name, "indextype")) + { + *rp = parse_index_type(ptr); + if (!*rp) + { + zebra_index_types_destroy(r); + return 0; + } + rp = &(*rp)->next; + } + } + } + else + { + zebra_index_types_destroy(r); + r = 0; + } + return r; +#else + yaz_log(YLOG_WARN, "Cannot read index types %s because YAZ is without XML " + "support", fname); + return 0; +/* YAZ_HAVE_XML2 */ +#endif +} + +void zebra_index_types_destroy(zebra_index_types_t r) +{ +#if YAZ_HAVE_XML2 + struct zebra_index_type *rule; + while (r->rules) + { + rule = r->rules; + r->rules = rule->next; + xfree(rule); + } + xmlFreeDoc(r->doc); + +#endif + xfree(r); +} + +const char *zebra_index_type_lookup_str(zebra_index_types_t r, const char *id) +{ +#if YAZ_HAVE_XML2 + + struct zebra_index_type *rule = r->rules; + + while (rule && !yaz_match_glob(rule->id, id)) + rule = rule->next; + if (rule) + return rule->id; +#endif + 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 deleted file mode 100644 index eaef68c..0000000 --- a/util/tst_index_rules.c +++ /dev/null @@ -1,113 +0,0 @@ -/* $Id: tst_index_rules.c,v 1.2 2007-10-24 13:55:55 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 - -*/ - -#include -#include -#include -#include -#include - -const char *xml_str = -" " -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -; - -int compare_lookup(zebra_index_rules_t r, const char *id, - const char *expected_id) -{ - const char *got_id = zebra_index_rule_lookup_str(r, id); - if (!got_id && !expected_id) - return 1; /* none expected */ - - if (got_id && expected_id && !strcmp(got_id, expected_id)) - return 1; - return 0; -} - -void tst1(void) -{ - xmlDocPtr doc = xmlParseMemory(xml_str, strlen(xml_str)); - - YAZ_CHECK(doc); - if (doc) - { - zebra_index_rules_t rules = zebra_index_rules_create_doc(doc); - YAZ_CHECK(rules); - - if (!rules) - return ; - - 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:en", 0)); - 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:sx", 0); - compare_lookup(rules, "title:Sx", 0); - } - } - - zebra_index_rules_destroy(rules); - } -} - -int main(int argc, char **argv) -{ - YAZ_CHECK_INIT(argc, argv); - YAZ_CHECK_LOG(); - - tst1(); - - YAZ_CHECK_TERM; -} - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/util/tst_index_types.c b/util/tst_index_types.c new file mode 100644 index 0000000..95d3330 --- /dev/null +++ b/util/tst_index_types.c @@ -0,0 +1,113 @@ +/* $Id: tst_index_types.c,v 1.1 2007-10-25 09:22:36 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 + +*/ + +#include +#include +#include +#include +#include + +const char *xml_str = +" " +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +; + +int compare_lookup(zebra_index_types_t r, const char *id, + const char *expected_id) +{ + const char *got_id = zebra_index_type_lookup_str(r, id); + if (!got_id && !expected_id) + return 1; /* none expected */ + + if (got_id && expected_id && !strcmp(got_id, expected_id)) + return 1; + return 0; +} + +void tst1(void) +{ + xmlDocPtr doc = xmlParseMemory(xml_str, strlen(xml_str)); + + YAZ_CHECK(doc); + if (doc) + { + zebra_index_types_t rules = zebra_index_types_create_doc(doc); + YAZ_CHECK(rules); + + if (!rules) + return ; + + 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:en", 0)); + 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:sx", 0); + compare_lookup(rules, "title:Sx", 0); + } + } + + zebra_index_types_destroy(rules); + } +} + +int main(int argc, char **argv) +{ + YAZ_CHECK_INIT(argc, argv); + YAZ_CHECK_LOG(); + + tst1(); + + YAZ_CHECK_TERM; +} + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +