xref: /illumos-gate/usr/src/cmd/troff/tdef.h (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
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 /* starting values for typesetting parameters: */
41 
42 #define	PS	10	/* default point size */
43 #define	FT	1	/* default font position */
44 #define ULFONT	2	/* default underline font */
45 #define	BDFONT	3	/* default emboldening font */
46 #define	BIFONT	4	/* default bold italic font */
47 #define	LL	(unsigned) 65*INCH/10	/* line length; 39picas=6.5in */
48 #define	VS	((12*INCH)/72)	/* initial vert space */
49 
50 #ifdef	NROFF
51 #	define	EM	t.Em
52 #	define	HOR	t.Adj
53 #	define	VERT	t.Vert
54 #	define	INCH	240	/* increments per inch */
55 #	define	SPS	INCH/10	/* space size */
56 #	define	SS	INCH/10	/* " */
57 #	define	TRAILER	0
58 #	define	PO	0 /* page offset */
59 #	define	ASCII	1
60 #	define	PTID	1
61 #	define	LG	0
62 #	define	DTAB	0	/* set at 8 Ems at init time */
63 #	define	ICS	2*SPS
64 #endif
65 #ifndef NROFF	/* TROFF */
66 	/* Inch is set by ptinit() when troff started. */
67 	/* all derived values set then too
68 	*/
69 #	define	INCH	Inch	/* troff resolution -- number of goobies/inch  */
70 #	define	POINT	(INCH/72)	/* goobies per point (1/72 inch) */
71 #	define	HOR	Hor	/* horizontal resolution in goobies */
72 #	define	VERT	Vert	/* vertical resolution in goobies */
73 #	define	SPS	(EM/3)	/* space size  */
74 #	define	SS	12	/* space size in 36ths of an em */
75 #	define	PO	(INCH)	/* page offset 1 inch */
76 /* #	define	EM	(POINT * pts) */
77 #define	EM	(((long) INCH * pts + 36) / 72)	/* don't lose significance */
78 #define	EMPTS(pts)	(((long) INCH * (pts) + 36) / 72)
79 #	define	ASCII	0
80 #	define	PTID	1
81 #	define	LG	1
82 #	define	DTAB	(INCH/2)
83 #	define	ICS	3*SPS
84 #endif
85 
86 /* These "characters" are used to encode various internal functions
87  * Some make use of the fact that most ascii characters between
88  * 0 and 040 don't have any graphic or other function.
89  * The few that do have a purpose (e.g., \n, \b, \t, ...
90  * are avoided by the ad hoc choices here.
91  * See ifilt[] in n1.c for others -- 1, 2, 3, 5, 6, 7, 010, 011, 012
92  */
93 
94 #define	LEADER	001
95 #define	IMP	004	/* impossible char; glues things together */
96 #define	TAB	011
97 #define	RPT	014	/* next character is to be repeated many times */
98 #define	CHARHT	015	/* size field sets character height */
99 #define	SLANT	016	/* size field sets amount of slant */
100 #define	DRAWFCN	017	/* next several chars describe arb drawing fcn */
101 			/* line: 'l' dx dy char */
102 			/* circle: 'c' r */
103 			/* ellipse: 'e' rx ry */
104 			/* arc: 'a' dx dy r */
105 			/* wiggly line '~' x y x y ... */
106 #define	DRAWLINE	'l'
107 #define	DRAWCIRCLE	'c'	/* circle */
108 #define	DRAWELLIPSE	'e'
109 #define	DRAWARC		'a'	/* arbitrary arc */
110 #define	DRAWSPLINE	'~'	/* quadratic B spline */
111 
112 #define	LEFT	020	/* \{ */
113 #define	RIGHT	021	/* \} */
114 #define	FILLER	022	/* \& and similar purposes */
115 #define	XON	023	/* \X'...' starts here */
116 #define	OHC	024	/* optional hyphenation character \% */
117 #define	CONT	025	/* \c character */
118 #define	PRESC	026	/* printable escape */
119 #define	UNPAD	027	/* unpaddable blank */
120 #define	XPAR	030	/* transparent mode indicator */
121 #define	FLSS	031
122 #define	WORDSP	032	/* paddable word space */
123 #define	ESC	033
124 #define	XOFF	034	/* \X'...' ends here */
125 
126 #define	iscontrol(n)	(n==035 || n==036)	/* used to test the next two */
127 #define	HX	035	/* next character is value of \x'...' */
128 #define	FONTPOS	036	/* position of font \f(XX encoded in top */
129 
130 #define	HYPHEN	c_hyphen
131 #define	EMDASH	c_emdash	/* \(em */
132 #define	RULE	c_rule		/* \(ru */
133 #define	MINUS	c_minus		/* minus sign on current font */
134 #define	LIG_FI	c_fi		/* \(ff */
135 #define	LIG_FL	c_fl		/* \(fl */
136 #define	LIG_FF	c_ff		/* \(ff */
137 #define	LIG_FFI	c_ffi		/* \(Fi */
138 #define	LIG_FFL	c_ffl		/* \(Fl */
139 #define	ACUTE	c_acute		/* acute accent \(aa */
140 #define	GRAVE	c_grave		/* grave accent \(ga */
141 #define	UNDERLINE c_under	/* \(ul */
142 #define	ROOTEN	c_rooten	/* root en \(rn */
143 #define	BOXRULE	c_boxrule	/* box rule \(br */
144 #define	LEFTHAND c_lefthand	/* left hand for word overflow */
145 #define	DAGGER	c_dagger	/* dagger for footnotes */
146 
147 /* array sizes, and similar limits: */
148 
149 #define	NFONT	10	/* maximum number of fonts (including specials) */
150 #define	EXTRAFONT 500	/* extra space for swapping a font */
151 #define	NN	400	/* number registers */
152 #define	NNAMES	15	 /* predefined reg names */
153 #define	NIF	15	/* if-else nesting */
154 #define	NS	128	/* name buffer */
155 #define	NTM	256	/* tm buffer */
156 #define	NEV	3	/* environments */
157 #define	EVLSZ	10	/* size of ev stack */
158 #define	DSIZE	512	/* disk sector size in chars */
159 
160 #define	NM	500	/* requests + macros */
161 #define	DELTA	1024	/* delta core bytes */
162 #define	NHYP	10	/* max hyphens per word */
163 #define	NHEX	128	/* byte size of exception word list */
164 #define	NTAB	40	/* tab stops */
165 #define	NSO	5	/* "so" depth */
166 #define	NMF	5	/* number of -m flags */
167 #define	WDSIZE	540	/* word buffer size */
168 #define	LNSIZE	680	/* line buffer size */
169 #define	NDI	5	/* number of diversions */
170 #define	NCHARS	512	/* maximum size of troff character set */
171 #define	NTRTAB	NCHARS	/* number of items in trtab[] */
172 #define	NWIDCACHE NCHARS	/* number of items in widcache */
173 #define	NTRAP	20	/* number of traps */
174 #define	NPN	20	/* numbers in "-o" */
175 #define	FBUFSZ	256	/* field buf size words */
176 #define	OBUFSZ	4096	/* bytes */
177 #define	IBUFSZ	4096	/* bytes */
178 #define	NC	1024	/* cbuf size words */
179 #define	NOV	10	/* number of overstrike chars */
180 #define	NPP	10	/* pads per field */
181 
182 /*
183 	Internal character representation:
184 	Internally, every character is carried around as
185 	a 32 bit cookie, called a "tchar" (typedef long).
186 	Bits are numbered 31..0 from left to right.
187 	If bit 15 is 1, the character is motion, with
188 		if bit 16 it's vertical motion
189 		if bit 17 it's negative motion
190 	If bit 15 is 0, the character is a real character.
191 		if bit 31	zero motion
192 		bits 30..24	size
193 		bits 23..16	font
194 ifndef EUC
195 		bit 8		absolute char number in 7..0
196 	This implies at most 256-32 characters in a single font,
197 	which is going to be a problem somewhere
198 else
199 		bits 14,13	identifier for the colunm of print of character.
200 		bits 12,11	multibyte position identifier
201 	Currently, this applies only to nroff.
202 endif EUC
203 */
204 
205 /* in the following, "L" should really be a tchar, but ... */
206 
207 #define	MOT	(01L<<15)	/* motion character indicator */
208 #define	MOTV	(07L<<15)	/* clear for motion part */
209 #define	VMOT	(01L<<16)	/* vert motion bit */
210 #define	NMOT	(01L<<17)	/* negative motion indicator*/
211 #define	MAXMOT	32767	/* bad way to write this!!! */
212 #define	ismot(n)	((n) & MOT)
213 #define	isvmot(n)	((n) & VMOT)	/* must have tested MOT previously */
214 #define	isnmot(n)	((n) & NMOT)	/* ditto */
215 #define	absmot(n)	(unsigned)(0177777 & (n) & ~MOT)	/* (short) is cheap mask */
216 
217 #define	ZBIT	0x80000000 	/*  (01L << 31) */	/* zero width char */
218 #define	iszbit(n)	((n) & ZBIT)
219 #define	ABSCHAR		0400	/* absolute char number in this font */
220 
221 #define	SMASK		(0177L << 24)
222 #define	FMASK		(0377L << 16)
223 #define	SFMASK		(SMASK|FMASK)	/* size and font in a tchar */
224 #define	sbits(n)	(unsigned)(((n) >> 24) & 0177)
225 #define	fbits(n)	(((n) >> 16) & 0377)
226 #define	sfbits(n)	(unsigned)(0177777 & (((n) & SFMASK) >> 16))
227 #define	cbits(n)	(unsigned)(0177777 & (n))	/* isolate bottom 16 bits  */
228 #define	absbits(n)	(cbits(n) & ~ABSCHAR)
229 
230 #define	setsbits(n,s)	n = (n & ~SMASK) | (tchar)(s) << 24
231 #define	setfbits(n,f)	n = (n & ~FMASK) | (tchar)(f) << 16
232 #define	setsfbits(n,sf)	n = (n & ~SFMASK) | (tchar)(sf) << 16
233 #define	setcbits(n,c)	n = (n & ~077777L | (c))	/* set character bits */
234 
235 #define	BYTEMASK	0377
236 #define	BYTE	8
237 
238 #define	ischar(n)	(((n) & ~BYTEMASK) == 0)
239 
240 #ifdef EUC
241 #ifdef NROFF
242 #define CSMASK	0x6000	/* colunm of print identifier */
243 #define MBMASK	0x1c00	/* bits identifying position in a multibyte char */
244 #define MBMASK1	0x1800
245 #define FIRSTOFMB	0x1000
246 #define MIDDLEOFMB	0x0800
247 #define LASTOFMB	0x0400
248 #define BYTE_CHR	0x0000
249 #define	cs(n)	(((n) & CSMASK) >> 13)	/* colum of print of character */
250 #define	setcsbits(n,c)	n = ((n & ~CSMASK) | ((c) << 13))
251 #define CHMASK	(BYTEMASK | CSMASK | MBMASK)
252 #define ZWDELIM1	ZBIT | FIRSTOFMB | ' '	/* non-ASCII word delimiter 1 */
253 #define ZWDELIM2	ZBIT | MIDDLEOFMB | ' '	/* non-ASCII word delimiter 2 */
254 #define ZWDELIM(c)	((c) == 0) ? ' ' : ((c) == 1) ? ZWDELIM1 : ZWDELIM2
255 #endif /* NROFF */
256 #endif /* EUC */
257 
258 #define	ZONE	5	/* 5 hrs for EST */
259 #define	TABMASK	 037777
260 #define	RTAB	(unsigned) 0100000
261 #define	CTAB	040000
262 
263 #define	TABBIT	02		/* bits in gchtab */
264 #define	LDRBIT	04
265 #define	FCBIT	010
266 
267 #define	PAIR(A,B)	(A|(B<<BYTE))
268 
269 #ifndef EUC
270 #define	oput(c)	if ((*obufp++ = (c)), obufp >= &obuf[OBUFSZ]) flusho(); else
271 #else
272 #ifndef NROFF
273 #define	oput(c)	if ((*obufp++ = (c)), obufp >= &obuf[OBUFSZ]) flusho(); else
274 #endif /* NROFF */
275 #define	oput(c)	if ((*obufp++ = cbits(c) & BYTEMASK), obufp >= &obuf[OBUFSZ]) flusho(); else
276 #endif /* EUC */
277 
278 /*
279  * "temp file" parameters.  macros and strings
280  * are stored in an array of linked blocks,
281  * which may be in memory and an array called
282  * corebuf[], if INCORE is set during
283  * compilation, or otherwise in a file called trtmp$$.
284 
285  * The numerology is delicate if filep is 16 bits:
286 	#define BLK 128
287 	#define NBLIST 512
288  * i.e., the product is 16 bits long.
289 
290  * If filep is an unsigned long (and if your
291  * compiler will let you say that) then NBLIST
292  * can be a lot bigger.  Of course that makes
293  * the file or core image a lot bigger too,
294  * and means you don't detect missing diversion
295  * terminations as quickly... .
296  * It also means that you may have trouble running
297  * on non-swapping systems, since the core image
298  * will be over 1Mb.
299 
300  * BLK must be a power of 2
301  */
302 
303 typedef unsigned int filep;	/* this is good for 32 bit machines */
304 
305 #define	BLK	128	/* alloc block in tchars */
306 
307 #ifdef SMALLER
308 #	define	NBLIST	512
309 #else
310 #	define	NBLIST	1024	/* allocation list.  smallish machines use 512 */
311 				/* machines with paging can use 2048 */
312 #endif
313 
314 /* Other things are stored in the temp file or corebuf:
315  *	a single block for .rd input, at offset RD_OFFSET
316  *	NEV copies of the environment block, at offset ENV_OFFSET
317 
318  * The existing implementation assumes very strongly that
319  * these are respectively NBLIST*BLK and 0.
320 
321  */
322 
323 #define	RD_OFFSET	(NBLIST * BLK)
324 #define ENV_OFFSET	0
325 #define	ENV_BLK		((NEV * sizeof(env) / sizeof(tchar) + BLK-1) / BLK)
326 				/* rounded up to even BLK */
327 
328 typedef	long	tchar;
329 
330 extern	tchar	getch(), getch0();
331 extern	tchar	rbf(), rbf0();
332 extern	tchar	mot(), hmot(), vmot();
333 extern	tchar	makem(), sethl();
334 extern	tchar	popi();
335 extern	tchar	getlg();
336 extern	tchar	xlss();
337 extern	tchar	setfield();
338 extern	tchar	setz();
339 extern	tchar	setch();
340 extern	tchar	setht(), setslant();
341 
342 #define	atoi(i)		((int) atoi0(i))
343 extern	long	atoi0();
344 
345 extern	int	Inch, Hor, Vert, Unitwidth;
346 
347 /* these characters are used as various signals or values
348  * in miscellaneous places.
349  * values are set in specnames in t10.c
350  */
351 
352 extern int	c_hyphen;
353 extern int	c_emdash;
354 extern int	c_rule;
355 extern int	c_minus;
356 extern int	c_fi;
357 extern int	c_fl;
358 extern int	c_ff;
359 extern int	c_ffi;
360 extern int	c_ffl;
361 extern int	c_acute;
362 extern int	c_grave;
363 extern int	c_under;
364 extern int	c_rooten;
365 extern int	c_boxrule;
366 extern int	c_lefthand;
367 extern int	c_dagger;
368 
369 /*
370  * <widec.h> includes <stdio.h> which defines
371  * stderr. So undef it if it is already defined.
372  */
373 #ifdef stderr
374 #	undef stderr
375 #endif
376 extern int	stderr;	/* this is NOT the stdio value! */
377 
378 #ifdef	DEBUG
379 extern	int	debug;	/*debug flag*/
380 #define	DB_MAC	01	/*print out macro calls*/
381 #define	DB_ALLC	02	/*print out message from alloc()*/
382 #define	DB_GETC	04	/*print out message from getch()*/
383 #define	DB_LOOP	010	/*print out message before "Eileen's loop" fix*/
384 #endif	/* DEBUG */
385 
386 struct	d {	/* diversion */
387 	filep	op;
388 	int	dnl;
389 	int	dimac;
390 	int	ditrap;
391 	int	ditf;
392 	int	alss;
393 	int	blss;
394 	int	nls;
395 	int	mkline;
396 	int	maxl;
397 	int	hnl;
398 	int	curd;
399 };
400 
401 struct	s {	/* stack frame */
402 	int	nargs;
403 	struct s *pframe;
404 	filep	pip;
405 	int	pnchar;
406 	tchar	prchar;
407 	int	ppendt;
408 	tchar	pch;
409 	tchar	*lastpbp;
410 	int	mname;
411 };
412 
413 extern struct contab {
414 	unsigned short	rq;
415 	struct	contab *link;
416 	int	(*f)();
417 	unsigned mx;
418 } contab[NM];
419 
420 extern struct numtab {
421 	short	r;		/* name */
422 	short	fmt;
423 	short	inc;
424 	int	val;
425 	struct	numtab *link;
426 } numtab[NN];
427 
428 #define	PN	0
429 #define	NL	1
430 #define	YR	2
431 #define	HP	3
432 #define	CT	4
433 #define	DN	5
434 #define	MO	6
435 #define	DY	7
436 #define	DW	8
437 #define	LN	9
438 #define	DL	10
439 #define	ST	11
440 #define	SB	12
441 #define	CD	13
442 #define	PID	14
443 
444 /* the infamous environment block */
445 
446 #define	ics	env._ics
447 #define	sps	env._sps
448 #define	spacesz	env._spacesz
449 #define	lss	env._lss
450 #define	lss1	env._lss1
451 #define	ll	env._ll
452 #define	ll1	env._ll1
453 #define	lt	env._lt
454 #define	lt1	env._lt1
455 #define	ic	env._ic
456 #define	icf	env._icf
457 #define	chbits	env._chbits
458 #define	spbits	env._spbits
459 #define	nmbits	env._nmbits
460 #define	apts	env._apts
461 #define	apts1	env._apts1
462 #define	pts	env._pts
463 #define	pts1	env._pts1
464 #define	font	env._font
465 #define	font1	env._font1
466 #define	ls	env._ls
467 #define	ls1	env._ls1
468 #define	ad	env._ad
469 #define	nms	env._nms
470 #define	ndf	env._ndf
471 #define	fi	env._fi
472 #define	cc	env._cc
473 #define	c2	env._c2
474 #define	ohc	env._ohc
475 #define	tdelim	env._tdelim
476 #define	hyf	env._hyf
477 #define	hyoff	env._hyoff
478 #define	un1	env._un1
479 #define	tabc	env._tabc
480 #define	dotc	env._dotc
481 #define	adsp	env._adsp
482 #define	adrem	env._adrem
483 #define	lastl	env._lastl
484 #define	nel	env._nel
485 #define	admod	env._admod
486 #define	wordp	env._wordp
487 #define	spflg	env._spflg
488 #define	linep	env._linep
489 #define	wdend	env._wdend
490 #define	wdstart	env._wdstart
491 #define	wne	env._wne
492 #define	ne	env._ne
493 #define	nc	env._nc
494 #define	nb	env._nb
495 #define	lnmod	env._lnmod
496 #define	nwd	env._nwd
497 #define	nn	env._nn
498 #define	ni	env._ni
499 #define	ul	env._ul
500 #define	cu	env._cu
501 #define	ce	env._ce
502 #define	in	env._in
503 #define	in1	env._in1
504 #define	un	env._un
505 #define	wch	env._wch
506 #define	pendt	env._pendt
507 #define	pendw	env._pendw
508 #define	pendnf	env._pendnf
509 #define	spread	env._spread
510 #define	it	env._it
511 #define	itmac	env._itmac
512 #define	lnsize	env._lnsize
513 #define	hyptr	env._hyptr
514 #define	tabtab	env._tabtab
515 #define	line	env._line
516 #define	word	env._word
517 
518 extern struct env {
519 	int	_ics;
520 	int	_sps;
521 	int	_spacesz;
522 	int	_lss;
523 	int	_lss1;
524 	int	_ll;
525 	int	_ll1;
526 	int	_lt;
527 	int	_lt1;
528 	tchar	_ic;
529 	int	_icf;
530 	tchar	_chbits;
531 	tchar	_spbits;
532 	tchar	_nmbits;
533 	int	_apts;
534 	int	_apts1;
535 	int	_pts;
536 	int	_pts1;
537 	int	_font;
538 	int	_font1;
539 	int	_ls;
540 	int	_ls1;
541 	int	_ad;
542 	int	_nms;
543 	int	_ndf;
544 	int	_fi;
545 	int	_cc;
546 	int	_c2;
547 	int	_ohc;
548 	int	_tdelim;
549 	int	_hyf;
550 	int	_hyoff;
551 	int	_un1;
552 	int	_tabc;
553 	int	_dotc;
554 	int	_adsp;
555 	int	_adrem;
556 	int	_lastl;
557 	int	_nel;
558 	int	_admod;
559 	tchar	*_wordp;
560 	int	_spflg;
561 	tchar	*_linep;
562 	tchar	*_wdend;
563 	tchar	*_wdstart;
564 	int	_wne;
565 	int	_ne;
566 	int	_nc;
567 	int	_nb;
568 	int	_lnmod;
569 	int	_nwd;
570 	int	_nn;
571 	int	_ni;
572 	int	_ul;
573 	int	_cu;
574 	int	_ce;
575 	int	_in;
576 	int	_in1;
577 	int	_un;
578 	int	_wch;
579 	int	_pendt;
580 	tchar	*_pendw;
581 	int	_pendnf;
582 	int	_spread;
583 	int	_it;
584 	int	_itmac;
585 	int	_lnsize;
586 	tchar	*_hyptr[NHYP];
587 	int	_tabtab[NTAB];
588 	tchar	_line[LNSIZE];
589 	tchar	_word[WDSIZE];
590 } env;
591