xref: /illumos-gate/usr/src/cmd/troff/tdef.h (revision afab0816ecb604f0099a09ad8ee398f0d7b77b1c)
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 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 /* starting values for typesetting parameters: */
43 
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 */
51 
52 #ifdef	NROFF
53 #	define	EM	t.Em
54 #	define	HOR	t.Adj
55 #	define	VERT	t.Vert
56 #	define	INCH	240	/* increments per inch */
57 #	define	SPS	INCH/10	/* space size */
58 #	define	SS	INCH/10	/* " */
59 #	define	TRAILER	0
60 #	define	PO	0 /* page offset */
61 #	define	ASCII	1
62 #	define	PTID	1
63 #	define	LG	0
64 #	define	DTAB	0	/* set at 8 Ems at init time */
65 #	define	ICS	2*SPS
66 #endif
67 #ifndef NROFF	/* TROFF */
68 	/* Inch is set by ptinit() when troff started. */
69 	/* all derived values set then too
70 	*/
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)
81 #	define	ASCII	0
82 #	define	PTID	1
83 #	define	LG	1
84 #	define	DTAB	(INCH/2)
85 #	define	ICS	3*SPS
86 #endif
87 
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
94  */
95 
96 #define	LEADER	001
97 #define	IMP	004	/* impossible char; glues things together */
98 #define	TAB	011
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 */
104 			/* circle: 'c' r */
105 			/* ellipse: 'e' rx ry */
106 			/* arc: 'a' dx dy r */
107 			/* wiggly line '~' x y x y ... */
108 #define	DRAWLINE	'l'
109 #define	DRAWCIRCLE	'c'	/* circle */
110 #define	DRAWELLIPSE	'e'
111 #define	DRAWARC		'a'	/* arbitrary arc */
112 #define	DRAWSPLINE	'~'	/* quadratic B spline */
113 
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 */
123 #define	FLSS	031
124 #define	WORDSP	032	/* paddable word space */
125 #define	ESC	033
126 #define	XOFF	034	/* \X'...' ends here */
127 
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 */
131 
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 */
148 
149 /* array sizes, and similar limits: */
150 
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 */
161 
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 */
183 
184 /*
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
194 		bits 30..24	size
195 		bits 23..16	font
196 ifndef EUC
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
200 else
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.
204 endif EUC
205 */
206 
207 /* in the following, "L" should really be a tchar, but ... */
208 
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 */
218 
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 */
222 
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)
231 
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 */
236 
237 #define	BYTEMASK	0377
238 #define	BYTE	8
239 
240 #define	ischar(n)	(((n) & ~BYTEMASK) == 0)
241 
242 #ifdef EUC
243 #ifdef NROFF
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
257 #endif /* NROFF */
258 #endif /* EUC */
259 
260 #define	ZONE	5	/* 5 hrs for EST */
261 #define	TABMASK	 037777
262 #define	RTAB	(unsigned) 0100000
263 #define	CTAB	040000
264 
265 #define	TABBIT	02		/* bits in gchtab */
266 #define	LDRBIT	04
267 #define	FCBIT	010
268 
269 #define	PAIR(A,B)	(A|(B<<BYTE))
270 
271 #ifndef EUC
272 #define	oput(c)	if ((*obufp++ = (c)), obufp >= &obuf[OBUFSZ]) flusho(); else
273 #else
274 #ifndef NROFF
275 #define	oput(c)	if ((*obufp++ = (c)), obufp >= &obuf[OBUFSZ]) flusho(); else
276 #endif /* NROFF */
277 #define	oput(c)	if ((*obufp++ = cbits(c) & BYTEMASK), obufp >= &obuf[OBUFSZ]) flusho(); else
278 #endif /* EUC */
279 
280 /*
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$$.
286 
287  * The numerology is delicate if filep is 16 bits:
288 	#define BLK 128
289 	#define NBLIST 512
290  * i.e., the product is 16 bits long.
291 
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
300  * will be over 1Mb.
301 
302  * BLK must be a power of 2
303  */
304 
305 typedef unsigned int filep;	/* this is good for 32 bit machines */
306 
307 #define	BLK	128	/* alloc block in tchars */
308 
309 #ifdef SMALLER
310 #	define	NBLIST	512
311 #else
312 #	define	NBLIST	1024	/* allocation list.  smallish machines use 512 */
313 				/* machines with paging can use 2048 */
314 #endif
315 
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
319 
320  * The existing implementation assumes very strongly that
321  * these are respectively NBLIST*BLK and 0.
322 
323  */
324 
325 #define	RD_OFFSET	(NBLIST * BLK)
326 #define ENV_OFFSET	0
327 #define	ENV_BLK		((NEV * sizeof(env) / sizeof(tchar) + BLK-1) / BLK)
328 				/* rounded up to even BLK */
329 
330 typedef	long	tchar;
331 
332 extern	tchar	getch(), getch0();
333 extern	tchar	rbf(), rbf0();
334 extern	tchar	mot(), hmot(), vmot();
335 extern	tchar	makem(), sethl();
336 extern	tchar	popi();
337 extern	tchar	getlg();
338 extern	tchar	xlss();
339 extern	tchar	setfield();
340 extern	tchar	setz();
341 extern	tchar	setch();
342 extern	tchar	setht(), setslant();
343 
344 #define	atoi(i)		((int) atoi0(i))
345 extern	long	atoi0();
346 
347 extern	int	Inch, Hor, Vert, Unitwidth;
348 
349 /* these characters are used as various signals or values
350  * in miscellaneous places.
351  * values are set in specnames in t10.c
352  */
353 
354 extern int	c_hyphen;
355 extern int	c_emdash;
356 extern int	c_rule;
357 extern int	c_minus;
358 extern int	c_fi;
359 extern int	c_fl;
360 extern int	c_ff;
361 extern int	c_ffi;
362 extern int	c_ffl;
363 extern int	c_acute;
364 extern int	c_grave;
365 extern int	c_under;
366 extern int	c_rooten;
367 extern int	c_boxrule;
368 extern int	c_lefthand;
369 extern int	c_dagger;
370 
371 /*
372  * <widec.h> includes <stdio.h> which defines
373  * stderr. So undef it if it is already defined.
374  */
375 #ifdef stderr
376 #	undef stderr
377 #endif
378 extern int	stderr;	/* this is NOT the stdio value! */
379 
380 #ifdef	DEBUG
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*/
386 #endif	/* DEBUG */
387 
388 struct	d {	/* diversion */
389 	filep	op;
390 	int	dnl;
391 	int	dimac;
392 	int	ditrap;
393 	int	ditf;
394 	int	alss;
395 	int	blss;
396 	int	nls;
397 	int	mkline;
398 	int	maxl;
399 	int	hnl;
400 	int	curd;
401 };
402 
403 struct	s {	/* stack frame */
404 	int	nargs;
405 	struct s *pframe;
406 	filep	pip;
407 	int	pnchar;
408 	tchar	prchar;
409 	int	ppendt;
410 	tchar	pch;
411 	tchar	*lastpbp;
412 	int	mname;
413 };
414 
415 extern struct contab {
416 	unsigned short	rq;
417 	struct	contab *link;
418 	int	(*f)();
419 	unsigned mx;
420 } contab[NM];
421 
422 extern struct numtab {
423 	short	r;		/* name */
424 	short	fmt;
425 	short	inc;
426 	int	val;
427 	struct	numtab *link;
428 } numtab[NN];
429 
430 #define	PN	0
431 #define	NL	1
432 #define	YR	2
433 #define	HP	3
434 #define	CT	4
435 #define	DN	5
436 #define	MO	6
437 #define	DY	7
438 #define	DW	8
439 #define	LN	9
440 #define	DL	10
441 #define	ST	11
442 #define	SB	12
443 #define	CD	13
444 #define	PID	14
445 
446 /* the infamous environment block */
447 
448 #define	ics	env._ics
449 #define	sps	env._sps
450 #define	spacesz	env._spacesz
451 #define	lss	env._lss
452 #define	lss1	env._lss1
453 #define	ll	env._ll
454 #define	ll1	env._ll1
455 #define	lt	env._lt
456 #define	lt1	env._lt1
457 #define	ic	env._ic
458 #define	icf	env._icf
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
464 #define	pts	env._pts
465 #define	pts1	env._pts1
466 #define	font	env._font
467 #define	font1	env._font1
468 #define	ls	env._ls
469 #define	ls1	env._ls1
470 #define	ad	env._ad
471 #define	nms	env._nms
472 #define	ndf	env._ndf
473 #define	fi	env._fi
474 #define	cc	env._cc
475 #define	c2	env._c2
476 #define	ohc	env._ohc
477 #define	tdelim	env._tdelim
478 #define	hyf	env._hyf
479 #define	hyoff	env._hyoff
480 #define	un1	env._un1
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
486 #define	nel	env._nel
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
493 #define	wne	env._wne
494 #define	ne	env._ne
495 #define	nc	env._nc
496 #define	nb	env._nb
497 #define	lnmod	env._lnmod
498 #define	nwd	env._nwd
499 #define	nn	env._nn
500 #define	ni	env._ni
501 #define	ul	env._ul
502 #define	cu	env._cu
503 #define	ce	env._ce
504 #define	in	env._in
505 #define	in1	env._in1
506 #define	un	env._un
507 #define	wch	env._wch
508 #define	pendt	env._pendt
509 #define	pendw	env._pendw
510 #define	pendnf	env._pendnf
511 #define	spread	env._spread
512 #define	it	env._it
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
519 
520 extern struct env {
521 	int	_ics;
522 	int	_sps;
523 	int	_spacesz;
524 	int	_lss;
525 	int	_lss1;
526 	int	_ll;
527 	int	_ll1;
528 	int	_lt;
529 	int	_lt1;
530 	tchar	_ic;
531 	int	_icf;
532 	tchar	_chbits;
533 	tchar	_spbits;
534 	tchar	_nmbits;
535 	int	_apts;
536 	int	_apts1;
537 	int	_pts;
538 	int	_pts1;
539 	int	_font;
540 	int	_font1;
541 	int	_ls;
542 	int	_ls1;
543 	int	_ad;
544 	int	_nms;
545 	int	_ndf;
546 	int	_fi;
547 	int	_cc;
548 	int	_c2;
549 	int	_ohc;
550 	int	_tdelim;
551 	int	_hyf;
552 	int	_hyoff;
553 	int	_un1;
554 	int	_tabc;
555 	int	_dotc;
556 	int	_adsp;
557 	int	_adrem;
558 	int	_lastl;
559 	int	_nel;
560 	int	_admod;
561 	tchar	*_wordp;
562 	int	_spflg;
563 	tchar	*_linep;
564 	tchar	*_wdend;
565 	tchar	*_wdstart;
566 	int	_wne;
567 	int	_ne;
568 	int	_nc;
569 	int	_nb;
570 	int	_lnmod;
571 	int	_nwd;
572 	int	_nn;
573 	int	_ni;
574 	int	_ul;
575 	int	_cu;
576 	int	_ce;
577 	int	_in;
578 	int	_in1;
579 	int	_un;
580 	int	_wch;
581 	int	_pendt;
582 	tchar	*_pendw;
583 	int	_pendnf;
584 	int	_spread;
585 	int	_it;
586 	int	_itmac;
587 	int	_lnsize;
588 	tchar	*_hyptr[NHYP];
589 	int	_tabtab[NTAB];
590 	tchar	_line[LNSIZE];
591 	tchar	_word[WDSIZE];
592 } env;
593