OSDN Git Service

2008-05-27 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-zzboio.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                 ADA.WIDE_WIDE_TEXT_IO.WIDE_WIDE_BOUNDED_IO               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1997-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_Wide_Text_IO; use Ada.Wide_Wide_Text_IO;
35 with Ada.Unchecked_Deallocation;
36
37 package body Ada.Wide_Wide_Text_IO.Wide_Wide_Bounded_IO is
38
39    type Wide_Wide_String_Access is access all Wide_Wide_String;
40
41    procedure Free (WWSA : in out Wide_Wide_String_Access);
42    --  Perform an unchecked deallocation of a non-null string
43
44    ----------
45    -- Free --
46    ----------
47
48    procedure Free (WWSA : in out Wide_Wide_String_Access) is
49       Null_Wide_Wide_String : constant Wide_Wide_String := "";
50
51       procedure Deallocate is
52         new Ada.Unchecked_Deallocation (
53           Wide_Wide_String, Wide_Wide_String_Access);
54
55    begin
56       --  Do not try to free statically allocated null string
57
58       if WWSA.all /= Null_Wide_Wide_String then
59          Deallocate (WWSA);
60       end if;
61    end Free;
62
63    --------------
64    -- Get_Line --
65    --------------
66
67    function Get_Line return Wide_Wide_Bounded.Bounded_Wide_Wide_String is
68    begin
69       return Wide_Wide_Bounded.To_Bounded_Wide_Wide_String (Get_Line);
70    end Get_Line;
71
72    --------------
73    -- Get_Line --
74    --------------
75
76    function Get_Line
77      (File : File_Type) return Wide_Wide_Bounded.Bounded_Wide_Wide_String
78    is
79    begin
80       return Wide_Wide_Bounded.To_Bounded_Wide_Wide_String (Get_Line (File));
81    end Get_Line;
82
83    --------------
84    -- Get_Line --
85    --------------
86
87    procedure Get_Line
88      (Item : out Wide_Wide_Bounded.Bounded_Wide_Wide_String)
89    is
90       Buffer : Wide_Wide_String (1 .. 1000);
91       Last   : Natural;
92       Str1   : Wide_Wide_String_Access;
93       Str2   : Wide_Wide_String_Access;
94
95    begin
96       Get_Line (Buffer, Last);
97       Str1 := new Wide_Wide_String'(Buffer (1 .. Last));
98
99       while Last = Buffer'Last loop
100          Get_Line (Buffer, Last);
101          Str2 := new Wide_Wide_String'(Str1.all & Buffer (1 .. Last));
102          Free (Str1);
103          Str1 := Str2;
104       end loop;
105
106       Item := Wide_Wide_Bounded.To_Bounded_Wide_Wide_String (Str1.all);
107    end Get_Line;
108
109    --------------
110    -- Get_Line --
111    --------------
112
113    procedure Get_Line
114      (File : File_Type;
115       Item : out Wide_Wide_Bounded.Bounded_Wide_Wide_String)
116    is
117       Buffer : Wide_Wide_String (1 .. 1000);
118       Last   : Natural;
119       Str1   : Wide_Wide_String_Access;
120       Str2   : Wide_Wide_String_Access;
121
122    begin
123       Get_Line (File, Buffer, Last);
124       Str1 := new Wide_Wide_String'(Buffer (1 .. Last));
125
126       while Last = Buffer'Last loop
127          Get_Line (File, Buffer, Last);
128          Str2 := new Wide_Wide_String'(Str1.all & Buffer (1 .. Last));
129          Free (Str1);
130          Str1 := Str2;
131       end loop;
132
133       Item := Wide_Wide_Bounded.To_Bounded_Wide_Wide_String (Str1.all);
134    end Get_Line;
135
136    ---------
137    -- Put --
138    ---------
139
140    procedure Put
141      (Item : Wide_Wide_Bounded.Bounded_Wide_Wide_String)
142    is
143    begin
144       Put (Wide_Wide_Bounded.To_Wide_Wide_String (Item));
145    end Put;
146
147    ---------
148    -- Put --
149    ---------
150
151    procedure Put
152      (File : File_Type;
153       Item : Wide_Wide_Bounded.Bounded_Wide_Wide_String)
154    is
155    begin
156       Put (File, Wide_Wide_Bounded.To_Wide_Wide_String (Item));
157    end Put;
158
159    --------------
160    -- Put_Line --
161    --------------
162
163    procedure Put_Line
164      (Item : Wide_Wide_Bounded.Bounded_Wide_Wide_String)
165    is
166    begin
167       Put_Line (Wide_Wide_Bounded.To_Wide_Wide_String (Item));
168    end Put_Line;
169
170    --------------
171    -- Put_Line --
172    --------------
173
174    procedure Put_Line
175      (File : File_Type;
176       Item : Wide_Wide_Bounded.Bounded_Wide_Wide_String)
177    is
178    begin
179       Put_Line (File, Wide_Wide_Bounded.To_Wide_Wide_String (Item));
180    end Put_Line;
181
182 end Ada.Wide_Wide_Text_IO.Wide_Wide_Bounded_IO;