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 (readutf8(&wc
, 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 */
79 int i
, nw
, n
, wid
, type
;
80 char buf
[100], ch
[100], s1
[100], s2
[100];
86 for (i
= 0; i
< ALPHABET
; i
++) {
87 chtemp
[i
] = chinit
; /* zero out to begin with */
88 chtemp
[i
].num
= chtemp
[i
].code
= i
; /* every alphabetic character is itself */
89 chtemp
[i
].wid
= 1; /* default ascii widths */
93 while (fgets(buf
, sizeof buf
, fp
) != NULL
) {
94 sscanf(buf
, "%s %s %[^\n]", ch
, s1
, s2
);
95 if (!eq(s1
, "\"")) { /* genuine new character */
96 sscanf(s1
, "%d", &wid
);
97 } /* else it's a synonym for prev character, */
98 /* so leave previous values intact */
100 /* decide what kind of alphabet it might come from */
102 if (strlen(ch
) == 1) { /* it's ascii */
103 n
= ch
[0]; /* origin includes non-graphics */
104 chtemp
[n
].num
= ch
[0];
105 } else if (ch
[0] == '\\' && ch
[1] == '0') {
106 n
= strtol(ch
+ 1, 0, 0); /* \0octal or \0xhex */
109 } else if (readutf8(&wc
, ch
) > 1) {
110 chtemp
[nw
].num
= chadd(ch
, MBchar
, Install
);
115 if (strcmp(ch
, "---") == 0) { /* no name */
116 sprintf(ch
, "%d", chtemp
[nw
].code
);
120 /* BUG in here somewhere when same character occurs twice in table */
121 chtemp
[nw
].num
= chadd(ch
, type
, Install
);
126 chtemp
[n
].str
= strdupl(parse(s2
, Type
));
129 t
.tfont
.wp
= (Chwid
*) malloc(nw
* sizeof(Chwid
));
130 if (t
.tfont
.wp
== NULL
)
132 for (i
= 0; i
< nw
; i
++)
133 t
.tfont
.wp
[i
] = chtemp
[i
];
142 char opt
[50], cmd
[100];
151 setslant
= n_setslant
;
164 if ((p
= getenv("NROFFTERM")) != 0)
167 strcpy(termtab
,DWBntermdir
);
171 strcpy(devname
, NDEVNAME
);
180 fontlab
[4] = PAIR('B','I');
185 /* hyphalg = 0; /* for testing */
187 strcat(termtab
, devname
);
188 if ((fp
= fopen(termtab
, "r")) == NULL
) {
189 ERROR
"cannot open %s", termtab WARN
;
194 /* this loop isn't robust about input format errors. */
195 /* it assumes name, name-value pairs..., charset */
196 /* god help us if we get out of sync. */
198 fscanf(fp
, "%s", cmd
); /* should be device name... */
199 if (!is(devname
) && trace
)
200 ERROR
"wrong terminal name: saw %s, wanted %s", cmd
, devname WARN
;
202 fscanf(fp
, "%s", cmd
);
205 fscanf(fp
, " %[^\n]", opt
);
206 if (is("bset")) t
.bset
= atoi(opt
);
207 else if (is("breset")) t
.breset
= atoi(opt
);
208 else if (is("Hor")) t
.Hor
= atoi(opt
);
209 else if (is("Vert")) t
.Vert
= atoi(opt
);
210 else if (is("Newline")) t
.Newline
= atoi(opt
);
211 else if (is("Char")) t
.Char
= atoi(opt
);
212 else if (is("Em")) t
.Em
= atoi(opt
);
213 else if (is("Halfline")) t
.Halfline
= atoi(opt
);
214 else if (is("Adj")) t
.Adj
= atoi(opt
);
215 else if (is("twinit")) t
.twinit
= strdupl(parse(opt
, Notype
));
216 else if (is("twrest")) t
.twrest
= strdupl(parse(opt
, Notype
));
217 else if (is("twnl")) t
.twnl
= strdupl(parse(opt
, Notype
));
218 else if (is("hlr")) t
.hlr
= strdupl(parse(opt
, Notype
));
219 else if (is("hlf")) t
.hlf
= strdupl(parse(opt
, Notype
));
220 else if (is("flr")) t
.flr
= strdupl(parse(opt
, Notype
));
221 else if (is("bdon")) t
.bdon
= strdupl(parse(opt
, Notype
));
222 else if (is("bdoff")) t
.bdoff
= strdupl(parse(opt
, Notype
));
223 else if (is("iton")) t
.iton
= strdupl(parse(opt
, Notype
));
224 else if (is("itoff")) t
.itoff
= strdupl(parse(opt
, Notype
));
225 else if (is("ploton")) t
.ploton
= strdupl(parse(opt
, Notype
));
226 else if (is("plotoff")) t
.plotoff
= strdupl(parse(opt
, Notype
));
227 else if (is("up")) t
.up
= strdupl(parse(opt
, Notype
));
228 else if (is("down")) t
.down
= strdupl(parse(opt
, Notype
));
229 else if (is("right")) t
.right
= strdupl(parse(opt
, Notype
));
230 else if (is("left")) t
.left
= strdupl(parse(opt
, Notype
));
232 ERROR
"bad tab.%s file, %s %s", devname
, cmd
, opt WARN
;
241 for (i
= 0; i
< 16; i
++)
242 tabtab
[i
] = dtab
* (i
+ 1);
247 ll
= ll1
= lt
= lt1
= LL
;
248 smnt
= nfonts
= 5; /* R I B BI S */
249 n_specnames(); /* install names like "hyphen", etc. */
255 void n_specnames(void)
260 for (i
= 0; spnames
[i
].n
; i
++)
261 *spnames
[i
].n
= chadd(spnames
[i
].v
, Troffchar
, Install
);
263 c_isalnum
= NROFFCHARS
;
268 if (!TROFF
&& t
.twrest
) {
280 void n_ptout(Tchar i
)
283 if (olinep
>= &oline
[LNSIZE
])
285 if (cbits(i
) != '\n')
288 lead
+= dip
->blss
+ lss
- t
.Newline
;
291 if (olinep
> oline
) {
311 static int oxfont
= FT
; /* start off in roman */
313 for (q
= oline
; q
< olinep
; q
++) {
325 if ((k
= cbits(i
)) <= ' ') {
339 phyw
= w
= t
.Char
* t
.tfont
.wp
[k
].wid
;
346 if (xfont
!= oxfont
) {
348 case ULFONT
: oputs(t
.itoff
); break;
349 case BDFONT
: oputs(t
.bdoff
); break;
350 case BIFONT
: oputs(t
.itoff
); oputs(t
.bdoff
); break;
354 if (*t
.iton
& 0377) oputs(t
.iton
); break;
356 if (*t
.bdon
& 0377) oputs(t
.bdon
); break;
358 if (*t
.bdon
& 0377) oputs(t
.bdon
);
359 if (*t
.iton
& 0377) oputs(t
.iton
);
364 if ((xfont
== ulfont
|| xfont
== BIFONT
) && !(*t
.iton
& 0377)) {
365 for (j
= w
/ t
.Char
; j
> 0; j
--)
367 for (j
= w
/ t
.Char
; j
> 0; j
--)
370 if (!(*t
.bdon
& 0377) && ((j
= bdtab
[xfont
]) || xfont
== BDFONT
|| xfont
== BIFONT
))
373 j
= 1; /* number of overstrikes for bold */
374 if (k
< ALPHABET
) { /* ordinary ascii */
380 } else if (k
>= t
.tfont
.nchars
) { /* BUG -- not really understood */
381 /* fprintf(stderr, "big char %d, name %s\n", k, chname(k)); /* */
382 oputs(chname(k
)+1); /* BUG: should separate Troffchar and MBchar... */
383 } else if (t
.tfont
.wp
[k
].str
== 0) {
384 /* fprintf(stderr, "nostr char %d, name %s\n", k, chname(k)); /* */
385 oputs(chname(k
)+1); /* BUG: should separate Troffchar and MBchar... */
386 } else if (t
.tfont
.wp
[k
].str
[0] == MBchar
) { /* parse() puts this on */
387 /* fprintf(stderr, "MBstr char %d, name %s\n", k, chname(k)); /* */
388 oputs(t
.tfont
.wp
[k
].str
+1);
391 /* fprintf(stderr, "str char %d, name %s\n", k, chname(k)); /* */
392 codep
= t
.tfont
.wp
[k
].str
+1; /* Troffchar by default */
393 while (*codep
!= 0) {
398 if (*codep
== '%') /* escape */
401 if (*codep
== '\033')
403 else if (*codep
!= '\b')
404 for (j
= oj
; --j
> 0; ) {
413 for (j
= phyw
/ t
.Char
; j
> 0; j
--)
426 if ((*k
& 0377) == 0200)
429 if (*k
== '%') { /* quote char within plot mode */
431 } else if (*k
& 0200) {
443 if ((i
= *k
& 037) == 0) { /* 2nd 0200 turns it off */
476 /* if(!esct)i = t.flr; else i = "\0";*/
481 k
= lead
/ t
.Newline
;
482 lead
= lead
% t
.Newline
;
487 k
= lead
/ t
.Halfline
;
488 lead
= lead
% t
.Halfline
;
491 } else { /* no half-line forward, not at line begining */
492 k
= lead
/ t
.Newline
;
493 lead
= lead
% t
.Newline
;
509 while ((dt
= dtab
- (iesct
% dtab
)) <= esc
) {
522 if ((*t
.ploton
& 0377) && (esc
|| lead
)) {
542 void n_ptpause(void )