Introduction
Introduction Statistics Contact Development Disclaimer Help
sfeed_xmlenc.c - sfeed - RSS and Atom parser
git clone git://git.codemadness.org/sfeed
Log
Files
Refs
README
LICENSE
---
sfeed_xmlenc.c (1335B)
---
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <strings.h>
4
5 #include "util.h"
6 #include "xml.h"
7
8 static XMLParser parser;
9 static int tags;
10
11 static void
12 xmltagstart(XMLParser *p, const char *t, size_t tl)
13 {
14 /* optimization: try to find a processing instruction only at the
15 * start of the data at the first few starting tags. */
16 if (tags++ > 3)
17 exit(0);
18 }
19
20 static void
21 xmlattr(XMLParser *p, const char *t, size_t tl, const char *n, size_t nl,
22 const char *v, size_t vl)
23 {
24 if (strcasecmp(t, "?xml") || strcasecmp(n, "encoding"))
25 return;
26
27 for (; *v; v++) {
28 if (ISALPHA((unsigned char)*v) ||
29 ISDIGIT((unsigned char)*v) ||
30 *v == '.' || *v == ':' || *v == '-' || *v == '_')
31 putchar(TOLOWER((unsigned char)*v));
32 }
33 }
34
35 static void
36 xmlattrend(XMLParser *p, const char *t, size_t tl, const char *n, size_t…
37 {
38 if (strcasecmp(t, "?xml") || strcasecmp(n, "encoding"))
39 return;
40 putchar('\n');
41 exit(0);
42 }
43
44 int
45 main(void)
46 {
47 if (pledge("stdio", NULL) == -1)
48 err(1, "pledge");
49
50 parser.xmlattr = xmlattr;
51 parser.xmlattrentity = xmlattr; /* no entity conversion */
52 parser.xmlattrend = xmlattrend;
53 parser.xmltagstart = xmltagstart;
54
55 /* NOTE: GETNEXT is defined in xml.h for inline optimization */
56 xml_parse(&parser);
57
58 checkfileerror(stdin, "<stdin>", 'r');
59 checkfileerror(stdout, "<stdout>", 'w');
60
61 return 0;
62 }
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.