configuration (bug #798).
+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)
-## $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 \
--- /dev/null
+/*
+ * 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 <yaz/ccl.h>
+#include <yaz/xmltypes.h>
+
+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
+<cclmap defaultattrset="bib-1">
+ <qual name="term">
+ <attr type="u" value="1016"/>
+ <attr type="s" value="pw"/>
+ </qual>
+ <qual name="title">
+ <attr type="u" value="4"/>
+ </qual>
+ <qual name="distributor">
+ <attr attrset="gils" type="u" value="2000"/>
+ </qual>
+ <directive name="and" value="+"/>
+</cclmap>
+ \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
+ */
+
## 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
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 \
tstodrcodec.h
.libs
tstccl
+tstccl.log
tsticonv
tstmatchstr
tstnmem
tst_record_conv
tst_retrieval
tst_tpath
+tst_timing
tst_timing.log
* 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 <string.h>
-#include <yaz/ccl.h>
+#include <yaz/ccl_xml.h>
#include <yaz/test.h>
"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 =
+ "<cclmap>\n"
+ " <qual name=\"ti\">\n"
+ " <attr type=\"u\" value=\"4\"/>\n"
+ " <attr type=\"s\" value=\"pw\"/>\n"
+ " <attr type=\"t\" value=\"l,r\"/>\n"
+ " </qual>\n"
+ " <qual name=\"term\">\n"
+ " <attr type=\"1\" value=\"1016\"/>\n"
+ " <attr type=\"s\" value=\"al,pw\"/>\n"
+ " </qual>\n"
+ " <qual name=\"dc.title\">\n"
+ " <attr type=\"1\" value=\"/my/title\"/>\n"
+ " </qual>\n"
+ " <qual name=\"date\">\n"
+ " <attr type=\"r\" value=\"r\"/>\n"
+ " </qual>\n"
+ " <qual name=\"x\">\n"
+ " <attr type=\"r\" value=\"o\"/>\n"
+ " </qual>\n"
+ "</cclmap>\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;
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;
}
/*
/* 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:
*
#include <stdlib.h>
#include <string.h>
-#include <yaz/ccl.h>
-
+#include <yaz/ccl_xml.h>
+#include <yaz/options.h>
#if HAVE_READLINE_READLINE_H
#include <readline/readline.h>
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);
}
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)
{