8 char *whitespace = " \t\r\n";
13 fprint(2, "%s [ -p ] [ -c charset ] [ file ]\n", argv0);
18 attr(char *s, char *a)
22 if((s = cistrstr(s, a)) == nil)
25 while(*s && strchr(whitespace, *s))
29 while(*s && strchr(whitespace, *s))
32 if(*s == '"' || *s == '\'')
39 if(*e == '-' || *e == '_')
44 return smprint("%.*s", (int)(e - s), s);
49 main(int argc, char *argv[])
51 int n, q, pfd[2], pflag = 0;
52 char *arg[4], *s, *e, *p, *g, *a, t;
57 cset = EARGF(usage());
68 if(open(*argv, OREAD) != 1)
74 while(nbuf < sizeof(buf)-1){
75 if((n = read(0, buf + nbuf, sizeof(buf)-1-nbuf)) <= 0)
80 if(memcmp(p, "\xEF\xBB\xBF", 3)==0){
86 if(memcmp(p, "\xFE\xFF", 2) == 0){
92 if(memcmp(p, "\xFF\xFE", 2) == 0){
101 if((s = strchr(s, '<')) == nil)
107 if(*s == '\'' || *s == '"'){
112 } else if(*s == '>' && q == 0){
120 if((a = attr(g, "encoding")) || (a = attr(g, "charset"))){
130 while(s+UTFmax < p+nbuf){
131 s += chartorune(&r, s);
150 sysfatal("pipe: %r");
152 switch(rfork(RFFDG|RFREND|RFPROC)){
154 sysfatal("fork: %r");
162 arg[2] = smprint("{tcs -f %s || cat} | tcs -f html", cset);
164 exec("/bin/rc", arg);
172 if(write(1, p, nbuf) != nbuf)
173 sysfatal("write: %r");
175 if((nbuf = read(0, p, sizeof(buf))) < 0)
176 sysfatal("read: %r");