Started the error handling in nfaxml. Not at all ready, but I want it in
[yaz-moved-to-github.git] / src / nfaxml.c
1 /*  Copyright (C) 2006, Index Data ApS
2  *  See the file LICENSE for details.
3  * 
4  *  $Id: nfaxml.c,v 1.1 2006-07-04 12:59:56 heikki Exp $ 
5  */
6
7 /**
8  * \file nfaxml.c
9  * \brief Routines for reading a NFA spec from an XML file
10  *
11  */
12
13 #if HAVE_XML2
14
15 #include <string.h>
16
17 #include <libxml/parser.h>
18 #include <libxml/tree.h>
19 #include <libxml/xinclude.h>
20
21 #include <yaz/nfa.h>
22 #include <yaz/nmem.h> 
23 #include <yaz/yconfig.h>
24 #include <yaz/nfa.h>
25 #include <yaz/nfaxml.h>
26
27
28
29
30 /** \brief Log XML errors in yaz_log 
31  *
32  */
33
34 static void log_xml_error(int errlevel, char *msg) {
35     xmlErrorPtr e=xmlGetLastError();
36     if (!e)  /* no error happened */
37         return;  
38     if (!errlevel)
39         errlevel=YLOG_FATAL;
40     yaz_log(errlevel,"%s %d/%d: %s:%d: '%s' ",
41             msg, e->domain, e->code, e->file, e->line, e->message);
42     if (e->str1 || e->str2 || e->str3 ) 
43     yaz_log(errlevel,"extra info: '%s' '%s' '%s' %d %d",
44             e->str1, e->str2, e->str3, e->int1, e->int2 );
45 }
46
47 /** \brief Parse the NFA from a XML document 
48  */
49 yaz_nfa *yaz_nfa_parse_xml_doc(xmlDocPtr doc){
50     if (!doc)
51         return 0;
52
53     return 0;
54 }
55
56
57 /** \brief Parse the NFA from a file 
58  */
59 yaz_nfa *yaz_nfa_parse_xml_file(char *filepath) {
60     int nSubst;
61     xmlDocPtr doc = xmlParseFile(filepath);
62     if (!doc) {
63         log_xml_error(YLOG_FATAL,
64                 "Error in parsing charmap file");
65         return 0;
66     }
67     nSubst=xmlXIncludeProcess(doc);
68     if (nSubst==-1) {
69         log_xml_error(YLOG_FATAL,
70                 "Error handling XIncludes in charmap file");
71         return 0;
72     }
73     return yaz_nfa_parse_xml_doc(doc);
74 }
75
76
77
78 #endif /* HAVE_XML2 */
79
80
81 /*
82  * Local variables:
83  * c-basic-offset: 4
84  * indent-tabs-mode: nil
85  * End:
86  * vim: shiftwidth=4 tabstop=8 expandtab
87  */