CVS.
-## $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 \
/* 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 $
*/
/**
#define YAZ_NFA_H
#include <yaz/yconfig.h>
+#include <stdio.h>
YAZ_BEGIN_CDECL
* 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 *) );
/* \} */
--- /dev/null
+/* 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 <yaz/yconfig.h>
+#include <yaz/log.h>
+#include <yaz/nfa.h>
+
+#if HAVE_XML2
+#include <libxml/parser.h>
+
+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
+ */
+
## 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
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)
/* 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 $
*/
/**
}
void yaz_nfa_destroy(yaz_nfa *n) {
- nmem_destroy(n->nmem);
+ if (n && n->nmem)
+ nmem_destroy(n->nmem);
}
--- /dev/null
+/* 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 <string.h>
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xinclude.h>
+
+#include <yaz/nfa.h>
+#include <yaz/nmem.h>
+#include <yaz/yconfig.h>
+#include <yaz/nfa.h>
+#include <yaz/nfaxml.h>
+
+
+
+
+/** \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
+ */
## 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
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