-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxml.c
More file actions
162 lines (140 loc) · 5.1 KB
/
Copy pathxml.c
File metadata and controls
162 lines (140 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* xml.c - Routines to parse xml files produced by DNAIO. */
/* Copyright (c) 2014 by Allen Yu
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
* */
#include <stdio.h>
#include <string.h>
#include <libxml/xmlreader.h>
#ifdef LIBXML_READER_ENABLED
/**
* parse_node:
* @reader: the xmlReader
*
* Dump information about the current node
*/
void parse_node(xmlTextReaderPtr reader,const xmlChar **name,const xmlChar **value, int *type) {
*name = xmlTextReaderConstName(reader);
if (*name == NULL)
*name = BAD_CAST "--";
*value = xmlTextReaderConstValue(reader);
*type = xmlTextReaderNodeType(reader);
}
void parse_meta(xmlTextReaderPtr reader,char meta_tags[64][32], char meta_values[64][1024])
{
const xmlChar *name, *value;
int type, ret, cur_tag=0;
//Read the next element
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
while (ret == 1 && (xmlStrcmp(name, (const xmlChar *)"Meta"))) {
if (xmlStrcmp(name, (const xmlChar *)"#text")){
strcpy(meta_tags[cur_tag], name);
//Get the #text element value
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
strcpy(meta_values[cur_tag], value);
//Skip the closing tags
while (ret == 1 && (xmlStrcmp(name, meta_tags[cur_tag])))
{
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
}
cur_tag+=1;
}
//Read the next record
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
}
//Skip the closing meta tag
ret = xmlTextReaderRead(reader);
meta_tags[cur_tag][0] = '\0';
meta_values[cur_tag][0] = '\0';
}
void parse_block(xmlTextReaderPtr reader,char *header_version, char *pos, char *header_checksum,
char *data, char *data_checksum, char *footer_version)
{
const xmlChar *name, *value;
int type, ret;
//Read the next element
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
while (ret == 1 && (xmlStrcmp(name, (const xmlChar *)"Block"))) {
if ((!xmlStrcmp(name, (const xmlChar *)"Header"))) {
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
while (ret == 1 && (xmlStrcmp(name, (const xmlChar *)"Header"))) {
if (!xmlStrcmp(name, (const xmlChar *)"Version")){
//Get the #text element value
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
strcpy(header_version, value);
//Get pass the closing element
ret = xmlTextReaderRead(reader);
}
else if (!xmlStrcmp(name, (const xmlChar *)"Position")){
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
strcpy(pos, value);
ret = xmlTextReaderRead(reader);
}
else if (!xmlStrcmp(name, (const xmlChar *)"Header_Checksum")){
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
strcpy(header_checksum, value);
ret = xmlTextReaderRead(reader);
}
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
}
}
else if ((!xmlStrcmp(name, (const xmlChar *)"Data"))) {
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
strcpy(data, value);
ret = xmlTextReaderRead(reader);
}
else if ((!xmlStrcmp(name, (const xmlChar *)"Footer"))) {
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
while (ret == 1 && (xmlStrcmp(name, (const xmlChar *)"Footer"))) {
if (!xmlStrcmp(name, (const xmlChar *)"Data_Checksum")){
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
strcpy(data_checksum, value);
ret = xmlTextReaderRead(reader);
}
else if (!xmlStrcmp(name, (const xmlChar *)"Version")){
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
strcpy(footer_version, value);
ret = xmlTextReaderRead(reader);
}
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
}
}
ret = xmlTextReaderRead(reader);
parse_node(reader, &name, &value, &type);
}
}
#else
int main(void) {
fprintf(stderr, "XInclude support not compiled in\n");
exit(1);
}
#endif