summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2013-05-20 19:32:22 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2013-05-20 19:32:22 +0200
commita4a8c9f7992dbbf0a636aef3982039b73b31e455 (patch)
tree8fbe06a86d147c41c4e2215a072af3e303f93a81
parent3003c3ab6912570f3ee01a99971bd82f31180627 (diff)
update sfeed_plain: pad time format, make code more readable
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
-rw-r--r--sfeed_plain.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/sfeed_plain.c b/sfeed_plain.c
index 92509d5..d300c27 100644
--- 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);