annotate gcc/ada/libgnat/a-textio.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
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 . 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 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
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 Text_IO (Integer_IO, Float_IO, Fixed_IO,
kono
parents:
diff changeset
37 -- Modular_IO, Decimal_IO and Enumeration_IO) appear as private children in
kono
parents:
diff changeset
38 -- GNAT. These children are with'ed automatically if they are referenced, so
kono
parents:
diff changeset
39 -- this rearrangement is invisible to user programs, but has the advantage
kono
parents:
diff changeset
40 -- that only the needed parts of Text_IO are processed and loaded.
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 with Ada.IO_Exceptions;
kono
parents:
diff changeset
43 with Ada.Streams;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 with System;
kono
parents:
diff changeset
46 with System.File_Control_Block;
kono
parents:
diff changeset
47 with System.WCh_Con;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 package Ada.Text_IO is
kono
parents:
diff changeset
50 pragma Elaborate_Body;
kono
parents:
diff changeset
51
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
52 type File_Type is limited private with Default_Initial_Condition;
111
kono
parents:
diff changeset
53 type File_Mode is (In_File, Out_File, Append_File);
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 -- The following representation clause allows the use of unchecked
kono
parents:
diff changeset
56 -- conversion for rapid translation between the File_Mode type
kono
parents:
diff changeset
57 -- used in this package and System.File_IO.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 for File_Mode use
kono
parents:
diff changeset
60 (In_File => 0, -- System.FIle_IO.File_Mode'Pos (In_File)
kono
parents:
diff changeset
61 Out_File => 2, -- System.File_IO.File_Mode'Pos (Out_File)
kono
parents:
diff changeset
62 Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 type Count is range 0 .. Natural'Last;
kono
parents:
diff changeset
65 -- The value of Count'Last must be large enough so that the assumption that
kono
parents:
diff changeset
66 -- the Line, Column and Page counts can never exceed this value is valid.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 subtype Positive_Count is Count range 1 .. Count'Last;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 Unbounded : constant Count := 0;
kono
parents:
diff changeset
71 -- Line and page length
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 subtype Field is Integer range 0 .. 255;
kono
parents:
diff changeset
74 -- Note: if for any reason, there is a need to increase this value, then it
kono
parents:
diff changeset
75 -- will be necessary to change the corresponding value in System.Img_Real
kono
parents:
diff changeset
76 -- in file s-imgrea.adb.
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 subtype Number_Base is Integer range 2 .. 16;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 type Type_Set is (Lower_Case, Upper_Case);
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 ---------------------
kono
parents:
diff changeset
83 -- File Management --
kono
parents:
diff changeset
84 ---------------------
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 procedure Create
kono
parents:
diff changeset
87 (File : in out File_Type;
kono
parents:
diff changeset
88 Mode : File_Mode := Out_File;
kono
parents:
diff changeset
89 Name : String := "";
kono
parents:
diff changeset
90 Form : String := "");
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 procedure Open
kono
parents:
diff changeset
93 (File : in out File_Type;
kono
parents:
diff changeset
94 Mode : File_Mode;
kono
parents:
diff changeset
95 Name : String;
kono
parents:
diff changeset
96 Form : String := "");
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 procedure Close (File : in out File_Type);
kono
parents:
diff changeset
99 procedure Delete (File : in out File_Type);
kono
parents:
diff changeset
100 procedure Reset (File : in out File_Type; Mode : File_Mode);
kono
parents:
diff changeset
101 procedure Reset (File : in out File_Type);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 function Mode (File : File_Type) return File_Mode;
kono
parents:
diff changeset
104 function Name (File : File_Type) return String;
kono
parents:
diff changeset
105 function Form (File : File_Type) return String;
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 function Is_Open (File : File_Type) return Boolean;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 ------------------------------------------------------
kono
parents:
diff changeset
110 -- Control of default input, output and error files --
kono
parents:
diff changeset
111 ------------------------------------------------------
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 procedure Set_Input (File : File_Type);
kono
parents:
diff changeset
114 procedure Set_Output (File : File_Type);
kono
parents:
diff changeset
115 procedure Set_Error (File : File_Type);
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 function Standard_Input return File_Type;
kono
parents:
diff changeset
118 function Standard_Output return File_Type;
kono
parents:
diff changeset
119 function Standard_Error return File_Type;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 function Current_Input return File_Type;
kono
parents:
diff changeset
122 function Current_Output return File_Type;
kono
parents:
diff changeset
123 function Current_Error return File_Type;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 type File_Access is access constant File_Type;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 function Standard_Input return File_Access;
kono
parents:
diff changeset
128 function Standard_Output return File_Access;
kono
parents:
diff changeset
129 function Standard_Error return File_Access;
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 function Current_Input return File_Access;
kono
parents:
diff changeset
132 function Current_Output return File_Access;
kono
parents:
diff changeset
133 function Current_Error return File_Access;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 --------------------
kono
parents:
diff changeset
136 -- Buffer control --
kono
parents:
diff changeset
137 --------------------
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 -- Note: The parameter file is IN OUT in the RM, but this is clearly
kono
parents:
diff changeset
140 -- an oversight, and was intended to be IN, see AI95-00057.
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 procedure Flush (File : File_Type);
kono
parents:
diff changeset
143 procedure Flush;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 --------------------------------------------
kono
parents:
diff changeset
146 -- Specification of line and page lengths --
kono
parents:
diff changeset
147 --------------------------------------------
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 procedure Set_Line_Length (File : File_Type; To : Count);
kono
parents:
diff changeset
150 procedure Set_Line_Length (To : Count);
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 procedure Set_Page_Length (File : File_Type; To : Count);
kono
parents:
diff changeset
153 procedure Set_Page_Length (To : Count);
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 function Line_Length (File : File_Type) return Count;
kono
parents:
diff changeset
156 function Line_Length return Count;
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 function Page_Length (File : File_Type) return Count;
kono
parents:
diff changeset
159 function Page_Length return Count;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 ------------------------------------
kono
parents:
diff changeset
162 -- Column, Line, and Page Control --
kono
parents:
diff changeset
163 ------------------------------------
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 procedure New_Line (File : File_Type; Spacing : Positive_Count := 1);
kono
parents:
diff changeset
166 procedure New_Line (Spacing : Positive_Count := 1);
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 procedure Skip_Line (File : File_Type; Spacing : Positive_Count := 1);
kono
parents:
diff changeset
169 procedure Skip_Line (Spacing : Positive_Count := 1);
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 function End_Of_Line (File : File_Type) return Boolean;
kono
parents:
diff changeset
172 function End_Of_Line return Boolean;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 procedure New_Page (File : File_Type);
kono
parents:
diff changeset
175 procedure New_Page;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 procedure Skip_Page (File : File_Type);
kono
parents:
diff changeset
178 procedure Skip_Page;
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 function End_Of_Page (File : File_Type) return Boolean;
kono
parents:
diff changeset
181 function End_Of_Page return Boolean;
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 function End_Of_File (File : File_Type) return Boolean;
kono
parents:
diff changeset
184 function End_Of_File return Boolean;
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 procedure Set_Col (File : File_Type; To : Positive_Count);
kono
parents:
diff changeset
187 procedure Set_Col (To : Positive_Count);
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 procedure Set_Line (File : File_Type; To : Positive_Count);
kono
parents:
diff changeset
190 procedure Set_Line (To : Positive_Count);
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 function Col (File : File_Type) return Positive_Count;
kono
parents:
diff changeset
193 function Col return Positive_Count;
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 function Line (File : File_Type) return Positive_Count;
kono
parents:
diff changeset
196 function Line return Positive_Count;
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 function Page (File : File_Type) return Positive_Count;
kono
parents:
diff changeset
199 function Page return Positive_Count;
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 ----------------------------
kono
parents:
diff changeset
202 -- Character Input-Output --
kono
parents:
diff changeset
203 ----------------------------
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 procedure Get (File : File_Type; Item : out Character);
kono
parents:
diff changeset
206 procedure Get (Item : out Character);
kono
parents:
diff changeset
207 procedure Put (File : File_Type; Item : Character);
kono
parents:
diff changeset
208 procedure Put (Item : Character);
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 procedure Look_Ahead
kono
parents:
diff changeset
211 (File : File_Type;
kono
parents:
diff changeset
212 Item : out Character;
kono
parents:
diff changeset
213 End_Of_Line : out Boolean);
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 procedure Look_Ahead
kono
parents:
diff changeset
216 (Item : out Character;
kono
parents:
diff changeset
217 End_Of_Line : out Boolean);
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 procedure Get_Immediate
kono
parents:
diff changeset
220 (File : File_Type;
kono
parents:
diff changeset
221 Item : out Character);
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 procedure Get_Immediate
kono
parents:
diff changeset
224 (Item : out Character);
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 procedure Get_Immediate
kono
parents:
diff changeset
227 (File : File_Type;
kono
parents:
diff changeset
228 Item : out Character;
kono
parents:
diff changeset
229 Available : out Boolean);
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 procedure Get_Immediate
kono
parents:
diff changeset
232 (Item : out Character;
kono
parents:
diff changeset
233 Available : out Boolean);
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 -------------------------
kono
parents:
diff changeset
236 -- String Input-Output --
kono
parents:
diff changeset
237 -------------------------
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 procedure Get (File : File_Type; Item : out String);
kono
parents:
diff changeset
240 procedure Get (Item : out String);
kono
parents:
diff changeset
241 procedure Put (File : File_Type; Item : String);
kono
parents:
diff changeset
242 procedure Put (Item : String);
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 procedure Get_Line
kono
parents:
diff changeset
245 (File : File_Type;
kono
parents:
diff changeset
246 Item : out String;
kono
parents:
diff changeset
247 Last : out Natural);
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 procedure Get_Line
kono
parents:
diff changeset
250 (Item : out String;
kono
parents:
diff changeset
251 Last : out Natural);
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 function Get_Line (File : File_Type) return String;
kono
parents:
diff changeset
254 pragma Ada_05 (Get_Line);
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 function Get_Line return String;
kono
parents:
diff changeset
257 pragma Ada_05 (Get_Line);
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 procedure Put_Line
kono
parents:
diff changeset
260 (File : File_Type;
kono
parents:
diff changeset
261 Item : String);
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 procedure Put_Line
kono
parents:
diff changeset
264 (Item : String);
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 ---------------------------------------
kono
parents:
diff changeset
267 -- Generic packages for Input-Output --
kono
parents:
diff changeset
268 ---------------------------------------
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 -- The generic packages:
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 -- Ada.Text_IO.Integer_IO
kono
parents:
diff changeset
273 -- Ada.Text_IO.Modular_IO
kono
parents:
diff changeset
274 -- Ada.Text_IO.Float_IO
kono
parents:
diff changeset
275 -- Ada.Text_IO.Fixed_IO
kono
parents:
diff changeset
276 -- Ada.Text_IO.Decimal_IO
kono
parents:
diff changeset
277 -- Ada.Text_IO.Enumeration_IO
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 -- are implemented as separate child packages in GNAT, so the
kono
parents:
diff changeset
280 -- spec and body of these packages are to be found in separate
kono
parents:
diff changeset
281 -- child units. This implementation detail is hidden from the
kono
parents:
diff changeset
282 -- Ada programmer by special circuitry in the compiler that
kono
parents:
diff changeset
283 -- treats these child packages as though they were nested in
kono
parents:
diff changeset
284 -- Text_IO. The advantage of this special processing is that
kono
parents:
diff changeset
285 -- the subsidiary routines needed if these generics are used
kono
parents:
diff changeset
286 -- are not loaded when they are not used.
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 ----------------
kono
parents:
diff changeset
289 -- Exceptions --
kono
parents:
diff changeset
290 ----------------
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 Status_Error : exception renames IO_Exceptions.Status_Error;
kono
parents:
diff changeset
293 Mode_Error : exception renames IO_Exceptions.Mode_Error;
kono
parents:
diff changeset
294 Name_Error : exception renames IO_Exceptions.Name_Error;
kono
parents:
diff changeset
295 Use_Error : exception renames IO_Exceptions.Use_Error;
kono
parents:
diff changeset
296 Device_Error : exception renames IO_Exceptions.Device_Error;
kono
parents:
diff changeset
297 End_Error : exception renames IO_Exceptions.End_Error;
kono
parents:
diff changeset
298 Data_Error : exception renames IO_Exceptions.Data_Error;
kono
parents:
diff changeset
299 Layout_Error : exception renames IO_Exceptions.Layout_Error;
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 private
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 -- The following procedures have a File_Type formal of mode IN OUT because
kono
parents:
diff changeset
304 -- they may close the original file. The Close operation may raise an
kono
parents:
diff changeset
305 -- exception, but in that case we want any assignment to the formal to
kono
parents:
diff changeset
306 -- be effective anyway, so it must be passed by reference (or the caller
kono
parents:
diff changeset
307 -- will be left with a dangling pointer).
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 pragma Export_Procedure
kono
parents:
diff changeset
310 (Internal => Close,
kono
parents:
diff changeset
311 External => "",
kono
parents:
diff changeset
312 Mechanism => Reference);
kono
parents:
diff changeset
313 pragma Export_Procedure
kono
parents:
diff changeset
314 (Internal => Delete,
kono
parents:
diff changeset
315 External => "",
kono
parents:
diff changeset
316 Mechanism => Reference);
kono
parents:
diff changeset
317 pragma Export_Procedure
kono
parents:
diff changeset
318 (Internal => Reset,
kono
parents:
diff changeset
319 External => "",
kono
parents:
diff changeset
320 Parameter_Types => (File_Type),
kono
parents:
diff changeset
321 Mechanism => Reference);
kono
parents:
diff changeset
322 pragma Export_Procedure
kono
parents:
diff changeset
323 (Internal => Reset,
kono
parents:
diff changeset
324 External => "",
kono
parents:
diff changeset
325 Parameter_Types => (File_Type, File_Mode),
kono
parents:
diff changeset
326 Mechanism => (File => Reference));
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 -----------------------------------
kono
parents:
diff changeset
329 -- Handling of Format Characters --
kono
parents:
diff changeset
330 -----------------------------------
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 -- Line marks are represented by the single character ASCII.LF (16#0A#).
kono
parents:
diff changeset
333 -- In DOS and similar systems, underlying file translation takes care
kono
parents:
diff changeset
334 -- of translating this to and from the standard CR/LF sequences used in
kono
parents:
diff changeset
335 -- these operating systems to mark the end of a line. On output there is
kono
parents:
diff changeset
336 -- always a line mark at the end of the last line, but on input, this
kono
parents:
diff changeset
337 -- line mark can be omitted, and is implied by the end of file.
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 -- Page marks are represented by the single character ASCII.FF (16#0C#),
kono
parents:
diff changeset
340 -- The page mark at the end of the file may be omitted, and is normally
kono
parents:
diff changeset
341 -- omitted on output unless an explicit New_Page call is made before
kono
parents:
diff changeset
342 -- closing the file. No page mark is added when a file is appended to,
kono
parents:
diff changeset
343 -- so, in accordance with the permission in (RM A.10.2(4)), there may
kono
parents:
diff changeset
344 -- or may not be a page mark separating preexisting text in the file
kono
parents:
diff changeset
345 -- from the new text to be written.
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 -- A file mark is marked by the physical end of file. In DOS translation
kono
parents:
diff changeset
348 -- mode on input, an EOF character (SUB = 16#1A#) gets translated to the
kono
parents:
diff changeset
349 -- physical end of file, so in effect this character is recognized as
kono
parents:
diff changeset
350 -- marking the end of file in DOS and similar systems.
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 LM : constant := Character'Pos (ASCII.LF);
kono
parents:
diff changeset
353 -- Used as line mark
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 PM : constant := Character'Pos (ASCII.FF);
kono
parents:
diff changeset
356 -- Used as page mark, except at end of file where it is implied
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 --------------------------------
kono
parents:
diff changeset
359 -- Text_IO File Control Block --
kono
parents:
diff changeset
360 --------------------------------
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 Default_WCEM : System.WCh_Con.WC_Encoding_Method :=
kono
parents:
diff changeset
363 System.WCh_Con.WCEM_UTF8;
kono
parents:
diff changeset
364 -- This gets modified during initialization (see body) using
kono
parents:
diff changeset
365 -- the default value established in the call to Set_Globals.
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 package FCB renames System.File_Control_Block;
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 type Text_AFCB;
kono
parents:
diff changeset
370 type File_Type is access all Text_AFCB;
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 type 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 little 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 : System.WCh_Con.WC_Encoding_Method := Default_WCEM;
kono
parents:
diff changeset
400 -- Encoding method to be used for this file. Text_IO does not deal with
kono
parents:
diff changeset
401 -- wide characters, but it does deal with upper half characters in the
kono
parents:
diff changeset
402 -- range 16#80#-16#FF# which may need encoding, e.g. in UTF-8 mode.
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 Before_Upper_Half_Character : Boolean := False;
kono
parents:
diff changeset
405 -- This flag is set to indicate that an encoded upper half character has
kono
parents:
diff changeset
406 -- been read by Text_IO.Look_Ahead. If it is set to True, then it means
kono
parents:
diff changeset
407 -- that the stream is logically positioned before the character but is
kono
parents:
diff changeset
408 -- physically positioned after it. The character involved must be in
kono
parents:
diff changeset
409 -- the range 16#80#-16#FF#, i.e. if the flag is set, then we know the
kono
parents:
diff changeset
410 -- next character has a code greater than 16#7F#, and the value of this
kono
parents:
diff changeset
411 -- character is saved in Saved_Upper_Half_Character.
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 Saved_Upper_Half_Character : Character;
kono
parents:
diff changeset
414 -- This field is valid only if Before_Upper_Half_Character is set. It
kono
parents:
diff changeset
415 -- contains an upper-half character read by Look_Ahead. If Look_Ahead
kono
parents:
diff changeset
416 -- reads a character in the range 16#00# to 16#7F#, then it can use
kono
parents:
diff changeset
417 -- ungetc to put it back, but ungetc cannot be called more than once,
kono
parents:
diff changeset
418 -- so for characters above this range, we don't try to back up the
kono
parents:
diff changeset
419 -- file. Instead we save the character in this field and set the flag
kono
parents:
diff changeset
420 -- Before_Upper_Half_Character to True to indicate that we are logically
kono
parents:
diff changeset
421 -- positioned before this character even though the stream is physically
kono
parents:
diff changeset
422 -- positioned after it.
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 end record;
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 function AFCB_Allocate (Control_Block : Text_AFCB) return FCB.AFCB_Ptr;
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 procedure AFCB_Close (File : not null access Text_AFCB);
kono
parents:
diff changeset
429 procedure AFCB_Free (File : not null access Text_AFCB);
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 procedure Read
kono
parents:
diff changeset
432 (File : in out 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 Text_IO file is treated directly as Stream
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 procedure Write
kono
parents:
diff changeset
438 (File : in out Text_AFCB;
kono
parents:
diff changeset
439 Item : Ada.Streams.Stream_Element_Array);
kono
parents:
diff changeset
440 -- Write operation used when Text_IO file is treated directly as 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_In_AFCB : aliased Text_AFCB;
kono
parents:
diff changeset
447 Standard_Out_AFCB : aliased Text_AFCB;
kono
parents:
diff changeset
448 Standard_Err_AFCB : aliased Text_AFCB;
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 Standard_In : aliased File_Type := Standard_In_AFCB'Access;
kono
parents:
diff changeset
451 Standard_Out : aliased File_Type := Standard_Out_AFCB'Access;
kono
parents:
diff changeset
452 Standard_Err : aliased File_Type := Standard_Err_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 function EOF_Char return Integer;
kono
parents:
diff changeset
461 -- Returns the system-specific character indicating the end of a text file.
kono
parents:
diff changeset
462 -- This is exported for use by child packages such as Enumeration_Aux to
kono
parents:
diff changeset
463 -- eliminate their needing to depend directly on Interfaces.C_Streams,
kono
parents:
diff changeset
464 -- which is not available in certain target environments (such as AAMP).
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 procedure Initialize_Standard_Files;
kono
parents:
diff changeset
467 -- Initializes the file control blocks for the standard files. Called from
kono
parents:
diff changeset
468 -- the elaboration routine for this package, and from Reset_Standard_Files
kono
parents:
diff changeset
469 -- in package Ada.Text_IO.Reset_Standard_Files.
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 end Ada.Text_IO;