1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
35 with GNAT.OS_Lib; use GNAT.OS_Lib;
37 package body Output is
39 Current_FD : File_Descriptor := Standout;
40 -- File descriptor for current output
42 Special_Output_Proc : Output_Proc := null;
43 -- Record argument to last call to Set_Special_Output. If this is
44 -- non-null, then we are in special output mode.
46 -------------------------
47 -- Line Buffer Control --
48 -------------------------
50 -- Note: the following buffer and column position are maintained by
51 -- the subprograms defined in this package, and are not normally
52 -- directly modified or accessed by a client. However, a client is
53 -- permitted to modify these values, using the knowledge that only
54 -- Write_Eol actually generates any output.
56 Buffer_Max : constant := 8192;
57 Buffer : String (1 .. Buffer_Max + 1);
58 -- Buffer used to build output line. We do line buffering because it
59 -- is needed for the support of the debug-generated-code option (-gnatD).
60 -- Historically it was first added because on VMS, line buffering is
61 -- needed with certain file formats. So in any case line buffering must
62 -- be retained for this purpose, even if other reasons disappear. Note
63 -- any attempt to write more output to a line than can fit in the buffer
64 -- will be silently ignored.
66 Next_Column : Pos range 1 .. Buffer'Length + 1 := 1;
67 -- Column about to be written.
69 -----------------------
70 -- Local_Subprograms --
71 -----------------------
73 procedure Flush_Buffer;
74 -- Flush buffer if non-empty and reset column counter
76 ---------------------------
77 -- Cancel_Special_Output --
78 ---------------------------
80 procedure Cancel_Special_Output is
82 Special_Output_Proc := null;
83 end Cancel_Special_Output;
89 procedure Flush_Buffer is
90 Len : constant Natural := Natural (Next_Column - 1);
95 -- If Special_Output_Proc has been set, then use it
97 if Special_Output_Proc /= null then
98 Special_Output_Proc.all (Buffer (1 .. Len));
100 -- If output is not set, then output to either standard output
101 -- or standard error.
103 elsif Len /= Write (Current_FD, Buffer'Address, Len) then
105 -- If there are errors with standard error, just quit
107 if Current_FD = Standerr then
110 -- Otherwise, set the output to standard error before
111 -- reporting a failure and quitting.
114 Current_FD := Standerr;
116 Write_Line ("fatal error: disk full");
121 -- Buffer is now empty
131 function Column return Nat is
136 ------------------------
137 -- Set_Special_Output --
138 ------------------------
140 procedure Set_Special_Output (P : Output_Proc) is
142 Special_Output_Proc := P;
143 end Set_Special_Output;
145 ------------------------
146 -- Set_Standard_Error --
147 ------------------------
149 procedure Set_Standard_Error is
151 if Special_Output_Proc = null then
156 Current_FD := Standerr;
157 end Set_Standard_Error;
159 -------------------------
160 -- Set_Standard_Output --
161 -------------------------
163 procedure Set_Standard_Output is
165 if Special_Output_Proc = null then
170 Current_FD := Standout;
171 end Set_Standard_Output;
177 procedure w (C : Character) is
185 procedure w (S : String) is
191 procedure w (V : Int) is
197 procedure w (B : Boolean) is
206 procedure w (L : String; C : Character) is
213 procedure w (L : String; S : String) is
220 procedure w (L : String; V : Int) is
227 procedure w (L : String; B : Boolean) is
238 procedure Write_Char (C : Character) is
240 if Next_Column < Buffer'Length then
241 Buffer (Natural (Next_Column)) := C;
242 Next_Column := Next_Column + 1;
250 procedure Write_Eol is
252 Buffer (Natural (Next_Column)) := ASCII.LF;
253 Next_Column := Next_Column + 1;
261 procedure Write_Int (Val : Int) is
269 Write_Int (Val / 10);
272 Write_Char (Character'Val ((Val mod 10) + Character'Pos ('0')));
280 procedure Write_Line (S : String) is
290 procedure Write_Str (S : String) is
292 for J in S'Range loop