DIRECTORY Ascii USING [CR, TAB], Format USING [Text], ParseDefs USING [commentString], PrintingDefs USING [outProc, echoSource], Storage USING [AppendChar, CopyString, FreeString]; PrintingImpl: PROGRAM IMPORTS Format, ParseDefs, PrintingDefs, Storage EXPORTS PrintingDefs = { OutCode: PUBLIC PROCEDURE [s: LONG STRING, indent: CARDINAL] = { FOR i: CARDINAL IN [0..indent) DO Format.Text[PrintingDefs.outProc^, " "L]; ENDLOOP; IF s # NIL THEN Format.Text[PrintingDefs.outProc^, s]; }; GetComment: PUBLIC PROCEDURE [] RETURNS [result: LONG STRING] = { limit, j: CARDINAL; newComment: LONG STRING; result _ Storage.CopyString[s: ""L, longer: 128]; FOR limit DECREASING IN [0..ParseDefs.commentString.length) DO IF ParseDefs.commentString.text[limit] = Ascii.CR THEN EXIT REPEAT FINISHED => RETURN [result]; ENDLOOP; newComment _ Storage.CopyString[s: ""L, longer: 128]; FOR j IN [0..limit] DO Storage.AppendChar[@result, ParseDefs.commentString.text[j]]; ENDLOOP; FOR j IN (limit..ParseDefs.commentString.length) DO Storage.AppendChar[@newComment, ParseDefs.commentString.text[j]]; ENDLOOP; Storage.FreeString[ParseDefs.commentString]; ParseDefs.commentString _ newComment; }; PrintComments: PUBLIC PROCEDURE [s: LONG STRING, indent: CARDINAL] = { i: CARDINAL; buffer: LONG STRING = [1]; IF NOT PrintingDefs.echoSource THEN RETURN; IF s.length = 0 THEN RETURN; buffer.length _ 1; OutCode["--"L, indent + 1]; i _ 0; WHILE i < s.length AND s.text[i] = Ascii.TAB DO s.text[i] _ ' ; i _ i + 1; ENDLOOP; i _ 0; WHILE i < s.length DO SELECT s.text[i] FROM Ascii.CR => { OutCode["\n"L, 0]; IF i < s.length - 1 THEN { j: CARDINAL; OutCode["--"L, indent + 1]; j _ i + 1; WHILE j < s.length AND s.text[j] = Ascii.TAB DO s.text[j] _ ' ; j _ j + 1; ENDLOOP; }; }; '- => { IF s.length > i + 1 AND s.text[i + 1] = '- THEN s.text[i + 1] _ '_; buffer.text[0] _ s.text[i]; OutCode[buffer, 0]; }; ENDCASE => { buffer.text[0] _ s.text[i]; OutCode[buffer, 0]; }; i _ i + 1; ENDLOOP; }; }.