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