sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 59583122dcacaf5d6db1cef37c367fc5e5bae9c5
parent 87f6ee55fc14327321e9d606ac9683c112fefaa9
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed,  9 Apr 2014 00:09:22 +0200

make some code more clear, linewrap

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

Diffstat:
Msfeed.c | 14++++++++------
Msfeed_frames.c | 44++++++++++++++++++++++----------------------
Msfeed_html.c | 54+++++++++++++++++++++++++++---------------------------
3 files changed, 57 insertions(+), 55 deletions(-)

diff --git a/sfeed.c b/sfeed.c @@ -92,7 +92,7 @@ gettag(int feedtype, const char *name, size_t namelen) { }; /* Atom, alphabetical order */ static FeedTag atomtag[] = { - { "author", 6, AtomTagAuthor }, /* assume this is: <author><name></name></author> */ + { "author", 6, AtomTagAuthor }, { "content", 7, AtomTagContent }, { "id", 2, AtomTagId }, { "link", 4, AtomTagLink }, @@ -417,7 +417,8 @@ isattr(const char *name, size_t len, const char *name2, size_t len2) { static void xml_handler_data(XMLParser *p, const char *s, size_t len) { if(ctx.field) { - /* author>name */ + /* add only data from <name> inside <author> tag + * or any other non-<author> tag */ if(ctx.tagid != AtomTagAuthor || !strcmp(p->tag, "name")) string_append(ctx.field, s, len); } @@ -499,8 +500,9 @@ static void xml_handler_start_element(XMLParser *p, const char *name, size_t namelen) { if(ctx.iscontenttag) { /* starts with div, handle as XML, dont convert entities */ - /* TODO: test properly and do printf() to debug */ - if(ctx.item.feedtype == FeedTypeAtom && !strncmp(name, "div", strlen("div"))) + /* TODO: test properly */ + if(ctx.item.feedtype == FeedTypeAtom && + !strncmp(name, "div", strlen("div"))) p->xmldataentity = NULL; } if(ctx.iscontent) { @@ -586,11 +588,11 @@ xml_handler_data_entity(XMLParser *p, const char *data, size_t datalen) { char buffer[16]; size_t len; - /* TODO: for content HTML data entities, convert &amp; to & ? */ + /* try to translate entity, else just pass as data */ if((len = entitytostr(data, buffer, sizeof(buffer)))) xml_handler_data(p, buffer, len); else - xml_handler_data(p, data, datalen); /* can't convert entity, just use it's data */ + xml_handler_data(p, data, datalen); } static void diff --git a/sfeed_frames.c b/sfeed_frames.c @@ -70,9 +70,9 @@ static size_t makepathname(const char *path, char *buffer, size_t bufsiz) { size_t i = 0, r = 0; - for(; *path && i < bufsiz - 1; p++) { + for(; *path && i < bufsiz - 1; path++) { if(isalpha((int)*path) || isdigit((int)*path)) { - buffer[i++] = tolower((int)*p); + buffer[i++] = tolower((int)*path); r = 0; } else { if(!r) /* don't repeat '-'. */ @@ -94,7 +94,7 @@ fileexists(const char *path) { int main(int argc, char **argv) { - struct feed *f, *feedcurrent = NULL; + struct feed *f, *fcur = NULL; char *fields[FieldLast]; char name[256]; /* TODO: bigger size? */ char *basepath = "."; @@ -137,7 +137,7 @@ main(int argc, char **argv) { while(parseline(&line, &linesize, fields, FieldLast, '\t', stdin) > 0) { /* first of feed section or new feed section. */ - if(!totalfeeds || (feedcurrent && strcmp(feedcurrent->name, fields[FieldFeedName]))) { + if(!totalfeeds || (fcur && strcmp(fcur->name, fields[FieldFeedName]))) { /* TODO: makepathname isnt necesary if fields[FieldFeedName] is the same as the previous line */ /* TODO: move this part below where FieldFeedName is checked if its different ? */ @@ -164,29 +164,29 @@ main(int argc, char **argv) { fputs("</table>\n", fpitems); - feedcurrent->next = f; - feedcurrent = feedcurrent->next; + fcur->next = f; + fcur = fcur->next; } else { /* first item. */ - feedcurrent = f; + fcur = f; - feeds = feedcurrent; + feeds = fcur; /* assume single feed (hide sidebar) */ if(fields[FieldFeedName][0] == '\0') showsidebar = 0; } /* write menu link if new. */ - if(!(feedcurrent->name = strdup(fields[FieldFeedName]))) + if(!(fcur->name = strdup(fields[FieldFeedName]))) die("can't allocate enough memory"); if(fields[FieldFeedName][0] != '\0') { fputs("<h2 id=\"", fpitems); - printfeednameid(feedcurrent->name, fpitems); + printfeednameid(fcur->name, fpitems); fputs("\"><a href=\"#", fpitems); - printfeednameid(feedcurrent->name, fpitems); + printfeednameid(fcur->name, fpitems); fputs("\">", fpitems); - fputs(feedcurrent->name, fpitems); + fputs(fcur->name, fpitems); fputs("</a></h2>\n", fpitems); } fputs("<table cellpadding=\"0\" cellspacing=\"0\">\n", fpitems); @@ -227,8 +227,8 @@ main(int argc, char **argv) { isnew = (parsedtime >= comparetime); totalnew += isnew; - feedcurrent->totalnew += isnew; - feedcurrent->total++; + fcur->totalnew += isnew; + fcur->total++; if(isnew) fputs("<tr class=\"n\">", fpitems); else @@ -256,20 +256,20 @@ main(int argc, char **argv) { "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\" />\n" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" "</head><body class=\"frame\"><div id=\"sidebar\">", fpmenu); - for(feedcurrent = feeds; feedcurrent; feedcurrent = feedcurrent->next) { - if(!feedcurrent->name || feedcurrent->name[0] == '\0') + for(fcur = feeds; fcur; fcur = fcur->next) { + if(!fcur->name || fcur->name[0] == '\0') continue; - if(feedcurrent->totalnew) + if(fcur->totalnew) fputs("<a class=\"n\" href=\"items.html#", fpmenu); else fputs("<a href=\"items.html#", fpmenu); - printfeednameid(feedcurrent->name, fpmenu); + printfeednameid(fcur->name, fpmenu); fputs("\" target=\"items\">", fpmenu); - if(feedcurrent->totalnew > 0) + if(fcur->totalnew > 0) fputs("<b><u>", fpmenu); - fputs(feedcurrent->name, fpmenu); - fprintf(fpmenu, " (%lu)", feedcurrent->totalnew); - if(feedcurrent->totalnew > 0) + fputs(fcur->name, fpmenu); + fprintf(fpmenu, " (%lu)", fcur->totalnew); + if(fcur->totalnew > 0) fputs("</u></b>", fpmenu); fputs("</a><br/>\n", fpmenu); } diff --git a/sfeed_html.c b/sfeed_html.c @@ -30,7 +30,7 @@ main(void) { char *fields[FieldLast]; unsigned long totalfeeds = 0, totalnew = 0; unsigned int islink, isnew; - struct feed *f, *feedcurrent = NULL; + struct feed *f, *fcur = NULL; time_t parsedtime, comparetime; size_t size = 0; @@ -46,27 +46,27 @@ main(void) { "\t<body class=\"noframe\">\n", stdout); - if(!(feedcurrent = calloc(1, sizeof(struct feed)))) + if(!(fcur = calloc(1, sizeof(struct feed)))) die("can't allocate enough memory"); - feeds = feedcurrent; + feeds = fcur; while(parseline(&line, &size, fields, FieldLast, '\t', stdin) > 0) { parsedtime = (time_t)strtol(fields[FieldUnixTimestamp], NULL, 10); isnew = (parsedtime >= comparetime); islink = (fields[FieldLink][0] != '\0'); /* first of feed section or new feed section. */ - /* TODO: allocate feedcurrent before here, feedcurrent can be NULL */ - if(!totalfeeds || (feedcurrent && strcmp(feedcurrent->name, fields[FieldFeedName]))) { + /* TODO: allocate fcur before here, fcur can be NULL */ + if(!totalfeeds || (fcur && strcmp(fcur->name, fields[FieldFeedName]))) { if(!(f = calloc(1, sizeof(struct feed)))) die("can't allocate enough memory"); /*f->next = NULL;*/ if(totalfeeds) { /* end previous one. */ fputs("</table>\n", stdout); - feedcurrent->next = f; - feedcurrent = f; + fcur->next = f; + fcur = f; } else { - feedcurrent = f; - feeds = feedcurrent; /* first item. */ + fcur = f; + feeds = fcur; /* first item. */ if(fields[FieldFeedName][0] == '\0' || !showsidebar) { /* set nosidebar class on div for styling */ fputs("\t\t<div id=\"items\" class=\"nosidebar\">\n", stdout); @@ -75,31 +75,31 @@ main(void) { fputs("\t\t<div id=\"items\">\n", stdout); } - /* TODO: memcpy and make feedcurrent->name static? */ - if(!(feedcurrent->name = strdup(fields[FieldFeedName]))) + /* TODO: memcpy and make fcur->name static? */ + if(!(fcur->name = strdup(fields[FieldFeedName]))) die("can't allocate enough memory"); /* - feedcurrent->totalnew = 0; - feedcurrent->total = 0; - feedcurrent->next = NULL;*/ + fcur->totalnew = 0; + fcur->total = 0; + fcur->next = NULL;*/ if(fields[FieldFeedName][0] != '\0') { fputs("<h2 id=\"", stdout); - printfeednameid(feedcurrent->name, stdout); + printfeednameid(fcur->name, stdout); fputs("\"><a href=\"#", stdout); - printfeednameid(feedcurrent->name, stdout); + printfeednameid(fcur->name, stdout); fputs("\">", stdout); - fputs(feedcurrent->name, stdout); + fputs(fcur->name, stdout); fputs("</a></h2>\n", stdout); } fputs("<table cellpadding=\"0\" cellspacing=\"0\">\n", stdout); totalfeeds++; } totalnew += isnew; - feedcurrent->totalnew += isnew; - feedcurrent->total++; + fcur->totalnew += isnew; + fcur->total++; if(isnew) fputs("<tr class=\"n\">", stdout); else @@ -128,20 +128,20 @@ main(void) { fputs("</table>\n\t\t</div>\n", stdout); /* div items */ if(showsidebar) { fputs("\t<div id=\"sidebar\">\n\t\t<ul>\n", stdout); - for(feedcurrent = feeds; feedcurrent; feedcurrent = feedcurrent->next) { - if(!feedcurrent->name || feedcurrent->name[0] == '\0') + for(fcur = feeds; fcur; fcur = fcur->next) { + if(!fcur->name || fcur->name[0] == '\0') continue; - if(feedcurrent->totalnew) + if(fcur->totalnew) fputs("<li class=\"n\"><a href=\"#", stdout); else fputs("<li><a href=\"#", stdout); - printfeednameid(feedcurrent->name, stdout); + printfeednameid(fcur->name, stdout); fputs("\">", stdout); - if(feedcurrent->totalnew > 0) + if(fcur->totalnew > 0) fputs("<b><u>", stdout); - fputs(feedcurrent->name, stdout); - fprintf(stdout, " (%lu)", feedcurrent->totalnew); - if(feedcurrent->totalnew > 0) + fputs(fcur->name, stdout); + fprintf(stdout, " (%lu)", fcur->totalnew); + if(fcur->totalnew > 0) fputs("</u></b>", stdout); fputs("</a></li>\n", stdout); }