Oberon/V5/Out1.Mod

(* Oberon, Copyright 2001 ETH Zuerich Institut fuer Computersysteme, ETH Zentrum, CH-8092 Zuerich. Refer to the "General ETH Oberon System Source License" contract available at&#58; http&#58;//www.oberon.ethz.ch/ *) MODULE Out; (** portable *)	(* based on module from "Programming in Oberon" *) (** Simple output routines for writing text into the Oberon log or a separate viewer. *) IMPORT Texts, Viewers, Oberon, MenuViewers, TextFrames; CONST &#32;&#32;StandardMenu &#61; "System.Close System.Copy System.Grow Edit.Search Edit.Store"; TYPE Appender &#61; PROCEDURE; VAR T&#58; Texts.Text; W&#58; Texts.Writer; Append&#58; Appender; PROCEDURE TA; BEGIN Texts.Append(T, W.buf) END TA; PROCEDURE AppendImmediate*; BEGIN Append &#58;&#61; TA END AppendImmediate; PROCEDURE Null; BEGIN END Null; PROCEDURE AppendDelayed*; BEGIN Append &#58;&#61; Null END AppendDelayed; (** Write character. *) PROCEDURE Char*(ch&#58; CHAR); BEGIN &#9;Texts.Write(W, ch); Append END Char; (** Write a string. *) PROCEDURE String*(str&#58; ARRAY OF CHAR); BEGIN &#9;Texts.WriteString(W, str); Append END String; (** Write the integer i in n field positions. *) PROCEDURE Int*(i, n&#58; LONGINT); BEGIN &#9;Texts.WriteInt(W, i, n); Append END Int; (** Write the integer i in hexadecimal with a leading space. *) PROCEDURE Hex*(i&#58; LONGINT); BEGIN &#9;Texts.WriteHex(W, i); Append END Hex; (** Write the real x in n field positions. *) PROCEDURE Real*(x&#58; REAL; n&#58; INTEGER); BEGIN &#9;Texts.WriteReal(W, x, n); Append END Real; (** Write the real x in n field positions in fixed point notation with f fraction digits. *) PROCEDURE RealFix*(x&#58; REAL; n, f&#58; INTEGER); BEGIN &#9;Texts.WriteRealFix(W, x, n, f); Append END RealFix; (** Write the longreal x in n field positions. *) PROCEDURE LongReal*(x&#58; LONGREAL; n&#58; INTEGER); BEGIN &#9;Texts.WriteReal(W, x, n); Append END LongReal; (** Write the longreal x in n field positions in fixed point notation with f fraction digits. *) PROCEDURE LongRealFix*(x&#58; LONGREAL; n, f&#58; INTEGER); BEGIN &#9;Texts.WriteRealFix(W, x, n, f); Append END LongRealFix; (** Write a carriage return (CR or end-of-line). *) PROCEDURE Ln*; BEGIN &#9;Texts.WriteLn(W); Texts.Append(T, W.buf) END Ln; (** Open a separate viewer for output. *) PROCEDURE Open*; &#32;&#32;VAR V&#58; Viewers.Viewer; &#32;&#32;&#32;&#32;X, Y&#58; INTEGER; BEGIN &#9;IF T &#61; Oberon.Log THEN NEW(T); Texts.Open(T, "") END; &#9;Oberon.AllocateUserViewer(400, X, Y); &#9;(* &#9;Oberon.OpenText("Out.Text", T, 400, 200) &#9;&#42;) &#9;V &#58;&#61; MenuViewers.New( &#9;&#9;TextFrames.NewMenu("Out.Text", StandardMenu), &#9;&#9;TextFrames.NewText(T, 0), &#9;&#9;TextFrames.menuH, X, Y) END Open; (** Revert output to the system log. *) PROCEDURE Close*; BEGIN &#9;T &#58;&#61; Oberon.Log END Close; BEGIN &#9;Texts.OpenWriter(W); T &#58;&#61; Oberon.Log; AppendDelayed END Out. (** Remarks&#58; 1. Out uses a Writer from module Texts to write output to the log. After AppendImmediate, Out is slow because the log is updated after  every procedure call.  After AppendDelayed, updating is delayed to  the end of the line and performance is better.  Best performance is  when Texts is used directly. 2. Out.Open creates a new text and viewer for output.  Once this is  done, output can be sent to the system log again by executing Close. &#42;)