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(((uint)r&~0xFFFF) != 0){
20 /* The cache must grow a lot to handle them */
21 fprint(2, "%s: can't handle rune '%C'\n", argv0, r);
25 if(tcscache[r>>8] && tcscache[r>>8][r&0xFF])
26 return tcscache[r>>8][r&0xFF];
39 execl("/bin/tcs", "tcs", "-t", "html", nil);
43 Binit(&b, p[0], OREAD);
47 /* HACK: extra newlines force rune+\n through tcs now */
48 fprint(fd, "%C\n\n\n\n", r);
49 q = Brdline(&b, '\n');
50 while (q != nil && *q == '\n')
51 q = Brdline(&b, '\n');
53 sysfatal("tcs: early eof");
54 q[Blinelen(&b)-1] = 0;
55 if(tcscache[r>>8] == nil)
56 tcscache[r>>8] = emalloc(256*sizeof tcscache[0][0]);
57 tcscache[r>>8][r&0xFF] = erunesmprint("%s", q);
58 return tcscache[r>>8][r&0xFF];
62 * Translate troff to Unicode by looking in troff's utfmap.
63 * This way we don't have yet another hard-coded table.
65 typedef struct Trtab Trtab;
72 static Trtab trtab[200];
75 static Trtab trinit[] =
88 char *file, *f[10], *p, s[3];
92 if(rs[0] >= Runeself || rs[1] >= Runeself)
98 for(i=0; i<nelem(trinit) && ntrtab < nelem(trtab); i++){
99 trtab[ntrtab] = trinit[i];
102 file = "/sys/lib/troff/font/devutf/utfmap";
103 if((b = Bopen(file, OREAD)) == nil)
104 sysfatal("open %s: %r", file);
105 while((p = Brdline(b, '\n')) != nil){
106 p[Blinelen(b)-1] = 0;
107 nf = getfields(p, f, nelem(f), 0, "\t");
108 for(i=0; i+2<=nf && ntrtab<nelem(trtab); i+=2){
109 chartorune(&trtab[ntrtab].r, f[i]);
110 memmove(trtab[ntrtab].t, f[i+1], 2);
116 if(ntrtab >= nelem(trtab))
117 fprint(2, "%s: trtab too small\n", argv0);
120 for(i=0; i<ntrtab; i++)
121 if(strcmp(s, trtab[i].t) == 0)