home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / externs next >
Text File  |  1994-02-26  |  96KB  |  2,002 lines

  1. /*@externs:External Declarations:Directories and file conventions@************/
  2. /*                                                                           */
  3. /*  LOUT: A HIGH-LEVEL LANGUAGE FOR DOCUMENT FORMATTING (VERSION 2.05)       */
  4. /*  COPYRIGHT (C) 1993 Jeffrey H. Kingston                                   */
  5. /*                                                                           */
  6. /*  Jeffrey H. Kingston (jeff@cs.su.oz.au)                                   */
  7. /*  Basser Department of Computer Science                                    */
  8. /*  The University of Sydney 2006                                            */
  9. /*  AUSTRALIA                                                                */
  10. /*                                                                           */
  11. /*  This program is free software; you can redistribute it and/or modify     */
  12. /*  it under the terms of the GNU General Public License as published by     */
  13. /*  the Free Software Foundation; either version 1, or (at your option)      */
  14. /*  any later version.                                                       */
  15. /*                                                                           */
  16. /*  This program is distributed in the hope that it will be useful,          */
  17. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
  18. /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
  19. /*  GNU General Public License for more details.                             */
  20. /*                                                                           */
  21. /*  You should have received a copy of the GNU General Public License        */
  22. /*  along with this program; if not, write to the Free Software              */
  23. /*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
  24. /*                                                                           */
  25. /*  FILE:         externs                                                    */
  26. /*  MODULE:       External Declarations                                      */
  27. /*                                                                           */
  28. /*****************************************************************************/
  29. #include <stdio.h>
  30. #ifndef OSK
  31. #include <string.h>
  32. #else
  33. #include <strings.h>
  34. #endif
  35.  
  36. /*****************************************************************************/
  37. /*                                                                           */
  38. /*  Include, font and database directories, and the DEBUG_ON and ASSERT_ON   */
  39. /*  flags (defined by -D options on the cc command line in the makefile).    */
  40. /*                                                                           */
  41. /*  LATIN               Non-zero means compile for ISO-LATIN-1 char set.     */
  42. /*  INCL_DIR            The system directory where @Include files are kept   */
  43. /*  FONT_DIR            The system directory where .AFM font files are kept  */
  44. /*  EVEC_DIR            The system directory where .CEV files are kept       */
  45. /*  DATA_DIR            The system directory where database files are kept   */
  46. /*  CHAR_IN             Determines assignment of input chars to lex classes  */
  47. /*  CHAR_OUT            Determines appearance of literal chars in output     */
  48. /*  DEBUG_ON            Non-zero means compile debug code (lout -d)          */
  49. /*  ASSERT_ON           Non-zero means test assertions                       */
  50. /*                                                                           */
  51. /*  #define  INCL_DIR   "/usr/local/lib/lout/include"                        */
  52. /*  #define  FONT_DIR   "/usr/local/lib/lout/font"                           */
  53. /*  #define  EVEC_DIR   "/usr/local/lib/lout/evec"                           */
  54. /*  #define  DATA_DIR   "/usr/local/lib/lout/data"                           */
  55. /*  #define  CHAR_IN    0                                                    */
  56. /*  #define  CHAR_OUT   0                                                    */
  57. /*  #define  DEBUG_ON   0                                                    */
  58. /*  #define  ASSERT_ON  1                                                    */
  59. /*                                                                           */
  60. /*  File naming conventions and version                                      */
  61. /*                                                                           */
  62. /*  LOUT_VERSION        Version information                                  */
  63. /*  CROSS_DB            The default name of the cross reference database     */
  64. /*  SOURCE_SUFFIX       Optional suffix of source files and include files    */
  65. /*  INDEX_SUFFIX        The suffix of database index files                   */
  66. /*  NEW_INDEX_SUFFIX    The suffix of new database index files               */
  67. /*  DATA_SUFFIX         The suffix of database data files                    */
  68. /*  NEW_DATA_SUFFIX     The additional suffix of new database data files     */
  69. /*  HYPH_FILENAME       The default name of the unpacked hyphenation file    */
  70. /*  HYPH_SUFFIX         The suffix of the packed hyphenation file            */
  71. /*                                                                           */
  72. /*****************************************************************************/
  73.  
  74. #define    LOUT_VERSION      AsciiToFull("Basser Lout Version 2.05 (July 1993)")
  75. #define    CROSS_DB      AsciiToFull("lout")
  76. #define    SOURCE_SUFFIX      AsciiToFull(".lout")
  77. #define    INDEX_SUFFIX      AsciiToFull(".li")
  78. #define    NEW_INDEX_SUFFIX  AsciiToFull(".lix")
  79. #define    DATA_SUFFIX      AsciiToFull(".ld")
  80. #define    NEW_DATA_SUFFIX      AsciiToFull("x")
  81. #define    HYPH_FILENAME      AsciiToFull("lout.hyph")
  82. #define    HYPH_SUFFIX      AsciiToFull(".pk")
  83.  
  84. /*@::Significant limits@******************************************************/
  85. /*                                                                           */
  86. /*  Significant Limits (other insignificant ones appear in other files)      */
  87. /*                                                                           */
  88. /*  MAX_LEN             The maximum value storable in type LENGTH            */
  89. /*                                                                           */
  90. /*  MAX_FILES           1 + the maximum number of files.  This cannot        */
  91. /*                      exceed 256 without changing type FILE_NUM; and       */
  92. /*                      it cannot exceed 255 without increasing MAX_WORD     */
  93. /*                      (a WORD is used to hold an array indexed by          */
  94. /*                      filenum in file z10.c).                              */
  95. /*                                                                           */
  96. /*  MAX_LINE            1 + the maximum length of an input line, in files    */
  97. /*                      of all types.  This cannot exceed 256, at least in   */
  98. /*                      source files, unless the col_num field of FILE_POS   */
  99. /*                      is enlarged beyond its present 1 byte unsigned       */
  100. /*                                                                           */
  101. /*  MAX_WORD            1 + the maximum length of a word storable in an      */
  102. /*                      object record, which includes all file path names    */
  103. /*                      too.  It is reasonable to make this MAX_LINE, since  */
  104. /*                      a word longer than MAX_LINE cannot be read in        */
  105. /*                                                                           */
  106. /*  MAX_OBJECT_REC      1 + the maximum size of an object record, measured   */
  107. /*                      in ALIGNs.  The value chosen should exceed           */
  108. /*                      ceiling( (wr + MAX_WORD - 4) / sizeof(ALIGN) )       */
  109. /*                      where wr = sizeof(struct word_rec), so that words of */
  110. /*                      length MAX_WORD-1 can be stored in an object record  */
  111. /*                                                                           */
  112. /*  MAX_FONT            1 + the maximum number of sized fonts.  This can be  */
  113. /*                      increased easily since font metric memory is         */
  114. /*                      obtained as required from malloc().                  */
  115. /*                                                                           */
  116. /*  MAX_LEX_STACK       The maximum depth of @Includes and @Databases.       */
  117. /*                      This can be increased easily if desired.             */
  118. /*                                                                           */
  119. /*****************************************************************************/
  120.  
  121. #define    MAX_LEN            32767
  122. #define    MAX_FILES        255
  123. #define MAX_LINE            256
  124. #define MAX_WORD            256
  125. #define    MAX_OBJECT_REC        73
  126. #define MAX_FONT        100
  127. #define    MAX_LEX_STACK         5
  128.  
  129. /*****************************************************************************/
  130. /*                                                                           */
  131. /*  Miscellaneous Macros                                                     */
  132. /*                                                                           */
  133. /*****************************************************************************/
  134.  
  135. #define    BOOLEAN        unsigned
  136. #define    FALSE        0
  137. #define    TRUE        1
  138. #define    bool(x)        (x ? AsciiToFull("TRUE") : AsciiToFull("FALSE") )
  139. #define    CHILD        0
  140. #define    PARENT        1
  141. #define    COL        0
  142. #define    ROW        1
  143. #define    dimen(x)    (x == COL ? AsciiToFull("COL") : AsciiToFull("ROW") )
  144. #define    nil        ( (OBJECT) NULL )
  145. #define    null        ( (FILE *) NULL )
  146.  
  147. #define max(a, b)    ((a) < (b) ? (b) : (a))
  148. #define min(a, b)    ((a) < (b) ? (a) : (b))
  149. #define    ceiling(a, b)    ( ((a) - 1)/(b) + 1 )    /* ceiling(a/b)              */
  150. #define is_odd(x)    ( (x) & 1 )        /* TRUE if x is odd number   */
  151.  
  152.  
  153. /*@::ALIGN, LENGTH, FONT_NUM, ENCODING, FULL_CHAR@****************************/
  154. /*                                                                           */
  155. /*  typedef ALIGN - the most restrictive memory alignment type.              */
  156. /*                                                                           */
  157. /*****************************************************************************/
  158.  
  159. typedef char *ALIGN;
  160.  
  161.  
  162. /*****************************************************************************/
  163. /*                                                                           */
  164. /*  typedef LENGTH - an integer physical distance.                           */
  165. /*                                                                           */
  166. /*****************************************************************************/
  167.  
  168. typedef short int LENGTH;
  169.  
  170.  
  171. /*****************************************************************************/
  172. /*                                                                           */
  173. /*  FONT_NUM - internal name for a font.                                     */
  174. /*                                                                           */
  175. /*****************************************************************************/
  176.  
  177. typedef unsigned char FONT_NUM;
  178.  
  179.  
  180. /*****************************************************************************/
  181. /*                                                                           */
  182. /*  ENCODING - internal name for a character encoding vector.                */
  183. /*                                                                           */
  184. /*****************************************************************************/
  185.  
  186. typedef unsigned char ENCODING;
  187.  
  188.  
  189. /*****************************************************************************/
  190. /*                                                                           */
  191. /*  typedef FULL_CHAR - one of the characters manipulated by Lout.           */
  192. /*                                                                           */
  193. /*  This program does not deal with 7-bit ASCII characters.  Instead, its    */
  194. /*  characters are defined by the FULL_CHAR typedef, and could be anything   */
  195. /*  from 7-bit ASCII to 8-bit ISO-LATIN-1 to 16-bit UNICODE and beyond.      */
  196. /*                                                                           */
  197. /*  Unfortunately C favours signed 8-bit characters: literal strings are     */
  198. /*  pointers to them, argv[] and the standard libraries assume them.  We get */
  199. /*  around these problems by using our own library, including AsciiToFull()  */
  200. /*  to convert an ASCII string (such as a C string) into a FULL_CHAR string. */
  201. /*                                                                           */
  202. /*  Formally this library appears in module z39.c; however since this        */
  203. /*  implementation uses 8-bit unsigned characters, most of the routines      */
  204. /*  can be implemented by macros containing type-cast calls to C standard    */
  205. /*  library routines.  These appear in the z39.c externs list below.         */
  206. /*                                                                           */
  207. /*****************************************************************************/
  208.  
  209. typedef unsigned char FULL_CHAR;
  210.  
  211.  
  212. /*@::Character literals@******************************************************/
  213. /*                                                                           */
  214. /*  Character Literals                                                       */
  215. /*                                                                           */
  216. /*  The following macros ensure that no Lout source is ever compared to a    */
  217. /*  literal character other than '\0':                                       */
  218. /*                                                                           */
  219. /*****************************************************************************/
  220.  
  221. #define    CH_FLAG_OUTFILE        'o'    /* the -o command line flag          */
  222. #define    CH_FLAG_SUPPRESS    's'    /* the -s command line flag          */
  223. #define    CH_FLAG_CROSS        'c'    /* the -c command line flag          */
  224. #define    CH_FLAG_ERRFILE        'e'    /* the -e command line flag          */
  225. #define    CH_FLAG_EPSFIRST    'E'    /* first letter of the -EPS flag     */
  226. #define    CH_FLAG_DIRPATH        'D'    /* the -D command line flag          */
  227. #define    CH_FLAG_ENCPATH        'C'    /* the -C command line flag          */
  228. #define    CH_FLAG_FNTPATH        'F'    /* the -F command line flag          */
  229. #define    CH_FLAG_INCPATH        'I'    /* the -I command line flag          */
  230. #define    CH_FLAG_INCLUDE        'i'    /* the -i command line flag          */
  231. #define    CH_FLAG_HYPHEN        'h'    /* the -h command line flag          */
  232. #define    CH_FLAG_VERSION        'V'    /* the -V command line flag          */
  233. #define    CH_FLAG_USAGE        'u'    /* the -u command line flag          */
  234. #define    CH_FLAG_DEBUG        'd'    /* the -d command line flag          */
  235.  
  236. #define    CH_SPACE        ' '    /* space character                   */
  237. #define    CH_NEWLINE        '\n'    /* the newline character             */
  238. #define    CH_SYMSTART        '@'    /* extra letter symbols may have     */
  239. #define    CH_QUOTE        '"'    /* the quote character             */
  240. #define    CH_ZERO            '0'    /* the first digit character, zero   */
  241. #define    CH_INCGAP        '+'    /* begins an incrementing gap         */
  242. #define    CH_DECGAP        '-'    /* begins a decrementing gap         */
  243. #define    CH_MINUS        '-'    /* minus sign                        */
  244. #define    CH_HYPHEN        '-'    /* the hyphen character             */
  245.  
  246. #define    CH_UNIT_CM        'c'    /* unit of measurement: centimetres  */
  247. #define    CH_UNIT_IN        'i'    /* unit of measurement: inches       */
  248. #define    CH_UNIT_PT        'p'    /* unit of measurement: points       */
  249. #define    CH_UNIT_EM        'm'    /* unit of measurement: ems          */
  250. #define    CH_UNIT_FT        'f'    /* unit of measurement: fontsizes    */
  251. #define    CH_UNIT_SP        's'    /* unit of measurement: spacewidths  */
  252. #define    CH_UNIT_VS        'v'    /* unit of measurement: vspaces      */
  253. #define    CH_UNIT_WD        'w'    /* unit of measurement: follwidths   */
  254. #define    CH_UNIT_BD        'b'    /* unit of measurement: boundwidths  */
  255. #define    CH_UNIT_RL        'r'    /* unit of measurement: relwidths    */
  256. #define    CH_UNIT_DG        'd'    /* unit of measurement: degrees      */
  257.  
  258. #define    CH_MODE_EDGE        'e'    /* spacing mode: edge-to-edge        */
  259. #define    CH_MODE_HYPH        'h'    /* spacing mode: hyphenation         */
  260. #define    CH_MODE_MARK        'x'    /* spacing mode: mark-to-mark        */
  261. #define    CH_MODE_OVER        'o'    /* spacing mode: overstrike          */
  262. #define    CH_MODE_KERN        'k'    /* spacing mode: kerning             */
  263. #define    CH_MODE_TABL        't'    /* spacing mode: tabulation          */
  264.  
  265. #define octaldigit(ch)        ( (ch) >= '0' && (ch) <= '7' )
  266. #define decimaldigit(ch)    ( (ch) >= '0' && (ch) <= '9' )
  267. #define    digitchartonum(ch)    ( (ch) - '0' )
  268. #define    numtodigitchar(ch)    ( (ch) + '0' )
  269. #define    beginsbreakstyle(ch)    ( (ch) >= 'a' && (ch) <= 'z' )
  270. #define    numericchar(ch)        ( decimaldigit(ch) || (ch) == '.' )
  271.  
  272.  
  273. /*@::String literals, FULL_CHAR type@*****************************************/
  274. /*                                                                           */
  275. /*  String Literals.                                                         */
  276. /*                                                                           */
  277. /*  All significant string literals are defined here.  The program has many  */
  278. /*  others, however: format strings, debug output, etc.                      */
  279. /*                                                                           */
  280. /*****************************************************************************/
  281.  
  282. #define    STR_EMPTY        AsciiToFull("")
  283. #define    STR_QUOTE        AsciiToFull("\"")
  284. #define    STR_ESCAPE        AsciiToFull("\\")
  285. #define    STR_COMMENT        AsciiToFull("#")
  286. #define    STR_SPACE        AsciiToFull(" ")
  287. #define    STR_TAB            AsciiToFull("\t")
  288. #define    STR_NEWLINE        AsciiToFull("\n")
  289. #define    STR_LETTERS_LOWER    AsciiToFull("abcdefghijklmnopqrstuvwxyz")
  290. #define    STR_LETTERS_UPPER    AsciiToFull("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  291. #define    STR_LETTERS_SYMSTART    AsciiToFull("@")
  292.  
  293. #if CHAR_IN==0
  294. #define    STR_LETTERS_EXTRA0    AsciiToFull("")
  295. #define    STR_LETTERS_EXTRA1    AsciiToFull("")
  296. #define    STR_LETTERS_EXTRA2    AsciiToFull("")
  297. #define    STR_LETTERS_EXTRA3    AsciiToFull("")
  298. #define    STR_LETTERS_EXTRA4    AsciiToFull("")
  299. #define    STR_LETTERS_EXTRA5    AsciiToFull("")
  300. #define    STR_LETTERS_EXTRA6    AsciiToFull("")
  301. #define    STR_LETTERS_EXTRA7    AsciiToFull("")
  302. #else
  303. #define    STR_LETTERS_EXTRA0    AsciiToFull("\300\301\302\303\304\305\306\307")
  304. #define    STR_LETTERS_EXTRA1    AsciiToFull("\310\311\312\313\314\315\316\317")
  305. #define    STR_LETTERS_EXTRA2    AsciiToFull("\320\321\322\323\324\325\326")
  306. #define    STR_LETTERS_EXTRA3    AsciiToFull("\330\331\332\333\334\335\336\337")
  307. #define    STR_LETTERS_EXTRA4    AsciiToFull("\340\341\342\343\344\345\346\347")
  308. #define    STR_LETTERS_EXTRA5    AsciiToFull("\350\351\352\353\354\355\356\357")
  309. #define    STR_LETTERS_EXTRA6    AsciiToFull("\360\361\362\363\364\365\366")
  310. #define    STR_LETTERS_EXTRA7    AsciiToFull("\370\371\372\373\374\375\376\377")
  311. #endif
  312.  
  313. #define    STR_STDIN        AsciiToFull("-")
  314. #define    STR_STDOUT        AsciiToFull("-")
  315. #define    STR_HYPHEN        AsciiToFull("-")
  316. #define    STR_EPS            AsciiToFull("EPS")
  317. #define    STR_ELSE        AsciiToFull("else")
  318. #define    STR_NOCROSS        AsciiToFull("??")
  319. #define    STR_BADKEY        AsciiToFull("badkey")
  320. #define    STR_NONE        AsciiToFull("none")
  321. #define    STR_ZERO        AsciiToFull("0")
  322. #define    STR_PS_SPACENAME    AsciiToFull("space")
  323. #define    STR_FONT_RECODE        AsciiToFull("Recode")
  324. #define    STR_FONT_NORECODE    AsciiToFull("NoRecode")
  325.  
  326. #define    STR_BREAK_HYPHEN    AsciiToFull("hyphen")
  327. #define    STR_BREAK_NOHYPHEN    AsciiToFull("nohyphen")
  328. #define    STR_BREAK_ADJUST    AsciiToFull("adjust")
  329. #define    STR_BREAK_OUTDENT    AsciiToFull("outdent")
  330. #define    STR_BREAK_RAGGED    AsciiToFull("ragged")
  331. #define    STR_BREAK_CRAGGED    AsciiToFull("cragged")
  332. #define    STR_BREAK_RRAGGED    AsciiToFull("rragged")
  333. #define    STR_BREAK_LINES        AsciiToFull("lines")
  334. #define    STR_BREAK_CLINES    AsciiToFull("clines")
  335. #define    STR_BREAK_RLINES    AsciiToFull("rlines")
  336.  
  337. #define    STR_GAP_RJUSTIFY    AsciiToFull("1rt")
  338. #define    STR_GAP_ZERO_HYPH    AsciiToFull("0ch")
  339.  
  340.  
  341. /*@::GAP, STYLE@**************************************************************/
  342. /*                                                                           */
  343. /*  typedef GAP - what separates one object from another.                    */
  344. /*                                                                           */
  345. /*****************************************************************************/
  346.  
  347. typedef struct
  348. { unsigned char    ospare;            /* left for other things in STYLE    */
  349.   BOOLEAN    omark    : 1;        /* TRUE if this gap is marked        */
  350.   BOOLEAN    ojoin    : 1;        /* TRUE if joins exist across gap    */
  351.   unsigned    ounits    : 3;        /* units of measurement: fixed, etc  */
  352.   unsigned    omode    : 3;        /* spacing mode: edge-to-edge, etc   */
  353.   LENGTH    owidth;            /* width of the gap                  */
  354. } GAP;
  355.  
  356. #define    mark(x)        (x).omark
  357. #define    join(x)        (x).ojoin
  358. #define    units(x)    (x).ounits
  359. #define    mode(x)        (x).omode
  360. #define    width(x)    (x).owidth
  361.  
  362. #define SetGap(x, xmark, xjoin, xunits, xmode, xwidth)            \
  363. ( mark(x) = xmark, join(x) = xjoin, units(x) = xunits,            \
  364.   mode(x) = xmode, width(x) = xwidth                    \
  365. )
  366.  
  367. #define GapCopy(x, y)                            \
  368. ( mark(x) = mark(y), join(x) = join(y), units(x) = units(y),        \
  369.   mode(x) = mode(y), width(x) = width(y)                \
  370. )
  371.  
  372. #define ClearGap(x)    SetGap(x, FALSE, TRUE, FIXED_UNIT, NO_MODE, 0)
  373.  
  374.  
  375. /*****************************************************************************/
  376. /*                                                                           */
  377. /*  typedef STYLE - information about how to break text, etc.                */
  378. /*                                                                           */
  379. /*****************************************************************************/
  380.  
  381. typedef struct
  382. { GAP        oline_gap;        /* separation between lines          */
  383.   union {
  384.     GAP        ospace_gap;        /* separation indiced by white space */
  385.     struct {
  386.       unsigned    ohyph_style    : 2;    /* hyphenation off or on             */
  387.       unsigned    ofill_style    : 2;    /* fill lines with text off/on       */
  388.       unsigned    odisplay_style : 3;    /* display lines adjusted, ragged... */
  389.     } oss;
  390.   } osu;
  391. } STYLE;
  392.  
  393. #define    line_gap(x)    (x).oline_gap
  394. #define    space_gap(x)    (x).osu.ospace_gap
  395. #define    font(x)        (x).oline_gap.ospare
  396. #define    hyph_style(x)    (x).osu.oss.ohyph_style
  397. #define    fill_style(x)    (x).osu.oss.ofill_style
  398. #define    display_style(x)(x).osu.oss.odisplay_style
  399.  
  400. #define StyleCopy(x, y)                            \
  401. ( GapCopy( line_gap(x), line_gap(y) ),                    \
  402.   font(x) = font(y),                            \
  403.   hyph_style(x) = hyph_style(y),                    \
  404.   fill_style(x) = fill_style(y),                    \
  405.   display_style(x) = display_style(y),                    \
  406.   GapCopy( space_gap(x), space_gap(y) )                    \
  407. )
  408.  
  409.  
  410. /*@::CONSTRAINT, FILE_NUM, FILE_POS, LIST@************************************/
  411. /*                                                                           */
  412. /*  typedef CONSTRAINT - a size constraint.                                  */
  413. /*                                                                           */
  414. /*****************************************************************************/
  415.  
  416. typedef struct
  417. { LENGTH  obc;
  418.   LENGTH  obfc;
  419.   LENGTH  ofc;
  420.   LENGTH  osparec;
  421. } CONSTRAINT;
  422.  
  423. #define    bc(x)        (x).obc
  424. #define    bfc(x)        (x).obfc
  425. #define    fc(x)        (x).ofc
  426. #define    sparec(x)    (x).osparec
  427. #define    constrained(x)    (bc(x)!=MAX_LEN || bfc(x)!=MAX_LEN || fc(x)!=MAX_LEN)
  428.  
  429. #define    SetConstraint(c,x,y,z)    (bc(c) = (x),   bfc(c) = (y),    fc(c) = (z))
  430. #define    CopyConstraint(x, y)    (bc(x) = bc(y), bfc(x) = bfc(y), fc(x) = fc(y))
  431. #define FitsConstraint(b, f, c)    (b <= bc(c)  && b + f <= bfc(c) && f <= fc(c))
  432.  
  433. #define    ig_fnum(x)    bc(constraint(x))
  434. #define    ig_xtrans(x)    bfc(constraint(x))
  435. #define    ig_ytrans(x)    fc(constraint(x))
  436.  
  437.  
  438. /*****************************************************************************/
  439. /*                                                                           */
  440. /*  typedef FILE_NUM - the internal representation of a file.                */
  441. /*                                                                           */
  442. /*****************************************************************************/
  443.  
  444. typedef unsigned char    FILE_NUM;
  445. #define    NO_FILE        0
  446.  
  447.  
  448. /*****************************************************************************/
  449. /*                                                                           */
  450. /*  typedef FILE_POS - a position in the set of input files.                 */
  451. /*                                                                           */
  452. /*****************************************************************************/
  453.  
  454. typedef    struct
  455. { FILE_NUM    ofile_num;        /* no. of file this record is from   */
  456.   unsigned char    ocol_num;        /* column number this is related to  */
  457.   LENGTH    oline_num;        /* the line number of this record    */
  458. } FILE_POS;
  459.  
  460. #define    file_num(x)    (x).ofile_num
  461. #define    col_num(x)    (x).ocol_num
  462. #define    line_num(x)    (x).oline_num
  463.  
  464. #define FposCopy(x, y)                            \
  465. ( file_num(x) = file_num(y),                        \
  466.   line_num(x) = line_num(y),                        \
  467.   col_num(x)  = col_num(y)                        \
  468. )
  469.  
  470.  
  471. /*****************************************************************************/
  472. /*                                                                           */
  473. /*  typedef LIST - two pointers used to make one doubly linked list          */
  474. /*                                                                           */
  475. /*****************************************************************************/
  476.  
  477. typedef struct { union rec *opred, *osucc; } LIST;
  478.  
  479.  
  480. /*@::FIRST_UNION@*************************************************************/
  481. /*                                                                           */
  482. /*  typedef FIRST_UNION - first four bytes of object record (after 2 LISTs). */
  483. /*                                                                           */
  484. /*****************************************************************************/
  485.  
  486. typedef union
  487. {
  488.   struct /* used by WORD and QWORD when they are tokens */
  489.   {    unsigned char    otype, orec_size;
  490.     unsigned char    ohspace, ovspace;
  491.   } os11;
  492.  
  493.   struct /* used by all non-WORD tokens, including CLOSURE and GAP_OBJ */
  494.   {    unsigned char    otype, oprecedence;
  495.     unsigned char    ohspace, ovspace;
  496.   } os12;
  497.  
  498.   struct /* used by WORD and QWORD when they are objects */
  499.   {    unsigned char    otype, orec_size;
  500.     BOOLEAN        ogall_rec    : 1;
  501.     BOOLEAN        obroken      : 1;
  502.     BOOLEAN        othreaded    : 1;
  503.     BOOLEAN        oexternal    : 1;
  504.     BOOLEAN        oblocked     : 1;
  505.     BOOLEAN        obackward    : 1;
  506.     BOOLEAN        otrigger_ext : 1;
  507.     BOOLEAN            omust_expand : 1;
  508.     FONT_NUM    oword_font;
  509.   } os13;
  510.  
  511.   struct /* used by all non-WORD objects, including CLOSURE */
  512.   {    unsigned char    otype, ospare;
  513.     BOOLEAN        ogall_rec    : 1;
  514.     BOOLEAN        obroken      : 1;
  515.     BOOLEAN        othreaded    : 1;
  516.     BOOLEAN        oexternal    : 1;
  517.     BOOLEAN        oblocked     : 1;
  518.     BOOLEAN        obackward    : 1;
  519.     BOOLEAN        otrigger_ext : 1;
  520.     BOOLEAN            omust_expand : 1;
  521.     unsigned char    ocross_type;         /* CROSS objects only */
  522.   } os14;
  523.  
  524.   struct /* used by WORD and QWORD when they are database nodes */
  525.   {    unsigned char    otype, orec_size;
  526.     unsigned    oreading     :    1;
  527.     unsigned     oleft_pos    : 15;
  528.   } os15;
  529.  
  530.   struct /* used by WORD and QWORD when they are font records */
  531.   {    unsigned char    otype, orec_size;
  532.     FONT_NUM    ofont_num;
  533.     BOOLEAN        ofont_recoded:  1;
  534.   } os16;
  535.  
  536.   struct /* used by symbol table entries */
  537.   {    unsigned char    otype, oprecedence;
  538.     BOOLEAN        ois_tag             : 1;
  539.     BOOLEAN        ohas_tag             : 1;
  540.     BOOLEAN        ohas_lpar            : 1;
  541.     BOOLEAN        ohas_rpar            : 1;
  542.     BOOLEAN        oright_assoc         : 1;
  543.     BOOLEAN        ois_target           : 1;
  544.     BOOLEAN        ohas_target          : 1;
  545.     BOOLEAN        oforce_target         : 1;
  546.     BOOLEAN        ohas_body            : 1;
  547.     BOOLEAN        oindefinite          : 1;
  548.     BOOLEAN        orecursive           : 1;
  549.     BOOLEAN        ouses_extern_target  : 1;
  550.     BOOLEAN        ois_extern_target    : 1;
  551.     BOOLEAN        ois_key             : 1;
  552.     BOOLEAN        ohas_key         : 1;
  553.     BOOLEAN        odirty               : 1;
  554.   } os17;
  555.  
  556. } FIRST_UNION;
  557.  
  558. /*@::SECOND_UNION, THIRD_UNION, FOURTH_UNION@*********************************/
  559. /*                                                                           */
  560. /*  typedef SECOND_UNION - four bytes usually holding a file position.       */
  561. /*                                                                           */
  562. /*  The fpos is overwritten in WORDs and QWORDs during FixAndPrintObject by  */
  563. /*  the horizontal coordinate of the word, which has to be remembered.       */
  564. /*                                                                           */
  565. /*****************************************************************************/
  566.  
  567. typedef union
  568. {
  569.   FILE_POS    ofpos;
  570.   int        oword_save_mark;
  571.  
  572. } SECOND_UNION;
  573.  
  574.  
  575. /*****************************************************************************/
  576. /*                                                                           */
  577. /*  typedef THIRD_UNION - eight bytes usually holding an object size.        */
  578. /*                                                                           */
  579. /*  In database records this space is used for a file pointer; in certain    */
  580. /*  WORD objects used privately in z10.c it is used for a galley-position.   */
  581. /*  In font records it holds the font size, space width, etc.                */
  582. /*                                                                           */
  583. /*****************************************************************************/
  584.  
  585. typedef union
  586. {
  587.   struct
  588.   {    LENGTH    oback[2];
  589.     LENGTH    ofwd[2];
  590.   } os31;
  591.  
  592.   FILE *ofilep;
  593.   int    ogall_pos;
  594.  
  595.   struct
  596.   {    LENGTH    ofont_size;
  597.     LENGTH    ofont_xheight2;
  598.     LENGTH    ofont_spacewidth;
  599.     ENCODING ofont_encoding;
  600.   } os32;
  601.  
  602. } THIRD_UNION;
  603.  
  604.  
  605. /*****************************************************************************/
  606. /*                                                                           */
  607. /*  typedef FOURTH_UNION - eight bytes holding a STYLE or CONSTRAINT.        */
  608. /*                                                                           */
  609. /*****************************************************************************/
  610.  
  611. typedef union
  612. {
  613.   STYLE        osave_style;
  614.   CONSTRAINT    oconstraint;
  615.  
  616. } FOURTH_UNION;
  617.  
  618.  
  619. /*@::OBJECT@******************************************************************/
  620. /*                                                                           */
  621. /*  typedef OBJECT - the general-purpose record used throughout Lout.        */
  622. /*                                                                           */
  623. /*****************************************************************************/
  624.  
  625. typedef union rec
  626. {
  627.   struct word_type    /* all fields of WORD and QWORD, token and object */
  628.   {  LIST        olist[2];
  629.      FIRST_UNION    ou1;
  630.      SECOND_UNION    ou2;
  631.      THIRD_UNION    ou3;
  632.      FULL_CHAR        ostring[4];
  633.   } os1;
  634.  
  635.   struct closure_type    /* all fields of CLOSURE, both as token and object */
  636.   {  LIST        olist[2];
  637.      FIRST_UNION    ou1;
  638.      SECOND_UNION    ou2;
  639.      THIRD_UNION    ou3;
  640.      FOURTH_UNION    ou4;
  641.      union rec        *oactual;
  642.      union
  643.      { union rec *owhereto;
  644.        LENGTH    osave_mark;
  645.      } oux;
  646.      union rec *oready_galls;
  647.   } os2;
  648.   
  649.   struct object_type    /* the general OBJECT */
  650.   {  LIST        olist[2];
  651.      FIRST_UNION    ou1;
  652.      SECOND_UNION    ou2;
  653.      THIRD_UNION    ou3;
  654.      FOURTH_UNION    ou4;
  655.   } os3;
  656.  
  657.   struct link_type    /* LINK */
  658.   {  LIST        olist[2];
  659.      unsigned char    otype;
  660.      unsigned char    onumber;
  661.      unsigned char    odb_targ;
  662.   } os4;
  663.   
  664.   struct gapobj_type    /* GAP_OBJ */
  665.   {  LIST        olist[2];
  666.      FIRST_UNION    ou1;
  667.      SECOND_UNION    ou2;
  668.      GAP        ogap;
  669.      int        osave_badness;        /* optimum paragraph breaker */
  670.      LENGTH        osave_space;        /* optimum paragraph breaker */
  671.      LENGTH        osave_actual_gap;    /* optimum paragraph breaker */
  672.      union rec      *osave_prev;        /* optimum paragraph breaker */
  673.   } os5;
  674.  
  675.   struct symbol_type
  676.   {  LIST        olist[2];
  677.      FIRST_UNION    ou1;
  678.      SECOND_UNION    ou2;
  679.      union rec        *oenclosing;
  680.      union rec        *osym_body;
  681.      union rec        *obase_uses;
  682.      union rec        *ouses;
  683.      union rec        *omarker;
  684.      union rec        *ocross_sym;
  685.      union rec        *oimports;
  686.      short unsigned     opredefined;
  687.      unsigned char    ouses_count;
  688.      BOOLEAN        ovisible         : 1;
  689.      BOOLEAN        ohas_mark         : 1;
  690.      BOOLEAN        ohas_join         : 1;
  691.      BOOLEAN        ohas_par             : 1;
  692.      BOOLEAN        ouses_galley         : 1;
  693.   } os6;
  694.  
  695.   struct cr_type
  696.   {  LIST        olist[2];
  697.      unsigned char    otype;
  698.      unsigned char    otarget_state;
  699.      FILE_NUM        otarget_file;
  700.      FILE_NUM        ocr_file;
  701.      union rec        *otarget_val;
  702.      int        otarget_seq;
  703.      int        otarget_pos;
  704.      int        ocr_seq;
  705.      int        ogall_seq;
  706.      union rec        *osymb;
  707.      union rec        *ogall_tag;
  708.      FILE_NUM        ogall_tfile;
  709.      FILE_NUM        ogentag_file;
  710.      int        ogentag_seq;
  711.      union rec        *ogentag_fseq;
  712.   } os7;
  713.  
  714.   struct ext_gall_type
  715.   {  LIST        olist[2];
  716.      unsigned char    otype;
  717.      FILE_NUM        oeg_fnum;
  718.      long        oeg_fpos;
  719.      long        oeg_cont;
  720.      union rec        *oeg_symbol;
  721.   } os8;
  722.  
  723.   struct uses_type
  724.   {  union rec    *oitem;
  725.      union rec    *onext;
  726.   } os9;
  727.  
  728.   struct hash_entry_type
  729.   {  LIST    olist[1];
  730.   } os10;
  731.  
  732. } *OBJECT;
  733.  
  734.  
  735. /*@::macros for fields of OBJECT@*********************************************/
  736. /*                                                                           */
  737. /*  Macros for fields of OBJECT.                                             */
  738. /*                                                                           */
  739. /*****************************************************************************/
  740.  
  741. #define    succ(x, dim)        (x)->os1.olist[dim].osucc
  742. #define    pred(x, dim)        (x)->os1.olist[dim].opred
  743.  
  744. #define type(x)            (x)->os1.ou1.os11.otype
  745. #define    rec_size(x)        (x)->os1.ou1.os11.orec_size
  746. #define    hspace(x)        (x)->os1.ou1.os11.ohspace
  747. #define    vspace(x)        (x)->os1.ou1.os11.ovspace
  748. #define    precedence(x)        (x)->os2.ou1.os12.oprecedence
  749.  
  750. #define    gall_rec(x)        (x)->os1.ou1.os13.ogall_rec
  751. #define    non_blocking(x)        gall_rec(x)
  752. #define    broken(x)        (x)->os1.ou1.os13.obroken
  753. #define    sized(x)        broken(x)
  754. #define    threaded(x)        (x)->os1.ou1.os13.othreaded
  755. #define    external(x)        (x)->os1.ou1.os13.oexternal
  756. #define    blocked(x)        (x)->os1.ou1.os13.oblocked
  757. #define    seen_nojoin(x)        blocked(x)
  758. #define    backward(x)        (x)->os1.ou1.os13.obackward
  759. #define    trigger_externs(x)    (x)->os1.ou1.os13.otrigger_ext
  760. #define    must_expand(x)        (x)->os1.ou1.os13.omust_expand
  761. #define    word_font(x)        (x)->os1.ou1.os13.oword_font
  762. #define    cross_type(x)        (x)->os1.ou1.os14.ocross_type
  763. #define    thr_state(x)        cross_type(x)
  764.  
  765. #define    reading(x)        (x)->os1.ou1.os15.oreading
  766. #define    left_pos(x)        (x)->os1.ou1.os15.oleft_pos
  767.  
  768. #define    has_lpar(x)        (x)->os1.ou1.os17.ohas_lpar
  769. #define    has_rpar(x)        (x)->os1.ou1.os17.ohas_rpar
  770. #define    right_assoc(x)        (x)->os1.ou1.os17.oright_assoc
  771. #define    is_target(x)        (x)->os1.ou1.os17.ois_target
  772. #define    has_target(x)        (x)->os1.ou1.os17.ohas_target
  773. #define    force_target(x)        (x)->os1.ou1.os17.oforce_target
  774. #define    is_tag(x)        (x)->os1.ou1.os17.ois_tag
  775. #define    has_tag(x)        (x)->os1.ou1.os17.ohas_tag
  776. #define    has_body(x)        (x)->os1.ou1.os17.ohas_body
  777. #define    indefinite(x)        (x)->os1.ou1.os17.oindefinite
  778. #define    recursive(x)        (x)->os1.ou1.os17.orecursive
  779. #define    uses_extern_target(x)    (x)->os1.ou1.os17.ouses_extern_target
  780. #define    is_extern_target(x)    (x)->os1.ou1.os17.ois_extern_target
  781. #define    is_key(x)        (x)->os1.ou1.os17.ois_key
  782. #define    has_key(x)        (x)->os1.ou1.os17.ohas_key
  783. #define    dirty(x)        (x)->os1.ou1.os17.odirty
  784.  
  785. #define    fpos(x)            (x)->os1.ou2.ofpos
  786. #define word_save_mark(x)    (x)->os1.ou2.oword_save_mark
  787.  
  788. #define    back(x, dim)        (x)->os1.ou3.os31.oback[dim]
  789. #define    fwd(x, dim)        (x)->os1.ou3.os31.ofwd[dim]
  790. #define    size(x, dim)        (back(x, dim) + fwd(x, dim))
  791. #define    filep(x)        (x)->os1.ou3.ofilep
  792. #define    gall_pos(x)        (x)->os1.ou3.ogall_pos
  793.  
  794. #define string(x)        (x)->os1.ostring
  795.  
  796. #define    save_style(x)        (x)->os2.ou4.osave_style
  797. #define    constraint(x)        (x)->os2.ou4.oconstraint
  798.  
  799. #define actual(x)        (x)->os2.oactual
  800. #define whereto(x)        (x)->os2.oux.owhereto
  801. #define save_mark(x)        (x)->os2.oux.osave_mark
  802. #define ready_galls(x)        (x)->os2.oready_galls
  803.  
  804. #define    number(x)        (x)->os4.onumber
  805. #define    db_targ(x)        (x)->os4.odb_targ
  806.  
  807. #define    gap(x)            (x)->os5.ogap
  808. #define    save_badness(x)        (x)->os5.osave_badness
  809. #define    save_space(x)        (x)->os5.osave_space
  810. #define    save_actual_gap(x)    (x)->os5.osave_actual_gap
  811. #define    save_prev(x)        (x)->os5.osave_prev
  812.  
  813. #define    enclosing(x)        (x)->os6.oenclosing
  814. #define    sym_body(x)        (x)->os6.osym_body
  815. #define    base_uses(x)        (x)->os6.obase_uses
  816. #define    uses(x)            (x)->os6.ouses
  817. #define    marker(x)        (x)->os6.omarker
  818. #define    cross_sym(x)        (x)->os6.ocross_sym
  819. #define    imports(x)        (x)->os6.oimports
  820. #define    predefined(x)        (x)->os6.opredefined
  821. #define    uses_count(x)        (x)->os6.ouses_count
  822. #define    visible(x)        (x)->os6.ovisible
  823. #define    has_mark(x)        (x)->os6.ohas_mark
  824. #define    has_join(x)        (x)->os6.ohas_join
  825. #define    has_par(x)        (x)->os6.ohas_par
  826. #define    uses_galley(x)        (x)->os6.ouses_galley
  827.  
  828. #define    target_state(x)        (x)->os7.otarget_state
  829. #define    target_file(x)        (x)->os7.otarget_file
  830. #define    cr_file(x)        (x)->os7.ocr_file
  831. #define    target_val(x)        (x)->os7.otarget_val
  832. #define    target_seq(x)        (x)->os7.otarget_seq
  833. #define    target_pos(x)        (x)->os7.otarget_pos
  834. #define    cr_seq(x)        (x)->os7.ocr_seq
  835. #define    gall_seq(x)        (x)->os7.ogall_seq
  836. #define    symb(x)            (x)->os7.osymb
  837. #define    gall_tag(x)        (x)->os7.ogall_tag
  838. #define    gall_tfile(x)        (x)->os7.ogall_tfile
  839. #define    gentag_file(x)        (x)->os7.ogentag_file
  840. #define    gentag_seq(x)        (x)->os7.ogentag_seq
  841. #define    gentag_fseq(x)        (x)->os7.ogentag_fseq
  842.  
  843. #define    eg_fnum(x)        (x)->os8.oeg_fnum
  844. #define    eg_fpos(x)        (x)->os8.oeg_fpos
  845. #define    eg_cont(x)        (x)->os8.oeg_cont
  846. #define    eg_symbol(x)        (x)->os8.oeg_symbol
  847.  
  848. #define    item(x)            (x)->os9.oitem
  849. #define    next(x)            (x)->os9.onext
  850.  
  851. #define    font_num(x)        (x)->os1.ou1.os16.ofont_num
  852. #define    font_recoded(x)        (x)->os1.ou1.os16.ofont_recoded
  853. #define    font_size(x)        (x)->os1.ou3.os32.ofont_size
  854. #define    font_xheight2(x)    (x)->os1.ou3.os32.ofont_xheight2
  855. #define    font_spacewidth(x)    (x)->os1.ou3.os32.ofont_spacewidth
  856. #define    font_encoding(x)    (x)->os1.ou3.os32.ofont_encoding
  857.  
  858.  
  859. /*@::object types@************************************************************/
  860. /*                                                                           */
  861. /*  OBJECT, TOKEN AND OTHER TYPES inhabiting type(x) and predefined(x)       */
  862. /*                                                                           */
  863. /*  Key letters in the adjacent comment indicate where the tag is legal:     */
  864. /*                                                                           */
  865. /*    t  a token type, pushed on token stack                                 */
  866. /*    o  an object type (returned by reduce(), inserted by Manifest)         */
  867. /*    i  an index type (a child of a galley header other than an object)     */
  868. /*    s  a predefined symbol (some symbol table entry has this predefined()) */
  869. /*    n  an indefinite object i.e. one which is ignored in catenation ops    */
  870. /*                                                                           */
  871. /*****************************************************************************/
  872.  
  873. #define    LINK         0        /*        a link between objects     */
  874. #define    GAP_OBJ         1        /*  o     a gap object               */
  875. #define    CLOSURE         2        /* to  n  a closure of a symbol      */
  876. #define    NULL_CLOS     3        /* to sn  @Null                      */
  877. #define    CROSS         4        /* to sn  && (a cross reference obj) */
  878. #define    HEAD         5        /*  o  n  a galley header            */
  879. #define    SPLIT         6        /*  o     @Split                     */
  880. #define    PAR         7        /*  o     a parameter of a closure   */
  881. #define    WORD         8        /*  o     a word                     */
  882. #define    QWORD         9        /*  o     a word (was quoted in i/p) */
  883. #define    ROW_THR        10        /*  o     a row thread               */
  884. #define    COL_THR        11        /*  o     a column thread            */
  885. #define    ACAT        12        /* to s   a sequence of &-ed objs    */
  886. #define    HCAT        13        /* to s   a sequence of |-ed objs    */
  887. #define    VCAT        14        /* to s   a sequence of /-ed objs    */
  888. #define    ONE_COL        15        /* to s   @OneCol                    */
  889. #define    ONE_ROW        16        /* to s   @OneRow                    */
  890. #define    WIDE        17        /* to s   @Wide                      */
  891. #define    HIGH        18        /* to s   @High                      */
  892. #define    HSCALE        19        /* to s   @HScale                    */
  893. #define    VSCALE        20        /* to s   @HScale                    */
  894. #define    SCALE        21        /* to s   @Scale                     */
  895. #define    HCONTRACT    22        /* to s   @HContract                 */
  896. #define    VCONTRACT    23        /* to s   @VContract                 */
  897. #define    HEXPAND        24        /* to s   @HExpand                   */
  898. #define    VEXPAND        25        /* to s   @VExpand                   */
  899. #define    PADJUST        26        /* to s   @PAdjust                   */
  900. #define    HADJUST        27        /* to s   @HAdjust                   */
  901. #define    VADJUST        28        /* to s   @VAdjust                   */
  902. #define    ROTATE        29        /* to s   @Rotate                    */
  903. #define    CASE        30        /* to s   @Case                      */
  904. #define    YIELD        31        /* to s   @Yield                     */
  905. #define    XCHAR        32        /* to s   @Char                      */
  906. #define    FONT        33        /* to s   @Font                      */
  907. #define    SPACE        34        /* to s   @Space                     */
  908. #define    BREAK        35        /* to s   @Break                     */
  909. #define    NEXT        36        /* to s   @Next                      */
  910. #define    ENV        37        /* to s   @LEnv                      */
  911. #define    CLOS        38        /* to s   @LClos                     */
  912. #define    LVIS        39        /* to s   @LVis                      */
  913. #define    OPEN        40        /* to s   @Open                      */
  914. #define    TAGGED        41        /* to s   @Tagged                    */
  915. #define    INCGRAPHIC    42        /* to s   @IncludeGraphic            */
  916. #define    SINCGRAPHIC    43        /* to s   @SysIncludeGraphic         */
  917. #define    GRAPHIC        44        /* to s   @Graphic                   */
  918.  
  919. #define    TSPACE        45        /* t      a space token, parser only */
  920. #define    TJUXTA        46        /* t      a juxta token, parser only */
  921. #define    LBR        47        /* t  s   left brace token           */
  922. #define    RBR        48        /* t  s   right brace token          */
  923. #define    BEGIN        49        /* t  s   @Begin token               */
  924. #define    END        50        /* t  s   @End token                 */
  925. #define    USE        51        /* t  s   @Use                       */
  926. #define    GSTUB_NONE    52        /* t      a galley stub, no rpar     */
  927. #define    GSTUB_INT    53        /* t      galley stub internal rpar  */
  928. #define    GSTUB_EXT    54        /* t      galley stub external rpar  */
  929. #define    INCLUDE        55        /*    s   @Include                   */
  930. #define    SYS_INCLUDE    56        /*    s   @SysInclude                */
  931. #define    PREPEND        57        /*    s   @Prepend                   */
  932. #define    SYS_PREPEND    58        /*    s   @SysPrepend                */
  933. #define    DATABASE    59        /*    s   @Database                  */
  934. #define    SYS_DATABASE    60        /*    s   @SysDatabase               */
  935. #define    START        61        /*    s   \Start                     */
  936.  
  937. #define    DEAD        63        /*   i    a dead galley              */
  938. #define    UNATTACHED    64        /*   i    an inner, unsized galley   */
  939. #define    RECEPTIVE    65        /*   i    a receptive object index   */
  940. #define    RECEIVING    66        /*   i    a receiving object index   */
  941. #define    RECURSIVE    67        /*   i    a recursive definite obj.  */
  942. #define    PRECEDES    68        /*   i    an ordering constraint     */
  943. #define    FOLLOWS        69        /*   i    other end of ordering c.   */
  944. #define    CROSS_FOLL    70        /*   i    following type cross-ref   */
  945. #define    GALL_FOLL    71        /*   i    galley with &&following    */
  946. #define    CROSS_TARG    72        /*   i    value of cross-ref         */
  947. #define    GALL_TARG    73        /*   i    target of these galleys    */
  948. #define    GALL_PREC    74        /*   i    galley with &&preceding    */
  949. #define    CROSS_PREC    75        /*   i    preceding type cross-ref   */
  950. #define    EXPAND_IND    76        /*   i    index of HEXPAND or VEXPD  */
  951. #define    THREAD        77        /*        a sequence of threads      */
  952. #define    CROSS_SYM    78        /*        cross-ref info             */
  953. #define    CR_ROOT        79        /*        RootCross                  */
  954. #define    MACRO        80        /*        a macro symbol             */
  955. #define    LOCAL        81        /*        a local symbol             */
  956. #define    LPAR        82        /*        a left parameter           */
  957. #define    NPAR        83        /*        a named parameter          */
  958. #define    RPAR        84        /*        a right parameter          */
  959. #define    EXT_GALL    85        /*        an external galley         */
  960. #define    CR_LIST        86        /*        a list of cross references */
  961. #define    DISPOSED    87        /*        a disposed record          */
  962.  
  963. #define is_indefinite(x)  ((x) >= CLOSURE && (x) <= HEAD)
  964. #define is_definite(x)      ((x) >= SPLIT && (x) <= GRAPHIC)
  965. #define    is_par(x)    ((x) >= LPAR   && (x) <= RPAR)
  966. #define    is_index(x)    ((x) >= DEAD && (x) <= EXPAND_IND)
  967. #define    is_type(x)    ((x) >= LINK && (x) < DISPOSED)
  968. #define    is_word(x)    ((x) == WORD || (x) == QWORD)
  969. #define is_cat_op(x)    (((x)>=ACAT && (x)<=VCAT) || (x)==TSPACE || (x)<=TJUXTA)
  970.  
  971.  
  972. /*@::miscellaneous constants@*************************************************/
  973. /*                                                                           */
  974. /*  Miscellaneous globally defined constants                                 */
  975. /*                                                                           */
  976. /*****************************************************************************/
  977.  
  978. /* gap modes occupying mode(x) */
  979. #define    NO_MODE        0        /* for error detection: no mode      */
  980. #define    EDGE_MODE    1        /* edge-to-edge spacing              */
  981. #define    HYPH_MODE    2        /* edge-to-edge with hyphenation     */
  982. #define    MARK_MODE    3        /* mark-to-mark spacing              */
  983. #define    OVER_MODE    4        /* overstrike spacing                */
  984. #define    KERN_MODE    5        /* kerning spacing                   */
  985. #define    TAB_MODE    6        /* tabulation spacing                */
  986. #define    ADD_HYPH    7        /* temp value used by FillObject     */
  987.  
  988. /* hyph_style(style) options                                                 */
  989. #define    HYPH_UNDEF    0        /* hyphenation option undefined      */
  990. #define    HYPH_OFF    1        /* hyphenation off                   */
  991. #define    HYPH_ON        2        /* hyphenation on                    */
  992.  
  993. /* fill_style(style) options                                                 */
  994. #define    FILL_UNDEF    0        /* fill option undefined             */
  995. #define    FILL_OFF    1        /* no filling of lines               */
  996. #define    FILL_ON        2        /* fill lines with text              */
  997.  
  998. /* display_style(style) options                                              */
  999. #define    DISPLAY_UNDEF    0        /* display option undefined          */
  1000. #define    DISPLAY_ADJUST    1        /* adjust lines (except last)        */
  1001. #define    DISPLAY_OUTDENT    2        /* outdent lines (except first)      */
  1002. #define    DISPLAY_LEFT    3        /* left-justify lines, no adjust     */
  1003. #define    DISPLAY_CENTRE    4        /* centre lines, no adjust           */
  1004. #define    DISPLAY_RIGHT    5        /* right-justify lines, no adjust    */
  1005. #define    DO_ADJUST    6        /* placed in ACATs when adjust need  */
  1006.  
  1007. /* sides of a mark */
  1008. #define    BACK        88        /* means lies to left of mark        */
  1009. #define    ON        89        /* means lies on mark                */
  1010. #define    FWD        90        /* means lies to right of mark       */
  1011.  
  1012. /* statuses of thread objects */
  1013. #define    NOTSIZED     0        /* this thread object is not sized   */
  1014. #define    SIZED         1        /* thread is sized but not printed   */
  1015. #define    FINALSIZE     2        /* thread object size is now final   */
  1016.  
  1017. /* constraint statuses */
  1018. #define    PROMOTE        91        /* this component may be promoted    */
  1019. #define    CLOSE        92        /* must close dest before promoting  */
  1020. #define    BLOCK        93        /* cannot promote this component     */
  1021. #define    CLEAR        94        /* this constraint is now satisfied  */
  1022.  
  1023. /* gap increment types */
  1024. #define    GAP_ABS        95        /* absolute,  e.g.  3p               */
  1025. #define    GAP_INC        96        /* increment, e.g. +3p               */
  1026. #define    GAP_DEC        97        /* decrement, e.g. -3p               */
  1027.  
  1028. /* file types */
  1029. #define    SOURCE_FILE     0        /* input file from command line      */
  1030. #define    INCLUDE_FILE     1        /* @Include file                     */
  1031. #define    INCGRAPHIC_FILE     2        /* @IncludeGraphic file              */
  1032. #define    DATABASE_FILE     3        /* database file                     */
  1033. #define    INDEX_FILE     4        /* database index file               */
  1034. #define    FONT_FILE     5        /* font file                         */
  1035. #define    PREPEND_FILE     6        /* PostScript prologue file          */
  1036. #define    HYPH_FILE     7        /* hyphenation file                  */
  1037. #define    HYPH_PACKED_FILE 8        /* packed hyphenation file           */
  1038. #define    ENCODING_FILE     9        /* encoding vector file              */
  1039.  
  1040. /* path types (i.e. sequences of directories for file searching) */
  1041. #define    SOURCE_PATH     0        /* path to search for source files   */
  1042. #define    INCLUDE_PATH     1        /* path for @Include files           */
  1043. #define    SYSINCLUDE_PATH     2        /* path for @SysInclude files        */
  1044. #define    DATABASE_PATH     3        /* path for @Database files          */
  1045. #define    SYSDATABASE_PATH 4        /* path for @SysDatabase files       */
  1046. #define    FONT_PATH     5        /* path for font metrics (AFM) files */
  1047. #define    ENCODING_PATH     6        /* path for encoding (CEV) files     */
  1048.  
  1049. /* units of measurement */
  1050. #define    NO_UNIT         0        /* no unit - for error detection     */
  1051. #define    FIXED_UNIT     1        /* inches, cm, points, ems           */
  1052. #define    FRAME_UNIT     2        /* f unit (frame widths)             */
  1053. #define    AVAIL_UNIT     3        /* r unit (available spaces)         */
  1054. #define    DEG_UNIT     4        /* d unit (degrees)                  */
  1055. #define    NEXT_UNIT     5        /* b unit (inners)                   */
  1056.  
  1057. /* units of distance as multiples of the basic unit */
  1058. #define    CM           567        /* 1 centimetre                      */
  1059. #define    IN          1440        /* 1 inch                            */
  1060. #define    EM           120        /* 1 em (= 1/12 inch)                */
  1061. #define    PT        20        /* 1 point (= 1/72 inch)             */
  1062. #define    FR          4096        /* virtual unit for frame units      */
  1063. #define    DG           128        /* virtual unit for degrees          */
  1064. #define    SF           128        /* virtual unit for @Scale factors   */
  1065.  
  1066. /* precedences */
  1067. #define    NO_PREC         0        /* lower than any precedence         */
  1068. #define    BEGIN_PREC     1        /* precedence of @Begin              */
  1069. #define    END_PREC     2        /* precedence of @End                */
  1070. #define    LBR_PREC     3        /* precedence of {                   */
  1071. #define    RBR_PREC     4        /* precedence of }                   */
  1072. #define    VCAT_PREC     5        /* precedence of /                   */
  1073. #define    HCAT_PREC     6        /* precedence of |                   */
  1074. #define    ACAT_PREC     7        /* precedence of & and white space   */
  1075. #define    MIN_PREC        10        /* minimum precedence of user ops    */
  1076. #define    MAX_PREC       100        /* maximim precedence of user ops    */
  1077. #define    DEFAULT_PREC   100        /* default precedence of user ops    */
  1078. #define CROSSOP_PREC   101        /* precedence of cross op &&         */
  1079. #define GAP_PREC       102        /* precedence of gap op after cat op */
  1080. #define JUXTA_PREC     103        /* precedence of juxtaposition &     */
  1081. #define    FORCE_PREC     104        /* higher than any precedence        */
  1082.  
  1083. /* error types */
  1084. #define    INTERN    0            /* internal error (i.e. bug)         */
  1085. #define    FATAL    1            /* fatal error, abort now            */
  1086. #define    WARN    2            /* warning, non-fatal                */
  1087.  
  1088.  
  1089. /*@::Keywords@****************************************************************/
  1090. /*                                                                           */
  1091. /*  Keywords.                                                                */
  1092. /*                                                                           */
  1093. /*****************************************************************************/
  1094.  
  1095. #define    KW_START        AsciiToFull("\\Start")
  1096. #define    KW_PRINT        AsciiToFull("\\Print")
  1097. #define    KW_DEF            AsciiToFull("def")
  1098. #define    KW_FONTDEF        AsciiToFull("fontdef")
  1099. #define    KW_FORCE        AsciiToFull("force")
  1100. #define    KW_INTO            AsciiToFull("into")
  1101. #define    KW_IMPORT        AsciiToFull("import")
  1102. #define    KW_EXPORT        AsciiToFull("export")
  1103. #define    KW_PRECEDENCE        AsciiToFull("precedence")
  1104. #define    KW_ASSOC        AsciiToFull("associativity")
  1105. #define    KW_LEFT            AsciiToFull("left")
  1106. #define    KW_RIGHT        AsciiToFull("right")
  1107. #define    KW_BODY            AsciiToFull("body")
  1108. #define    KW_MACRO        AsciiToFull("macro")
  1109. #define    KW_NAMED        AsciiToFull("named")
  1110. #define    KW_NEXT            AsciiToFull("@Next")
  1111. #define    KW_WIDE            AsciiToFull("@Wide")
  1112. #define    KW_HIGH            AsciiToFull("@High")
  1113. #define    KW_ONE_COL        AsciiToFull("@OneCol")
  1114. #define    KW_ONE_ROW        AsciiToFull("@OneRow")
  1115. #define    KW_HSCALE        AsciiToFull("@HScale")
  1116. #define    KW_VSCALE        AsciiToFull("@VScale")
  1117. #define    KW_SCALE        AsciiToFull("@Scale")
  1118. #define    KW_HCONTRACT        AsciiToFull("@HContract")
  1119. #define    KW_VCONTRACT        AsciiToFull("@VContract")
  1120. #define    KW_HEXPAND        AsciiToFull("@HExpand")
  1121. #define    KW_VEXPAND        AsciiToFull("@VExpand")
  1122. #define    KW_PADJUST        AsciiToFull("@PAdjust")
  1123. #define    KW_HADJUST        AsciiToFull("@HAdjust")
  1124. #define    KW_VADJUST        AsciiToFull("@VAdjust")
  1125. #define    KW_ROTATE        AsciiToFull("@Rotate")
  1126. #define    KW_INCGRAPHIC        AsciiToFull("@IncludeGraphic")
  1127. #define    KW_SINCGRAPHIC        AsciiToFull("@SysIncludeGraphic")
  1128. #define    KW_GRAPHIC        AsciiToFull("@Graphic")
  1129. #define    KW_CASE            AsciiToFull("@Case")
  1130. #define    KW_YIELD        AsciiToFull("@Yield")
  1131. #define    KW_XCHAR        AsciiToFull("@Char")
  1132. #define    KW_FONT            AsciiToFull("@Font")
  1133. #define    KW_SPACE        AsciiToFull("@Space")
  1134. #define    KW_BREAK        AsciiToFull("@Break")
  1135. #define    KW_ENV            AsciiToFull("@LEnv")
  1136. #define    KW_CLOS            AsciiToFull("@LClos")
  1137. #define    KW_LVIS            AsciiToFull("@LVis")
  1138. #define    KW_OPEN            AsciiToFull("@Open")
  1139. #define    KW_USE            AsciiToFull("@Use")
  1140. #define    KW_TAGGED        AsciiToFull("@Tagged")
  1141. #define    KW_DATABASE        AsciiToFull("@Database")
  1142. #define    KW_SYSDATABASE        AsciiToFull("@SysDatabase")
  1143. #define    KW_INCLUDE        AsciiToFull("@Include")
  1144. #define    KW_SYSINCLUDE        AsciiToFull("@SysInclude")
  1145. #define    KW_PREPEND        AsciiToFull("@PrependGraphic")
  1146. #define    KW_SYSPREPEND        AsciiToFull("@SysPrependGraphic")
  1147. #define    KW_TARGET        AsciiToFull("@Target")
  1148. #define    KW_FOLLOWING        AsciiToFull("following")
  1149. #define    KW_PRECEDING        AsciiToFull("preceding")
  1150. #define    KW_NOW            AsciiToFull("now")
  1151. #define    KW_NULL            AsciiToFull("@Null")
  1152. #define    KW_GALLEY        AsciiToFull("@Galley")
  1153. #define    KW_INPUT        AsciiToFull("@LInput")
  1154. #define    KW_SPLIT        AsciiToFull("@Split")
  1155. #define    KW_TAG            AsciiToFull("@Tag")
  1156. #define    KW_KEY            AsciiToFull("@Key")
  1157. #define    KW_CROSS        AsciiToFull("&&")
  1158. #define    KW_LBR            AsciiToFull("{")
  1159. #define    KW_RBR            AsciiToFull("}")
  1160. #define    KW_BEGIN        AsciiToFull("@Begin")
  1161. #define    KW_END            AsciiToFull("@End")
  1162. #define    KW_VCAT_NN        AsciiToFull("//")
  1163. #define    KW_VCAT_MN        AsciiToFull("^//")
  1164. #define    KW_VCAT_NJ        AsciiToFull("/")
  1165. #define    KW_VCAT_MJ        AsciiToFull("^/")
  1166. #define    KW_HCAT_NN        AsciiToFull("||")
  1167. #define    KW_HCAT_MN        AsciiToFull("^||")
  1168. #define    KW_HCAT_NJ        AsciiToFull("|")
  1169. #define    KW_HCAT_MJ        AsciiToFull("^|")
  1170. #define    KW_ACAT_NJ        AsciiToFull("&")
  1171. #define    KW_ACAT_MJ        AsciiToFull("^&")
  1172. #define    KW_MOMENT        AsciiToFull("@Moment")
  1173. #define    KW_SECOND        AsciiToFull("@Second")
  1174. #define    KW_MINUTE        AsciiToFull("@Minute")
  1175. #define    KW_HOUR            AsciiToFull("@Hour")
  1176. #define    KW_DAY            AsciiToFull("@Day")
  1177. #define    KW_MONTH        AsciiToFull("@Month")
  1178. #define    KW_YEAR            AsciiToFull("@Year")
  1179. #define    KW_CENTURY        AsciiToFull("@Century")
  1180. #define    KW_WEEKDAY        AsciiToFull("@WeekDay")
  1181. #define    KW_YEARDAY        AsciiToFull("@YearDay")
  1182. #define    KW_DAYLIGHTSAVING    AsciiToFull("@DaylightSaving")
  1183.  
  1184.  
  1185. /*@::GetMem(), New(), NewWord(), PutMem(), Dispose()@*************************/
  1186. /*                                                                           */
  1187. /*  OBJECT GetMem(siz, pos)                                                  */
  1188. /*  OBJECT New(typ)                                                          */
  1189. /*  OBJECT NewWord(typ, len, pos)                                            */
  1190. /*         PutMem(x, siz)                                                    */
  1191. /*         Dispose(x)                                                        */
  1192. /*                                                                           */
  1193. /*  Return a pointer to a new record, of appropriate length (in ALIGNs).     */
  1194. /*  The New and NewWord versions initialise LIST, type and rec_size fields.  */
  1195. /*  Note that NewWord must be used for WORD and QWORD objects.               */
  1196. /*  Dispose x, which is of size siz.  Dispose works out the size itself.     */
  1197. /*                                                                           */
  1198. /*****************************************************************************/
  1199. #define    USES_SIZE ceiling( sizeof(struct uses_type), sizeof(ALIGN) )
  1200.  
  1201. #if DEBUG_ON
  1202. #define newcount zz_newcount++,
  1203. #else
  1204. #define newcount
  1205. #endif
  1206.  
  1207. #define    GetMem(siz, pos)                        \
  1208. ( newcount (zz_size=(siz))>=MAX_OBJECT_REC ?                \
  1209.       (OBJECT) Error(FATAL, pos, "word is too long")            \
  1210.   : zz_free[zz_size] == nil ? zz_hold = GetMemory(zz_size, pos)        \
  1211.   : (zz_hold = zz_free[zz_size],                    \
  1212.     zz_free[zz_size] = pred(zz_hold, CHILD), zz_hold)        \
  1213. )
  1214.  
  1215. #if DEBUG_ON
  1216. #define checknew(typ)                            \
  1217.   !is_type(typ) ? Error(INTERN, no_fpos,"New: type = %s", Image(typ)) :    \
  1218.   zz_lengths[typ] == 0 ? Error(INTERN, no_fpos, "New: 0 length!") : 0,
  1219. #else
  1220. #define checknew(typ)
  1221. #endif
  1222.  
  1223. #define    New(typ)                            \
  1224. ( checknew(typ) GetMem(zz_lengths[typ], no_fpos), type(zz_hold) = typ,    \
  1225.   pred(zz_hold, CHILD)  = succ(zz_hold, CHILD)  =            \
  1226.   pred(zz_hold, PARENT) = succ(zz_hold, PARENT) = zz_hold        \
  1227. )
  1228.  
  1229. #define NewWord(typ, len, pos)                        \
  1230. ( zz_size = sizeof(struct word_type) - 4 + ((len)+1)*sizeof(FULL_CHAR),    \
  1231.   GetMem(ceiling(zz_size, sizeof(ALIGN)), pos),  /* RESETS zz_size */    \
  1232.   rec_size(zz_hold) = zz_size,  type(zz_hold) = typ,            \
  1233.   pred(zz_hold, CHILD)  = succ(zz_hold, CHILD)  =            \
  1234.   pred(zz_hold, PARENT) = succ(zz_hold, PARENT) = zz_hold        \
  1235. )
  1236.  
  1237. #if DEBUG_ON
  1238. #define disposecount zz_disposecount++,
  1239. #define    setdisposed  , type(zz_hold) = DISPOSED
  1240. #else
  1241. #define disposecount
  1242. #define    setdisposed
  1243. #endif
  1244.  
  1245. #define PutMem(x, siz)                            \
  1246. ( disposecount zz_hold = (x), zz_size = (siz),                \
  1247.   pred(zz_hold, CHILD) = zz_free[zz_size], zz_free[zz_size] = zz_hold )
  1248.  
  1249. #define Dispose(x)                            \
  1250. ( zz_hold = (x),                            \
  1251.   assert( pred(zz_hold, CHILD)  == zz_hold, "Dispose: pred(CHILD)!"  ),    \
  1252.   assert( succ(zz_hold, CHILD)  == zz_hold, "Dispose: succ(CHILD)!"  ),    \
  1253.   assert( pred(zz_hold, PARENT) == zz_hold, "Dispose: pred(PARENT)!" ),    \
  1254.   assert( succ(zz_hold, PARENT) == zz_hold, "Dispose: succ(PARENT)!" ),    \
  1255.   PutMem(zz_hold, is_word(type(zz_hold)) ? rec_size(zz_hold)        \
  1256.               : zz_lengths[type(zz_hold)]) setdisposed  )
  1257.  
  1258. /*@::Append(), Delete(), DeleteAndDispose()@**********************************/
  1259. /*                                                                           */
  1260. /*  OBJECT Append(x, y, dir)                                                 */
  1261. /*                                                                           */
  1262. /*  Return the append of lists x and y (dir is PARENT or CHILD).             */
  1263. /*                                                                           */
  1264. /*****************************************************************************/
  1265.  
  1266. #define    Append(x, y, dir)                        \
  1267. ( zz_res = (x),    zz_hold = (y),                        \
  1268.   zz_hold == nil ? zz_res  :                        \
  1269.   zz_res  == nil ? zz_hold :                        \
  1270.   ( zz_tmp = pred(zz_hold, dir),                    \
  1271.     pred(zz_hold, dir) = pred(zz_res, dir),                \
  1272.     succ(pred(zz_res, dir), dir) = zz_hold,                \
  1273.     pred(zz_res, dir) = zz_tmp,                        \
  1274.     succ(zz_tmp, dir) = zz_res                        \
  1275.   )                                    \
  1276. )
  1277.  
  1278.  
  1279. /*****************************************************************************/
  1280. /*                                                                           */
  1281. /*  OBJECT Delete(x, dir)                                                    */
  1282. /*                                                                           */
  1283. /*  Delete x from its dir list, and return succ(x, dir) or nil if none.      */
  1284. /*                                                                           */
  1285. /*****************************************************************************/
  1286.  
  1287. #define Delete(x, dir)                            \
  1288. ( zz_hold = (x),                            \
  1289.   succ(zz_hold, dir) == zz_hold ? nil :                    \
  1290.   ( zz_res = succ(zz_hold, dir),                    \
  1291.     pred(zz_res, dir) = pred(zz_hold, dir),                \
  1292.     succ(pred(zz_hold, dir), dir) = zz_res,                \
  1293.     pred(zz_hold, dir) = succ(zz_hold, dir) = zz_hold,            \
  1294.     zz_res                                \
  1295.   )                                    \
  1296. )
  1297.  
  1298. /*****************************************************************************/
  1299. /*                                                                           */
  1300. /*  OBJECT DeleteAndDispose(x, dir)                                          */
  1301. /*                                                                           */
  1302. /*  Delete x as above, dispose it, and return succ(x, dir) or nil if none.   */
  1303. /*                                                                           */
  1304. /*****************************************************************************/
  1305.  
  1306. #define DeleteAndDispose(x, dir)                    \
  1307. ( zz_hold = (x),                            \
  1308.   zz_res  = succ(zz_hold, dir) == zz_hold ? nil :            \
  1309.         ( pred(succ(zz_hold, dir), dir) = pred(zz_hold, dir),    \
  1310.           succ(pred(zz_hold, dir), dir) = succ(zz_hold, dir) ),    \
  1311.   pred(zz_hold, dir) = succ(zz_hold, dir) = zz_hold,            \
  1312.   Dispose(zz_hold),                            \
  1313.   zz_res                                \
  1314. )
  1315.  
  1316. #define Down(x)        succ(x, CHILD)
  1317. #define NextDown(x)    succ(x, CHILD)
  1318. #define LastDown(x)    pred(x, CHILD)
  1319. #define PrevDown(x)    pred(x, CHILD)
  1320. #define    Up(x)        succ(x, PARENT)
  1321. #define    NextUp(x)    succ(x, PARENT)
  1322. #define    LastUp(x)    pred(x, PARENT)
  1323. #define    PrevUp(x)    pred(x, PARENT)
  1324.  
  1325. #define    Child(y, link)                            \
  1326. for( y = pred(link, PARENT);  type(y) == LINK;  y = pred(y, PARENT) )
  1327.  
  1328. #define    Parent(y, link)                            \
  1329. for( y = pred(link, CHILD);   type(y) == LINK;  y = pred(y, CHILD) )
  1330.  
  1331.  
  1332. /*@::UpDim(), DownDim(), Link(), DeleteLink(), etc.@**************************/
  1333. /*                                                                           */
  1334. /*  UpDim(x, dim)                                                            */
  1335. /*  DownDim(x, dim)                                                          */
  1336. /*                                                                           */
  1337. /*  Returns the dim child or parent link of node x (dim == COL or ROW).      */
  1338. /*                                                                           */
  1339. /*****************************************************************************/
  1340.  
  1341. #define UpDim(x, dim)    ( (dim) == COL ? succ(x, PARENT) : pred(x, PARENT) )
  1342. #define DownDim(x, dim)    ( (dim) == COL ? succ(x, CHILD) : pred(x, CHILD) )
  1343.  
  1344.  
  1345. /*****************************************************************************/
  1346. /*                                                                           */
  1347. /*  OBJECT Link(x, y)                                                        */
  1348. /*                                                                           */
  1349. /*  Make y a child of x in the directed graph, using a new link.             */
  1350. /*  The link node is returned.                                               */
  1351. /*                                                                           */
  1352. /*****************************************************************************/
  1353.  
  1354. #define Link(x, y)                            \
  1355. ( xx_link = New(LINK),                            \
  1356.   Append(xx_link, (x), CHILD),                        \
  1357.   Append(xx_link, (y), PARENT)                        \
  1358. )
  1359.  
  1360.  
  1361. /*****************************************************************************/
  1362. /*                                                                           */
  1363. /*  OBJECT DeleteLink(link)                                                  */
  1364. /*                                                                           */
  1365. /*  Cut the link between nodes x and y of the directed graph.                */
  1366. /*  Returns the link node of the next child of x, or x if none.              */
  1367. /*                                                                           */
  1368. /*****************************************************************************/
  1369.  
  1370. #define DeleteLink(link)                        \
  1371. ( xx_link = (link),                            \
  1372.   Delete(xx_link, PARENT),                        \
  1373.   DeleteAndDispose(xx_link, CHILD)                    \
  1374. )
  1375.  
  1376.  
  1377. /*****************************************************************************/
  1378. /*                                                                           */
  1379. /*  DisposeChild(link)                                                       */
  1380. /*                                                                           */
  1381. /*  Delete link, and if its child is thereby unattached, dispose it.         */
  1382. /*                                                                           */
  1383. /*****************************************************************************/
  1384.  
  1385. #define DisposeChild(link)                        \
  1386. ( xx_link = (link),                            \
  1387.   xx_tmp = Delete(xx_link, PARENT),                    \
  1388.   DeleteAndDispose(xx_link, CHILD),                    \
  1389.   succ(xx_tmp, PARENT) == xx_tmp ? DisposeObject(xx_tmp) : 0        \
  1390. ) /* end DisposeChild */
  1391.  
  1392.  
  1393. /*****************************************************************************/
  1394. /*                                                                           */
  1395. /*  MoveLink(link, x, dir)                                                   */
  1396. /*                                                                           */
  1397. /*  Move the dir end of link from wherever it is now to node x.              */
  1398. /*                                                                           */
  1399. /*****************************************************************************/
  1400.  
  1401. #define MoveLink(link, x, dir)                        \
  1402. ( xx_link = (link),                            \
  1403.   Delete(xx_link, 1 - (dir) ),                        \
  1404.   Append(xx_link, (x), 1 - (dir) )                    \
  1405. ) /* end MoveLink */
  1406.  
  1407.  
  1408. /*@::TransferLinks(), DeleteNode(), etc.@*************************************/
  1409. /*                                                                           */
  1410. /*  TransferLinks(start_link, stop_link, dest_link)                          */
  1411. /*                                                                           */
  1412. /*  Move parent end of links start_link (inclusive) to stop_link (exclusive) */
  1413. /*  to just before dest_link.                                                */
  1414. /*                                                                           */
  1415. /*****************************************************************************/
  1416.  
  1417. #define TransferLinks(start_link, stop_link, dest_link)            \
  1418. { OBJECT xxstart = start_link, xxstop = stop_link, xxdest = dest_link;    \
  1419.   if( xxstart != xxstop )                        \
  1420.   {    assert( type(xxstart) == LINK, "TransferLinks: start_link!" );    \
  1421.     Append(xxstart, xxstop, CHILD); /* actually a split */        \
  1422.     Append(xxstart, xxdest, CHILD);                    \
  1423.   }                                    \
  1424. }
  1425.  
  1426.  
  1427. /*****************************************************************************/
  1428. /*                                                                           */
  1429. /*  DeleteNode(x)                                                            */
  1430. /*                                                                           */
  1431. /*  Delete node x and every edge attaching to x.                             */
  1432. /*                                                                           */
  1433. /*****************************************************************************/
  1434.  
  1435. #define DeleteNode(x)                            \
  1436. { xx_hold = (x);                            \
  1437.   while( Up(xx_hold)   != xx_hold ) DeleteLink( Up(xx_hold) );        \
  1438.   while( Down(xx_hold) != xx_hold ) DeleteLink( Down(xx_hold) );    \
  1439.   Dispose(xx_hold);                            \
  1440. }
  1441.  
  1442.  
  1443. /*****************************************************************************/
  1444. /*                                                                           */
  1445. /*  MergeNode(x, y)                                                          */
  1446. /*                                                                           */
  1447. /*  Take all the children of y and make them children of x.                  */
  1448. /*  Take all the parents of y and make them parents of x.  Dispose y.        */
  1449. /*                                                                           */
  1450. /*****************************************************************************/
  1451.  
  1452. #define MergeNode(x, y)                            \
  1453. { xx_res = (x); xx_hold = (y);                        \
  1454.   xx_tmp = Delete(xx_hold, PARENT);                    \
  1455.   Append(xx_res, xx_tmp, PARENT);                    \
  1456.   xx_tmp = DeleteAndDispose(xx_hold, CHILD);                \
  1457.   Append(xx_res, xx_tmp, CHILD);                    \
  1458. }  /* end MergeNode */
  1459.  
  1460.  
  1461. /*****************************************************************************/
  1462. /*                                                                           */
  1463. /*  ReplaceNode(x, y)                                                        */
  1464. /*                                                                           */
  1465. /*  Move all the parent links of y to x.                                     */
  1466. /*                                                                           */
  1467. /*****************************************************************************/
  1468.  
  1469. #define ReplaceNode(x, y)                        \
  1470. ( xx_tmp = Delete((y), PARENT),                        \
  1471.   Append((x), xx_tmp, PARENT)                        \
  1472. ) /* end ReplaceNode */
  1473.  
  1474.  
  1475. /*@::FirstDefinite(), NextDefinite(), etc.@***********************************/
  1476. /*                                                                           */
  1477. /*  FirstDefinite(x, link, y)                                                */
  1478. /*                                                                           */
  1479. /*  On input, x is an object and link and y are undefined.  On output there  */
  1480. /*  are two cases:                                                           */
  1481. /*                                                                           */
  1482. /*  link != x.  Then y is first definite child of x and link is its link.    */
  1483. /*                                                                           */
  1484. /*  link == x.  Then x has no definite child and y is undefined.             */
  1485. /*                                                                           */
  1486. /*  A SPLIT object is considered to be definite if both its children are     */
  1487. /*  definite.  This condition is returned by SplitIsDefinite.                */
  1488. /*                                                                           */
  1489. /*****************************************************************************/
  1490.  
  1491. #define FirstDefinite(x, link, y)                    \
  1492. { for( link = Down(x);  link != x;  link = NextDown(link) )        \
  1493.   { Child(y, link);                            \
  1494.     if( type(y) == SPLIT ? SplitIsDefinite(y) : is_definite(type(y)) )    \
  1495.     break;                                \
  1496.   }                                    \
  1497. } /* end FirstDefinite */
  1498.  
  1499.  
  1500. /*****************************************************************************/
  1501. /*                                                                           */
  1502. /*  NextDefinite(x, link, y)                                                 */
  1503. /*                                                                           */
  1504. /*  On input, x is an object and link is a link to one of its children; y    */
  1505. /*  is undefined.  On output there are two cases:                            */
  1506. /*                                                                           */
  1507. /*  link != x.  Then y is the first definite child of x following link, and  */
  1508. /*              link is changed to be the link of y.                         */
  1509. /*                                                                           */
  1510. /*  link == x.  Then x has no definite child following link, and y remains   */
  1511. /*              undefined.                                                   */
  1512. /*                                                                           */
  1513. /*****************************************************************************/
  1514.  
  1515. #define NextDefinite(x, link, y)                    \
  1516. { for( link = NextDown(link);  link != x;  link = NextDown(link) )    \
  1517.   { Child(y, link);                            \
  1518.     if( type(y) == SPLIT ? SplitIsDefinite(y) : is_definite(type(y)) )    \
  1519.     break;                                \
  1520.   }                                    \
  1521. } /* end NextDefinite */
  1522.  
  1523.  
  1524. /*****************************************************************************/
  1525. /*                                                                           */
  1526. /*  NextDefiniteWithGap(x, link, y, g)                                       */
  1527. /*                                                                           */
  1528. /*  On input, x is an object and link is a link to one of its children; y    */
  1529. /*  and g are undefined.  On output there are two cases:                     */
  1530. /*                                                                           */
  1531. /*  link != x.  Then y is the first definite child of x following link, and  */
  1532. /*              link is changed to be the link of y.  Also, g is defined     */
  1533. /*              to be the gap just before y; this must exist and is tested   */
  1534. /*              by an assert test.                                           */
  1535. /*                                                                           */
  1536. /*  link == x.  Then x has no definite child following link, and y and g     */
  1537. /*              remain undefined.                                            */
  1538. /*                                                                           */
  1539. /*****************************************************************************/
  1540.  
  1541. #define NextDefiniteWithGap(x, link, y, g)                \
  1542. { g = nil;                                \
  1543.   for( link = NextDown(link);  link != x;  link = NextDown(link) )    \
  1544.   { Child(y, link);                            \
  1545.     if( type(y) == GAP_OBJ )  g = y;                    \
  1546.     else if( type(y)==SPLIT ? SplitIsDefinite(y):is_definite(type(y)) )    \
  1547.     { assert( g != nil, "NextDefinite: g == nil!" );            \
  1548.       break;                                \
  1549.     }                                    \
  1550.   }                                    \
  1551. } /* end NextDefiniteWithGap */
  1552.  
  1553. /*@@**************************************************************************/
  1554. /*                                                                           */
  1555. /*  LastDefinite(x, link, y)                                                 */
  1556. /*                                                                           */
  1557. /*  On input, x is an object and link and y are undefined.  On output there  */
  1558. /*  are two cases:                                                           */
  1559. /*                                                                           */
  1560. /*  link != x.  Then y is the last definite child of x and link is its link. */
  1561. /*                                                                           */
  1562. /*  link == x.  Then x has no definite child and y is undefined.             */
  1563. /*                                                                           */
  1564. /*  A SPLIT object is considered to be definite if both its children are     */
  1565. /*  definite.  This condition is returned by SplitIsDefinite.                */
  1566. /*                                                                           */
  1567. /*****************************************************************************/
  1568.  
  1569. #define LastDefinite(x, link, y)                    \
  1570. { for( link = LastDown(x);  link != x;  link = PrevDown(link) )        \
  1571.   { Child(y, link);                            \
  1572.     if( type(y) == SPLIT ? SplitIsDefinite(y) : is_definite(type(y)) )    \
  1573.     break;                                \
  1574.   }                                    \
  1575. } /* end LastDefinite */
  1576.  
  1577.  
  1578. /*****************************************************************************/
  1579. /*                                                                           */
  1580. /*  PrevDefinite(x, link, y)                                                 */
  1581. /*                                                                           */
  1582. /*  On input, x is an object and link is a link to one of its children; y    */
  1583. /*  is undefined.  On output there are two cases:                            */
  1584. /*                                                                           */
  1585. /*  link != x.  Then y is the first definite child of x preceding link, and  */
  1586. /*              link is changed to be the link of y.                         */
  1587. /*                                                                           */
  1588. /*  link == x.  Then x has no definite child preceding link, and y remains   */
  1589. /*              undefined.                                                   */
  1590. /*                                                                           */
  1591. /*****************************************************************************/
  1592.  
  1593. #define PrevDefinite(x, link, y)                    \
  1594. { for( link = PrevDown(link);  link != x;  link = PrevDown(link) )    \
  1595.   { Child(y, link);                            \
  1596.     if( type(y) == SPLIT ? SplitIsDefinite(y) : is_definite(type(y)) )    \
  1597.     break;                                \
  1598.   }                                    \
  1599. } /* end PrevDefinite */
  1600.  
  1601.  
  1602. /*@::Module Declarations@*****************************************************/
  1603. /*                                                                           */
  1604. /*  MODULE DECLARATIONS                                                      */
  1605. /*                                                                           */
  1606. /*****************************************************************************/
  1607.  
  1608. /*****  z01.c        Supervise        ******************************/
  1609. extern            main();            /* main program              */
  1610. extern    OBJECT        StartSym;        /* sym tab entry for \Start  */
  1611. extern    OBJECT        GalleySym;        /* sym tab entry for @Galley */
  1612. extern    OBJECT        InputSym;        /* sym tab entry for \Input  */
  1613. extern    OBJECT        PrintSym;        /* sym tab entry for \Print  */
  1614. extern    BOOLEAN        AllowCrossDb;        /* true when -s flag absent  */
  1615. extern    BOOLEAN        Encapsulated;        /* true when eps wanted      */
  1616.  
  1617. /*****  z02.c        Lexical Analyser    ******************************/
  1618. extern            LexInit();        /* initialise lex. analyser  */
  1619. extern            LexPush();        /* switch to new file list   */
  1620. extern            LexPop();        /* return to prev. file list */
  1621. extern    BOOLEAN        LexLegalName();        /* check identifier format   */
  1622. extern    OBJECT        LexGetToken();        /* get next token from input */
  1623. extern    long        LexNextTokenPos();    /* like ftell() on curr file */
  1624.  
  1625. /*****  z03.c        File Service            ******************************/
  1626. extern    FILE_POS    *no_fpos;        /* a null filepos            */
  1627. extern            InitFiles();        /* initialize this module    */
  1628. extern            AddToPath();        /* add directory to path     */
  1629. extern    FILE_NUM    DefineFile();        /* declare input file        */
  1630. extern    FILE_NUM    FirstFile();        /* first file of given type  */
  1631. extern    FILE_NUM    NextFile();        /* next file of given type   */
  1632. extern    FILE_NUM    FileNum();        /* file with given name      */
  1633. extern    FULL_CHAR    *FileName();        /* file name of file         */
  1634. extern    FULL_CHAR    *EchoFilePos();        /* string value of FILE_POS  */
  1635. extern    FILE_POS    *PosOfFile();        /* string of file FILE_POS   */
  1636. extern    FILE        *OpenFile();        /* open file for reading     */
  1637. extern    FILE        *OpenIncGraphicFile();    /* open @IncludeGraphic file */
  1638. extern    OBJECT        ReadFromFile();        /* read object from file     */
  1639. extern            AppendToFile();        /* append object to file     */
  1640. extern            CloseFiles();        /* close database files      */
  1641.  
  1642. /*****  z04.c        Token Service            ******************************/
  1643. extern    OBJECT        NewToken();        /* get a new token           */
  1644. extern    OBJECT        CopyTokenList();    /* copy a list of tokens     */
  1645. extern    FULL_CHAR    *EchoCatOp();        /* string value of CAT op    */
  1646. extern    FULL_CHAR    *EchoToken();        /* returns image of token    */
  1647.  
  1648. /*****  z05.c        Read Definitions      ******************************/
  1649. extern            ReadPrependDef();    /* read @Prepend ...         */
  1650. extern            ReadDatabaseDef();    /* read @Database ...        */
  1651. extern            ReadDefinitions();    /* read definitions          */
  1652.  
  1653. /*****  z06.c        Object Parser            ******************************/
  1654. extern            InitParser();        /* initialise parser         */
  1655. extern    OBJECT        Parse();        /* parser                    */
  1656.  
  1657. /*****  z07.c        Object Service            ******************************/
  1658. extern    OBJECT        MakeWord();        /* a new WORD or QWORD       */
  1659. extern    OBJECT        MakeWordTwo();        /* a new WORD from 2 strings */
  1660. extern    OBJECT        CopyObject();        /* make a copy of an object  */
  1661. extern            DisposeObject();    /* dispose an object         */
  1662. extern    BOOLEAN        SplitIsDefinite();    /* TRUE if SPLIT is definite */
  1663.  
  1664. /*****  z08.c        Object Manifest            ******************************/
  1665. extern    OBJECT        ReplaceWithTidy();    /* tidy up an object         */
  1666. extern    OBJECT        Manifest();        /* manifest an object        */
  1667.  
  1668. /*****  z09.c        Closure Expansion    ******************************/
  1669. extern    OBJECT        SetEnv();        /* build up environment      */
  1670. extern            AttachEnv();        /* attach env. to object     */
  1671. extern    OBJECT        SearchEnv();        /* search environment        */
  1672. extern    OBJECT        GetEnv();        /* retrieve env. from object */
  1673. extern    OBJECT        DetachEnv();        /* retrieve and detach env.  */
  1674. extern    OBJECT        ClosureExpand();    /* expand a user-def CLOSURE */
  1675.  
  1676. /*****  z10.c        Cross References    ******************************/
  1677. extern            CrossInit();        /* initialize cr record      */
  1678. extern            CrossAddTag();        /* add auto tag to closure   */
  1679. extern    OBJECT        CrossMake();        /* returns a cross-reference */
  1680. extern    OBJECT        GallTargEval();        /* returns the value of a cr */
  1681. extern    OBJECT        CrossExpand();        /* returns the value of a cr */
  1682. extern            CrossSequence();    /* record cr off root galley */
  1683. extern            CrossClose();        /* close down this module    */
  1684.  
  1685. /*****  z11.c        Style Service        ******************************/
  1686. extern            BreakChange();        /* change line spacing       */
  1687. extern            SpaceChange();        /* change word spacing       */
  1688. extern    FULL_CHAR    *EchoStyle();        /* string value of a style   */
  1689.  
  1690. /*****  z12.c        Size Finder        ******************************/
  1691. extern    OBJECT        MinSize();        /* min. possible size of obj */
  1692.  
  1693. /*****  z13.c        Object Breaking        ******************************/
  1694. extern    OBJECT        BreakObject();        /* break object to fit width */
  1695.  
  1696. /*****  z14.c        Object Filling            ******************************/
  1697. extern    OBJECT        FillObject();        /* optimal paragraph breaker */
  1698. extern    OBJECT        SimpleFillObject();    /* simple paragraph breaker  */
  1699.  
  1700. /*****  z15.c        Size Constraints    ******************************/
  1701. extern    FULL_CHAR    *EchoConstraint();    /* string value of a constr. */
  1702. extern            MinConstraint();    /* take minimum of two const */
  1703. extern            EnlargeToConstraint();    /* enlarge obj to constraint */
  1704. extern            RotateConstraint();    /* rotate constraints        */
  1705. extern            InvScaleConstraint();    /* inverse scale a constr.   */
  1706. extern            Constrained();        /* finds size constraint     */
  1707. extern            DebugConstrained();    /* debug constraint code     */
  1708.  
  1709. /*****  z16.c        Size Adjustments    ******************************/
  1710. extern            SetNeighbours();    /* locate definite neighbours*/
  1711. extern            AdjustSize();        /* updates sizes if changed  */
  1712.  
  1713. /*****  z17.c        Gap Widths        ******************************/
  1714. extern            GetGap();        /* convert string gap to num */
  1715. extern    LENGTH        MinGap();        /* min. possible gap width   */
  1716. extern    LENGTH        ExtraGap();        /* extra available gap width */
  1717. extern    LENGTH        ActualGap();        /* gap width for output      */
  1718. extern    FULL_CHAR    *EchoGap();        /* echo gap (cat. operator)  */
  1719.  
  1720. /*****  z18.c        Galley Transfer        ******************************/
  1721. extern            TransferInit();        /* initialise this module    */
  1722. extern    OBJECT        TransferBegin();    /* begin transfer of galley  */
  1723. extern            TransferComponent();    /* transfer one component    */
  1724. extern            TransferEnd();        /* end galley transfer       */
  1725. extern            TransferClose();    /* close this module         */
  1726.  
  1727. /*****  z19.c        Galley Attaching    ******************************/
  1728. extern    OBJECT        SearchGalley();        /* search galley for target  */
  1729. extern            AttachGalley();        /* start off a galley        */
  1730. extern            DetachGalley();        /* detach a galley           */
  1731.  
  1732. /*****  z20.c        Galley Flushing        ******************************/
  1733. extern            FlushGalley();        /* flush out a galley        */
  1734.  
  1735. /***    z21.c        Galley Maker        ******************************/
  1736. extern            SizeGalley();        /* convert object to galley  */
  1737.  
  1738. /***    z22.c        Galley Service        ******************************/
  1739. extern            FlushInners();        /* flush a list of galleys.  */
  1740. extern            ExpandRecursives();    /* expand recursive definite */
  1741. extern            Promote();        /* promote components        */
  1742. extern            KillGalley();        /* destroy a galley          */
  1743. extern            FreeGalley();        /* free a galley to flush    */
  1744. extern            Interpose();        /* interpose a VCAT          */
  1745. extern    BOOLEAN        TargetSymbol();        /* find target of galley     */
  1746. extern    int        CheckConstraint();    /* check ordering constraint */
  1747.  
  1748. /*****  z23.c        Galley Printer        ******************************/
  1749. extern            FixAndPrintObject();    /* fix and print component   */
  1750.  
  1751. /*****  z24.c        Print Service           ******************************/
  1752. extern            PrintInit();        /* initialise this module    */
  1753. extern            PrintPrologue();    /* print output prologue     */
  1754. extern            PrintOriginIncrement();    /* reset current o/p origin  */
  1755. extern            PrintWord();        /* print word at given pos   */
  1756. extern            PrintClose();        /* wrapup output stream      */
  1757. extern            CoordTranslate();    /* translate coord system    */
  1758. extern            CoordRotate();        /* rotate coord system       */
  1759. extern            CoordScale();        /* scale coord system        */
  1760. extern            SaveGraphicState();    /* save coord system etc.    */
  1761. extern            RestoreGraphicState();    /* restore coord system etc. */
  1762. extern            DefineGraphicNames();    /* define xsize, ysize, etc. */
  1763. extern            PrintGraphicObject();    /* print PostScript object   */
  1764. extern            PrintGraphicInclude();    /* include PostScript file   */
  1765.  
  1766. /*****  z25.c        Object Echo            ******************************/
  1767. extern    FULL_CHAR    *EchoObject();        /* return object as string   */
  1768. extern            DebugObject();        /* print object on stderr    */
  1769.  
  1770. /*****  z26.c        Echo Service            ******************************/
  1771. extern            BeginString();        /* begin string accumulator  */
  1772. extern            AppendString();        /* append to current string  */
  1773. extern    FULL_CHAR    *EndString();        /* return current string     */
  1774. extern    FULL_CHAR    *EchoLength();        /* echo a length             */
  1775. extern    FULL_CHAR    *Image();        /* string value of type(x)   */
  1776.  
  1777. /*****    z27.c        Debug Service        ******************************/
  1778. extern            DebugInit();        /* set debug flag            */
  1779. extern            Debug();        /* print debug o/p on stderr */
  1780. extern            ProfileOn();        /* start profiling           */
  1781. extern            ProfileOff();        /* stop profiling            */
  1782. extern            ProfilePrint();        /* print profiling results   */
  1783.  
  1784. /*****    z28.c        Error Service        ******************************/
  1785. extern            ErrorInit();        /* initialise log file       */
  1786. extern            Error();        /* print error message       */
  1787. extern    BOOLEAN        ErrorSeen();        /* TRUE after first error    */
  1788. extern            EnterErrorBlock();    /* new error message block   */
  1789. extern            LeaveErrorBlock();    /* commit or discard block   */
  1790.  
  1791. /*****  z29.c        Symbol Table        ******************************/
  1792. extern            InitSym();        /* initialize table to empty */
  1793. extern            PushScope();        /* push a new scope on stack */
  1794. extern            PopScope();        /* pop a scope from stack    */
  1795. extern            SuppressVisible();    /* suppress visible flag     */
  1796. extern            UnSuppressVisible();    /* unsuppress visible flag   */
  1797. extern            SuppressScope();    /* suppress all scoping      */
  1798. extern            UnSuppressScope();    /* unsuppress scoping        */
  1799. extern            SwitchScope();        /* switch to a saved scope   */
  1800. extern            UnSwitchScope();    /* switch back from saved s. */
  1801. extern            BodyParAllowed();    /* body par is invokable     */
  1802. extern            BodyParNotAllowed();    /* body par is not invokable */
  1803. extern    OBJECT        SearchSym();        /* search table for symbol   */
  1804. extern    OBJECT        InsertSym();        /* insert a new symbol       */
  1805. extern            DeleteEverySym();    /* dispose all symbols       */
  1806. extern    FULL_CHAR    *SymName();        /* string name of a symbol   */
  1807. extern    FULL_CHAR    *FullSymName();        /* full path name of symbol  */
  1808. extern    OBJECT        ChildSym();        /* return a child of a sym   */
  1809. extern            CheckSymSpread();    /* check hash table spread   */
  1810.  
  1811. /*****  z30.c        Symbol Uses        ******************************/
  1812. extern            InsertUses();        /* record symbol x uses y    */
  1813. extern            FlattenUses();        /* massage uses relation     */
  1814. extern    BOOLEAN        SearchUses();        /* retrieve uses info        */
  1815. extern    OBJECT        FirstExternTarget();    /* together these return all */
  1816. extern    OBJECT        NextExternTarget();    /*   targets of extern galls */
  1817.  
  1818. /*****  z31.c        Memory Allocator    ******************************/
  1819. extern            MemInit();        /* initialise mem. allocator */
  1820. extern    OBJECT        GetMemory();        /* get some fresh memory     */
  1821. extern            DebugMemory();        /* print memory usage        */
  1822. extern    OBJECT        zz_free[];        /* array of free lists       */
  1823. extern    unsigned char    zz_lengths[];        /* array of record lengths   */
  1824. extern    int        zz_newcount;        /* debug count of News       */
  1825. extern    int        zz_disposecount;    /* debug count of Disposes   */
  1826. extern    OBJECT        zz_hold;        /* temporary variable only   */
  1827. extern    OBJECT        zz_tmp;            /* temporary variable only   */
  1828. extern    OBJECT        zz_res;            /* temporary variable only   */
  1829. extern    int        zz_size;        /* temporary variable only   */
  1830. extern    OBJECT        xx_link, xx_tmp;    /* temporary variable only   */
  1831. extern    OBJECT        xx_hold, xx_res;    /* temporary variable only   */
  1832.  
  1833. /*****  z32.c        Counter Service        ******************************/
  1834. extern    OBJECT        Next();            /* increment argument by one */
  1835.  
  1836. /*****  z33.c        Database Service    ******************************/
  1837. extern    OBJECT        OldCrossDb;        /* cross refs from last run  */
  1838. extern    OBJECT        NewCrossDb;        /* cross refs from this run  */
  1839. extern    OBJECT        DbCreate();        /* create writable database  */
  1840. extern            DbInsert();        /* insert into database      */
  1841. extern            DbConvert();        /* con. writable to readable */
  1842. extern    OBJECT        DbLoad();        /* open readable database    */
  1843. extern    BOOLEAN        DbRetrieve();        /* retrieve from database    */
  1844. extern    BOOLEAN        DbRetrieveNext();    /* next entry from database  */
  1845. extern            DbClose();        /* close a readable database */
  1846.  
  1847. /*****  z34.c        Rotation Service        ******************************/
  1848. extern            RotateSize();        /* calculate rotated size    */
  1849.  
  1850. /*****  z35.c        Time Keeper         ******************************/
  1851. extern    OBJECT        MomentSym;        /* the @Moment symbol        */
  1852. extern            InitTime();        /* initialize this module    */
  1853. extern    OBJECT        StartMoment();        /* a copy of the init time   */
  1854. extern    FULL_CHAR    *TimeString();        /* a string containing time  */
  1855.  
  1856. /*****  z36.c        Hyphenation         ******************************/
  1857. extern    OBJECT        Hyphenate();        /* hyphenate a paragraph     */
  1858.  
  1859. /*****  z37.c        Font Service             *****************************/
  1860. extern            FontInit();        /* intialize this module     */
  1861. extern            FontDefine();        /* define a font             */
  1862. extern            FontChange();        /* change current font       */
  1863. extern            FontWordSize();        /* set sizes of a word       */
  1864. extern    LENGTH        FontSize();        /* size of a font            */
  1865. extern    LENGTH        FontHalfXHeight();    /* xheight/2 of a font       */
  1866. extern    ENCODING    FontEncoding();        /* encoding vector of a font */
  1867. extern    FULL_CHAR    *FontName();        /* output name of a font     */
  1868. extern    FULL_CHAR    *FontFamilyAndFace();    /* Lout name of a font       */
  1869. extern    BOOLEAN        FontNeeded();        /* writes out font needs     */
  1870.  
  1871. /*****  z38.c        Encoding Vectors    ******************************/
  1872. extern    ENCODING    EvLoad();        /* load one encoding vector  */
  1873. extern    FULL_CHAR    EvRetrieve();        /* convert char name to code */
  1874. extern    FULL_CHAR    *EvName();        /* name of encoding vector   */
  1875. extern            EvPrintAll();        /* print encoding vectors    */
  1876.  
  1877. /*****  z39.c        String Handler          ******************************/
  1878. #define            AsciiToFull(x)        ( (FULL_CHAR *) (x) )
  1879. #define            StringEqual(a, b) (strcmp((char *)(a), (char *)(b))==0)
  1880. #define            StringLessEqual(a, b) (strcmp((char*)(a),(char*)(b))<=0)
  1881. #define            StringCat(a, b)        strcat((char *)(a),(char *)(b))
  1882. #define            StringCopy(a, b)    strcpy((char *)(a),(char *)(b))
  1883. #define            StringLength(a)        strlen((char *)(a))
  1884. #define            StringFOpen(a, b)    fopen( (char *) (a), (b) )
  1885. #define            StringFPuts(a, b)    fputs( (char *) (a), (b) )
  1886. #define            StringFGets(a, b, c)    fgets( (char *) (a), (b), (c) )
  1887. #define            StringUnlink(a)        unlink((char *)(a))
  1888. #define            StringLink(a, b)    link((char *)(a),(char *)(b))
  1889. extern    BOOLEAN        StringBeginsWith();    /* string compare            */
  1890. extern    BOOLEAN        StringContains();    /* string search             */
  1891. extern    FULL_CHAR    *StringInt();        /* returns integer as string */
  1892. extern    FULL_CHAR    *StringFiveInt();    /* returns integer as string */
  1893. extern    FULL_CHAR    *StringQuotedWord();    /* returns string in Lout    */
  1894.  
  1895. /*@::assert(), debug(), debug flags@******************************************/
  1896. /*                                                                           */
  1897. /*  ASSERT AND DEBUG CODE                                                    */
  1898. /*                                                                           */
  1899. /*****************************************************************************/
  1900.  
  1901. #if ASSERT_ON
  1902. #define assert(c, m)                            \
  1903.    ( (c) ? 0 : Error(INTERN, no_fpos, "Assert failed in %s", m) )
  1904. #else
  1905. #define assert(c, m)    0
  1906. #endif
  1907.  
  1908. #if DEBUG_ON
  1909.  
  1910. struct dbs
  1911. {    char    *flag;            /* external names for debug flags    */
  1912.     BOOLEAN    on[3];            /* the debug flags                   */
  1913. };
  1914. extern    struct dbs     dbg[];
  1915.  
  1916. /* debug routines */
  1917. #define debug0(cat, urg, str)                                \
  1918.     if( dbg[cat].on[urg] ) Debug(cat, urg, str); else
  1919. #define debug1(cat, urg, str, p1)                    \
  1920.     if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1); else
  1921. #define debug2(cat, urg, str, p1, p2)                    \
  1922.     if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2); else
  1923. #define debug3(cat, urg, str, p1, p2, p3)                \
  1924.     if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3); else
  1925. #define debug4(cat, urg, str, p1, p2, p3, p4)                \
  1926.     if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3, p4); else
  1927. #define debug5(cat, urg, str, p1, p2, p3, p4, p5)            \
  1928.     if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3, p4, p5); else
  1929. #define debug6(cat, urg, str, p1, p2, p3, p4, p5, p6)            \
  1930.     if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3, p4, p5, p6); else
  1931. #define debug7(cat, urg, str, p1, p2, p3, p4, p5, p6, p7)        \
  1932.     if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2, p3, p4, p5,p6,p7); else
  1933. #define debug8(cat, urg, str, p1, p2, p3, p4, p5, p6, p7, p8)        \
  1934.     if( dbg[cat].on[urg] ) Debug(cat, urg, str, p1, p2,p3,p4,p5,p6,p7,p8); else
  1935. #define    ifdebug(cat, urg, x)                        \
  1936.     if( dbg[cat].on[urg] ) { x; } else 
  1937. #define    debug_init(str)                            \
  1938.     DebugInit(str)
  1939.  
  1940. /* debug styles */
  1941. #define    D     0
  1942. #define    DD     1
  1943. #define    DDD     2
  1944.  
  1945. /* debug flags */
  1946. #define    DSP     1        /*  z01.c   -dsp   Supervise                 */
  1947. #define    DLA     2        /*  z02.c   -dla   Lexical Analyser          */
  1948. #define    DFS     3        /*  z03.c   -dfs   File Service              */
  1949. #define    DTS     4        /*  z04.c   -dts   Token Service             */
  1950. #define    DRD     5        /*  z05.c   -drd   Read Definitions          */
  1951. #define    DOP     6        /*  z06.c   -dop   Object Parser             */
  1952. #define    DOS     7        /*  z07.c   -dos   Object Service            */
  1953. #define    DOM     8        /*  z08.c   -dom   Object Manifest           */
  1954. #define    DCE     9        /*  z09.c   -dce   Closure Expansion         */
  1955. #define    DCR    10        /*  z10.c   -dcr   Cross References         */
  1956. #define    DSS    11        /*  z11.c   -dss   Style Service         */
  1957. #define    DSF    12        /*  z12.c   -dsf   Size Finder               */
  1958. #define    DOB    13        /*  z13.c   -dob   Object Breaking         */
  1959. #define    DOF    14        /*  z14.c   -dof   Object Filling         */
  1960. #define    DSC    15        /*  z15.c   -dsc   Size Constraints          */
  1961. #define    DSA    16        /*  z16.c   -dsa   Size Adjustments         */
  1962. #define    DGW    17        /*  z17.c   -dgw   Gap Widths                */
  1963. #define    DGT    18        /*  z18.c   -dgt   Galley Transfer           */
  1964. #define    DGA    19        /*  z19.c   -dgf   Galley Attaching          */
  1965. #define    DGF    20        /*  z20.c   -dgf   Galley Flushing           */
  1966. #define    DGM    21        /*  z21.c   -dgm   Galley Maker              */
  1967. #define    DGS    22        /*  z22.c   -dgs   Galley Service            */
  1968. #define    DGP    23        /*  z23.c   -dgp   Galley Printer            */
  1969. #define    DPS    24        /*  z24.c   -dps   Print Service             */
  1970. #define    DOE    25        /*  z25.c   -doe   Object Echo               */
  1971. #define    DES    26        /*  z26.c   -des   Echo Service             */
  1972. #define    DZZ    27        /*  z27.c   -dzz   Debug Service             */
  1973. #define    DYY    28        /*  z28.c   -dyy   Error Service             */
  1974. #define    DST    29        /*  z29.c   -dst   Symbol Table              */
  1975. #define    DSU    30        /*  z30.c   -dsu   Symbol Uses               */
  1976. #define    DMA    31        /*  z31.c   -dma   Memory Allocator          */
  1977. #define    DCS    32        /*  z32.c   -dcs   Counter Service           */
  1978. #define    DBS    33        /*  z33.c   -dbs   Database Service          */
  1979. #define    DRS    34        /*  z34.c   -drs   Rotation Service          */
  1980. #define    DTK    35        /*  z35.c   -dtk   Time Keeper               */
  1981. #define    DHY    36        /*  z36.c   -dhy   Hyphenation               */
  1982. #define    DFT    37        /*  z37.c   -dft   Font Service              */
  1983. #define    DEV    38        /*  z38.c   -dev   Encoding Vectors          */
  1984. #define    DSH    39        /*  z39.c   -dsh   String Handler            */
  1985. #define    DPP    40        /*          -dpp   Profiling                 */
  1986. #define    ANY    41        /*          -d     any                       */
  1987.  
  1988. #else
  1989. #define ifdebug(cat, urg, x)
  1990. #define debug0(cat, urg, str)
  1991. #define debug1(cat, urg, str, p1)
  1992. #define debug2(cat, urg, str, p1, p2)
  1993. #define debug3(cat, urg, str, p1, p2, p3)
  1994. #define debug4(cat, urg, str, p1, p2, p3, p4)
  1995. #define debug5(cat, urg, str, p1, p2, p3, p4, p5)
  1996. #define debug6(cat, urg, str, p1, p2, p3, p4, p5, p6)
  1997. #define debug7(cat, urg, str, p1, p2, p3, p4, p5, p6, p7)
  1998. #define debug8(cat, urg, str, p1, p2, p3, p4, p5, p6, p7, p8)
  1999. #define    debug_init(str)    Error(FATAL, no_fpos,            \
  2000.             "%s - debug flags not implemented", str)
  2001. #endif
  2002.