-- file: TexBuildPageImpl.mesa
-- Pascal-to-Mesa translator output, translated at September 27, 1985 10:21:38 am PDT


DIRECTORY
  PascalBasic,
  TexTypes,
  TexInteraction,
  TexMemory,
  TexSymbols,
  TexScan,
  TexDvi,
  TexOps,
  TexBuildPage,
  TexRest,
  TexSysdepInline;

TexBuildPageImpl: PROGRAM IMPORTS TexTypes, TexInteraction, TexMemory, TexSymbols, TexBuildPage, TexRest, TexSysdepInline EXPORTS TexBuildPage = PUBLIC
BEGIN OPEN PascalBasic, TexTypes, TexInteraction, TexMemory, TexSymbols, TexScan, TexDvi, TexOps, TexBuildPage, TexRest, TexSysdepInline;
--:555----592:--
TotalPages: PascalInteger;


MaxV: Scaled;

MaxH: Scaled;

MaxPush: PascalInteger;

LastBop: PascalInteger;


DeadCycles: PascalInteger;

DoingLeaders: PascalBoolean;

C: Quarterword;

F: Quarterword;


RuleHt: Scaled;

RuleDp: Scaled;

RuleWd: Scaled;

G: Halfword;

Lq: PascalInteger;

Lr: PascalInteger;
--:1012--  BuildPage: PROCEDURE = 
BEGIN  P:Halfword;
Q, R:Halfword;B, C:PascalInteger;Pi:PascalInteger;N:PascalInteger[0..255];Delta, H, W:Scaled;
 {IF (Mem[64999]↑.Hh.Rh=0)OR OutputActive  THEN  GOTO Label10;
DO --998:--  DO {--Label22:--P←Mem[64999]↑.Hh.Rh;--996:
IF LastGlue#65515  THEN DeleteGlueRef[LastGlue];LastPenalty←0;
LastKern←0;IF Mem[P]↑.Hh.B0=10  THEN BEGIN LastGlue←Mem[P+1]↑.Hh.Lh;
Mem[LastGlue]↑.Hh.Rh←Mem[LastGlue]↑.Hh.Rh+1;
 END  ELSE BEGIN LastGlue←65515;
IF Mem[P]↑.Hh.B0=12  THEN LastPenalty←Mem[P+1]↑.Int  ELSE IF 
Mem[P]↑.Hh.B0=11  THEN LastKern←Mem[P+1]↑.Int; END--:996--;--997:----1000:
{{{{SELECT Mem[P]↑.Hh.B0 FROM 0,1,2 =>IF  INT[PageContents]<2  THEN--1001:
BEGIN IF PageContents=0  THEN FreezePageSpecs[2] ELSE PageContents←2;
Q←NewSkipParam[9];Mem[Q]↑.Hh.Rh←P;
IF Mem[TempPtr+1]↑.Int>Mem[P+3]↑.Int  THEN Mem[TempPtr+1]↑.Int←Mem[
TempPtr+1]↑.Int-Mem[P+3]↑.Int  ELSE Mem[TempPtr+1]↑.Int←0;
Mem[Q]↑.Hh.Rh←P;Mem[64999]↑.Hh.Rh←Q; GOTO Label22; END--:1001-- ELSE--1002:
BEGIN PageSoFar↑[1]←PageSoFar↑[1]+PageSoFar↑[7]+Mem[P+3]↑.Int;
PageSoFar↑[7]←Mem[P+2]↑.Int; GOTO Label80; END--:1002--;8 =>--1363:-- GOTO Label80--:1363--;
10 =>IF  INT[PageContents]<2  THEN  GOTO Label31  ELSE IF( INT[Mem[PageTail]↑.Hh.B0]<9) THEN
Pi←0  ELSE  GOTO Label90;
11 =>IF  INT[PageContents]<2  THEN  GOTO Label31  ELSE IF Mem[P]↑.Hh.Rh=0  THEN  GOTO Label10
 ELSE IF Mem[Mem[P]↑.Hh.Rh]↑.Hh.B0=10  THEN Pi←0  ELSE  GOTO Label90;
12 =>IF  INT[PageContents]<2  THEN  GOTO Label31  ELSE Pi←Mem[P+1]↑.Int;4 => GOTO Label80;
3 =>--1008:--BEGIN IF PageContents=0  THEN FreezePageSpecs[1];
N←Mem[P]↑.Hh.B1;R←65000;
WHILE  INT[N]>=Mem[Mem[R]↑.Hh.Rh]↑.Hh.B1 DO R←Mem[R]↑.Hh.Rh ENDLOOP ;N←N;
IF Mem[R]↑.Hh.B1#N  THEN--1009:--BEGIN Q←GetNode[4];
Mem[Q]↑.Hh.Rh←Mem[R]↑.Hh.Rh;Mem[R]↑.Hh.Rh←Q;R←Q;Mem[R]↑.Hh.B1←N;
Mem[R]↑.Hh.B0←0;EnsureVbox[N];
IF Eqtb↑[3822+N].Hh.Rh=0  THEN Mem[R+3]↑.Int←0  ELSE Mem[R+3]↑.Int←Mem[Eqtb
↑[3822+N].Hh.Rh+3]↑.Int+Mem[Eqtb↑[3822+N].Hh.Rh+2]↑.Int;Mem[R+2]↑.Hh.Lh←0;
Q←Eqtb↑[3044+N].Hh.Rh;
IF Eqtb↑[4817+N].Int=1000  THEN H←Mem[R+3]↑.Int  ELSE H←XOverN[Mem[R+3]↑.
Int,1000]*Eqtb↑[4817+N].Int;
PageSoFar↑[0]←PageSoFar↑[0]-H-Mem[Q+1]↑.Int;
PageSoFar↑[2+Mem[Q]↑.Hh.B0]←PageSoFar↑[2+Mem[Q]↑.Hh.B0]+Mem[Q+2]↑.Int;
PageSoFar↑[6]←PageSoFar↑[6]+Mem[Q+3]↑.Int;
IF(Mem[Q]↑.Hh.B1#0)AND (Mem[Q+3]↑.Int#0) THEN BEGIN BEGIN IF Interaction=3
 THEN NULL;PrintNl[134];Print[851]; END;PrintEsc[263];PrintInt[N];
BEGIN HelpPtr←3;HelpLine↑[2]←852;HelpLine↑[1]←853;HelpLine↑[0]←781;
 END;Error[]; END; END--:1009--;
IF Mem[R]↑.Hh.B0=1  THEN InsertPenalties←InsertPenalties+Mem[P+1]↑.Int
 ELSE BEGIN Mem[R+2]↑.Hh.Rh←P;
Delta←PageSoFar↑[0]-PageSoFar↑[1]-PageSoFar↑[7]+PageSoFar↑[6];
IF Eqtb↑[4817+N].Int=1000  THEN H←Mem[P+3]↑.Int  ELSE H←XOverN[Mem[P+3]↑.
Int,1000]*Eqtb↑[4817+N].Int;
IF((H<=0)OR (H<=Delta))AND (Mem[P+3]↑.Int+Mem[R+3]↑.Int<=Eqtb↑[5221+N].Int)
 THEN BEGIN PageSoFar↑[0]←PageSoFar↑[0]-H;
Mem[R+3]↑.Int←Mem[R+3]↑.Int+Mem[P+3]↑.Int; END  ELSE--1010:
BEGIN IF Eqtb↑[4817+N].Int<=0  THEN W←1073741823  ELSE BEGIN W←
PageSoFar↑[0]-PageSoFar↑[1]-PageSoFar↑[7];
IF Eqtb↑[4817+N].Int#1000  THEN W←XOverN[W,Eqtb↑[4817+N].Int]*1000; END;
IF W>Eqtb↑[5221+N].Int-Mem[R+3]↑.Int  THEN W←Eqtb↑[5221+N].Int-Mem[R+3]↑.Int
;Q←VertBreak[Mem[P+4]↑.Hh.Lh,W,Mem[P+2]↑.Int];
Mem[R+3]↑.Int←Mem[R+3]↑.Int+BestHeightPlusDepth;
IF Eqtb↑[4800].Int>0  THEN--1011:--BEGIN BeginDiagnostic[];PrintNl[854];
PrintInt[N];Print[855];PrintScaled[W];PrintChar[44];
PrintScaled[BestHeightPlusDepth];Print[790];
IF Q=0  THEN PrintInt[-10000] ELSE IF Mem[Q]↑.Hh.B0=12  THEN PrintInt[Mem[
Q+1]↑.Int] ELSE PrintChar[48];EndDiagnostic[FALSE]; END--:1011--;
IF Eqtb↑[4817+N].Int#1000  THEN BestHeightPlusDepth←XOverN[
BestHeightPlusDepth,1000]*Eqtb↑[4817+N].Int;
PageSoFar↑[0]←PageSoFar↑[0]-BestHeightPlusDepth;Mem[R]↑.Hh.B0←1;
Mem[R+1]↑.Hh.Rh←Q;Mem[R+1]↑.Hh.Lh←P;
IF Q=0  THEN InsertPenalties←InsertPenalties-10000  ELSE IF Mem[Q]↑.Hh.
B0=12  THEN InsertPenalties←InsertPenalties+Mem[Q+1]↑.Int; END--:1010--;
 END; GOTO Label80; END--:1008--; ENDCASE =>Confusion[846]--:1000--;--1005:
IF Pi<10000  THEN BEGIN--1007:
IF PageSoFar↑[1]<PageSoFar↑[0] THEN IF(PageSoFar↑[3]#0)OR (PageSoFar
↑[4]#0)OR (PageSoFar↑[5]#0) THEN B←0  ELSE B←Badness[
PageSoFar↑[0]-PageSoFar↑[1],PageSoFar↑[2]] ELSE IF 
PageSoFar↑[1]-PageSoFar↑[0]>PageSoFar↑[6] THEN B←1073741823  ELSE B←Badness[
PageSoFar↑[1]-PageSoFar↑[0],PageSoFar↑[6]]--:1007--;
IF B<1073741823  THEN IF Pi<=-10000  THEN C←Pi  ELSE IF B<10000  THEN C←
B+Pi+InsertPenalties  ELSE C←100000  ELSE C←B;
IF InsertPenalties>=10000  THEN C←1073741823;
IF Eqtb↑[4800].Int>0  THEN--1006:--BEGIN BeginDiagnostic[];PrintNl[37];
Print[786];PrintTotals[];Print[849];PrintScaled[PageSoFar↑[0]];
Print[789];IF B=1073741823  THEN PrintChar[42] ELSE PrintInt[B];
Print[790];PrintInt[Pi];Print[850];
IF C=1073741823  THEN PrintChar[42] ELSE PrintInt[C];
IF C<=LeastPageCost  THEN PrintChar[35];EndDiagnostic[FALSE];
 END--:1006--;IF C<=LeastPageCost  THEN BEGIN BestPageBreak←P;
BestSize←PageSoFar↑[0];LeastPageCost←C;R←Mem[65000]↑.Hh.Rh;
WHILE R#65000 DO BEGIN Mem[R+2]↑.Hh.Lh←Mem[R+2]↑.Hh.Rh;R←Mem[R]↑.Hh.Rh;
 END ENDLOOP ; END;IF(C=1073741823)OR (Pi<=-10000) THEN BEGIN FireUp[P];
IF OutputActive  THEN  GOTO Label10; GOTO Label30; END; END--:1005--;
IF( INT[Mem[P]↑.Hh.B0]<10)OR ( INT[Mem[P]↑.Hh.B0]>11) THEN  GOTO Label80;EXITS Label90 => NULL};--1004:
IF Mem[P]↑.Hh.B0=11  THEN Q←P  ELSE BEGIN Q←Mem[P+1]↑.Hh.Lh;
PageSoFar↑[2+Mem[Q]↑.Hh.B0]←PageSoFar↑[2+Mem[Q]↑.Hh.B0]+Mem[Q+2]↑.Int;
PageSoFar↑[6]←PageSoFar↑[6]+Mem[Q+3]↑.Int;
IF(Mem[Q]↑.Hh.B1#0)AND (Mem[Q+3]↑.Int#0) THEN BEGIN BEGIN IF Interaction=3
 THEN NULL;PrintNl[134];Print[847]; END;BEGIN HelpPtr←4;HelpLine↑[3]←848;
HelpLine↑[2]←816;HelpLine↑[1]←817;HelpLine↑[0]←781; END;Error[];
R←NewSpec[Q];Mem[R]↑.Hh.B1←0;DeleteGlueRef[Q];Mem[P+1]↑.Hh.Lh←R; END;
 END;PageSoFar↑[1]←PageSoFar↑[1]+PageSoFar↑[7]+Mem[Q+1]↑.Int;
PageSoFar↑[7]←0--:1004--;EXITS Label80 => NULL};--1003:
IF PageSoFar↑[7]>PageMaxDepth  THEN BEGIN PageSoFar↑[1]←PageSoFar↑
[1]+PageSoFar↑[7]-PageMaxDepth;PageSoFar↑[7]←PageMaxDepth; END;
--:1003--Mem[PageTail]↑.Hh.Rh←P;PageTail←P;
Mem[64999]↑.Hh.Rh←Mem[P]↑.Hh.Rh;Mem[P]↑.Hh.Rh←0; GOTO Label30--:998--;EXITS Label31 => NULL};--999:
Mem[64999]↑.Hh.Rh←Mem[P]↑.Hh.Rh;Mem[P]↑.Hh.Rh←0;FlushNodeList[P]--:999--;
EXITS Label30 => NULL};--:997--EXIT; EXITS Label22 => NULL} ENDLOOP; IF Mem[64999]↑.Hh.Rh=0 THEN EXIT; ENDLOOP;--995:
IF NestPtr=0  THEN CurList.TailField←64999  ELSE Nest↑[0].TailField←
64999--:995--;EXITS Label10 => NULL}; END;--:994----1030:----1043:--
END.