From fb61309506b52ca0dad9aea4135ceeda63707b0d Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Tue, 4 Jul 2006 12:59:56 +0000 Subject: [PATCH] Started the error handling in nfaxml. Not at all ready, but I want it in CVS. --- include/yaz/Makefile.am | 5 ++- include/yaz/nfa.h | 7 +++- include/yaz/nfaxml.h | 95 +++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 4 +- src/nfa.c | 5 ++- src/nfaxml.c | 87 +++++++++++++++++++++++++++++++++++++++++++ test/Makefile.am | 4 +- 7 files changed, 198 insertions(+), 9 deletions(-) create mode 100644 include/yaz/nfaxml.h create mode 100644 src/nfaxml.c diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index 8da7306..4f8de2a 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -1,7 +1,8 @@ -## $Id: Makefile.am,v 1.31 2006-05-07 17:45:41 adam Exp $ +## $Id: Makefile.am,v 1.32 2006-07-04 12:59:56 heikki Exp $ pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \ - diagbib1.h diagsrw.h sortspec.h log.h logrpn.h marcdisp.h nfa.h \ + diagbib1.h diagsrw.h sortspec.h log.h logrpn.h marcdisp.h \ + nfa.h nfaxml.h \ nmem.h odr.h \ oid.h options.h otherinfo.h pquery.h prt-ext.h querytowrbuf.h \ readconf.h record_conv.h retrieval.h statserv.h \ diff --git a/include/yaz/nfa.h b/include/yaz/nfa.h index ddce4af..addea16 100644 --- a/include/yaz/nfa.h +++ b/include/yaz/nfa.h @@ -1,6 +1,6 @@ /* Copyright (C) 2006, Index Data ApS * See the file LICENSE for details. - * $Id: nfa.h,v 1.7 2006-05-10 13:58:46 heikki Exp $ + * $Id: nfa.h,v 1.8 2006-07-04 12:59:56 heikki Exp $ */ /** @@ -28,6 +28,7 @@ #define YAZ_NFA_H #include +#include YAZ_BEGIN_CDECL @@ -529,7 +530,9 @@ yaz_nfa_state *yaz_nfa_get_next(yaz_nfa *n, yaz_nfa_state *s); * already printable, passing a null pointer here prints them with a %s * */ -void yaz_nfa_dump(FILE *F, yaz_nfa *n, char *(*strfunc)(void *) ); +void yaz_nfa_dump(FILE *F, + yaz_nfa *n, + char *(*strfunc)(void *) ); /* \} */ diff --git a/include/yaz/nfaxml.h b/include/yaz/nfaxml.h new file mode 100644 index 0000000..582f9e7 --- /dev/null +++ b/include/yaz/nfaxml.h @@ -0,0 +1,95 @@ +/* Copyright (C) 2006, Index Data ApS + * See the file LICENSE for details. + * $Id: nfaxml.h,v 1.1 2006-07-04 12:59:56 heikki Exp $ + */ + +/** + * \file nfaxml.h + * \brief Routines for reading NFA specs from an XML file + * + * The xml file is something like this (using round brakcets + * on tags, not to confuse our documentation tools) + * (?xml ...) + * (charmap) + * (rule) + * (fromstring) FOO (/fromstring) + * (tostring) BAR (/tostring) + * (/rule) + * (rule) + * (fromrange) a-z (/fromrange) + * (torange) A-Z (/torange) + * (/rule) + * ... + * + * The rules consist of two parts, 'from' and 'to'. + * From rules can be + * fromstring (which can be a single character) + * fromrange (like a-z) + * (later, perhaps a fromregexp) + * To rules can be + * tostring (which can be a single character) + * torange (only with a fromrange) + * (later, perhaps backrefs from regexps) + */ + +#ifndef YAZ_NFA_XML_H +#define YAZ_NFA_XML_H + +#include +#include +#include + +#if HAVE_XML2 +#include + +YAZ_BEGIN_CDECL + + + +/** \brief Parse the NFA from a XML document + * + * \param doc the xml tree to parse + * \param error_info will be filled in case of errors + * + * \returns either the NFA, or null in case of errors + * + * It is up to the caller to destroy the nfa when done. + * + * In case of errors, returns a null pointer. You can then + * call xmlGetLastError() to get the details of the error. + * + */ +yaz_nfa *yaz_nfa_parse_xml_doc(xmlDocPtr doc); + + +/** \brief Parse the NFA from a file + * + * \param filepath path to the xml file to parse + * \param error_info will be filled in case of errors + * + * \returns either the NFA, or null in case of errors + * + * It is up to the caller to destroy the nfa when done. + * + * In case of errors, error_info will be filled with + * suitable diagnostics. It may be null, if you don't + * care. + * + */ +yaz_nfa *yaz_nfa_parse_xml_file(char *filepath); + + +YAZ_END_CDECL + +#endif /* HAVE_XML2 */ + +#endif /* YAZ_NFA_XML_H */ + +/* + * 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 d391c5f..7e405ec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ ## This file is part of the YAZ toolkit. ## Copyright (C) 1994-2006, Index Data, All rights reserved. -## $Id: Makefile.am,v 1.39 2006-05-23 20:39:27 adam Exp $ +## $Id: Makefile.am,v 1.40 2006-07-04 12:59:56 heikki Exp $ YAZ_VERSION_INFO=2:1:0 @@ -73,7 +73,7 @@ libyaz_la_SOURCES=version.c options.c log.c marcdisp.c oid.c wrbuf.c \ eventl.h service.c service.h session.h test.c \ xmlquery.c \ mime.c mime.h \ - nfa.c \ + nfa.c nfaxml.c \ record_conv.c retrieval.c libyaz_la_LDFLAGS=-version-info $(YAZ_VERSION_INFO) diff --git a/src/nfa.c b/src/nfa.c index dca14c6..d00d41a 100644 --- a/src/nfa.c +++ b/src/nfa.c @@ -1,7 +1,7 @@ /* Copyright (C) 2006, Index Data ApS * See the file LICENSE for details. * - * $Id: nfa.c,v 1.9 2006-05-10 13:58:46 heikki Exp $ + * $Id: nfa.c,v 1.10 2006-07-04 12:59:56 heikki Exp $ */ /** @@ -113,7 +113,8 @@ yaz_nfa *yaz_nfa_init() { } void yaz_nfa_destroy(yaz_nfa *n) { - nmem_destroy(n->nmem); + if (n && n->nmem) + nmem_destroy(n->nmem); } diff --git a/src/nfaxml.c b/src/nfaxml.c new file mode 100644 index 0000000..a573eee --- /dev/null +++ b/src/nfaxml.c @@ -0,0 +1,87 @@ +/* Copyright (C) 2006, Index Data ApS + * See the file LICENSE for details. + * + * $Id: nfaxml.c,v 1.1 2006-07-04 12:59:56 heikki Exp $ + */ + +/** + * \file nfaxml.c + * \brief Routines for reading a NFA spec from an XML file + * + */ + +#if HAVE_XML2 + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + + + + +/** \brief Log XML errors in yaz_log + * + */ + +static void log_xml_error(int errlevel, char *msg) { + xmlErrorPtr e=xmlGetLastError(); + if (!e) /* no error happened */ + return; + if (!errlevel) + errlevel=YLOG_FATAL; + yaz_log(errlevel,"%s %d/%d: %s:%d: '%s' ", + msg, e->domain, e->code, e->file, e->line, e->message); + if (e->str1 || e->str2 || e->str3 ) + yaz_log(errlevel,"extra info: '%s' '%s' '%s' %d %d", + e->str1, e->str2, e->str3, e->int1, e->int2 ); +} + +/** \brief Parse the NFA from a XML document + */ +yaz_nfa *yaz_nfa_parse_xml_doc(xmlDocPtr doc){ + if (!doc) + return 0; + + return 0; +} + + +/** \brief Parse the NFA from a file + */ +yaz_nfa *yaz_nfa_parse_xml_file(char *filepath) { + int nSubst; + xmlDocPtr doc = xmlParseFile(filepath); + if (!doc) { + log_xml_error(YLOG_FATAL, + "Error in parsing charmap file"); + return 0; + } + nSubst=xmlXIncludeProcess(doc); + if (nSubst==-1) { + log_xml_error(YLOG_FATAL, + "Error handling XIncludes in charmap file"); + return 0; + } + return yaz_nfa_parse_xml_doc(doc); +} + + + +#endif /* HAVE_XML2 */ + + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/test/Makefile.am b/test/Makefile.am index 7059259..6b9cfa0 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,9 +1,10 @@ ## Copyright (C) 1994-2006, Index Data ApS ## All rights reserved. -## $Id: Makefile.am,v 1.19 2006-06-08 10:26:10 adam Exp $ +## $Id: Makefile.am,v 1.20 2006-07-04 12:59:57 heikki Exp $ check_PROGRAMS = tsticonv tstnmem tstmatchstr tstwrbuf tstodr tstccl tstlog \ tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery nfatest1 \ + nfatest1 nfaxmltest1 \ tst_filepath tst_record_conv tst_retrieval tst_tpath check_SCRIPTS = tstcql.sh tstmarciso.sh tstmarcxml.sh @@ -51,6 +52,7 @@ tstlogthread_SOURCES = tstlogthread.c tstxmlquery_SOURCES = tstxmlquery.c tstpquery_SOURCES = tstpquery.c nfatest1_SOURCES = nfatest1.c +nfaxmltest1_SOURCES = nfaxmltest1.c tst_filepath_SOURCES = tst_filepath.c tst_record_conv_SOURCES = tst_record_conv.c tst_retrieval_SOURCES = tst_retrieval.c -- 1.7.10.4