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
|
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <ctype.h>
#include "xml.h"
static int isxmlpi = 0, tags = 0;
static void
xmltagstart(XMLParser *p, const char *tag, size_t taglen) {
if(tags > 3) /* optimization: try to find processing instruction at start */
exit(EXIT_FAILURE);
isxmlpi = (!strncasecmp(tag, "?xml", taglen)) ? 1 : 0;
tags++;
}
static void
xmltagend(XMLParser *p, const char *tag, size_t taglen, int isshort) {
isxmlpi = 0;
}
static void
xmlattr(XMLParser *p, const char *tag, size_t taglen, const char *name, size_t namelen, const char *value, size_t valuelen) {
if(isxmlpi && (!strncasecmp(name, "encoding", namelen))) {
for(; *value; value++)
putc(tolower((int)*value), stdout); /* output lowercase */
exit(EXIT_SUCCESS);
}
}
int
main(int argc, char **argv) {
XMLParser x;
xmlparser_init(&x, stdin);
x.xmltagstart = xmltagstart;
x.xmltagend = xmltagend;
x.xmlattr = xmlattr;
xmlparser_parse(&x);
return EXIT_FAILURE;
}
|