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
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]
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
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 /* starting values for typesetting parameters: */
44 #define PS 10 /* default point size */
45 #define FT 1 /* default font position */
46 #define ULFONT 2 /* default underline font */
47 #define BDFONT 3 /* default emboldening font */
48 #define BIFONT 4 /* default bold italic font */
49 #define LL (unsigned) 65*INCH/10 /* line length; 39picas=6.5in */
50 #define VS ((12*INCH)/72) /* initial vert space */
56 # define INCH 240 /* increments per inch */
57 # define SPS INCH/10 /* space size */
58 # define SS INCH/10 /* " */
60 # define PO 0 /* page offset */
64 # define DTAB 0 /* set at 8 Ems at init time */
67 #ifndef NROFF /* TROFF */
68 /* Inch is set by ptinit() when troff started. */
69 /* all derived values set then too
71 # define INCH Inch /* troff resolution -- number of goobies/inch */
72 # define POINT (INCH/72) /* goobies per point (1/72 inch) */
73 # define HOR Hor /* horizontal resolution in goobies */
74 # define VERT Vert /* vertical resolution in goobies */
75 # define SPS (EM/3) /* space size */
76 # define SS 12 /* space size in 36ths of an em */
77 # define PO (INCH) /* page offset 1 inch */
78 /* # define EM (POINT * pts) */
79 #define EM (((long) INCH * pts + 36) / 72) /* don't lose significance */
80 #define EMPTS(pts) (((long) INCH * (pts) + 36) / 72)
84 # define DTAB (INCH/2)
88 /* These "characters" are used to encode various internal functions
89 * Some make use of the fact that most ascii characters between
90 * 0 and 040 don't have any graphic or other function.
91 * The few that do have a purpose (e.g., \n, \b, \t, ...
92 * are avoided by the ad hoc choices here.
93 * See ifilt[] in n1.c for others -- 1, 2, 3, 5, 6, 7, 010, 011, 012
97 #define IMP 004 /* impossible char; glues things together */
99 #define RPT 014 /* next character is to be repeated many times */
100 #define CHARHT 015 /* size field sets character height */
101 #define SLANT 016 /* size field sets amount of slant */
102 #define DRAWFCN 017 /* next several chars describe arb drawing fcn */
103 /* line: 'l' dx dy char */
105 /* ellipse: 'e' rx ry */
106 /* arc: 'a' dx dy r */
107 /* wiggly line '~' x y x y ... */
109 #define DRAWCIRCLE 'c' /* circle */
110 #define DRAWELLIPSE 'e'
111 #define DRAWARC 'a' /* arbitrary arc */
112 #define DRAWSPLINE '~' /* quadratic B spline */
114 #define LEFT 020 /* \{ */
115 #define RIGHT 021 /* \} */
116 #define FILLER 022 /* \& and similar purposes */
117 #define XON 023 /* \X'...' starts here */
118 #define OHC 024 /* optional hyphenation character \% */
119 #define CONT 025 /* \c character */
120 #define PRESC 026 /* printable escape */
121 #define UNPAD 027 /* unpaddable blank */
122 #define XPAR 030 /* transparent mode indicator */
124 #define WORDSP 032 /* paddable word space */
126 #define XOFF 034 /* \X'...' ends here */
128 #define iscontrol(n) (n==035 || n==036) /* used to test the next two */
129 #define HX 035 /* next character is value of \x'...' */
130 #define FONTPOS 036 /* position of font \f(XX encoded in top */
132 #define HYPHEN c_hyphen
133 #define EMDASH c_emdash /* \(em */
134 #define RULE c_rule /* \(ru */
135 #define MINUS c_minus /* minus sign on current font */
136 #define LIG_FI c_fi /* \(ff */
137 #define LIG_FL c_fl /* \(fl */
138 #define LIG_FF c_ff /* \(ff */
139 #define LIG_FFI c_ffi /* \(Fi */
140 #define LIG_FFL c_ffl /* \(Fl */
141 #define ACUTE c_acute /* acute accent \(aa */
142 #define GRAVE c_grave /* grave accent \(ga */
143 #define UNDERLINE c_under /* \(ul */
144 #define ROOTEN c_rooten /* root en \(rn */
145 #define BOXRULE c_boxrule /* box rule \(br */
146 #define LEFTHAND c_lefthand /* left hand for word overflow */
147 #define DAGGER c_dagger /* dagger for footnotes */
149 /* array sizes, and similar limits: */
151 #define NFONT 10 /* maximum number of fonts (including specials) */
152 #define EXTRAFONT 500 /* extra space for swapping a font */
153 #define NN 400 /* number registers */
154 #define NNAMES 15 /* predefined reg names */
155 #define NIF 15 /* if-else nesting */
156 #define NS 128 /* name buffer */
157 #define NTM 256 /* tm buffer */
158 #define NEV 3 /* environments */
159 #define EVLSZ 10 /* size of ev stack */
160 #define DSIZE 512 /* disk sector size in chars */
162 #define NM 500 /* requests + macros */
163 #define DELTA 1024 /* delta core bytes */
164 #define NHYP 10 /* max hyphens per word */
165 #define NHEX 128 /* byte size of exception word list */
166 #define NTAB 40 /* tab stops */
167 #define NSO 5 /* "so" depth */
168 #define NMF 5 /* number of -m flags */
169 #define WDSIZE 540 /* word buffer size */
170 #define LNSIZE 680 /* line buffer size */
171 #define NDI 5 /* number of diversions */
172 #define NCHARS 512 /* maximum size of troff character set */
173 #define NTRTAB NCHARS /* number of items in trtab[] */
174 #define NWIDCACHE NCHARS /* number of items in widcache */
175 #define NTRAP 20 /* number of traps */
176 #define NPN 20 /* numbers in "-o" */
177 #define FBUFSZ 256 /* field buf size words */
178 #define OBUFSZ 4096 /* bytes */
179 #define IBUFSZ 4096 /* bytes */
180 #define NC 1024 /* cbuf size words */
181 #define NOV 10 /* number of overstrike chars */
182 #define NPP 10 /* pads per field */
185 Internal character representation:
186 Internally, every character is carried around as
187 a 32 bit cookie, called a "tchar" (typedef long).
188 Bits are numbered 31..0 from left to right.
189 If bit 15 is 1, the character is motion, with
190 if bit 16 it's vertical motion
191 if bit 17 it's negative motion
192 If bit 15 is 0, the character is a real character.
193 if bit 31 zero motion
197 bit 8 absolute char number in 7..0
198 This implies at most 256-32 characters in a single font,
199 which is going to be a problem somewhere
201 bits 14,13 identifier for the colunm of print of character.
202 bits 12,11 multibyte position identifier
203 Currently, this applies only to nroff.
207 /* in the following, "L" should really be a tchar, but ... */
209 #define MOT (01L<<15) /* motion character indicator */
210 #define MOTV (07L<<15) /* clear for motion part */
211 #define VMOT (01L<<16) /* vert motion bit */
212 #define NMOT (01L<<17) /* negative motion indicator*/
213 #define MAXMOT 32767 /* bad way to write this!!! */
214 #define ismot(n) ((n) & MOT)
215 #define isvmot(n) ((n) & VMOT) /* must have tested MOT previously */
216 #define isnmot(n) ((n) & NMOT) /* ditto */
217 #define absmot(n) (unsigned)(0177777 & (n) & ~MOT) /* (short) is cheap mask */
219 #define ZBIT 0x80000000 /* (01L << 31) */ /* zero width char */
220 #define iszbit(n) ((n) & ZBIT)
221 #define ABSCHAR 0400 /* absolute char number in this font */
223 #define SMASK (0177L << 24)
224 #define FMASK (0377L << 16)
225 #define SFMASK (SMASK|FMASK) /* size and font in a tchar */
226 #define sbits(n) (unsigned)(((n) >> 24) & 0177)
227 #define fbits(n) (((n) >> 16) & 0377)
228 #define sfbits(n) (unsigned)(0177777 & (((n) & SFMASK) >> 16))
229 #define cbits(n) (unsigned)(0177777 & (n)) /* isolate bottom 16 bits */
230 #define absbits(n) (cbits(n) & ~ABSCHAR)
232 #define setsbits(n,s) n = (n & ~SMASK) | (tchar)(s) << 24
233 #define setfbits(n,f) n = (n & ~FMASK) | (tchar)(f) << 16
234 #define setsfbits(n,sf) n = (n & ~SFMASK) | (tchar)(sf) << 16
235 #define setcbits(n,c) n = (n & ~077777L | (c)) /* set character bits */
237 #define BYTEMASK 0377
240 #define ischar(n) (((n) & ~BYTEMASK) == 0)
244 #define CSMASK 0x6000 /* colunm of print identifier */
245 #define MBMASK 0x1c00 /* bits identifying position in a multibyte char */
246 #define MBMASK1 0x1800
247 #define FIRSTOFMB 0x1000
248 #define MIDDLEOFMB 0x0800
249 #define LASTOFMB 0x0400
250 #define BYTE_CHR 0x0000
251 #define cs(n) (((n) & CSMASK) >> 13) /* colum of print of character */
252 #define setcsbits(n,c) n = ((n & ~CSMASK) | ((c) << 13))
253 #define CHMASK (BYTEMASK | CSMASK | MBMASK)
254 #define ZWDELIM1 ZBIT | FIRSTOFMB | ' ' /* non-ASCII word delimiter 1 */
255 #define ZWDELIM2 ZBIT | MIDDLEOFMB | ' ' /* non-ASCII word delimiter 2 */
256 #define ZWDELIM(c) ((c) == 0) ? ' ' : ((c) == 1) ? ZWDELIM1 : ZWDELIM2
260 #define ZONE 5 /* 5 hrs for EST */
261 #define TABMASK 037777
262 #define RTAB (unsigned) 0100000
265 #define TABBIT 02 /* bits in gchtab */
269 #define PAIR(A,B) (A|(B<<BYTE))
272 #define oput(c) if ((*obufp++ = (c)), obufp >= &obuf[OBUFSZ]) flusho(); else
275 #define oput(c) if ((*obufp++ = (c)), obufp >= &obuf[OBUFSZ]) flusho(); else
277 #define oput(c) if ((*obufp++ = cbits(c) & BYTEMASK), obufp >= &obuf[OBUFSZ]) flusho(); else
281 * "temp file" parameters. macros and strings
282 * are stored in an array of linked blocks,
283 * which may be in memory and an array called
284 * corebuf[], if INCORE is set during
285 * compilation, or otherwise in a file called trtmp$$.
287 * The numerology is delicate if filep is 16 bits:
290 * i.e., the product is 16 bits long.
292 * If filep is an unsigned long (and if your
293 * compiler will let you say that) then NBLIST
294 * can be a lot bigger. Of course that makes
295 * the file or core image a lot bigger too,
296 * and means you don't detect missing diversion
297 * terminations as quickly... .
298 * It also means that you may have trouble running
299 * on non-swapping systems, since the core image
302 * BLK must be a power of 2
305 typedef unsigned int filep
; /* this is good for 32 bit machines */
307 #define BLK 128 /* alloc block in tchars */
312 # define NBLIST 1024 /* allocation list. smallish machines use 512 */
313 /* machines with paging can use 2048 */
316 /* Other things are stored in the temp file or corebuf:
317 * a single block for .rd input, at offset RD_OFFSET
318 * NEV copies of the environment block, at offset ENV_OFFSET
320 * The existing implementation assumes very strongly that
321 * these are respectively NBLIST*BLK and 0.
325 #define RD_OFFSET (NBLIST * BLK)
327 #define ENV_BLK ((NEV * sizeof(env) / sizeof(tchar) + BLK-1) / BLK)
328 /* rounded up to even BLK */
332 extern tchar
getch(), getch0();
333 extern tchar
rbf(), rbf0();
334 extern tchar
mot(), hmot(), vmot();
335 extern tchar
makem(), sethl();
337 extern tchar
getlg();
339 extern tchar
setfield();
341 extern tchar
setch();
342 extern tchar
setht(), setslant();
344 #define atoi(i) ((int) atoi0(i))
347 extern int Inch
, Hor
, Vert
, Unitwidth
;
349 /* these characters are used as various signals or values
350 * in miscellaneous places.
351 * values are set in specnames in t10.c
367 extern int c_boxrule
;
368 extern int c_lefthand
;
372 * <widec.h> includes <stdio.h> which defines
373 * stderr. So undef it if it is already defined.
378 extern int stderr
; /* this is NOT the stdio value! */
381 extern int debug
; /*debug flag*/
382 #define DB_MAC 01 /*print out macro calls*/
383 #define DB_ALLC 02 /*print out message from alloc()*/
384 #define DB_GETC 04 /*print out message from getch()*/
385 #define DB_LOOP 010 /*print out message before "Eileen's loop" fix*/
388 struct d
{ /* diversion */
403 struct s
{ /* stack frame */
415 extern struct contab
{
422 extern struct numtab
{
446 /* the infamous environment block */
450 #define spacesz env._spacesz
452 #define lss1 env._lss1
459 #define chbits env._chbits
460 #define spbits env._spbits
461 #define nmbits env._nmbits
462 #define apts env._apts
463 #define apts1 env._apts1
465 #define pts1 env._pts1
466 #define font env._font
467 #define font1 env._font1
477 #define tdelim env._tdelim
479 #define hyoff env._hyoff
481 #define tabc env._tabc
482 #define dotc env._dotc
483 #define adsp env._adsp
484 #define adrem env._adrem
485 #define lastl env._lastl
487 #define admod env._admod
488 #define wordp env._wordp
489 #define spflg env._spflg
490 #define linep env._linep
491 #define wdend env._wdend
492 #define wdstart env._wdstart
497 #define lnmod env._lnmod
508 #define pendt env._pendt
509 #define pendw env._pendw
510 #define pendnf env._pendnf
511 #define spread env._spread
513 #define itmac env._itmac
514 #define lnsize env._lnsize
515 #define hyptr env._hyptr
516 #define tabtab env._tabtab
517 #define line env._line
518 #define word env._word