* gcc.dg/compat/struct-layout-1_generate.c (dg_options): New. Moved
[official-gcc.git] / gcc / ada / output.adb
blob6a2a723e580011f4c4f0ebff1d8ebc1b816cda8a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- O U T P U T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
10 -- --
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. --
21 -- --
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. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 with System.OS_Lib; use System.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
57 begin
58 Special_Output_Proc := null;
59 end Cancel_Special_Output;
61 ------------
62 -- Column --
63 ------------
65 function Column return Pos is
66 begin
67 return Pos (Next_Col);
68 end Column;
70 ------------------
71 -- Flush_Buffer --
72 ------------------
74 procedure Flush_Buffer is
75 Len : constant Natural := Next_Col - 1;
77 begin
78 if Len /= 0 then
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
86 -- or standard error.
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
93 OS_Exit (2);
95 -- Otherwise, set the output to standard error before
96 -- reporting a failure and quitting.
98 else
99 Current_FD := Standerr;
100 Next_Col := 1;
101 Write_Line ("fatal error: disk full");
102 OS_Exit (2);
103 end if;
104 end if;
106 -- Buffer is now empty
108 Next_Col := 1;
109 end if;
110 end Flush_Buffer;
112 ---------------------------
113 -- Restore_Output_Buffer --
114 ---------------------------
116 procedure Restore_Output_Buffer (S : Saved_Output_Buffer) is
117 begin
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;
128 begin
129 S.Buffer (1 .. Next_Col - 1) := Buffer (1 .. Next_Col - 1);
130 S.Next_Col := Next_Col;
131 Next_Col := 1;
132 return S;
133 end Save_Output_Buffer;
135 ------------------------
136 -- Set_Special_Output --
137 ------------------------
139 procedure Set_Special_Output (P : Output_Proc) is
140 begin
141 Special_Output_Proc := P;
142 end Set_Special_Output;
144 ------------------------
145 -- Set_Standard_Error --
146 ------------------------
148 procedure Set_Standard_Error is
149 begin
150 if Special_Output_Proc = null then
151 Flush_Buffer;
152 Next_Col := 1;
153 end if;
155 Current_FD := Standerr;
156 end Set_Standard_Error;
158 -------------------------
159 -- Set_Standard_Output --
160 -------------------------
162 procedure Set_Standard_Output is
163 begin
164 if Special_Output_Proc = null then
165 Flush_Buffer;
166 Next_Col := 1;
167 end if;
169 Current_FD := Standout;
170 end Set_Standard_Output;
172 -------
173 -- w --
174 -------
176 procedure w (C : Character) is
177 begin
178 Write_Char (''');
179 Write_Char (C);
180 Write_Char (''');
181 Write_Eol;
182 end w;
184 procedure w (S : String) is
185 begin
186 Write_Str (S);
187 Write_Eol;
188 end w;
190 procedure w (V : Int) is
191 begin
192 Write_Int (V);
193 Write_Eol;
194 end w;
196 procedure w (B : Boolean) is
197 begin
198 if B then
199 w ("True");
200 else
201 w ("False");
202 end if;
203 end w;
205 procedure w (L : String; C : Character) is
206 begin
207 Write_Str (L);
208 Write_Char (' ');
209 w (C);
210 end w;
212 procedure w (L : String; S : String) is
213 begin
214 Write_Str (L);
215 Write_Char (' ');
216 w (S);
217 end w;
219 procedure w (L : String; V : Int) is
220 begin
221 Write_Str (L);
222 Write_Char (' ');
223 w (V);
224 end w;
226 procedure w (L : String; B : Boolean) is
227 begin
228 Write_Str (L);
229 Write_Char (' ');
230 w (B);
231 end w;
233 ----------------
234 -- Write_Char --
235 ----------------
237 procedure Write_Char (C : Character) is
238 begin
239 if Next_Col = Buffer'Length then
240 Write_Eol;
241 end if;
243 if C = ASCII.LF then
244 Write_Eol;
245 else
246 Buffer (Next_Col) := C;
247 Next_Col := Next_Col + 1;
248 end if;
249 end Write_Char;
251 ---------------
252 -- Write_Eol --
253 ---------------
255 procedure Write_Eol is
256 begin
257 -- Remove any trailing space
259 while Next_Col > 1 and then Buffer (Next_Col - 1) = ' ' loop
260 Next_Col := Next_Col - 1;
261 end loop;
263 Buffer (Next_Col) := ASCII.LF;
264 Next_Col := Next_Col + 1;
265 Flush_Buffer;
266 end Write_Eol;
268 ---------------------------
269 -- Write_Eol_Keep_Blanks --
270 ---------------------------
272 procedure Write_Eol_Keep_Blanks is
273 begin
274 Buffer (Next_Col) := ASCII.LF;
275 Next_Col := Next_Col + 1;
276 Flush_Buffer;
277 end Write_Eol_Keep_Blanks;
279 ----------------------
280 -- Write_Erase_Char --
281 ----------------------
283 procedure Write_Erase_Char (C : Character) is
284 begin
285 if Next_Col /= 1 and then Buffer (Next_Col - 1) = C then
286 Next_Col := Next_Col - 1;
287 end if;
288 end Write_Erase_Char;
290 ---------------
291 -- Write_Int --
292 ---------------
294 procedure Write_Int (Val : Int) is
295 begin
296 if Val < 0 then
297 Write_Char ('-');
298 Write_Int (-Val);
300 else
301 if Val > 9 then
302 Write_Int (Val / 10);
303 end if;
305 Write_Char (Character'Val ((Val mod 10) + Character'Pos ('0')));
306 end if;
307 end Write_Int;
309 ----------------
310 -- Write_Line --
311 ----------------
313 procedure Write_Line (S : String) is
314 begin
315 Write_Str (S);
316 Write_Eol;
317 end Write_Line;
319 ------------------
320 -- Write_Spaces --
321 ------------------
323 procedure Write_Spaces (N : Nat) is
324 begin
325 for J in 1 .. N loop
326 Write_Char (' ');
327 end loop;
328 end Write_Spaces;
330 ---------------
331 -- Write_Str --
332 ---------------
334 procedure Write_Str (S : String) is
335 begin
336 for J in S'Range loop
337 Write_Char (S (J));
338 end loop;
339 end Write_Str;
341 end Output;