4 * Translate Unicode to HTML by asking tcs(1).
5 * This way we don't have yet another table.
12 static Rune **tcscache[256];
19 if(tcscache[r>>8] && tcscache[r>>8][r&0xFF])
20 return tcscache[r>>8][r&0xFF];
33 execl("/bin/tcs", "tcs", "-t", "html", nil);
37 Binit(&b, p[0], OREAD);
41 /* HACK: extra newlines force rune+\n through tcs now */
42 fprint(fd, "%C\n\n\n\n", r);
43 q = Brdline(&b, '\n');
44 while (q != nil && *q == '\n')
45 q = Brdline(&b, '\n');
47 sysfatal("tcs: early eof");
48 q[Blinelen(&b)-1] = 0;
49 if(tcscache[r>>8] == nil)
50 tcscache[r>>8] = emalloc(256*sizeof tcscache[0][0]);
51 tcscache[r>>8][r&0xFF] = erunesmprint("%s", q);
52 return tcscache[r>>8][r&0xFF];
56 * Translate troff to Unicode by looking in troff's utfmap.
57 * This way we don't have yet another hard-coded table.
59 typedef struct Trtab Trtab;
66 static Trtab trtab[200];
69 static Trtab trinit[] =
82 char *file, *f[10], *p, s[3];
86 if(rs[0] >= Runeself || rs[1] >= Runeself)
92 for(i=0; i<nelem(trinit) && ntrtab < nelem(trtab); i++){
93 trtab[ntrtab] = trinit[i];
96 file = "/sys/lib/troff/font/devutf/utfmap";
97 if((b = Bopen(file, OREAD)) == nil)
98 sysfatal("open %s: %r", file);
99 while((p = Brdline(b, '\n')) != nil){
100 p[Blinelen(b)-1] = 0;
101 nf = getfields(p, f, nelem(f), 0, "\t");
102 for(i=0; i+2<=nf && ntrtab<nelem(trtab); i+=2){
103 chartorune(&trtab[ntrtab].r, f[i]);
104 memmove(trtab[ntrtab].t, f[i+1], 2);
110 if(ntrtab >= nelem(trtab))
111 fprint(2, "%s: trtab too small\n", argv0);
114 for(i=0; i<ntrtab; i++)
115 if(strcmp(s, trtab[i].t) == 0)