Introduction
Introduction Statistics Contact Development Disclaimer Help
sfeed_plain.c - sfeed - RSS and Atom parser
git clone git://git.codemadness.org/sfeed
Log
Files
Refs
README
LICENSE
---
sfeed_plain.c (1858B)
---
1 #include <locale.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <time.h>
5
6 #include "util.h"
7
8 static time_t comparetime;
9 static char *line;
10 static size_t linesize;
11
12 static void
13 printfeed(FILE *fp, const char *feedname)
14 {
15 char *fields[FieldLast];
16 struct tm rtm, *tm;
17 time_t parsedtime;
18 ssize_t linelen;
19
20 while ((linelen = getline(&line, &linesize, fp)) > 0 &&
21 !ferror(stdout)) {
22 if (line[linelen - 1] == '\n')
23 line[--linelen] = '\0';
24 parseline(line, fields);
25
26 parsedtime = 0;
27 if (!strtotime(fields[FieldUnixTimestamp], &parsedtime) …
28 (tm = localtime_r(&parsedtime, &rtm))) {
29 if (parsedtime >= comparetime)
30 fputs("N ", stdout);
31 else
32 fputs(" ", stdout);
33 fprintf(stdout, "%04d-%02d-%02d %02d:%02d ",
34 tm->tm_year + 1900, tm->tm_mon + 1, tm->…
35 tm->tm_hour, tm->tm_min);
36 } else {
37 fputs(" ", stdout);
38 }
39
40 if (feedname[0]) {
41 printutf8pad(stdout, feedname, 15, ' ');
42 fputs(" ", stdout);
43 }
44 printutf8pad(stdout, fields[FieldTitle], 70, ' ');
45 printf(" %s\n", fields[FieldLink]);
46 }
47 }
48
49 int
50 main(int argc, char *argv[])
51 {
52 FILE *fp;
53 char *name;
54 int i;
55
56 if (pledge("stdio rpath", NULL) == -1)
57 err(1, "pledge");
58
59 setlocale(LC_CTYPE, "");
60
61 if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1)
62 err(1, "pledge");
63
64 if ((comparetime = getcomparetime()) == (time_t)-1)
65 errx(1, "getcomparetime");
66
67 if (argc == 1) {
68 printfeed(stdin, "");
69 checkfileerror(stdin, "<stdin>", 'r');
70 } else {
71 for (i = 1; i < argc; i++) {
72 if (!(fp = fopen(argv[i], "r")))
73 err(1, "fopen: %s", argv[i]);
74 name = ((name = strrchr(argv[i], '/'))) ? name +…
75 printfeed(fp, name);
76 checkfileerror(fp, argv[i], 'r');
77 checkfileerror(stdout, "<stdout>", 'w');
78 fclose(fp);
79 }
80 }
81 checkfileerror(stdout, "<stdout>", 'w');
82
83 return 0;
84 }
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.