Oberon/V5/Out.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 (* IN V5 *); (** 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"; VAR T&#58; Texts.Text; W&#58; Texts.Writer; epoch&#58; CHAR; (* &#32;&#32;epoch &#61; "i" denoting "append immediately", &#32;&#32;epoch &#61; "e" denoting "append at end of line". *) PROCEDURE SetEpoch*(c&#58; CHAR); BEGIN epoch &#58;&#61; c END SetEpoch; PROCEDURE Append; BEGIN &#32;&#32;IF epoch &#61; "i" THEN &#32;&#32;&#32;&#32;Texts.Append(T, W.buf) &#32;&#32;ELSIF epoch &#61; "e" THEN (* Postpone *) &#32;&#32;ELSE &#32;&#32;&#32;&#32;Texts.WriteString(W, "Character "); Texts.Write(W, epoch); &#32;&#32;&#32;&#32;Texts.WriteString(W, " in epoch not recognizable."); Texts.WriteLn(W); &#32;&#32;&#32;&#32;Texts.Append(T, W.buf) &#32;&#32;END END Append; (** 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; epoch &#58;&#61; "e" END Out. (** Remarks&#58; 1. Out uses a Writer from module Texts to write output to the log. When epoch &#61; "i" Out is slow because the log is updated after every  procedure call.  When epoch &#61; "e" performance is better.  Best  performance is when Texts is used directly.  SetEpoch is exported  to allow programmatical change of epoch. 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;)