OSDN Git Service

* config/pa/fptr.c: Update license header.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-szuzti.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --             ADA.STRINGS.WIDE_WIDE_UNBOUNDED.WIDE_WIDE_TEXT_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
36 package body Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Text_IO is
37
38    --------------
39    -- Get_Line --
40    --------------
41
42    function Get_Line return Unbounded_Wide_Wide_String is
43       Buffer : Wide_Wide_String (1 .. 1000);
44       Last   : Natural;
45       Str1   : Wide_Wide_String_Access;
46       Str2   : Wide_Wide_String_Access;
47       Result : Unbounded_Wide_Wide_String;
48
49    begin
50       Get_Line (Buffer, Last);
51       Str1 := new Wide_Wide_String'(Buffer (1 .. Last));
52       while Last = Buffer'Last loop
53          Get_Line (Buffer, Last);
54          Str2 := new Wide_Wide_String'(Str1.all & Buffer (1 .. Last));
55          Free (Str1);
56          Str1 := Str2;
57       end loop;
58
59       Result.Reference := Str1;
60       Result.Last      := Str1'Length;
61       return Result;
62    end Get_Line;
63
64    function Get_Line
65      (File : Ada.Wide_Wide_Text_IO.File_Type) return Unbounded_Wide_Wide_String
66    is
67       Buffer : Wide_Wide_String (1 .. 1000);
68       Last   : Natural;
69       Str1   : Wide_Wide_String_Access;
70       Str2   : Wide_Wide_String_Access;
71       Result : Unbounded_Wide_Wide_String;
72
73    begin
74       Get_Line (File, Buffer, Last);
75       Str1 := new Wide_Wide_String'(Buffer (1 .. Last));
76
77       while Last = Buffer'Last loop
78          Get_Line (File, Buffer, Last);
79          Str2 := new Wide_Wide_String'(Str1.all & Buffer (1 .. Last));
80          Free (Str1);
81          Str1 := Str2;
82       end loop;
83
84       Result.Reference := Str1;
85       Result.Last      := Str1'Length;
86       return Result;
87    end Get_Line;
88
89    procedure Get_Line (Item : out Unbounded_Wide_Wide_String) is
90    begin
91       Get_Line (Current_Input, Item);
92    end Get_Line;
93
94    procedure Get_Line
95      (File : Ada.Wide_Wide_Text_IO.File_Type;
96       Item : out Unbounded_Wide_Wide_String)
97    is
98    begin
99       --  We are going to read into the string that is already there and
100       --  allocated. Hopefully it is big enough now, if not, we will extend
101       --  it in the usual manner using Realloc_For_Chunk.
102
103       --  Make sure we start with at least 80 characters
104
105       if Item.Reference'Last < 80 then
106          Realloc_For_Chunk (Item, 80);
107       end if;
108
109       --  Loop to read data, filling current string as far as possible.
110       --  Item.Last holds the number of characters read so far.
111
112       Item.Last := 0;
113       loop
114          Get_Line
115            (File,
116             Item.Reference (Item.Last + 1 .. Item.Reference'Last),
117             Item.Last);
118
119          --  If we hit the end of the line before the end of the buffer, then
120          --  we are all done, and the result length is properly set.
121
122          if Item.Last < Item.Reference'Last then
123             return;
124          end if;
125
126          --  If not enough room, double it and keep reading
127
128          Realloc_For_Chunk (Item, Item.Last);
129       end loop;
130    end Get_Line;
131
132    ---------
133    -- Put --
134    ---------
135
136    procedure Put (U : Unbounded_Wide_Wide_String) is
137    begin
138       Put (U.Reference (1 .. U.Last));
139    end Put;
140
141    procedure Put (File : File_Type; U : Unbounded_Wide_Wide_String) is
142    begin
143       Put (File, U.Reference (1 .. U.Last));
144    end Put;
145
146    --------------
147    -- Put_Line --
148    --------------
149
150    procedure Put_Line (U : Unbounded_Wide_Wide_String) is
151    begin
152       Put_Line (U.Reference (1 .. U.Last));
153    end Put_Line;
154
155    procedure Put_Line (File : File_Type; U : Unbounded_Wide_Wide_String) is
156    begin
157       Put_Line (File, U.Reference (1 .. U.Last));
158    end Put_Line;
159
160 end Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Text_IO;