xref: /titanic_53/usr/src/cmd/troff/n9.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1989 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
35*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
36*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
37*7c478bd9Sstevel@tonic-gate  *
38*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
39*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
40*7c478bd9Sstevel@tonic-gate  * contributors.
41*7c478bd9Sstevel@tonic-gate  */
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #include <libintl.h>
44*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #include "tdef.h"
47*7c478bd9Sstevel@tonic-gate #ifdef NROFF
48*7c478bd9Sstevel@tonic-gate #include "tw.h"
49*7c478bd9Sstevel@tonic-gate #endif
50*7c478bd9Sstevel@tonic-gate #include "ext.h"
51*7c478bd9Sstevel@tonic-gate #ifdef EUC
52*7c478bd9Sstevel@tonic-gate #include <locale.h>
53*7c478bd9Sstevel@tonic-gate #include <wctype.h>
54*7c478bd9Sstevel@tonic-gate #include <langinfo.h>
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate #define	ISO646	"646"
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate int	multi_locale;
59*7c478bd9Sstevel@tonic-gate int	(*wdbdg)(wchar_t, wchar_t, int);
60*7c478bd9Sstevel@tonic-gate wchar_t	*(*wddlm)(wchar_t, wchar_t, int);
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate int	csi_width[4] = {
63*7c478bd9Sstevel@tonic-gate 	1,
64*7c478bd9Sstevel@tonic-gate 	1,
65*7c478bd9Sstevel@tonic-gate 	2,
66*7c478bd9Sstevel@tonic-gate 	3,
67*7c478bd9Sstevel@tonic-gate };
68*7c478bd9Sstevel@tonic-gate #endif /* EUC */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate /*
71*7c478bd9Sstevel@tonic-gate  * troff9.c
72*7c478bd9Sstevel@tonic-gate  *
73*7c478bd9Sstevel@tonic-gate  * misc functions
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate tchar setz()
77*7c478bd9Sstevel@tonic-gate {
78*7c478bd9Sstevel@tonic-gate 	tchar i;
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 	if (!ismot(i = getch()))
81*7c478bd9Sstevel@tonic-gate 		i |= ZBIT;
82*7c478bd9Sstevel@tonic-gate 	return(i);
83*7c478bd9Sstevel@tonic-gate }
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate setline()
86*7c478bd9Sstevel@tonic-gate {
87*7c478bd9Sstevel@tonic-gate 	register tchar *i;
88*7c478bd9Sstevel@tonic-gate 	tchar c;
89*7c478bd9Sstevel@tonic-gate 	int	length;
90*7c478bd9Sstevel@tonic-gate 	int	w, cnt, delim, rem, temp;
91*7c478bd9Sstevel@tonic-gate 	tchar linebuf[NC];
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	if (ismot(c = getch()))
94*7c478bd9Sstevel@tonic-gate 		return;
95*7c478bd9Sstevel@tonic-gate 	delim = cbits(c);
96*7c478bd9Sstevel@tonic-gate 	vflag = 0;
97*7c478bd9Sstevel@tonic-gate 	dfact = EM;
98*7c478bd9Sstevel@tonic-gate 	length = quant(atoi(), HOR);
99*7c478bd9Sstevel@tonic-gate 	dfact = 1;
100*7c478bd9Sstevel@tonic-gate 	if (!length) {
101*7c478bd9Sstevel@tonic-gate 		eat(delim);
102*7c478bd9Sstevel@tonic-gate 		return;
103*7c478bd9Sstevel@tonic-gate 	}
104*7c478bd9Sstevel@tonic-gate s0:
105*7c478bd9Sstevel@tonic-gate 	if ((cbits(c = getch())) == delim) {
106*7c478bd9Sstevel@tonic-gate 		ch = c;
107*7c478bd9Sstevel@tonic-gate 		c = RULE | chbits;
108*7c478bd9Sstevel@tonic-gate 	} else if (cbits(c) == FILLER)
109*7c478bd9Sstevel@tonic-gate 		goto s0;
110*7c478bd9Sstevel@tonic-gate 	w = width(c);
111*7c478bd9Sstevel@tonic-gate 	i = linebuf;
112*7c478bd9Sstevel@tonic-gate 	if (length < 0) {
113*7c478bd9Sstevel@tonic-gate 		*i++ = makem(length);
114*7c478bd9Sstevel@tonic-gate 		length = -length;
115*7c478bd9Sstevel@tonic-gate 	}
116*7c478bd9Sstevel@tonic-gate 	if (!(cnt = length / w)) {
117*7c478bd9Sstevel@tonic-gate 		*i++ = makem(-(temp = ((w - length) / 2)));
118*7c478bd9Sstevel@tonic-gate 		*i++ = c;
119*7c478bd9Sstevel@tonic-gate 		*i++ = makem(-(w - length - temp));
120*7c478bd9Sstevel@tonic-gate 		goto s1;
121*7c478bd9Sstevel@tonic-gate 	}
122*7c478bd9Sstevel@tonic-gate 	if (rem = length % w) {
123*7c478bd9Sstevel@tonic-gate 		if (cbits(c) == RULE || cbits(c) == UNDERLINE || cbits(c) == ROOTEN)
124*7c478bd9Sstevel@tonic-gate 			*i++ = c | ZBIT;
125*7c478bd9Sstevel@tonic-gate 		*i++ = makem(rem);
126*7c478bd9Sstevel@tonic-gate 	}
127*7c478bd9Sstevel@tonic-gate 	if (cnt) {
128*7c478bd9Sstevel@tonic-gate 		*i++ = RPT;
129*7c478bd9Sstevel@tonic-gate 		*i++ = cnt;
130*7c478bd9Sstevel@tonic-gate 		*i++ = c;
131*7c478bd9Sstevel@tonic-gate 	}
132*7c478bd9Sstevel@tonic-gate s1:
133*7c478bd9Sstevel@tonic-gate 	*i++ = 0;
134*7c478bd9Sstevel@tonic-gate 	eat(delim);
135*7c478bd9Sstevel@tonic-gate 	pushback(linebuf);
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate eat(c)
140*7c478bd9Sstevel@tonic-gate register int	c;
141*7c478bd9Sstevel@tonic-gate {
142*7c478bd9Sstevel@tonic-gate 	register i;
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 	while ((i = cbits(getch())) != c &&  (i != '\n'))
145*7c478bd9Sstevel@tonic-gate 		;
146*7c478bd9Sstevel@tonic-gate 	return(i);
147*7c478bd9Sstevel@tonic-gate }
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate setov()
151*7c478bd9Sstevel@tonic-gate {
152*7c478bd9Sstevel@tonic-gate 	register j, k;
153*7c478bd9Sstevel@tonic-gate 	tchar i, o[NOV];
154*7c478bd9Sstevel@tonic-gate 	int delim, w[NOV];
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 	if (ismot(i = getch()))
157*7c478bd9Sstevel@tonic-gate 		return;
158*7c478bd9Sstevel@tonic-gate 	delim = cbits(i);
159*7c478bd9Sstevel@tonic-gate 	for (k = 0; (k < NOV) && ((j = cbits(i = getch())) != delim) &&  (j != '\n'); k++) {
160*7c478bd9Sstevel@tonic-gate 		o[k] = i;
161*7c478bd9Sstevel@tonic-gate 		w[k] = width(i);
162*7c478bd9Sstevel@tonic-gate 	}
163*7c478bd9Sstevel@tonic-gate 	o[k] = w[k] = 0;
164*7c478bd9Sstevel@tonic-gate 	if (o[0])
165*7c478bd9Sstevel@tonic-gate 		for (j = 1; j; ) {
166*7c478bd9Sstevel@tonic-gate 			j = 0;
167*7c478bd9Sstevel@tonic-gate 			for (k = 1; o[k] ; k++) {
168*7c478bd9Sstevel@tonic-gate 				if (w[k-1] < w[k]) {
169*7c478bd9Sstevel@tonic-gate 					j++;
170*7c478bd9Sstevel@tonic-gate 					i = w[k];
171*7c478bd9Sstevel@tonic-gate 					w[k] = w[k-1];
172*7c478bd9Sstevel@tonic-gate 					w[k-1] = i;
173*7c478bd9Sstevel@tonic-gate 					i = o[k];
174*7c478bd9Sstevel@tonic-gate 					o[k] = o[k-1];
175*7c478bd9Sstevel@tonic-gate 					o[k-1] = i;
176*7c478bd9Sstevel@tonic-gate 				}
177*7c478bd9Sstevel@tonic-gate 			}
178*7c478bd9Sstevel@tonic-gate 		}
179*7c478bd9Sstevel@tonic-gate 	else
180*7c478bd9Sstevel@tonic-gate 		return;
181*7c478bd9Sstevel@tonic-gate 	*pbp++ = makem(w[0] / 2);
182*7c478bd9Sstevel@tonic-gate 	for (k = 0; o[k]; k++)
183*7c478bd9Sstevel@tonic-gate 		;
184*7c478bd9Sstevel@tonic-gate 	while (k>0) {
185*7c478bd9Sstevel@tonic-gate 		k--;
186*7c478bd9Sstevel@tonic-gate 		*pbp++ = makem(-((w[k] + w[k+1]) / 2));
187*7c478bd9Sstevel@tonic-gate 		*pbp++ = o[k];
188*7c478bd9Sstevel@tonic-gate 	}
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate setbra()
193*7c478bd9Sstevel@tonic-gate {
194*7c478bd9Sstevel@tonic-gate 	register k;
195*7c478bd9Sstevel@tonic-gate 	tchar i, *j, dwn;
196*7c478bd9Sstevel@tonic-gate 	int	cnt, delim;
197*7c478bd9Sstevel@tonic-gate 	tchar brabuf[NC];
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate 	if (ismot(i = getch()))
200*7c478bd9Sstevel@tonic-gate 		return;
201*7c478bd9Sstevel@tonic-gate 	delim = cbits(i);
202*7c478bd9Sstevel@tonic-gate 	j = brabuf + 1;
203*7c478bd9Sstevel@tonic-gate 	cnt = 0;
204*7c478bd9Sstevel@tonic-gate #ifdef NROFF
205*7c478bd9Sstevel@tonic-gate 	dwn = (2 * t.Halfline) | MOT | VMOT;
206*7c478bd9Sstevel@tonic-gate #endif
207*7c478bd9Sstevel@tonic-gate #ifndef NROFF
208*7c478bd9Sstevel@tonic-gate 	dwn = EM | MOT | VMOT;
209*7c478bd9Sstevel@tonic-gate #endif
210*7c478bd9Sstevel@tonic-gate 	while (((k = cbits(i = getch())) != delim) && (k != '\n') &&  (j <= (brabuf + NC - 4))) {
211*7c478bd9Sstevel@tonic-gate 		*j++ = i | ZBIT;
212*7c478bd9Sstevel@tonic-gate 		*j++ = dwn;
213*7c478bd9Sstevel@tonic-gate 		cnt++;
214*7c478bd9Sstevel@tonic-gate 	}
215*7c478bd9Sstevel@tonic-gate 	if (--cnt < 0)
216*7c478bd9Sstevel@tonic-gate 		return;
217*7c478bd9Sstevel@tonic-gate 	else if (!cnt) {
218*7c478bd9Sstevel@tonic-gate 		ch = *(j - 2);
219*7c478bd9Sstevel@tonic-gate 		return;
220*7c478bd9Sstevel@tonic-gate 	}
221*7c478bd9Sstevel@tonic-gate 	*j = 0;
222*7c478bd9Sstevel@tonic-gate #ifdef NROFF
223*7c478bd9Sstevel@tonic-gate 	*--j = *brabuf = (cnt * t.Halfline) | MOT | NMOT | VMOT;
224*7c478bd9Sstevel@tonic-gate #endif
225*7c478bd9Sstevel@tonic-gate #ifndef NROFF
226*7c478bd9Sstevel@tonic-gate 	*--j = *brabuf = (cnt * EM) / 2 | MOT | NMOT | VMOT;
227*7c478bd9Sstevel@tonic-gate #endif
228*7c478bd9Sstevel@tonic-gate 	*--j &= ~ZBIT;
229*7c478bd9Sstevel@tonic-gate 	pushback(brabuf);
230*7c478bd9Sstevel@tonic-gate }
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate setvline()
234*7c478bd9Sstevel@tonic-gate {
235*7c478bd9Sstevel@tonic-gate 	register i;
236*7c478bd9Sstevel@tonic-gate 	tchar c, rem, ver, neg;
237*7c478bd9Sstevel@tonic-gate 	int	cnt, delim, v;
238*7c478bd9Sstevel@tonic-gate 	tchar vlbuf[NC];
239*7c478bd9Sstevel@tonic-gate 	register tchar *vlp;
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate 	if (ismot(c = getch()))
242*7c478bd9Sstevel@tonic-gate 		return;
243*7c478bd9Sstevel@tonic-gate 	delim = cbits(c);
244*7c478bd9Sstevel@tonic-gate 	dfact = lss;
245*7c478bd9Sstevel@tonic-gate 	vflag++;
246*7c478bd9Sstevel@tonic-gate 	i = quant(atoi(), VERT);
247*7c478bd9Sstevel@tonic-gate 	dfact = 1;
248*7c478bd9Sstevel@tonic-gate 	if (!i) {
249*7c478bd9Sstevel@tonic-gate 		eat(delim);
250*7c478bd9Sstevel@tonic-gate 		vflag = 0;
251*7c478bd9Sstevel@tonic-gate 		return;
252*7c478bd9Sstevel@tonic-gate 	}
253*7c478bd9Sstevel@tonic-gate 	if ((cbits(c = getch())) == delim) {
254*7c478bd9Sstevel@tonic-gate 		c = BOXRULE | chbits;	/*default box rule*/
255*7c478bd9Sstevel@tonic-gate 	} else
256*7c478bd9Sstevel@tonic-gate 		getch();
257*7c478bd9Sstevel@tonic-gate 	c |= ZBIT;
258*7c478bd9Sstevel@tonic-gate 	neg = 0;
259*7c478bd9Sstevel@tonic-gate 	if (i < 0) {
260*7c478bd9Sstevel@tonic-gate 		i = -i;
261*7c478bd9Sstevel@tonic-gate 		neg = NMOT;
262*7c478bd9Sstevel@tonic-gate 	}
263*7c478bd9Sstevel@tonic-gate #ifdef NROFF
264*7c478bd9Sstevel@tonic-gate 	v = 2 * t.Halfline;
265*7c478bd9Sstevel@tonic-gate #endif
266*7c478bd9Sstevel@tonic-gate #ifndef NROFF
267*7c478bd9Sstevel@tonic-gate 	v = EM;
268*7c478bd9Sstevel@tonic-gate #endif
269*7c478bd9Sstevel@tonic-gate 	cnt = i / v;
270*7c478bd9Sstevel@tonic-gate 	rem = makem(i % v) | neg;
271*7c478bd9Sstevel@tonic-gate 	ver = makem(v) | neg;
272*7c478bd9Sstevel@tonic-gate 	vlp = vlbuf;
273*7c478bd9Sstevel@tonic-gate 	if (!neg)
274*7c478bd9Sstevel@tonic-gate 		*vlp++ = ver;
275*7c478bd9Sstevel@tonic-gate 	if (absmot(rem) != 0) {
276*7c478bd9Sstevel@tonic-gate 		*vlp++ = c;
277*7c478bd9Sstevel@tonic-gate 		*vlp++ = rem;
278*7c478bd9Sstevel@tonic-gate 	}
279*7c478bd9Sstevel@tonic-gate 	while ((vlp < (vlbuf + NC - 3)) && cnt--) {
280*7c478bd9Sstevel@tonic-gate 		*vlp++ = c;
281*7c478bd9Sstevel@tonic-gate 		*vlp++ = ver;
282*7c478bd9Sstevel@tonic-gate 	}
283*7c478bd9Sstevel@tonic-gate 	*(vlp - 2) &= ~ZBIT;
284*7c478bd9Sstevel@tonic-gate 	if (!neg)
285*7c478bd9Sstevel@tonic-gate 		vlp--;
286*7c478bd9Sstevel@tonic-gate 	*vlp++ = 0;
287*7c478bd9Sstevel@tonic-gate 	pushback(vlbuf);
288*7c478bd9Sstevel@tonic-gate 	vflag = 0;
289*7c478bd9Sstevel@tonic-gate }
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate #define	NPAIR	(NC/2-6)	/* max pairs in spline, etc. */
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate setdraw()	/* generate internal cookies for a drawing function */
294*7c478bd9Sstevel@tonic-gate {
295*7c478bd9Sstevel@tonic-gate 	int i, j, k, dx[NPAIR], dy[NPAIR], delim, type;
296*7c478bd9Sstevel@tonic-gate 	tchar c, drawbuf[NC];
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate 	/* input is \D'f dx dy dx dy ... c' (or at least it had better be) */
299*7c478bd9Sstevel@tonic-gate 	/* this does drawing function f with character c and the */
300*7c478bd9Sstevel@tonic-gate 	/* specified dx,dy pairs interpreted as appropriate */
301*7c478bd9Sstevel@tonic-gate 	/* pairs are deltas from last point, except for radii */
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	/* l dx dy:	line from here by dx,dy */
304*7c478bd9Sstevel@tonic-gate 	/* c x:		circle of diameter x, left side here */
305*7c478bd9Sstevel@tonic-gate 	/* e x y:	ellipse of diameters x,y, left side here */
306*7c478bd9Sstevel@tonic-gate 	/* a dx1 dy1 dx2 dy2:
307*7c478bd9Sstevel@tonic-gate 			ccw arc: ctr at dx1,dy1, then end at dx2,dy2 from there */
308*7c478bd9Sstevel@tonic-gate 	/* ~ dx1 dy1 dx2 dy2...:
309*7c478bd9Sstevel@tonic-gate 			spline to dx1,dy1 to dx2,dy2 ... */
310*7c478bd9Sstevel@tonic-gate 	/* f dx dy ...:	f is any other char:  like spline */
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate 	if (ismot(c = getch()))
313*7c478bd9Sstevel@tonic-gate 		return;
314*7c478bd9Sstevel@tonic-gate 	delim = cbits(c);
315*7c478bd9Sstevel@tonic-gate 	type = cbits(getch());
316*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < NPAIR ; i++) {
317*7c478bd9Sstevel@tonic-gate 		c = getch();
318*7c478bd9Sstevel@tonic-gate 		if (cbits(c) == delim)
319*7c478bd9Sstevel@tonic-gate 			break;
320*7c478bd9Sstevel@tonic-gate 	/* ought to pick up optional drawing character */
321*7c478bd9Sstevel@tonic-gate 		if (cbits(c) != ' ')
322*7c478bd9Sstevel@tonic-gate 			ch = c;
323*7c478bd9Sstevel@tonic-gate 		vflag = 0;
324*7c478bd9Sstevel@tonic-gate 		dfact = EM;
325*7c478bd9Sstevel@tonic-gate 		dx[i] = quant(atoi(), HOR);
326*7c478bd9Sstevel@tonic-gate 		if (dx[i] > MAXMOT)
327*7c478bd9Sstevel@tonic-gate 			dx[i] = MAXMOT;
328*7c478bd9Sstevel@tonic-gate 		else if (dx[i] < -MAXMOT)
329*7c478bd9Sstevel@tonic-gate 			dx[i] = -MAXMOT;
330*7c478bd9Sstevel@tonic-gate 		if (cbits((c = getch())) == delim) {	/* spacer */
331*7c478bd9Sstevel@tonic-gate 			dy[i++] = 0;
332*7c478bd9Sstevel@tonic-gate 			break;
333*7c478bd9Sstevel@tonic-gate 		}
334*7c478bd9Sstevel@tonic-gate 		vflag = 1;
335*7c478bd9Sstevel@tonic-gate 		dfact = lss;
336*7c478bd9Sstevel@tonic-gate 		dy[i] = quant(atoi(), VERT);
337*7c478bd9Sstevel@tonic-gate 		if (dy[i] > MAXMOT)
338*7c478bd9Sstevel@tonic-gate 			dy[i] = MAXMOT;
339*7c478bd9Sstevel@tonic-gate 		else if (dy[i] < -MAXMOT)
340*7c478bd9Sstevel@tonic-gate 			dy[i] = -MAXMOT;
341*7c478bd9Sstevel@tonic-gate 	}
342*7c478bd9Sstevel@tonic-gate 	dfact = 1;
343*7c478bd9Sstevel@tonic-gate 	vflag = 0;
344*7c478bd9Sstevel@tonic-gate #ifndef NROFF
345*7c478bd9Sstevel@tonic-gate 	drawbuf[0] = DRAWFCN | chbits | ZBIT;
346*7c478bd9Sstevel@tonic-gate 	drawbuf[1] = type | chbits | ZBIT;
347*7c478bd9Sstevel@tonic-gate 	drawbuf[2] = '.' | chbits | ZBIT;	/* use default drawing character */
348*7c478bd9Sstevel@tonic-gate 	for (k = 0, j = 3; k < i; k++) {
349*7c478bd9Sstevel@tonic-gate 		drawbuf[j++] = MOT | ((dx[k] >= 0) ? dx[k] : (NMOT | -dx[k]));
350*7c478bd9Sstevel@tonic-gate 		drawbuf[j++] = MOT | VMOT | ((dy[k] >= 0) ? dy[k] : (NMOT | -dy[k]));
351*7c478bd9Sstevel@tonic-gate 	}
352*7c478bd9Sstevel@tonic-gate 	if (type == DRAWELLIPSE) {
353*7c478bd9Sstevel@tonic-gate 		drawbuf[5] = drawbuf[4] | NMOT;	/* so the net vertical is zero */
354*7c478bd9Sstevel@tonic-gate 		j = 6;
355*7c478bd9Sstevel@tonic-gate 	}
356*7c478bd9Sstevel@tonic-gate 	drawbuf[j++] = DRAWFCN | chbits | ZBIT;	/* marks end for ptout */
357*7c478bd9Sstevel@tonic-gate 	drawbuf[j] = 0;
358*7c478bd9Sstevel@tonic-gate 	pushback(drawbuf);
359*7c478bd9Sstevel@tonic-gate #endif
360*7c478bd9Sstevel@tonic-gate }
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate casefc()
364*7c478bd9Sstevel@tonic-gate {
365*7c478bd9Sstevel@tonic-gate 	register i;
366*7c478bd9Sstevel@tonic-gate 	tchar j;
367*7c478bd9Sstevel@tonic-gate 
368*7c478bd9Sstevel@tonic-gate 	gchtab[fc] &= ~FCBIT;
369*7c478bd9Sstevel@tonic-gate 	fc = IMP;
370*7c478bd9Sstevel@tonic-gate 	padc = ' ';
371*7c478bd9Sstevel@tonic-gate 	if (skip() || ismot(j = getch()) || (i = cbits(j)) == '\n')
372*7c478bd9Sstevel@tonic-gate 		return;
373*7c478bd9Sstevel@tonic-gate 	fc = i;
374*7c478bd9Sstevel@tonic-gate 	gchtab[fc] |= FCBIT;
375*7c478bd9Sstevel@tonic-gate 	if (skip() || ismot(ch) || (ch = cbits(ch)) == fc)
376*7c478bd9Sstevel@tonic-gate 		return;
377*7c478bd9Sstevel@tonic-gate 	padc = ch;
378*7c478bd9Sstevel@tonic-gate }
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate 
381*7c478bd9Sstevel@tonic-gate tchar
382*7c478bd9Sstevel@tonic-gate setfield(x)
383*7c478bd9Sstevel@tonic-gate int	x;
384*7c478bd9Sstevel@tonic-gate {
385*7c478bd9Sstevel@tonic-gate 	register tchar ii, jj, *fp;
386*7c478bd9Sstevel@tonic-gate 	register i, j;
387*7c478bd9Sstevel@tonic-gate 	int length, ws, npad, temp, type;
388*7c478bd9Sstevel@tonic-gate 	tchar **pp, *padptr[NPP];
389*7c478bd9Sstevel@tonic-gate 	tchar fbuf[FBUFSZ];
390*7c478bd9Sstevel@tonic-gate 	int savfc, savtc, savlc;
391*7c478bd9Sstevel@tonic-gate 	tchar rchar;
392*7c478bd9Sstevel@tonic-gate 	int savepos;
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate 	if (x == tabch)
395*7c478bd9Sstevel@tonic-gate 		rchar = tabc | chbits;
396*7c478bd9Sstevel@tonic-gate 	else if (x ==  ldrch)
397*7c478bd9Sstevel@tonic-gate 		rchar = dotc | chbits;
398*7c478bd9Sstevel@tonic-gate 	temp = npad = ws = 0;
399*7c478bd9Sstevel@tonic-gate 	savfc = fc;
400*7c478bd9Sstevel@tonic-gate 	savtc = tabch;
401*7c478bd9Sstevel@tonic-gate 	savlc = ldrch;
402*7c478bd9Sstevel@tonic-gate 	tabch = ldrch = fc = IMP;
403*7c478bd9Sstevel@tonic-gate 	savepos = numtab[HP].val;
404*7c478bd9Sstevel@tonic-gate 	gchtab[tabch] &= ~TABBIT;
405*7c478bd9Sstevel@tonic-gate 	gchtab[ldrch] &= ~LDRBIT;
406*7c478bd9Sstevel@tonic-gate 	gchtab[fc] &= ~FCBIT;
407*7c478bd9Sstevel@tonic-gate 	gchtab[IMP] |= TABBIT|LDRBIT|FCBIT;
408*7c478bd9Sstevel@tonic-gate 	for (j = 0; ; j++) {
409*7c478bd9Sstevel@tonic-gate 		if ((tabtab[j] & TABMASK) == 0) {
410*7c478bd9Sstevel@tonic-gate 			if (x == savfc)
411*7c478bd9Sstevel@tonic-gate 				errprint(gettext("zero field width."));
412*7c478bd9Sstevel@tonic-gate 			jj = 0;
413*7c478bd9Sstevel@tonic-gate 			goto rtn;
414*7c478bd9Sstevel@tonic-gate 		}
415*7c478bd9Sstevel@tonic-gate 		if ((length = ((tabtab[j] & TABMASK) - numtab[HP].val)) > 0 )
416*7c478bd9Sstevel@tonic-gate 			break;
417*7c478bd9Sstevel@tonic-gate 	}
418*7c478bd9Sstevel@tonic-gate 	type = tabtab[j] & (~TABMASK);
419*7c478bd9Sstevel@tonic-gate 	fp = fbuf;
420*7c478bd9Sstevel@tonic-gate 	pp = padptr;
421*7c478bd9Sstevel@tonic-gate 	if (x == savfc) {
422*7c478bd9Sstevel@tonic-gate 		while (1) {
423*7c478bd9Sstevel@tonic-gate 			j = cbits(ii = getch());
424*7c478bd9Sstevel@tonic-gate 			jj = width(ii);
425*7c478bd9Sstevel@tonic-gate 			widthp = jj;
426*7c478bd9Sstevel@tonic-gate 			numtab[HP].val += jj;
427*7c478bd9Sstevel@tonic-gate 			if (j == padc) {
428*7c478bd9Sstevel@tonic-gate 				npad++;
429*7c478bd9Sstevel@tonic-gate 				*pp++ = fp;
430*7c478bd9Sstevel@tonic-gate 				if (pp > (padptr + NPP - 1))
431*7c478bd9Sstevel@tonic-gate 					break;
432*7c478bd9Sstevel@tonic-gate 				goto s1;
433*7c478bd9Sstevel@tonic-gate 			} else if (j == savfc)
434*7c478bd9Sstevel@tonic-gate 				break;
435*7c478bd9Sstevel@tonic-gate 			else if (j == '\n') {
436*7c478bd9Sstevel@tonic-gate 				temp = j;
437*7c478bd9Sstevel@tonic-gate 				nlflg = 0;
438*7c478bd9Sstevel@tonic-gate 				break;
439*7c478bd9Sstevel@tonic-gate 			}
440*7c478bd9Sstevel@tonic-gate 			ws += jj;
441*7c478bd9Sstevel@tonic-gate s1:
442*7c478bd9Sstevel@tonic-gate 			*fp++ = ii;
443*7c478bd9Sstevel@tonic-gate 			if (fp > (fbuf + FBUFSZ - 3))
444*7c478bd9Sstevel@tonic-gate 				break;
445*7c478bd9Sstevel@tonic-gate 		}
446*7c478bd9Sstevel@tonic-gate 		if (!npad) {
447*7c478bd9Sstevel@tonic-gate 			npad++;
448*7c478bd9Sstevel@tonic-gate 			*pp++ = fp;
449*7c478bd9Sstevel@tonic-gate 			*fp++ = 0;
450*7c478bd9Sstevel@tonic-gate 		}
451*7c478bd9Sstevel@tonic-gate 		*fp++ = temp;
452*7c478bd9Sstevel@tonic-gate 		*fp++ = 0;
453*7c478bd9Sstevel@tonic-gate 		temp = i = (j = length - ws) / npad;
454*7c478bd9Sstevel@tonic-gate 		i = (i / HOR) * HOR;
455*7c478bd9Sstevel@tonic-gate 		if ((j -= i * npad) < 0)
456*7c478bd9Sstevel@tonic-gate 			j = -j;
457*7c478bd9Sstevel@tonic-gate 		ii = makem(i);
458*7c478bd9Sstevel@tonic-gate 		if (temp < 0)
459*7c478bd9Sstevel@tonic-gate 			ii |= NMOT;
460*7c478bd9Sstevel@tonic-gate 		for (; npad > 0; npad--) {
461*7c478bd9Sstevel@tonic-gate 			*(*--pp) = ii;
462*7c478bd9Sstevel@tonic-gate 			if (j) {
463*7c478bd9Sstevel@tonic-gate 				j -= HOR;
464*7c478bd9Sstevel@tonic-gate 				(*(*pp)) += HOR;
465*7c478bd9Sstevel@tonic-gate 			}
466*7c478bd9Sstevel@tonic-gate 		}
467*7c478bd9Sstevel@tonic-gate 		pushback(fbuf);
468*7c478bd9Sstevel@tonic-gate 		jj = 0;
469*7c478bd9Sstevel@tonic-gate 	} else if (type == 0) {
470*7c478bd9Sstevel@tonic-gate 		/*plain tab or leader*/
471*7c478bd9Sstevel@tonic-gate 		if ((j = width(rchar)) > 0) {
472*7c478bd9Sstevel@tonic-gate 			int nchar = length / j;
473*7c478bd9Sstevel@tonic-gate 			while (nchar-->0 && pbp < &pbbuf[NC-3]) {
474*7c478bd9Sstevel@tonic-gate 				numtab[HP].val += j;
475*7c478bd9Sstevel@tonic-gate 				widthp = j;
476*7c478bd9Sstevel@tonic-gate 				*pbp++ = rchar;
477*7c478bd9Sstevel@tonic-gate 			}
478*7c478bd9Sstevel@tonic-gate 			length %= j;
479*7c478bd9Sstevel@tonic-gate 		}
480*7c478bd9Sstevel@tonic-gate 		if (length)
481*7c478bd9Sstevel@tonic-gate 			jj = length | MOT;
482*7c478bd9Sstevel@tonic-gate 		else
483*7c478bd9Sstevel@tonic-gate 			jj = getch0();
484*7c478bd9Sstevel@tonic-gate 	} else {
485*7c478bd9Sstevel@tonic-gate 		/*center tab*/
486*7c478bd9Sstevel@tonic-gate 		/*right tab*/
487*7c478bd9Sstevel@tonic-gate 		while (((j = cbits(ii = getch())) != savtc) &&  (j != '\n') && (j != savlc)) {
488*7c478bd9Sstevel@tonic-gate 			jj = width(ii);
489*7c478bd9Sstevel@tonic-gate 			ws += jj;
490*7c478bd9Sstevel@tonic-gate 			numtab[HP].val += jj;
491*7c478bd9Sstevel@tonic-gate 			widthp = jj;
492*7c478bd9Sstevel@tonic-gate 			*fp++ = ii;
493*7c478bd9Sstevel@tonic-gate 			if (fp > (fbuf + FBUFSZ - 3))
494*7c478bd9Sstevel@tonic-gate 				break;
495*7c478bd9Sstevel@tonic-gate 		}
496*7c478bd9Sstevel@tonic-gate 		*fp++ = ii;
497*7c478bd9Sstevel@tonic-gate 		*fp++ = 0;
498*7c478bd9Sstevel@tonic-gate 		if (type == RTAB)
499*7c478bd9Sstevel@tonic-gate 			length -= ws;
500*7c478bd9Sstevel@tonic-gate 		else
501*7c478bd9Sstevel@tonic-gate 			length -= ws / 2; /*CTAB*/
502*7c478bd9Sstevel@tonic-gate 		pushback(fbuf);
503*7c478bd9Sstevel@tonic-gate 		if ((j = width(rchar)) != 0 && length > 0) {
504*7c478bd9Sstevel@tonic-gate 			int nchar = length / j;
505*7c478bd9Sstevel@tonic-gate 			while (nchar-- > 0 && pbp < &pbbuf[NC-3])
506*7c478bd9Sstevel@tonic-gate 				*pbp++ = rchar;
507*7c478bd9Sstevel@tonic-gate 			length %= j;
508*7c478bd9Sstevel@tonic-gate 		}
509*7c478bd9Sstevel@tonic-gate 		length = (length / HOR) * HOR;
510*7c478bd9Sstevel@tonic-gate 		jj = makem(length);
511*7c478bd9Sstevel@tonic-gate 		nlflg = 0;
512*7c478bd9Sstevel@tonic-gate 	}
513*7c478bd9Sstevel@tonic-gate rtn:
514*7c478bd9Sstevel@tonic-gate 	gchtab[fc] &= ~FCBIT;
515*7c478bd9Sstevel@tonic-gate 	gchtab[tabch] &= ~TABBIT;
516*7c478bd9Sstevel@tonic-gate 	gchtab[ldrch] &= ~LDRBIT;
517*7c478bd9Sstevel@tonic-gate 	fc = savfc;
518*7c478bd9Sstevel@tonic-gate 	tabch = savtc;
519*7c478bd9Sstevel@tonic-gate 	ldrch = savlc;
520*7c478bd9Sstevel@tonic-gate 	gchtab[fc] |= FCBIT;
521*7c478bd9Sstevel@tonic-gate 	gchtab[tabch] = TABBIT;
522*7c478bd9Sstevel@tonic-gate 	gchtab[ldrch] |= LDRBIT;
523*7c478bd9Sstevel@tonic-gate 	numtab[HP].val = savepos;
524*7c478bd9Sstevel@tonic-gate 	return(jj);
525*7c478bd9Sstevel@tonic-gate }
526*7c478bd9Sstevel@tonic-gate 
527*7c478bd9Sstevel@tonic-gate 
528*7c478bd9Sstevel@tonic-gate #ifdef EUC
529*7c478bd9Sstevel@tonic-gate #ifdef NROFF
530*7c478bd9Sstevel@tonic-gate /* locale specific initialization */
531*7c478bd9Sstevel@tonic-gate int localize()
532*7c478bd9Sstevel@tonic-gate {
533*7c478bd9Sstevel@tonic-gate 	extern int	wdbindf();
534*7c478bd9Sstevel@tonic-gate 	extern wchar_t	*wddelim();
535*7c478bd9Sstevel@tonic-gate 	char	*codeset;
536*7c478bd9Sstevel@tonic-gate 
537*7c478bd9Sstevel@tonic-gate 	codeset = nl_langinfo(CODESET);
538*7c478bd9Sstevel@tonic-gate 
539*7c478bd9Sstevel@tonic-gate 	if (MB_CUR_MAX > 1)
540*7c478bd9Sstevel@tonic-gate 		multi_locale = 1;
541*7c478bd9Sstevel@tonic-gate 	else {
542*7c478bd9Sstevel@tonic-gate 		if (*codeset == '\0' ||
543*7c478bd9Sstevel@tonic-gate 			(strcmp(codeset, ISO646) == 0)) {
544*7c478bd9Sstevel@tonic-gate 			/*
545*7c478bd9Sstevel@tonic-gate 			 * if codeset is an empty string
546*7c478bd9Sstevel@tonic-gate 			 * assumes this is C locale (7-bit) locale.
547*7c478bd9Sstevel@tonic-gate 			 * This happens in 2.5, 2.5.1, and 2.6 system
548*7c478bd9Sstevel@tonic-gate 			 * Or, if codeset is "646"
549*7c478bd9Sstevel@tonic-gate 			 * this is 7-bit locale.
550*7c478bd9Sstevel@tonic-gate 			 */
551*7c478bd9Sstevel@tonic-gate 			multi_locale = 0;
552*7c478bd9Sstevel@tonic-gate 		} else {
553*7c478bd9Sstevel@tonic-gate 			/* 8-bit locale */
554*7c478bd9Sstevel@tonic-gate 			multi_locale = 1;
555*7c478bd9Sstevel@tonic-gate 		}
556*7c478bd9Sstevel@tonic-gate 
557*7c478bd9Sstevel@tonic-gate 	}
558*7c478bd9Sstevel@tonic-gate 	wdbdg = wdbindf;
559*7c478bd9Sstevel@tonic-gate 	wddlm = wddelim;
560*7c478bd9Sstevel@tonic-gate }
561*7c478bd9Sstevel@tonic-gate #endif /* EUC */
562*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
563