abaco: remove unused stuff, move pipeline() into util.c
This commit is contained in:
parent
1bc8f69780
commit
a7a90b2f3c
3 changed files with 12 additions and 116 deletions
|
@ -66,7 +66,7 @@ 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 *);
|
||||||
int findctype(char *, int, char *, char *);
|
int findctype(char *, int, char *, char *);
|
||||||
void execproc(void *);
|
int pipeline(int fd, char *cmd, ...);
|
||||||
void getimage(Cimage *, Rune *);
|
void getimage(Cimage *, Rune *);
|
||||||
Point getpt(Page *p, Point);
|
Point getpt(Page *p, Point);
|
||||||
Rune *urlcombine(Rune *, Rune *);
|
Rune *urlcombine(Rune *, Rune *);
|
||||||
|
|
|
@ -146,40 +146,6 @@ 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)
|
||||||
|
|
|
@ -655,7 +655,7 @@ validurl(Rune *r)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
execproc(void *v)
|
execproc(void *v)
|
||||||
{
|
{
|
||||||
Channel *sync;
|
Channel *sync;
|
||||||
|
@ -687,107 +687,37 @@ execproc(void *v)
|
||||||
error("can't exec");
|
error("can't exec");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
int
|
||||||
writeproc(void *v)
|
pipeline(int fd, char *cmd, ...)
|
||||||
{
|
|
||||||
Channel *sync;
|
|
||||||
void **a;
|
|
||||||
char *s;
|
|
||||||
long np;
|
|
||||||
int fd, i, n;
|
|
||||||
|
|
||||||
threadsetname("writeproc");
|
|
||||||
a = v;
|
|
||||||
sync = a[0];
|
|
||||||
fd = (int)a[1];
|
|
||||||
s = a[2];
|
|
||||||
np =(long)a[3];
|
|
||||||
free(a);
|
|
||||||
|
|
||||||
for(i=0; i<np; i+=n){
|
|
||||||
n = np-i;
|
|
||||||
if(n > BUFSIZE)
|
|
||||||
n = BUFSIZE;
|
|
||||||
if(write(fd, s+i, n) != n)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
sendul(sync, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
uhtml(char *cs, char *s, long *np)
|
|
||||||
{
|
{
|
||||||
Channel *sync;
|
Channel *sync;
|
||||||
Exec *e;
|
Exec *e;
|
||||||
long i, n;
|
|
||||||
void **a;
|
|
||||||
char buf[BUFSIZE], cmd[50];
|
|
||||||
char *t;
|
|
||||||
int p[2], q[2];
|
int p[2], q[2];
|
||||||
|
va_list a;
|
||||||
if(s==nil || *s=='\0' || *np==0){
|
|
||||||
werrstr("uhtml failed: no data");
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pipe(p)<0 || pipe(q)<0)
|
if(pipe(p)<0 || pipe(q)<0)
|
||||||
error("can't create pipe");
|
error("can't create pipe");
|
||||||
|
close(p[0]);
|
||||||
|
p[0] = fd;
|
||||||
sync = chancreate(sizeof(ulong), 0);
|
sync = chancreate(sizeof(ulong), 0);
|
||||||
if(sync == nil)
|
if(sync == nil)
|
||||||
error("can't create channel");
|
error("can't create channel");
|
||||||
|
|
||||||
snprint(cmd, sizeof cmd, (cs != nil && *cs != '\0') ? "uhtml -c %s" : "uthml", cs);
|
|
||||||
e = emalloc(sizeof(Exec));
|
e = emalloc(sizeof(Exec));
|
||||||
e->p[0] = p[0];
|
e->p[0] = p[0];
|
||||||
e->p[1] = p[1];
|
e->p[1] = p[1];
|
||||||
e->q[0] = q[0];
|
e->q[0] = q[0];
|
||||||
e->q[1] = q[1];
|
e->q[1] = q[1];
|
||||||
e->cmd = cmd;
|
va_start(a, cmd);
|
||||||
|
e->cmd = vsmprint(cmd, a);
|
||||||
|
va_end(a);
|
||||||
e->sync = sync;
|
e->sync = sync;
|
||||||
proccreate(execproc, e, STACK);
|
proccreate(execproc, e, STACK);
|
||||||
recvul(sync);
|
recvul(sync);
|
||||||
chanfree(sync);
|
chanfree(sync);
|
||||||
close(p[0]);
|
close(p[0]);
|
||||||
|
close(p[1]);
|
||||||
close(q[1]);
|
close(q[1]);
|
||||||
|
return q[0];
|
||||||
/* in case uhtml fails */
|
|
||||||
t = s;
|
|
||||||
sync = chancreate(sizeof(ulong), 0);
|
|
||||||
if(sync == nil)
|
|
||||||
error("can't create channel");
|
|
||||||
|
|
||||||
a = emalloc(4*sizeof(void *));
|
|
||||||
a[0] = sync;
|
|
||||||
a[1] = (void *)p[1];
|
|
||||||
a[2] = s;
|
|
||||||
a[3] = (void *)*np;
|
|
||||||
proccreate(writeproc, a, STACK);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
s = nil;
|
|
||||||
while((n = read(q[0], buf, sizeof(buf))) > 0){
|
|
||||||
s = erealloc(s, i+n+1);
|
|
||||||
memmove(s+i, buf, n);
|
|
||||||
i += n;
|
|
||||||
s[i] = '\0';
|
|
||||||
}
|
|
||||||
n = recvul(sync);
|
|
||||||
if(n != *np)
|
|
||||||
fprint(2, "uhtml failed: did not write %ld; wrote %uld\n", *np, n);
|
|
||||||
|
|
||||||
*np = i;
|
|
||||||
chanfree(sync);
|
|
||||||
close(q[0]);
|
|
||||||
|
|
||||||
if(s == nil){
|
|
||||||
fprint(2, "uhtml failed: can't convert charset=%s\n", cs);
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
free(t);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue