12 fprint(2, "%s [ -p ] [ -c charset ] [ file ]\n", argv0);
17 attr(char *s, char *a)
21 if((s = cistrstr(s, a)) == nil)
24 while(strchr("\r\n\t ", *s))
28 while(strchr("\r\n\t ", *s))
31 if(*s == '"' || *s == '\'')
38 if(*e == '-' || *e == '_')
43 return smprint("%.*s", (int)(e-s), s);
48 main(int argc, char *argv[])
50 int n, q, pfd[2], pflag = 0;
51 char *arg[4], *s, *e, *p, *g, *a, t;
56 cset = EARGF(usage());
67 if(open(*argv, OREAD) != 1)
73 while(nbuf < sizeof(buf)-1){
74 if((n = read(0, buf + nbuf, sizeof(buf)-1-nbuf)) <= 0)
79 if(memcmp(p, "\xEF\xBB\xBF", 3)==0){
84 if(memcmp(p, "\xFE\xFF", 2) == 0){
89 if(memcmp(p, "\xFF\xFE", 2) == 0){
97 if((s = strchr(s, '<')) == nil)
103 if(*s == '\'' || *s == '"'){
108 } else if(*s == '>' && q == 0){
116 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");