ref: f22bc11bf8add2bc897559f9bdd3570bcddf1384
parent: d649b6ec7abe5cddde70d7d14ee2eea6787e4150
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sun Jul 14 14:31:07 EDT 2013
abaco: simplify, pipeline html directly thru uhtml
--- a/sys/src/cmd/abaco/fns.h
+++ b/sys/src/cmd/abaco/fns.h
@@ -65,7 +65,7 @@
int forceitem(Item *);
int xtofchar(Rune *, Font *, long);
int istextsel(Page *, Rectangle, int *, int *, Rune *, Font *);
-char* convert(Runestr, char *, long *);
+int findctype(char *, int, char *, char *);
void execproc(void *);
void getimage(Cimage *, Rune *);
Point getpt(Page *p, Point);
--- a/sys/src/cmd/abaco/page.c
+++ b/sys/src/cmd/abaco/page.c
@@ -147,33 +147,14 @@
}
static
-Cimage *
-loadimg(Rune *src, int x , int y)
+int
+pipeline(int fd, char *cmd, ...)
{Channel *sync;
- Cimage *ci;
- Runestr rs;
Exec *e;
- char *filter;
- int fd, p[2], q[2];
+ int p[2], q[2];
+ va_list a;
- ci = emalloc(sizeof(Cimage));
- rs. r = src;
- rs.nr = runestrlen(rs.r);
- ci->url = urlalloc(&rs, nil, HGet);
- fd = urlopen(ci->url);
- if(fd < 0){- Err1:
- return ci;
- }
- filter = getfilter(ci->url->ctype.r, x, y);
- if(filter == nil){- werrstr("%S unsupported: %S", ci->url->ctype.r, ci->url->act.r);- Err2:
- close(fd);
- goto Err1;
- }
-
if(pipe(p)<0 || pipe(q)<0)
error("can't create pipe");close(p[0]);
@@ -186,7 +167,9 @@
e->p[1] = p[1];
e->q[0] = q[0];
e->q[1] = q[1];
- e->cmd = filter;
+ va_start(a, cmd);
+ e->cmd = vsmprint(cmd, a);
+ va_end(a);
e->sync = sync;
proccreate(execproc, e, STACK);
recvul(sync);
@@ -194,14 +177,44 @@
close(p[0]);
close(p[1]);
close(q[1]);
+ return q[0];
+}
- ci->mi = readmemimage(q[0]);
- close(q[0]);
+static
+Cimage *
+loadimg(Rune *src, int x , int y)
+{+ Cimage *ci;
+ Runestr rs;
+ char *filter;
+ int fd;
+
+ ci = emalloc(sizeof(Cimage));
+ rs. r = src;
+ rs.nr = runestrlen(rs.r);
+ ci->url = urlalloc(&rs, nil, HGet);
+ fd = urlopen(ci->url);
+ if(fd < 0){+ Err1:
+ return ci;
+ }
+ filter = getfilter(ci->url->ctype.r, x, y);
+ if(filter == nil){+ werrstr("%S unsupported: %S", ci->url->ctype.r, ci->url->act.r);+ Err2:
+ close(fd);
+ goto Err1;
+ }
+ fd = pipeline(fd, "%s", filter);
+ free(filter);
+ if(fd < 0)
+ goto Err2;
+ ci->mi = readmemimage(fd);
+ close(fd);
if(ci->mi == nil){ werrstr("can't read image");goto Err2;
}
- free(filter);
return ci;
}
@@ -262,7 +275,7 @@
pageloadproc(void *v)
{Page *p;
- char buf[BUFSIZE], *s;
+ char buf[BUFSIZE], cs[32], *s;
long n, l;
int fd, i, ctype;
@@ -297,7 +310,17 @@
goto Err;
}
addrefresh(p, "loading: %S...", p->url->src.r);
+
s = nil;
+ if(p->url->ctype.nr > 0){+ snprint(buf, sizeof(buf), "%.*S", p->url->ctype.nr, p->url->ctype.r);
+ if(findctype(cs, sizeof(cs), "charset", buf) == 0)
+ s = cs;
+ }
+ if((fd = pipeline(fd, s != nil ? "uhtml -c %q" : "uhtml", s)) < 0)
+ goto Err;
+
+ s = nil;
l = 0;
while((n=read(fd, buf, sizeof(buf))) > 0){ if(p->aborting){@@ -315,7 +338,6 @@
close(fd);
n = l;
if(s){- s = convert(p->url->ctype, s, &n);
p->items = parsehtml((uchar *)s, n, p->url->act.r, ctype, UTF_8, &p->doc);
free(s);
fixtext(p);
--- a/sys/src/cmd/abaco/util.c
+++ b/sys/src/cmd/abaco/util.c
@@ -797,7 +797,6 @@
return c==' ' || c== '\t' || c=='\r' || c=='\n';
}
-static
int
findctype(char *b, int l, char *keyword, char *s)
{@@ -834,19 +833,6 @@
return -1;
snprint(b, l, "%.*s", i, p);
return 0;
-}
-
-char *
-convert(Runestr ctype, char *s, long *np)
-{- char t[25], buf[256];
-
- *t = '\0';
- if(ctype.nr){- snprint(buf, sizeof(buf), "%.*S", ctype.nr, ctype.r);
- findctype(t, sizeof(t), "charset", buf);
- }
- return uhtml(t, s, np);
}
int
--
⑨