summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2018-12-02 12:16:00 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2018-12-02 12:16:00 +0100
commitaf021fb1161c2b0f669991bf64a7cbb696830156 (patch)
treecd2af314ed73e51c0e991a48d77bbfbcecec9daa
parentaea9644b0a408233385c24d41590f88fa63a8028 (diff)
sfeed_xmlenc: simplify and don't print control characters
-rw-r--r--sfeed_xmlenc.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/sfeed_xmlenc.c b/sfeed_xmlenc.c
index 52a0be3..955042f 100644
--- a/sfeed_xmlenc.c
+++ b/sfeed_xmlenc.c
@@ -11,37 +11,31 @@
#include "xml.h"
static XMLParser parser;
-static int isxmlpi, tags;
+static int tags;
static void
-xmltagstart(XMLParser *p, const char *tag, size_t taglen)
+xmltagstart(XMLParser *p, const char *t, size_t tl)
{
- /* optimization: try to find processing instruction at start */
- if (tags > 3)
+ /* optimization: try to find a processing instruction only at the
+ start of the data. */
+ if (tags++ > 3)
exit(1);
- isxmlpi = (!strncasecmp(tag, "?xml", taglen)) ? 1 : 0;
- tags++;
}
static void
-xmltagend(XMLParser *p, const char *tag, size_t taglen, int isshort)
+xmlattr(XMLParser *p, const char *t, size_t tl, const char *n,
+ size_t nl, const char *v, size_t vl)
{
- isxmlpi = 0;
-}
+ if (strcasecmp(t, "?xml") || strcasecmp(n, "encoding"))
+ return;
-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 && !strcasecmp(name, "encoding")) {
- if (*value) {
- /* output lowercase */
- for (; *value; value++)
- putchar(tolower((unsigned char)*value));
- putchar('\n');
- }
- exit(0);
+ /* output lowercase, no control characters */
+ for (; *v; v++) {
+ if (!iscntrl((unsigned char)*v))
+ putchar(tolower((unsigned char)*v));
}
+ putchar('\n');
+ exit(0);
}
int
@@ -51,7 +45,6 @@ main(void)
err(1, "pledge");
parser.xmlattr = xmlattr;
- parser.xmltagend = xmltagend;
parser.xmltagstart = xmltagstart;
parser.getnext = getchar;