From 276d5789fd91d1cbe84b7baee736dea28b1e04c0 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 5 Jul 2020 15:57:02 +0200 Subject: 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? --- sfeed_frames.c | 22 +++++++++++----------- sfeed_gopher.c | 31 ++++++++++++++++--------------- sfeed_html.c | 24 ++++++++++++------------ sfeed_plain.c | 24 ++++++++++++------------ sfeed_twtxt.c | 16 ++++++++-------- 5 files changed, 59 insertions(+), 58 deletions(-) diff --git a/sfeed_frames.c b/sfeed_frames.c index 972f9ce..bb55c31 100644 --- 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("= 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 index 97318af..42e6572 100644 --- 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("= 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 index 52281d2..2b171ba 100644 --- 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); -- cgit v1.2.3