-- file: TexHyphImpl.mesa -- Pascal-to-Mesa translator output, translated at September 27, 1985 10:21:38 am PDT DIRECTORY PascalBasic, TexTypes, TexInit, TexInteraction, TexMemory, TexSymbols, TexScan, TexParagraph, TexSysdepInline; TexHyphImpl: PROGRAM IMPORTS PascalBasic, TexTypes, TexInit, TexInteraction, TexMemory, TexSymbols, TexScan, TexParagraph, TexSysdepInline EXPORTS TexParagraph = PUBLIC BEGIN OPEN PascalBasic, TexTypes, TexInit, TexInteraction, TexMemory, TexSymbols, TexScan, TexParagraph, TexSysdepInline; Hyphenate: PROCEDURE = BEGIN --901:--I, J, L:PascalInteger[0..65];Q, R, S:Halfword;--:901----912: MajorTail, MinorTail:Halfword;C:AsciiCode;--:912----922:--Z:TriePointer; V:Quarterword;--:922----929:--H:HyphPointer;K:StrNumber;U:PoolPointer; --:929----923:-- --903: FOR i:INT IN [ INT[0 ].. INT[Hn ]] DO J ← i; Hyf↑[J]←0 ENDLOOP;--930:--H←Hc↑[1]; FOR i:INT IN [ INT[2 ].. INT[Hn ]] DO J ← i; H← ( INT[H+H]+Hc↑[J])MOD 307 ENDLOOP;{{WHILE TRUE DO BEGIN--931: K←HyphWord↑[H];IF K=0 THEN GOTO Label45; IF( INT[StrStart↑[K+1]]-StrStart↑[K])<Hn THEN GOTO Label45; {IF( INT[StrStart↑[K+1]]-StrStart↑[K])=Hn THEN BEGIN J←1;U←StrStart↑[K]; DO IF INT[StrPool↑[U]]<Hc↑[J] THEN GOTO Label45; IF INT[StrPool↑[U]]>Hc↑[J] THEN GOTO Label30;J←J+1;U←U+1; IF INT[J]>Hn THEN EXIT; ENDLOOP;--932: S←HyphList↑[H];WHILE S#0 DO BEGIN Hyf↑[Mem[S]↑.Hh.Lh]←1; S←Mem[S]↑.Hh.Rh; END--:932-- ENDLOOP ; GOTO Label40; END;EXITS Label30 => NULL};--:931--IF INT[H]>0 THEN H←H-1 ELSE H←307; END ENDLOOP ;EXITS Label45 => NULL};--:930--Hc↑[0]←127;Hc↑[Hn+1]←127; Hc↑[Hn+2]←256;FOR i:INT IN [ INT[0 ].. INT[Hn-2 ]] DO J ← i; Z←Hc↑[J];L←J; WHILE Hc↑[L]=Trie↑[Z].B1 DO BEGIN IF Trie↑[Z].B0#0 THEN--924: BEGIN V←Trie↑[Z].B0;DO I←L-HyfDistance↑[V]; IF INT[HyfNum↑[V]]>Hyf↑[I] THEN Hyf↑[I]←HyfNum↑[V];V←HyfNext↑[V]; IF V=0 THEN EXIT; ENDLOOP; END--:924--;L←L+1;Z← INT[Trie↑[Z].Rh]+Hc↑[L]; END ENDLOOP ; ENDLOOP;EXITS Label40 => NULL};Hyf↑[1]←0;Hyf↑[Hn-2]←0; Hyf↑[Hn-1]←0;Hyf↑[Hn]←0--:923--;--902: {{FOR i:INT IN [ INT[2 ].. INT[Hn-3 ]] DO J ← i; IF PascalODD[Hyf↑[J]] THEN GOTO Label41 ENDLOOP; GOTO Label10;EXITS Label41 => NULL};--:902--Q←Mem[Hb]↑.Hh.Rh;Mem[Hb]↑.Hh.Rh←0;S←CurP; WHILE Mem[S]↑.Hh.Rh#Ha DO S←Mem[S]↑.Hh.Rh ENDLOOP ;Mem[S]↑.Hh.Rh←0; FlushNodeList[Ha];--913:--J←0;DO L←J;J←Reconstitute[J+1,Hn]; IF HyphenPassed#0 THEN--914:--BEGIN R←GetNode[2];Mem[S]↑.Hh.Rh←R; Mem[R]↑.Hh.Rh←Mem[64996]↑.Hh.Rh;Mem[R]↑.Hh.B0←7; MajorTail←Mem[64996]↑.Hh.Rh; IF Mem[MajorTail]↑.Hh.Rh#0 THEN MajorTail←Mem[MajorTail]↑.Hh.Rh; I←HyphenPassed;--915:--MinorTail←0;C←Hu↑[I+1]; Hu↑[I+1]←HyphenChar↑[Hf];DO L←Reconstitute[L+1,I+1]; IF MinorTail=0 THEN Mem[R+1]↑.Hh.Lh←Mem[64996]↑.Hh.Rh ELSE Mem[ MinorTail]↑.Hh.Rh←Mem[64996]↑.Hh.Rh;MinorTail←Mem[64996]↑.Hh.Rh; IF Mem[MinorTail]↑.Hh.Rh#0 THEN MinorTail←Mem[MinorTail]↑.Hh.Rh; IF INT[L]>I THEN EXIT; ENDLOOP;Hu↑[I+1]←C;L←L-1;Hyf↑[L]←0--:915--;--916:--MinorTail←0; Mem[R+1]↑.Hh.Rh←0;WHILE INT[L]<J DO BEGIN DO L←Reconstitute[L+1,Hn]; IF MinorTail=0 THEN Mem[R+1]↑.Hh.Rh←Mem[64996]↑.Hh.Rh ELSE Mem[ MinorTail]↑.Hh.Rh←Mem[64996]↑.Hh.Rh;MinorTail←Mem[64996]↑.Hh.Rh; IF Mem[MinorTail]↑.Hh.Rh#0 THEN BEGIN Hyf↑[L]←0; MinorTail←Mem[MinorTail]↑.Hh.Rh; END; IF INT[L]>=J THEN EXIT; ENDLOOP; WHILE INT[L]>J DO BEGIN J←Reconstitute[J+1,Hn]; Mem[MajorTail]↑.Hh.Rh←Mem[64996]↑.Hh.Rh;MajorTail←Mem[64996]↑.Hh.Rh; IF Mem[MajorTail]↑.Hh.Rh#0 THEN BEGIN Hyf↑[J]←0; MajorTail←Mem[MajorTail]↑.Hh.Rh; END; END ENDLOOP ; END--:916-- ENDLOOP ;--917:--I←0;S←R; WHILE Mem[S]↑.Hh.Rh#0 DO BEGIN I←I+1;S←Mem[S]↑.Hh.Rh; END ENDLOOP ; Mem[R]↑.Hh.B1←I--:917--; END--:914 ELSE BEGIN Mem[S]↑.Hh.Rh←Mem[64996]↑.Hh.Rh;S←Mem[S]↑.Hh.Rh; IF Mem[S]↑.Hh.Rh#0 THEN S←Mem[S]↑.Hh.Rh; END;IF PascalODD[Hyf↑[J]] THEN--918: BEGIN R←NewDisc[];Mem[R+1]↑.Hh.Lh←NewCharacter[Hf,HyphenChar↑[Hf]]; Mem[S]↑.Hh.Rh←R;S←R; END--:918--; IF J=Hn THEN EXIT; ENDLOOP;Mem[S]↑.Hh.Rh←Q--:913----:903--; EXITS Label10 => NULL}; END;--:895-- NewHyphExceptions: PROCEDURE = BEGIN N:SmallNumber; J:SmallNumber;H:HyphPointer;K:StrNumber;P:Halfword;Q:Halfword; S, T:StrNumber;U, V:PoolPointer; ScanLeftBrace[];--935:--N←0;P←0; {WHILE TRUE DO BEGIN GetXToken[];DO {--Label21:--SELECT CurCmd FROM 11,12,67 =>--937: IF CurChr=45 THEN--938:--BEGIN IF INT[N]>1 THEN BEGIN Q←GetAvail[]; Mem[Q]↑.Hh.Rh←P;Mem[Q]↑.Hh.Lh←N;P←Q; END; END--:938 ELSE BEGIN IF( INT[CurChr]>127)OR (Eqtb↑[ INT[4255]+CurChr].Hh.Rh=0) THEN BEGIN BEGIN IF Interaction=3 THEN NULL;PrintNl[134];Print[802]; END;BEGIN HelpPtr←2; HelpLine↑[1]←803;HelpLine↑[0]←804; END;Error[]; END ELSE IF INT[N]<63 THEN BEGIN N←N+1;Hc↑[N]← INT[Eqtb↑[ INT[4255]+CurChr].Hh.Rh]-1; END; END--:937--;16 =>BEGIN ScanCharNum[];CurChr←CurVal;CurCmd←67; GOTO Label21; END;10,2 =>BEGIN IF INT[N]>4 THEN--939: BEGIN BEGIN IF INT[PoolPtr+N]>PoolSize THEN Overflow[129, PoolSize-InitPoolPtr]; END;H←0;FOR i:INT IN [ INT[1 ].. INT[N ]] DO J ← i; H← ( INT[H+H]+Hc↑[J])MOD 307; BEGIN StrPool↑[PoolPtr]←Hc↑[J];PoolPtr←PoolPtr+1; END; ENDLOOP; S←MakeString[];{WHILE TRUE DO BEGIN IF P=0 THEN GOTO Label30; IF INT[Mem[P]↑.Hh.Lh]<N-2 THEN GOTO Label30;Q←Mem[P]↑.Hh.Rh; BEGIN Mem[P]↑.Hh.Rh←Avail;Avail←P;DynUsed←DynUsed-1; END;P←Q; END ENDLOOP ; EXITS Label30 => NULL};--940:--IF HyphCount=307 THEN Overflow[805,307]; HyphCount←HyphCount+1;WHILE HyphWord↑[H]#0 DO BEGIN--941: K←HyphWord↑[H]; {{IF( INT[StrStart↑[K+1]]-StrStart↑[K])<( INT[StrStart↑[S+1]]-StrStart↑[S]) THEN GOTO Label40; IF( INT[StrStart↑[K+1]]-StrStart↑[K])>( INT[StrStart↑[S+1]]-StrStart↑[S]) THEN GOTO Label45;U←StrStart↑[K];V←StrStart↑[S]; DO IF INT[StrPool↑[U]]<StrPool↑[V] THEN GOTO Label40; IF INT[StrPool↑[U]]>StrPool↑[V] THEN GOTO Label45;U←U+1;V←V+1; IF U=StrStart↑[K+1] THEN EXIT; ENDLOOP;EXITS Label40 => NULL};Q←HyphList↑[H];HyphList↑[H]←P;P←Q; T←HyphWord↑[H];HyphWord↑[H]←S;S←T;EXITS Label45 => NULL};--:941--IF INT[H]>0 THEN H←H-1 ELSE H←307; END ENDLOOP ;HyphWord↑[H]←S;HyphList↑[H]←P--:940 ; END--:939--;IF CurCmd=2 THEN GOTO Label10;N←0;P←0; END; ENDCASE =>--936: BEGIN BEGIN IF Interaction=3 THEN NULL;PrintNl[134];Print[539]; END; PrintEsc[798];Print[799];BEGIN HelpPtr←2;HelpLine↑[1]←800; HelpLine↑[0]←801; END;Error[]; END--:936--;EXIT; EXITS Label21 => NULL} ENDLOOP; END--:935-- ENDLOOP ;EXITS Label10 => NULL}; END;--:934----942: --944:-- NewTrieOp: PROCEDURE[D,N: SmallNumber,V: Quarterword] RETURNS[NewTrieOpResult: Quarterword] = BEGIN H:PascalInteger[0..510];U:Quarterword; H← ABS[N+313*D+ INT[361]*V]MOD 510; {WHILE TRUE DO BEGIN U←TrieOpHash↑[H]; IF U=0 THEN BEGIN IF TrieOpPtr=255 THEN BEGIN NewTrieOpResult←0; GOTO Label10; END;TrieOpPtr←TrieOpPtr+1;HyfDistance↑[TrieOpPtr]←D; HyfNum↑[TrieOpPtr]←N;HyfNext↑[TrieOpPtr]←V; TrieOpHash↑[H]←TrieOpPtr;NewTrieOpResult←TrieOpPtr; GOTO Label10; END; IF(HyfDistance↑[U]=D)AND (HyfNum↑[U]=N)AND (HyfNext↑[U]=V) THEN BEGIN NewTrieOpResult←U; GOTO Label10; END;IF INT[H]>0 THEN H←H-1 ELSE H←510; END ENDLOOP ;EXITS Label10 => NULL}; END; --:944----947:-- TrieNode: PROCEDURE[P: TriePointer] RETURNS[TrieNodeResult: TriePointer] = BEGIN H:TriePointer;Q:TriePointer; H← ABS[TrieC↑[P]+ INT[1009]*TrieO↑[P]+ INT[2718]*TrieL↑[P]+ INT[3142]*TrieR↑[P]]MOD TrieSize;{WHILE TRUE DO BEGIN Q←TrieHash↑[H]; IF Q=0 THEN BEGIN TrieHash↑[H]←P;TrieNodeResult←P; GOTO Label10; END; IF(TrieC↑[Q]=TrieC↑[P])AND (TrieO↑[Q]=TrieO↑[P])AND (TrieL↑[Q]=TrieL↑[P]) AND (TrieR↑[Q]=TrieR↑[P]) THEN BEGIN TrieNodeResult←Q; GOTO Label10; END; IF INT[H]>0 THEN H←H-1 ELSE H←TrieSize; END ENDLOOP ;EXITS Label10 => NULL}; END;--:947----948: CompressTrie: PROCEDURE[P: TriePointer] RETURNS[CompressTrieResult: TriePointer] = BEGIN IF P=0 THEN CompressTrieResult←0 ELSE BEGIN TrieL↑[P]←CompressTrie[ TrieL↑[P]];TrieR↑[P]←CompressTrie[TrieR↑[P]]; CompressTrieResult←TrieNode[P]; END; END;--:948----949: --:949----951:-- InitTrieMemory: PROCEDURE = BEGIN P:TriePointer; FOR i:INT IN [ INT[0 ].. INT[TriePtr ]] DO P ← i; TrieHash↑[P]←0 ENDLOOP;TrieMax←128; TrieMin←128;Trie↑[0].Rh←1;TrieTaken↑[0]←FALSE; FOR i:INT IN [ INT[1 ].. INT[128 ]] DO P ← i; Trie↑[P].Lh←P-1;Trie↑[P].Rh←P+1; TrieTaken↑[P]←FALSE; ENDLOOP; END;--:951----953: FirstFit: PROCEDURE[P: TriePointer] = BEGIN H:TriePointer; Z:TriePointer;Q:TriePointer;C:AsciiCode; C←TrieC↑[P]; IF INT[C]<TrieMin THEN TrieMin←C;Z←Trie↑[TrieMin-1].Rh; {WHILE TRUE DO BEGIN {IF INT[Z]<C THEN GOTO Label45;H←Z-C;--954: IF INT[TrieMax]<H+128 THEN BEGIN IF INT[TrieSize]<=H+128 THEN Overflow[806, TrieSize];DO TrieMax←TrieMax+1;TrieTaken↑[TrieMax]←FALSE; Trie↑[TrieMax].Rh←TrieMax+1;Trie↑[TrieMax].Lh←TrieMax-1; IF TrieMax=H+128 THEN EXIT; ENDLOOP; END--:954--;IF TrieTaken↑[H] THEN GOTO Label45;--955: Q←TrieR↑[P];WHILE INT[Q]>0 DO BEGIN IF Trie↑[H+TrieC↑[Q]].Rh=0 THEN GOTO Label45; Q←TrieR↑[Q]; END ENDLOOP ; GOTO Label40--:955--;EXITS Label45 => NULL};Z←Trie↑[Z].Rh; END ENDLOOP ;EXITS Label40 => NULL};--956: TrieTaken↑[H]←TRUE;TrieHash↑[P]←H;Q←P;DO Z←H+TrieC↑[Q]; Trie↑[Trie↑[Z].Rh].Lh←Trie↑[Z].Lh;Trie↑[Trie↑[Z].Lh].Rh←Trie↑[Z].Rh; Trie↑[Z].Rh←0;Q←TrieR↑[Q]; IF Q=0--:956-- THEN EXIT; ENDLOOP; END;--:953----957: TriePack: PROCEDURE[P: TriePointer] = BEGIN Q:TriePointer; DO Q←TrieL↑[P]; IF( INT[Q]>0)AND (TrieHash↑[Q]=0) THEN BEGIN FirstFit[Q];TriePack[Q]; END; P←TrieR↑[P]; IF P=0 THEN EXIT; ENDLOOP; END;--:957----959: TrieFix: PROCEDURE[P: TriePointer] = BEGIN Q:TriePointer;C:AsciiCode; Z:TriePointer; Z←TrieHash↑[P];WHILE P#0 DO BEGIN Q←TrieL↑[P]; C←TrieC↑[P];Trie↑[Z+C].Rh←TrieHash↑[Q];Trie↑[Z+C].B1←C; Trie↑[Z+C].B0←TrieO↑[P];IF INT[Q]>0 THEN TrieFix[Q];P←TrieR↑[P]; END ENDLOOP ; END; --:959----960:-- NewPatterns: PROCEDURE = BEGIN K, L:SmallNumber; DigitSensed:PascalBoolean;V:Quarterword;P, Q:TriePointer;FirstChild:PascalBoolean; C:AsciiCode;R, S:TriePointer;H:TwoHalves; ScanLeftBrace[]; InitPatternMemory[];--961:--K←0;Hyf↑[0]←0;DigitSensed←FALSE; {WHILE TRUE DO BEGIN GetXToken[];SELECT CurCmd FROM 11,12 =>--962: IF DigitSensed OR ( INT[CurChr]<48)OR ( INT[CurChr]>57) THEN BEGIN IF CurChr=46 THEN CurChr←128 ELSE BEGIN CurChr←Eqtb↑[ INT[4255]+CurChr].Hh.Rh; IF CurChr=0 THEN BEGIN BEGIN IF Interaction=3 THEN NULL;PrintNl[134]; Print[810]; END;BEGIN HelpPtr←1;HelpLine↑[0]←809; END;Error[]; CurChr←128; END; END;IF INT[K]<63 THEN BEGIN K←K+1;Hc↑[K]← INT[CurChr]-1; Hyf↑[K]←0;DigitSensed←FALSE; END; END ELSE BEGIN Hyf↑[K]← INT[CurChr]-48; IF INT[K]<63 THEN DigitSensed←TRUE; END--:962--;10,2 =>BEGIN IF INT[K]>0 THEN--963: BEGIN--965:-- IF Hc↑[1]=127 THEN Hyf↑[0]←0;IF Hc↑[K]=127 THEN Hyf↑[K]←0;L←K; V←0;{WHILE TRUE DO BEGIN IF Hyf↑[L]#0 THEN V←NewTrieOp[K-L,Hyf↑[L],V]; IF INT[L]>0 THEN L←L-1 ELSE GOTO Label31; END ENDLOOP ;EXITS Label31 => NULL};--:965--Q←0; WHILE INT[L]<K DO BEGIN L←L+1;C←Hc↑[L];P←TrieL↑[Q];FirstChild←TRUE; WHILE( INT[P]>0)AND ( INT[C]>TrieC↑[P])DO BEGIN Q←P;P←TrieR↑[Q];FirstChild←FALSE; END ENDLOOP ;IF(P=0)OR ( INT[C]<TrieC↑[P]) THEN--964: BEGIN IF TriePtr=TrieSize THEN Overflow[806,TrieSize]; TriePtr←TriePtr+1;TrieR↑[TriePtr]←P;P←TriePtr;TrieL↑[P]←0; IF FirstChild THEN TrieL↑[Q]←P ELSE TrieR↑[Q]←P;TrieC↑[P]←C; TrieO↑[P]←0; END--:964--;Q←P; END ENDLOOP ; IF TrieO↑[Q]#0 THEN BEGIN BEGIN IF Interaction=3 THEN NULL;PrintNl[134]; Print[811]; END;BEGIN HelpPtr←1;HelpLine↑[0]←809; END;Error[]; END; TrieO↑[Q]←V; END--:963--;IF CurCmd=2 THEN GOTO Label30;K←0;Hyf↑[0]←0; DigitSensed←FALSE; END; ENDCASE =>BEGIN BEGIN IF Interaction=3 THEN NULL; PrintNl[134];Print[807]; END;PrintEsc[808];BEGIN HelpPtr←1; HelpLine↑[0]←809; END;Error[]; END ; END ENDLOOP ;EXITS Label30 => NULL};--:961--TrieL↑[0]←CompressTrie[TrieL↑[0]];--966:--InitTrieMemory[]; IF TrieL↑[0]#0 THEN BEGIN FirstFit[TrieL↑[0]];TriePack[TrieL↑[0]]; END;--958:--R←0;WHILE TrieTaken↑[R]DO R←R+1 ENDLOOP ;TrieHash↑[0]←R; TrieFix[TrieL↑[0]]--:958--;R←0;H.Rh←0;H.B0←0;H.B1←0; DO S←Trie↑[R].Rh;Trie↑[R]←H;R←S; IF INT[R]>TrieMax--:966-- THEN EXIT; ENDLOOP; END;--:960 END.