Skip to content

Commit 8df6013

Browse files
committed
unifies both html functions.
1 parent 994bb39 commit 8df6013

File tree

1 file changed

+10
-57
lines changed

1 file changed

+10
-57
lines changed

rssfill.c

+10-57
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ usage(void)
2525
}
2626

2727
char*
28-
cdatahtml(char *text)
28+
parsehtml(char *text, int *variable, char *c1, char *c2, char *c3, char *c4)
2929
{
3030
char *s, buf[8192];
3131
String *str;
3232
int n, m, written;
3333
int p[2];
3434

35-
dohtml = 0;
35+
*variable = 0;
3636

3737
if (pipe(p) < 0)
3838
sysfatal("pipe: %r");
@@ -49,64 +49,14 @@ cdatahtml(char *text)
4949
dup(p[1], 1);
5050
close(p[1]);
5151
close(p[0]);
52-
execl("/bin/htmlfmt", "htmlfmt", "-cutf-8", nil);
52+
execl(c1, c2, c3, c4, nil);
5353
exits(nil);
5454
default:
5555
close(p[1]);
5656
str = s_new();
5757
written = 0;
58-
while (written < strlen(text) && (n = write(p[0], &text[written], strlen(&text[written]))) > 0){
59-
written += n;
60-
write(p[0], "", 0); // htmlfmt needs double flush, idk why
61-
write(p[0], "", 0);
62-
m = read(p[0], buf, 8191);
63-
buf[m] = 0;
64-
str = s_append(str, buf);
65-
}
66-
close(p[0]);
67-
while (waitpid() > 0)
68-
;
69-
s = strdup(s_to_c(str));
70-
s_free(str);
71-
}
72-
73-
if (s)
74-
return s;
75-
return strdup(text);
76-
}
77-
78-
char*
79-
dotypehtml(char *text)
80-
{
81-
char *s, buf[8192];
82-
String *str;
83-
int n, m, written;
84-
int p[2];
85-
86-
typehtml = 0;
87-
88-
if (pipe(p) < 0)
89-
sysfatal("pipe: %r");
90-
91-
s = nil;
92-
switch (fork()){
93-
case -1:
94-
close(p[0]);
95-
close(p[1]);
96-
return strdup(text);
97-
break;
98-
case 0:
99-
dup(p[1], 0);
100-
dup(p[1], 1);
101-
close(p[1]);
102-
close(p[0]);
103-
execl("/bin/rc", "rc", "-c", "uhtml | sed 's/&lt;/</g;s/&gt;/>/g;s/&amp;/&/g' | htmlfmt -cutf-8", nil);
104-
exits(nil);
105-
default:
106-
close(p[1]);
107-
str = s_new();
108-
written = 0;
109-
while (written < strlen(text) && (n = write(p[0], &text[written], strlen(&text[written]))) > 0){
58+
while (written < strlen(text) &&
59+
(n = write(p[0], &text[written], strlen(&text[written]))) > 0){
11060
written += n;
11161
write(p[0], "", 0); // htmlfmt needs double flush, idk why
11262
write(p[0], "", 0);
@@ -129,11 +79,14 @@ dotypehtml(char *text)
12979
char*
13080
html(char *text)
13181
{
82+
/* prefer CDATA */
13283
if (dohtml)
133-
return cdatahtml(text);
84+
return parsehtml(text, &dohtml, "/bin/htmlfmt", "htmlfmt", "-cutf-8", nil);
13485

13586
if (typehtml)
136-
return dotypehtml(text);
87+
return parsehtml(text, &typehtml,
88+
"/bin/rc", "rc", "-c",
89+
"uhtml | sed 's/&lt;/</g;s/&gt;/>/g;s/&amp;/&/g' | htmlfmt -cutf-8");
13790

13891
return strdup(text);
13992
}

0 commit comments

Comments
 (0)