sfeed

Simple RSS and Atom feed parser
git clone https://git.sinitax.com/codemadness/sfeed
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit af021fb1161c2b0f669991bf64a7cbb696830156
parent aea9644b0a408233385c24d41590f88fa63a8028
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  2 Dec 2018 12:16:00 +0100

sfeed_xmlenc: simplify and don't print control characters

Diffstat:
Msfeed_xmlenc.c | 37+++++++++++++++----------------------
1 file changed, 15 insertions(+), 22 deletions(-)

diff --git 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;