#include #include #include #include #include #include #include "util.h" static struct feed **feeds = NULL; static int showsidebar = 0; /* show sidebar ? */ static char *line = NULL; static size_t linesize = 0; static unsigned long totalnew = 0; static time_t comparetime; static void printfeed(FILE *fp, struct feed *f) { char *fields[FieldLast]; time_t parsedtime; unsigned int islink, isnew; int r; if (f->name[0] != '\0') { fputs("

name, stdout); fputs("\">name, stdout); fputs("\">", stdout); printxmlencoded(f->name, stdout); fputs("

\n", stdout); } fputs("\n", stdout); while (parseline(&line, &linesize, fields, FieldLast, '\t', fp) > 0) { r = strtotime(fields[FieldUnixTimestamp], &parsedtime); isnew = (r != -1 && parsedtime >= comparetime) ? 1 : 0; islink = (fields[FieldLink][0] != '\0') ? 1 : 0; totalnew += isnew; f->totalnew += isnew; f->total++; if (isnew) fputs("", stdout); else fputs("", stdout); fputs("\n", stdout); } fputs("
", stdout); fputs(fields[FieldTimeFormatted], stdout); fputs("", stdout); if (isnew) fputs("", stdout); if (islink) { fputs("", stdout); } printxmlencoded(fields[FieldTitle], stdout); if (islink) fputs("", stdout); if (isnew) fputs("", stdout); fputs("
\n", stdout); } int main(int argc, char *argv[]) { struct feed *f; FILE *fp; int i; if (!(feeds = calloc(argc, sizeof(struct feed *)))) err(1, "calloc"); if ((comparetime = time(NULL)) == -1) err(1, "time"); /* 1 day old is old news */ comparetime -= 86400; fputs("\n" "\n" "\t\n" "\t\t\n" "\t\t\n" "\t\n" "\t\n", stdout); showsidebar = (argc > 1); if (showsidebar) fputs("\t\t
\n", stdout); else fputs("\t\t
\n", stdout); if (argc == 1) { if (!(feeds[0] = calloc(1, sizeof(struct feed)))) err(1, "calloc"); feeds[0]->name = ""; printfeed(stdin, feeds[0]); if (ferror(stdin)) err(1, "ferror: :"); } else { for (i = 1; i < argc; i++) { if (!(feeds[i - 1] = calloc(1, sizeof(struct feed)))) err(1, "calloc"); feeds[i - 1]->name = xbasename(argv[i]); if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); printfeed(fp, feeds[i - 1]); if (ferror(fp)) err(1, "ferror: %s", argv[i]); fclose(fp); } } fputs("
\n", stdout); /* div items */ if (showsidebar) { fputs("\t\n", stdout); } fprintf(stdout, "\t\n\tNewsfeed (%lu)\n", totalnew); return 0; }