12 fprint(2, "%s [ -h ] [ -c charset ] [ file ]\n", argv0);
21 while(strchr("\t ", *s))
24 if(*s == '"' || *s == '\'')
31 if(*e == '-' || *e == '_')
36 return smprint("%.*s", (int)(e-s), s);
41 main(int argc, char *argv[])
43 int n, pfd[2], pflag = 0;
51 cset = EARGF(usage());
60 if(open(*argv, OREAD) != 1)
65 while(nbuf < sizeof(buf)-1){
66 if((n = read(0, buf + nbuf, sizeof(buf)-1-nbuf)) <= 0)
71 if(memcmp(p, "\xEF\xBB\xBF", 3)==0){
76 if(memcmp(p, "\xFE\xFF", 2) == 0){
81 if(memcmp(p, "\xFF\xFE", 2) == 0){
87 if(s = cistrstr(p, "encoding="))
92 if(s = cistrstr(p, "charset="))
103 while(s+UTFmax < p+nbuf){
104 s += chartorune(&r, s);
123 sysfatal("pipe: %r");
125 switch(rfork(RFFDG|RFREND|RFPROC)){
127 sysfatal("fork: %r");
135 arg[2] = smprint("{tcs -f %s | tcs -f html} || cat", cset);
137 exec("/bin/rc", arg);
145 if(write(1, p, nbuf) != nbuf)
146 sysfatal("write: %r");
148 if((nbuf = read(0, p, sizeof(buf))) < 0)
149 sysfatal("read: %r");