10 /* Site dependent definitions */
13 #define TMACDIR "lib/tmac/tmac."
16 #define FONTDIR "lib/font"
19 #define NTERMDIR "lib/term/tab."
22 #define TDEVNAME "post"
28 #define TEXHYPHENS "/usr/lib/tex/macros/hyphen.tex"
31 #define ALTHYPHENS "lib/tmac/hyphen.tex" /* another place to look */
34 typedef unsigned char Uchar;
35 typedef unsigned short Ushort;
37 typedef /*unsigned*/ long Tchar;
39 typedef struct Blockp Blockp;
40 typedef struct Diver Diver;
41 typedef struct Stack Stack;
42 typedef struct Divsiz Divsiz;
43 typedef struct Contab Contab;
44 typedef struct Numtab Numtab;
45 typedef struct Numerr Numerr;
46 typedef struct Env Env;
47 typedef struct Term Term;
48 typedef struct Chwid Chwid;
49 typedef struct Font Font;
50 typedef struct Spnames Spnames;
51 typedef struct Wcache Wcache;
52 typedef struct Tbuf Tbuf;
54 /* this simulates printf into a buffer that gets flushed sporadically */
55 /* the BSD goo is because SunOS sprintf doesn't return anything useful */
58 #define OUT (obufp += strlen(sprintf(obufp,
59 #define PUT ))) > obuf+BUFSIZ ? flusho() : 1
61 #define OUT (obufp += sprintf(obufp,
62 #define PUT )) > obuf+BUFSIZ ? flusho() : 1
65 #define oputs(a) OUT "%s", a PUT
66 #define oput(c) ( *obufp++ = (c), obufp > obuf+BUFSIZ ? flusho() : 1 )
69 #define ERROR sprintf(errbuf,
70 #define WARN ), errprint()
71 #define FATAL ), errprint(), exit(1)
73 /* starting values for typesetting parameters: */
75 #define PS 10 /* default point size */
76 #define FT 1 /* default font position */
77 #define ULFONT 2 /* default underline font */
78 #define BDFONT 3 /* default emboldening font */
79 #define BIFONT 4 /* default bold italic font */
80 #define LL (unsigned) 65*INCH/10 /* line length; 39picas=6.5in */
81 #define VS ((12*INCH)/72) /* initial vert space */
84 #define EMPTS(pts) (((long)Inch*(pts) + 36) / 72)
85 #define EM (TROFF? EMPTS(pts): t.Em)
86 #define INCH (TROFF? Inch: 240)
87 #define HOR (TROFF? Hor: t.Adj)
88 #define VERT (TROFF? Vert: t.Vert)
89 #define PO (TROFF? Inch: 0)
90 #define SPS (TROFF? EMPTS(pts)/3: INCH/10)
91 #define SS (TROFF? 12: INCH/10)
92 #define ICS (TROFF? EMPTS(pts): 2*INCH/10)
93 #define DTAB (TROFF? (INCH/2): 0)
95 /* These "characters" are used to encode various internal functions
96 /* Some make use of the fact that most ascii characters between
97 /* 0 and 040 don't have any graphic or other function.
98 /* The few that do have a purpose (e.g., \n, \b, \t, ...
99 /* are avoided by the ad hoc choices here.
100 /* See ifilt[] in n1.c for others -- 1, 2, 3, 5, 6, 7, 010, 011, 012
104 #define IMP 004 /* impossible char; glues things together */
106 #define RPT 014 /* next character is to be repeated many times */
107 #define CHARHT 015 /* size field sets character height */
108 #define SLANT 016 /* size field sets amount of slant */
109 #define DRAWFCN 017 /* next several chars describe arb drawing fcns */
110 # define DRAWLINE 'l' /* line: 'l' dx dy char */
111 # define DRAWCIRCLE 'c' /* circle: 'c' r */
112 # define DRAWELLIPSE 'e' /* ellipse: 'e' rx ry */
113 # define DRAWARC 'a' /* arc: 'a' dx dy dx dy */
114 # define DRAWSPLINE '~' /* quadratic B spline: '~' dx dy dx dy ... */
115 /* other splines go thru too */
116 /* NOTE: the use of ~ is a botch since it's often used in .tr commands */
117 /* better to use a letter like s, but change it in the postprocessors too */
118 /* for now, this is taken care of in n9.c and t10.c */
119 # define DRAWBUILD 'b' /* built-up character (e.g., { */
121 #define LEFT 020 /* \{ */
122 #define RIGHT 021 /* \} */
123 #define FILLER 022 /* \& and similar purposes */
124 #define XON 023 /* \X'...' starts here */
125 #define OHC 024 /* optional hyphenation character \% */
126 #define CONT 025 /* \c character */
127 #define PRESC 026 /* printable escape */
128 #define UNPAD 027 /* unpaddable blank */
129 #define XPAR 030 /* transparent mode indicator */
130 #define FLSS 031 /* next Tchar contains vertical space */
131 /* used when recalling diverted text */
132 #define WORDSP 032 /* paddable word space */
133 #define ESC 033 /* current escape character */
134 #define XOFF 034 /* \X'...' ends here */
135 /* matches XON, but they will probably never nest */
136 /* so could drop this when another control is needed */
137 #define HX 035 /* next character is value of \x'...' */
138 #define MOTCH 036 /* this "character" is really motion; used by cbits() */
140 #define HYPHEN c_hyphen
141 #define EMDASH c_emdash /* \(em */
142 #define RULE c_rule /* \(ru */
143 #define MINUS c_minus /* minus sign on current font */
144 #define LIG_FI c_fi /* \(ff */
145 #define LIG_FL c_fl /* \(fl */
146 #define LIG_FF c_ff /* \(ff */
147 #define LIG_FFI c_ffi /* \(Fi */
148 #define LIG_FFL c_ffl /* \(Fl */
149 #define ACUTE c_acute /* acute accent \(aa */
150 #define GRAVE c_grave /* grave accent \(ga */
151 #define UNDERLINE c_under /* \(ul */
152 #define ROOTEN c_rooten /* root en \(rn */
153 #define BOXRULE c_boxrule /* box rule \(br */
154 #define LEFTHAND c_lefthand /* left hand for word overflow */
155 #define DAGGER c_dagger /* dagger for end of sentence/footnote */
157 #define HYPHALG 1 /* hyphenation algorithm: 0=>good old troff, 1=>tex */
160 /* array sizes, and similar limits: */
162 #define MAXFONTS 99 /* Maximum number of fonts in fontab */
163 #define NM 90 /* requests + macros */
164 #define NN NNAMES /* number registers */
165 #define NNAMES 15 /* predefined reg names */
166 #define NIF 15 /* if-else nesting */
167 #define NS 128 /* name buffer */
168 #define NTM 1024 /* tm buffer */
169 #define NEV 3 /* environments */
170 #define EVLSZ 10 /* size of ev stack */
172 #define STACKSIZE (12*1024) /* stack for macros and strings in progress */
173 #define NHYP 10 /* max hyphens per word */
174 #define NHEX 512 /* byte size of exception word list */
175 #define NTAB 100 /* tab stops */
176 #define NSO 5 /* "so" depth */
177 #define NMF 5 /* number of -m flags */
178 #define WDSIZE 500 /* word buffer click size */
179 #define LNSIZE 4000 /* line buffer click size */
180 #define OLNSIZE 5000 /* output line buffer click; bigger for 'w', etc. */
181 #define NDI 5 /* number of diversions */
183 #define ALPHABET alphabet /* number of characters in basic alphabet. */
184 /* 128 for parochial USA 7-bit ascii, */
185 /* 256 for "European" mode with e.g., Latin-1 */
187 /* NCHARS must be greater than
188 ALPHABET (ascii stuff) + total number of distinct char names
189 from all fonts that will be run in this job (including
190 unnamed ones and \N's)
193 #define NCHARS (8*1024) /* maximum size of troff character set*/
196 /* However for nroff you want only :
197 1. number of special codes in charset of DESC, which ends up being the
198 value of nchtab and which must be less than 512.
199 2. ALPHABET, which apparently is the size of the portion of the tables reserved
200 for special control symbols
201 Apparently the max N of \N is irrelevant; */
202 /* to allow \N of up to 254 with up to 338 special characters
203 you need NCHARS of 338 + ALPHABET = 466 */
205 #define NROFFCHARS 1024 /* maximum size of nroff character set */
207 #define NTRTAB NCHARS /* number of items in trtab[] */
208 #define NWIDCACHE NCHARS /* number of items in widcache[] */
210 #define NTRAP 20 /* number of traps */
211 #define NPN 20 /* numbers in "-o" */
212 #define FBUFSZ 512 /* field buf size words */
213 #define IBUFSZ 4096 /* bytes */
214 #define NC 1024 /* cbuf size words */
215 #define NOV 10 /* number of overstrike chars */
216 #define NPP 10 /* pads per field */
219 Internal character representation:
220 Internally, every character is carried around as
221 a 32 bit cookie, called a "Tchar" (typedef long).
222 Bits are numbered 31..0 from left to right.
223 If bit 15 is 1, the character is motion, with
224 if bit 16 it's vertical motion
225 if bit 17 it's negative motion
226 If bit 15 is 0, the character is a real character.
227 if bit 31 zero motion
232 /* in the following, "L" should really be a Tchar, but ... */
233 /* numerology leaves room for 16 bit chars */
235 #define MOT (01uL << 16) /* motion character indicator */
236 #define VMOT (01uL << 30) /* vertical motion bit */
237 #define NMOT (01uL << 29) /* negative motion indicator */
238 /* #define MOTV (MOT|VMOT|NMOT) /* motion flags */
239 /* #define MAXMOT (~MOTV) /* maximum motion permitted */
240 #define MAXMOT 0xFFFF
242 #define ismot(n) ((n) & MOT)
243 #define isvmot(n) (((n) & (MOT|VMOT)) == (MOT|VMOT)) /* must have tested MOT previously */
244 #define isnmot(n) (((n) & (MOT|NMOT)) == (MOT|NMOT)) /* ditto */
245 #define absmot(n) ((n) & 0xFFFF)
247 #define ZBIT (01uL << 31) /* zero width char */
248 #define iszbit(n) ((n) & ZBIT)
251 #define SSHIFT (FSHIFT+7)
252 #define SMASK (0177uL << SSHIFT) /* 128 distinct sizes */
253 #define FMASK (0177uL << FSHIFT) /* 128 distinct fonts */
254 #define SFMASK (SMASK|FMASK) /* size and font in a Tchar */
255 #define sbits(n) (((n) >> SSHIFT) & 0177)
256 #define fbits(n) (((n) >> FSHIFT) & 0177)
257 #define sfbits(n) (((n) & SFMASK) >> FSHIFT)
258 #define cbits(n) ((n) & 0x1FFFF) /* isolate character bits, */
259 /* but don't include motions */
260 extern int realcbits(Tchar);
262 #define setsbits(n,s) n = (n & ~SMASK) | (Tchar)(s) << SSHIFT
263 #define setfbits(n,f) n = (n & ~FMASK) | (Tchar)(f) << FSHIFT
264 #define setsfbits(n,sf) n = (n & ~SFMASK) | (Tchar)(sf) << FSHIFT
265 #define setcbits(n,c) n = (n & ~0xFFFFuL | (c)) /* set character bits */
267 #define BYTEMASK 0377
270 #define SHORTMASK 0XFFFF
273 #define TABMASK ((unsigned) INT_MAX >> 1)
274 #define RTAB ((TABMASK << 1) & ~TABMASK)
275 #define CTAB (RTAB << 1)
277 #define TABBIT 02 /* bits in gchtab */
281 #define PAIR(A,B) (A|(B<<SHORT))
284 extern int Inch, Hor, Vert, Unitwidth;
292 extern Spnames spnames[];
295 String and macro definitions are stored conceptually in a giant array
296 indexed by type Offset. In olden times, this array was real, and thus
297 both huge and limited in size, leading to the "Out of temp file space"
298 error. In this version, the array is represented by a list of blocks,
299 pointed to by blist[].bp. Each block is of size BLK Tchars, and BLK
300 MUST be a power of 2 for the macros below to work.
302 The blocks associated with a particular string or macro are chained
303 together in the array blist[]. Each blist[i].nextoff contains the
304 Offset associated with the next block in the giant array, or -1 if
305 this is the last block in the chain. If .nextoff is 0, the block is
308 To find the right index in blist for an Offset, divide by BLK.
311 #define NBLIST 2048 /* starting number of blocks in all definitions */
313 #define BLK 128 /* number of Tchars in a block; must be 2^N with defns below */
315 #define rbf0(o) (blist[bindex(o)].bp[boffset(o)])
316 #define bindex(o) ((o) / BLK)
317 #define boffset(o) ((o) & (BLK-1))
318 #define pastend(o) (((o) & (BLK-1)) == 0)
319 /* #define incoff(o) ( (++o & (BLK-1)) ? o : blist[bindex(o-1)].nextoff ) */
320 #define incoff(o) ( (((o)+1) & (BLK-1)) ? o+1 : blist[bindex(o)].nextoff )
322 #define skipline(f) while (getc(f) != '\n')
323 #define is(s) (strcmp(cmd, s) == 0)
324 #define eq(s1, s2) (strcmp(s1, s2) == 0)
327 typedef unsigned long Offset; /* an offset in macro/string storage */
329 struct Blockp { /* info about a block: */
330 Tchar *bp; /* the data */
331 Offset nextoff; /* offset of next block in a chain */
334 extern Blockp *blist;
336 #define RD_OFFSET (1 * BLK) /* .rd command uses block 1 */
338 struct Diver { /* diversion */
353 struct Stack { /* stack frame */
372 struct Contab { /* command or macro */
381 #define C(a,b) {a, 0, b, 0, 0} /* how to initialize a contab entry */
383 extern Contab contab[NM];
385 struct Numtab { /* number registers */
386 unsigned int r; /* name */
393 extern Numtab numtab[NN];
411 struct Wcache { /* width cache, indexed by character */
416 struct Tbuf { /* growable Tchar buffer */
421 /* the infamous environment block */
423 #define ics envp->_ics
424 #define sps envp->_sps
425 #define spacesz envp->_spacesz
426 #define lss envp->_lss
427 #define lss1 envp->_lss1
429 #define ll1 envp->_ll1
431 #define lt1 envp->_lt1
433 #define icf envp->_icf
434 #define chbits envp->_chbits
435 #define spbits envp->_spbits
436 #define nmbits envp->_nmbits
437 #define apts envp->_apts
438 #define apts1 envp->_apts1
439 #define pts envp->_pts
440 #define pts1 envp->_pts1
441 #define font envp->_font
442 #define font1 envp->_font1
444 #define ls1 envp->_ls1
446 #define nms envp->_nms
447 #define ndf envp->_ndf
448 #define nmwid envp->_nmwid
452 #define ohc envp->_ohc
453 #define tdelim envp->_tdelim
454 #define hyf envp->_hyf
455 #define hyoff envp->_hyoff
456 #define hyphalg envp->_hyphalg
457 #define un1 envp->_un1
458 #define tabc envp->_tabc
459 #define dotc envp->_dotc
460 #define adsp envp->_adsp
461 #define adrem envp->_adrem
462 #define lastl envp->_lastl
463 #define nel envp->_nel
464 #define admod envp->_admod
465 #define wordp envp->_wordp
466 #define spflg envp->_spflg
467 #define linep envp->_linep
468 #define wdend envp->_wdend
469 #define wdstart envp->_wdstart
470 #define wne envp->_wne
474 #define lnmod envp->_lnmod
475 #define nwd envp->_nwd
482 #define in1 envp->_in1
484 #define wch envp->_wch
485 #define pendt envp->_pendt
486 #define pendw envp->_pendw
487 #define pendnf envp->_pendnf
488 #define spread envp->_spread
490 #define itmac envp->_itmac
491 #define hyptr envp->_hyptr
492 #define tabtab envp->_tabtab
493 #define line envp->_line._bufp
494 #define lnsize envp->_line._size
495 #define word envp->_word._bufp
496 #define wdsize envp->_word._size
498 #define oline _oline._bufp
499 #define olnsize _oline._size
503 * If this structure changes in ni.c, you must change
504 * this as well, and vice versa.
585 enum { MBchar = 'U', Troffchar = 'C', Number = 'N', Install = 'i', Lookup = 'l' };
586 /* U => utf, for instance; C => \(xx, N => \N'...' */
590 struct Chwid { /* data on one character */
591 Ushort num; /* character number:
592 0 -> not on this font
593 >= ALPHABET -> its number among all Cxy's */
594 Ushort code; /* char code for actual device. used for \N */
595 char *str; /* code string for nroff */
596 Uchar wid; /* width */
597 Uchar kern; /* ascender/descender */
600 struct Font { /* characteristics of a font */
601 int name; /* int name, e.g., BI (2 chars) */
602 char longname[64]; /* long name of this font (e.g., "Bembo" */
603 char *truename; /* path name of table if not in standard place */
604 int nchars; /* number of width entries for this font */
605 char specfont; /* 1 == special font */
606 int spacewidth; /* width of space on this font */
607 int defaultwidth; /* default width of characters on this font */
608 Chwid *wp; /* widths, etc., of the real characters */
609 char ligfont; /* 1 == ligatures exist on this font */
612 /* ligatures, ORed into ligfont */
621 #define TRNARGS 01 /* trace legality of numeric arguments */
622 #define TRREQ 02 /* trace requests */
623 #define TRMAC 04 /* trace macros */
624 #define RQERR 01 /* processing request/macro */
626 /* typewriter driving table structure */
631 int bset; /* these bits have to be on */
632 int breset; /* these bits have to be off */
633 int Hor; /* #units in minimum horiz motion */
634 int Vert; /* #units in minimum vert motion */
635 int Newline; /* #units in single line space */
636 int Char; /* #units in character width */
638 int Halfline; /* half line units */
639 int Adj; /* minimum units for horizontal adjustment */
640 char *twinit; /* initialize terminal */
641 char *twrest; /* reinitialize terminal */
642 char *twnl; /* terminal sequence for newline */
643 char *hlr; /* half-line reverse */
644 char *hlf; /* half-line forward */
645 char *flr; /* full-line reverse */
646 char *bdon; /* turn bold mode on */
647 char *bdoff; /* turn bold mode off */
648 char *iton; /* turn italic mode on */
649 char *itoff; /* turn italic mode off */
650 char *ploton; /* turn plot mode on */
651 char *plotoff; /* turn plot mode off */
652 char *up; /* sequence to move up in plot mode */
653 char *down; /* ditto */
654 char *right; /* ditto */
655 char *left; /* ditto */
657 Font tfont; /* widths and other info, as in a troff font */
663 * for error reporting; keep track of escapes/requests with numeric arguments
666 char type; /* request or escape? */
667 char esc; /* was escape sequence named esc */
668 char escarg; /* argument of esc's like \D'l' */
669 unsigned int req; /* was request or macro named req */