1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include "cdo_output.h"
6 #include "compare.h"
7 #include "template_parser.h"
8 #include "magics_template_parser.h"
9 #include "results_template_parser.h"
10
11 #ifdef HAVE_LIBXML2
12 #include <libxml/parser.h>
13 #include <libxml/tree.h>
14 static xmlNode *root_node;
15 static xmlDoc *param_doc;
16 #endif
17
18 #define DBG_MSG 0
19
20 void *magics_node = nullptr;
21 void *results_node = nullptr;
22
23 #ifdef HAVE_LIBXML2
24 int
init_XML_template_parser(char * Filename)25 init_XML_template_parser(char *Filename)
26 {
27 param_doc = xmlReadFile(Filename, nullptr, 0);
28 if (param_doc == nullptr)
29 {
30 printf("Error: Could not parse the file \"%s\"\n", Filename);
31 return (1);
32 }
33 else
34 {
35 fprintf(stderr, "XML file %s being parsed \n", Filename);
36 root_node = xmlDocGetRootElement(param_doc);
37 }
38
39 return 0;
40 }
41 #else
42 int
init_XML_template_parser(char * Filename)43 init_XML_template_parser(char *Filename)
44 {
45 (void) Filename;
46 cdo_abort("XML2 support not compiled in!");
47 return -1;
48 }
49 #endif
50
51 int
updatemagics_and_results_nodes(void)52 updatemagics_and_results_nodes(void)
53 {
54 #ifdef HAVE_LIBXML2
55 xmlNode *cur_node = nullptr;
56
57 if (root_node == nullptr)
58 {
59 printf("Invalid Root Node\n");
60 return 0;
61 }
62
63 for (cur_node = root_node->children; cur_node; cur_node = cur_node->next)
64 {
65 if (cur_node->type == XML_ELEMENT_NODE)
66 {
67 #if DBG_MSG
68 fprintf(stdout, "Node Name: %s \n", cur_node->name);
69 #endif
70 if (cdo_cmpstr((const char *) cur_node->name, "magics"))
71 {
72 magics_node = (void *) cur_node;
73 #if DBG_MSG
74 fprintf(stdout, "Node Name: %s \n", cur_node->name);
75 #endif
76 }
77
78 if (cdo_cmpstr((const char *) cur_node->name, "results"))
79 {
80 results_node = (void *) cur_node;
81 #if DBG_MSG
82 fprintf(stdout, "Node Name: %s \n", cur_node->name);
83 #endif
84 }
85 }
86 }
87 #else
88
89 cdo_abort("XML2 support not compiled in!");
90
91 #endif
92
93 return 0;
94 }
95
96 int
quit_XML_template_parser(void)97 quit_XML_template_parser(void)
98 {
99 #ifdef HAVE_LIBXML2
100 xmlFreeDoc(param_doc);
101 xmlCleanupParser();
102 if (param_doc == nullptr) printf("Cleaned XML parser\n");
103 #if DBG_MSG
104 fprintf(stdout, "Cleaned XML parser\n");
105 #endif
106 #else
107
108 cdo_abort("XML2 support not compiled in!");
109
110 #endif
111
112 return 0;
113 }
114