OSDN Git Service

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