OSDN Git Service

2003-10-21 Arnaud Charlet <charlet@act-europe.fr>
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-io.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUNTIME COMPONENTS                          --
4 --                                                                          --
5 --                              G N A T . I O                               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --           Copyright (C) 1995-2002 Ada Core Technologies, 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 ------------------------------------------------------------------------------
33
34 package body GNAT.IO is
35
36    Current_Out : File_Type := Stdout;
37    pragma Atomic (Current_Out);
38    --  Current output file (modified by Set_Output)
39
40    ---------
41    -- Get --
42    ---------
43
44    procedure Get (X : out Integer) is
45
46       function Get_Int return Integer;
47       pragma Import (C, Get_Int, "get_int");
48
49    begin
50       X := Get_Int;
51    end Get;
52
53    procedure Get (C : out Character) is
54
55       function Get_Char return Character;
56       pragma Import (C, Get_Char, "get_char");
57
58    begin
59       C := Get_Char;
60    end Get;
61
62    --------------
63    -- Get_Line --
64    --------------
65
66    procedure Get_Line (Item : out String; Last : out Natural) is
67       C : Character;
68
69    begin
70       for Nstore in Item'Range loop
71          Get (C);
72
73          if C = ASCII.LF then
74             Last := Nstore - 1;
75             return;
76
77          else
78             Item (Nstore) := C;
79          end if;
80       end loop;
81
82       Last := Item'Last;
83    end Get_Line;
84
85    --------------
86    -- New_Line --
87    --------------
88
89    procedure New_Line (File : File_Type; Spacing : Positive := 1) is
90    begin
91       for J in 1 .. Spacing loop
92          Put (File, ASCII.LF);
93       end loop;
94    end New_Line;
95
96    procedure New_Line (Spacing : Positive := 1) is
97    begin
98       New_Line (Current_Out, Spacing);
99    end New_Line;
100
101    ---------
102    -- Put --
103    ---------
104
105    procedure Put (X : Integer) is
106    begin
107       Put (Current_Out, X);
108    end Put;
109
110    procedure Put (File : File_Type; X : Integer) is
111
112       procedure Put_Int (X : Integer);
113       pragma Import (C, Put_Int, "put_int");
114
115       procedure Put_Int_Stderr (X : Integer);
116       pragma Import (C, Put_Int_Stderr, "put_int_stderr");
117
118    begin
119       case File is
120          when Stdout => Put_Int (X);
121          when Stderr => Put_Int_Stderr (X);
122       end case;
123    end Put;
124
125    procedure Put (C : Character) is
126    begin
127       Put (Current_Out, C);
128    end Put;
129
130    procedure Put (File : in File_Type; C : Character) is
131
132       procedure Put_Char (C : Character);
133       pragma Import (C, Put_Char, "put_char");
134
135       procedure Put_Char_Stderr (C : Character);
136       pragma Import (C, Put_Char_Stderr, "put_char_stderr");
137
138    begin
139       case File is
140          when Stdout => Put_Char (C);
141          when Stderr => Put_Char_Stderr (C);
142       end case;
143    end Put;
144
145    procedure Put (S : String) is
146    begin
147       Put (Current_Out, S);
148    end Put;
149
150    procedure Put (File : File_Type; S : String) is
151    begin
152       for J in S'Range loop
153          Put (File, S (J));
154       end loop;
155    end Put;
156
157    --------------
158    -- Put_Line --
159    --------------
160
161    procedure Put_Line (S : String) is
162    begin
163       Put_Line (Current_Out, S);
164    end Put_Line;
165
166    procedure Put_Line (File : File_Type; S : String) is
167    begin
168       Put (File, S);
169       New_Line (File);
170    end Put_Line;
171
172    ----------------
173    -- Set_Output --
174    ----------------
175
176    procedure Set_Output (File : in File_Type) is
177    begin
178       Current_Out := File;
179    end Set_Output;
180
181    ---------------------
182    -- Standard_Output --
183    ---------------------
184
185    function Standard_Output return File_Type is
186    begin
187       return Stdout;
188    end Standard_Output;
189
190    --------------------
191    -- Standard_Error --
192    --------------------
193
194    function Standard_Error return File_Type is
195    begin
196       return Stderr;
197    end Standard_Error;
198
199 end GNAT.IO;