#include #include #include #include #include #include #include "queue.h" #include "util.h" static int showsidebar = 1; /* show sidebar ? */ static SLIST_HEAD(feedshead, feed) fhead = SLIST_HEAD_INITIALIZER(fhead); static char *line = NULL; int main(void) { char *fields[FieldLast]; unsigned long totalfeeds = 0, totalnew = 0; unsigned int islink, isnew; struct feed *f, *fcur = NULL; time_t parsedtime, comparetime; size_t size = 0; int r; /* 1 day old is old news */ comparetime = time(NULL) - 86400; fputs("\n" "\n" "\t\n" "\t\t\n" "\t\t\n" "\t\n" "\t\n", stdout); if(!(fcur = calloc(1, sizeof(struct feed)))) err(1, "calloc"); SLIST_INSERT_HEAD(&fhead, fcur, entry); while(parseline(&line, &size, fields, FieldLast, '\t', stdin) > 0) { r = strtotime(fields[FieldUnixTimestamp], &parsedtime); isnew = (r != -1 && parsedtime >= comparetime) ? 1 : 0; islink = (fields[FieldLink][0] != '\0') ? 1 : 0; /* first of feed section or new feed section (differs from * previous one). */ if(!totalfeeds || strcmp(fcur->name, fields[FieldFeedName])) { if(!(f = calloc(1, sizeof(struct feed)))) err(1, "calloc"); if(!(f->name = strdup(fields[FieldFeedName]))) err(1, "strdup"); SLIST_INSERT_AFTER(fcur, f, entry); fcur = f; if(totalfeeds) { /* end previous one. */ fputs("\n", stdout); } else { if(fields[FieldFeedName][0] == '\0' || !showsidebar) { /* set nosidebar class on div for styling */ fputs("\t\t
\n", stdout); showsidebar = 0; } else { fputs("\t\t
\n", stdout); } } if(fields[FieldFeedName][0] != '\0') { fputs("

name, stdout); fputs("\">name, stdout); fputs("\">", stdout); fputs(fcur->name, stdout); fputs("

\n", stdout); } fputs("\n", stdout); totalfeeds++; } totalnew += isnew; fcur->totalnew += isnew; fcur->total++; if(isnew) fputs("", stdout); else fputs("", stdout); fputs("\n", stdout); } if(totalfeeds) fputs("
", stdout); fputs(fields[FieldTimeFormatted], stdout); fputs("", stdout); if(isnew) fputs("", stdout); if(islink) { fputs("", stdout); } printhtmlencoded(fields[FieldTitle], stdout); if(islink) fputs("", stdout); if(isnew) fputs("", stdout); fputs("
\n\t\t
\n", stdout); /* div items */ if(showsidebar) { fputs("\t
\n\t\t\n\t
\n", stdout); } fprintf(stdout, "\t\n\tNewsfeed (%lu)\n", totalnew); return 0; }