From: Adam Dickmeiss Date: Mon, 8 Jan 2007 10:48:06 +0000 (+0000) Subject: Implemented function ccl_xml_config which parses XML version of CCL X-Git-Tag: YAZ.2.1.46~11 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=2edee0444eb7d2aba3528a6ae6523c2d1dd92a18;p=yaz-moved-to-github.git Implemented function ccl_xml_config which parses XML version of CCL configuration (bug #798). --- diff --git a/NEWS b/NEWS index 6e84878..308869c 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +Implemented function ccl_xml_config which parses XML version of CCL +configuration (bug #798). + Fixed bug #797: yaz_marc_write_xml does not honor character conversion. Added timings utility (yaz/timing.h) diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index 7b37175..9f9dbd2 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -1,6 +1,6 @@ -## $Id: Makefile.am,v 1.37 2007-01-03 13:46:17 adam Exp $ +## $Id: Makefile.am,v 1.38 2007-01-08 10:48:07 adam Exp $ -pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \ +pkginclude_HEADERS= backend.h ccl.h ccl_xml.h cql.h comstack.h \ diagbib1.h diagsrw.h diagsru_update.h sortspec.h log.h logrpn.h marcdisp.h \ nmem.h nmem_xml.h odr.h \ oid.h options.h otherinfo.h pquery.h prt-ext.h querytowrbuf.h \ diff --git a/include/yaz/ccl_xml.h b/include/yaz/ccl_xml.h new file mode 100644 index 0000000..19814c1 --- /dev/null +++ b/include/yaz/ccl_xml.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1995-2007, Index Data + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Index Data nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* $Id: ccl_xml.h,v 1.1 2007-01-08 10:48:07 adam Exp $ */ + +/** + * \file ccl_xml.h + * \brief Header for CCL + XML stuff + */ +#ifndef YAZ_CCL_XML_H +#define YAZ_CCL_XML_H + +#include +#include + +YAZ_BEGIN_CDECL + +/** \brief configures CCL bibset using XML configuration + \param bibset CCL bibliographic profile + \param ptr xml node pointer pointing to "cclmap" element + \param addinfo has error message if configuration could not be parsed + \retval 0 OK + \retval -1 errors. Inspect addinfo for error message + + Configuration example: + \verbatim + + + + + + + + + + + + + + \endverbatim +*/ +YAZ_EXPORT +int ccl_xml_config(CCL_bibset bibset, const xmlNode *ptr, + const char **addinfo); + +YAZ_END_CDECL + +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/Makefile.am b/src/Makefile.am index 430c797..692de94 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ ## This file is part of the YAZ toolkit. ## Copyright (C) 1995-2007, Index Data, All rights reserved. -## $Id: Makefile.am,v 1.48 2007-01-03 13:46:18 adam Exp $ +## $Id: Makefile.am,v 1.49 2007-01-08 10:48:07 adam Exp $ YAZ_VERSION_INFO=2:1:0 @@ -73,7 +73,7 @@ libyaz_la_SOURCES=version.c options.c log.c \ otherinfo.c pquery.c sortspec.c z3950oid.c charneg.c initopt.c \ zoom-c.c zoom-opt.c zoom-p.h grs1disp.c zgdu.c soap.c srw.c srwutil.c \ opacdisp.c cclfind.c ccltoken.c cclerrms.c cclqual.c cclptree.c \ - cclqfile.c cclstr.c \ + cclqfile.c cclstr.c cclxmlconfig.c \ cql.y cqlstdio.c cqltransform.c cqlutil.c xcqlutil.c cqlstring.c \ cqlstrer.c querytowrbuf.c \ eventl.c seshigh.c statserv.c requestq.c tcpdchk.c \ diff --git a/test/.cvsignore b/test/.cvsignore index 021b6cb..9f74eea 100644 --- a/test/.cvsignore +++ b/test/.cvsignore @@ -5,6 +5,7 @@ tstodrcodec.c tstodrcodec.h .libs tstccl +tstccl.log tsticonv tstmatchstr tstnmem @@ -21,4 +22,5 @@ tst_filepath tst_record_conv tst_retrieval tst_tpath +tst_timing tst_timing.log diff --git a/test/tstccl.c b/test/tstccl.c index 32c0329..2a95345 100644 --- a/test/tstccl.c +++ b/test/tstccl.c @@ -2,13 +2,13 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tstccl.c,v 1.12 2007-01-03 08:42:16 adam Exp $ + * $Id: tstccl.c,v 1.13 2007-01-08 10:48:07 adam Exp $ */ /* CCL test */ #include -#include +#include #include @@ -98,6 +98,45 @@ void tst1(int pass) "x r=o\n" ); break; + case 3: +#if YAZ_HAVE_XML2 + if (1) + { + xmlDocPtr doc; + int r; + const char *addinfo = 0; + const char *xml_str = + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; + + doc = xmlParseMemory(xml_str, strlen(xml_str)); + YAZ_CHECK(doc); + + r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo); + YAZ_CHECK_EQ(r, 0); + } + break; +#else + return; +#endif default: YAZ_CHECK(0); return; @@ -169,9 +208,11 @@ void tst1(int pass) int main(int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); + YAZ_CHECK_LOG(); tst1(0); tst1(1); tst1(2); + tst1(3); YAZ_CHECK_TERM; } /* diff --git a/util/cclsh.c b/util/cclsh.c index 4110aad..0d89350 100644 --- a/util/cclsh.c +++ b/util/cclsh.c @@ -44,7 +44,7 @@ /* CCL shell. * Europagate 1995 * - * $Id: cclsh.c,v 1.4 2007-01-03 08:42:16 adam Exp $ + * $Id: cclsh.c,v 1.5 2007-01-08 10:48:08 adam Exp $ * * Old Europagate Log: * @@ -88,8 +88,8 @@ #include #include -#include - +#include +#include #if HAVE_READLINE_READLINE_H #include @@ -104,7 +104,7 @@ static char *prog; void usage(const char *prog) { - fprintf (stderr, "%s: [-d] [-b configfile]\n", prog); + fprintf (stderr, "%s: [-d] [-b configfile] [-x xmlconfig]\n", prog); exit (1); } @@ -113,50 +113,101 @@ int main (int argc, char **argv) CCL_bibset bibset; FILE *bib_inf; char *bib_fname; + int ret; + char *arg; +#if YAZ_HAVE_XML2 + xmlDocPtr doc; + const char *addinfo; +#endif + WRBUF q_wrbuf = 0; prog = *argv; bibset = ccl_qual_mk (); - while (--argc > 0) + + while ((ret = options("db:x:", argv, argc, &arg)) != -2) { - if (**++argv == '-') + switch(ret) { - switch (argv[0][1]) + case 'd': + debug = 1; + break; + case 'b': + bib_fname = arg; + bib_inf = fopen (bib_fname, "r"); + if (!bib_inf) { - case 'd': - debug = 1; - break; - case 'b': - if (argv[0][2]) - bib_fname = argv[0]+2; - else if (argc > 0) - { - --argc; - bib_fname = *++argv; - } - else - { - fprintf (stderr, "%s: missing bib filename\n", prog); - exit (1); - } - bib_inf = fopen (bib_fname, "r"); - if (!bib_inf) - { - fprintf (stderr, "%s: cannot open %s\n", prog, - bib_fname); - exit (1); - } - ccl_qual_file (bibset, bib_inf); - fclose (bib_inf); - break; - default: - usage(prog); + fprintf (stderr, "%s: cannot open %s\n", prog, + bib_fname); + exit (1); + } + ccl_qual_file (bibset, bib_inf); + fclose (bib_inf); + break; +#if YAZ_HAVE_XML2 + case 'x': + doc = xmlParseFile(arg); + if (!doc) + { + fprintf(stderr, "%s: could not read %s\n", prog, arg); + exit(1); + } + if (ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo)) + { + fprintf(stderr, "%s: error in %s: %s\n", prog, arg, addinfo); + exit(1); } + xmlFreeDoc(doc); + break; +#endif + case 0: + if (q_wrbuf) + wrbuf_puts(q_wrbuf, " "); + else + q_wrbuf = wrbuf_alloc(); + wrbuf_puts(q_wrbuf, arg); + break; + default: + usage(prog); + } + } + if (q_wrbuf) + { + CCL_parser cclp = ccl_parser_create (); + struct ccl_token *list; + int error; + struct ccl_rpn_node *rpn; + + cclp->bibset = bibset; + + list = ccl_parser_tokenize (cclp, wrbuf_cstr(q_wrbuf)); + rpn = ccl_parser_find (cclp, list); + + error = cclp->error_code; + + if (error) + { + printf ("%s\n", ccl_err_msg (error)); } else { - fprintf (stderr, "%s: no filenames, please\n", prog); - exit (1); + if (rpn) + { + ccl_pr_tree (rpn, stdout); + printf ("\n"); + } + } + if (debug) + { + struct ccl_token *lp; + for (lp = list; lp; lp = lp->next) + printf ("%d %.*s\n", lp->kind, (int) (lp->len), lp->name); } + ccl_token_del (list); + ccl_parser_destroy (cclp); + if (rpn) + ccl_rpn_delete(rpn); + wrbuf_destroy(q_wrbuf); + exit(0); } while (1) {