Disable tests for strdup/strndup on __hpux__
[official-gcc.git] / gcc / ada / libgnat / a-ztflio.adb
blobea14d117894084e667dc80e20af1a8ae05f70bf1
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . W I D E _ W I D E _ T E X T _ I O . F L O A T _ I O --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2023, 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 3, 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. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with Ada.Wide_Wide_Text_IO.Float_Aux;
33 with System.Img_Flt; use System.Img_Flt;
34 with System.Img_LFlt; use System.Img_LFlt;
35 with System.Img_LLF; use System.Img_LLF;
36 with System.Val_Flt; use System.Val_Flt;
37 with System.Val_LFlt; use System.Val_LFlt;
38 with System.Val_LLF; use System.Val_LLF;
39 with System.WCh_Con; use System.WCh_Con;
40 with System.WCh_WtS; use System.WCh_WtS;
42 package body Ada.Wide_Wide_Text_IO.Float_IO is
44 package Aux_Float is new
45 Ada.Wide_Wide_Text_IO.Float_Aux (Float, Scan_Float, Set_Image_Float);
47 package Aux_Long_Float is new
48 Ada.Wide_Wide_Text_IO.Float_Aux
49 (Long_Float, Scan_Long_Float, Set_Image_Long_Float);
51 package Aux_Long_Long_Float is new
52 Ada.Wide_Wide_Text_IO.Float_Aux
53 (Long_Long_Float, Scan_Long_Long_Float, Set_Image_Long_Long_Float);
55 -- Throughout this generic body, we distinguish between the case where type
56 -- Float is OK, where type Long_Float is OK and where type Long_Long_Float
57 -- is needed. These boolean constants are used to test for this, such that
58 -- only code for the relevant case is included in the instance.
60 OK_Float : constant Boolean := Num'Base'Digits <= Float'Digits;
62 OK_Long_Float : constant Boolean := Num'Base'Digits <= Long_Float'Digits;
64 ---------
65 -- Get --
66 ---------
68 procedure Get
69 (File : File_Type;
70 Item : out Num;
71 Width : Field := 0)
73 pragma Unsuppress (Range_Check);
75 begin
76 if OK_Float then
77 Aux_Float.Get (File, Float (Item), Width);
78 elsif OK_Long_Float then
79 Aux_Long_Float.Get (File, Long_Float (Item), Width);
80 else
81 Aux_Long_Long_Float.Get (File, Long_Long_Float (Item), Width);
82 end if;
84 -- In the case where the type is unconstrained (e.g. Standard'Float),
85 -- the above conversion may result in an infinite value, which is
86 -- normally fine for a conversion, but in this case, we want to treat
87 -- that as a data error.
89 if not Item'Valid then
90 raise Data_Error;
91 end if;
93 exception
94 when Constraint_Error => raise Data_Error;
95 end Get;
97 procedure Get
98 (Item : out Num;
99 Width : Field := 0)
101 begin
102 Get (Current_In, Item, Width);
103 end Get;
105 procedure Get
106 (From : Wide_Wide_String;
107 Item : out Num;
108 Last : out Positive)
110 pragma Unsuppress (Range_Check);
112 S : constant String := Wide_Wide_String_To_String (From, WCEM_Upper);
113 -- String on which we do the actual conversion. Note that the method
114 -- used for wide character encoding is irrelevant, since if there is
115 -- a character outside the Standard.Character range then the call to
116 -- Aux.Gets will raise Data_Error in any case.
118 begin
119 if OK_Float then
120 Aux_Float.Gets (S, Float (Item), Last);
121 elsif OK_Long_Float then
122 Aux_Long_Float.Gets (S, Long_Float (Item), Last);
123 else
124 Aux_Long_Long_Float.Gets (S, Long_Long_Float (Item), Last);
125 end if;
127 -- In the case where the type is unconstrained (e.g. Standard'Float),
128 -- the above conversion may result in an infinite value, which is
129 -- normally fine for a conversion, but in this case, we want to treat
130 -- that as a data error.
132 if not Item'Valid then
133 raise Data_Error;
134 end if;
136 exception
137 when Constraint_Error => raise Data_Error;
138 end Get;
140 ---------
141 -- Put --
142 ---------
144 procedure Put
145 (File : File_Type;
146 Item : Num;
147 Fore : Field := Default_Fore;
148 Aft : Field := Default_Aft;
149 Exp : Field := Default_Exp)
151 begin
152 if OK_Float then
153 Aux_Float.Put (File, Float (Item), Fore, Aft, Exp);
154 elsif OK_Long_Float then
155 Aux_Long_Float.Put (File, Long_Float (Item), Fore, Aft, Exp);
156 else
157 Aux_Long_Long_Float.Put
158 (File, Long_Long_Float (Item), Fore, Aft, Exp);
159 end if;
160 end Put;
162 procedure Put
163 (Item : Num;
164 Fore : Field := Default_Fore;
165 Aft : Field := Default_Aft;
166 Exp : Field := Default_Exp)
168 begin
169 Put (Current_Out, Item, Fore, Aft, Exp);
170 end Put;
172 procedure Put
173 (To : out Wide_Wide_String;
174 Item : Num;
175 Aft : Field := Default_Aft;
176 Exp : Field := Default_Exp)
178 S : String (To'First .. To'Last);
180 begin
181 if OK_Float then
182 Aux_Float.Puts (S, Float (Item), Aft, Exp);
183 elsif OK_Long_Float then
184 Aux_Long_Float.Puts (S, Long_Float (Item), Aft, Exp);
185 else
186 Aux_Long_Long_Float.Puts (S, Long_Long_Float (Item), Aft, Exp);
187 end if;
189 for J in S'Range loop
190 To (J) := Wide_Wide_Character'Val (Character'Pos (S (J)));
191 end loop;
192 end Put;
194 end Ada.Wide_Wide_Text_IO.Float_IO;