12 Term t; /* terminal characteristics */
18 enum { Notype = 0, Type = 1 };
20 static char *parse(char *s, int typeit) /* convert \0, etc to nroff driving table format */
21 { /* typeit => add a type id to the front for later use */
22 static char buf[100], *t, *obuf;
26 obuf = typeit == Type ? buf : buf+1;
28 if (mbtowc(&wc, s, strlen(s)) > 1) { /* it's multibyte, */
32 } /* so just hand it back */
41 if (quote && *s == '"') {
45 if (!quote && (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\0'))
51 if (isdigit(s[0]) && isdigit(s[1]) && isdigit(s[2])) {
52 *t++ = (s[0]-'0')<<6 | (s[1]-'0')<<3 | s[2]-'0';
54 } else if (isdigit(s[0])) {
56 } else if (*s == 'b') {
58 } else if (*s == 'n') {
60 } else if (*s == 'r') {
62 } else if (*s == 't') {
75 static int getnrfont(FILE *fp) /* read the nroff description file */
80 int i, nw, n, wid, code, type;
81 char buf[100], ch[100], s1[100], s2[100], cmd[300];
87 for (i = 0; i < ALPHABET; i++) {
88 chtemp[i] = chinit; /* zero out to begin with */
89 chtemp[i].num = chtemp[i].code = i; /* every alphabetic character is itself */
90 chtemp[i].wid = 1; /* default ascii widths */
94 while (fgets(buf, sizeof buf, fp) != NULL) {
95 sscanf(buf, "%s %s %[^\n]", ch, s1, s2);
96 if (!eq(s1, "\"")) { /* genuine new character */
97 sscanf(s1, "%d", &wid);
98 } /* else it's a synonym for prev character, */
99 /* so leave previous values intact */
101 /* decide what kind of alphabet it might come from */
103 if (strlen(ch) == 1) { /* it's ascii */
104 n = ch[0]; /* origin includes non-graphics */
105 chtemp[n].num = ch[0];
106 } else if (ch[0] == '\\' && ch[1] == '0') {
107 n = strtol(ch+1, 0, 0); /* \0octal or \0xhex */
110 } else if (mbtowc(&wc, ch, strlen(ch)) > 1) {
111 chtemp[nw].num = chadd(ch, MBchar, Install);
116 if (strcmp(ch, "---") == 0) { /* no name */
117 sprintf(ch, "%d", code);
121 /* BUG in here somewhere when same character occurs twice in table */
122 chtemp[nw].num = chadd(ch, type, Install);
127 chtemp[n].str = strdupl(parse(s2, Type));
130 t.tfont.wp = (Chwid *) malloc(nw * sizeof(Chwid));
131 if (t.tfont.wp == NULL)
133 for (i = 0; i < nw; i++)
134 t.tfont.wp[i] = chtemp[i];
143 char opt[50], cmd[100];
152 setslant = n_setslant;
165 if ((p = getenv("NROFFTERM")) != 0)
168 strcpy(termtab,DWBntermdir);
172 strcpy(devname, NDEVNAME);
181 fontlab[4] = PAIR('B','I');
186 /* hyphalg = 0; /* for testing */
188 strcat(termtab, devname);
189 if ((fp = fopen(termtab, "r")) == NULL) {
190 ERROR "cannot open %s", termtab WARN;
195 /* this loop isn't robust about input format errors. */
196 /* it assumes name, name-value pairs..., charset */
197 /* god help us if we get out of sync. */
199 fscanf(fp, "%s", cmd); /* should be device name... */
200 if (!is(devname) && trace)
201 ERROR "wrong terminal name: saw %s, wanted %s", cmd, devname WARN;
203 fscanf(fp, "%s", cmd);
206 fscanf(fp, " %[^\n]", opt);
207 if (is("bset")) t.bset = atoi(opt);
208 else if (is("breset")) t.breset = atoi(opt);
209 else if (is("Hor")) t.Hor = atoi(opt);
210 else if (is("Vert")) t.Vert = atoi(opt);
211 else if (is("Newline")) t.Newline = atoi(opt);
212 else if (is("Char")) t.Char = atoi(opt);
213 else if (is("Em")) t.Em = atoi(opt);
214 else if (is("Halfline")) t.Halfline = atoi(opt);
215 else if (is("Adj")) t.Adj = atoi(opt);
216 else if (is("twinit")) t.twinit = strdupl(parse(opt, Notype));
217 else if (is("twrest")) t.twrest = strdupl(parse(opt, Notype));
218 else if (is("twnl")) t.twnl = strdupl(parse(opt, Notype));
219 else if (is("hlr")) t.hlr = strdupl(parse(opt, Notype));
220 else if (is("hlf")) t.hlf = strdupl(parse(opt, Notype));
221 else if (is("flr")) t.flr = strdupl(parse(opt, Notype));
222 else if (is("bdon")) t.bdon = strdupl(parse(opt, Notype));
223 else if (is("bdoff")) t.bdoff = strdupl(parse(opt, Notype));
224 else if (is("iton")) t.iton = strdupl(parse(opt, Notype));
225 else if (is("itoff")) t.itoff = strdupl(parse(opt, Notype));
226 else if (is("ploton")) t.ploton = strdupl(parse(opt, Notype));
227 else if (is("plotoff")) t.plotoff = strdupl(parse(opt, Notype));
228 else if (is("up")) t.up = strdupl(parse(opt, Notype));
229 else if (is("down")) t.down = strdupl(parse(opt, Notype));
230 else if (is("right")) t.right = strdupl(parse(opt, Notype));
231 else if (is("left")) t.left = strdupl(parse(opt, Notype));
233 ERROR "bad tab.%s file, %s %s", devname, cmd, opt WARN;
242 for (i = 0; i < 16; i++)
243 tabtab[i] = dtab * (i + 1);
248 ll = ll1 = lt = lt1 = LL;
249 smnt = nfonts = 5; /* R I B BI S */
250 n_specnames(); /* install names like "hyphen", etc. */
256 void n_specnames(void)
261 for (i = 0; spnames[i].n; i++)
262 *spnames[i].n = chadd(spnames[i].v, Troffchar, Install);
264 c_isalnum = NROFFCHARS;
269 if (!TROFF && t.twrest) {
281 void n_ptout(Tchar i)
284 if (olinep >= &oline[LNSIZE])
286 if (cbits(i) != '\n')
289 lead += dip->blss + lss - t.Newline;
292 if (olinep > oline) {
312 static int oxfont = FT; /* start off in roman */
314 for (q = oline; q < olinep; q++) {
326 if ((k = cbits(i)) <= ' ') {
340 phyw = w = t.Char * t.tfont.wp[k].wid;
347 if (xfont != oxfont) {
349 case ULFONT: oputs(t.itoff); break;
350 case BDFONT: oputs(t.bdoff); break;
351 case BIFONT: oputs(t.itoff); oputs(t.bdoff); break;
355 if (*t.iton & 0377) oputs(t.iton); break;
357 if (*t.bdon & 0377) oputs(t.bdon); break;
359 if (*t.bdon & 0377) oputs(t.bdon);
360 if (*t.iton & 0377) oputs(t.iton);
365 if ((xfont == ulfont || xfont == BIFONT) && !(*t.iton & 0377)) {
366 for (j = w / t.Char; j > 0; j--)
368 for (j = w / t.Char; j > 0; j--)
371 if (!(*t.bdon & 0377) && ((j = bdtab[xfont]) || xfont == BDFONT || xfont == BIFONT))
374 j = 1; /* number of overstrikes for bold */
375 if (k < ALPHABET) { /* ordinary ascii */
381 } else if (k >= t.tfont.nchars) { /* BUG -- not really understood */
382 /* fprintf(stderr, "big char %d, name %s\n", k, chname(k)); /* */
383 oputs(chname(k)+1); /* BUG: should separate Troffchar and MBchar... */
384 } else if (t.tfont.wp[k].str == 0) {
385 /* fprintf(stderr, "nostr char %d, name %s\n", k, chname(k)); /* */
386 oputs(chname(k)+1); /* BUG: should separate Troffchar and MBchar... */
387 } else if (t.tfont.wp[k].str[0] == MBchar) { /* parse() puts this on */
388 /* fprintf(stderr, "MBstr char %d, name %s\n", k, chname(k)); /* */
389 oputs(t.tfont.wp[k].str+1);
392 /* fprintf(stderr, "str char %d, name %s\n", k, chname(k)); /* */
393 codep = t.tfont.wp[k].str+1; /* Troffchar by default */
394 while (*codep != 0) {
399 if (*codep == '%') /* escape */
402 if (*codep == '\033')
404 else if (*codep != '\b')
405 for (j = oj; --j > 0; ) {
414 for (j = phyw / t.Char; j > 0; j--)
427 if ((*k & 0377) == 0200)
430 if (*k == '%') { /* quote char within plot mode */
432 } else if (*k & 0200) {
444 if ((i = *k & 037) == 0) { /* 2nd 0200 turns it off */
477 /* if(!esct)i = t.flr; else i = "\0";*/
482 k = lead / t.Newline;
483 lead = lead % t.Newline;
488 k = lead / t.Halfline;
489 lead = lead % t.Halfline;
492 } else { /* no half-line forward, not at line begining */
493 k = lead / t.Newline;
494 lead = lead % t.Newline;
510 while ((dt = dtab - (iesct % dtab)) <= esc) {
523 if ((*t.ploton & 0377) && (esc || lead)) {
543 void n_ptpause(void )