Skip to content

Commit dad23be

Browse files
committed
updates readme, includes htmlfmt for CDATA html stuff.
1 parent 62e0c14 commit dad23be

File tree

2 files changed

+70
-9
lines changed

2 files changed

+70
-9
lines changed

Readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ fetch data every hour or use a cronjob.
2121
Building and Installation
2222
-------------------------
2323

24-
**You need the `xmlpull` library. You can find it in `extra` (`9fs 9front`).**
24+
This package includes an updated version of `xmlpull` from contrib.
2525

2626
mk install

rssfill.c

+69-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <u.h>
22
#include <libc.h>
33
#include <bio.h>
4+
#include <String.h>
45
#include "xmlpull.h"
56
#include "rssfill.h"
67

@@ -10,6 +11,9 @@ char *prefix = "";
1011
int chatty = 0;
1112
int dry = 0;
1213

14+
int dohtml;
15+
int typehtml;
16+
1317
void
1418
usage(void)
1519
{
@@ -20,6 +24,59 @@ usage(void)
2024
exits("usage");
2125
}
2226

27+
char*
28+
html(char *text)
29+
{
30+
char *s, buf[8192];
31+
String *str;
32+
int n, m, written;
33+
int p[2];
34+
35+
if (!dohtml)
36+
return strdup(text);
37+
dohtml = 0;
38+
39+
if (pipe(p) < 0)
40+
sysfatal("pipe: %r");
41+
42+
s = nil;
43+
switch (fork()){
44+
case -1:
45+
close(p[0]);
46+
close(p[1]);
47+
return strdup(text);
48+
break;
49+
case 0:
50+
dup(p[1], 0);
51+
dup(p[1], 1);
52+
close(p[1]);
53+
close(p[0]);
54+
execl("/bin/htmlfmt", "htmlfmt", "-cutf-8", nil);
55+
exits(nil);
56+
default:
57+
close(p[1]);
58+
str = s_new();
59+
written = 0;
60+
while (written < strlen(text) && (n = write(p[0], &text[written], strlen(&text[written]))) > 0){
61+
written += n;
62+
write(p[0], "", 0); // htmlfmt needs double flush, idk why
63+
write(p[0], "", 0);
64+
m = read(p[0], buf, 8191);
65+
buf[m] = 0;
66+
str = s_append(str, buf);
67+
}
68+
close(p[0]);
69+
while (waitpid() > 0)
70+
;
71+
s = strdup(s_to_c(str));
72+
s_free(str);
73+
}
74+
75+
if (s)
76+
return s;
77+
return strdup(text);
78+
}
79+
2380
void
2481
writefeedfiles(Feed *f)
2582
{
@@ -208,7 +265,7 @@ main(int argc, char **argv)
208265
xmlpull *x, *a;
209266
char st;
210267
Feed *f, *r;
211-
268+
212269
ARGBEGIN {
213270
case 'd':
214271
directory = EARGF(usage());
@@ -223,14 +280,14 @@ main(int argc, char **argv)
223280
chatty = 1;
224281
break;
225282
} ARGEND;
226-
283+
227284
if(dry)
228285
chatty = 1;
229-
286+
230287
st = NONE;
231288
f = nil;
232289
r = nil;
233-
290+
234291
x = openxmlpull(0);
235292
while((a = nextxmlpull(x)) != nil && st != END){
236293
switch(a->ev){
@@ -277,25 +334,29 @@ main(int argc, char **argv)
277334
case ATTR:
278335
if(!strcmp(x->na, "href") && st == LINK)
279336
f->link = strdup(x->va);
337+
if(!strcmp(x->na, "type") && !cistrcmp(x->va, "html"))
338+
typehtml = 1;
280339
break;
281340
case CDATA:
341+
/* if typehtml AND cdata, do html */
342+
dohtml = typehtml;
282343
case TEXT:
283344
switch(st){
284345
case TITLE:
285346
if (!f->title || strlen(f->title) == 0)
286-
f->title = strdup(x->na);
347+
f->title = html(x->na);
287348
break;
288349
case LINK:
289350
if (!f->link || strlen(f->link) == 0)
290351
f->link = strdup(x->na);
291352
break;
292353
case DESC:
293354
if (!f->desc || strlen(f->desc) == 0)
294-
f->desc = strdup(x->na);
355+
f->desc = html(x->na);
295356
break;
296357
case CONTENT:
297358
if (!f->cont || strlen(f->cont) == 0)
298-
f->cont = strdup(x->na);
359+
f->cont = html(x->na);
299360
break;
300361
case DATE:
301362
if (!f->date || strlen(f->date) == 0)
@@ -362,6 +423,6 @@ main(int argc, char **argv)
362423
}
363424
}
364425
freexmlpull(x);
365-
freefeedt(r);
426+
// freefeedt(r);
366427
exits(nil);
367428
}

0 commit comments

Comments
 (0)