Daily bump.
[official-gcc.git] / gcc / ada / a-tideau.adb
blob7f07129524cf4ca63f3dc8b40da2b6b1d1d7355a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUNTIME COMPONENTS --
4 -- --
5 -- A D A . T E X T _ I O . D E C I M A L _ A U X --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision: 1.1 $
10 -- --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 -- --
34 ------------------------------------------------------------------------------
36 with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
37 with Ada.Text_IO.Float_Aux; use Ada.Text_IO.Float_Aux;
39 with System.Img_Dec; use System.Img_Dec;
40 with System.Img_LLD; use System.Img_LLD;
41 with System.Val_Dec; use System.Val_Dec;
42 with System.Val_LLD; use System.Val_LLD;
44 package body Ada.Text_IO.Decimal_Aux is
46 -------------
47 -- Get_Dec --
48 -------------
50 function Get_Dec
51 (File : in File_Type;
52 Width : in Field;
53 Scale : Integer)
54 return Integer
56 Buf : String (1 .. Field'Last);
57 Ptr : aliased Integer;
58 Stop : Integer := 0;
59 Item : Integer;
61 begin
62 if Width /= 0 then
63 Load_Width (File, Width, Buf, Stop);
64 String_Skip (Buf, Ptr);
65 else
66 Load_Real (File, Buf, Stop);
67 Ptr := 1;
68 end if;
70 Item := Scan_Decimal (Buf, Ptr'Access, Stop, Scale);
71 Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
72 return Item;
73 end Get_Dec;
75 -------------
76 -- Get_LLD --
77 -------------
79 function Get_LLD
80 (File : in File_Type;
81 Width : in Field;
82 Scale : Integer)
83 return Long_Long_Integer
85 Buf : String (1 .. Field'Last);
86 Ptr : aliased Integer;
87 Stop : Integer := 0;
88 Item : Long_Long_Integer;
90 begin
91 if Width /= 0 then
92 Load_Width (File, Width, Buf, Stop);
93 String_Skip (Buf, Ptr);
94 else
95 Load_Real (File, Buf, Stop);
96 Ptr := 1;
97 end if;
99 Item := Scan_Long_Long_Decimal (Buf, Ptr'Access, Stop, Scale);
100 Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
101 return Item;
102 end Get_LLD;
104 --------------
105 -- Gets_Dec --
106 --------------
108 function Gets_Dec
109 (From : in String;
110 Last : access Positive;
111 Scale : Integer)
112 return Integer
114 Pos : aliased Integer;
115 Item : Integer;
117 begin
118 String_Skip (From, Pos);
119 Item := Scan_Decimal (From, Pos'Access, From'Last, Scale);
120 Last.all := Pos - 1;
121 return Item;
123 exception
124 when Constraint_Error =>
125 Last.all := Pos - 1;
126 raise Data_Error;
127 end Gets_Dec;
129 --------------
130 -- Gets_LLD --
131 --------------
133 function Gets_LLD
134 (From : in String;
135 Last : access Positive;
136 Scale : Integer)
137 return Long_Long_Integer
139 Pos : aliased Integer;
140 Item : Long_Long_Integer;
142 begin
143 String_Skip (From, Pos);
144 Item := Scan_Long_Long_Decimal (From, Pos'Access, From'Last, Scale);
145 Last.all := Pos - 1;
146 return Item;
148 exception
149 when Constraint_Error =>
150 Last.all := Pos - 1;
151 raise Data_Error;
152 end Gets_LLD;
154 -------------
155 -- Put_Dec --
156 -------------
158 procedure Put_Dec
159 (File : in File_Type;
160 Item : in Integer;
161 Fore : in Field;
162 Aft : in Field;
163 Exp : in Field;
164 Scale : Integer)
166 Buf : String (1 .. Field'Last);
167 Ptr : Natural := 0;
169 begin
170 Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
171 Put_Item (File, Buf (1 .. Ptr));
172 end Put_Dec;
174 -------------
175 -- Put_LLD --
176 -------------
178 procedure Put_LLD
179 (File : in File_Type;
180 Item : in Long_Long_Integer;
181 Fore : in Field;
182 Aft : in Field;
183 Exp : in Field;
184 Scale : Integer)
186 Buf : String (1 .. Field'Last);
187 Ptr : Natural := 0;
189 begin
190 Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
191 Put_Item (File, Buf (1 .. Ptr));
192 end Put_LLD;
194 --------------
195 -- Puts_Dec --
196 --------------
198 procedure Puts_Dec
199 (To : out String;
200 Item : in Integer;
201 Aft : in Field;
202 Exp : in Field;
203 Scale : Integer)
205 Buf : String (1 .. Field'Last);
206 Fore : Integer;
207 Ptr : Natural := 0;
209 begin
210 if Exp = 0 then
211 Fore := To'Length - 1 - Aft;
212 else
213 Fore := To'Length - 2 - Aft - Exp;
214 end if;
216 if Fore < 1 then
217 raise Layout_Error;
218 end if;
220 Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
222 if Ptr > To'Length then
223 raise Layout_Error;
224 else
225 To := Buf (1 .. Ptr);
226 end if;
227 end Puts_Dec;
229 --------------
230 -- Puts_Dec --
231 --------------
233 procedure Puts_LLD
234 (To : out String;
235 Item : in Long_Long_Integer;
236 Aft : in Field;
237 Exp : in Field;
238 Scale : Integer)
240 Buf : String (1 .. Field'Last);
241 Fore : Integer;
242 Ptr : Natural := 0;
244 begin
245 if Exp = 0 then
246 Fore := To'Length - 1 - Aft;
247 else
248 Fore := To'Length - 2 - Aft - Exp;
249 end if;
251 if Fore < 1 then
252 raise Layout_Error;
253 end if;
255 Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
257 if Ptr > To'Length then
258 raise Layout_Error;
259 else
260 To := Buf (1 .. Ptr);
261 end if;
262 end Puts_LLD;
264 end Ada.Text_IO.Decimal_Aux;