home *** CD-ROM | disk | FTP | other *** search
- (*************************************************************************
-
- $RCSfile: Out.mod $
- Description: Formatted output on the standard output stream.
-
- Created by: fjc (Frank Copeland)
- $Revision: 1.3 $
- $Author: fjc $
- $Date: 1995/01/26 00:40:27 $
-
- Copyright © 1994-1995, Frank Copeland.
- This file is part of the Oberon-A Library.
- See Oberon-A.doc for conditions of use and distribution.
-
- *************************************************************************)
-
- <* STANDARD- *>
-
- MODULE Out;
-
- (**
- ** Extracts from the Oakwood Report are enclosed in quotes.
- **
- ** "Module Out provides a set of basic routines for formatted output of
- ** characters, numbers and strings. It assumes a standard output stream
- ** to which the symbols are written."
- *)
-
- IMPORT Dos, DosUtil, WbConsole, Reals;
-
-
- PROCEDURE Open*;
-
- VAR ignore : LONGINT;
-
- BEGIN (* Open *)
- IF Dos.Flush (Dos.Output()) THEN
- ignore := Dos.Seek (Dos.Output(), 0, Dos.beginning)
- END;
- END Open;
-
-
- PROCEDURE Write ( ch : CHAR );
- BEGIN (* Write *)
- Dos.PrintF ("%lc", ch)
- END Write;
-
-
- PROCEDURE Char* ( ch : CHAR );
-
- BEGIN (* Char *)
- DosUtil.HaltIfBreak ({Dos.ctrlC});
- Write (ch); IF Dos.Flush (Dos.Output()) THEN END
- END Char;
-
-
- PROCEDURE String* ( str : ARRAY OF CHAR );
-
- VAR ignore : LONGINT;
-
- <*$CopyArrays-*>
- BEGIN (* String *)
- DosUtil.HaltIfBreak ({Dos.ctrlC});
- ignore := Dos.PutStr (str); IF Dos.Flush (Dos.Output()) THEN END
- END String;
-
-
- PROCEDURE Int* ( x, n : LONGINT );
-
- VAR i : INTEGER; x0 : LONGINT; a : ARRAY 11 OF CHAR;
-
- BEGIN (* Int *)
- DosUtil.HaltIfBreak ({Dos.ctrlC});
- i := 0;
- IF x < 0 THEN
- IF x = MIN (LONGINT) THEN String (" -2147483648"); RETURN
- ELSE DEC (n); x0 := -x
- END
- ELSE x0 := x
- END;
- REPEAT a [i] := CHR (x0 MOD 10 + 30H); x0 := x0 DIV 10; INC (i)
- UNTIL x0 = 0;
- WHILE n > i DO Write (" "); DEC (n) END;
- IF x < 0 THEN Write ("-") END;
- REPEAT DEC (i); Write (a [i]) UNTIL i = 0;
- IF Dos.Flush (Dos.Output()) THEN END
- END Int;
-
-
- PROCEDURE Real* ( x : REAL; n : INTEGER );
-
- CONST maxD = 32;
-
- VAR e : INTEGER; x0 : REAL; d : ARRAY maxD OF CHAR;
-
- BEGIN (* Real *)
- DosUtil.HaltIfBreak ({Dos.ctrlC});
- e := Reals.Expo (x);
- IF e = 0 THEN
- Write ("0");
- REPEAT Write (" "); DEC (n) UNTIL n <= 3
- ELSIF e = 255 THEN
- String ("NaN");
- WHILE n > 4 DO Write (" "); DEC (n) END
- ELSE
- IF n <= 9 THEN n := 3 ELSE DEC (n, 6) END;
- REPEAT Write (" "); DEC (n) UNTIL n <= 8;
- (* there are 2 < n <= 8 digits to be written *)
- IF x < 0.0 THEN Write ("-"); x := -x ELSE Write (" ") END;
- e := (e - 127) * 77 DIV 256;
- IF e >= 0 THEN x := x / Reals.Ten (e) ELSE x := Reals.Ten (-e) * x END;
- IF x >= 10.0 THEN x := 0.1 * x; INC (e) END;
- x0 := Reals.Ten (n - 1); x := x0 * x + 0.5;
- IF x >= 10.0 * x0 THEN x := x * 0.1; INC (e) END;
- Reals.Convert (x, n, d);
- DEC (n); Write (d [n]); Write (".");
- REPEAT DEC (n); Write (d [n]) UNTIL n = 0;
- Write ("E");
- IF e < 0 THEN Write ("-"); e := -e ELSE Write ("+") END;
- Write (CHR (e DIV 10 + 30H)); Write (CHR (e MOD 10 + 30H))
- END;
- IF Dos.Flush (Dos.Output()) THEN END
- END Real;
-
-
- PROCEDURE LongReal* ( x : LONGREAL; n : INTEGER );
-
- BEGIN (* LongReal *)
- Real (SHORT(x), n)
- END LongReal;
-
-
- PROCEDURE Ln*;
-
- BEGIN (* Ln *)
- Char (0AX)
- END Ln;
-
- END Out.
-