* arm.c (FL_WBUF): Define.
[official-gcc.git] / gcc / ada / a-tideau.adb
blob56d40508c950591be22623ff37ce39f0cc173100
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 -- Copyright (C) 1992-2001 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, 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 ------------------------------------------------------------------------------
34 with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
35 with Ada.Text_IO.Float_Aux; use Ada.Text_IO.Float_Aux;
37 with System.Img_Dec; use System.Img_Dec;
38 with System.Img_LLD; use System.Img_LLD;
39 with System.Val_Dec; use System.Val_Dec;
40 with System.Val_LLD; use System.Val_LLD;
42 package body Ada.Text_IO.Decimal_Aux is
44 -------------
45 -- Get_Dec --
46 -------------
48 function Get_Dec
49 (File : in File_Type;
50 Width : in Field;
51 Scale : Integer)
52 return Integer
54 Buf : String (1 .. Field'Last);
55 Ptr : aliased Integer;
56 Stop : Integer := 0;
57 Item : Integer;
59 begin
60 if Width /= 0 then
61 Load_Width (File, Width, Buf, Stop);
62 String_Skip (Buf, Ptr);
63 else
64 Load_Real (File, Buf, Stop);
65 Ptr := 1;
66 end if;
68 Item := Scan_Decimal (Buf, Ptr'Access, Stop, Scale);
69 Check_End_Of_Field (Buf, Stop, Ptr, Width);
70 return Item;
71 end Get_Dec;
73 -------------
74 -- Get_LLD --
75 -------------
77 function Get_LLD
78 (File : in File_Type;
79 Width : in Field;
80 Scale : Integer)
81 return Long_Long_Integer
83 Buf : String (1 .. Field'Last);
84 Ptr : aliased Integer;
85 Stop : Integer := 0;
86 Item : Long_Long_Integer;
88 begin
89 if Width /= 0 then
90 Load_Width (File, Width, Buf, Stop);
91 String_Skip (Buf, Ptr);
92 else
93 Load_Real (File, Buf, Stop);
94 Ptr := 1;
95 end if;
97 Item := Scan_Long_Long_Decimal (Buf, Ptr'Access, Stop, Scale);
98 Check_End_Of_Field (Buf, Stop, Ptr, Width);
99 return Item;
100 end Get_LLD;
102 --------------
103 -- Gets_Dec --
104 --------------
106 function Gets_Dec
107 (From : in String;
108 Last : access Positive;
109 Scale : Integer)
110 return Integer
112 Pos : aliased Integer;
113 Item : Integer;
115 begin
116 String_Skip (From, Pos);
117 Item := Scan_Decimal (From, Pos'Access, From'Last, Scale);
118 Last.all := Pos - 1;
119 return Item;
121 exception
122 when Constraint_Error =>
123 Last.all := Pos - 1;
124 raise Data_Error;
125 end Gets_Dec;
127 --------------
128 -- Gets_LLD --
129 --------------
131 function Gets_LLD
132 (From : in String;
133 Last : access Positive;
134 Scale : Integer)
135 return Long_Long_Integer
137 Pos : aliased Integer;
138 Item : Long_Long_Integer;
140 begin
141 String_Skip (From, Pos);
142 Item := Scan_Long_Long_Decimal (From, Pos'Access, From'Last, Scale);
143 Last.all := Pos - 1;
144 return Item;
146 exception
147 when Constraint_Error =>
148 Last.all := Pos - 1;
149 raise Data_Error;
150 end Gets_LLD;
152 -------------
153 -- Put_Dec --
154 -------------
156 procedure Put_Dec
157 (File : in File_Type;
158 Item : in Integer;
159 Fore : in Field;
160 Aft : in Field;
161 Exp : in Field;
162 Scale : Integer)
164 Buf : String (1 .. Field'Last);
165 Ptr : Natural := 0;
167 begin
168 Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
169 Put_Item (File, Buf (1 .. Ptr));
170 end Put_Dec;
172 -------------
173 -- Put_LLD --
174 -------------
176 procedure Put_LLD
177 (File : in File_Type;
178 Item : in Long_Long_Integer;
179 Fore : in Field;
180 Aft : in Field;
181 Exp : in Field;
182 Scale : Integer)
184 Buf : String (1 .. Field'Last);
185 Ptr : Natural := 0;
187 begin
188 Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
189 Put_Item (File, Buf (1 .. Ptr));
190 end Put_LLD;
192 --------------
193 -- Puts_Dec --
194 --------------
196 procedure Puts_Dec
197 (To : out String;
198 Item : in Integer;
199 Aft : in Field;
200 Exp : in Field;
201 Scale : Integer)
203 Buf : String (1 .. Field'Last);
204 Fore : Integer;
205 Ptr : Natural := 0;
207 begin
208 if Exp = 0 then
209 Fore := To'Length - 1 - Aft;
210 else
211 Fore := To'Length - 2 - Aft - Exp;
212 end if;
214 if Fore < 1 then
215 raise Layout_Error;
216 end if;
218 Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
220 if Ptr > To'Length then
221 raise Layout_Error;
222 else
223 To := Buf (1 .. Ptr);
224 end if;
225 end Puts_Dec;
227 --------------
228 -- Puts_Dec --
229 --------------
231 procedure Puts_LLD
232 (To : out String;
233 Item : in Long_Long_Integer;
234 Aft : in Field;
235 Exp : in Field;
236 Scale : Integer)
238 Buf : String (1 .. Field'Last);
239 Fore : Integer;
240 Ptr : Natural := 0;
242 begin
243 if Exp = 0 then
244 Fore := To'Length - 1 - Aft;
245 else
246 Fore := To'Length - 2 - Aft - Exp;
247 end if;
249 if Fore < 1 then
250 raise Layout_Error;
251 end if;
253 Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
255 if Ptr > To'Length then
256 raise Layout_Error;
257 else
258 To := Buf (1 .. Ptr);
259 end if;
260 end Puts_LLD;
262 end Ada.Text_IO.Decimal_Aux;