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