sfeed

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

commit dba6dfe4e54781529dac942733b9c42eb4fa182e
parent 07606d60544c25129ee8968f49f13711f1119a54
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu,  8 May 2014 14:20:10 +0000

sfeed: remove level of indentation

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
MTODO | 4+++-
Msfeed.c | 114++++++++++++++++++++++++++++++++++++++++----------------------------------------
2 files changed, 60 insertions(+), 58 deletions(-)

diff --git a/TODO b/TODO @@ -9,4 +9,6 @@ [ ] feeds file: empty tab (encoding can't be detected?) [ ] optimize [ ] afgets() - [ ] namedentitytostr, xml parser, etc. + [ ] gettag() lookup. + [ ] namedentitytostr lookup. + [ ] xml parser, etc. diff --git a/sfeed.c b/sfeed.c @@ -73,7 +73,6 @@ static FeedContext ctx; static XMLParser parser; /* XML parser state */ static char *append = NULL; /* append string after each output line */ -/* TODO: optimize lookup */ /* unique number for parsed tag (faster comparison) */ static int gettag(int feedtype, const char *name, size_t namelen) { @@ -387,6 +386,7 @@ string_print(String *s) { putchar(*p); } #if 0 + /* NOTE: optimized string output, re-test this later */ for(i = 0; *p; p++) { if(ISWSNOSPACE(*p)) { /* isspace(c) && c != ' ' */ if(*p == '\n') { /* escape newline */ @@ -639,64 +639,64 @@ xml_handler_end_element(XMLParser *p, const char *name, size_t namelen, int issh } return; } - if(ctx.item.feedtype != FeedTypeNone) { - /* end of RSS or Atom entry / item */ - /* TODO: optimize, use gettag() ? to tagid? */ - if((ctx.item.feedtype == FeedTypeAtom && - istag(name, namelen, "entry", strlen("entry"))) || /* Atom */ - (ctx.item.feedtype == FeedTypeRSS && - istag(name, namelen, "item", strlen("item")))) /* RSS */ - { - printf("%ld", (long)parsetime((&ctx.item.timestamp)->data, - timebuf, sizeof(timebuf))); - putchar(FieldSeparator); - fputs(timebuf, stdout); - putchar(FieldSeparator); - string_print(&ctx.item.title); - putchar(FieldSeparator); - string_print(&ctx.item.link); - putchar(FieldSeparator); - string_print(&ctx.item.content); - putchar(FieldSeparator); - fputs(contenttypes[ctx.item.contenttype], stdout); - putchar(FieldSeparator); - string_print(&ctx.item.id); - putchar(FieldSeparator); - string_print(&ctx.item.author); + if(ctx.item.feedtype == FeedTypeNone) + return; + /* end of RSS or Atom entry / item */ + /* TODO: optimize, use gettag() ? to tagid? */ + if((ctx.item.feedtype == FeedTypeAtom && + istag(name, namelen, "entry", strlen("entry"))) || /* Atom */ + (ctx.item.feedtype == FeedTypeRSS && + istag(name, namelen, "item", strlen("item")))) /* RSS */ + { + printf("%ld", (long)parsetime((&ctx.item.timestamp)->data, + timebuf, sizeof(timebuf))); + putchar(FieldSeparator); + fputs(timebuf, stdout); + putchar(FieldSeparator); + string_print(&ctx.item.title); + putchar(FieldSeparator); + string_print(&ctx.item.link); + putchar(FieldSeparator); + string_print(&ctx.item.content); + putchar(FieldSeparator); + fputs(contenttypes[ctx.item.contenttype], stdout); + putchar(FieldSeparator); + string_print(&ctx.item.id); + putchar(FieldSeparator); + string_print(&ctx.item.author); + putchar(FieldSeparator); + fputs(feedtypes[ctx.item.feedtype], stdout); + if(append) { putchar(FieldSeparator); - fputs(feedtypes[ctx.item.feedtype], stdout); - if(append) { - putchar(FieldSeparator); - fputs(append, stdout); - } - putchar('\n'); - - /* clear strings */ - string_clear(&ctx.item.timestamp); - string_clear(&ctx.item.title); - string_clear(&ctx.item.link); - string_clear(&ctx.item.content); - string_clear(&ctx.item.id); - string_clear(&ctx.item.author); - ctx.item.feedtype = FeedTypeNone; - ctx.item.contenttype = ContentTypePlain; - ctx.tag[0] = '\0'; /* unset tag */ - ctx.taglen = 0; - ctx.tagid = TagUnknown; - - /* not sure if needed */ - ctx.iscontenttag = 0; - ctx.iscontent = 0; - } else if(!strcmp(ctx.tag, name)) { /* clear */ /* XXX: optimize ? */ - ctx.field = NULL; - ctx.tag[0] = '\0'; /* unset tag */ - ctx.taglen = 0; - ctx.tagid = TagUnknown; - - /* not sure if needed */ - ctx.iscontenttag = 0; - ctx.iscontent = 0; + fputs(append, stdout); } + putchar('\n'); + + /* clear strings */ + string_clear(&ctx.item.timestamp); + string_clear(&ctx.item.title); + string_clear(&ctx.item.link); + string_clear(&ctx.item.content); + string_clear(&ctx.item.id); + string_clear(&ctx.item.author); + ctx.item.feedtype = FeedTypeNone; + ctx.item.contenttype = ContentTypePlain; + ctx.tag[0] = '\0'; /* unset tag */ + ctx.taglen = 0; + ctx.tagid = TagUnknown; + + /* not sure if needed */ + ctx.iscontenttag = 0; + ctx.iscontent = 0; + } else if(!strcmp(ctx.tag, name)) { /* clear */ /* XXX: optimize ? */ + ctx.field = NULL; + ctx.tag[0] = '\0'; /* unset tag */ + ctx.taglen = 0; + ctx.tagid = TagUnknown; + + /* not sure if needed */ + ctx.iscontenttag = 0; + ctx.iscontent = 0; } }