#include #include #include #include #include #include #include "util.h" static int showsidebar = 1; /* show sidebar ? */ static struct feed *feeds = NULL; /* start of feeds linked-list. */ 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; comparetime = time(NULL) - (3600 * 24); /* 1 day is old news */ 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"); feeds = fcur; 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. */ if(!totalfeeds || (fcur && strcmp(fcur->name, fields[FieldFeedName]))) { if(!(f = calloc(1, sizeof(struct feed)))) err(1, "calloc"); if(totalfeeds) { /* end previous one. */ fputs("\n", stdout); fcur->next = f; fcur = f; } else { fcur = f; feeds = fcur; /* first item. */ 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); } } /* TODO: memcpy and make fcur->name static? */ if(!(fcur->name = strdup(fields[FieldFeedName]))) err(1, "strdup"); 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); } fputs( "\t\n" "\tNewsfeed (", stdout); fprintf(stdout, "%lu", totalnew); fputs(")\n", stdout); return 0; }