1 /* $MirOS: src/usr.bin/oldroff/nroff/n6.c,v 1.3 2008/11/08 23:04:41 tg Exp $ */
2
3 /*-
4 * Copyright (c) 1979, 1980, 1981, 1986, 1988, 1990, 1991, 1992
5 * The Regents of the University of California.
6 * Copyright (C) Caldera International Inc. 2001-2002.
7 * Copyright (c) 2003, 2004
8 * Thorsten "mirabilos" Glaser <tg@mirbsd.org>
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms,
12 * with or without modification, are permitted provided
13 * that the following conditions are met:
14 *
15 * Redistributions of source code and documentation must retain
16 * the above copyright notice, this list of conditions and the
17 * following disclaimer. Redistributions in binary form must
18 * reproduce the above copyright notice, this list of conditions
19 * and the following disclaimer in the documentation and/or other
20 * materials provided with the distribution.
21 *
22 * All advertising materials mentioning features or use of this
23 * software must display the following acknowledgement:
24 * This product includes software developed or owned by
25 * Caldera International, Inc.
26 *
27 * Neither the name of Caldera International, Inc. nor the names
28 * of other contributors may be used to endorse or promote products
29 * derived from this software without specific prior written permission.
30 *
31 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
32 * INTERNATIONAL, INC. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
33 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
36 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
39 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
41 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44
45 #include <sys/cdefs.h>
46 __SCCSID("@(#)n6.c 4.3 (Berkeley) 4/18/91");
47 __RCSID("$MirOS: src/usr.bin/oldroff/nroff/n6.c,v 1.3 2008/11/08 23:04:41 tg Exp $");
48
49 #include "tdef.h"
50 extern
51 #include "d.h"
52 extern
53 #include "v.h"
54 #ifdef NROFF
55 extern
56 #include "tw.h"
57 #endif
58
59 /*
60 troff6.c
61
62 width functions, sizes and fonts
63 */
64
65 extern int inchar[LNSIZE], *pinchar; /* XXX */
66 extern int eschar;
67 extern int widthp;
68 extern int ohc;
69 extern int xfont;
70 extern int smnt;
71 extern int setwdf;
72 extern char trtab[];
73 extern int chbits;
74 extern int nonumb;
75 extern int noscale;
76 extern int font;
77 extern int font1;
78 extern int pts;
79 extern int sps;
80 extern int nlflg;
81 extern int nform;
82 extern int dfact;
83 extern int dfactd;
84 extern int lss;
85 extern int lss1;
86 extern int vflag;
87 extern int ch0;
88 extern int level;
89 extern int ch;
90 extern int res;
91 extern int xxx;
92 int fontlab[] = {'R','I','B','S',0};
93
width(c)94 width(c)
95 int c;
96 {
97 register i,j,k;
98
99 j = c;
100 k = 0;
101 if(j & MOT){
102 if(j & VMOT)goto rtn;
103 k = j & ~MOTV;
104 if(j & NMOT)k = -k;
105 goto rtn;
106 }
107 if((i = (j & CMASK)) == 010){
108 k = -widthp;
109 goto rtn;
110 }
111 if(i == PRESC)i = eschar;
112 if((i == ohc) ||
113 (i >= 0370))goto rtn;
114 if(j & ZBIT)goto rtn;
115 i = trtab[i] & BMASK;
116 if(i < 040)goto rtn;
117 if (t.codetab[i-32])
118 k = (*(t.codetab[i-32]) & 0177) * t.Char;
119 else
120 k = 0;
121 widthp = k;
122 rtn:
123 return(k);
124 }
setch()125 setch(){
126 register i,*j,k;
127 extern int chtab[];
128
129 if((i = getrq()) == 0)return(0);
130 for(j=chtab;*j != i;j++)if(*(j++) == 0)return(0);
131 k = *(++j) | chbits;
132 return(k);
133 }
find(i,j)134 find(i,j)
135 int i,j[];
136 {
137 register k;
138
139 if(((k = i-'0') >= 1) && (k <= 4) && (k != smnt))return(--k);
140 for(k=0; j[k] != i; k++)if(j[k] == 0)return(-1);
141 return(k);
142 }
mchbits()143 mchbits(){
144 chbits = (((pts)<<2) | font) << (BYTE + 1);
145 sps = width(' ' | chbits);
146 }
setps()147 setps(){
148 register i,j;
149
150 if((((i=getch() & CMASK) == '+') || (i == '-')) &&
151 (((j=(ch = getch() & CMASK) - '0') >= 0) && (j <= 9))){
152 ch = 0;
153 return;
154 }
155 if((i -= '0') == 0){
156 return;
157 }
158 if((i > 0) && (i <= 9)){
159 if((i <= 3) &&
160 ((j=(ch = getch() & CMASK) - '0') >= 0) && (j <= 9)){
161 i = 10*i +j;
162 ch = 0;
163 }
164 }
165 }
caseft()166 caseft(){
167 skip();
168 setfont(1);
169 }
setfont(a)170 setfont(a)
171 int a;
172 {
173 register i,j;
174
175 if(a)i = getrq();
176 else i = getsn();
177 if(!i || (i == 'P')){
178 j = font1;
179 goto s0;
180 }
181 if(i == 'S')return;
182 if((j = find(i,fontlab)) == -1)return;
183 s0:
184 font1 = font;
185 font = j;
186 mchbits();
187 }
setwd()188 setwd(){
189 register i, base, wid;
190 int delim, em, k;
191 int savlevel, savhp, savfont, savfont1;
192 int *savpinchar, *p, *q, tempinchar[LNSIZE]; /* XXX */
193
194 base = v.st = v.sb = wid = v.ct = 0;
195 if((delim = getch() & CMASK) & MOT)return;
196 savhp = v.hp;
197 savpinchar = pinchar; /* XXX */
198 for (p=inchar, q=tempinchar; p < pinchar; ) /* XXX */
199 *q++ = *p++; /* XXX */
200 pinchar = inchar; /* XXX */
201 savlevel = level;
202 v.hp = level = 0;
203 savfont = font;
204 savfont1 = font1;
205 setwdf++;
206 while((((i = getch()) & CMASK) != delim) && !nlflg){
207 wid += width(i);
208 if(!(i & MOT)){
209 em = 2*t.Halfline;
210 }else if(i & VMOT){
211 k = i & ~MOTV;
212 if(i & NMOT)k = -k;
213 base -= k;
214 em = 0;
215 }else continue;
216 if(base < v.sb)v.sb = base;
217 if((k=base + em) > v.st)v.st = k;
218 }
219 nform = 0;
220 setn1(wid);
221 v.hp = savhp;
222 pinchar = savpinchar; /* XXX */
223 for (p=inchar, q=tempinchar; p < pinchar; ) /* XXX */
224 *p++ = *q++; /* XXX */
225 level = savlevel;
226 font = savfont;
227 font1 = savfont1;
228 mchbits();
229 setwdf = 0;
230 }
vmot()231 vmot(){
232 dfact = lss;
233 vflag++;
234 return(mot());
235 }
hmot()236 hmot(){
237 dfact = EM;
238 return(mot());
239 }
mot()240 mot(){
241 register i, j;
242
243 j = HOR;
244 getch(); /*eat delim*/
245 if(i = nr_atoi()){
246 if(vflag)j = VERT;
247 i = makem(quant(i,j));
248 }
249 getch();
250 vflag = 0;
251 dfact = 1;
252 return(i);
253 }
sethl(k)254 sethl(k)
255 int k;
256 {
257 register i;
258
259 i = t.Halfline;
260 if(k == 'u')i = -i;
261 else if(k == 'r')i = -2*i;
262 vflag++;
263 i = makem(i);
264 vflag = 0;
265 return(i);
266 }
makem(i)267 makem(i)
268 int i;
269 {
270 register j;
271
272 if((j = i) < 0)j = -j;
273 j = (j & ~MOTV) | MOT;
274 if(i < 0)j |= NMOT;
275 if(vflag)j |= VMOT;
276 return(j);
277 }
casefp()278 casefp(){
279 register i, j;
280
281 skip();
282 if(((i = (getch() & CMASK) - '0' -1) < 0) || (i >3))return;
283 if(skip() || !(j = getrq()))return;
284 fontlab[i] = j;
285 }
casevs()286 casevs(){
287 register i;
288
289 skip();
290 vflag++;
291 dfact = INCH; /*default scaling is points!*/
292 dfactd = 72;
293 res = VERT;
294 i = inumb(&lss);
295 if(nonumb)i = lss1;
296 if(i < VERT)i = VERT;
297 lss1 = lss;
298 lss = i;
299 }
xlss()300 xlss(){
301 register i, j;
302
303 getch();
304 dfact = lss;
305 i = quant(nr_atoi(),VERT);
306 dfact = 1;
307 getch();
308 if((j = i) < 0)j = -j;
309 ch0 = ((j & 03700)<<3) | HX;
310 if(i < 0)ch0 |= 040000;
311 return(((j & 077)<<9) | LX);
312 }
casefz()313 casefz(){}
caseps()314 caseps(){}
caselg()315 caselg(){}
casecs()316 casecs(){}
casebd()317 casebd(){}
casess()318 casess(){}
getlg(i)319 getlg(i)
320 int i;
321 {
322 return(i);
323 }
324