* rtl.h (struct rtx_def): Update comments.
[official-gcc.git] / gcc / ada / a-wtflau.adb
blob3358a659e2c2535e3b3dc1a0615be50308b1779b
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . W I D E _ T E X T _ I O . F L O A T _ 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 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 -- --
33 ------------------------------------------------------------------------------
35 with Ada.Wide_Text_IO.Generic_Aux; use Ada.Wide_Text_IO.Generic_Aux;
37 with System.Img_Real; use System.Img_Real;
38 with System.Val_Real; use System.Val_Real;
40 package body Ada.Wide_Text_IO.Float_Aux is
42 ---------
43 -- Get --
44 ---------
46 procedure Get
47 (File : in File_Type;
48 Item : out Long_Long_Float;
49 Width : in Field)
51 Buf : String (1 .. Field'Last);
52 Stop : Integer := 0;
53 Ptr : aliased Integer := 1;
55 begin
56 if Width /= 0 then
57 Load_Width (File, Width, Buf, Stop);
58 String_Skip (Buf, Ptr);
59 else
60 Load_Real (File, Buf, Stop);
61 end if;
63 Item := Scan_Real (Buf, Ptr'Access, Stop);
65 Check_End_Of_Field (Buf, Stop, Ptr, Width);
66 end Get;
68 ----------
69 -- Gets --
70 ----------
72 procedure Gets
73 (From : in String;
74 Item : out Long_Long_Float;
75 Last : out Positive)
77 Pos : aliased Integer;
79 begin
80 String_Skip (From, Pos);
81 Item := Scan_Real (From, Pos'Access, From'Last);
82 Last := Pos - 1;
84 exception
85 when Constraint_Error =>
86 Last := Pos - 1;
87 raise Data_Error;
88 end Gets;
90 ---------------
91 -- Load_Real --
92 ---------------
94 procedure Load_Real
95 (File : in File_Type;
96 Buf : out String;
97 Ptr : in out Natural)
99 Loaded : Boolean;
101 begin
102 -- Skip initial blanks and load possible sign
104 Load_Skip (File);
105 Load (File, Buf, Ptr, '+', '-');
107 -- Case of .nnnn
109 Load (File, Buf, Ptr, '.', Loaded);
111 if Loaded then
112 Load_Digits (File, Buf, Ptr, Loaded);
114 -- Hopeless junk if no digits loaded
116 if not Loaded then
117 return;
118 end if;
120 -- Otherwise must have digits to start
122 else
123 Load_Digits (File, Buf, Ptr, Loaded);
125 -- Hopeless junk if no digits loaded
127 if not Loaded then
128 return;
129 end if;
131 -- Based cases
133 Load (File, Buf, Ptr, '#', ':', Loaded);
135 if Loaded then
137 -- Case of nnn#.xxx#
139 Load (File, Buf, Ptr, '.', Loaded);
141 if Loaded then
142 Load_Extended_Digits (File, Buf, Ptr);
144 -- Case of nnn#xxx.[xxx]# or nnn#xxx#
146 else
147 Load_Extended_Digits (File, Buf, Ptr);
148 Load (File, Buf, Ptr, '.', Loaded);
150 if Loaded then
151 Load_Extended_Digits (File, Buf, Ptr);
152 end if;
154 -- As usual, it seems strange to allow mixed base characters,
155 -- but that is what ACVC tests expect, see CE3804M, case (3).
157 Load (File, Buf, Ptr, '#', ':');
158 end if;
160 -- Case of nnn.[nnn] or nnn
162 else
163 Load (File, Buf, Ptr, '.', Loaded);
165 if Loaded then
166 Load_Digits (File, Buf, Ptr);
167 end if;
168 end if;
169 end if;
171 -- Deal with exponent
173 Load (File, Buf, Ptr, 'E', 'e', Loaded);
175 if Loaded then
176 Load (File, Buf, Ptr, '+', '-');
177 Load_Digits (File, Buf, Ptr);
178 end if;
179 end Load_Real;
181 ---------
182 -- Put --
183 ---------
185 procedure Put
186 (File : in File_Type;
187 Item : in Long_Long_Float;
188 Fore : in Field;
189 Aft : in Field;
190 Exp : in Field)
192 Buf : String (1 .. Field'Last);
193 Ptr : Natural := 0;
195 begin
196 Set_Image_Real (Item, Buf, Ptr, Fore, Aft, Exp);
197 Put_Item (File, Buf (1 .. Ptr));
198 end Put;
200 ----------
201 -- Puts --
202 ----------
204 procedure Puts
205 (To : out String;
206 Item : in Long_Long_Float;
207 Aft : in Field;
208 Exp : in Field)
210 Buf : String (1 .. Field'Last);
211 Ptr : Natural := 0;
213 begin
214 Set_Image_Real (Item, Buf, Ptr, Fore => 1, Aft => Aft, Exp => Exp);
216 if Ptr > To'Length then
217 raise Layout_Error;
219 else
220 for J in 1 .. Ptr loop
221 To (To'Last - Ptr + J) := Buf (J);
222 end loop;
224 for J in To'First .. To'Last - Ptr loop
225 To (J) := ' ';
226 end loop;
227 end if;
228 end Puts;
230 end Ada.Wide_Text_IO.Float_Aux;