-- file: WeaveOutput.mesa
-- Pascal-to-Mesa translator output, translated at September 15, 1985 4:11:16 pm PDT


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  WeaveProcs,
  WeaveProcArray,
  WeaveVars;

WeaveOutput: PROGRAM IMPORTS PascalWizardFiles, WeaveProcs, WeaveProcArray, WeaveVars EXPORTS WeaveProcs = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, WeaveProcs, WeaveProcArray, WeaveVars;
--205:-- PushLevel: PROCEDURE[P: TextPointer]
 = 
BEGIN IF StackPtr=StackSize  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "stack"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[];
 END  ELSE BEGIN IF  INT[StackPtr]>0  THEN Stack↑[StackPtr]←CurState;
StackPtr←StackPtr+1;
--IF STACK←PTR>MAX←STACK←PTR THEN MAX←STACK←PTR:=STACK←PTR;
CurState.TokField←TokStart↑[P];CurState.EndField←TokStart↑[P+1];
 END; END;--:205----207:-- GetOutput: PROCEDURE RETURNS[GetOutputResult: EightBits] = 
BEGIN 
 A:SixteenBits;
 DO {--Label20:--WHILE CurState.TokField=CurState.EndField DO BEGIN
StackPtr←StackPtr-1;CurState←Stack↑[StackPtr]; END ENDLOOP ;
A←TokMem↑[CurState.TokField];
CurState.TokField← INT[CurState.TokField]+1;
IF  INT[A]>=256  THEN BEGIN CurName← A MOD 10240;SELECT  A /10240 FROM 2 =>A←129;
3 =>A←128;4 =>BEGIN PushLevel[CurName]; GOTO Label20; END;
5 =>BEGIN PushLevel[CurName];CurState.ModeField←0; GOTO Label20; END;
 ENDCASE =>A←130 ; END;--IF TROUBLE←SHOOTING THEN DEBUG←HELP;
GetOutputResult←A;EXIT; EXITS Label20 => NULL} ENDLOOP; END;--:207----208:--
 OutputPascal: PROCEDURE
 = 
BEGIN SaveTokPtr, SaveTextPtr, SaveNextControl:SixteenBits;
P:TextPointer; SaveTokPtr←TokPtr;SaveTextPtr←TextPtr;
SaveNextControl←NextControl;NextControl←124;P←PascalTranslate[];
TokMem↑[TokPtr]←P+51200;TokPtr←TokPtr+1;MakeOutput[];
--IF TEXT←PTR>MAX←TXT←PTR THEN MAX←TXT←PTR:=TEXT←PTR;
-- IF TOK←PTR>MAX←TOK←PTR THEN MAX←TOK←PTR:=TOK←PTR;
TextPtr←SaveTextPtr;TokPtr←SaveTokPtr;
NextControl←SaveNextControl; END;--:208----209:-- 
 MakeOutput: PROCEDURE = 
BEGIN  A:EightBits;B:EightBits;K, KLimit:PascalInteger[0..MaxBytes];
W:PascalInteger[0..1];J:PascalInteger[0..LongBufSize];StringDelimiter:AsciiCode;
SaveLoc, SaveLimit:PascalInteger[0..LongBufSize];CurModName:NamePointer;
SaveMode:Mode; TokMem↑[TokPtr]←143;TokPtr←TokPtr+1;
TextPtr←TextPtr+1;TokStart↑[TextPtr]←TokPtr;
PushLevel[TextPtr-1];{WHILE TRUE DO BEGIN A←GetOutput[];
DO {--Label21:--SELECT A FROM 143 => GOTO Label10;130,129 =>--210:
BEGIN BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←92; END;
IF A=130  THEN IF  INT[ByteStart↑[CurName+2]]-ByteStart↑[CurName]=1  THEN
BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←124;
 END  ELSE BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←92;
 END  ELSE BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←38; END;
IF  INT[ByteStart↑[CurName+2]]-ByteStart↑[CurName]=1  THEN BEGIN IF 
OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←ByteMem[ CurName MOD 2, ByteStart↑[CurName]]↑;
 END  ELSE OutName[CurName]; END--:210--;128 =>--214:
BEGIN BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←92;IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←88; END;CurXref←Xref↑[CurName];
IF  INT[Xmem↑[CurXref].NumField]>=10240  THEN BEGIN OutMod[ INT[Xmem↑[CurXref].
NumField]-10240];
IF PhaseThree  THEN BEGIN CurXref←Xmem↑[CurXref].XlinkField;
WHILE  INT[Xmem↑[CurXref].NumField]>=10240 DO BEGIN BEGIN IF 
OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;OutBuf↑[OutPtr]←44;
IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←32; END;OutMod[ INT[Xmem↑[CurXref].NumField]-10240];
CurXref←Xmem↑[CurXref].XlinkField; END ENDLOOP ; END;
 END  ELSE BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←48; END;BEGIN IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←58; END;--215:
K←ByteStart↑[CurName];W← CurName MOD 2;
KLimit←ByteStart↑[CurName+2];CurModName←CurName;
WHILE  INT[K]<KLimit DO BEGIN B←ByteMem[W, K]↑;K←K+1;IF B=64  THEN--216:
BEGIN IF ByteMem[W, K]↑#64  THEN BEGIN BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! Illegal control code in section name:"]; END;
BEGIN PascalWriteLn[file: @TermOut];PascalWriteLongString[file: @TermOut, item: "<"]; END;PrintId[CurModName];
PascalWriteLongString[file: @TermOut, item: "> "];History←2; END;K←K+1; END--:216--;
IF B#124  THEN BEGIN IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←B; END  ELSE BEGIN--217:-- J←Limit+1;
Buffer↑[J]←124;StringDelimiter←0;
{WHILE TRUE DO BEGIN IF  INT[K]>=KLimit  THEN BEGIN BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! Pascal text in section name didn't end:"]; END;
BEGIN PascalWriteLn[file: @TermOut];PascalWriteLongString[file: @TermOut, item: "<"]; END;PrintId[CurModName];
PascalWriteLongString[file: @TermOut, item: "> "];History←2; GOTO Label31; END;B←ByteMem[W, K]↑;K←K+1;
IF B=64  THEN--218:
BEGIN IF  INT[J]>LongBufSize-4  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "buffer"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;Buffer↑[J+1]←64;Buffer↑[J+2]←ByteMem[W, K]↑;
J←J+2;K←K+1; END--:218
 ELSE BEGIN IF(B=34)OR (B=39) THEN IF StringDelimiter=0  THEN
StringDelimiter←B  ELSE IF StringDelimiter=B  THEN StringDelimiter←0;
IF(B#124)OR (StringDelimiter#0) THEN BEGIN IF  INT[J]>LongBufSize-3  THEN
BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "buffer"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;J←J+1;Buffer↑[J]←B; END  ELSE  GOTO Label31; END; END ENDLOOP ;
EXITS Label31 => NULL};--:217--SaveLoc←Loc;SaveLimit←Limit;Loc←Limit+2;Limit←J+1;
Buffer↑[Limit]←124;OutputPascal[];Loc←SaveLoc;Limit←SaveLimit; END;
 END--:215-- ENDLOOP ;BEGIN IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←92;
IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←88; END; END--:214--;131,133,132 =>--211:
BEGIN BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←92;IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←109;
IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←97;IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←116;
IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←104; END;
IF A=131  THEN BEGIN IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←98;
IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←105;IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←110;
 END  ELSE IF A=132  THEN BEGIN IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←114;
IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←101;IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←108;
 END  ELSE BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←111;IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←112; END;
BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←123; END; END--:211--;135 =>BEGIN DO A←GetOutput[];
 IF( INT[A]<139)OR ( INT[A]>142) THEN EXIT; ENDLOOP; GOTO Label21; END;134 =>BEGIN DO A←GetOutput[];
 IF(( INT[A]<139)AND (A#32))OR ( INT[A]>142) THEN EXIT; ENDLOOP; GOTO Label21; END;
136,137,138,139,140,141,142 =>--212:
IF  INT[A]<140  THEN BEGIN IF CurState.ModeField=1  THEN BEGIN BEGIN IF
OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←92;IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←A-87; END;
IF A=138  THEN BEGIN IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←GetOutput[];
 END ; END  ELSE IF A=138  THEN B←GetOutput []; END  ELSE--213:--BEGIN B←A;
SaveMode←CurState.ModeField;WHILE TRUE DO BEGIN A←GetOutput[];
IF(A=135)OR (A=134) THEN  GOTO Label21;
IF((A#32)AND ( INT[A]<140))OR ( INT[A]>142) THEN BEGIN IF SaveMode=1  THEN BEGIN IF
 INT[OutPtr]>3  THEN IF(OutBuf↑[OutPtr]=80)AND (OutBuf↑[OutPtr-1]=92)AND (
OutBuf↑[OutPtr-2]=89)AND (OutBuf↑[OutPtr-3]=92) THEN  GOTO Label21;
BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←92;IF OutPtr=LineLength  THEN BreakOut[];
OutPtr←OutPtr+1;OutBuf↑[OutPtr]←B-87; END;
IF A#143  THEN FinishLine[];
 END  ELSE IF(A#143)AND (CurState.ModeField=0) THEN BEGIN IF 
OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;OutBuf↑[OutPtr]←32; END;
 GOTO Label21; END;IF  INT[A]>B  THEN B←A; END ENDLOOP ; END--:213----:212--;
 ENDCASE =>BEGIN IF OutPtr=LineLength  THEN BreakOut[];OutPtr←OutPtr+1;
OutBuf↑[OutPtr]←A; END ;EXIT; EXITS Label21 => NULL} ENDLOOP; END ENDLOOP ;EXITS Label10 => NULL}; END;--:209----227:

END.