sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit a4a8c9f7992dbbf0a636aef3982039b73b31e455
parent 3003c3ab6912570f3ee01a99971bd82f31180627
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Mon, 20 May 2013 19:32:22 +0200

update sfeed_plain: pad time format, make code more readable

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Msfeed_plain.c | 22++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/sfeed_plain.c b/sfeed_plain.c @@ -2,13 +2,14 @@ #include <string.h> #include <stdlib.h> #include <time.h> -#include "common.c" +#include "common.h" +#include "compat.h" void printutf8padded(const char *s, size_t len) { - unsigned int n = 0, i = 0; + size_t n = 0, i; - for(; s[i] && n < len; i++) { + for(i = 0; s[i] && n < len; i++) { if((s[i] & 0xc0) != 0x80) /* start of character */ n++; putchar(s[i]); @@ -18,26 +19,27 @@ printutf8padded(const char *s, size_t len) { } int -main(void) { +main(int argc, char **argv) { char *line = NULL, *fields[FieldLast]; time_t parsedtime, comparetime; + int isnew; size_t size = 0; - tzset(); comparetime = time(NULL) - (3600 * 24); /* 1 day is old news */ - while(parseline(&line, &size, fields, FieldLast, stdin, FieldSeparator) > 0) { + while(parseline(&line, &size, fields, FieldLast, '\t', stdin) > 0) { + isnew = (parsedtime >= comparetime); parsedtime = (time_t)strtol(fields[FieldUnixTimestamp], NULL, 10); - printf(" %c ", (parsedtime >= comparetime) ? 'N' : ' '); + printf(" %c ", isnew ? 'N' : ' '); if(fields[FieldFeedName][0] != '\0') printf("%-15.15s ", fields[FieldFeedName]); - fputs(fields[FieldTimeFormatted], stdout); + printf("%-30.30s", fields[FieldTimeFormatted]); fputs(" ", stdout); printutf8padded(fields[FieldTitle], 70); fputs(" ", stdout); if(fields[FieldBaseSiteUrl][0] != '\0') - printlink(fields[FieldLink], fields[FieldBaseSiteUrl]); + printlink(fields[FieldLink], fields[FieldBaseSiteUrl], stdout); else - printlink(fields[FieldLink], fields[FieldFeedUrl]); + printlink(fields[FieldLink], fields[FieldFeedUrl], stdout); putchar('\n'); } free(line);