OSDN Git Service

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