FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / a-wtinau.adb
blob54396a5e6e6c927e36b1987ed5d6044e587af67a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUNTIME COMPONENTS --
4 -- --
5 -- A D A . W I D E _ T E X T _ I O . I N T E G E R _ A U X --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- --
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. --
22 -- --
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. --
29 -- --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 with Ada.Wide_Text_IO.Generic_Aux; use Ada.Wide_Text_IO.Generic_Aux;
37 with System.Img_BIU; use System.Img_BIU;
38 with System.Img_Int; use System.Img_Int;
39 with System.Img_LLB; use System.Img_LLB;
40 with System.Img_LLI; use System.Img_LLI;
41 with System.Img_LLW; use System.Img_LLW;
42 with System.Img_WIU; use System.Img_WIU;
43 with System.Val_Int; use System.Val_Int;
44 with System.Val_LLI; use System.Val_LLI;
46 package body Ada.Wide_Text_IO.Integer_Aux is
48 -----------------------
49 -- Local Subprograms --
50 -----------------------
52 procedure Load_Integer
53 (File : in File_Type;
54 Buf : out String;
55 Ptr : in out Natural);
56 -- This is an auxiliary routine that is used to load an possibly signed
57 -- integer literal value from the input file into Buf, starting at Ptr + 1.
58 -- On return, Ptr is set to the last character stored.
60 -------------
61 -- Get_Int --
62 -------------
64 procedure Get_Int
65 (File : in File_Type;
66 Item : out Integer;
67 Width : in Field)
69 Buf : String (1 .. Field'Last);
70 Ptr : aliased Integer := 1;
71 Stop : Integer := 0;
73 begin
74 if Width /= 0 then
75 Load_Width (File, Width, Buf, Stop);
76 String_Skip (Buf, Ptr);
77 else
78 Load_Integer (File, Buf, Stop);
79 end if;
81 Item := Scan_Integer (Buf, Ptr'Access, Stop);
82 Check_End_Of_Field (Buf, Stop, Ptr, Width);
83 end Get_Int;
85 -------------
86 -- Get_LLI --
87 -------------
89 procedure Get_LLI
90 (File : in File_Type;
91 Item : out Long_Long_Integer;
92 Width : in Field)
94 Buf : String (1 .. Field'Last);
95 Ptr : aliased Integer := 1;
96 Stop : Integer := 0;
98 begin
99 if Width /= 0 then
100 Load_Width (File, Width, Buf, Stop);
101 String_Skip (Buf, Ptr);
102 else
103 Load_Integer (File, Buf, Stop);
104 end if;
106 Item := Scan_Long_Long_Integer (Buf, Ptr'Access, Stop);
107 Check_End_Of_Field (Buf, Stop, Ptr, Width);
108 end Get_LLI;
110 --------------
111 -- Gets_Int --
112 --------------
114 procedure Gets_Int
115 (From : in String;
116 Item : out Integer;
117 Last : out Positive)
119 Pos : aliased Integer;
121 begin
122 String_Skip (From, Pos);
123 Item := Scan_Integer (From, Pos'Access, From'Last);
124 Last := Pos - 1;
126 exception
127 when Constraint_Error =>
128 Last := Pos - 1;
129 raise Data_Error;
131 end Gets_Int;
133 --------------
134 -- Gets_LLI --
135 --------------
137 procedure Gets_LLI
138 (From : in String;
139 Item : out Long_Long_Integer;
140 Last : out Positive)
142 Pos : aliased Integer;
144 begin
145 String_Skip (From, Pos);
146 Item := Scan_Long_Long_Integer (From, Pos'Access, From'Last);
147 Last := Pos - 1;
149 exception
150 when Constraint_Error =>
151 Last := Pos - 1;
152 raise Data_Error;
154 end Gets_LLI;
156 ------------------
157 -- Load_Integer --
158 ------------------
160 procedure Load_Integer
161 (File : in File_Type;
162 Buf : out String;
163 Ptr : in out Natural)
165 Hash_Loc : Natural;
166 Loaded : Boolean;
168 begin
169 Load_Skip (File);
170 Load (File, Buf, Ptr, '+', '-');
172 Load_Digits (File, Buf, Ptr, Loaded);
174 if Loaded then
175 Load (File, Buf, Ptr, '#', ':', Loaded);
177 if Loaded then
178 Hash_Loc := Ptr;
179 Load_Extended_Digits (File, Buf, Ptr);
180 Load (File, Buf, Ptr, Buf (Hash_Loc));
181 end if;
183 Load (File, Buf, Ptr, 'E', 'e', Loaded);
185 if Loaded then
187 -- Note: it is strange to allow a minus sign, since the syntax
188 -- does not, but that is what ACVC test CE3704F, case (6) wants.
190 Load (File, Buf, Ptr, '+', '-');
191 Load_Digits (File, Buf, Ptr);
192 end if;
193 end if;
194 end Load_Integer;
196 -------------
197 -- Put_Int --
198 -------------
200 procedure Put_Int
201 (File : in File_Type;
202 Item : in Integer;
203 Width : in Field;
204 Base : in Number_Base)
206 Buf : String (1 .. Field'Last);
207 Ptr : Natural := 0;
209 begin
210 if Base = 10 and then Width = 0 then
211 Set_Image_Integer (Item, Buf, Ptr);
212 elsif Base = 10 then
213 Set_Image_Width_Integer (Item, Width, Buf, Ptr);
214 else
215 Set_Image_Based_Integer (Item, Base, Width, Buf, Ptr);
216 end if;
218 Put_Item (File, Buf (1 .. Ptr));
219 end Put_Int;
221 -------------
222 -- Put_LLI --
223 -------------
225 procedure Put_LLI
226 (File : in File_Type;
227 Item : in Long_Long_Integer;
228 Width : in Field;
229 Base : in Number_Base)
231 Buf : String (1 .. Field'Last);
232 Ptr : Natural := 0;
234 begin
235 if Base = 10 and then Width = 0 then
236 Set_Image_Long_Long_Integer (Item, Buf, Ptr);
237 elsif Base = 10 then
238 Set_Image_Width_Long_Long_Integer (Item, Width, Buf, Ptr);
239 else
240 Set_Image_Based_Long_Long_Integer (Item, Base, Width, Buf, Ptr);
241 end if;
243 Put_Item (File, Buf (1 .. Ptr));
244 end Put_LLI;
246 --------------
247 -- Puts_Int --
248 --------------
250 procedure Puts_Int
251 (To : out String;
252 Item : in Integer;
253 Base : in Number_Base)
255 Buf : String (1 .. Field'Last);
256 Ptr : Natural := 0;
258 begin
259 if Base = 10 then
260 Set_Image_Width_Integer (Item, To'Length, Buf, Ptr);
261 else
262 Set_Image_Based_Integer (Item, Base, To'Length, Buf, Ptr);
263 end if;
265 if Ptr > To'Length then
266 raise Layout_Error;
267 else
268 To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
269 end if;
270 end Puts_Int;
272 --------------
273 -- Puts_LLI --
274 --------------
276 procedure Puts_LLI
277 (To : out String;
278 Item : in Long_Long_Integer;
279 Base : in Number_Base)
281 Buf : String (1 .. Field'Last);
282 Ptr : Natural := 0;
284 begin
285 if Base = 10 then
286 Set_Image_Width_Long_Long_Integer (Item, To'Length, Buf, Ptr);
287 else
288 Set_Image_Based_Long_Long_Integer (Item, Base, To'Length, Buf, Ptr);
289 end if;
291 if Ptr > To'Length then
292 raise Layout_Error;
293 else
294 To (To'First .. To'First + Ptr - 1) := Buf (1 .. Ptr);
295 end if;
296 end Puts_LLI;
298 end Ada.Wide_Text_IO.Integer_Aux;