#include #include #include #include #include #include #include "util.h" static struct feed *feeds; static int showsidebar; static char *line; static size_t linesize; static unsigned long totalnew; static time_t comparetime; static void printfeed(FILE *fp, struct feed *f) { char *fields[FieldLast]; struct tm *tm; time_t parsedtime; unsigned int isnew; ssize_t linelen; if (f->name[0]) { fputs("

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

\n", stdout); } fputs("
\n", stdout);

	while ((linelen = getline(&line, &linesize, fp)) > 0) {
		if (line[linelen - 1] == '\n')
			line[--linelen] = '\0';
		parseline(line, fields);

		parsedtime = 0;
		if (!strtotime(fields[FieldUnixTimestamp], &parsedtime) &&
		    (tm = localtime(&parsedtime))) {
			isnew = (parsedtime >= comparetime) ? 1 : 0;
			totalnew += isnew;
			f->totalnew += isnew;

			fprintf(stdout, "%04d-%02d-%02d %02d:%02d ",
			        tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
			        tm->tm_hour, tm->tm_min);
		} else {
			fputs("                 ", stdout);
		}
		f->total++;

		if (fields[FieldLink][0]) {
			fputs("", stdout);
		}
		if (isnew)
			fputs("", stdout);
		xmlencode(fields[FieldTitle], stdout);
		if (isnew)
			fputs("", stdout);
		if (fields[FieldLink][0])
			fputs("", stdout);
		fputs("\n", stdout);
	}
	fputs("
\n", stdout); } int main(int argc, char *argv[]) { struct feed *f; char *name; FILE *fp; int i; if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); if (!(feeds = calloc(argc, sizeof(struct feed)))) err(1, "calloc"); if ((comparetime = time(NULL)) == -1) err(1, "time"); /* 1 day is old news */ comparetime -= 86400; fputs("\n" "\n" "\t\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) { feeds[0].name = ""; printfeed(stdin, &feeds[0]); if (ferror(stdin)) err(1, "ferror: :"); } else { for (i = 1; i < argc; i++) { name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i]; feeds[i - 1].name = name; 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\n", totalnew); return 0; }