summaryrefslogtreecommitdiff
path: root/sfeed_xmlenc.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2014-03-31 22:46:58 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2014-03-31 22:46:58 +0200
commitd8b0c45812890670943becd45383f75d57056e52 (patch)
tree055375c12586e9f38f19ce5281f0a2c54de92226 /sfeed_xmlenc.c
parent1fa71087c9d754b687d52059ee88ca82b45ec1eb (diff)
new version
lots of things changed, but cleanup todo. changelog and consistent stream of small updates will come in the future. Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
Diffstat (limited to 'sfeed_xmlenc.c')
-rw-r--r--sfeed_xmlenc.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/sfeed_xmlenc.c b/sfeed_xmlenc.c
new file mode 100644
index 0000000..c5cd289
--- /dev/null
+++ b/sfeed_xmlenc.c
@@ -0,0 +1,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 = (tag[0] == '?' && (!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);
+ x.xmltagstart = xmltagstart;
+ x.xmltagend = xmltagend;
+ x.xmlattr = xmlattr;
+
+ xmlparser_parse(&x);
+
+ return EXIT_FAILURE;
+}