ref: 994bb39e5d7079883a28d0d712d9ae2c39d787e3
parent: 82adf021cee0aba86e834af3a2f734936aef4f5a
author: sirjofri <[email protected]>
date: Tue Apr 20 07:12:05 EDT 2021
adds other html stuff, assumes html if CDATA.
--- a/rssfill.c
+++ b/rssfill.c
@@ -25,7 +25,7 @@
}
char*
-html(char *text)
+cdatahtml(char *text)
{
char *s, buf[8192];
String *str;
@@ -32,8 +32,6 @@
int n, m, written;
int p[2];
- if (!dohtml)
- return strdup(text);
dohtml = 0;
if (pipe(p) < 0)
@@ -77,6 +75,69 @@
return strdup(text);
}
+char*
+dotypehtml(char *text)
+{
+ char *s, buf[8192];
+ String *str;
+ int n, m, written;
+ int p[2];
+
+ typehtml = 0;
+
+ if (pipe(p) < 0)
+ sysfatal("pipe: %r");
+
+ s = nil;
+ switch (fork()){
+ case -1:
+ close(p[0]);
+ close(p[1]);
+ return strdup(text);
+ break;
+ case 0:
+ dup(p[1], 0);
+ dup(p[1], 1);
+ close(p[1]);
+ close(p[0]);
+ execl("/bin/rc", "rc", "-c", "uhtml | sed 's/</</g;s/>/>/g;s/&/&/g' | htmlfmt -cutf-8", nil);
+ exits(nil);
+ default:
+ close(p[1]);
+ str = s_new();
+ written = 0;
+ while (written < strlen(text) && (n = write(p[0], &text[written], strlen(&text[written]))) > 0){
+ written += n;
+ write(p[0], "", 0); // htmlfmt needs double flush, idk why
+ write(p[0], "", 0);
+ m = read(p[0], buf, 8191);
+ buf[m] = 0;
+ str = s_append(str, buf);
+ }
+ close(p[0]);
+ while (waitpid() > 0)
+ ;
+ s = strdup(s_to_c(str));
+ s_free(str);
+ }
+
+ if (s)
+ return s;
+ return strdup(text);
+}
+
+char*
+html(char *text)
+{
+ if (dohtml)
+ return cdatahtml(text);
+
+ if (typehtml)
+ return dotypehtml(text);
+
+ return strdup(text);
+}
+
Tm*
parsetime(Tm *t, char *s, int *validtime)
{
@@ -356,8 +417,8 @@
typehtml = 1;
break;
case CDATA:
- /* if typehtml AND cdata, do html */
- dohtml = typehtml;
+ /* not really correct, but assume CDATA is always html */
+ dohtml = 1;
case TEXT:
switch(st){
case TITLE: