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) != 0)
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 == '=' && q == 0)
109 else if(*s == '\'' || *s == '"'){
115 else if(*s == '>' && q != '\'' && q != '"'){
119 else if(q == '=' && strchr(whitespace, *s) == nil)
125 if((a = attr(g, "encoding")) || (a = attr(g, "charset"))){
137 while(s+UTFmax < p+nbuf){
138 s += chartorune(&r, s);
157 sysfatal("pipe: %r");
159 switch(rfork(RFFDG|RFREND|RFPROC)){
161 sysfatal("fork: %r");
169 arg[2] = smprint("{tcs -f %s || cat} | tcs -f html", cset);
171 exec("/bin/rc", arg);
179 if(write(1, p, nbuf) != nbuf)
180 sysfatal("write: %r");
182 if((nbuf = read(0, p, sizeof(buf))) < 0)
183 sysfatal("read: %r");