1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2017 Gary Mills
24 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 /*
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
34 * All Rights Reserved
35 *
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
38 * contributors.
39 */
40
41 #include "tdef.h"
42 #include "tw.h"
43 #include "ext.h"
44 #include <ctype.h>
45
46 /*
47 * n6.c -- width functions, sizes and fonts
48 */
49
50 int bdtab[NFONT+1] ={ 0, 0, 0, 3, 3, 0, };
51 int sbold = 0;
52 int fontlab[NFONT+1] = { 0, 'R', 'I', 'B', PAIR('B','I'), 'S', 0 };
53
54 extern int nchtab;
55
56 int
width(j)57 width(j)
58 tchar j;
59 {
60 int i, k;
61
62 if (j & (ZBIT|MOT)) {
63 if (iszbit(j))
64 return(0);
65 if (isvmot(j))
66 return(0);
67 k = absmot(j);
68 if (isnmot(j))
69 k = -k;
70 return(k);
71 }
72 i = cbits(j);
73 if (i < ' ') {
74 if (i == '\b')
75 return(-widthp);
76 if (i == PRESC)
77 i = eschar;
78 else if (iscontrol(i))
79 return(0);
80 }
81 if (i==ohc)
82 return(0);
83 #ifdef EUC
84 #ifdef NROFF
85 if (multi_locale) {
86 if ((j & MBMASK) || (j & CSMASK)) {
87 switch(j & MBMASK) {
88 case BYTE_CHR:
89 case LASTOFMB:
90 k = t.Char * csi_width[cs(j)];
91 break;
92 default:
93 k = 0;
94 break;
95 }
96 widthp = k;
97 return(k);
98 }
99 }
100 i &= 0x1ff;
101 #endif /* NROFF */
102 #endif /* EUC */
103 i = trtab[i];
104 if (i < 32)
105 return(0);
106 k = t.width[i] * t.Char;
107 widthp = k;
108 return(k);
109 }
110
111
setch()112 tchar setch()
113 {
114 int j;
115 char temp[10];
116 char *s;
117
118 s = temp;
119 if ((*s++ = getach()) == 0 || (*s++ = getach()) == 0)
120 return(0);
121 *s = '\0';
122 if ((j = findch(temp)) > 0)
123 return j | chbits;
124 else
125 return 0;
126 }
127
setabs()128 tchar setabs() /* set absolute char from \C'...' */
129 { /* for now, a no-op */
130 int i, n, nf;
131
132 getch();
133 n = 0;
134 n = inumb(&n);
135 getch();
136 if (nonumb)
137 return 0;
138 return n + nchtab + _SPECCHAR_ST;
139 }
140
141 int
findft(i)142 findft(i)
143 int i;
144 {
145 int k;
146
147 if ((k = i - '0') >= 0 && k <= nfonts && k < smnt)
148 return(k);
149 for (k = 0; fontlab[k] != i; k++)
150 if (k > nfonts)
151 return(-1);
152 return(k);
153 }
154
155 int
caseps()156 caseps()
157 {
158 return (0);
159 }
160
161 int
mchbits()162 mchbits()
163 {
164 chbits = 0;
165 setfbits(chbits, font);
166 sps = width(' ' | chbits);
167
168 return (0);
169 }
170
171
172 int
setps()173 setps()
174 {
175 int i, j;
176
177 i = cbits(getch());
178 if (ischar(i) && isdigit(i)) { /* \sd or \sdd */
179 i -= '0';
180 if (i == 0) /* \s0 */
181 ;
182 else if (i <= 3 && ischar(j = cbits(ch = getch())) &&
183 isdigit(j)) { /* \sdd */
184 ch = 0;
185 }
186 } else if (i == '(') { /* \s(dd */
187 getch();
188 getch();
189 } else if (i == '+' || i == '-') { /* \s+, \s- */
190 j = cbits(getch());
191 if (ischar(j) && isdigit(j)) { /* \s+d, \s-d */
192 ;
193 } else if (j == '(') { /* \s+(dd, \s-(dd */
194 getch();
195 getch();
196 }
197 }
198
199 return (0);
200 }
201
202
setht()203 tchar setht() /* set character height from \H'...' */
204 {
205 tchar c;
206
207 getch();
208 (void) inumb(&apts);
209 getch();
210 return(0);
211 }
212
213
setslant()214 tchar setslant() /* set slant from \S'...' */
215 {
216 int n;
217 tchar c;
218
219 getch();
220 n = 0;
221 n = inumb(&n);
222 getch();
223 return(0);
224 }
225
226
227 int
caseft()228 caseft()
229 {
230 skip();
231 setfont(1);
232
233 return (0);
234 }
235
236
237 int
setfont(a)238 setfont(a)
239 int a;
240 {
241 int i, j;
242
243 if (a)
244 i = getrq();
245 else
246 i = getsn();
247 if (!i || i == 'P') {
248 j = font1;
249 goto s0;
250 }
251 if (i == 'S' || i == '0')
252 return (0);
253 if ((j = findft(i, fontlab)) == -1)
254 return (0);
255 s0:
256 font1 = font;
257 font = j;
258 mchbits();
259
260 return (0);
261 }
262
263
264 int
setwd()265 setwd()
266 {
267 int base, wid;
268 tchar i;
269 int delim, emsz, k;
270 int savhp, savapts, savapts1, savfont, savfont1, savpts, savpts1;
271
272 base = numtab[ST].val = wid = numtab[CT].val = 0;
273 if (ismot(i = getch()))
274 return (0);
275 delim = cbits(i);
276 savhp = numtab[HP].val;
277 numtab[HP].val = 0;
278 savapts = apts;
279 savapts1 = apts1;
280 savfont = font;
281 savfont1 = font1;
282 savpts = pts;
283 savpts1 = pts1;
284 setwdf++;
285 while (cbits(i = getch()) != delim && !nlflg) {
286 k = width(i);
287 wid += k;
288 numtab[HP].val += k;
289 if (!ismot(i)) {
290 emsz = (INCH * pts + 36) / 72;
291 } else if (isvmot(i)) {
292 k = absmot(i);
293 if (isnmot(i))
294 k = -k;
295 base -= k;
296 emsz = 0;
297 } else
298 continue;
299 if (base < numtab[SB].val)
300 numtab[SB].val = base;
301 if ((k = base + emsz) > numtab[ST].val)
302 numtab[ST].val = k;
303 }
304 setn1(wid, 0, (tchar) 0);
305 numtab[HP].val = savhp;
306 apts = savapts;
307 apts1 = savapts1;
308 font = savfont;
309 font1 = savfont1;
310 pts = savpts;
311 pts1 = savpts1;
312 mchbits();
313 setwdf = 0;
314
315 return (0);
316 }
317
318
vmot()319 tchar vmot()
320 {
321 dfact = lss;
322 vflag++;
323 return(mot());
324 }
325
326
hmot()327 tchar hmot()
328 {
329 dfact = EM;
330 return(mot());
331 }
332
333
mot()334 tchar mot()
335 {
336 int j, n;
337 tchar i;
338
339 j = HOR;
340 getch(); /*eat delim*/
341 if (n = atoi()) {
342 if (vflag)
343 j = VERT;
344 i = makem(quant(n, j));
345 } else
346 i = 0;
347 getch();
348 vflag = 0;
349 dfact = 1;
350 return(i);
351 }
352
353
sethl(k)354 tchar sethl(k)
355 int k;
356 {
357 int j;
358 tchar i;
359
360 j = t.Halfline;
361 if (k == 'u')
362 j = -j;
363 else if (k == 'r')
364 j = -2 * j;
365 vflag++;
366 i = makem(j);
367 vflag = 0;
368 return(i);
369 }
370
371
makem(i)372 tchar makem(i)
373 int i;
374 {
375 tchar j;
376
377 if ((j = i) < 0)
378 j = -j;
379 j |= MOT;
380 if (i < 0)
381 j |= NMOT;
382 if (vflag)
383 j |= VMOT;
384 return(j);
385 }
386
387
getlg(i)388 tchar getlg(i)
389 tchar i;
390 {
391 return(i);
392 }
393
394
395 int
caselg()396 caselg()
397 {
398 return (0);
399 }
400
401
402 int
casefp()403 casefp()
404 {
405 int i, j;
406
407 skip();
408 if ((i = cbits(getch()) - '0') < 0 || i > nfonts)
409 return (0);
410 if (skip() || !(j = getrq()))
411 return (0);
412 fontlab[i] = j;
413
414 return (0);
415 }
416
417
418 int
casecs()419 casecs()
420 {
421 return (0);
422 }
423
424
425 int
casebd()426 casebd()
427 {
428 int i, j, k;
429
430 k = 0;
431 bd0:
432 if (skip() || !(i = getrq()) || (j = findft(i)) == -1) {
433 if (k)
434 goto bd1;
435 else
436 return (0);
437 }
438 if (j == smnt) {
439 k = smnt;
440 goto bd0;
441 }
442 if (k) {
443 sbold = j;
444 j = k;
445 }
446 bd1:
447 skip();
448 noscale++;
449 bdtab[j] = atoi();
450 noscale = 0;
451
452 return (0);
453 }
454
455
456 int
casevs()457 casevs()
458 {
459 int i;
460
461 skip();
462 vflag++;
463 dfact = INCH; /*default scaling is points!*/
464 dfactd = 72;
465 res = VERT;
466 i = inumb(&lss);
467 if (nonumb)
468 i = lss1;
469 if (i < VERT)
470 i = VERT; /* was VERT */
471 lss1 = lss;
472 lss = i;
473
474 return (0);
475 }
476
477
478
479 int
casess()480 casess()
481 {
482 return (0);
483 }
484
485
xlss()486 tchar xlss()
487 {
488 /* stores \x'...' into
489 * two successive tchars.
490 * the first contains HX, the second the value,
491 * encoded as a vertical motion.
492 * decoding is done in n2.c by pchar().
493 */
494 int i;
495
496 getch();
497 dfact = lss;
498 i = quant(atoi(), VERT);
499 dfact = 1;
500 getch();
501 if (i >= 0)
502 *pbp++ = MOT | VMOT | i;
503 else
504 *pbp++ = MOT | VMOT | NMOT | -i;
505 return(HX);
506 }
507