home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume37 / lout / part08 < prev    next >
Text File  |  1993-06-20  |  84KB  |  2,165 lines

  1. Newsgroups: comp.sources.misc
  2. From: jeff@joyce.cs.su.oz.au (Jeff Kingston)
  3. Subject: v37i106:  lout - Lout document formatting system, v2, Part08/30
  4. Message-ID: <1993Jun1.051802.25549@sparky.imd.sterling.com>
  5. X-Md4-Signature: 3fffd6449640f77c88ede06baef97105
  6. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Tue, 1 Jun 1993 05:18:02 GMT
  9. Approved: kent@sparky.imd.sterling.com
  10.  
  11. Submitted-by: jeff@joyce.cs.su.oz.au (Jeff Kingston)
  12. Posting-number: Volume 37, Issue 106
  13. Archive-name: lout/part08
  14. Environment: UNIX
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  lout/doc/tr.impl/s2.3 lout/include/eq lout/z36.c
  21. # Wrapped by kent@sparky on Sun May 30 19:43:55 1993
  22. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  23. echo If this archive is complete, you will see the following message:
  24. echo '          "shar: End of archive 8 (of 30)."'
  25. if test -f 'lout/doc/tr.impl/s2.3' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'lout/doc/tr.impl/s2.3'\"
  27. else
  28.   echo shar: Extracting \"'lout/doc/tr.impl/s2.3'\" \(12558 characters\)
  29.   sed "s/^X//" >'lout/doc/tr.impl/s2.3' <<'END_OF_FILE'
  30. X@SubSection
  31. X    @Tag { objects }
  32. X    @Title { Basic structural operators }
  33. X@Begin
  34. X@PP
  35. XA programming language may be considered complete when it attains the
  36. Xpower of a Turing machine, but no such criterion seems relevant to
  37. Xdocument formatting.  Instead, as the language develops and new
  38. Xapplications are attempted, deficiencies are exposed and the operator set is
  39. Xrevised to overcome them.
  40. X@PP
  41. XLout has a repertoire of 23 primitive operators
  42. X(Figure {@NumberOf primitives}),
  43. X
  44. X@Figure
  45. X   @Caption { The 23 primitive operators of Lout, in order of
  46. Xincreasing precedence. }
  47. X   @Tag { primitives }
  48. X@Tab
  49. X   vmargin { 0.5vx }
  50. X   @Fmta { @Col @I A ! @Col B }
  51. X{
  52. X@Rowa
  53. X   A { object  {@Code "/"}gap  object }
  54. X   B { Vertical concatenation with mark alignment }
  55. X@Rowa
  56. X   A { object  {@Code "//"}gap  object }
  57. X   B { Vertical concatenation with left justification }
  58. X@Rowa
  59. X   A { object  {@Code "|"}gap  object }
  60. X   B { Horizontal concatenation with mark alignment }
  61. X@Rowa
  62. X   A { object  {@Code "||"}gap  object }
  63. X   B { Horizontal concatenation with top-justification }
  64. X@Rowa
  65. X   A { object  {@Code "&"}gap  object }
  66. X   B { Horizontal concatenation within paragraphs }
  67. X@Rowa
  68. X   A { {@Code "@OneCol"}  object }
  69. X   B { Hide all but one column mark of @I object }
  70. X@Rowa
  71. X   A { {@Code "@OneRow"}  object }
  72. X   B { Hide all but one row mark of @I object }
  73. X@Rowa
  74. X   A { font  @Code "@Font"  object }
  75. X   B { Render @I object in nominated font }
  76. X@Rowa
  77. X   A { breakstyle  @Code "@Break"  object}
  78. X   B { Break paragraphs of @I object in nominated style }
  79. X@Rowa
  80. X   A { spacestyle  @Code "@Space"  object }
  81. X   B { Render spaces between words in nominated style }
  82. X@Rowa
  83. X   A { length  {@Code "@Wide"}  object }
  84. X   B { Render @I object to width @I length }
  85. X@Rowa
  86. X   A { length  {@Code "@High"}  object }
  87. X   B { Render @I object to height @I length }
  88. X@Rowa
  89. X   A { {@Code "@HExpand"}  object}
  90. X   B { Expand horizontal gaps to fill available space }
  91. X@Rowa
  92. X   A { {@Code "@VExpand"}  object}
  93. X   B { Expand vertical gaps to fill available space }
  94. X@Rowa
  95. X   A { {@Code "@HScale"}  object }
  96. X   B { Horizontal geometrical scaling to fill available space }
  97. X@Rowa
  98. X   A { {@Code "@VScale"}  object }
  99. X   B { Vertical geometrical scaling to fill available space }
  100. X@Rowa
  101. X   A { angle  {@Code "@Rotate"}  object }
  102. X   B { Rotate @I object by @I angle }
  103. X@Rowa
  104. X   A { PostScript  {@Code "@Graphic"}  object }
  105. X   B { Escape to graphics language }
  106. X@Rowa
  107. X   A { @Code "@Next"  object }
  108. X   B { Add 1 to an object denoting a number }
  109. X@Rowa
  110. X   A { object  @Code "@Case"  alternatives }
  111. X   B { Select from a set of alternative objects }
  112. X@Rowa
  113. X   A { identifier  @Code "&&"  object }
  114. X   B { Cross reference }
  115. X@Rowa
  116. X   A { cross-reference  @Code "@Open"  object }
  117. X   B { Retrieve value from cross reference }
  118. X@Rowa
  119. X   A { cross-reference  @Code "@Tagged"  object}
  120. X   B { Attach cross referencing tag to object }
  121. X}
  122. X
  123. Xwhich has proven adequate for a wide variety of features, including equations,
  124. Xtables, and page layout, and so seems to be reasonably complete in this
  125. Xpragmatic sense.  In this section we introduce the eight concatenation and
  126. Xmark-hiding operators.  To them falls the basic task of assembling complex
  127. Xobjects from simple ones, and they were the first
  128. Xto be designed and implemented.
  129. X@PP
  130. XMany of the operators of Eqn can be viewed as building small tables.  A
  131. Xbuilt-up fraction, for example, has one column and three rows
  132. X(numerator, line, and denominator).  Numerous investigations of this
  133. Xkind convinced the author that operators capable of assembling the rows
  134. Xand columns of tables would suffice for building all kinds of objects.
  135. X@PP
  136. XThe simplest objects are empty objects and literal words like
  137. X{@Code metempsychosis}, which have one column mark and one row mark:
  138. X@ID {
  139. X@ShowMarks metempsychosis
  140. X}
  141. XTo place two arbitrary objects side by side, we use the infix
  142. Xoperator {@Code "|"}, denoting horizontal concatenation.  For
  143. Xexample,
  144. X@ID {
  145. X@Code "USA  |0.2i  Australia"
  146. X}
  147. Xproduces the object
  148. X@ID {
  149. X@ShowMarks USA |0.2i @ShowMarks Australia
  150. X}
  151. XThe row marks are merged into one, fixing the vertical position of
  152. Xthe objects relative to each other; their horizontal separation is
  153. Xdetermined by the @I gap attached to the operator, in this case 0.2
  154. Xinches.  We think of the gap as part of the operator, although
  155. Xstrictly it is a third parameter.  It may be omitted, defaulting to
  156. X{@Code "0i"}.
  157. X@PP
  158. X@I {Vertical concatenation} & , denoted by the infix operator {@Code "/"},
  159. Xis the same apart from the change of direction:
  160. X@ID {
  161. X@Code "Australia  /0.1i  USA"
  162. X}
  163. Xproduces the object
  164. X@ID {
  165. X@ShowMarks Australia /0.1i
  166. X@ShowMarks USA
  167. X}
  168. Xwith column marks merged and a 0.1 inch gap.
  169. X@PP
  170. XConsider now what happens when horizontal and vertical are combined:
  171. X@ID  @Code {
  172. X             |1m  "{"  USA         |1m  "|0.2i" |1m   Australia  "}"
  173. X/1vx "/0.1i" |    "{"  Washington  |    "|"     |     Canberra  "}"
  174. X}
  175. XThe two parameters of @Code "/" now have two column marks each, and
  176. Xthey will be merged with the corresponding marks in the other
  177. Xparameter, yielding the object
  178. X@ID {
  179. X      @ShowMarks USA &
  180. X      { 0 ymark moveto xsize 10 pt add ymark lineto [ 3 pt ] 0 setdash stroke }
  181. X      @Graphic {1c @Wide }
  182. X      |0.2i @ShowMarks Australia
  183. X/0.1i @ShowMarks Washington  |     @ShowMarks Canberra
  184. X}
  185. XThe @Code "0.2i" gap separates columns, not individual items in
  186. Xcolumns, so a gap attached to the second @Code "|" would serve no
  187. Xpurpose; any such gap is ignored.  If the number of marks to be merged
  188. Xdiffers, empty columns are added at the right to equalize the number.  The
  189. Xfour marks protruding from the result are all available for merging
  190. Xwith neighbouring marks by other concatenation operators.  The precedence
  191. Xof @Code "|" is higher than the precedence of {@Code "/"}, so the braces
  192. Xcould be omitted.
  193. X@PP
  194. XWhen lines of text are concatenated, it is conventional to measure
  195. Xtheir separation from baseline to baseline (mark to mark in Lout),
  196. Xrather than from edge to edge as above.  This idea of different
  197. Xreference points for measurement evolved over the years into a
  198. Xsystem of six @I {gap modes} (Figure {@NumberOf gapmodes}), expressed
  199. Xby appending a letter to the length.  For example, @Code "|0.2i" is
  200. Xan abbreviation for {@Code "|0.2ie"}, meaning 0.2 inches measured
  201. Xfrom edge to edge; @Code "|0.3ix"
  202. Xproduces a 0.3 inch gap measured from mark to mark and widened if
  203. Xnecessary to prevent overstriking; and @Code "|2.5it" places its right
  204. Xparameter 2.5 inches from the current left margin, irrespective of
  205. Xthe position of the left parameter.  There is also a choice of
  206. Xeleven units of measurement (inches, centimetres, multiples of the
  207. Xcurrent font size, etc.), the most interesting being
  208. Xthe @Code r unit:  one @Code r is the column width minus the width of
  209. Xthe following object, so that @Code "|1rt" produces sufficient space
  210. Xto right justify the following object, and @Code "|0.5rt" to center
  211. Xit.  These features implement spacings needed in practice rather
  212. Xthan suggested by theory.  They work with all five concatenation
  213. Xoperators, horizontal and vertical.
  214. X
  215. X@Figure
  216. X   @Tag { gapmodes }
  217. X   @Caption { The six gap modes (@I length is any length).  Hyphenation
  218. Xmode has an extra property not shown here. }
  219. X@Fig {
  220. X{ /2.5vx Edge-to-edge |0.3i   {@Code "|"} &1p {@I length} &1p {@Code e}
  221. X  /4.2vx Hyphenation    |0.3i   {@Code "|"} &1p {@I length} &1p {@Code h}
  222. X  /4.2vx Overstrike     |0.3i   {@Code "|"} &1p {@I length} &1p {@Code o}
  223. X  /4.2vx Mark-to-mark   |0.3i   {@Code "|"} &1p {@I length} &1p {@Code x}
  224. X  /4.2vx Kerning        |0.3i   {@Code "|"} &1p {@I length} &1p {@Code k}
  225. X  /4.2vx Tabulation     |0.3i   {@Code "|"} &1p {@I length} &1p {@Code t}
  226. X}
  227. X||0.5i
  228. X@Box margin { 0c } 6c @Wide 13.5c @High 9p @Font
  229. X{
  230. X  @OneRow {
  231. X     @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  232. X     @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  233. X     @At { 2.2c @Wide 1.4c @High } @Put { @DoubleArrow 1.8c }
  234. X     @At { 2.2c @Wide 1.6c @High } @Put { 1.8c @Wide { &0.5rt @I length } }
  235. X  }
  236. X  //4vx
  237. X  @OneRow {
  238. X     @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  239. X     @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  240. X     @At { 2.2c @Wide 1.4c @High } @Put { @DoubleArrow 1.8c }
  241. X     @At { 2.2c @Wide 1.6c @High } @Put { 1.8c @Wide { &0.5rt @I length } }
  242. X  }
  243. X  //4vx
  244. X  @OneRow {
  245. X     @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  246. X     @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  247. X     @At { 1.2c @Wide 1.5c @High } @Put { @DoubleArrow 3.3c }
  248. X     @At { 1.2c @Wide 1.7c @High } @Put { 3.3c @Wide { &0.5rt @I length } }
  249. X  }
  250. X  //4vx
  251. X  @OneRow {
  252. X     @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  253. X     @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  254. X     @At { 1.2c @Wide 1.5c @High } @Put { @DoubleArrow 3.3c }
  255. X     @At { 1.2c @Wide 1.7c @High }
  256. X    @Put 3.3c @Wide { |0.5rt @Eq { max(length, a+b) } }
  257. X     @At { 1.2c @Wide 0.4c @High } @Put { @DoubleArrow 1.0c }
  258. X     @At { 1.2c @Wide 0.2c @High } @Put { 1.0c @Wide { &0.5rt @I a } }
  259. X     @At { 4c   @Wide 0.4c @High } @Put { @DoubleArrow 0.5c }
  260. X     @At { 4c   @Wide 0.2c @High } @Put { 0.5c @Wide { &0.5rt @I b } }
  261. X  }
  262. X  //4.5vx
  263. X  @OneRow {
  264. X     @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  265. X     @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  266. X     @At { 1.2c @Wide 1.5c @High } @Put { @DoubleArrow 3.3c }
  267. X     @At { 1.2c @Wide 1.7c @High }
  268. X    @Put { 3.3c @Wide { |0.5rt @Eq { max(length, a, b) } } }
  269. X     @At { 1.2c @Wide 0.4c @High } @Put { @DoubleArrow 1.0c }
  270. X     @At { 1.2c @Wide 0.2c @High } @Put { 1.0c @Wide { &0.5rt @I a } }
  271. X     @At { 4c   @Wide 0.4c @High } @Put { @DoubleArrow 0.5c }
  272. X     @At { 4c   @Wide 0.2c @High } @Put { 0.5c @Wide { &0.5rt @I b } }
  273. X  }
  274. X  //4vx
  275. X  @OneRow {
  276. X     @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  277. X     @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  278. X     @At { 0.0c @Wide 1.6c @High } @Put { @DoubleArrow 4.0c }
  279. X     @At { 2.8c @Wide 1.8c @High } @Put { @I length }
  280. X  }
  281. X  //5vx
  282. X  @DoubleArrow 6c
  283. X  //0.1c |0.5rt @I { current bound }
  284. X}
  285. X}
  286. X
  287. X@PP
  288. XWhen we construct a built-up fraction, the result has three row marks, but
  289. Xonly the second should be visible outside the object:
  290. X@ID @Eq { @ShowMarks { X over Y } }
  291. XThis is a common problem, and accordingly a @Code "@OneRow" operator was
  292. Xintroduced for hiding all but one of the row marks of its
  293. Xparameter.  Normally, the first mark is the survivor, but a later mark can
  294. Xbe chosen by prefixing @Code "^" to the preceding concatenation operator:
  295. X@ID @Code "@OneRow { X  ^/2p  @HLine  /2p  Y }"
  296. Xhas the desired result, where {@Code "2p"} is two points and @Code "@HLine"
  297. Xis an easy combination of Lout's graphics operators.  A similar operator,
  298. X{@Code "@OneCol"}, hides column marks.
  299. X@PP
  300. XA variant of @Code "/" called @Code "//" is provided which performs
  301. Xvertical concatenation but ignores all column marks and simply
  302. Xleft-justifies its two parameters:
  303. X@ID @Code {
  304. X"Heading  //0.1i"
  305. X"A  |0.2i  B  /0.1i"
  306. X"C  |  D"
  307. X}
  308. Xhas result
  309. X@ID { Heading //0.1i  A  |0.2i  B  /0.1i  C  |  D }
  310. Xshowing that spanning columns in tables motivate the inclusion of this
  311. Xoperator.  There is an analogous @Code "||" operator.  The author
  312. Xwould have preferred to leave out these operators, since they
  313. Xcomplicate the implementation, and it is interesting to examine the
  314. Xprospects of doing so.
  315. X@PP
  316. XThe @Code "//" operator is formally redundant, because in general
  317. Xthe expression @Code "x // y" can be replaced by
  318. X@ID @Code {
  319. X"@OneCol {  |  x  }   /"
  320. X"@OneCol {  |  y  }"
  321. X}
  322. Xfor any objects {@Code x} and {@Code y}.  By concatenating an empty
  323. Xobject at the left of @Code x and hiding all but that empty object's
  324. Xcolumn mark, we effectively shift {@Code x}'s column mark to its left
  325. Xedge.  The same goes for {@Code y}, so the @Code "/" operator has just
  326. Xone column mark to merge, at the extreme left, and its effect is
  327. Xindistinguishable from {@Code "//"}.
  328. X@PP
  329. XUnfortunately, if @Code y consists of two rows separated by {@Code "/"},
  330. Xas in the example above, both rows must be placed inside the
  331. X{@Code "@OneCol"}, and the table cannot be entered in the simple
  332. Xrow-by-row manner that non-expert users naturally expect.  Another
  333. Xadvantage of @Code "//" is that its left parameter can be printed
  334. Xbefore its right parameter is known; this is important when the left
  335. Xparameter is an entire page.
  336. X@PP
  337. XThe fifth and final concatenation operator, {@Code "&"}, is an explicit
  338. Xversion of the horizontal concatenation operator interpolated when
  339. Xobjects are separated by white space.  It is formally identical to
  340. X@Code "|" except for taking higher precedence and being subject to
  341. Xreplacement by @Code "//1vx" during paragraph breaking
  342. X(Section {@NumberOf style}).
  343. X@End @SubSection
  344. END_OF_FILE
  345.   if test 12558 -ne `wc -c <'lout/doc/tr.impl/s2.3'`; then
  346.     echo shar: \"'lout/doc/tr.impl/s2.3'\" unpacked with wrong size!
  347.   fi
  348.   # end of 'lout/doc/tr.impl/s2.3'
  349. fi
  350. if test -f 'lout/include/eq' -a "${1}" != "-c" ; then 
  351.   echo shar: Will not clobber existing file \"'lout/include/eq'\"
  352. else
  353.   echo shar: Extracting \"'lout/include/eq'\" \(35135 characters\)
  354.   sed "s/^X//" >'lout/include/eq' <<'END_OF_FILE'
  355. X
  356. X###############################################################################
  357. X#                                                                             #
  358. X#  Lout @Eq package for equation formatting (Version 2.0)                     #
  359. X#                                                                             #
  360. X#  Version 1.0 by Jeffrey H. Kingston, December 1990.                         #
  361. X#  Version 2.0 by Jeffrey H. Kingston, 22 December 1992.                      #
  362. X#                                                                             #
  363. X#  See "Eq - a Lout package for typesetting mathematics" for user             #
  364. X#  information.  Acknowledgement:  the @Eq language is based closely on       #
  365. X#  the Eqn language of B. W. Kernighan and L. L. Cherry; the spacing rules    #
  366. X#  are similar to those of the TeX system by D. E. Knuth.                     #
  367. X#                                                                             #
  368. X###############################################################################
  369. X
  370. Xexport    "`" "``" "```" bin rel punct non vctr big
  371. X
  372. X    space exclam universal numbersign existential percent
  373. X    ampersand suchthat parenleft parenright asteriskmath
  374. X    plus comma minus period slash zero one two three four
  375. X    five six seven eight nine colon semicolon less equal
  376. X    greater question congruent Alpha Beta Chi Delta Epsilon
  377. X    Phi Gamma Eta Iota thetaone Kappa Lambda Mu Nu Omicron
  378. X    Pi Theta Rho Sigma Tau Upsilon sigmaone Omega Xi Psi Zeta
  379. X    bracketleft therefore bracketright perpendicular underscore
  380. X    radicalex alpha beta chi delta epsilon phi gamma eta iota
  381. X    phione kappa lambda mu nu omicron pi theta rho sigma tau
  382. X    upsilon omegaone omega xi psi zeta braceleft bar braceright
  383. X    similar Upsilonone minute lessequal fraction infinity florin
  384. X    club diamond heart spade arrowboth arrowleft arrowup
  385. X    arrowright arrowdown degree plusminus second greaterequal
  386. X    multiply proportional partialdiff bullet divide notequal
  387. X    equivalence approxequal ellipsis arrowvertex arrowhorizex
  388. X    carriagereturn aleph Ifraktur Rfraktur weierstrass
  389. X    circlemultiply circleplus emptyset intersection union
  390. X    propersuperset reflexsuperset notsubset propersubset
  391. X    reflexsubset element notelement angle gradient registerserif
  392. X    copyrightserif trademarkserif product radical dotmath
  393. X    logicalnot logicaland logicalor arrowdblboth arrowdblleft
  394. X    arrowdblup arrowdblright arrowdbldown lozenge angleleft
  395. X    registersans copyrightsans trademarksans summation parenlefttp
  396. X    parenleftex parenleftbt bracketlefttp bracketleftex
  397. X    bracketleftbt bracelefttp braceleftmid braceleftbt braceex
  398. X    angleright integral integraltp integralex integralbt
  399. X    parenrighttp parenrightex parenrightbt bracketrighttp
  400. X    bracketrightex bracketrightbt bracerighttp bracerightmid
  401. X    bracerightbt
  402. X
  403. X    hbar Re Im partial infty prime nabla surd top bot dbar
  404. X    triangle backslash forall exists neg circle square
  405. X
  406. X    "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
  407. X
  408. X    sum prod coprod int oint bcap bcup bvee bwedge bodot botimes
  409. X    boplus buplus
  410. X
  411. X    "+" "-" "+-" "-+" setminus cdot times "*" circ div cap cup uplus
  412. X    sqcap sqcup triangleleft triangleright wr bigcirc bigtriangleup
  413. X    bigtriangledown vee wedge oplus ominus otimes oslash odot dagger
  414. X    daggerdbl amalg
  415. X
  416. X    "<" ">" "=" "<=" prec preceq "<<" subset subseteq sqsubseteq
  417. X    in vdash smile frown ">=" succ succeq ">>" supset supseteq
  418. X    sqsupseteq ni dashv mid parallel "==" "~" "-~" asymp "~~"
  419. X    "=~" bowtie propto models doteq perp notsub notin "!=" not
  420. X    "<->" "<--" "-->" up down "<=>" "<==" "==>" dblup dbldown
  421. X    ":" "::" ":="
  422. X
  423. X    lpar blpar rpar brpar lbrack blbrack rbrack brbrack lbrace blbrace
  424. X    rbrace brbrace lfloor blfloor rfloor brfloor lceil blceil
  425. X    rceil brceil langle blangle rangle brangle
  426. X
  427. X    ";" "," col
  428. X    
  429. X    "!" "?" "%" "(" ")" "[" "]"
  430. X
  431. X    arccos arcsin arctan arg cos cosh cot coth csc deg det dim exp
  432. X    gcd hom inf ker lg lim liminf limsup ln log max min Pr sec sin
  433. X    sinh supr tan tanh mod ldots cdots vdots ddots del grad
  434. X    "..." "'" empty
  435. X    
  436. X    sup sub supp on frac half third over from to widefrom wideto
  437. X    dot dotdot hat tilde vec dyad overbar underbar sqrt root above
  438. X    labove cabove rabove mabove nextcol matrix
  439. X
  440. Xdef @Eq                  
  441. X   body @Body
  442. X@Begin
  443. X
  444. X   def @SkewGap  { 0.05f  }
  445. X   def @SupGap   { 0.40fk }
  446. X   def @ThinGap  { 0.15v  }
  447. X   def @MedGap   { 0.20v  }
  448. X   def @ThickGap { 0.25v  }
  449. X   def @ColGap   { 0.8f   }
  450. X   def @RowGap   { 0.5f   }
  451. X   def @FontRed  { 0.7f   }
  452. X   def @FontInc  { 1.3f   }
  453. X
  454. X   def "`"       { &@ThinGap  }
  455. X   def "``"      { &@MedGap   }
  456. X   def "```"     { &@ThickGap }
  457. X
  458. X   def bin    right x { ``  x ``  }
  459. X   def rel    right x { ``` x ``` }
  460. X   def punct    right x {     x `   }
  461. X   def non    right x { 0c @Break x }
  462. X   def big    right x { @FontInc @Font 0c @Space @FontInc @Break x }
  463. X
  464. X   def @Base    right x { Base @Font x }
  465. X   def @Smaller right x { @FontRed @Font 0c @Space     0.2f @Break x }
  466. X   def @Sym     right x { {Symbol Base} @Font x }
  467. X
  468. X   def @HLine
  469. X      named line { "0.05 ft setlinewidth" }
  470. X   {  
  471. X      { "0 0 moveto xsize 0 lineto" line "stroke" } @Graphic {}
  472. X   }
  473. X
  474. X   def @VLine
  475. X   {
  476. X      "0 0 moveto 0 ysize lineto 0.05 ft setlinewidth stroke" @Graphic {}
  477. X   }
  478. X
  479. X   def vctr
  480. X      right x
  481. X   { @OneRow {   -180d @Rotate { /0.5wo 180d @Rotate { / @OneRow @OneCol x  } }
  482. X           ^/      @OneRow { /0.5wo      @OneRow { @OneRow @OneCol x ^/ } }
  483. X         }
  484. X   }
  485. X
  486. X   ###################################################################
  487. X   #                                                                 #
  488. X   #   Full names                                                    #
  489. X   #                                                                 #
  490. X   #   These symbols and their names are taken directly from the     #
  491. X   #   Adobe Systems Inc. Symbol font (see PostScript Language       #
  492. X   #   Reference Manual, pp. 256-257).  The only differences are:    #
  493. X   #                                                                 #
  494. X   #      Adobe:  theta1        Eq:  thetaone                        #
  495. X   #              sigma1             sigmaone                        #
  496. X   #              phi1               phione                          #
  497. X   #              omega1             omegaone                        #
  498. X   #                                                                 #
  499. X   #   These were needed since Lout identifiers do not have digits.  #
  500. X   #                                                                 #
  501. X   ###################################################################
  502. X
  503. X   def space           { @Sym "\040"  }
  504. X   def exclam          { @Sym "\041"  }
  505. X   def universal       { @Sym "\042"  }
  506. X   def numbersign      { @Sym "\043"  }
  507. X   def existential     { @Sym "\044"  }
  508. X   def percent         { @Sym "\045"  }
  509. X   def ampersand       { @Sym "\046"  }
  510. X   def suchthat        { @Sym "\047"  }
  511. X   def parenleft       { @Sym "\050"  }
  512. X   def parenright      { @Sym "\051"  }
  513. X   def asteriskmath    { @Sym "\052"  }
  514. X   def plus            { @Sym "+"     }
  515. X   def comma           { @Sym "\054"  }
  516. X   def minus           { @Sym "-"     }
  517. X   def period          { @Sym "\056"  }
  518. X   def slash           { @Sym "\057"  }
  519. X   def zero            { @Sym "\060"  }
  520. X   def one             { @Sym "\061"  }
  521. X   def two             { @Sym "\062"  }
  522. X   def three           { @Sym "\063"  }
  523. X   def four            { @Sym "\064"  }
  524. X   def five            { @Sym "\065"  }
  525. X   def six             { @Sym "\066"  }
  526. X   def seven           { @Sym "\067"  }
  527. X   def eight           { @Sym "\070"  }
  528. X   def nine            { @Sym "\071"  }
  529. X   def colon           { @Sym "\072"  }
  530. X   def semicolon       { @Sym "\073"  }
  531. X   def less            { @Sym "\074"  }
  532. X   def equal           { @Sym "\075"  }
  533. X   def greater         { @Sym "\076"  }
  534. X   def question        { @Sym "\077"  }
  535. X   def congruent       { @Sym "\100"  }
  536. X   def Alpha           { @Sym "\101"  }
  537. X   def Beta            { @Sym "\102"  }
  538. X   def Chi             { @Sym "\103"  }
  539. X   def Delta           { @Sym "\104"  }
  540. X   def Epsilon         { @Sym "\105"  }
  541. X   def Phi             { @Sym "\106"  }
  542. X   def Gamma           { @Sym "\107"  }
  543. X   def Eta             { @Sym "\110"  }
  544. X   def Iota            { @Sym "\111"  }
  545. X   def thetaone        { @Sym "\112"  }
  546. X   def Kappa           { @Sym "\113"  }
  547. X
  548. X   def Lambda          { @Sym "\114"  }
  549. X   def Mu              { @Sym "\115"  }
  550. X   def Nu              { @Sym "\116"  }
  551. X   def Omicron         { @Sym "\117"  }
  552. X   def Pi              { @Sym "\120"  }
  553. X   def Theta           { @Sym "\121"  }
  554. X   def Rho             { @Sym "\122"  }
  555. X   def Sigma           { @Sym "\123"  }
  556. X   def Tau             { @Sym "\124"  }
  557. X   def Upsilon         { @Sym "\125"  }
  558. X   def sigmaone        { @Sym "\126"  }
  559. X   def Omega           { @Sym "\127"  }
  560. X   def Xi              { @Sym "\130"  }
  561. X   def Psi             { @Sym "\131"  }
  562. X   def Zeta            { @Sym "\132"  }
  563. X   def bracketleft     { @Sym "\133"  }
  564. X   def therefore       { @Sym "\134"  }
  565. X   def bracketright    { @Sym "\135"  }
  566. X   def perpendicular   { @Sym "\136"  }
  567. X   def underscore      { @Sym "\137"  }
  568. X   def radicalex       { @Sym "\140"  }
  569. X   def alpha           { @Sym "\141"  }
  570. X   def beta            { @Sym "\142"  }
  571. X   def chi             { @Sym "\143"  }
  572. X   def delta           { @Sym "\144"  }
  573. X   def epsilon         { @Sym "\145"  }
  574. X   def phi             { @Sym "\146"  }
  575. X   def gamma           { @Sym "\147"  }
  576. X   def eta             { @Sym "\150"  }
  577. X   def iota            { @Sym "\151"  }
  578. X   def phione          { @Sym "\152"  }
  579. X   def kappa           { @Sym "\153"  }
  580. X   def lambda          { @Sym "\154"  }
  581. X   def mu              { @Sym "\155"  }
  582. X   def nu              { @Sym "\156"  }
  583. X
  584. X   def omicron         { @Sym "\157"  }
  585. X   def pi              { @Sym "\160"  }
  586. X   def theta           { @Sym "\161"  }
  587. X   def rho             { @Sym "\162"  }
  588. X   def sigma           { @Sym "\163"  }
  589. X   def tau             { @Sym "\164"  }
  590. X   def upsilon         { @Sym "\165"  }
  591. X   def omegaone        { @Sym "\166"  }
  592. X   def omega           { @Sym "\167"  }
  593. X   def xi              { @Sym "\170"  }
  594. X   def psi             { @Sym "\171"  }
  595. X   def zeta            { @Sym "\172"  }
  596. X   def braceleft       { @Sym "\173"  }
  597. X   def bar             { @Sym "\174"  }
  598. X   def braceright      { @Sym "\175"  }
  599. X   def similar         { @Sym "\176"  }
  600. X   def Upsilonone      { @Sym "\241"  }
  601. X   def minute          { @Sym "\242"  }
  602. X   def lessequal       { @Sym "\243"  }
  603. X   def fraction        { @Sym "\244"  }
  604. X   def infinity        { @Sym "\245"  }
  605. X   def florin          { @Sym "\246"  }
  606. X   def club            { @Sym "\247"  }
  607. X   def diamond         { @Sym "\250"  }
  608. X   def heart           { @Sym "\251"  }
  609. X   def spade           { @Sym "\252"  }
  610. X   def arrowboth       { @Sym "\253"  }
  611. X   def arrowleft       { @Sym "\254"  }
  612. X   def arrowup         { @Sym "\255"  }
  613. X   def arrowright      { @Sym "\256"  }
  614. X   def arrowdown       { @Sym "\257"  }
  615. X   def degree          { @Sym "\260"  }
  616. X   def plusminus       { @Sym "\261"  }
  617. X   def second          { @Sym "\262"  }
  618. X   def greaterequal    { @Sym "\263"  }
  619. X
  620. X   def multiply        { @Sym "\264"  }
  621. X   def proportional    { @Sym "\265"  }
  622. X   def partialdiff     { @Sym "\266"  }
  623. X   def bullet          { @Sym "\267"  }
  624. X   def divide          { @Sym "\270"  }
  625. X   def notequal        { @Sym "\271"  }
  626. X   def equivalence     { @Sym "\272"  }
  627. X   def approxequal     { @Sym "\273"  }
  628. X   def ellipsis        { @Sym "\274"  }
  629. X   def arrowvertex     { @Sym "\275"  }
  630. X   def arrowhorizex    { @Sym "\276"  }
  631. X   def carriagereturn  { @Sym "\277"  }
  632. X   def aleph           { @Sym "\300"  }
  633. X   def Ifraktur        { @Sym "\301"  }
  634. X   def Rfraktur        { @Sym "\302"  }
  635. X   def weierstrass     { @Sym "\303"  }
  636. X   def circlemultiply  { @Sym "\304"  }
  637. X   def circleplus      { @Sym "\305"  }
  638. X   def emptyset        { @Sym "\306"  }
  639. X   def intersection    { @Sym "\307"  }
  640. X   def union           { @Sym "\310"  }
  641. X   def propersuperset  { @Sym "\311"  }
  642. X   def reflexsuperset  { @Sym "\312"  }
  643. X   def notsubset       { @Sym "\313"  }
  644. X   def propersubset    { @Sym "\314"  }
  645. X   def reflexsubset    { @Sym "\315"  }
  646. X   def element         { @Sym "\316"  }
  647. X   def notelement      { @Sym "\317"  }
  648. X   def angle           { @Sym "\320"  }
  649. X   def gradient        { @Sym "\321"  }
  650. X   def registerserif   { @Sym "\322"  }
  651. X   def copyrightserif  { @Sym "\323"  }
  652. X   def trademarkserif  { @Sym "\324"  }
  653. X   def product         { @Sym "\325"  }
  654. X   def radical         { @Sym "\326"  }
  655. X   def dotmath         { @Sym "\327"  }
  656. X
  657. X   def logicalnot      { @Sym "\330"  }
  658. X   def logicaland      { @Sym "\331"  }
  659. X   def logicalor       { @Sym "\332"  }
  660. X   def arrowdblboth    { @Sym "\333"  }
  661. X   def arrowdblleft    { @Sym "\334"  }
  662. X   def arrowdblup      { @Sym "\335"  }
  663. X   def arrowdblright   { @Sym "\336"  }
  664. X   def arrowdbldown    { @Sym "\337"  }
  665. X   def lozenge         { @Sym "\340"  }
  666. X   def angleleft       { @Sym "\341"  }
  667. X   def registersans    { @Sym "\342"  }
  668. X   def copyrightsans   { @Sym "\343"  }
  669. X   def trademarksans   { @Sym "\344"  }
  670. X   def summation       { @Sym "\345"  }
  671. X   def parenlefttp     { @Sym "\346"  }
  672. X   def parenleftex     { @Sym "\347"  }
  673. X   def parenleftbt     { @Sym "\350"  }
  674. X   def bracketlefttp   { @Sym "\351"  }
  675. X   def bracketleftex   { @Sym "\352"  }
  676. X   def bracketleftbt   { @Sym "\353"  }
  677. X   def bracelefttp     { @Sym "\354"  }
  678. X   def braceleftmid    { @Sym "\355"  }
  679. X   def braceleftbt     { @Sym "\356"  }
  680. X   def braceex         { @Sym "\357"  }
  681. X   def angleright      { @Sym "\361"  }
  682. X   def integral        { @Sym "\362"  }
  683. X   def integraltp      { @Sym "\363"  }
  684. X   def integralex      { @Sym "\364"  }
  685. X   def integralbt      { @Sym "\365"  }
  686. X   def parenrighttp    { @Sym "\366"  }
  687. X   def parenrightex    { @Sym "\367"  }
  688. X   def parenrightbt    { @Sym "\370"  }
  689. X   def bracketrighttp  { @Sym "\371"  }
  690. X   def bracketrightex  { @Sym "\372"  }
  691. X   def bracketrightbt  { @Sym "\373"  }
  692. X   def bracerighttp    { @Sym "\374"  }
  693. X   def bracerightmid   { @Sym "\375"  }
  694. X   def bracerightbt    { @Sym "\376"  }
  695. X
  696. X
  697. X   ###################################################################
  698. X   #                                                                 #
  699. X   #   Short names                                                   #
  700. X   #                                                                 #
  701. X   #   These symbols, their names, and their spacing, are based on   #
  702. X   #   the list in Appendix F of Donald E. Knuth's The TeXBook.      #
  703. X   #                                                                 #
  704. X   #   Group 1 (lowercase Greek letters):  see full names above      #
  705. X   #   Group 2 (uppercase Greek letters):  see full names above      #
  706. X   #   Group 3 (calligraphic capitals):    not provided by Eq        #
  707. X   #                                                                 #
  708. X   ###################################################################
  709. X
  710. X   ###################################################################
  711. X   #                                                                 #
  712. X   #   Group 4 (miscellaneous Ord symbols)                           #
  713. X   #                                                                 #
  714. X   #   Not all of Knuth's symbols are available.  The four suits     #
  715. X   #   (heartsuit, etc.), have definitions above.                    #
  716. X   #                                                                 #
  717. X   ###################################################################
  718. X
  719. X   def hbar         { @OneCol { &0.1f @Base "-" ^/0.25fo h }    }
  720. X   def Re           { Rfraktur                    }
  721. X   def Im           { Ifraktur                    }
  722. X   def partial      { partialdiff                }
  723. X   def infty        { infinity                    }
  724. X   def prime        {  minute                        }
  725. X  #def emptyset     { defined above                }
  726. X   def nabla        { gradient                    }
  727. X   def surd         { radical                    }
  728. X   def top          { 180d @Rotate perpendicular        }
  729. X   def bot          { perpendicular                }
  730. X   def dbar         { @Base "||"                             }
  731. X  #def angle        { defined above                }
  732. X   def backslash    { "\\"                    }
  733. X   def forall       { universal                    }
  734. X   def exists       { existential                }
  735. X   def neg          { logicalnot                }
  736. X
  737. X   def circle       { @HContract @VContract
  738. X              { "xsize ysize 2 div moveto"
  739. X            "xsize 2 div ysize 2 div xsize 2 div 0 360 arc"
  740. X            "0.04 ft setlinewidth stroke"
  741. X              }
  742. X              @Graphic { 0.7f @Wide 0.3f @High ^/ 0.3f @High }
  743. X            }
  744. X
  745. X   def square       { @HContract @VContract
  746. X              { "0 0 moveto xsize 0 lineto xsize ysize lineto"
  747. X            "0 ysize lineto closepath"
  748. X            "0.04 ft setlinewidth stroke"
  749. X              }
  750. X              @Graphic { 0.6f @Wide 0.3f @High ^/ 0.3f @High }
  751. X            }
  752. X
  753. X   def triangle     { @HContract @VContract
  754. X              { "0 0 moveto xsize 0 lineto"
  755. X                "xsize 2 div ysize lineto closepath"
  756. X            "0.04 ft setlinewidth stroke"
  757. X              }
  758. X              @Graphic
  759. X              { 0.3f @Wide 0.3f @High ^| ^/
  760. X                0.3f @Wide 0.3f @High
  761. X              }
  762. X            }
  763. X
  764. X   ###################################################################
  765. X   #                                                                 #
  766. X   #   Group 5 (digits)                                              #
  767. X   #                                                                 #
  768. X   ###################################################################
  769. X
  770. X   def "0" { zero            }
  771. X   def "1" { one             }
  772. X   def "2" { two             }
  773. X   def "3" { three           }
  774. X   def "4" { four            }
  775. X   def "5" { five            }
  776. X   def "6" { six             }
  777. X   def "7" { seven           }
  778. X   def "8" { eight           }
  779. X   def "9" { nine            }
  780. X
  781. X
  782. X   ###################################################################
  783. X   #                                                                 #
  784. X   #   Group 6 ("Large" operators)                                   #
  785. X   #                                                                 #
  786. X   #   Knuth's large operators automatically change size depending   #
  787. X   #   on whether the equation is display or inline.  Eq does not    #
  788. X   #   do this; instead, the `big' operator must be used.            #
  789. X   #                                                                 #
  790. X   ###################################################################
  791. X
  792. X   def sum    { summation                    }
  793. X   def prod    { product                    }
  794. X   def coprod    { 180d @Rotate vctr product            }
  795. X   def int    { 1.3f @Font vctr integral            }
  796. X   def oint    { @OneCol { vctr degree |0.015fo int }        }
  797. X   def bcap    { 1.3f @Font intersection            }
  798. X   def bcup    { 1.3f @Font union                }
  799. X   def bvee    { 1.3f @Font logicalor                }
  800. X   def bwedge    { 1.3f @Font logicaland                }
  801. X   def bodot    { & 1.3f @Font @HContract { circle /0io &0.5rt dotmath } }
  802. X   def botimes    { 1.3f @Font circlemultiply            }
  803. X   def boplus    { 1.3f @Font circleplus                }
  804. X   def buplus    { & 1.3f @Font @HContract { &0.5rt 0.7f @Font plus ^/0.2fo union } }
  805. X
  806. X   ###################################################################
  807. X   #                                                                 #
  808. X   #   Group 7 (binary operations)                                   #
  809. X   #                                                                 #
  810. X   #   All of Knuth's symbols are available except \star, \diamond   #
  811. X   #   and \bullet; a few have been given more mnemonic names.       #
  812. X   #                                                                 #
  813. X   ###################################################################
  814. X
  815. X   def "+"        { bin plus                }
  816. X   def "-"        { bin minus                }
  817. X   def "+-"        { bin plusminus                }
  818. X   def "-+"        { bin 180d @Rotate plusminus        }
  819. X   def setminus        { bin backslash                }
  820. X   def cdot        { bin dotmath                }
  821. X   def times        { bin multiply                }
  822. X   def "*"        { bin asteriskmath            }
  823. X  #def diamond        { name used above            }
  824. X   def circ        { bin circle                }
  825. X  #def bullet        { name used above            }
  826. X   def div        { bin divide                }
  827. X   def cap        { bin intersection            }
  828. X   def cup        { bin union                }
  829. X   def uplus        { bin @OneRow @HContract { &0.5rt 0.7f @Font plus ^/0.2fo union}}
  830. X   def sqcap        { bin
  831. X              { @HContract @VContract
  832. X                {    "0 0 moveto 0 ysize lineto xsize ysize lineto"
  833. X                "xsize 0 lineto"
  834. X                "0.04 ft setlinewidth stroke"
  835. X                }
  836. X                @Graphic
  837. X                {    0.3f @Wide 0.3f @High ^| ^/
  838. X                0.3f @Wide 0.3f @High
  839. X                }
  840. X              }
  841. X            }
  842. X   def sqcup        { 180d @Rotate sqcap            }
  843. X   def triangleleft    { bin 90d @Rotate 0.8f @Font triangle    }
  844. X   def triangleright    { bin "-90d" @Rotate 0.8f @Font triangle}
  845. X   def wr        { bin vctr {90d @Rotate similar}    }
  846. X   def bigcirc        { bin 1.2f @Font circle            }
  847. X   def bigtriangleup    { bin 1.2f @Font triangle        }
  848. X   def bigtriangledown    { bin 180d @Rotate 1.2f @Font triangle    }
  849. X   def vee        { bin logicalor                }
  850. X   def wedge        { bin logicaland            }
  851. X   def oplus        { bin circleplus            }
  852. X   def ominus        { bin @OneRow @HContract { circle /0io &0.5rt minus}}
  853. X   def otimes        { bin circlemultiply            }
  854. X   def oslash        {`vctr 60d @Rotate @HContract {circle/0io &0.5rt minus`}}
  855. X   def odot        { bin @OneRow @HContract {circle/0io &0.5rt dotmath}}
  856. X   def dagger        { bin @Base "\262"            }
  857. X   def daggerdbl    { bin @Base "\263"            }
  858. X   def amalg        { bin 180d @Rotate vctr product        }
  859. X
  860. X   ###################################################################
  861. X   #                                                                 #
  862. X   #   Group 8 (relations)                                           #
  863. X   #                                                                 #
  864. X   #   All Knuth's operators are available, but many have been       #
  865. X   #   given different, more mnemonic names.  Also included is       #
  866. X   #   a not operator for negating the relations.                    #
  867. X   #                                                                 #
  868. X   ###################################################################
  869. X
  870. X   def "<"        { rel less                }
  871. X   def ">"        { rel greater                }
  872. X   def "="        { rel equal                }
  873. X   def "<="        { rel lessequal                }
  874. X   def prec        { rel { 0.45f @Font "-90d" @Rotate
  875. X                { parenrighttp ^| parenlefttp }
  876. X                  }
  877. X            }
  878. X   def preceq        { rel { @OneRow non prec /0.1f minus }    }
  879. X   def "<<"        { rel {less less}            }
  880. X   def subset        { rel propersubset            }
  881. X   def subseteq        { rel reflexsubset            }
  882. X   def sqsubseteq    { rel @HContract @VContract
  883. X              {    { "xsize 0 moveto"
  884. X                  "0 0 lineto"
  885. X                  "0 ysize lineto"
  886. X                  "xsize ysize lineto"
  887. X                  "0.04 ft setlinewidth stroke"
  888. X                }
  889. X                @Graphic
  890. X                { 0.5f @Wide 0.25f @High ^/
  891. X                  0.25f @High
  892. X                }
  893. X                /0.1f minus
  894. X              }
  895. X            }
  896. X
  897. X   def in        { rel element                }
  898. X   def vdash        { rel vctr{"-90d" @Rotate perpendicular}}
  899. X   def smile        { rel vctr 90d @Rotate parenleft    }
  900. X   def frown        { rel vctr 90d @Rotate parenright    }
  901. X
  902. X   def ">="        { rel greaterequal            }
  903. X   def succ        { rel { 0.45f @Font 90d @Rotate
  904. X                    { parenrighttp ^| parenlefttp }
  905. X                  }
  906. X            }
  907. X   def succeq        { rel { @OneRow non succ /0.1f minus }    }
  908. X   def ">>"        { rel {greater greater}            }
  909. X   def supset        { rel propersuperset            }
  910. X   def supseteq        { rel reflexsuperset            }
  911. X   def sqsupseteq    { rel @HContract @VContract
  912. X              {    { "0 0 moveto xsize 0 lineto"
  913. X                  "xsize ysize lineto"
  914. X                  "0 ysize lineto"
  915. X                  "0.04 ft setlinewidth stroke"
  916. X                }
  917. X                @Graphic
  918. X                { 0.5f @Wide 0.25f @High ^/
  919. X                  0.25f @High
  920. X                }
  921. X                /0.1f minus
  922. X              }
  923. X            }
  924. X   def ni        { rel 180d @Rotate element        }
  925. X   def dashv        { rel vctr {90d @Rotate perpendicular}    }
  926. X   def mid        { rel @Base "|"                }
  927. X   def parallel        { rel @Base "||"            }
  928. X
  929. X   def "=="        { rel equivalence            }
  930. X   def "~"        { rel similar                }
  931. X   def "-~"        { rel @OneRow{similar^/0.07f/0.07f minus}}
  932. X   def asymp        { rel 0.7f @Font @OneRow
  933. X                  { 90d @Rotate parenleft ^/0.008f
  934. X                  /0.008f 90d @Rotate parenright }
  935. X            }
  936. X   def "~~"        { rel approxequal            }
  937. X   def "=~"        { rel congruent                }
  938. X   def bowtie        { rel{non triangleright non triangleleft}}
  939. X   def propto        { rel proportional            }
  940. X   def models        { rel{@Base vctr "|" &0.05fo vctr equal}}
  941. X   def doteq        { rel @OneRow @HContract {&0.5rt dotmath^/0.15f equal}}
  942. X   def perp        { rel perpendicular            }
  943. X
  944. X   def notsub        { rel notsubset                }
  945. X   def notin        { rel notelement            }
  946. X   def "!="        { rel notequal                }
  947. X
  948. X   def "<->"        { rel arrowboth                }
  949. X   def "<--"        { rel arrowleft                }
  950. X   def "-->"        { rel arrowright            }
  951. X   def up        { rel arrowup                }
  952. X   def down        { rel arrowdown                }
  953. X   def "<=>"        { rel arrowdblboth            }
  954. X   def "<=="        { rel arrowdblleft            }
  955. X   def "==>"        { rel arrowdblright            }
  956. X   def dblup        { rel arrowdblup            }
  957. X   def dbldown        { rel arrowdbldown            }
  958. X
  959. X   def ":"        { rel colon                }
  960. X   def "::"        { rel @OneCol {colon ` colon}        }
  961. X   def ":="        { rel { colon{ //0.05fo equal} }    }
  962. X
  963. X   def not right x    { @HContract {@OneCol x /0co &0.5rt slash}}
  964. X
  965. X
  966. X   ###################################################################
  967. X   #                                                                 #
  968. X   #   Groups 11 and 12 - openings and closings.                     #
  969. X   #                                                                 #
  970. X   ###################################################################
  971. X
  972. X   def lpar    { parenleft        }
  973. X   def rpar    { parenright        }
  974. X   def lbrack    { bracketleft        }
  975. X   def rbrack    { bracketright        }
  976. X   def lbrace    { braceleft        }
  977. X   def rbrace    { braceright        }
  978. X   def lfloor    { bracketleftbt        }
  979. X   def rfloor    { bracketrightbt    }
  980. X   def lceil    { bracketlefttp        }
  981. X   def rceil    { bracketrighttp    }
  982. X   def langle    { angleleft        }
  983. X   def rangle    { angleright        }
  984. X
  985. X   def blpar    { @OneRow {parenlefttp    ^/ parenleftex    / parenleftbt   } }
  986. X   def brpar    { @OneRow {parenrighttp   ^/ parenrightex   / parenrightbt  } }
  987. X   def blbrack    { @OneRow {bracketlefttp  ^/ bracketleftex  / bracketleftbt } }
  988. X   def brbrack    { @OneRow {bracketrighttp ^/ bracketrightex / bracketrightbt} }
  989. X   def blbrace    { @OneRow {bracelefttp    ^/ braceleftmid   / braceleftbt   } }
  990. X   def brbrace    { @OneRow {bracerighttp   ^/ bracerightmid  / bracerightbt  } }
  991. X   def blfloor    { @OneRow {bracketleftex  ^/ bracketleftex  / bracketleftbt } }
  992. X   def brfloor    { @OneRow {bracketrightex ^/ bracketrightex / bracketrightbt} }
  993. X   def blceil    { @OneRow {bracketlefttp  ^/ bracketleftex  / bracketleftex } }
  994. X   def brceil    { @OneRow {bracketrighttp ^/ bracketrightex / bracketrightex} }
  995. X   def blangle    { @HContract @VContract
  996. X          { "xsize 0 moveto"
  997. X            "0 ysize 2 div lineto"
  998. X            "xsize ysize lineto"
  999. X            "0.04 ft setlinewidth stroke"
  1000. X              }
  1001. X              @Graphic { 0.5f @Wide 2f @High ^/ 2f @High }
  1002. X        }
  1003. X   def brangle    { @HContract @VContract
  1004. X          { "0 0 moveto"
  1005. X            "xsize ysize 2 div lineto"
  1006. X            "0 ysize lineto"
  1007. X            "0.04 ft setlinewidth stroke"
  1008. X              }
  1009. X              @Graphic { 0.5f @Wide 2f @High ^/ 2f @High }
  1010. X        }
  1011. X
  1012. X
  1013. X   ###################################################################
  1014. X   #                                                                 #
  1015. X   #   Group 13 - punctuation.                                       #
  1016. X   #                                                                 #
  1017. X   ###################################################################
  1018. X
  1019. X   def ";"     { punct semicolon     }
  1020. X   def ","     { punct comma         }
  1021. X   def col     { punct colon         }
  1022. X
  1023. X
  1024. X   ###################################################################
  1025. X   #                                                                 #
  1026. X   #   Additional short symbols (Knuth p. 132)                       #
  1027. X   #                                                                 #
  1028. X   ###################################################################
  1029. X
  1030. X   def "!" { exclam          }
  1031. X   def "?" { question        }
  1032. X   def "%" { percent         }
  1033. X   def "(" { parenleft       }
  1034. X   def ")" { parenright      }
  1035. X   def "[" { bracketleft     }
  1036. X   def "]" { bracketright    }
  1037. X
  1038. X
  1039. X   ###################################################################
  1040. X   #                                                                 #
  1041. X   #   Common mathematical functions (from Knuth p. 162).            #
  1042. X   #   mod is included, since @Rel mod is easily typed if needed.    #
  1043. X   #                                                                 #
  1044. X   ###################################################################
  1045. X
  1046. X   def arccos    { @Base "arccos"    }
  1047. X   def arcsin    { @Base "arcsin"    }
  1048. X   def arctan    { @Base "arctan"    }
  1049. X   def arg    { @Base "arg"        }
  1050. X   def cos    { @Base "cos"        }
  1051. X   def cosh    { @Base "cosh"        }
  1052. X   def cot    { @Base "cot"        }
  1053. X   def coth    { @Base "coth"        }
  1054. X   def csc    { @Base "csc"        }
  1055. X   def deg    { @Base "deg"        }
  1056. X   def det    { @Base "det"        }
  1057. X   def dim    { @Base "dim"        }
  1058. X   def exp    { @Base "exp"        }
  1059. X   def gcd    { @Base "gcd"        }
  1060. X   def hom    { @Base "hom"        }
  1061. X   def inf    { @Base "inf"        }
  1062. X   def ker    { @Base "ker"        }
  1063. X   def lg    { @Base "lg"        }
  1064. X   def lim    { @Base "lim"        }
  1065. X   def liminf    { @OneCol { @Base "lim" ` @Base "inf" }    }
  1066. X   def limsup    { @OneCol { @Base "lim" ` @Base "sup" }    }
  1067. X   def ln    { @Base "ln"        }
  1068. X   def log    { @Base "log"        }
  1069. X   def max    { @Base "max"        }
  1070. X   def min    { @Base "min"        }
  1071. X   def Pr    { @Base "Pr"        }
  1072. X   def sec    { @Base "sec"        }
  1073. X   def sin    { @Base "sin"        }
  1074. X   def sinh    { @Base "sinh"        }
  1075. X   def supr    { @Base "sup"        }
  1076. X   def tan    { @Base "tan"        }
  1077. X   def tanh    { @Base "tanh"        }
  1078. X   def mod    { @Base "mod"        }
  1079. X
  1080. X
  1081. X   ###################################################################
  1082. X   #                                                                 #
  1083. X   #   Other symbols taken from TeX.                                 #
  1084. X   #                                                                 #
  1085. X   ###################################################################
  1086. X
  1087. X   def ldots { .       &0.3f .       &0.3f .            }
  1088. X   def cdots { dotmath &0.3f dotmath &0.3f dotmath        }
  1089. X   def vdots { @OneRow { dotmath ^/0.3f dotmath /0.3f dotmath } }
  1090. X   def ddots { @OneCol @OneRow
  1091. X           {        dotmath
  1092. X             ^/0.3f |0.3f dotmath
  1093. X                  /0.3f |     |0.3f dotmath
  1094. X           }
  1095. X         }
  1096. X
  1097. X
  1098. X   ###################################################################
  1099. X   #                                                                 #
  1100. X   #   Symbols taken from eqn (Kernighan and Cherry 1975).           #
  1101. X   #                                                                 #
  1102. X   ###################################################################
  1103. X
  1104. X   def del    { gradient        }
  1105. X   def grad    { gradient        }
  1106. X   def "..."    { ellipsis        }
  1107. X   def ",...,"    { , ellipsis ``` ,    }
  1108. X   def "'"    { minute        }
  1109. X   def empty    { emptyset        }
  1110. X
  1111. X
  1112. X
  1113. X   ###################################################################
  1114. X   #                                                                 #
  1115. X   #   Symbols with parameters.                                      #
  1116. X   #                                                                 #
  1117. X   #   These symbols are essentially those of eqn, with some         #
  1118. X   #   changes and additions.                                        #
  1119. X   #                                                                 #
  1120. X   ###################################################################
  1121. X
  1122. X   def sup
  1123. X      precedence 60
  1124. X      associativity left
  1125. X      left x
  1126. X      named gap { @SupGap }
  1127. X      right y
  1128. X   {  @HContract @VContract
  1129. X      {          | @Smaller y
  1130. X    ^/gap  x
  1131. X      }
  1132. X   }
  1133. X
  1134. X   def sub
  1135. X      precedence 60
  1136. X      associativity left
  1137. X      left x
  1138. X      named gap { @SupGap }
  1139. X      right y
  1140. X   {  @HContract @VContract
  1141. X      {
  1142. X          x
  1143. X     /gap    |  @Smaller y
  1144. X      }
  1145. X   }
  1146. X
  1147. X   def supp
  1148. X      precedence 60
  1149. X      associativity left
  1150. X      left x
  1151. X      named gap { @SupGap }
  1152. X      right y
  1153. X   {  @HContract @VContract
  1154. X      { { ^/gap x /gap } |  @Smaller y
  1155. X      }
  1156. X   }
  1157. X
  1158. X   def on
  1159. X      precedence 61
  1160. X      associativity left
  1161. X      left x
  1162. X      named gap { @SupGap }
  1163. X      right y
  1164. X   {  x ^/  / y 
  1165. X   }
  1166. X
  1167. X   def frac
  1168. X      precedence 54
  1169. X      associativity left
  1170. X      left x
  1171. X      named gap { 0ik }
  1172. X      right y
  1173. X   {  @HContract @VContract @Smaller
  1174. X      { x ^/gap | fraction /gap | | y }
  1175. X   }
  1176. X
  1177. X   def half { 1 frac 2 }
  1178. X   def third { 1 frac 3 }
  1179. X
  1180. X   def over
  1181. X      precedence 54
  1182. X      associativity left
  1183. X      left x
  1184. X      named gap { 0.2f }
  1185. X      right y
  1186. X   {  
  1187. X      @HContract @VContract
  1188. X      {          |0.5rt @OneCol x
  1189. X    ^//gap   @HLine
  1190. X     //gap   |0.5rt @OneCol y
  1191. X      }
  1192. X   }
  1193. X
  1194. X   def from
  1195. X      precedence 58
  1196. X      associativity left
  1197. X      left x
  1198. X      named gap { @ThinGap  }
  1199. X      named skew { 0c }
  1200. X      right y
  1201. X   {  
  1202. X      @HContract @VContract
  1203. X      {          |0.5rt x
  1204. X     //gap   |0.5rt &skew @Smaller y
  1205. X      }
  1206. X   }
  1207. X
  1208. X   def to
  1209. X      precedence 58
  1210. X      associativity left
  1211. X      left x
  1212. X      named gap { @ThinGap  }
  1213. X      named skew { 0c }
  1214. X      right y
  1215. X   {
  1216. X      @HContract @VContract
  1217. X      {          |0.5rt &skew @Smaller y
  1218. X    ^//gap   |0.5rt x
  1219. X      }
  1220. X   }
  1221. X
  1222. X   def widefrom
  1223. X      precedence 58
  1224. X      associativity left
  1225. X      left x
  1226. X      named gap { @ThinGap  }
  1227. X      right y
  1228. X   {
  1229. X      @HContract @VContract
  1230. X      {  x //gap @HScale y
  1231. X      }
  1232. X   }
  1233. X
  1234. X   def wideto
  1235. X      precedence 58
  1236. X      associativity left
  1237. X      left x
  1238. X      named gap { @ThinGap  }
  1239. X      right y
  1240. X   {
  1241. X      @HContract @VContract
  1242. X      { @HScale y ^//gap x
  1243. X      }
  1244. X   }
  1245. X
  1246. X   def dot
  1247. X      precedence 62
  1248. X      left x
  1249. X      named gap { @ThinGap }
  1250. X   {  x to gap { gap } skew { @SkewGap } .
  1251. X   }
  1252. X
  1253. X   def dotdot
  1254. X      precedence 62
  1255. X      left x
  1256. X      named gap { @ThinGap }
  1257. X   {  x to gap { gap } skew { @SkewGap } ..
  1258. X   }
  1259. X
  1260. X   def hat
  1261. X      precedence 62
  1262. X      left x
  1263. X      named gap { @ThinGap }
  1264. X   {  x to gap { gap } skew { @SkewGap } @Base "^"
  1265. X   }
  1266. X
  1267. X   def tilde
  1268. X      precedence 62
  1269. X      left x
  1270. X      named gap { @ThinGap }
  1271. X   {  x to gap { gap } skew { @SkewGap } @Base "~"
  1272. X   }
  1273. X
  1274. X   def vec
  1275. X      precedence 62
  1276. X      left x
  1277. X      named gap { @ThinGap }
  1278. X   {  x to gap { gap } skew { @SkewGap } arrowright
  1279. X   }
  1280. X
  1281. X   def dyad
  1282. X      precedence 62
  1283. X      left x
  1284. X      named gap { @ThinGap }
  1285. X   {  x to gap { gap } skew { @SkewGap } arrowboth
  1286. X   }
  1287. X
  1288. X   def overbar
  1289. X      precedence 62
  1290. X      left x
  1291. X      named gap { @ThinGap }
  1292. X   {  x wideto gap { gap } minus
  1293. X   }
  1294. X
  1295. X   def underbar
  1296. X      precedence 62
  1297. X      left x
  1298. X      named gap { @ThinGap }
  1299. X   {  x widefrom gap { gap } minus
  1300. X   }
  1301. X
  1302. X   def sqrt
  1303. X      precedence 56
  1304. X      named gap { @ThinGap }
  1305. X      right x
  1306. X   {
  1307. X      @HContract @VContract
  1308. X      { @VScale surd | @OneRow
  1309. X    { @HLine line { "0.03 ft setlinewidth 2 setlinecap" }
  1310. X      ^//gap  |gap  x //gap
  1311. X    }
  1312. X      }
  1313. X   }
  1314. X
  1315. X   def root
  1316. X      precedence 56
  1317. X      left x
  1318. X      right y
  1319. X   { "" sup x &0io sqrt y
  1320. X   }
  1321. X
  1322. X   def above
  1323. X      precedence 52
  1324. X      left x
  1325. X      named gap { @RowGap }
  1326. X      right y
  1327. X   {  |0.5rt x //gap |0.5rt y
  1328. X   }
  1329. X
  1330. X   def labove
  1331. X      precedence 52
  1332. X      left x
  1333. X      named gap { @RowGap }
  1334. X      right y
  1335. X   {  x //gap y
  1336. X   }
  1337. X
  1338. X   def cabove
  1339. X      precedence 52
  1340. X      left x
  1341. X      named gap { @RowGap }
  1342. X      right y
  1343. X   {  |0.5rt x //gap |0.5rt y
  1344. X   }
  1345. X
  1346. X   def rabove
  1347. X      precedence 52
  1348. X      left x
  1349. X      named gap { @RowGap }
  1350. X      right y
  1351. X   {  |1rt x //gap |1rt y
  1352. X   }
  1353. X
  1354. X   def mabove
  1355. X      precedence 52
  1356. X      left x
  1357. X      named gap { @RowGap }
  1358. X      right y
  1359. X   {  x /gap y
  1360. X   }
  1361. X
  1362. X   def nextcol
  1363. X      precedence 50
  1364. X      left x
  1365. X      named gap { @ColGap }
  1366. X      right y
  1367. X   { x |gap y
  1368. X   }
  1369. X
  1370. X   def matrix
  1371. X      precedence 100
  1372. X      named gap { @MedGap }
  1373. X      named atleft {}
  1374. X      named atright {}
  1375. X      right x
  1376. X   { vctr @HContract @VContract
  1377. X     {  @VScale atleft
  1378. X    ||@ThinGap  { //gap x //gap } ||@ThinGap
  1379. X    @VScale atright
  1380. X     }
  1381. X   }
  1382. X
  1383. X   Slope @Font 1.2f @Break 0c @Space @Body
  1384. X
  1385. X@End @Eq                  
  1386. END_OF_FILE
  1387.   if test 35135 -ne `wc -c <'lout/include/eq'`; then
  1388.     echo shar: \"'lout/include/eq'\" unpacked with wrong size!
  1389.   fi
  1390.   # end of 'lout/include/eq'
  1391. fi
  1392. if test -f 'lout/z36.c' -a "${1}" != "-c" ; then 
  1393.   echo shar: Will not clobber existing file \"'lout/z36.c'\"
  1394. else
  1395.   echo shar: Extracting \"'lout/z36.c'\" \(31731 characters\)
  1396.   sed "s/^X//" >'lout/z36.c' <<'END_OF_FILE'
  1397. X/*@z36.c:Hyphenation: Hyphenate()@********************************************/
  1398. X/*                                                                           */
  1399. X/*  LOUT: A HIGH-LEVEL LANGUAGE FOR DOCUMENT FORMATTING (VERSION 2.03)       */
  1400. X/*  COPYRIGHT (C) 1993 Jeffrey H. Kingston                                   */
  1401. X/*                                                                           */
  1402. X/*  Jeffrey H. Kingston (jeff@cs.su.oz.au)                                   */
  1403. X/*  Basser Department of Computer Science                                    */
  1404. X/*  The University of Sydney 2006                                            */
  1405. X/*  AUSTRALIA                                                                */
  1406. X/*                                                                           */
  1407. X/*  This program is free software; you can redistribute it and/or modify     */
  1408. X/*  it under the terms of the GNU General Public License as published by     */
  1409. X/*  the Free Software Foundation; either version 1, or (at your option)      */
  1410. X/*  any later version.                                                       */
  1411. X/*                                                                           */
  1412. X/*  This program is distributed in the hope that it will be useful,          */
  1413. X/*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
  1414. X/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
  1415. X/*  GNU General Public License for more details.                             */
  1416. X/*                                                                           */
  1417. X/*  You should have received a copy of the GNU General Public License        */
  1418. X/*  along with this program; if not, write to the Free Software              */
  1419. X/*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
  1420. X/*                                                                           */
  1421. X/*  FILE:         z36.c                                                      */
  1422. X/*  MODULE:       Hyphenation                                                */
  1423. X/*  EXTERNS:      Hyphenate()                                                */
  1424. X/*                                                                           */
  1425. X/*****************************************************************************/
  1426. X#include "externs"
  1427. X#define MAX_CHAR    256        /* max chars represented in one char */
  1428. X#define TRIE_MAGIC    5361534
  1429. X#define KILL_CLASS    0        /* characters which prevent hyphen'n */
  1430. X#define PUNCT_CLASS    1        /* characters which delimit hyphen'n */
  1431. X
  1432. Xtypedef struct trie_rec
  1433. X{ int    magic;                /* a magic number to make sure ok    */
  1434. X  int    class_count;            /* the number of character classes   */
  1435. X  unsigned char    class[MAX_CHAR];    /* the character classes             */
  1436. X  short    *node_mem;            /* the node memory                   */
  1437. X  int    node_lim;            /* top of node memory                */
  1438. X  int    node_free;            /* first free space in node memory   */
  1439. X  unsigned char    *string_mem;        /* the string memory                 */
  1440. X  int    string_lim;            /* top of string memory              */
  1441. X  int    string_first;            /* the first (last inserted) string  */
  1442. X} *TRIE;
  1443. X
  1444. X
  1445. X#ifdef DEBUG_ON
  1446. X/*****************************************************************************/
  1447. X/*                                                                           */
  1448. X/*  findrep(i, T)     Returns one character whose class in T is i.           */
  1449. X/*                                                                           */
  1450. X/*****************************************************************************/
  1451. X
  1452. Xstatic unsigned char findrep(i, T)
  1453. Xint i;  TRIE T;
  1454. X{ int ch;
  1455. X  for( ch = 0;  ch < MAX_CHAR;  ch++ )  if( T->class[ch] == i )  return ch;
  1456. X  Error(INTERN, no_fpos, "hyph DoTriePrint: findrep failed");
  1457. X} /* end findrep */
  1458. X#endif
  1459. X
  1460. X
  1461. X/*****************************************************************************/
  1462. X/*                                                                           */
  1463. X/*  TRIE T                                                                   */
  1464. X/*                                                                           */
  1465. X/*  The packed hyphenation table, or NULL if not yet read in.                */
  1466. X/*                                                                           */
  1467. X/*****************************************************************************/
  1468. X
  1469. Xstatic TRIE    T = (TRIE) NULL;    /* the compressed hyphenation table  */
  1470. X
  1471. X/*@@**************************************************************************/
  1472. X/*                                                                           */
  1473. X/*  TRIE NewTrie(node_lim, string_lim)                                       */
  1474. X/*                                                                           */
  1475. X/*  Initialize a new trie with the given amount of space for nodes and       */
  1476. X/*  strings.                                                                 */
  1477. X/*                                                                           */
  1478. X/*****************************************************************************/
  1479. X
  1480. Xstatic TRIE NewTrie(node_lim, string_lim)
  1481. Xint node_lim, string_lim;
  1482. X{ TRIE T;  int i;  char *malloc();
  1483. X  debug2(DHY, D, "NewTrie(%d, %d)", node_lim, string_lim);
  1484. X  T = (TRIE) malloc( sizeof(struct trie_rec)
  1485. X             + node_lim*sizeof(short) + string_lim*sizeof(char));
  1486. X  T->magic = TRIE_MAGIC;  T->class_count = 1;
  1487. X  for( i = 0;  i < MAX_CHAR;  i++ )  T->class[i] = 0;
  1488. X  T->node_mem = (short *) ( (char *) T + sizeof(struct trie_rec));
  1489. X  T->node_lim = node_lim;  T->node_free = 0;
  1490. X  T->string_mem = (unsigned char *) &(T->node_mem[node_lim]);
  1491. X  T->string_lim = T->string_first = string_lim;
  1492. X  debug0(DHY, D, "NewTrie returning.");
  1493. X  return T;
  1494. X} /* end NewTrie */
  1495. X
  1496. X
  1497. X/*****************************************************************************/
  1498. X/*                                                                           */
  1499. X/*  ClassConvert(in, out, T)                                                 */
  1500. X/*                                                                           */
  1501. X/*  Set out[i] to the character class of in[i] in T, for all i.              */
  1502. X/*                                                                           */
  1503. X/*****************************************************************************/
  1504. X
  1505. X#define ClassConvert(in, out, T)                    \
  1506. X{ int i;                                \
  1507. X  for( i = 0;  in[i] != '\0';  i++ )                    \
  1508. X    if( T->class[in[i]] != 0 )  out[i] = T->class[in[i]];        \
  1509. X    else Error(INTERN, no_fpos, "hyph: \"%s\" has illegal class", in);    \
  1510. X  out[i] = '\0';                            \
  1511. X} /* end ClassConvert */
  1512. X
  1513. X
  1514. X/*****************************************************************************/
  1515. X/*                                                                           */
  1516. X/*  short NewTrieString(str, T)                                              */
  1517. X/*                                                                           */
  1518. X/*  Copy a new string into T, and return its offset in string_mem;           */
  1519. X/*                                                                           */
  1520. X/*****************************************************************************/
  1521. X
  1522. Xstatic short NewTrieString(str, T)
  1523. Xunsigned char *str;  TRIE T;
  1524. X{ int i;  short res = T->string_first - strlen(str) - 1;
  1525. X  if( res < 0 )  Error(INTERN, no_fpos, "hyph: trie string limit exceeded");
  1526. X  T->string_first = res;  strcpy(&(T->string_mem[res]), str);
  1527. X  return res;
  1528. X} /* end NewTrieString */
  1529. X
  1530. X
  1531. X/*****************************************************************************/
  1532. X/*                                                                           */
  1533. X/*  int NewTrieNode(T)                                                       */
  1534. X/*                                                                           */
  1535. X/*  Allocate a new empty trie node in T, and return its offset in node_mem.  */
  1536. X/*                                                                           */
  1537. X/*****************************************************************************/
  1538. X
  1539. Xstatic int NewTrieNode(T)
  1540. XTRIE T;
  1541. X{ int i;  int res;
  1542. X  if( T->node_free + T->class_count > T->node_lim )
  1543. X    Error(INTERN, no_fpos, "hyph: trie node limit exceeded");
  1544. X  res = T->node_free;  T->node_free += T->class_count;
  1545. X  for( i = res;  i < T->node_free;  i++ )  T->node_mem[i] = 0;
  1546. X  return res;
  1547. X} /* end NewTrieNode */
  1548. X
  1549. X
  1550. X/*@@**************************************************************************/
  1551. X/*                                                                           */
  1552. X/*  AddClassToTrie(str, T)                                                   */
  1553. X/*                                                                           */
  1554. X/*  Add a new character class, whose members are the characters of str, to   */
  1555. X/*  trie T.  This cannot occur after the first insertion.                    */
  1556. X/*                                                                           */
  1557. X/*****************************************************************************/
  1558. X
  1559. Xstatic AddClassToTrie(str, T)
  1560. Xunsigned char *str; TRIE T;
  1561. X{ int i;
  1562. X  if( T->string_first != T-> string_lim )
  1563. X    Error(INTERN, no_fpos, "hyph AddClassToTrie after first insertion!");
  1564. X  for( i = 0;  str[i] != '\0';  i++ )
  1565. X    if( T->class[str[i]] == 0 ) T->class[str[i]] = T->class_count;
  1566. X    else Error(INTERN,no_fpos, "hyph: class of %c may not be changed!", str[i]);
  1567. X  T->class_count++;
  1568. X} /* end AddClassToTrie */
  1569. X
  1570. X
  1571. X/*****************************************************************************/
  1572. X/*                                                                           */
  1573. X/*  TrieInsert(key, value, T)                                                */
  1574. X/*                                                                           */
  1575. X/*  Insert a new key and value into trie T.                                  */
  1576. X/*                                                                           */
  1577. X/*****************************************************************************/
  1578. X
  1579. XTrieInsert(key, value, T)
  1580. Xunsigned char *key, *value;  TRIE T;
  1581. X{ unsigned char str[MAX_LINE];  int i, curr_node, next_node, pos, ch;
  1582. X  debug2(DHY, D, "TrieInsert(%s, %s, T)", key, value);
  1583. X
  1584. X  /* if first insertion, add one node after making sure class_count is even */
  1585. X  if( T->node_free == 0 )
  1586. X  { T->class_count = 2 * ceiling(T->class_count, 2);
  1587. X    ch = NewTrieNode(T);
  1588. X  }
  1589. X
  1590. X  /* invariant: curr_node is an existing node of T with prefix str[0..i-1] */
  1591. X  ClassConvert(key, str, T);
  1592. X  curr_node = i = 0;
  1593. X  for(;;)
  1594. X  {
  1595. X    /* if str is ended, add value only to string memory */
  1596. X    if( str[i] == '\0' )
  1597. X    { if( T->node_mem[curr_node] != 0 )
  1598. X    Error(INTERN, no_fpos, "hyph string %s already inserted", key);
  1599. X      else T->node_mem[curr_node] = - NewTrieString(value, T);
  1600. X      debug0(DHY, D, "TrieInsert returning (empty suffix).");
  1601. X      return;
  1602. X    }
  1603. X
  1604. X    /* if next position is unoccupied, store remainder of str and value */
  1605. X    next_node = T->node_mem[curr_node + str[i]];
  1606. X    if( next_node == 0 )
  1607. X    { ch = NewTrieString(value, T);
  1608. X      T->node_mem[curr_node + str[i]] = - NewTrieString(&str[i+1], T);
  1609. X      debug0(DHY, D, "TrieInsert returning (non-empty suffix).");
  1610. X      return;
  1611. X    }
  1612. X
  1613. X    /* if next position is occupied by a non-empty string, move that */
  1614. X    /* string down one level and replace it by a trie node           */
  1615. X    if( next_node < 0 )
  1616. X    { pos = - next_node;
  1617. X      ch = T->string_mem[pos];
  1618. X      if( T->string_first == pos )  T->string_first++;
  1619. X      T->node_mem[curr_node + str[i]] = next_node = NewTrieNode(T)/2;
  1620. X      T->node_mem[2*next_node + ch] = -(pos+1);
  1621. X    }
  1622. X
  1623. X    /* now next is the offset of the next node to be searched */
  1624. X    curr_node = 2*next_node;  i++;
  1625. X  }
  1626. X} /* end TrieInsert */
  1627. X
  1628. X
  1629. X/*@@**************************************************************************/
  1630. X/*                                                                           */
  1631. X/*  BeGetChar(fp, pv)                                                        */
  1632. X/*  BePutChar(fp, v)                                                         */
  1633. X/*  BeGetShort(fp, pv)                                                       */
  1634. X/*  BePutShort(fp, v)                                                        */
  1635. X/*  BeGetInt(fp, pv)                                                         */
  1636. X/*  BePutInt(fp, v)                                                          */
  1637. X/*                                                                           */
  1638. X/*  Get char, short, or int pv from file fp, and put char, short, or int     */
  1639. X/*  onto file fp.  These routines are designed so that the file can be       */
  1640. X/*  written or read safely by big-endian and little-endian architectures;    */
  1641. X/*  this is accomplished by reading and writing one byte at a time to and    */
  1642. X/*  from a big-endian format file.  All return 0 on success, -1 on failure.  */
  1643. X/*  Thanks to David W. Sanderson for this code.                              */
  1644. X/*                                                                           */
  1645. X/*****************************************************************************/
  1646. X
  1647. X#define BeGetChar(fp, pv)  ( (c = getc(fp)) == EOF ? -1 : (*pv = c & 0xFF, 0) )
  1648. X#define BePutChar(fp, v)   ( putc(v & 0xFF, fp), 0 )
  1649. X
  1650. X#define BeGetShort(fp, pv)                        \
  1651. X(  (c = getc(fp)) == EOF ? -1 :                        \
  1652. X   (  *pv = (c & 0xFF) << 8,                        \
  1653. X      (c = getc(fp)) == EOF ? -1 : (*pv |= c & 0xFF, 0)            \
  1654. X   )                                    \
  1655. X)
  1656. X
  1657. X#define BePutShort(fp, v)                        \
  1658. X( putc((v >> 8) & 0xFF, fp), putc(v & 0xFF, fp), 0 )
  1659. X
  1660. Xint BeGetInt(fp, pv)
  1661. XFILE *fp; int *pv;
  1662. X{ int c;
  1663. X  if ((c = getc(fp)) == EOF) return -1;
  1664. X  *pv = (c & 0xFF) << 24;
  1665. X  if ((c = getc(fp)) == EOF) return -1;
  1666. X  *pv |= (c & 0xFF) << 16;
  1667. X  if ((c = getc(fp)) == EOF) return -1;
  1668. X  *pv |= (c & 0xFF) << 8;
  1669. X  if ((c = getc(fp)) == EOF) return -1;
  1670. X  *pv |= c & 0xFF;
  1671. X  return 0;
  1672. X}
  1673. X
  1674. Xint BePutInt(fp, v)
  1675. XFILE *fp; int v;
  1676. X{
  1677. X  putc((v >> 24) & 0xFF, fp);
  1678. X  putc((v >> 16) & 0xFF, fp);
  1679. X  putc((v >> 8) & 0xFF, fp);
  1680. X  putc(v & 0xFF, fp);
  1681. X  return 0;
  1682. X}
  1683. X
  1684. X
  1685. X/*@@**************************************************************************/
  1686. X/*                                                                           */
  1687. X/*  TRIE TrieRead()                                                          */
  1688. X/*                                                                           */
  1689. X/*  Read in a packed trie if possible, otherwise pack an unpacked one.       */
  1690. X/*                                                                           */
  1691. X/*****************************************************************************/
  1692. X
  1693. XTRIE TrieRead()
  1694. X{ TRIE T;  FILE_NUM unpacked_fnum, packed_fnum;
  1695. X  FILE *unpacked_fp, *packed_fp;  int len, prev, i, j, c;
  1696. X  char *malloc();
  1697. X  debug0(DHY, D, "TrieRead()");
  1698. X
  1699. X  /* open file, using name stored in file handler */
  1700. X  packed_fnum = FirstFile(HYPH_PACKED_FILE);
  1701. X  assert( packed_fnum != NO_FILE, "TrieRead: packed_fnum!" );
  1702. X  packed_fp = OpenFile(packed_fnum, FALSE);
  1703. X  if( packed_fp == NULL )
  1704. X  {
  1705. X    /* no packed file, so open unpacked one instead */
  1706. X    unsigned char str[MAX_LINE], key[MAX_LINE], value[MAX_LINE],
  1707. X          buff[MAX_LINE+10];
  1708. X    unpacked_fnum = FirstFile(HYPH_FILE);
  1709. X    assert( unpacked_fnum != NO_FILE, "TrieRead: unpacked unpacked_fnum!" );
  1710. X    unpacked_fp = OpenFile(unpacked_fnum, FALSE);
  1711. X    if( unpacked_fp == NULL )
  1712. X    { Error(WARN, no_fpos, "cannot open hyphenation file %s",
  1713. X    FileName(unpacked_fnum));
  1714. X      return (TRIE) NULL;
  1715. X    }
  1716. X
  1717. X    /* read in unpacked hyphenation trie from unpacked_fp and compress it */
  1718. X    T = NewTrie(60000, 32767);
  1719. X    while( fgets(str, MAX_LINE, unpacked_fp) != NULL && str[0] != '\n' )
  1720. X    { str[strlen(str)-1] = '\0';
  1721. X      debug1(DHY, D, "adding class %s", str);
  1722. X      AddClassToTrie(str, T);
  1723. X    }
  1724. X    while( fgets(str, MAX_LINE, unpacked_fp) != NULL && str[0] != '\n' )
  1725. X    { prev = '0'; j = 0;
  1726. X      for( i = 0;  str[i] != '\n' && str[i] != '\0';  i++ )
  1727. X      { if( str[i] >= '0' && str[i] <= '9' )  prev = str[i];
  1728. X        else key[j] = str[i], value[j++] = prev, prev = '0';
  1729. X      }
  1730. X      key[j] = '\0';  value[j] = prev;  value[j+1] = '\0';
  1731. X      TrieInsert(key, value, T);
  1732. X    }
  1733. X    fclose(unpacked_fp);
  1734. X    len = CompressTrie(T);
  1735. X
  1736. X    /* write the compressed trie out to the packed file */
  1737. X    strcpy(buff, FileName(unpacked_fnum));
  1738. X    strcat(buff, HYPH_SUFFIX);
  1739. X    packed_fp = fopen(buff, "w");
  1740. X    if( packed_fp == NULL )  Error(FATAL, no_fpos,
  1741. X      "cannot write to hyphenation file %s", buff);
  1742. X    BePutInt(packed_fp, T->magic);
  1743. X    BePutInt(packed_fp, T->class_count);
  1744. X    for( i = 0; i < MAX_CHAR; i++ )  BePutChar(packed_fp, T->class[i]);
  1745. X    BePutInt(packed_fp, 0);  /* placeholder for node_mem */
  1746. X    BePutInt(packed_fp, T->node_lim);
  1747. X    BePutInt(packed_fp, T->node_free);
  1748. X    BePutInt(packed_fp, 0);  /* placeholder for string_mem */
  1749. X    BePutInt(packed_fp, T->string_lim);
  1750. X    BePutInt(packed_fp, T->string_first);
  1751. X    for( i = 0; i < T->node_free; i++ )  BePutShort(packed_fp, T->node_mem[i]);
  1752. X    for( i = 0; i < T->string_lim; i++)  BePutChar(packed_fp, T->string_mem[i]);
  1753. X    fclose(packed_fp);
  1754. X    /***OLD*VERSION*********************************************************
  1755. X    if( fwrite( (char *) T, len, 1, packed_fp) != 1 )  Error(FATAL, no_fpos,
  1756. X      "error on write to hyphenation file %s", buff);
  1757. X    ***********************************************************************/
  1758. X
  1759. X    /* now try again to open packed_fnum, the file just written */
  1760. X    packed_fp = OpenFile(packed_fnum, FALSE);
  1761. X    if( packed_fp == NULL )  Error(FATAL, no_fpos,
  1762. X      "cannot open hyphenation file %s", FileName(packed_fnum));
  1763. X  }
  1764. X
  1765. X  /* now packed hyphenation file is open, read it in */
  1766. X  fseek(packed_fp, 0L, 2);  len = (int) ftell(packed_fp);  rewind(packed_fp);
  1767. X  T = (TRIE) malloc(len);
  1768. X  /***OLD*VERSION**********************************************************
  1769. X  if( fread( (char *) T, len, 1, packed_fp) != 1 )  Error(FATAL, no_fpos,
  1770. X      "error on read of hyphenation file %s", FileName(packed_fnum));
  1771. X  ************************************************************************/
  1772. X  if( BeGetInt(packed_fp, &T->magic) != 0 )  Error(FATAL, no_fpos,
  1773. X      "error on read from packed hyphenation file %s", FileName(packed_fnum));
  1774. X  if( T->magic != TRIE_MAGIC )  Error(FATAL, no_fpos,
  1775. X      "bad magic number in hyphenation file %s", FileName(packed_fnum));
  1776. X  BeGetInt(packed_fp, &T->class_count);
  1777. X  for( i = 0; i < MAX_CHAR; i++ )  BeGetChar(packed_fp, &T->class[i]);
  1778. X  BeGetInt(packed_fp, &i);  /* placeholder for node_mem */
  1779. X  BeGetInt(packed_fp, &T->node_lim);
  1780. X  BeGetInt(packed_fp, &T->node_free);
  1781. X  BeGetInt(packed_fp, &i);  /* placeholder for string_mem */
  1782. X  BeGetInt(packed_fp, &T->string_lim);
  1783. X  BeGetInt(packed_fp, &T->string_first);
  1784. X  T->node_mem = (short *) ( (char *) T + sizeof(struct trie_rec) );
  1785. X  T->string_mem = (unsigned char *) &(T->node_mem[T->node_lim]);
  1786. X  for( i = 0; i < T->node_free; i++ )  BeGetShort(packed_fp, &T->node_mem[i]);
  1787. X  for( i = 0; i < T->string_lim; i++ ) BeGetChar(packed_fp, &T->string_mem[i]);
  1788. X
  1789. X  /* debug and exit */
  1790. X  debug0(DHY, D, "TrieRead returning, T =");
  1791. X  ifdebug(DHY, DD, TriePrint(T, stderr));
  1792. X  return T;
  1793. X} /* end TrieRead */
  1794. X
  1795. X
  1796. X/*@@**************************************************************************/
  1797. X/*                                                                           */
  1798. X/*  int CompressTrie(T)                                                      */
  1799. X/*                                                                           */
  1800. X/*  Compress trie T and return its length in characters.                     */
  1801. X/*                                                                           */
  1802. X/*****************************************************************************/
  1803. X
  1804. Xint CompressTrie(T)
  1805. XTRIE T;
  1806. X{ unsigned char *p, *q;  int len, i;
  1807. X  debug0(DHY, D, "CompressTrie(T), T =");
  1808. X  ifdebug(DHY, DD, TriePrint(T, stderr));
  1809. X  T->node_lim = T->node_free;
  1810. X  for( i = 0;  i < T->node_lim;  i++ )
  1811. X    if( T->node_mem[i] < 0 )
  1812. X      T->node_mem[i] = - ( -T->node_mem[i] - T->string_first);
  1813. X  p = (unsigned char *) &(T->node_mem[T->node_free]);
  1814. X  q = &(T->string_mem[T->string_first]);
  1815. X  len = T->string_lim - T->string_first;
  1816. X  for( i = 0;  i < len;  i++ )  *p++ = *q++;
  1817. X  T->string_mem = (unsigned char *) &(T->node_mem[T->node_lim]);
  1818. X  T->string_first = 0;
  1819. X  T->string_lim = len;
  1820. X  len = sizeof(struct trie_rec) + T->node_lim * sizeof(short)
  1821. X                + T->string_lim * sizeof(unsigned char);
  1822. X  debug1(DHY, D, "CompressTrie returning %d, T =", len);
  1823. X  ifdebug(DHY, DD, TriePrint(T, stderr));
  1824. X  return len;
  1825. X} /* end CompressTrie */
  1826. X
  1827. X
  1828. X/*****************************************************************************/
  1829. X/*                                                                           */
  1830. X/*  AccumulateRating(x, y)                                                   */
  1831. X/*                                                                           */
  1832. X/*  Accumulate the hyphenation rating string x into y.                       */
  1833. X/*                                                                           */
  1834. X/*****************************************************************************/
  1835. X
  1836. X#define AccumulateRating(x, y)                        \
  1837. X{ unsigned char *p = x, *q = y;                            \
  1838. X  while( *p )                                \
  1839. X  { if( *p > *q )  *q = *p;                        \
  1840. X    p++, q++;                                \
  1841. X  }                                    \
  1842. X} /* end AccumulateRating */
  1843. X
  1844. X
  1845. X/*@@**************************************************************************/
  1846. X/*                                                                           */
  1847. X/*  OBJECT Hyphenate(x)                                                      */
  1848. X/*                                                                           */
  1849. X/*  Hyphenate ACAT object x, returning the hyphenated result.                */
  1850. X/*                                                                           */
  1851. X/*****************************************************************************/
  1852. X
  1853. XOBJECT Hyphenate(x)
  1854. XOBJECT x;
  1855. X{ OBJECT link, y, z, next_link;
  1856. X  unsigned char str[MAX_LINE+2], rate[MAX_LINE+3],
  1857. X        *class, *key, *ss, *s, *rem, *p, *q;
  1858. X  int start, stop, i, j, curr_node, next_node, pos;
  1859. X  BOOLEAN hyphenated;  static ShowRate();
  1860. X  static BOOLEAN tried_file = FALSE;
  1861. X  assert( type(x) == ACAT, "Hyphenate: type(x) != ACAT!" );
  1862. X  debug1(DHY, DD, "Hyphenate(%s)", EchoObject(null, x));
  1863. X
  1864. X  /* if no trie is present, try to get it from a file */
  1865. X  if( T == (TRIE) NULL )
  1866. X  { if( !tried_file )  T = TrieRead();
  1867. X    tried_file = TRUE;
  1868. X    if( T == (TRIE) NULL )
  1869. X    { debug0(DHY, DD, "Hyphenate returning (no trie).");
  1870. X      return x;
  1871. X    }
  1872. X  }
  1873. X
  1874. X  /* for each word y of x, try to hyphenate it */
  1875. X  for( link = Down(x);  link != x;  link = NextDown(link) )
  1876. X  { Child(y, link);
  1877. X    if( type(y) != WORD )  continue;
  1878. X    debug1(DHY, DD, "Hyphenate() examining %s", EchoObject(null, y));
  1879. X
  1880. X    /* start := index of y's first letter, stop := index following last */
  1881. X    key = string(y);  class = T->class;
  1882. X    for( start = 0;  class[key[start]] == PUNCT_CLASS;  start++ );
  1883. X    for( stop = start;  class[key[stop]] > PUNCT_CLASS;  stop++ );
  1884. X
  1885. X    /* if a - ended the run, hyphenate there only */
  1886. X    if( key[stop] == '-' )
  1887. X    { next_link = NextDown(link);
  1888. X      z = MakeWord(&key[stop+1], &fpos(y));
  1889. X      word_font(z) = word_font(y);
  1890. X      FontAtomSize(z);
  1891. X      Link(NextDown(link), z);
  1892. X      z = New(GAP_OBJ);
  1893. X      SetGap(gap(z), FALSE, TRUE, FIXED_UNIT, HYPH_MODE, 0);
  1894. X      Link(NextDown(link), z);
  1895. X      Link(z, MakeWord("0ch", &fpos(y)));
  1896. X      key[stop + 1] = '\0';
  1897. X      FontAtomSize(y);
  1898. X      link = PrevDown(next_link);
  1899. X      continue;
  1900. X    }
  1901. X
  1902. X    /* don't hyphenate if less than 5 letters, or a kill char is nearby */
  1903. X    if( stop - start < 5 )  continue;
  1904. X    if( key[stop] != '\0' && class[key[stop]] == KILL_CLASS )  continue;
  1905. X
  1906. X    /* let str[] be the converted substring, let rate[] be all '0' */
  1907. X    str[0] = PUNCT_CLASS;  rate[0] = '0';
  1908. X    for( i = 0;  i < stop - start;  i++ )
  1909. X    { str[i+1] = class[key[start + i]];
  1910. X      rate[i+1] = '0';
  1911. X    }
  1912. X    str[i+1] = PUNCT_CLASS;  rate[i+1] = '0';
  1913. X    str[i+2] = '\0';  rate[i+2] = '0';
  1914. X    rate[i+3] = '\0';
  1915. X    ifdebug(DHY, DD, ShowRate(key, start, stop, rate, stderr));
  1916. X
  1917. X    /* for each suffix of str[], accumulate patterns matching its prefixes */
  1918. X    ss = str;
  1919. X    do
  1920. X    {
  1921. X      ifdebug(DHY, DD,
  1922. X    fprintf(stderr, "trying suffix \"");
  1923. X    for( p = ss; *p != 0;  p++ )  fprintf(stderr, "%c", findrep(*p, T));
  1924. X    fprintf(stderr, "\"\n");
  1925. X      );
  1926. X    
  1927. X      /* accumulate all prefixes of ss */
  1928. X      curr_node = 0;  s = ss;
  1929. X      for(;;)
  1930. X      {
  1931. X    /* if curr_node has empty string, that is one prefix */
  1932. X    pos = T->node_mem[curr_node];
  1933. X    if( pos < 0 )
  1934. X    { AccumulateRating(&T->string_mem[- pos], rate+(ss-str));
  1935. X      debug1(DHY, DD, " found %s", &(T->string_mem[- pos]));
  1936. X    }
  1937. X
  1938. X    /* if ss is finished, no other prefixes are possible */
  1939. X    if( *s == '\0' )  break;
  1940. X
  1941. X    /* determine next_node and break if empty */
  1942. X    next_node = T->node_mem[curr_node + *s];
  1943. X    if( next_node == 0 )  break;
  1944. X
  1945. X    /* if next_node is a string, check whether it is a prefix of ss */
  1946. X    if( next_node < 0 )
  1947. X    { rem = &(T->string_mem[-next_node]);
  1948. X      do
  1949. X      { if( *rem == '\0' )
  1950. X        { AccumulateRating(rem+1, rate+(ss-str));
  1951. X          debug1(DHY, DD, " found %s", rem+1);
  1952. X          break;
  1953. X        }
  1954. X      } while( *++s == *rem++ );
  1955. X      break;
  1956. X    }
  1957. X
  1958. X    /* otherwise go on to the next trie node */
  1959. X    curr_node = 2*next_node;  s++;
  1960. X      }
  1961. X    } while( *(++ss + 2) != PUNCT_CLASS );
  1962. X    ifdebug(DHY, DD, ShowRate(key, start, stop, rate, stderr));
  1963. X
  1964. X    /* now rate[] has accumulated ratings; use it to perform hyphenations */
  1965. X    hyphenated = FALSE;
  1966. X    /* hyphenate after any concluding - */
  1967. X    /* *** now doing this at start only (see above)
  1968. X    if( key[stop] == '-' )
  1969. X    {
  1970. X      z = MakeWord(&key[stop+1], &fpos(y));
  1971. X      word_font(z) = word_font(y);
  1972. X      FontAtomSize(z);
  1973. X      Link(NextDown(link), z);
  1974. X      z = New(GAP_OBJ);
  1975. X      SetGap(gap(z), FALSE, TRUE, FIXED_UNIT, HYPH_MODE, 0);
  1976. X      Link(NextDown(link), z);
  1977. X      Link(z, MakeWord("0ch", &fpos(y)));
  1978. X      key[stop + 1] = '\0';
  1979. X      hyphenated = TRUE;
  1980. X    }
  1981. X    *** */
  1982. X    next_link = NextDown(link);
  1983. X    for( i = stop - start - 1;  i >= 3;  i-- )
  1984. X    {
  1985. X      /* hyphenate at i if rate[i] is odd */
  1986. X      if( is_odd(rate[i]) )
  1987. X      {    z = MakeWord(&key[start+i-1], &fpos(y));
  1988. X    word_font(z) = word_font(y);
  1989. X    FontAtomSize(z);
  1990. X    Link(NextDown(link), z);
  1991. X    z = New(GAP_OBJ);
  1992. X    SetGap(gap(z), FALSE, TRUE, FIXED_UNIT, HYPH_MODE, 0);
  1993. X    Link(NextDown(link), z);
  1994. X    Link(z, MakeWord("0ch", &fpos(y)));
  1995. X    key[start + i - 1] = '\0';
  1996. X    hyphenated = TRUE;
  1997. X      }
  1998. X    }
  1999. X    if( hyphenated )
  2000. X    { FontAtomSize(y);
  2001. X      link = PrevDown(next_link);
  2002. X    }
  2003. X
  2004. X  } /* end for each word */
  2005. X
  2006. X  debug1(DHY, DD, "Hyphenate returning %s", EchoObject(null, x));
  2007. X  return x;
  2008. X} /* end Hyphenate */
  2009. X
  2010. X
  2011. X/*@@**************************************************************************/
  2012. X/*                                                                           */
  2013. X/*  unsigned char *TrieRetrieve(key, T)                                      */
  2014. X/*                                                                           */
  2015. X/*  Retrieve the value associated with key in T, or NULL if not present.     */
  2016. X/*                                                                           */
  2017. X/*****************************************************************************/
  2018. X#if DEBUG_ON
  2019. X
  2020. Xunsigned char *TrieRetrieve(key, T)
  2021. Xunsigned char *key;  TRIE T;
  2022. X{ unsigned char str[MAX_LINE];  int i, curr_node, next_node, pos;
  2023. X  debug1(DHY, DD, "TrieRetrieve(%s, T)", key);
  2024. X  ClassConvert(key, str, T);
  2025. X
  2026. X  /* invariant: curr_node is an existing node of T with prefix str[0..i-1] */
  2027. X  curr_node = i = 0;
  2028. X  for(;;)
  2029. X  {
  2030. X    /* if next_node is 0, the string was never inserted */
  2031. X    next_node = T->node_mem[curr_node + str[i]];
  2032. X    if( next_node == 0 )  return (unsigned char *) NULL;
  2033. X
  2034. X    /* if next_node < 0 it represents an offset into the string memory */
  2035. X    if( next_node < 0 )
  2036. X    { pos = - next_node;
  2037. X      if( str[i] != '\0' )
  2038. X      {    do
  2039. X    { if( str[++i] != T->string_mem[pos++] )  return (unsigned char *) NULL;
  2040. X    } while( str[i] != '\0' );
  2041. X      }
  2042. X      return &(T->string_mem[pos]);
  2043. X    }
  2044. X
  2045. X    /* otherwise next_node is the trie node to be searched next */
  2046. X    curr_node = 2*next_node;  i++;
  2047. X  }
  2048. X} /* end TrieRetrieve */
  2049. X
  2050. X
  2051. X/*****************************************************************************/
  2052. X/*                                                                           */
  2053. X/*  ShowRate(key, start, stop, rate, fp)                                     */
  2054. X/*                                                                           */
  2055. X/*  Debug print of key[] and rate[] on file fp.                              */
  2056. X/*                                                                           */
  2057. X/*****************************************************************************/
  2058. X
  2059. Xstatic ShowRate(key, start, stop, rate, fp)
  2060. Xunsigned char *key;  int start, stop;  unsigned char *rate;  FILE *fp;
  2061. X{ int i;
  2062. X  fprintf(fp, "key:    ");
  2063. X  for( i = start;  i < stop;  i++ )  fprintf(fp, " %c", key[i]);
  2064. X  fprintf(fp, "\nrate:");
  2065. X  for( i = 0;  rate[i] != '\0';  i++ )  fprintf(fp, " %c", rate[i]);
  2066. X  fprintf(fp, "\n");
  2067. X} /* end ShowRate */
  2068. X
  2069. X
  2070. X/*@@**************************************************************************/
  2071. X/*                                                                           */
  2072. X/*  DoTriePrint(T, node, len, fp)                                            */
  2073. X/*                                                                           */
  2074. X/*  Print on file fp the subset of the entries of trie T stored in node and  */
  2075. X/*  its descendants.  The node has prefix prefix[0..len-1].                  */
  2076. X/*                                                                           */
  2077. X/*****************************************************************************/
  2078. X
  2079. Xstatic unsigned char prefix[MAX_LINE];
  2080. X
  2081. Xstatic DoTriePrint(T, node, len, fp)
  2082. XTRIE T; int node, len; FILE *fp;
  2083. X{ int i, next_node, pos;
  2084. X  for( i = 0;  i < T->class_count;  i++ )
  2085. X  {
  2086. X    /* if next_node < 0, have string to print */
  2087. X    next_node = T->node_mem[node + i];
  2088. X    if( next_node < 0 )
  2089. X    {
  2090. X      prefix[len] = '\0';
  2091. X      fprintf(fp, "%s", prefix);
  2092. X      pos = - next_node;
  2093. X      if( i != 0 )
  2094. X      {
  2095. X    fprintf(fp, "%c", findrep(i, T));
  2096. X    while( T->string_mem[pos] != '\0' )
  2097. X    { fprintf(fp, "%c", findrep(T->string_mem[pos], T));
  2098. X      pos++;
  2099. X    }
  2100. X    pos++;
  2101. X      }
  2102. X      fprintf(fp, " %s\n", &(T->string_mem[pos]));
  2103. X    }
  2104. X
  2105. X    /* else if next_node > 0 have a child node to explore */
  2106. X    else if( next_node > 0 )
  2107. X    { assert( i > 0, "DoTriePrint: i == 0!" );
  2108. X      prefix[len] = findrep(i, T);
  2109. X      prefix[len+1] = '\0';
  2110. X      DoTriePrint(T, 2*next_node, len+1, fp);
  2111. X    }
  2112. X  }
  2113. X} /* end DoTriePrint */
  2114. X
  2115. X
  2116. X/*****************************************************************************/
  2117. X/*                                                                           */
  2118. X/*  TriePrint(T, fp)                                                         */
  2119. X/*                                                                           */
  2120. X/*  Print trie T on file fp.                                                 */
  2121. X/*                                                                           */
  2122. X/*****************************************************************************/
  2123. X
  2124. XTriePrint(T, fp)
  2125. XTRIE T;  FILE *fp;
  2126. X{ int i, j, ch;
  2127. X  assert( T-> magic == TRIE_MAGIC, "TriePrint: magic!" );
  2128. X  fprintf(fp, "Classes:");
  2129. X  for( i = 1;  i < T->class_count;  i++ )
  2130. X  { fprintf(fp, " ");
  2131. X    for( ch = 0;  ch < MAX_CHAR;  ch++ )
  2132. X      if( T->class[ch] == i )  fprintf(fp, "%c", ch);
  2133. X  }
  2134. X  fprintf(fp, "\n");
  2135. X  fprintf(fp, "Node space: %d capacity, %d used\n", T->node_lim, T->node_free);
  2136. X  fprintf(fp, "String space: %d capacity, %d used\n", T->string_lim,
  2137. X    T->string_lim - T->string_first);
  2138. X  prefix[0] = '\0';
  2139. X  DoTriePrint(T, 0, 0, fp);
  2140. X} /* end TriePrint */
  2141. X#endif
  2142. END_OF_FILE
  2143.   if test 31731 -ne `wc -c <'lout/z36.c'`; then
  2144.     echo shar: \"'lout/z36.c'\" unpacked with wrong size!
  2145.   fi
  2146.   # end of 'lout/z36.c'
  2147. fi
  2148. echo shar: End of archive 8 \(of 30\).
  2149. cp /dev/null ark8isdone
  2150. MISSING=""
  2151. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ; do
  2152.     if test ! -f ark${I}isdone ; then
  2153.     MISSING="${MISSING} ${I}"
  2154.     fi
  2155. done
  2156. if test "${MISSING}" = "" ; then
  2157.     echo You have unpacked all 30 archives.
  2158.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2159. else
  2160.     echo You still must unpack the following archives:
  2161.     echo "        " ${MISSING}
  2162. fi
  2163. exit 0
  2164. exit 0 # Just in case...
  2165.