* sh.h (REG_CLASS_FROM_LETTER): Change to:
[official-gcc.git] / gcc / ada / a-wtflau.adb
blobc7c6741d1b90eb3bdeecc11b24efa0b8b50e878c
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 -- 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.Wide_Text_IO.Generic_Aux; use Ada.Wide_Text_IO.Generic_Aux;
36 with System.Img_Real; use System.Img_Real;
37 with System.Val_Real; use System.Val_Real;
39 package body Ada.Wide_Text_IO.Float_Aux is
41 ---------
42 -- Get --
43 ---------
45 procedure Get
46 (File : in File_Type;
47 Item : out Long_Long_Float;
48 Width : in Field)
50 Buf : String (1 .. Field'Last);
51 Stop : Integer := 0;
52 Ptr : aliased Integer := 1;
54 begin
55 if Width /= 0 then
56 Load_Width (File, Width, Buf, Stop);
57 String_Skip (Buf, Ptr);
58 else
59 Load_Real (File, Buf, Stop);
60 end if;
62 Item := Scan_Real (Buf, Ptr'Access, Stop);
64 Check_End_Of_Field (Buf, Stop, Ptr, Width);
65 end Get;
67 ----------
68 -- Gets --
69 ----------
71 procedure Gets
72 (From : in String;
73 Item : out Long_Long_Float;
74 Last : out Positive)
76 Pos : aliased Integer;
78 begin
79 String_Skip (From, Pos);
80 Item := Scan_Real (From, Pos'Access, From'Last);
81 Last := Pos - 1;
83 exception
84 when Constraint_Error =>
85 Last := Pos - 1;
86 raise Data_Error;
87 end Gets;
89 ---------------
90 -- Load_Real --
91 ---------------
93 procedure Load_Real
94 (File : in File_Type;
95 Buf : out String;
96 Ptr : in out Natural)
98 Loaded : Boolean;
100 begin
101 -- Skip initial blanks and load possible sign
103 Load_Skip (File);
104 Load (File, Buf, Ptr, '+', '-');
106 -- Case of .nnnn
108 Load (File, Buf, Ptr, '.', Loaded);
110 if Loaded then
111 Load_Digits (File, Buf, Ptr, Loaded);
113 -- Hopeless junk if no digits loaded
115 if not Loaded then
116 return;
117 end if;
119 -- Otherwise must have digits to start
121 else
122 Load_Digits (File, Buf, Ptr, Loaded);
124 -- Hopeless junk if no digits loaded
126 if not Loaded then
127 return;
128 end if;
130 -- Based cases
132 Load (File, Buf, Ptr, '#', ':', Loaded);
134 if Loaded then
136 -- Case of nnn#.xxx#
138 Load (File, Buf, Ptr, '.', Loaded);
140 if Loaded then
141 Load_Extended_Digits (File, Buf, Ptr);
143 -- Case of nnn#xxx.[xxx]# or nnn#xxx#
145 else
146 Load_Extended_Digits (File, Buf, Ptr);
147 Load (File, Buf, Ptr, '.', Loaded);
149 if Loaded then
150 Load_Extended_Digits (File, Buf, Ptr);
151 end if;
153 -- As usual, it seems strange to allow mixed base characters,
154 -- but that is what ACVC tests expect, see CE3804M, case (3).
156 Load (File, Buf, Ptr, '#', ':');
157 end if;
159 -- Case of nnn.[nnn] or nnn
161 else
162 Load (File, Buf, Ptr, '.', Loaded);
164 if Loaded then
165 Load_Digits (File, Buf, Ptr);
166 end if;
167 end if;
168 end if;
170 -- Deal with exponent
172 Load (File, Buf, Ptr, 'E', 'e', Loaded);
174 if Loaded then
175 Load (File, Buf, Ptr, '+', '-');
176 Load_Digits (File, Buf, Ptr);
177 end if;
178 end Load_Real;
180 ---------
181 -- Put --
182 ---------
184 procedure Put
185 (File : in File_Type;
186 Item : in Long_Long_Float;
187 Fore : in Field;
188 Aft : in Field;
189 Exp : in Field)
191 Buf : String (1 .. Field'Last);
192 Ptr : Natural := 0;
194 begin
195 Set_Image_Real (Item, Buf, Ptr, Fore, Aft, Exp);
196 Put_Item (File, Buf (1 .. Ptr));
197 end Put;
199 ----------
200 -- Puts --
201 ----------
203 procedure Puts
204 (To : out String;
205 Item : in Long_Long_Float;
206 Aft : in Field;
207 Exp : in Field)
209 Buf : String (1 .. Field'Last);
210 Ptr : Natural := 0;
212 begin
213 Set_Image_Real (Item, Buf, Ptr, Fore => 1, Aft => Aft, Exp => Exp);
215 if Ptr > To'Length then
216 raise Layout_Error;
218 else
219 for J in 1 .. Ptr loop
220 To (To'Last - Ptr + J) := Buf (J);
221 end loop;
223 for J in To'First .. To'Last - Ptr loop
224 To (J) := ' ';
225 end loop;
226 end if;
227 end Puts;
229 end Ada.Wide_Text_IO.Float_Aux;