1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with GNAT.OS_Lib; use GNAT.OS_Lib;
36 package body Output is
38 Current_FD : File_Descriptor := Standout;
39 -- File descriptor for current output
41 Special_Output_Proc : Output_Proc := null;
42 -- Record argument to last call to Set_Special_Output. If this is
43 -- non-null, then we are in special output mode.
45 -----------------------
46 -- Local_Subprograms --
47 -----------------------
49 procedure Flush_Buffer;
50 -- Flush buffer if non-empty and reset column counter
52 ---------------------------
53 -- Cancel_Special_Output --
54 ---------------------------
56 procedure Cancel_Special_Output is
58 Special_Output_Proc := null;
59 end Cancel_Special_Output;
65 function Column return Pos is
67 return Pos (Next_Col);
74 procedure Flush_Buffer is
75 Len : constant Natural := Next_Col - 1;
80 -- If Special_Output_Proc has been set, then use it
82 if Special_Output_Proc /= null then
83 Special_Output_Proc.all (Buffer (1 .. Len));
85 -- If output is not set, then output to either standard output
88 elsif Len /= Write (Current_FD, Buffer'Address, Len) then
90 -- If there are errors with standard error, just quit
92 if Current_FD = Standerr then
95 -- Otherwise, set the output to standard error before
96 -- reporting a failure and quitting.
99 Current_FD := Standerr;
101 Write_Line ("fatal error: disk full");
106 -- Buffer is now empty
112 ---------------------------
113 -- Restore_Output_Buffer --
114 ---------------------------
116 procedure Restore_Output_Buffer (S : Saved_Output_Buffer) is
118 Next_Col := S.Next_Col;
119 Buffer (1 .. Next_Col - 1) := S.Buffer (1 .. Next_Col - 1);
120 end Restore_Output_Buffer;
122 ------------------------
123 -- Save_Output_Buffer --
124 ------------------------
126 function Save_Output_Buffer return Saved_Output_Buffer is
127 S : Saved_Output_Buffer;
129 S.Buffer (1 .. Next_Col - 1) := Buffer (1 .. Next_Col - 1);
130 S.Next_Col := Next_Col;
133 end Save_Output_Buffer;
135 ------------------------
136 -- Set_Special_Output --
137 ------------------------
139 procedure Set_Special_Output (P : Output_Proc) is
141 Special_Output_Proc := P;
142 end Set_Special_Output;
144 ------------------------
145 -- Set_Standard_Error --
146 ------------------------
148 procedure Set_Standard_Error is
150 if Special_Output_Proc = null then
155 Current_FD := Standerr;
156 end Set_Standard_Error;
158 -------------------------
159 -- Set_Standard_Output --
160 -------------------------
162 procedure Set_Standard_Output is
164 if Special_Output_Proc = null then
169 Current_FD := Standout;
170 end Set_Standard_Output;
176 procedure w (C : Character) is
184 procedure w (S : String) is
190 procedure w (V : Int) is
196 procedure w (B : Boolean) is
205 procedure w (L : String; C : Character) is
212 procedure w (L : String; S : String) is
219 procedure w (L : String; V : Int) is
226 procedure w (L : String; B : Boolean) is
237 procedure Write_Char (C : Character) is
239 if Next_Col = Buffer'Length then
246 Buffer (Next_Col) := C;
247 Next_Col := Next_Col + 1;
255 procedure Write_Eol is
257 Buffer (Next_Col) := ASCII.LF;
258 Next_Col := Next_Col + 1;
262 ----------------------
263 -- Write_Erase_Char --
264 ----------------------
266 procedure Write_Erase_Char (C : Character) is
268 if Next_Col /= 1 and then Buffer (Next_Col - 1) = C then
269 Next_Col := Next_Col - 1;
271 end Write_Erase_Char;
277 procedure Write_Int (Val : Int) is
285 Write_Int (Val / 10);
288 Write_Char (Character'Val ((Val mod 10) + Character'Pos ('0')));
296 procedure Write_Line (S : String) is
306 procedure Write_Spaces (N : Nat) is
317 procedure Write_Str (S : String) is
319 for J in S'Range loop