abaco: simplify, pipeline html directly thru uhtml
This commit is contained in:
parent
1f850cbab1
commit
1bc8f69780
3 changed files with 53 additions and 45 deletions
|
@ -65,7 +65,7 @@ int istextfield(Item *);
|
||||||
int forceitem(Item *);
|
int forceitem(Item *);
|
||||||
int xtofchar(Rune *, Font *, long);
|
int xtofchar(Rune *, Font *, long);
|
||||||
int istextsel(Page *, Rectangle, int *, int *, Rune *, Font *);
|
int istextsel(Page *, Rectangle, int *, int *, Rune *, Font *);
|
||||||
char* convert(Runestr, char *, long *);
|
int findctype(char *, int, char *, char *);
|
||||||
void execproc(void *);
|
void execproc(void *);
|
||||||
void getimage(Cimage *, Rune *);
|
void getimage(Cimage *, Rune *);
|
||||||
Point getpt(Page *p, Point);
|
Point getpt(Page *p, Point);
|
||||||
|
|
|
@ -146,16 +146,48 @@ closeimages(Page *p)
|
||||||
p->ncimage = 0;
|
p->ncimage = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int
|
||||||
|
pipeline(int fd, char *cmd, ...)
|
||||||
|
{
|
||||||
|
Channel *sync;
|
||||||
|
Exec *e;
|
||||||
|
int p[2], q[2];
|
||||||
|
va_list a;
|
||||||
|
|
||||||
|
if(pipe(p)<0 || pipe(q)<0)
|
||||||
|
error("can't create pipe");
|
||||||
|
close(p[0]);
|
||||||
|
p[0] = fd;
|
||||||
|
sync = chancreate(sizeof(ulong), 0);
|
||||||
|
if(sync == nil)
|
||||||
|
error("can't create channel");
|
||||||
|
e = emalloc(sizeof(Exec));
|
||||||
|
e->p[0] = p[0];
|
||||||
|
e->p[1] = p[1];
|
||||||
|
e->q[0] = q[0];
|
||||||
|
e->q[1] = q[1];
|
||||||
|
va_start(a, cmd);
|
||||||
|
e->cmd = vsmprint(cmd, a);
|
||||||
|
va_end(a);
|
||||||
|
e->sync = sync;
|
||||||
|
proccreate(execproc, e, STACK);
|
||||||
|
recvul(sync);
|
||||||
|
chanfree(sync);
|
||||||
|
close(p[0]);
|
||||||
|
close(p[1]);
|
||||||
|
close(q[1]);
|
||||||
|
return q[0];
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
Cimage *
|
Cimage *
|
||||||
loadimg(Rune *src, int x , int y)
|
loadimg(Rune *src, int x , int y)
|
||||||
{
|
{
|
||||||
Channel *sync;
|
|
||||||
Cimage *ci;
|
Cimage *ci;
|
||||||
Runestr rs;
|
Runestr rs;
|
||||||
Exec *e;
|
|
||||||
char *filter;
|
char *filter;
|
||||||
int fd, p[2], q[2];
|
int fd;
|
||||||
|
|
||||||
ci = emalloc(sizeof(Cimage));
|
ci = emalloc(sizeof(Cimage));
|
||||||
rs. r = src;
|
rs. r = src;
|
||||||
|
@ -173,35 +205,16 @@ loadimg(Rune *src, int x , int y)
|
||||||
close(fd);
|
close(fd);
|
||||||
goto Err1;
|
goto Err1;
|
||||||
}
|
}
|
||||||
|
fd = pipeline(fd, "%s", filter);
|
||||||
if(pipe(p)<0 || pipe(q)<0)
|
free(filter);
|
||||||
error("can't create pipe");
|
if(fd < 0)
|
||||||
close(p[0]);
|
goto Err2;
|
||||||
p[0] = fd;
|
ci->mi = readmemimage(fd);
|
||||||
sync = chancreate(sizeof(ulong), 0);
|
close(fd);
|
||||||
if(sync == nil)
|
|
||||||
error("can't create channel");
|
|
||||||
e = emalloc(sizeof(Exec));
|
|
||||||
e->p[0] = p[0];
|
|
||||||
e->p[1] = p[1];
|
|
||||||
e->q[0] = q[0];
|
|
||||||
e->q[1] = q[1];
|
|
||||||
e->cmd = filter;
|
|
||||||
e->sync = sync;
|
|
||||||
proccreate(execproc, e, STACK);
|
|
||||||
recvul(sync);
|
|
||||||
chanfree(sync);
|
|
||||||
close(p[0]);
|
|
||||||
close(p[1]);
|
|
||||||
close(q[1]);
|
|
||||||
|
|
||||||
ci->mi = readmemimage(q[0]);
|
|
||||||
close(q[0]);
|
|
||||||
if(ci->mi == nil){
|
if(ci->mi == nil){
|
||||||
werrstr("can't read image");
|
werrstr("can't read image");
|
||||||
goto Err2;
|
goto Err2;
|
||||||
}
|
}
|
||||||
free(filter);
|
|
||||||
return ci;
|
return ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +275,7 @@ void
|
||||||
pageloadproc(void *v)
|
pageloadproc(void *v)
|
||||||
{
|
{
|
||||||
Page *p;
|
Page *p;
|
||||||
char buf[BUFSIZE], *s;
|
char buf[BUFSIZE], cs[32], *s;
|
||||||
long n, l;
|
long n, l;
|
||||||
int fd, i, ctype;
|
int fd, i, ctype;
|
||||||
|
|
||||||
|
@ -297,6 +310,16 @@ pageloadproc(void *v)
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
addrefresh(p, "loading: %S...", p->url->src.r);
|
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;
|
s = nil;
|
||||||
l = 0;
|
l = 0;
|
||||||
while((n=read(fd, buf, sizeof(buf))) > 0){
|
while((n=read(fd, buf, sizeof(buf))) > 0){
|
||||||
|
@ -315,7 +338,6 @@ pageloadproc(void *v)
|
||||||
close(fd);
|
close(fd);
|
||||||
n = l;
|
n = l;
|
||||||
if(s){
|
if(s){
|
||||||
s = convert(p->url->ctype, s, &n);
|
|
||||||
p->items = parsehtml((uchar *)s, n, p->url->act.r, ctype, UTF_8, &p->doc);
|
p->items = parsehtml((uchar *)s, n, p->url->act.r, ctype, UTF_8, &p->doc);
|
||||||
free(s);
|
free(s);
|
||||||
fixtext(p);
|
fixtext(p);
|
||||||
|
|
|
@ -797,7 +797,6 @@ isspace(char c)
|
||||||
return c==' ' || c== '\t' || c=='\r' || c=='\n';
|
return c==' ' || c== '\t' || c=='\r' || c=='\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
int
|
int
|
||||||
findctype(char *b, int l, char *keyword, char *s)
|
findctype(char *b, int l, char *keyword, char *s)
|
||||||
{
|
{
|
||||||
|
@ -836,19 +835,6 @@ findctype(char *b, int l, char *keyword, char *s)
|
||||||
return 0;
|
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
|
int
|
||||||
xtofchar(Rune *s, Font *f, long p)
|
xtofchar(Rune *s, Font *f, long p)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue