uhtml: scan tags only, fix cat fallback, usage, cleanup
This commit is contained in:
parent
6512bbc679
commit
0a9ae3758c
|
@ -9,16 +9,23 @@ char *cset = nil;
|
||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprint(2, "%s [ -h ] [ -c charset ] [ file ]\n", argv0);
|
fprint(2, "%s [ -p ] [ -c charset ] [ file ]\n", argv0);
|
||||||
exits("usage");
|
exits("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
strval(char *s)
|
attr(char *s, char *a)
|
||||||
{
|
{
|
||||||
char *e, q;
|
char *e, q;
|
||||||
|
|
||||||
while(strchr("\t ", *s))
|
if((s = cistrstr(s, a)) == nil)
|
||||||
|
return nil;
|
||||||
|
s += strlen(a);
|
||||||
|
while(strchr("\r\n\t ", *s))
|
||||||
|
s++;
|
||||||
|
if(*s++ != '=')
|
||||||
|
return nil;
|
||||||
|
while(strchr("\r\n\t ", *s))
|
||||||
s++;
|
s++;
|
||||||
q = 0;
|
q = 0;
|
||||||
if(*s == '"' || *s == '\'')
|
if(*s == '"' || *s == '\'')
|
||||||
|
@ -41,18 +48,18 @@ void
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int n, pfd[2], pflag = 0;
|
int n, pfd[2], pflag = 0;
|
||||||
char *arg[4], *s, *p;
|
char *arg[4], *s, *e, *p, *g, t;
|
||||||
Rune r;
|
Rune r;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'h':
|
|
||||||
usage();
|
|
||||||
case 'c':
|
case 'c':
|
||||||
cset = EARGF(usage());
|
cset = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
pflag = 1;
|
pflag = 1;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
if(*argv){
|
if(*argv){
|
||||||
|
@ -62,6 +69,7 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
nbuf = 0;
|
nbuf = 0;
|
||||||
p = buf;
|
p = buf;
|
||||||
|
g = buf;
|
||||||
while(nbuf < sizeof(buf)-1){
|
while(nbuf < sizeof(buf)-1){
|
||||||
if((n = read(0, buf + nbuf, sizeof(buf)-1-nbuf)) <= 0)
|
if((n = read(0, buf + nbuf, sizeof(buf)-1-nbuf)) <= 0)
|
||||||
break;
|
break;
|
||||||
|
@ -84,16 +92,22 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(s = cistrstr(p, "encoding="))
|
s = g;
|
||||||
if(s = strval(s+9)){
|
do {
|
||||||
cset = s;
|
if((s = strchr(s, '<')) == nil)
|
||||||
break;
|
break;
|
||||||
}
|
g = s;
|
||||||
if(s = cistrstr(p, "charset="))
|
if((e = strchr(++s, '>')) == nil)
|
||||||
if(s = strval(s+8)){
|
e = buf+nbuf;
|
||||||
cset = s;
|
t = *e;
|
||||||
|
*e = 0;
|
||||||
|
if((cset = attr(s, "encoding")) || (cset = attr(s, "charset"))){
|
||||||
|
*e = t;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
*e = t;
|
||||||
|
s = ++e;
|
||||||
|
} while(t);
|
||||||
}
|
}
|
||||||
nbuf -= p - buf;
|
nbuf -= p - buf;
|
||||||
|
|
||||||
|
@ -132,7 +146,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
arg[0] = "rc";
|
arg[0] = "rc";
|
||||||
arg[1] = "-c";
|
arg[1] = "-c";
|
||||||
arg[2] = smprint("{tcs -f %s | tcs -f html} || cat", cset);
|
arg[2] = smprint("{tcs -f %s || cat} | tcs -f html", cset);
|
||||||
arg[3] = nil;
|
arg[3] = nil;
|
||||||
exec("/bin/rc", arg);
|
exec("/bin/rc", arg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue