commit 276d5789fd91d1cbe84b7baee736dea28b1e04c0
parent a13633a0a6b4e43d7809919ad70e085b9ecdff47
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sun, 5 Jul 2020 15:57:02 +0200
format tools: don't skip items with a missing/invalid timestamp field
Handle it appropriately in the context of each format tool. Output the item but
keep it blanked.
NOTE: maybe in sfeed_twtxt it should use the current time instead?
Diffstat:
5 files changed, 59 insertions(+), 58 deletions(-)
diff --git a/sfeed_frames.c b/sfeed_frames.c
@@ -41,19 +41,19 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f)
parseline(line, fields);
parsedtime = 0;
- if (strtotime(fields[FieldUnixTimestamp], &parsedtime))
- continue;
- if (!(tm = localtime(&parsedtime)))
- err(1, "localtime");
-
- isnew = (parsedtime >= comparetime) ? 1 : 0;
- totalnew += isnew;
- f->totalnew += isnew;
+ if (!strtotime(fields[FieldUnixTimestamp], &parsedtime) &&
+ (tm = localtime(&parsedtime))) {
+ isnew = (parsedtime >= comparetime) ? 1 : 0;
+ totalnew += isnew;
+ f->totalnew += isnew;
+ fprintf(fpitems, "%04d-%02d-%02d %02d:%02d ",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min);
+ } else {
+ fputs(" ", fpitems);
+ }
f->total++;
- fprintf(fpitems, "%04d-%02d-%02d %02d:%02d ",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min);
if (fields[FieldLink][0]) {
fputs("<a href=\"", fpitems);
xmlencode(fields[FieldLink], fpitems);
diff --git a/sfeed_gopher.c b/sfeed_gopher.c
@@ -55,16 +55,6 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f)
line[--linelen] = '\0';
parseline(line, fields);
- parsedtime = 0;
- if (strtotime(fields[FieldUnixTimestamp], &parsedtime))
- continue;
- if (!(tm = localtime(&parsedtime)))
- err(1, "localtime");
-
- isnew = (parsedtime >= comparetime) ? 1 : 0;
- f->totalnew += isnew;
- f->total++;
-
itemhost = host;
itemport = port;
itemtype = 'i';
@@ -89,11 +79,22 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f)
}
}
- fprintf(fpitems, "%c%c %04d-%02d-%02d %02d:%02d ",
- itemtype,
- isnew ? 'N' : ' ',
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min);
+ parsedtime = 0;
+ if (!strtotime(fields[FieldUnixTimestamp], &parsedtime) &&
+ (tm = localtime(&parsedtime))) {
+ isnew = (parsedtime >= comparetime) ? 1 : 0;
+ f->totalnew += isnew;
+
+ fprintf(fpitems, "%c%c %04d-%02d-%02d %02d:%02d ",
+ itemtype,
+ isnew ? 'N' : ' ',
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min);
+ } else {
+ fprintf(fpitems, "%c ", itemtype);
+ }
+ f->total++;
+
gophertext(fpitems, fields[FieldTitle]);
fputs("\t", fpitems);
if (itemtype == 'h' && fields[FieldLink] == itempath)
diff --git a/sfeed_html.c b/sfeed_html.c
@@ -41,20 +41,20 @@ printfeed(FILE *fp, struct feed *f)
parseline(line, fields);
parsedtime = 0;
- if (strtotime(fields[FieldUnixTimestamp], &parsedtime))
- continue;
- if (!(tm = localtime(&parsedtime)))
- err(1, "localtime");
-
- isnew = (parsedtime >= comparetime) ? 1 : 0;
- totalnew += isnew;
- f->totalnew += isnew;
+ 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++;
- fprintf(stdout, "%04d-%02d-%02d %02d:%02d ",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min);
-
if (fields[FieldLink][0]) {
fputs("<a href=\"", stdout);
xmlencode(fields[FieldLink], stdout);
diff --git a/sfeed_plain.c b/sfeed_plain.c
@@ -26,19 +26,19 @@ printfeed(FILE *fp, const char *feedname)
parseline(line, fields);
parsedtime = 0;
- if (strtotime(fields[FieldUnixTimestamp], &parsedtime))
- continue;
- if (!(tm = localtime(&parsedtime)))
- err(1, "localtime");
-
- if (parsedtime >= comparetime)
- fputs("N ", stdout);
- else
- fputs(" ", stdout);
+ if (!strtotime(fields[FieldUnixTimestamp], &parsedtime) &&
+ (tm = localtime(&parsedtime))) {
+ if (parsedtime >= comparetime)
+ fputs("N ", stdout);
+ else
+ fputs(" ", stdout);
+ 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);
+ }
- fprintf(stdout, "%04d-%02d-%02d %02d:%02d ",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min);
if (feedname[0]) {
printutf8pad(stdout, feedname, 15, ' ');
fputs(" ", stdout);
diff --git a/sfeed_twtxt.c b/sfeed_twtxt.c
@@ -24,14 +24,14 @@ printfeed(FILE *fp, const char *feedname)
parseline(line, fields);
parsedtime = 0;
- if (strtotime(fields[FieldUnixTimestamp], &parsedtime))
- continue;
- if (!(tm = gmtime(&parsedtime)))
- err(1, "gmtime");
-
- fprintf(stdout, "%04d-%02d-%02dT%02d:%02d:%02dZ\t",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec);
+ if (!strtotime(fields[FieldUnixTimestamp], &parsedtime) &&
+ (tm = gmtime(&parsedtime))) {
+ fprintf(stdout, "%04d-%02d-%02dT%02d:%02d:%02dZ\t",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+ } else {
+ fputs("\t", stdout);
+ }
if (feedname[0])
printf("[%s] ", feedname);
fputs(fields[FieldTitle], stdout);