diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-08-05 16:05:14 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-08-05 16:05:14 +0200 |
commit | 1a1bd0e5a3a1a9dbdf20d7afec7c3246c2468e34 (patch) | |
tree | e869c9abfe1cc15c4d9985b600722359857fda90 | |
parent | c1c5db91a1591048dbce73760691c12fa76e8e2b (diff) |
sfeed_web: separate by tab, url<tab>contenttype, simplify
-rw-r--r-- | sfeed_web.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/sfeed_web.c b/sfeed_web.c index 075cedd..2d3c344 100644 --- a/sfeed_web.c +++ b/sfeed_web.c @@ -9,6 +9,7 @@ #include "util.h" #include "xml.h" +static XMLParser parser; static unsigned int isbase, islink, isfeedlink, found; static char abslink[4096], feedlink[4096], basehref[4096], feedtype[256]; @@ -27,12 +28,13 @@ xmltagstart(XMLParser *p, const char *tag, size_t taglen) (void)p; isbase = islink = isfeedlink = 0; - if (taglen == 4) { /* optimization */ - if (!strncasecmp(tag, "base", taglen)) - isbase = 1; - else if (!strncasecmp(tag, "link", taglen)) - islink = 1; - } + if (taglen != 4) /* optimization */ + return; + + if (!strncasecmp(tag, "base", taglen)) + isbase = 1; + else if (!strncasecmp(tag, "link", taglen)) + islink = 1; } static void @@ -43,16 +45,15 @@ xmltagstartparsed(XMLParser *p, const char *tag, size_t taglen, int isshort) (void)taglen; (void)isshort; - if (isfeedlink) { - if (*feedtype) { - printfeedtype(feedtype, stdout); - putchar(' '); - } - if (absuri(feedlink, basehref, abslink, sizeof(abslink)) != -1) - fputs(abslink, stdout); - putchar('\n'); - found++; - } + if (!isfeedlink) + return; + + if (absuri(feedlink, basehref, abslink, sizeof(abslink)) != -1) + fputs(abslink, stdout); + fputc('\t', stdout); + printfeedtype(feedtype, stdout); + putchar('\n'); + found++; } static void @@ -86,14 +87,11 @@ xmlattr(XMLParser *p, const char *tag, size_t taglen, const char *name, int main(int argc, char *argv[]) { - XMLParser parser; - if (argc > 1) strlcpy(basehref, argv[1], sizeof(basehref)); - memset(&parser, 0, sizeof(parser)); - parser.xmltagstart = xmltagstart; parser.xmlattr = xmlattr; + parser.xmltagstart = xmltagstart; parser.xmltagstartparsed = xmltagstartparsed; xmlparser_parse_fd(&parser, 0); |