8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / troff / nroff.d / n6.c
blob4098b23d69a2cbe149e58ce0785d7087c39755f6
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #include "tdef.h"
41 #include "tw.h"
42 #include "ext.h"
43 #include <ctype.h>
46 * n6.c -- width functions, sizes and fonts
49 int bdtab[NFONT+1] ={ 0, 0, 0, 3, 3, 0, };
50 int sbold = 0;
51 int fontlab[NFONT+1] = { 0, 'R', 'I', 'B', PAIR('B','I'), 'S', 0 };
53 extern int nchtab;
55 int
56 width(j)
57 tchar j;
59 int i, k;
61 if (j & (ZBIT|MOT)) {
62 if (iszbit(j))
63 return(0);
64 if (isvmot(j))
65 return(0);
66 k = absmot(j);
67 if (isnmot(j))
68 k = -k;
69 return(k);
71 i = cbits(j);
72 if (i < ' ') {
73 if (i == '\b')
74 return(-widthp);
75 if (i == PRESC)
76 i = eschar;
77 else if (iscontrol(i))
78 return(0);
80 if (i==ohc)
81 return(0);
82 #ifdef EUC
83 #ifdef NROFF
84 if (multi_locale) {
85 if ((j & MBMASK) || (j & CSMASK)) {
86 switch(j & MBMASK) {
87 case BYTE_CHR:
88 case LASTOFMB:
89 k = t.Char * csi_width[cs(j)];
90 break;
91 default:
92 k = 0;
93 break;
95 widthp = k;
96 return(k);
99 i &= 0x1ff;
100 #endif /* NROFF */
101 #endif /* EUC */
102 i = trtab[i];
103 if (i < 32)
104 return(0);
105 k = t.width[i] * t.Char;
106 widthp = k;
107 return(k);
111 tchar setch()
113 int j;
114 char temp[10];
115 char *s;
117 s = temp;
118 if ((*s++ = getach()) == 0 || (*s++ = getach()) == 0)
119 return(0);
120 *s = '\0';
121 if ((j = findch(temp)) > 0)
122 return j | chbits;
123 else
124 return 0;
127 tchar setabs() /* set absolute char from \C'...' */
128 { /* for now, a no-op */
129 int i, n, nf;
131 getch();
132 n = 0;
133 n = inumb(&n);
134 getch();
135 if (nonumb)
136 return 0;
137 return n + nchtab + _SPECCHAR_ST;
141 findft(i)
142 int i;
144 int k;
146 if ((k = i - '0') >= 0 && k <= nfonts && k < smnt)
147 return(k);
148 for (k = 0; fontlab[k] != i; k++)
149 if (k > nfonts)
150 return(-1);
151 return(k);
155 caseps()
157 return (0);
161 mchbits()
163 chbits = 0;
164 setfbits(chbits, font);
165 sps = width(' ' | chbits);
167 return (0);
172 setps()
174 int i, j;
176 i = cbits(getch());
177 if (ischar(i) && isdigit(i)) { /* \sd or \sdd */
178 i -= '0';
179 if (i == 0) /* \s0 */
181 else if (i <= 3 && ischar(j = cbits(ch = getch())) &&
182 isdigit(j)) { /* \sdd */
183 ch = 0;
185 } else if (i == '(') { /* \s(dd */
186 getch();
187 getch();
188 } else if (i == '+' || i == '-') { /* \s+, \s- */
189 j = cbits(getch());
190 if (ischar(j) && isdigit(j)) { /* \s+d, \s-d */
192 } else if (j == '(') { /* \s+(dd, \s-(dd */
193 getch();
194 getch();
198 return (0);
202 tchar setht() /* set character height from \H'...' */
204 int n;
205 tchar c;
207 getch();
208 n = inumb(&apts);
209 getch();
210 return(0);
214 tchar setslant() /* set slant from \S'...' */
216 int n;
217 tchar c;
219 getch();
220 n = 0;
221 n = inumb(&n);
222 getch();
223 return(0);
228 caseft()
230 skip();
231 setfont(1);
233 return (0);
238 setfont(a)
239 int a;
241 int i, j;
243 if (a)
244 i = getrq();
245 else
246 i = getsn();
247 if (!i || i == 'P') {
248 j = font1;
249 goto s0;
251 if (i == 'S' || i == '0')
252 return (0);
253 if ((j = findft(i, fontlab)) == -1)
254 return (0);
256 font1 = font;
257 font = j;
258 mchbits();
260 return (0);
265 setwd()
267 int base, wid;
268 tchar i;
269 int delim, emsz, k;
270 int savhp, savapts, savapts1, savfont, savfont1, savpts, savpts1;
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;
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;
315 return (0);
319 tchar vmot()
321 dfact = lss;
322 vflag++;
323 return(mot());
327 tchar hmot()
329 dfact = EM;
330 return(mot());
334 tchar mot()
336 int j, n;
337 tchar i;
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);
354 tchar sethl(k)
355 int k;
357 int j;
358 tchar i;
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);
372 tchar makem(i)
373 int i;
375 tchar j;
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);
388 tchar getlg(i)
389 tchar i;
391 return(i);
396 caselg()
398 return (0);
403 casefp()
405 int i, j;
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;
414 return (0);
419 casecs()
421 return (0);
426 casebd()
428 int i, j, k;
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);
438 if (j == smnt) {
439 k = smnt;
440 goto bd0;
442 if (k) {
443 sbold = j;
444 j = k;
446 bd1:
447 skip();
448 noscale++;
449 bdtab[j] = atoi();
450 noscale = 0;
452 return (0);
457 casevs()
459 int i;
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;
474 return (0);
480 casess()
482 return (0);
486 tchar xlss()
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().
494 int i;
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);