annotate gcc/ada/libgnat/a-witeio.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . W I D E _ T E X T _ I O --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This specification is derived from the Ada Reference Manual for use with --
kono
parents:
diff changeset
12 -- GNAT. The copyright notice above, and the license provisions that follow --
kono
parents:
diff changeset
13 -- apply solely to the contents of the part following the private keyword. --
kono
parents:
diff changeset
14 -- --
kono
parents:
diff changeset
15 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
16 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
23 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
24 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
25 -- --
kono
parents:
diff changeset
26 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
27 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
29 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
30 -- --
kono
parents:
diff changeset
31 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
33 -- --
kono
parents:
diff changeset
34 ------------------------------------------------------------------------------
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- Note: the generic subpackages of Wide_Text_IO (Integer_IO, Float_IO,
kono
parents:
diff changeset
37 -- Fixed_IO, Modular_IO, Decimal_IO and Enumeration_IO) appear as private
kono
parents:
diff changeset
38 -- children in GNAT. These children are with'ed automatically if they are
kono
parents:
diff changeset
39 -- referenced, so this rearrangement is invisible to user programs, but has
kono
parents:
diff changeset
40 -- the advantage that only the needed parts of Wide_Text_IO are processed
kono
parents:
diff changeset
41 -- and loaded.
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 with Ada.IO_Exceptions;
kono
parents:
diff changeset
44 with Ada.Streams;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 with Interfaces.C_Streams;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 with System;
kono
parents:
diff changeset
49 with System.File_Control_Block;
kono
parents:
diff changeset
50 with System.WCh_Con;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 package Ada.Wide_Text_IO is
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 type File_Type is limited private;
kono
parents:
diff changeset
55 type File_Mode is (In_File, Out_File, Append_File);
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- The following representation clause allows the use of unchecked
kono
parents:
diff changeset
58 -- conversion for rapid translation between the File_Mode type
kono
parents:
diff changeset
59 -- used in this package and System.File_IO.
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 for File_Mode use
kono
parents:
diff changeset
62 (In_File => 0, -- System.FIle_IO.File_Mode'Pos (In_File)
kono
parents:
diff changeset
63 Out_File => 2, -- System.File_IO.File_Mode'Pos (Out_File)
kono
parents:
diff changeset
64 Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 type Count is range 0 .. Natural'Last;
kono
parents:
diff changeset
67 -- The value of Count'Last must be large enough so that the assumption that
kono
parents:
diff changeset
68 -- the Line, Column and Page counts can never exceed this value is valid.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 subtype Positive_Count is Count range 1 .. Count'Last;
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 Unbounded : constant Count := 0;
kono
parents:
diff changeset
73 -- Line and page length
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 subtype Field is Integer range 0 .. 255;
kono
parents:
diff changeset
76 -- Note: if for any reason, there is a need to increase this value, then it
kono
parents:
diff changeset
77 -- will be necessary to change the corresponding value in System.Img_Real
kono
parents:
diff changeset
78 -- in file s-imgrea.adb.
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 subtype Number_Base is Integer range 2 .. 16;
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 type Type_Set is (Lower_Case, Upper_Case);
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 ---------------------
kono
parents:
diff changeset
85 -- File Management --
kono
parents:
diff changeset
86 ---------------------
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 procedure Create
kono
parents:
diff changeset
89 (File : in out File_Type;
kono
parents:
diff changeset
90 Mode : File_Mode := Out_File;
kono
parents:
diff changeset
91 Name : String := "";
kono
parents:
diff changeset
92 Form : String := "");
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 procedure Open
kono
parents:
diff changeset
95 (File : in out File_Type;
kono
parents:
diff changeset
96 Mode : File_Mode;
kono
parents:
diff changeset
97 Name : String;
kono
parents:
diff changeset
98 Form : String := "");
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 procedure Close (File : in out File_Type);
kono
parents:
diff changeset
101 procedure Delete (File : in out File_Type);
kono
parents:
diff changeset
102 procedure Reset (File : in out File_Type; Mode : File_Mode);
kono
parents:
diff changeset
103 procedure Reset (File : in out File_Type);
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 function Mode (File : File_Type) return File_Mode;
kono
parents:
diff changeset
106 function Name (File : File_Type) return String;
kono
parents:
diff changeset
107 function Form (File : File_Type) return String;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 function Is_Open (File : File_Type) return Boolean;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 ------------------------------------------------------
kono
parents:
diff changeset
112 -- Control of default input, output and error files --
kono
parents:
diff changeset
113 ------------------------------------------------------
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 procedure Set_Input (File : File_Type);
kono
parents:
diff changeset
116 procedure Set_Output (File : File_Type);
kono
parents:
diff changeset
117 procedure Set_Error (File : File_Type);
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 function Standard_Input return File_Type;
kono
parents:
diff changeset
120 function Standard_Output return File_Type;
kono
parents:
diff changeset
121 function Standard_Error return File_Type;
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 function Current_Input return File_Type;
kono
parents:
diff changeset
124 function Current_Output return File_Type;
kono
parents:
diff changeset
125 function Current_Error return File_Type;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 type File_Access is access constant File_Type;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 function Standard_Input return File_Access;
kono
parents:
diff changeset
130 function Standard_Output return File_Access;
kono
parents:
diff changeset
131 function Standard_Error return File_Access;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 function Current_Input return File_Access;
kono
parents:
diff changeset
134 function Current_Output return File_Access;
kono
parents:
diff changeset
135 function Current_Error return File_Access;
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 --------------------
kono
parents:
diff changeset
138 -- Buffer control --
kono
parents:
diff changeset
139 --------------------
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 -- Note: The parameter file is in out in the RM, but as pointed out
kono
parents:
diff changeset
142 -- in <<95-5166.a Tucker Taft 95-6-23>> this is clearly an oversight.
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 procedure Flush (File : File_Type);
kono
parents:
diff changeset
145 procedure Flush;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 --------------------------------------------
kono
parents:
diff changeset
148 -- Specification of line and page lengths --
kono
parents:
diff changeset
149 --------------------------------------------
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 procedure Set_Line_Length (File : File_Type; To : Count);
kono
parents:
diff changeset
152 procedure Set_Line_Length (To : Count);
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 procedure Set_Page_Length (File : File_Type; To : Count);
kono
parents:
diff changeset
155 procedure Set_Page_Length (To : Count);
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 function Line_Length (File : File_Type) return Count;
kono
parents:
diff changeset
158 function Line_Length return Count;
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 function Page_Length (File : File_Type) return Count;
kono
parents:
diff changeset
161 function Page_Length return Count;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 ------------------------------------
kono
parents:
diff changeset
164 -- Column, Line, and Page Control --
kono
parents:
diff changeset
165 ------------------------------------
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 procedure New_Line (File : File_Type; Spacing : Positive_Count := 1);
kono
parents:
diff changeset
168 procedure New_Line (Spacing : Positive_Count := 1);
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 procedure Skip_Line (File : File_Type; Spacing : Positive_Count := 1);
kono
parents:
diff changeset
171 procedure Skip_Line (Spacing : Positive_Count := 1);
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 function End_Of_Line (File : File_Type) return Boolean;
kono
parents:
diff changeset
174 function End_Of_Line return Boolean;
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 procedure New_Page (File : File_Type);
kono
parents:
diff changeset
177 procedure New_Page;
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 procedure Skip_Page (File : File_Type);
kono
parents:
diff changeset
180 procedure Skip_Page;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 function End_Of_Page (File : File_Type) return Boolean;
kono
parents:
diff changeset
183 function End_Of_Page return Boolean;
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 function End_Of_File (File : File_Type) return Boolean;
kono
parents:
diff changeset
186 function End_Of_File return Boolean;
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 procedure Set_Col (File : File_Type; To : Positive_Count);
kono
parents:
diff changeset
189 procedure Set_Col (To : Positive_Count);
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 procedure Set_Line (File : File_Type; To : Positive_Count);
kono
parents:
diff changeset
192 procedure Set_Line (To : Positive_Count);
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 function Col (File : File_Type) return Positive_Count;
kono
parents:
diff changeset
195 function Col return Positive_Count;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 function Line (File : File_Type) return Positive_Count;
kono
parents:
diff changeset
198 function Line return Positive_Count;
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 function Page (File : File_Type) return Positive_Count;
kono
parents:
diff changeset
201 function Page return Positive_Count;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 ----------------------------
kono
parents:
diff changeset
204 -- Character Input-Output --
kono
parents:
diff changeset
205 ----------------------------
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 procedure Get (File : File_Type; Item : out Wide_Character);
kono
parents:
diff changeset
208 procedure Get (Item : out Wide_Character);
kono
parents:
diff changeset
209 procedure Put (File : File_Type; Item : Wide_Character);
kono
parents:
diff changeset
210 procedure Put (Item : Wide_Character);
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 procedure Look_Ahead
kono
parents:
diff changeset
213 (File : File_Type;
kono
parents:
diff changeset
214 Item : out Wide_Character;
kono
parents:
diff changeset
215 End_Of_Line : out Boolean);
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 procedure Look_Ahead
kono
parents:
diff changeset
218 (Item : out Wide_Character;
kono
parents:
diff changeset
219 End_Of_Line : out Boolean);
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 procedure Get_Immediate
kono
parents:
diff changeset
222 (File : File_Type;
kono
parents:
diff changeset
223 Item : out Wide_Character);
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 procedure Get_Immediate
kono
parents:
diff changeset
226 (Item : out Wide_Character);
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 procedure Get_Immediate
kono
parents:
diff changeset
229 (File : File_Type;
kono
parents:
diff changeset
230 Item : out Wide_Character;
kono
parents:
diff changeset
231 Available : out Boolean);
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 procedure Get_Immediate
kono
parents:
diff changeset
234 (Item : out Wide_Character;
kono
parents:
diff changeset
235 Available : out Boolean);
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 -------------------------
kono
parents:
diff changeset
238 -- String Input-Output --
kono
parents:
diff changeset
239 -------------------------
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 procedure Get (File : File_Type; Item : out Wide_String);
kono
parents:
diff changeset
242 procedure Get (Item : out Wide_String);
kono
parents:
diff changeset
243 procedure Put (File : File_Type; Item : Wide_String);
kono
parents:
diff changeset
244 procedure Put (Item : Wide_String);
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 procedure Get_Line
kono
parents:
diff changeset
247 (File : File_Type;
kono
parents:
diff changeset
248 Item : out Wide_String;
kono
parents:
diff changeset
249 Last : out Natural);
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 procedure Get_Line
kono
parents:
diff changeset
252 (Item : out Wide_String;
kono
parents:
diff changeset
253 Last : out Natural);
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 function Get_Line (File : File_Type) return Wide_String;
kono
parents:
diff changeset
256 pragma Ada_05 (Get_Line);
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 function Get_Line return Wide_String;
kono
parents:
diff changeset
259 pragma Ada_05 (Get_Line);
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 procedure Put_Line
kono
parents:
diff changeset
262 (File : File_Type;
kono
parents:
diff changeset
263 Item : Wide_String);
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 procedure Put_Line
kono
parents:
diff changeset
266 (Item : Wide_String);
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 ---------------------------------------
kono
parents:
diff changeset
269 -- Generic packages for Input-Output --
kono
parents:
diff changeset
270 ---------------------------------------
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 -- The generic packages:
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 -- Ada.Wide_Text_IO.Integer_IO
kono
parents:
diff changeset
275 -- Ada.Wide_Text_IO.Modular_IO
kono
parents:
diff changeset
276 -- Ada.Wide_Text_IO.Float_IO
kono
parents:
diff changeset
277 -- Ada.Wide_Text_IO.Fixed_IO
kono
parents:
diff changeset
278 -- Ada.Wide_Text_IO.Decimal_IO
kono
parents:
diff changeset
279 -- Ada.Wide_Text_IO.Enumeration_IO
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 -- are implemented as separate child packages in GNAT, so the
kono
parents:
diff changeset
282 -- spec and body of these packages are to be found in separate
kono
parents:
diff changeset
283 -- child units. This implementation detail is hidden from the
kono
parents:
diff changeset
284 -- Ada programmer by special circuitry in the compiler that
kono
parents:
diff changeset
285 -- treats these child packages as though they were nested in
kono
parents:
diff changeset
286 -- Text_IO. The advantage of this special processing is that
kono
parents:
diff changeset
287 -- the subsidiary routines needed if these generics are used
kono
parents:
diff changeset
288 -- are not loaded when they are not used.
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 ----------------
kono
parents:
diff changeset
291 -- Exceptions --
kono
parents:
diff changeset
292 ----------------
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 Status_Error : exception renames IO_Exceptions.Status_Error;
kono
parents:
diff changeset
295 Mode_Error : exception renames IO_Exceptions.Mode_Error;
kono
parents:
diff changeset
296 Name_Error : exception renames IO_Exceptions.Name_Error;
kono
parents:
diff changeset
297 Use_Error : exception renames IO_Exceptions.Use_Error;
kono
parents:
diff changeset
298 Device_Error : exception renames IO_Exceptions.Device_Error;
kono
parents:
diff changeset
299 End_Error : exception renames IO_Exceptions.End_Error;
kono
parents:
diff changeset
300 Data_Error : exception renames IO_Exceptions.Data_Error;
kono
parents:
diff changeset
301 Layout_Error : exception renames IO_Exceptions.Layout_Error;
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 private
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 -- The following procedures have a File_Type formal of mode IN OUT because
kono
parents:
diff changeset
306 -- they may close the original file. The Close operation may raise an
kono
parents:
diff changeset
307 -- exception, but in that case we want any assignment to the formal to
kono
parents:
diff changeset
308 -- be effective anyway, so it must be passed by reference (or the caller
kono
parents:
diff changeset
309 -- will be left with a dangling pointer).
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 pragma Export_Procedure
kono
parents:
diff changeset
312 (Internal => Close,
kono
parents:
diff changeset
313 External => "",
kono
parents:
diff changeset
314 Mechanism => Reference);
kono
parents:
diff changeset
315 pragma Export_Procedure
kono
parents:
diff changeset
316 (Internal => Delete,
kono
parents:
diff changeset
317 External => "",
kono
parents:
diff changeset
318 Mechanism => Reference);
kono
parents:
diff changeset
319 pragma Export_Procedure
kono
parents:
diff changeset
320 (Internal => Reset,
kono
parents:
diff changeset
321 External => "",
kono
parents:
diff changeset
322 Parameter_Types => (File_Type),
kono
parents:
diff changeset
323 Mechanism => Reference);
kono
parents:
diff changeset
324 pragma Export_Procedure
kono
parents:
diff changeset
325 (Internal => Reset,
kono
parents:
diff changeset
326 External => "",
kono
parents:
diff changeset
327 Parameter_Types => (File_Type, File_Mode),
kono
parents:
diff changeset
328 Mechanism => (File => Reference));
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 package WCh_Con renames System.WCh_Con;
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 -----------------------------------
kono
parents:
diff changeset
333 -- Handling of Format Characters --
kono
parents:
diff changeset
334 -----------------------------------
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 -- Line marks are represented by the single character ASCII.LF (16#0A#).
kono
parents:
diff changeset
337 -- In DOS and similar systems, underlying file translation takes care
kono
parents:
diff changeset
338 -- of translating this to and from the standard CR/LF sequences used in
kono
parents:
diff changeset
339 -- these operating systems to mark the end of a line. On output there is
kono
parents:
diff changeset
340 -- always a line mark at the end of the last line, but on input, this
kono
parents:
diff changeset
341 -- line mark can be omitted, and is implied by the end of file.
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 -- Page marks are represented by the single character ASCII.FF (16#0C#),
kono
parents:
diff changeset
344 -- The page mark at the end of the file may be omitted, and is normally
kono
parents:
diff changeset
345 -- omitted on output unless an explicit New_Page call is made before
kono
parents:
diff changeset
346 -- closing the file. No page mark is added when a file is appended to,
kono
parents:
diff changeset
347 -- so, in accordance with the permission in (RM A.10.2(4)), there may
kono
parents:
diff changeset
348 -- or may not be a page mark separating preexisting text in the file
kono
parents:
diff changeset
349 -- from the new text to be written.
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 -- A file mark is marked by the physical end of file. In DOS translation
kono
parents:
diff changeset
352 -- mode on input, an EOF character (SUB = 16#1A#) gets translated to the
kono
parents:
diff changeset
353 -- physical end of file, so in effect this character is recognized as
kono
parents:
diff changeset
354 -- marking the end of file in DOS and similar systems.
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 LM : constant := Character'Pos (ASCII.LF);
kono
parents:
diff changeset
357 -- Used as line mark
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 PM : constant := Character'Pos (ASCII.FF);
kono
parents:
diff changeset
360 -- Used as page mark, except at end of file where it is implied
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 -------------------------------------
kono
parents:
diff changeset
363 -- Wide_Text_IO File Control Block --
kono
parents:
diff changeset
364 -------------------------------------
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 Default_WCEM : WCh_Con.WC_Encoding_Method := WCh_Con.WCEM_UTF8;
kono
parents:
diff changeset
367 -- This gets modified during initialization (see body) using
kono
parents:
diff changeset
368 -- the default value established in the call to Set_Globals.
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 package FCB renames System.File_Control_Block;
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 type Wide_Text_AFCB is new FCB.AFCB with record
kono
parents:
diff changeset
373 Page : Count := 1;
kono
parents:
diff changeset
374 Line : Count := 1;
kono
parents:
diff changeset
375 Col : Count := 1;
kono
parents:
diff changeset
376 Line_Length : Count := 0;
kono
parents:
diff changeset
377 Page_Length : Count := 0;
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 Self : aliased File_Type;
kono
parents:
diff changeset
380 -- Set to point to the containing Text_AFCB block. This is used to
kono
parents:
diff changeset
381 -- implement the Current_{Error,Input,Output} functions which return
kono
parents:
diff changeset
382 -- a File_Access, the file access value returned is a pointer to
kono
parents:
diff changeset
383 -- the Self field of the corresponding file.
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 Before_LM : Boolean := False;
kono
parents:
diff changeset
386 -- This flag is used to deal with the anomalies introduced by the
kono
parents:
diff changeset
387 -- peculiar definition of End_Of_File and End_Of_Page in Ada. These
kono
parents:
diff changeset
388 -- functions require looking ahead more than one character. Since
kono
parents:
diff changeset
389 -- there is no convenient way of backing up more than one character,
kono
parents:
diff changeset
390 -- what we do is to leave ourselves positioned past the LM, but set
kono
parents:
diff changeset
391 -- this flag, so that we know that from an Ada point of view we are
kono
parents:
diff changeset
392 -- in front of the LM, not after it. A bit odd, but it works.
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 Before_LM_PM : Boolean := False;
kono
parents:
diff changeset
395 -- This flag similarly handles the case of being physically positioned
kono
parents:
diff changeset
396 -- after a LM-PM sequence when logically we are before the LM-PM. This
kono
parents:
diff changeset
397 -- flag can only be set if Before_LM is also set.
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 WC_Method : WCh_Con.WC_Encoding_Method := Default_WCEM;
kono
parents:
diff changeset
400 -- Encoding method to be used for this file
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 Before_Wide_Character : Boolean := False;
kono
parents:
diff changeset
403 -- This flag is set to indicate that a wide character in the input has
kono
parents:
diff changeset
404 -- been read by Wide_Text_IO.Look_Ahead. If it is set to True, then it
kono
parents:
diff changeset
405 -- means that the stream is logically positioned before the character
kono
parents:
diff changeset
406 -- but is physically positioned after it. The character involved must
kono
parents:
diff changeset
407 -- not be in the range 16#00#-16#7F#, i.e. if the flag is set, then
kono
parents:
diff changeset
408 -- we know the next character has a code greater than 16#7F#, and the
kono
parents:
diff changeset
409 -- value of this character is saved in Saved_Wide_Character.
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 Saved_Wide_Character : Wide_Character;
kono
parents:
diff changeset
412 -- This field is valid only if Before_Wide_Character is set. It
kono
parents:
diff changeset
413 -- contains a wide character read by Look_Ahead. If Look_Ahead
kono
parents:
diff changeset
414 -- reads a character in the range 16#0000# to 16#007F#, then it
kono
parents:
diff changeset
415 -- can use ungetc to put it back, but ungetc cannot be called
kono
parents:
diff changeset
416 -- more than once, so for characters above this range, we don't
kono
parents:
diff changeset
417 -- try to back up the file. Instead we save the character in this
kono
parents:
diff changeset
418 -- field and set the flag Before_Wide_Character to indicate that
kono
parents:
diff changeset
419 -- we are logically positioned before this character even though
kono
parents:
diff changeset
420 -- the stream is physically positioned after it.
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 end record;
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 type File_Type is access all Wide_Text_AFCB;
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 function AFCB_Allocate (Control_Block : Wide_Text_AFCB) return FCB.AFCB_Ptr;
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 procedure AFCB_Close (File : not null access Wide_Text_AFCB);
kono
parents:
diff changeset
429 procedure AFCB_Free (File : not null access Wide_Text_AFCB);
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 procedure Read
kono
parents:
diff changeset
432 (File : in out Wide_Text_AFCB;
kono
parents:
diff changeset
433 Item : out Ada.Streams.Stream_Element_Array;
kono
parents:
diff changeset
434 Last : out Ada.Streams.Stream_Element_Offset);
kono
parents:
diff changeset
435 -- Read operation used when Wide_Text_IO file is treated as a Stream
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 procedure Write
kono
parents:
diff changeset
438 (File : in out Wide_Text_AFCB;
kono
parents:
diff changeset
439 Item : Ada.Streams.Stream_Element_Array);
kono
parents:
diff changeset
440 -- Write operation used when Wide_Text_IO file is treated as a Stream
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 ------------------------
kono
parents:
diff changeset
443 -- The Standard Files --
kono
parents:
diff changeset
444 ------------------------
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 Standard_Err_AFCB : aliased Wide_Text_AFCB;
kono
parents:
diff changeset
447 Standard_In_AFCB : aliased Wide_Text_AFCB;
kono
parents:
diff changeset
448 Standard_Out_AFCB : aliased Wide_Text_AFCB;
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 Standard_Err : aliased File_Type := Standard_Err_AFCB'Access;
kono
parents:
diff changeset
451 Standard_In : aliased File_Type := Standard_In_AFCB'Access;
kono
parents:
diff changeset
452 Standard_Out : aliased File_Type := Standard_Out_AFCB'Access;
kono
parents:
diff changeset
453 -- Standard files
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 Current_In : aliased File_Type := Standard_In;
kono
parents:
diff changeset
456 Current_Out : aliased File_Type := Standard_Out;
kono
parents:
diff changeset
457 Current_Err : aliased File_Type := Standard_Err;
kono
parents:
diff changeset
458 -- Current files
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 procedure Initialize_Standard_Files;
kono
parents:
diff changeset
461 -- Initializes the file control blocks for the standard files. Called from
kono
parents:
diff changeset
462 -- the elaboration routine for this package, and from Reset_Standard_Files
kono
parents:
diff changeset
463 -- in package Ada.Wide_Text_IO.Reset_Standard_Files.
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 -----------------------
kono
parents:
diff changeset
466 -- Local Subprograms --
kono
parents:
diff changeset
467 -----------------------
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 -- These subprograms are in the private part of the spec so that they can
kono
parents:
diff changeset
470 -- be shared by the children of Ada.Wide_Text_IO.
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 function Getc (File : File_Type) return Interfaces.C_Streams.int;
kono
parents:
diff changeset
473 -- Gets next character from file, which has already been checked for being
kono
parents:
diff changeset
474 -- in read status, and returns the character read if no error occurs. The
kono
parents:
diff changeset
475 -- result is EOF if the end of file was read.
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 procedure Get_Character (File : File_Type; Item : out Character);
kono
parents:
diff changeset
478 -- This is essentially a copy of the normal Get routine from Text_IO. It
kono
parents:
diff changeset
479 -- obtains a single character from the input file File, and places it in
kono
parents:
diff changeset
480 -- Item. This character may be the leading character of a Wide_Character
kono
parents:
diff changeset
481 -- sequence, but that is up to the caller to deal with.
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 function Get_Wide_Char
kono
parents:
diff changeset
484 (C : Character;
kono
parents:
diff changeset
485 File : File_Type) return Wide_Character;
kono
parents:
diff changeset
486 -- This function is shared by Get and Get_Immediate to extract a wide
kono
parents:
diff changeset
487 -- character value from the given File. The first byte has already been
kono
parents:
diff changeset
488 -- read and is passed in C. The wide character value is returned as the
kono
parents:
diff changeset
489 -- result, and the file pointer is bumped past the character.
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 function Nextc (File : File_Type) return Interfaces.C_Streams.int;
kono
parents:
diff changeset
492 -- Returns next character from file without skipping past it (i.e. it is a
kono
parents:
diff changeset
493 -- combination of Getc followed by an Ungetc).
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 end Ada.Wide_Text_IO;