2015-07-31 19:06:52 +00:00
|
|
|
#include <ctype.h>
|
2015-06-20 22:24:30 +00:00
|
|
|
#include <err.h>
|
2012-08-03 10:03:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-11-11 18:56:05 +00:00
|
|
|
#include <string.h>
|
2012-08-03 10:03:17 +00:00
|
|
|
#include <time.h>
|
2014-03-31 20:46:58 +00:00
|
|
|
|
|
|
|
#include "util.h"
|
2012-08-03 10:03:17 +00:00
|
|
|
|
2015-06-20 22:24:30 +00:00
|
|
|
static time_t comparetime;
|
2015-08-16 18:09:59 +00:00
|
|
|
static char *line;
|
|
|
|
static size_t linesize;
|
2015-06-20 22:24:30 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
printfeed(FILE *fp, const char *feedname)
|
2014-11-11 18:56:05 +00:00
|
|
|
{
|
2015-06-20 22:24:30 +00:00
|
|
|
char *fields[FieldLast];
|
2016-03-29 08:21:06 +00:00
|
|
|
struct tm *tm;
|
2015-06-20 22:24:30 +00:00
|
|
|
time_t parsedtime;
|
2016-02-28 16:34:45 +00:00
|
|
|
ssize_t linelen;
|
2012-08-03 10:03:17 +00:00
|
|
|
|
2016-02-28 16:34:45 +00:00
|
|
|
while ((linelen = getline(&line, &linesize, fp)) > 0) {
|
|
|
|
if (line[linelen - 1] == '\n')
|
|
|
|
line[--linelen] = '\0';
|
2016-02-27 15:21:30 +00:00
|
|
|
if (!parseline(line, fields))
|
|
|
|
break;
|
2016-02-28 16:34:45 +00:00
|
|
|
|
2015-08-07 19:23:58 +00:00
|
|
|
parsedtime = 0;
|
|
|
|
strtotime(fields[FieldUnixTimestamp], &parsedtime);
|
2016-03-29 08:21:06 +00:00
|
|
|
if (!(tm = localtime(&parsedtime)))
|
|
|
|
err(1, "localtime");
|
2015-08-07 19:23:58 +00:00
|
|
|
|
|
|
|
if (parsedtime >= comparetime)
|
2015-08-05 10:47:54 +00:00
|
|
|
fputs("N ", stdout);
|
2014-03-31 21:17:16 +00:00
|
|
|
else
|
2015-08-05 10:47:54 +00:00
|
|
|
fputs(" ", stdout);
|
2015-06-20 22:24:30 +00:00
|
|
|
|
2015-07-28 19:56:46 +00:00
|
|
|
if (feedname[0])
|
2016-03-29 08:21:06 +00:00
|
|
|
printf("%-15.15s ", feedname);
|
|
|
|
|
|
|
|
fprintf(stdout, "%04d-%02d-%02d %02d:%02d ",
|
|
|
|
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
|
|
|
tm->tm_hour, tm->tm_min);
|
2014-11-11 18:11:56 +00:00
|
|
|
printutf8pad(stdout, fields[FieldTitle], 70, ' ');
|
2015-10-02 15:29:24 +00:00
|
|
|
printf(" %s\n", fields[FieldLink]);
|
2012-08-03 10:03:17 +00:00
|
|
|
}
|
2015-06-20 22:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
FILE *fp;
|
2015-07-28 19:28:34 +00:00
|
|
|
char *name;
|
2015-06-20 22:24:30 +00:00
|
|
|
int i;
|
|
|
|
|
2016-02-27 15:21:30 +00:00
|
|
|
if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1)
|
|
|
|
err(1, "pledge");
|
|
|
|
|
2015-07-30 14:09:54 +00:00
|
|
|
if ((comparetime = time(NULL)) == -1)
|
|
|
|
err(1, "time");
|
2015-06-20 22:24:30 +00:00
|
|
|
/* 1 day is old news */
|
2015-07-30 14:09:54 +00:00
|
|
|
comparetime -= 86400;
|
2015-06-20 22:24:30 +00:00
|
|
|
|
2015-07-28 19:56:46 +00:00
|
|
|
if (argc == 1) {
|
2015-06-20 22:24:30 +00:00
|
|
|
printfeed(stdin, "");
|
|
|
|
} else {
|
2015-07-28 19:56:46 +00:00
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (!(fp = fopen(argv[i], "r")))
|
2015-06-20 22:24:30 +00:00
|
|
|
err(1, "fopen: %s", argv[i]);
|
2016-04-10 12:36:16 +00:00
|
|
|
name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i];
|
2015-07-28 19:28:34 +00:00
|
|
|
printfeed(fp, name);
|
2015-07-28 19:56:46 +00:00
|
|
|
if (ferror(fp))
|
2015-06-20 22:24:30 +00:00
|
|
|
err(1, "ferror: %s", argv[i]);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
2015-01-02 14:32:45 +00:00
|
|
|
return 0;
|
2012-08-03 10:03:17 +00:00
|
|
|
}
|