OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [ada/] [a-wtdeau.adb] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
------------------------------------------------------------------------------
2
--                                                                          --
3
--                         GNAT RUN-TIME COMPONENTS                         --
4
--                                                                          --
5
--         A D A . W I D E _ 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-2005, 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,  51  Franklin  Street,  Fifth  Floor, --
20
-- Boston, MA 02110-1301, 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
------------------------------------------------------------------------------
33
 
34
with Ada.Wide_Text_IO.Generic_Aux; use Ada.Wide_Text_IO.Generic_Aux;
35
with Ada.Wide_Text_IO.Float_Aux;   use Ada.Wide_Text_IO.Float_Aux;
36
 
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;
41
 
42
package body Ada.Wide_Text_IO.Decimal_Aux is
43
 
44
   -------------
45
   -- Get_Dec --
46
   -------------
47
 
48
   function Get_Dec
49
     (File   : File_Type;
50
      Width  : Field;
51
      Scale  : Integer)
52
      return   Integer
53
   is
54
      Buf  : String (1 .. Field'Last);
55
      Ptr  : aliased Integer;
56
      Stop : Integer := 0;
57
      Item : Integer;
58
 
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;
67
 
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;
72
 
73
   -------------
74
   -- Get_LLD --
75
   -------------
76
 
77
   function Get_LLD
78
     (File   : File_Type;
79
      Width  : Field;
80
      Scale  : Integer)
81
      return   Long_Long_Integer
82
   is
83
      Buf  : String (1 .. Field'Last);
84
      Ptr  : aliased Integer;
85
      Stop : Integer := 0;
86
      Item : Long_Long_Integer;
87
 
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;
96
 
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;
101
 
102
   --------------
103
   -- Gets_Dec --
104
   --------------
105
 
106
   function Gets_Dec
107
     (From  : String;
108
      Last  : access Positive;
109
      Scale : Integer)
110
      return  Integer
111
   is
112
      Pos  : aliased Integer;
113
      Item : Integer;
114
 
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;
120
 
121
   exception
122
      when Constraint_Error =>
123
         Last.all := Pos - 1;
124
         raise Data_Error;
125
 
126
   end Gets_Dec;
127
 
128
   --------------
129
   -- Gets_LLD --
130
   --------------
131
 
132
   function Gets_LLD
133
     (From  : String;
134
      Last  : access Positive;
135
      Scale : Integer)
136
      return  Long_Long_Integer
137
   is
138
      Pos  : aliased Integer;
139
      Item : Long_Long_Integer;
140
 
141
   begin
142
      String_Skip (From, Pos);
143
      Item := Scan_Long_Long_Decimal (From, Pos'Access, From'Last, Scale);
144
      Last.all := Pos - 1;
145
      return Item;
146
 
147
   exception
148
      when Constraint_Error =>
149
         Last.all := Pos - 1;
150
         raise Data_Error;
151
 
152
   end Gets_LLD;
153
 
154
   -------------
155
   -- Put_Dec --
156
   -------------
157
 
158
   procedure Put_Dec
159
     (File  : File_Type;
160
      Item  : Integer;
161
      Fore  : Field;
162
      Aft   : Field;
163
      Exp   : Field;
164
      Scale : Integer)
165
   is
166
      Buf : String (1 .. Field'Last);
167
      Ptr : Natural := 0;
168
 
169
   begin
170
      Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
171
      Put_Item (File, Buf (1 .. Ptr));
172
   end Put_Dec;
173
 
174
   -------------
175
   -- Put_LLD --
176
   -------------
177
 
178
   procedure Put_LLD
179
     (File  : File_Type;
180
      Item  : Long_Long_Integer;
181
      Fore  : Field;
182
      Aft   : Field;
183
      Exp   : Field;
184
      Scale : Integer)
185
   is
186
      Buf : String (1 .. Field'Last);
187
      Ptr : Natural := 0;
188
 
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;
193
 
194
   --------------
195
   -- Puts_Dec --
196
   --------------
197
 
198
   procedure Puts_Dec
199
     (To    : out String;
200
      Item  : Integer;
201
      Aft   : Field;
202
      Exp   : Field;
203
      Scale : Integer)
204
   is
205
      Buf  : String (1 .. Field'Last);
206
      Fore : Integer;
207
      Ptr  : Natural := 0;
208
 
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;
215
 
216
      if Fore < 1 then
217
         raise Layout_Error;
218
      end if;
219
 
220
      Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
221
 
222
      if Ptr > To'Length then
223
         raise Layout_Error;
224
      else
225
         To := Buf (1 .. Ptr);
226
      end if;
227
   end Puts_Dec;
228
 
229
   --------------
230
   -- Puts_Dec --
231
   --------------
232
 
233
   procedure Puts_LLD
234
     (To    : out String;
235
      Item  : Long_Long_Integer;
236
      Aft   : Field;
237
      Exp   : Field;
238
      Scale : Integer)
239
   is
240
      Buf  : String (1 .. Field'Last);
241
      Fore : Integer;
242
      Ptr  : Natural := 0;
243
 
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;
250
 
251
      if Fore < 1 then
252
         raise Layout_Error;
253
      end if;
254
 
255
      Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
256
 
257
      if Ptr > To'Length then
258
         raise Layout_Error;
259
      else
260
         To := Buf (1 .. Ptr);
261
      end if;
262
   end Puts_LLD;
263
 
264
end Ada.Wide_Text_IO.Decimal_Aux;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.