Debian Codegraph @

source_2020/pre_io.mss

raw
1 @Part(predefio, Root="ada.mss")
2
3 @Comment{$Date: 2020/06/03 00:09:01 $}
4
5 @Comment{$Source: e:\\cvsroot/ARM/Source/pre_io.mss,v $}
6 @Comment{$Revision: 1.76 $}
7 @LabeledClause{Input-Output}
8 @begin{Intro}
9 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
10 @Redundant[@Defn{input}@Defn{output}
11 Input-output is provided through
12 language-defined packages, each of which is a child of the root package Ada.
13 The generic packages Sequential_IO and Direct_IO
14 define input-output operations applicable to files containing elements
15 of a given type. The generic package Storage_IO supports reading from and
16 writing to an in-memory buffer.
17 Additional operations for text input-output are
18 supplied in the packages Text_IO@Chg{Version=[2],New=[,],Old=[ and]}
19 Wide_Text_IO@Chg{Version=[2],New=[, and Wide_Wide_Text_IO],Old=[]}.
20 Heterogeneous input-output is provided through the child packages
21 Streams.@!Stream_IO and Text_IO.@!Text_@!Streams
22 (see also @RefSecNum{Streams}).
23 The package IO_Exceptions defines the
24 exceptions needed by the predefined input-output packages.]
25 @end{Intro}
26
27 @begin{Inconsistent83}
28 @Defn{inconsistencies with Ada 83}
29 The introduction of Append_File as a new element of the enumeration type
30 File_Mode in Sequential_IO and Text_IO, and the introduction of
31 several new declarations
32 in Text_IO, may result in name clashes in the
33 presence of @key[use] clauses.
34 @end{Inconsistent83}
35
36 @begin{Extend83}
37 @Defn{extensions to Ada 83}
38 Text_IO enhancements
39 (Get_Immediate, Look_Ahead, Standard_Error, Modular_IO, Decimal_IO),
40 Wide_Text_IO, and the stream input-output facilities are new in Ada 95.
41 @end{Extend83}
42
43 @begin{DiffWord83}
44 RM83-14.6, "Low Level Input-Output,"
45 is removed. This has no semantic effect,
46 since the package was entirely implementation defined,
47 nobody actually implemented it,
48 and if they did, they can always provide it as a vendor-supplied
49 package.
50 @end{DiffWord83}
51
52 @begin{Diffword95}
53 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
54 @ChgAdded{Version=[2],Text=[Included package Wide_Wide_Text_IO
55 in this description.]}
56 @end{Diffword95}
57
58
59 @LabeledClause{External Files and File Objects}
60
61 @begin{StaticSem}
62 @Defn{external file}
63 @Defn2{Term=[name], Sec=(of an external file)}
64 @Defn2{Term=[form], Sec=(of an external file)}
65 Values input from the external environment of the program, or output to
66 the external environment,
67 are considered to occupy @i{external files}.
68 An external file can be anything external to the program that can
69 produce a value to be read or receive a value to be written. An
70 external file is identified by a string (the @i{name}). A second string
71 (the @i{form}) gives further system-dependent characteristics that may
72 be associated with the file, such as the physical organization or access
73 rights. The conventions governing the interpretation of such strings
74 shall be documented.
75
76 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
77 @Defn2{Term=[file], Sec=(as file object)}
78 Input and output operations are expressed as operations on objects of
79 some @i{file type}, rather than directly in terms of the external files. In
80 the remainder of this @Chg{Version=[3],New=[clause],Old=[section]}, the term
81 @i{file} is always used to refer to a file object; the term @i{external file} is
82 used otherwise.
83
84 Input-output for sequential files of values of a single element type is
85 defined by means of the generic package Sequential_IO.
86 In order to define sequential input-output for a given element type, an
87 instantiation of this generic unit, with the given type as actual
88 parameter, has to be declared. The resulting package contains the
89 declaration of a file type (called File_Type) for files of such
90 elements, as well as the operations applicable to these files, such as
91 the Open, Read, and Write procedures.
92
93 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
94 Input-output for direct access files is likewise defined by a generic
95 package called Direct_IO. Input-output in human-readable form is
96 defined by the (nongeneric) packages Text_IO for Character and String
97 data, @Chg{Version=[2],New=[],Old=[and ]}Wide_Text_IO for Wide_Character and
98 Wide_String data@Chg{Version=[2],New=[, and Wide_Wide_Text_IO for
99 Wide_Wide_Character and Wide_Wide_String data],Old=[]}.
100 Input-output for files containing streams of
101 elements representing values of possibly different types is defined by means of
102 the (nongeneric) package Streams.Stream_IO.
103
104 Before input or output operations can be performed on a file, the file
105 first has to be associated with an external file. While such an
106 association is in effect, the file is said to be @i{open}, and otherwise the
107 file is said to be @i{closed}.
108
109 The language does not define what happens to external files after the
110 completion of the main program and all the library tasks (in particular,
111 if corresponding files have not been closed).
112 @Defn2{Term=[access types], Sec=(input-output unspecified)}
113 @Defn2{Term=[input-output], Sec=(unspecified for access types)}
114 @PDefn{unspecified}
115 The effect of input-output for access types is unspecified.
116
117 @Leading@Keepnext@Defn2{Term=[current mode], Sec=(of an open file)}
118 An open file has a @i{current mode}, which is a value of one of the
119 following enumeration types:
120 @begin{DescribeCode}
121 @begin{Example}
122 @key[type] File_Mode @key[is] (In_File, Inout_File, Out_File); --@RI{ for Direct_IO}
123 @end{Example}
124
125 These values correspond respectively to the cases where only reading,
126 both reading and writing, or only writing are to be performed.
127 @begin{Example}
128 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
129 @key[type] File_Mode @key[is] (In_File, Out_File, Append_File);
130 --@RI{ for Sequential_IO, Text_IO, Wide_Text_IO, @Chg{Version=[2],New=[Wide_Wide_Text_IO, ],
131 Old=[]}and Stream_IO}
132 @end{Example}
133
134 These values correspond respectively to the cases where only reading,
135 only writing, or only appending are to be performed.
136
137 @Trailing@;The mode of a file can be changed.
138 @end{DescribeCode}
139
140 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
141 Several file management operations are common to Sequential_IO,
142 Direct_IO, Text_IO, @Chg{Version=[2],New=[],Old=[and ]}Wide_Text_IO@Chg{Version=[2],
143 New=[, and Wide_Wide_Text_IO],Old=[]}.
144 These operations are described in subclause
145 @RefSecNum{File Management} for
146 sequential and direct files.
147 Any additional effects concerning text
148 input-output are described in subclause @RefSecNum{Text File Management}.
149
150 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
151 The exceptions that can be propagated by the execution of an input-output
152 subprogram are defined in the package IO_Exceptions; the situations
153 in which they can be propagated are described following the description of
154 the subprogram (and in @Chg{Version=[3],New=[subclause],Old=[clause]}
155 @RefSecNum{Exceptions in Input-Output}).
156 The exceptions Storage_Error and Program_Error may be propagated.
157 (Program_Error can only be propagated due to errors made by the
158 caller of the subprogram.) Finally, exceptions can be propagated
159 in certain implementation-defined situations.
160 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
161 Text=[@ChgDeleted{Version=[2],
162 Text=[Any implementation-defined characteristics of the
163 input-output packages.]}]}
164 @begin{Discussion}
165 @ChgRef{Version=[2],Kind=[AddedNormal]}
166 @ChgAdded{Version=[2],Text=[The last sentence here is referring to the
167 documentation requirements in @RefSec{Exceptions in Input-Output}, and
168 the documentation summary item is provided there.]}
169 @end{Discussion}
170 @end{StaticSem}
171
172 @begin{Notes}
173 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
174 Each instantiation of the generic packages Sequential_IO and Direct_IO
175 declares a different type File_Type. In the case of Text_IO, Wide_Text_IO,
176 @Chg{Version=[2],New=[Wide_Wide_Text_IO, ],Old=[]}and Streams.Stream_IO,
177 the corresponding type File_Type is unique.
178
179 A bidirectional device can often be modeled as two sequential files
180 associated with the device, one of mode In_File, and one of mode
181 Out_File. An implementation may restrict the number of files that may
182 be associated with a given external file.
183 @end{Notes}
184
185 @begin{Diffword95}
186 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
187 @ChgAdded{Version=[2],Text=[Included package Wide_Wide_Text_IO
188 in this description.]}
189 @end{Diffword95}
190
191
192 @RMNewPageVer{Version=[1]}@Comment{Break here so printed Ada 95 w/ corrigendum RM looks better.}
193 @LabeledClause{Sequential and Direct Files}
194
195 @begin{StaticSem}
196 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00283-01]}
197 @Defn{sequential file}
198 @Defn{direct file}@Chg{Version=[2],New=[@Defn{stream file}],Old=[]}
199 Two kinds of access to external files are defined in this subclause:
200 @i{sequential access} and @i{direct access}.
201 The corresponding file types and the associated
202 operations are provided by the generic packages Sequential_IO and
203 Direct_IO. A file
204 object to be used for sequential access is called a @i{sequential file},
205 and one to be used for direct access is called a @i{direct file}.
206 Access to @Chg{Version=[2],New=[@i{stream file}s],Old=[stream files]}
207 is described in @RefSecNum(The Package Streams.Stream_IO).
208
209 @Defn{sequential access}
210 For sequential access, the file is viewed as a sequence of values that
211 are transferred in the order of their appearance (as produced by the
212 program or by the external environment).
213 When the file is opened with mode
214 In_File or Out_File, transfer starts respectively
215 from or to the beginning of the file. When the file is opened with mode
216 Append_File, transfer to the file starts after the last element of the
217 file.
218 @begin{Discussion}
219 Adding stream I/O necessitates a review of the terminology. In
220 Ada 83, `sequential' implies both the access method (purely sequential
221 @em that is, no indexing or positional access) and homogeneity. Direct
222 access includes purely sequential access and indexed access, as well as
223 homogeneity. In Ada 95, streams allow purely sequential access but also
224 positional access to an individual
225 element, and are
226 heterogeneous. We considered generalizing the notion of
227 `sequential file' to include both Sequential_IO and Stream_IO files, but
228 since streams allow positional access it seems misleading to call them
229 sequential files. Or, looked at differently, if the criterion for
230 calling something a sequential file is whether it permits (versus
231 requires) purely sequential access, then one could just as soon regard a
232 Direct_IO file as a sequential file.
233
234 It seems better to regard `sequential file' as meaning `only permitting
235 purely sequential access'; hence we have decided to supplement `sequential
236 access' and `direct access' with a third category, informally called `access
237 to streams'. (We decided against the term `stream access' because of possible
238 confusion with the Stream_Access type declared in one of the stream packages.)@end{discussion}
239
240 @Defn{direct access}
241 @Defn2{Term=[index], Sec=(of an element of an open direct file)}
242 @Defn2{Term=[current size], Sec=(of an external file)}
243 For direct access, the file is viewed as a set of elements occupying
244 consecutive positions in linear order; a value can be transferred to or
245 from an element of the file at any selected position. The position of
246 an element is specified by its @i{index}, which is a number, greater than
247 zero, of the implementation-defined integer type Count. The first
248 element, if any, has index one; the index of the last element, if any,
249 is called the @i{current size}; the current size is zero if there are no
250 elements. The current size is a property of the external file.
251
252 @Defn2{Term=[current index], Sec=(of an open direct file)}
253 An open direct file has a @i{current index}, which is the index that will be
254 used by the next read or write operation. When a direct file is opened,
255 the current index is set to one. The current index of a direct file is
256 a property of a file object, not of an external file.
257 @end{StaticSem}
258
259 @begin{DiffWord95}
260 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00283-01]}
261 @ChgAdded{Version=[2],Text=[Italicized @lquotes@;stream file@rquotes@;
262 to clarify that this is another kind of file.]}
263 @end{DiffWord95}
264
265
266 @LabeledSubClause{The Generic Package Sequential_IO}
267
268 @begin{StaticSem}
269 @Leading@;The generic library package Sequential_IO has the following declaration:
270 @begin{Example}
271 @key[with] Ada.IO_Exceptions;
272 @key[generic]
273 @key[type] Element_Type(<>) @key[is] @key[private];
274 @key[package] Ada.Sequential_IO @key[is]@ChildUnit{Parent=[Ada],Child=[Sequential_IO]}
275
276 @key[type] @AdaTypeDefn{File_Type} @key[is] @key[limited] @key[private];
277
278 @key[type] @AdaTypeDefn{File_Mode} @key[is] (In_File, Out_File, Append_File);
279
280 @RI{-- File management}
281
282 @key[procedure] @AdaSubDefn{Create}(File : @key[in] @key[out] File_Type;
283 Mode : @key[in] File_Mode := Out_File;
284 Name : @key[in] String := "";
285 Form : @key[in] String := "");
286
287 @key[procedure] @AdaSubDefn{Open} (File : @key[in] @key[out] File_Type;
288 Mode : @key[in] File_Mode;
289 Name : @key[in] String;
290 Form : @key[in] String := "");
291
292 @key[procedure] @AdaSubDefn{Close} (File : @key[in] @key[out] File_Type);
293 @key[procedure] @AdaSubDefn{Delete}(File : @key[in] @key[out] File_Type);
294 @key[procedure] @AdaSubDefn{Reset} (File : @key[in] @key[out] File_Type; Mode : @key[in] File_Mode);
295 @key[procedure] @AdaSubDefn{Reset} (File : @key[in] @key[out] File_Type);
296
297 @key[function] @AdaSubDefn{Mode} (File : @key[in] File_Type) @key[return] File_Mode;
298 @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] String;
299 @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] String;
300
301 @key[function] @AdaSubDefn{Is_Open}(File : @key[in] File_Type) @key[return] Boolean;
302
303 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0130-1]}
304 @ChgAdded{Version=[4],Text=[ @key[procedure] @AdaSubDefn{Flush} (File : @key[in] File_Type);]}
305
306 --@RI{ Input and output operations}
307
308 @key[procedure] @AdaSubDefn{Read} (File : @key[in] File_Type; Item : @key[out] Element_Type);
309 @key[procedure] @AdaSubDefn{Write} (File : @key[in] File_Type; Item : @key[in] Element_Type);
310
311 @key[function] @AdaSubDefn{End_Of_File}(File : @key[in] File_Type) @key[return] Boolean;
312
313 @keepnext --@RI{ Exceptions}
314
315 @AdaExcDefn{Status_Error} : @key[exception] @key[renames] IO_Exceptions.Status_Error;
316 @AdaExcDefn{Mode_Error} : @key[exception] @key[renames] IO_Exceptions.Mode_Error;
317 @AdaExcDefn{Name_Error} : @key[exception] @key[renames] IO_Exceptions.Name_Error;
318 @AdaExcDefn{Use_Error} : @key[exception] @key[renames] IO_Exceptions.Use_Error;
319 @AdaExcDefn{Device_Error} : @key[exception] @key[renames] IO_Exceptions.Device_Error;
320 @AdaExcDefn{End_Error} : @key[exception] @key[renames] IO_Exceptions.End_Error;
321 @AdaExcDefn{Data_Error} : @key[exception] @key[renames] IO_Exceptions.Data_Error;
322
323 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
324 @ChgAdded{Version=[5],Text=[ @key[package] @AdaPackDefn{Wide_File_Names} @key[is]]}
325
326 @ChgRef{Version=[5],Kind=[Added]}
327 @ChgAdded{Version=[5],Text=[ -- @examcom{File management}]}
328
329 @ChgRef{Version=[5],Kind=[Added]}
330 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Create}(File : @key[in out] File_Type;
331 Mode : @key[in] File_Mode := Out_File;
332 Name : @key[in] Wide_String := "";
333 Form : @key[in] Wide_String := "");]}
334
335 @ChgRef{Version=[5],Kind=[Added]}
336 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Open} (File : @key[in out] File_Type;
337 Mode : @key[in] File_Mode;
338 Name : @key[in] Wide_String;
339 Form : @key[in] Wide_String := "");]}
340
341 @ChgRef{Version=[5],Kind=[Added]}
342 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] Wide_String;]}
343
344 @ChgRef{Version=[5],Kind=[Added]}
345 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] Wide_String;]}
346
347 @ChgRef{Version=[5],Kind=[Added]}
348 @ChgAdded{Version=[5],Text=[ @key[end] Wide_File_Names;]}
349
350
351 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
352 @ChgAdded{Version=[5],Text=[ @key[package] @AdaPackDefn{Wide_Wide_File_Names} @key[is]]}
353
354 @ChgRef{Version=[5],Kind=[Added]}
355 @ChgAdded{Version=[5],Text=[ -- @examcom{File management}]}
356
357 @ChgRef{Version=[5],Kind=[Added]}
358 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Create}(File : @key[in out] File_Type;
359 Mode : @key[in] File_Mode := Out_File;
360 Name : @key[in] Wide_Wide_String := "";
361 Form : @key[in] Wide_Wide_String := "");]}
362
363 @ChgRef{Version=[5],Kind=[Added]}
364 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Open} (File : @key[in out] File_Type;
365 Mode : @key[in] File_Mode;
366 Name : @key[in] Wide_Wide_String;
367 Form : @key[in] Wide_Wide_String := "");]}
368
369 @ChgRef{Version=[5],Kind=[Added]}
370 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] Wide_Wide_String;]}
371
372 @ChgRef{Version=[5],Kind=[Added]}
373 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] Wide_Wide_String;]}
374
375 @ChgRef{Version=[5],Kind=[Added]}
376 @ChgAdded{Version=[5],Text=[ @key[end] Wide_Wide_File_Names;]}
377
378
379 @key[private]
380 ... -- @RI{not specified by the language}
381 @key[end] Ada.Sequential_IO;
382 @end{Example}
383
384 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00360-01]}
385 @ChgAdded{Version=[2],Text=[The type File_Type
386 needs finalization@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}
387 (see @RefSecNum{Assignment and Finalization})
388 in every instantiation of Sequential_IO.]}
389
390 @end{StaticSem}
391
392 @begin{Incompatible83}
393 @Defn{incompatibilities with Ada 83}
394 The new enumeration element Append_File may introduce upward incompatibilities.
395 It is possible that a program based on the assumption that File_Mode'Last = Out_File
396 will be illegal (e.g., case statement choice coverage)
397 or execute with a different effect in Ada 95.
398 @end{Incompatible83}
399
400 @begin{ImplNote}
401 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0097],ARef=[AI95-00115-01]}
402 @ChgRef{Version=[2],Kind=[DeletedAdded],ARef=[AI95-00344-01]}
403 @ChgDeleted{Version=[2],Text=[@Chg{Version=[1],New=[File_Type cannot be
404 implemented as a (directly) controlled type, as Ada.Sequential_IO can be
405 instantiated at any nesting depth. File_Type could have a component of a
406 controlled type, as long as that type is declared in some other (nongeneric)
407 package.],Old=[]}]}@ChgNote{AI-344 allows controlled types to be declared at
408 any nesting depth, so this note is obsolete.}
409 @end{ImplNote}
410
411 @begin{Incompatible95}
412 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00360-01]}
413 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
414 @B[Amendment Correction:] File_Type in
415 an instance of Sequential_IO is defined to need finalization. If the
416 restriction No_Nested_Finalization (see @RefSecNum{Tasking Restrictions})
417 applies to the partition, and File_Type does not have a controlled part, it
418 will not be allowed in local objects in Ada 2005 whereas it would be allowed
419 in original Ada 95. Such code is not portable, as another Ada compiler
420 may have a controlled part in File_Type, and thus would be illegal.]}
421 @end{Incompatible95}
422
423 @begin{Incompatible2012}
424 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0130-1]}
425 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}
426 @b<Corrigendum:> The Flush procedure is newly added to Ada.Sequential_IO.
427 If an instance of Ada.Sequential_IO is referenced in a @nt{use_clause}, and
428 a procedure Flush is defined in some other package that is also referenced
429 in a @nt{use_clause}, the user-defined Flush may no longer be use-visible,
430 resulting in errors. This should be rare and is easily fixed if it does occur.]}
431
432 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0021-1]}
433 @ChgAdded{Version=[5],Text=[The Wide_File_Names and Wide_Wide_File_Names
434 nested packages are newly added to Ada.Sequential_IO.
435 If an instance of Ada.Sequential_IO is referenced in a @nt{use_clause}, and
436 an entity with one of those names is defined in some other package that is
437 also referenced in a @nt{use_clause}, the user-defined entity may no longer be
438 use-visible, resulting in errors. This should be rare and is easily fixed if
439 it does occur.]}
440 @end{Incompatible2012}
441
442
443 @LabeledSubClause{File Management}
444
445 @begin{StaticSem}
446
447 The procedures and functions described in this subclause provide for the
448 control of external files; their declarations are repeated in each of
449 the packages for sequential, direct,
450 text, and stream
451 input-output. For
452 text input-output, the procedures Create, Open, and Reset have
453 additional effects described in subclause
454 @RefSecNum{Text File Management}.
455 @begin{DescribeCode}
456 @begin{Example}@Keepnext
457 @key[procedure] Create(File : @key[in] @key[out] File_Type;
458 Mode : @key[in] File_Mode := @RI{default_mode};
459 Name : @key[in] String := "";
460 Form : @key[in] String := "");
461 @end{Example}
462 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00283-01]}
463 Establishes a new external file, with the given name and form,
464 and associates this external file with the given file. The
465 given file is left open. The current mode of the given file
466 is set to the given access mode. The default access mode is
467 the mode Out_File for sequential@Chg{Version=[2],New=[, stream,],Old=[]}
468 and text input-output; it is
469 the mode Inout_File for direct input-output. For direct
470 access, the size of the created file is implementation defined.
471
472 @begin{Ramification}
473 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0005-1]}
474 @ChgAdded{Version=[4],Text=[For a direct file, the initial value of current
475 index is 1 (see @RefSecNum{Sequential and Direct Files}).]}
476 @end{Ramification}
477
478 A null string for Name specifies an
479 external file that is not accessible after the completion of
480 the main program (a temporary file). A null string for Form
481 specifies the use of the default options of the implementation
482 for the external file.
483
484 @Trailing@;The exception Status_Error is propagated if the given file is
485 already open. The exception Name_Error is propagated if the
486 string given as Name does not allow the identification of an
487 external file. The exception Use_Error is propagated if, for the
488 specified mode, the external environment does not support creation of
489 an external file with the given name (in the absence of
490 Name_Error) and form.
491
492 @begin{Example}@Keepnext
493 @key[procedure] Open(File : @key[in] @key[out] File_Type;
494 Mode : @key[in] File_Mode;
495 Name : @key[in] String;
496 Form : @key[in] String := "");
497 @end{Example}
498 Associates the given file with an existing external file
499 having the given name and form, and sets the current mode of
500 the given file to the given mode. The given file is left open.
501
502 @begin{Ramification}
503 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0005-1]}
504 @ChgAdded{Version=[4],Text=[For a direct file, the initial value of current
505 index is 1 (see @RefSecNum{Sequential and Direct Files}).]}
506 @end{Ramification}
507
508 @Trailing@;The exception Status_Error is propagated if the given file is
509 already open. The exception Name_Error is propagated if the
510 string given as Name does not allow the identification of an
511 external file; in particular, this exception is propagated if no
512 external file with the given name exists. The exception
513 Use_Error is propagated if, for the specified mode, the
514 external environment does not support opening for an external file with
515 the given name (in the absence of Name_Error) and form.
516
517 @begin{Example}@Keepnext
518 @key[procedure] Close(File : @key[in] @key[out] File_Type);
519 @end{Example}
520 Severs the association between the given file and its
521 associated external file. The given file is left closed.
522 In addition, for sequential files, if the file
523 being closed has mode Out_File or Append_File, then the last element
524 written since the most recent open or reset is the last element that
525 can be read from the file. If no elements have been written and the
526 file mode is Out_File, then the closed file is empty.
527 If no elements have been written and the file mode is Append_File,
528 then the closed file is unchanged.
529
530 @Trailing@;The exception Status_Error is propagated if the given file is not open.
531
532 @begin{Example}@Keepnext
533 @key[procedure] Delete(File : @key[in] @key[out] File_Type);
534 @end{Example}
535 Deletes the external file associated with the given file. The
536 given file is closed, and the external file ceases to exist.
537
538 @Trailing@;The exception Status_Error is propagated if the given file is not
539 open. The exception Use_Error is propagated if
540 deletion of the external file is not supported
541 by the external environment.
542
543 @begin{Example}@Keepnext
544 @key[procedure] Reset(File : @key[in] @key[out] File_Type; Mode : @key[in] File_Mode);
545 @key[procedure] Reset(File : @key[in] @key[out] File_Type);
546 @end{Example}
547 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00085-01]}
548 Resets the given file so that reading from its
549 elements can be restarted from the beginning of the
550 @Chg{Version=[2],New=[external ],Old=[]}file (for
551 modes In_File and Inout_File), and so that writing to its elements can be
552 restarted at the beginning of the
553 @Chg{Version=[2],New=[external ],Old=[]}file (for modes Out_File and Inout_File)
554 or after the last element of the @Chg{Version=[2],New=[external ],Old=[]}file
555 (for mode Append_File).
556 In particular, for direct access this means that the current
557 index is set to one. If a Mode parameter is supplied, the
558 current mode of the given file is set to the given mode. In addition, for
559 sequential files, if the given file has mode Out_File or Append_File when
560 Reset is called, the last element written since the most recent open or
561 reset is the last element that can be read from the
562 @Chg{Version=[2],New=[external ],Old=[]}file. If no elements
563 have been written and the file mode is Out_File, the reset file is empty.
564 If no elements have been written and the file mode is Append_File,
565 then the reset file is unchanged.
566
567 @Trailing@;The exception Status_Error is propagated if the file is not open.
568 The exception Use_Error is propagated if the external environment
569 does not support resetting for the external file and, also, if the
570 external environment does not support resetting to the specified mode
571 for the external file.
572
573 @begin{Example}@Keepnext
574 @key[function] Mode(File : @key[in] File_Type) @key[return] File_Mode;
575 @end{Example}
576 Returns the current mode of the given file.
577
578 @Trailing@;The exception Status_Error is propagated if the file is not open.
579
580 @begin{Example}@Keepnext
581 @key[function] Name(File : @key[in] File_Type) @key[return] String;
582 @end{Example}
583 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00248-01]}
584 Returns a string which uniquely identifies the external file
585 currently associated with the given file (and may thus be used
586 in an Open operation).@Chg{Version=[2],New=[],Old=[ If an external
587 environment allows alternative
588 specifications of the name (for example, abbreviations), the string
589 returned by the function should correspond to a full specification of
590 the name.]}
591
592 @begin{Discussion}
593 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00248-01]}
594 @ChgAdded{Version=[2],Text=[Retrieving the full path can be
595 accomplished by passing the result of Name to Directories.Full_Name
596 (see @RefSecNum{The Package Directories}). It is important to drop the
597 requirement on Name, as the only way to accomplish this requirement given
598 that the current directory can be changed with package Directories is to
599 store the full path when the file is opened. That's expensive, and it's
600 better for users that need the full path to explicitly request it.]}
601 @end{Discussion}
602
603 @Trailing@;The exception Status_Error is propagated if the given file is not
604 open. The exception Use_Error is propagated if the associated
605 external file is a temporary file that cannot be opened
606 by any name.
607
608 @begin{Example}@Keepnext
609 @key[function] Form(File : @key[in] File_Type) @key[return] String;
610 @end{Example}
611 Returns the form string for the external file currently
612 associated with the given file. If an
613 external environment allows
614 alternative specifications of the form (for example,
615 abbreviations using default options), the string returned by
616 the function should correspond to a full specification (that
617 is, it should indicate explicitly all options selected,
618 including default options).
619
620 @Trailing@;The exception Status_Error is propagated if the given file is not open.
621
622 @begin{Example}@Keepnext
623 @key[function] Is_Open(File : @key[in] File_Type) @key[return] Boolean;
624 @end{Example}
625 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
626 Returns True if the file is open (that is, if it is associated
627 with an external file)@Chg{Version=[3],New=[;],Old=[,]}
628 otherwise@Chg{Version=[3],New=[,],Old=[]} returns False.
629
630 @begin{Example}@Keepnext
631 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0130-1]}
632 @ChgAdded{Version=[4],Type=[Leading],Text=[@key[procedure] Flush(File : @key[in] File_Type);]}
633 @end{Example}
634 @ChgRef{Version=[4],Kind=[Added]}
635 @ChgAdded{Version=[4],Text=[The Flush procedure synchronizes the external
636 file with the internal file (by flushing any internal buffers) without
637 closing the file. For a direct file, the current index is unchanged; for a
638 stream file (see @RefSecNum{The Package Streams.Stream_IO}), the current
639 position is unchanged.]}
640
641 @ChgRef{Version=[4],Kind=[Added]}
642 @ChgAdded{Version=[4],Type=[Trailing],Text=[The exception Status_Error is
643 propagated if the file is not open. The exception Mode_Error is propagated
644 if the mode of the file is In_File.]}
645
646 @end{DescribeCode}
647
648 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
649 @ChgAdded{Version=[5],Text=[The nested package Wide_File_Names provides
650 operations equivalent to the operations of the same name of the outer package
651 except that Wide_String is used instead of String for the name and form of the
652 external file.]}
653
654 @begin{ImplNote}
655 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0021-1]}
656 @ChgAdded{Version=[5],Text=[The expectation is that if one opens a file with
657 this subpackage and then requests the name with Name from this subpackage,
658 the result will include
659 the same Wide_Characters that were used to open the file (rather than some
660 encoded form). Since file names are completely implementation-defined, we
661 cannot say this normatively. We have no expectations when retrieving the name
662 of a file opened with this package using the String Name. Similar
663 considerations apply to the nested package Wide_Wide_File_Names (see below).]}
664 @end{ImplNote}
665
666
667 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
668 @ChgAdded{Version=[5],Text=[The nested package Wide_Wide_File_Names provides
669 operations equivalent to the operations of the same name of the outer package
670 except that Wide_Wide_String is used instead of String for the name and form of
671 the external file.]}
672
673 @end{StaticSem}
674
675 @begin{ImplPerm}
676 An implementation may propagate
677 Name_Error or Use_Error if an attempt is
678 made to use an I/O feature that cannot be supported by the
679 implementation due to limitations in the external environment.
680 Any such restriction should be documented.
681 @end{ImplPerm}
682
683 @begin{DiffWord95}
684 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00085-01]}
685 @ChgAdded{Version=[2],Text=[Clarified that Reset affects and depends on the
686 external file.]}
687
688 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00248-01]}
689 @ChgAdded{Version=[2],Text=[Removed the requirement for Name to return
690 a full path; this is now accomplished by Directories.Full_Name(Name(File))
691 (see @RefSecNum{The Package Directories}). This is not documented as
692 an inconsistency, because there is no requirement for implementations to
693 change @em the Ada 95 behavior is still allowed, it just is no longer
694 required.]}
695
696 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00283-01]}
697 @ChgAdded{Version=[2],Text=[Added text to specify the default mode for
698 a stream file.]}
699 @end{DiffWord95}
700
701 @begin{DiffWord2012}
702 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0130-1]}
703 @ChgAdded{Version=[4],Text=[Procedure Flush is now defined here, so it
704 can be used for all of the I/O packages.]}
705
706 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0021-1]}
707 @ChgAdded{Version=[5],Text=[The nested Wide_File_Names and
708 Wide_Wide_File_Names packages are now described here.]}
709 @end{DiffWord2012}
710
711
712 @LabeledSubClause{Sequential Input-Output Operations}
713
714 @begin{StaticSem}
715 The operations available for sequential input and output are described
716 in this subclause. The exception Status_Error is propagated if any of these
717 operations is attempted for a file that is not open.
718 @begin{DescribeCode}
719 @begin{Example}@Keepnext
720 @key[procedure] Read(File : @key[in] File_Type; Item : @key[out] Element_Type);
721 @end{Example}
722 Operates on a file of mode In_File. Reads an element
723 from the given file, and returns the value of this element
724 in the Item parameter.
725 @begin{Discussion}
726 We considered basing Sequential_IO.Read on Element_Type'Read from
727 an implicit stream associated with the sequential file.
728 However, Element_Type'Read is a type-related
729 attribute, whereas Sequential_IO should take advantage of the
730 particular constraints of the actual subtype corresponding
731 to Element_Type to minimize the size of the external file.
732 Furthermore, forcing the implementation of Sequential_IO to
733 be based on Element_Type'Read would create an upward incompatibility
734 since existing data files written by an Ada 83 program using
735 Sequential_IO might not be readable by the identical program
736 built with an Ada 95 implementation of Sequential_IO.
737
738 An Ada 95 implementation might still use an implementation-defined
739 attribute analogous to 'Read to implement the procedure Read,
740 but that attribute will likely have to be subtype-specific
741 rather than type-related, and it need not be user-specifiable.
742 Such an attribute will presumably be needed to implement the
743 generic package Storage_IO (see @RefSecNum{The Generic Package Storage_IO}).
744 @end{Discussion}
745
746 @Trailing@;The exception Mode_Error is propagated if the mode is not In_File.
747 The exception End_Error is propagated if no more elements can be
748 read from the given file.
749 The exception Data_Error can be propagated if the element read cannot
750 be interpreted as a value of the subtype Element_Type
751 (see @RefSec{Exceptions in Input-Output}).
752 @begin{Discussion}
753 Data_Error need not be propagated if the check is too complex.
754 See @RefSec{Exceptions in Input-Output}.
755 @end{Discussion}
756
757 @begin{Example}@Keepnext
758 @key[procedure] Write(File : @key[in] File_Type; Item : @key[in] Element_Type);
759 @end{Example}
760 Operates on a file of mode Out_File or Append_File.
761 Writes the value of Item to the given file.
762
763 @Trailing@;The exception Mode_Error is propagated if the mode is not
764 Out_File or Append_File. The exception Use_Error is propagated if the capacity
765 of the external file is exceeded.
766
767 @begin{Example}@Keepnext
768 @key[function] End_Of_File(File : @key[in] File_Type) @key[return] Boolean;
769 @end{Example}
770 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
771 Operates on a file of mode In_File. Returns True if no more
772 elements can be read from the given file;
773 otherwise@Chg{Version=[3],New=[,],Old=[]} returns False.
774
775 The exception Mode_Error is propagated if the mode is not In_File.
776 @end{DescribeCode}
777 @end{StaticSem}
778
779 @LabeledSubClause{The Generic Package Direct_IO}
780
781 @begin{StaticSem}
782 @Leading@;The generic library package Direct_IO has the following declaration:
783 @begin{Example}
784 @key[with] Ada.IO_Exceptions;
785 @key[generic]
786 @key[type] Element_Type @key[is] @key[private];
787 @key[package] Ada.Direct_IO @key[is]@ChildUnit{Parent=[Ada],Child=[Direct_IO]}
788
789 @key[type] @AdaTypeDefn{File_Type} @key[is] @key[limited] @key[private];
790
791 @key[type] @AdaTypeDefn{File_Mode} @key[is] (In_File, Inout_File, Out_File);
792 @key[type] @AdaTypeDefn{Count} @key[is] @key[range] 0 .. @RI[implementation-defined];
793 @key[subtype] @AdaSubtypeDefn{Name=[Positive_Count],Of=[Count]} @key[is] Count @key[range] 1 .. Count'Last;
794
795 --@RI{ File management}
796
797 @key[procedure] @AdaSubDefn{Create}(File : @key[in] @key[out] File_Type;
798 Mode : @key[in] File_Mode := Inout_File;
799 Name : @key[in] String := "";
800 Form : @key[in] String := "");
801
802 @key[procedure] @AdaSubDefn{Open} (File : @key[in] @key[out] File_Type;
803 Mode : @key[in] File_Mode;
804 Name : @key[in] String;
805 Form : @key[in] String := "");
806
807 @key[procedure] @AdaSubDefn{Close} (File : @key[in] @key[out] File_Type);
808 @key[procedure] @AdaSubDefn{Delete}(File : @key[in] @key[out] File_Type);
809 @key[procedure] @AdaSubDefn{Reset} (File : @key[in] @key[out] File_Type; Mode : @key[in] File_Mode);
810 @key[procedure] @AdaSubDefn{Reset} (File : @key[in] @key[out] File_Type);
811
812 @key[function] @AdaSubDefn{Mode} (File : @key[in] File_Type) @key[return] File_Mode;
813 @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] String;
814 @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] String;
815
816 @key[function] @AdaSubDefn{Is_Open}(File : @key[in] File_Type) @key[return] Boolean;
817
818 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0130-1]}
819 @ChgAdded{Version=[4],Text=[ @key[procedure] @AdaSubDefn{Flush} (File : @key[in] File_Type);]}
820
821 --@RI{ Input and output operations}
822
823 @key[procedure] @AdaSubDefn{Read} (File : @key[in] File_Type; Item : @key[out] Element_Type;
824 From : @key[in] Positive_Count);
825 @key[procedure] @AdaSubDefn{Read} (File : @key[in] File_Type; Item : @key[out] Element_Type);
826
827 @key[procedure] @AdaSubDefn{Write}(File : @key[in] File_Type; Item : @key[in] Element_Type;
828 To : @key[in] Positive_Count);
829 @key[procedure] @AdaSubDefn{Write}(File : @key[in] File_Type; Item : @key[in] Element_Type);
830
831 @key[procedure] @AdaSubDefn{Set_Index}(File : @key[in] File_Type; To : @key[in] Positive_Count);
832
833 @key[function] @AdaSubDefn{Index}(File : @key[in] File_Type) @key[return] Positive_Count;
834 @key[function] @AdaSubDefn{Size} (File : @key[in] File_Type) @key[return] Count;
835
836 @key[function] @AdaSubDefn{End_Of_File}(File : @key[in] File_Type) @key[return] Boolean;
837
838 @keepnext --@RI{ Exceptions}
839
840 @AdaExcDefn{Status_Error} : @key[exception] @key[renames] IO_Exceptions.Status_Error;
841 @AdaExcDefn{Mode_Error} : @key[exception] @key[renames] IO_Exceptions.Mode_Error;
842 @AdaExcDefn{Name_Error} : @key[exception] @key[renames] IO_Exceptions.Name_Error;
843 @AdaExcDefn{Use_Error} : @key[exception] @key[renames] IO_Exceptions.Use_Error;
844 @AdaExcDefn{Device_Error} : @key[exception] @key[renames] IO_Exceptions.Device_Error;
845 @AdaExcDefn{End_Error} : @key[exception] @key[renames] IO_Exceptions.End_Error;
846 @AdaExcDefn{Data_Error} : @key[exception] @key[renames] IO_Exceptions.Data_Error;
847
848 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
849 @ChgAdded{Version=[5],Text=[ @key[package] @AdaPackDefn{Wide_File_Names} @key[is]]}
850
851 @ChgRef{Version=[5],Kind=[Added]}
852 @ChgAdded{Version=[5],Text=[ -- @examcom{File management}]}
853
854 @ChgRef{Version=[5],Kind=[Added]}
855 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Create}(File : @key[in out] File_Type;
856 Mode : @key[in] File_Mode := Inout_File;
857 Name : @key[in] Wide_String := "";
858 Form : @key[in] Wide_String := "");]}
859
860 @ChgRef{Version=[5],Kind=[Added]}
861 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Open} (File : @key[in out] File_Type;
862 Mode : @key[in] File_Mode;
863 Name : @key[in] Wide_String;
864 Form : @key[in] Wide_String := "");]}
865
866
867 @ChgRef{Version=[5],Kind=[Added]}
868 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] Wide_String;]}
869
870 @ChgRef{Version=[5],Kind=[Added]}
871 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] Wide_String;]}
872
873 @ChgRef{Version=[5],Kind=[Added]}
874 @ChgAdded{Version=[5],Text=[ @key[end] Wide_File_Names;]}
875
876
877 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
878 @ChgAdded{Version=[5],Text=[ @key[package] @AdaPackDefn{Wide_Wide_File_Names} @key[is]]}
879
880 @ChgRef{Version=[5],Kind=[Added]}
881 @ChgAdded{Version=[5],Text=[ -- @examcom{File management}]}
882
883 @ChgRef{Version=[5],Kind=[Added]}
884 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Create}(File : @key[in out] File_Type;
885 Mode : @key[in] File_Mode := Inout_File;
886 Name : @key[in] Wide_Wide_String := "";
887 Form : @key[in] Wide_Wide_String := "");]}
888
889 @ChgRef{Version=[5],Kind=[Added]}
890 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Open} (File : @key[in out] File_Type;
891 Mode : @key[in] File_Mode;
892 Name : @key[in] Wide_Wide_String;
893 Form : @key[in] Wide_Wide_String := "");]}
894
895 @ChgRef{Version=[5],Kind=[Added]}
896 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] Wide_Wide_String;]}
897
898 @ChgRef{Version=[5],Kind=[Added]}
899 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] Wide_Wide_String;]}
900
901 @ChgRef{Version=[5],Kind=[Added]}
902 @ChgAdded{Version=[5],Text=[ @key[end] Wide_Wide_File_Names;]}
903
904
905 @key[private]
906 ... -- @RI{not specified by the language}
907 @key[end] Ada.Direct_IO;
908 @end{Example}
909 @begin{Reason}
910 The Element_Type formal of Direct_IO does not have an
911 @nt{unknown_discriminant_part} (unlike Sequential_IO)
912 so that the implementation can make use of the ability to declare
913 uninitialized variables of the type.
914 @end{Reason}
915
916 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00360-01]}
917 @ChgAdded{Version=[2],Text=[The type File_Type
918 needs finalization@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}
919 (see @RefSecNum{Assignment and Finalization})
920 in every instantiation of Direct_IO.]}
921
922 @begin{ImplNote}
923 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0097],ARef=[AI95-00115-01]}
924 @ChgRef{Version=[2],Kind=[DeletedAdded],ARef=[AI95-00344-01]}
925 @ChgDeleted{Version=[2],Text=[@Chg{Version=[1],New=[File_Type cannot be
926 implemented as a (directly)
927 controlled type, as Ada.Direct_IO can be instantiated at any nesting depth.
928 File_Type could have a component of a controlled type, as long as that type is
929 declared in some other (nongeneric) package.],Old=[]}]}
930 @end{ImplNote}
931
932 @end{StaticSem}
933
934 @begin{Incompatible95}
935 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00360-01]}
936 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
937 @B[Amendment Correction:] File_Type in
938 an instance of Direct_IO is defined to need finalization. If the
939 restriction No_Nested_Finalization (see @RefSecNum{Tasking Restrictions})
940 applies to the partition, and File_Type does not have a controlled part, it
941 will not be allowed in local objects in Ada 2005 whereas it would be allowed
942 in original Ada 95. Such code is not portable, as another Ada compiler
943 may have a controlled part in File_Type, and thus would be illegal.]}
944 @end{Incompatible95}
945
946 @begin{Incompatible2012}
947 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0130-1]}
948 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}
949 @b<Corrigendum:> The Flush procedure is newly added to Ada.Direct_IO.
950 If an instance of Ada.Direct_IO is referenced in a @nt{use_clause}, and
951 a procedure Flush is defined in some other package that is also referenced
952 in a @nt{use_clause}, the user-defined Flush may no longer be use-visible,
953 resulting in errors. This should be rare and is easily fixed if it does occur.]}
954
955 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0021-1]}
956 @ChgAdded{Version=[5],Text=[The Wide_File_Names and Wide_Wide_File_Names
957 nested packages are newly added to Ada.Direct_IO.
958 If an instance of Ada.Direct_IO is referenced in a @nt{use_clause}, and
959 an entity with one of those names is defined in some other package that is
960 also referenced in a @nt{use_clause}, the user-defined entity may no longer be
961 use-visible, resulting in errors. This should be rare and is easily fixed if
962 it does occur.]}
963 @end{Incompatible2012}
964
965
966 @LabeledSubClause{Direct Input-Output Operations}
967
968 @begin{StaticSem}
969 The operations available for direct input and output are described in
970 this subclause. The exception Status_Error is propagated if any of these
971 operations is attempted for a file that is not open.
972 @begin{DescribeCode}
973 @begin{Example}@Keepnext
974 @key[procedure] Read(File : @key[in] File_Type; Item : @key[out] Element_Type;
975 From : @key[in] Positive_Count);
976 @key[procedure] Read(File : @key[in] File_Type; Item : @key[out] Element_Type);
977 @end{Example}
978 Operates on a file of mode In_File or Inout_File. In the case
979 of the first form, sets the current index of the given file to
980 the index value given by the parameter From. Then (for both
981 forms) returns, in the parameter Item, the value of the
982 element whose position in the given file is specified by the
983 current index of the file; finally, increases the current
984 index by one.
985
986 @Trailing@;The exception Mode_Error is propagated if the mode of the given
987 file is Out_File. The exception End_Error is propagated if the
988 index to be used exceeds the size of the external file. The
989 exception Data_Error can be propagated if the element read cannot be
990 interpreted as a value of the subtype Element_Type
991 (see @RefSecNum{Exceptions in Input-Output}).
992
993 @begin{Example}@Keepnext
994 @key[procedure] Write(File : @key[in] File_Type; Item : @key[in] Element_Type;
995 To : @key[in] Positive_Count);
996 @key[procedure] Write(File : @key[in] File_Type; Item : @key[in] Element_Type);
997 @end{Example}
998 Operates on a file of mode Inout_File or Out_File. In the
999 case of the first form, sets the index of the given file to
1000 the index value given by the parameter To. Then (for both
1001 forms) gives the value of the parameter Item to the element
1002 whose position in the given file is specified by the current
1003 index of the file; finally, increases the current index by
1004 one.
1005
1006 @Trailing@;The exception Mode_Error is propagated if the mode of the given
1007 file is In_File. The exception Use_Error is propagated if the
1008 capacity of the external file is exceeded.
1009
1010 @begin{Example}@Keepnext
1011 @key[procedure] Set_Index(File : @key[in] File_Type; To : @key[in] Positive_Count);
1012 @end{Example}
1013 @Trailing@;Operates on a file of any mode. Sets the current index of the
1014 given file to the given index value (which may exceed the
1015 current size of the file).
1016
1017 @begin{Example}@Keepnext
1018 @key[function] Index(File : @key[in] File_Type) @key[return] Positive_Count;
1019 @end{Example}
1020 @Trailing@;Operates on a file of any mode. Returns the current index of
1021 the given file.
1022
1023 @begin{Example}@Keepnext
1024 @key[function] Size(File : @key[in] File_Type) @key[return] Count;
1025 @end{Example}
1026 @Trailing@;Operates on a file of any mode. Returns the current size of
1027 the external file that is associated with the given file.
1028
1029 @begin{Example}@Keepnext
1030 @key[function] End_Of_File(File : @key[in] File_Type) @key[return] Boolean;
1031 @end{Example}
1032 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
1033 Operates on a file of mode In_File or Inout_File. Returns
1034 True if the current index exceeds the size of the external
1035 file; otherwise@Chg{Version=[3],New=[,],Old=[]} returns False.
1036
1037 The exception Mode_Error is propagated if the mode of the given file is
1038 Out_File.
1039
1040 @end{DescribeCode}
1041 @end{StaticSem}
1042
1043 @begin{Notes}
1044 Append_File mode is not supported for the generic package Direct_IO.
1045 @end{Notes}
1046
1047 @LabeledClause{The Generic Package Storage_IO}
1048
1049 @begin{Intro}
1050 The generic package Storage_IO provides for reading from and
1051 writing to an in-memory buffer. This generic package supports
1052 the construction of user-defined input-output packages.
1053 @begin{Reason}
1054 This package exists to allow the portable construction of
1055 user-defined direct-access-oriented input-output packages.
1056 The Write procedure writes a value of type Element_Type into a
1057 Storage_Array of size Buffer_Size, flattening out any implicit
1058 levels of indirection used in the representation of the
1059 type. The Read procedure reads
1060 a value of type Element_Type from the buffer, reconstructing
1061 any implicit levels of indirection used in the representation
1062 of the type. It also properly initializes any type tags that appear
1063 within the value, presuming that the buffer was written by
1064 a different program and that tag values for the@lquotes@;same@rquotes@; type
1065 might vary from one executable to another.
1066 @end{Reason}
1067 @end{Intro}
1068
1069 @begin{StaticSem}
1070 @Leading@;The generic library package Storage_IO has the following declaration:
1071 @begin{Example}
1072 @key[with] Ada.IO_Exceptions;
1073 @key[with] System.Storage_Elements;
1074 @key[generic]
1075 @key[type] Element_Type @key[is] @key[private];
1076 @key[package] Ada.Storage_IO @key[is]@ChildUnit{Parent=[Ada],Child=[Storage_IO]}
1077 @key[pragma] Preelaborate(Storage_IO);
1078
1079 @AdaObjDefn{Buffer_Size} : @key(constant) System.Storage_Elements.Storage_Count :=
1080 @RI(implementation-defined);
1081 @key(subtype) @AdaSubtypeDefn{Name=[Buffer_Type],Of=[Storage_Array]} @key(is)
1082 System.Storage_Elements.Storage_Array(1..Buffer_Size);
1083
1084 --@RI{ Input and output operations}
1085
1086 @key[procedure] @AdaSubDefn{Read} (Buffer : @key[in] Buffer_Type; Item : @key[out] Element_Type);
1087
1088 @key[procedure] @AdaSubDefn{Write}(Buffer : @key[out] Buffer_Type; Item : @key[in] Element_Type);
1089
1090 @keepnext --@RI{ Exceptions}
1091
1092 @AdaExcDefn{Data_Error} : @key[exception] @key[renames] IO_Exceptions.Data_Error;
1093 @key[end] Ada.Storage_IO;
1094 @end{Example}
1095
1096 In each instance,
1097 the constant Buffer_Size has a value that is the size (in storage elements)
1098 of the buffer required to represent the content of an object of
1099 subtype Element_Type, including any implicit levels of indirection used by
1100 the implementation.
1101 The Read and Write procedures of Storage_IO correspond to the Read and Write
1102 procedures of Direct_IO (see @RefSecNum{The Generic Package Direct_IO}),
1103 but with the content of the Item parameter being read from
1104 or written into the specified Buffer, rather than an external file.
1105
1106 @begin{Reason}
1107 @Leading@;As with Direct_IO, the Element_Type formal of Storage_IO does not
1108 have an @nt{unknown_discriminant_part}
1109 so that there is a well-defined upper bound on the size of
1110 the buffer needed to hold the content of an object of the
1111 formal subtype (i.e. Buffer_Size). If there are no implicit levels
1112 of indirection, Buffer_Size will typically equal:
1113 @begin{Example}
1114 (Element_Type'Size + System.Storage_Unit - 1) / System.Storage_Unit
1115 @end{Example}
1116 @end{Reason}
1117 @ImplDef{The value of Buffer_Size in Storage_IO.}
1118 @end{StaticSem}
1119
1120 @begin{Notes}
1121 A buffer used for Storage_IO holds only one element at a time; an external
1122 file used for Direct_IO holds a sequence of elements.
1123 @end{Notes}
1124
1125 @begin{Extend83}
1126 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
1127 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 83}
1128 Storage_IO is new in Ada 95.]}
1129 @end{Extend83}
1130
1131
1132 @LabeledClause{Text Input-Output}
1133
1134 @begin{StaticSem}
1135 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1136 This @Chg{Version=[3],New=[subclause],Old=[clause]} describes the
1137 package Text_IO, which provides facilities
1138 for input and output in human-readable form. Each file is read or
1139 written sequentially, as a sequence of characters grouped into lines,
1140 and as a sequence of lines grouped into pages. The specification of the
1141 package is given below in subclause
1142 @RefSecNum{The Package Text_IO}.
1143
1144 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1145 The facilities for file management given above, in subclauses
1146 @RefSecNum{File Management} and
1147 @RefSecNum{Sequential Input-Output Operations},
1148 are available for text input-output. In place of Read and
1149 Write, however, there are procedures Get and Put that input values of
1150 suitable types from text files, and output values to them. These values
1151 are provided to the Put procedures, and returned by the Get procedures,
1152 in a parameter Item. Several overloaded procedures of these names
1153 exist, for different types of Item. These Get procedures analyze the
1154 input sequences of characters based on
1155 lexical elements (see
1156 @Chg{Version=[3],New=[Clause],Old=[Section]} @RefSecNum{Lexical Elements}) and
1157 return the corresponding values; the Put procedures output the given
1158 values as appropriate lexical elements. Procedures Get and Put are also
1159 available that input and output individual characters treated as
1160 character values rather than as lexical elements.
1161 Related to character input are procedures to look ahead at the
1162 next character without reading it, and to read a character @lquotes@;immediately@rquotes@;
1163 without waiting for an end-of-line to signal availability.
1164
1165 In addition to the procedures Get and Put for numeric and enumeration
1166 types of Item that operate on text files, analogous procedures are
1167 provided that read from and write to a parameter of type String. These
1168 procedures perform the same analysis and composition of character
1169 sequences as their counterparts which have a file parameter.
1170
1171 For all Get and Put procedures that operate on text files, and for many
1172 other subprograms, there are forms with and without a file parameter.
1173 Each such Get procedure operates on an input file, and each such Put
1174 procedure operates on an output file. If no file is specified, a
1175 default input file or a default output file is used.
1176
1177 @Defn{standard input file}
1178 @Defn{standard output file}
1179 At the beginning of program execution the default input and output files
1180 are the so-called standard input file and standard output file. These
1181 files are open, have respectively the current modes In_File and
1182 Out_File, and are associated with two implementation-defined external
1183 files. Procedures are provided to change the current default input file
1184 and the current default output file.
1185 @ChgNote{The following was poorly formatted.}
1186 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
1187 Text=[@Chg{Version=[2],New=[The ],
1188 Old=[]}external files @Chg{Version=[2],New=[associated with the],Old=[for]} standard
1189 input, standard output, and standard error@Chg{Version=[2],New=[ files.],Old=[]}]}
1190 @begin{ImplNote}
1191 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0113],ARef=[AI95-00087-01]}
1192 @ChgAdded{Version=[1],Text=[The default input file and default output file
1193 are not the names
1194 of distinct file objects, but rather the @i<role> played by one or more
1195 (other) file object(s). Thus, they generally will be implemented as accesses
1196 to another file object. An implementation that implements them by copying
1197 them is incorrect.]}
1198 @end{ImplNote}
1199
1200 @Defn{standard error file}
1201 At the beginning of program execution a default file for
1202 program-dependent error-related text output is the
1203 so-called standard error file. This file is open, has the current
1204 mode Out_File, and is associated with an implementation-defined
1205 external file. A procedure is provided to change the current
1206 default error file.
1207
1208 @Defn{line terminator}
1209 @Defn{page terminator}
1210 @Defn{file terminator}
1211 From a logical point of view, a text file is a sequence of pages, a page
1212 is a sequence of lines, and a line is a sequence of characters; the end
1213 of a line is marked by a @i{line terminator}; the end of a page is marked by
1214 the combination of a line terminator immediately followed by a @i{page
1215 terminator}; and the end of a file is marked by the combination of a line
1216 terminator immediately followed by a page terminator and then a @i{file
1217 terminator}. Terminators are generated during output; either by calls of
1218 procedures provided expressly for that purpose; or implicitly as part of
1219 other operations, for example, when a bounded line length, a bounded
1220 page length, or both, have been specified for a file.
1221
1222 The actual nature of terminators is not defined by the language and
1223 hence depends on the implementation. Although terminators are
1224 recognized or generated by certain of the procedures that follow, they
1225 are not necessarily implemented as characters or as sequences of
1226 characters. Whether they are characters (and if so which ones) in any
1227 particular implementation need not concern a user who neither explicitly
1228 outputs nor explicitly inputs control characters. The effect of input
1229 (Get)
1230 or output (Put)
1231 of control characters (other than horizontal tabulation) is
1232 not specified by the language.
1233 @PDefn{unspecified}
1234
1235 @Defn{column number}
1236 @Defn{current column number}
1237 @Defn{current line number}
1238 @Defn{current page number}
1239 The characters of a line are numbered, starting from one; the number of
1240 a character is called its @i{column number}. For a line terminator, a
1241 column number is also defined: it is one more than the number of
1242 characters in the line. The lines of a page, and the pages of a file,
1243 are similarly numbered. The current column number is the column number
1244 of the next character or line terminator to be transferred. The current
1245 line number is the number of the current line. The current page number
1246 is the number of the current page. These numbers are values of the
1247 subtype Positive_Count of the type Count (by convention, the value zero
1248 of the type Count is used to indicate special conditions).
1249 @begin{Example}
1250 @Trailing@key[type] Count @key[is] @key[range] 0 .. @RI[implementation-defined];
1251 @key[subtype] Positive_Count @key[is] Count @key[range] 1 .. Count'Last;
1252 @end{Example}
1253
1254 @Defn{maximum line length}
1255 @Defn{maximum page length}
1256 For an output file or an append file, a @i{maximum line length} can be specified
1257 and a @i{maximum page length} can be specified. If a value to be output cannot
1258 fit on the current line, for a specified maximum line length, then a new line
1259 is automatically started before the value is output; if, further, this new
1260 line cannot fit on the current page, for a specified maximum page
1261 length, then a new page is automatically started before the value is
1262 output. Functions are provided to determine the maximum line length and
1263 the maximum page length. When a file is opened with mode Out_File
1264 or Append_File, both values are zero: by convention, this means that the line
1265 lengths and
1266 page lengths are unbounded. (Consequently, output consists of a single
1267 line if the subprograms for explicit control of line and page structure
1268 are not used.) The constant Unbounded is provided for this purpose.
1269 @end{StaticSem}
1270
1271 @begin{Extend83}
1272 @Defn{extensions to Ada 83}
1273 Append_File is new in Ada 95.
1274 @end{Extend83}
1275
1276 @LabeledSubClause{The Package Text_IO}
1277
1278 @begin{StaticSem}
1279 @Leading@;The library package Text_IO has the following declaration:
1280 @begin{Example}
1281 @key[with] Ada.IO_Exceptions;
1282 @key[package] Ada.Text_IO @key[is]@ChildUnit{Parent=[Ada],Child=[Text_IO]}
1283
1284 @key[type] @AdaTypeDefn{File_Type} @key[is] @key[limited] @key[private];
1285
1286 @key[type] @AdaTypeDefn{File_Mode} @key[is] (In_File, Out_File, Append_File);
1287
1288 @key[type] @AdaTypeDefn{Count} @key[is] @key[range] 0 .. @RI[implementation-defined];
1289 @key[subtype] @AdaSubtypeDefn{Name=[Positive_Count],Of=[Count]} @key[is] Count @key[range] 1 .. Count'Last;
1290 @AdaObjDefn{Unbounded} : @key[constant] Count := 0; --@RI{ line and page length}
1291
1292 @key[subtype] @AdaSubtypeDefn{Name=[Field],Of=[Integer]} @key[is] Integer @key[range] 0 .. @RI[implementation-defined];
1293 @key[subtype] @AdaSubtypeDefn{Name=[Number_Base],Of=[Integer]} @key[is] Integer @key[range] 2 .. 16;
1294
1295 @key[type] @AdaTypeDefn{Type_Set} @key[is] (Lower_Case, Upper_Case);
1296
1297 --@RI{ File Management}
1298
1299 @key[procedure] @AdaSubDefn{Create} (File : @key[in] @key[out] File_Type;
1300 Mode : @key[in] File_Mode := Out_File;
1301 Name : @key[in] String := "";
1302 Form : @key[in] String := "");
1303
1304 @key[procedure] @AdaSubDefn{Open} (File : @key[in] @key[out] File_Type;
1305 Mode : @key[in] File_Mode;
1306 Name : @key[in] String;
1307 Form : @key[in] String := "");
1308
1309 @key[procedure] @AdaSubDefn{Close} (File : @key[in] @key[out] File_Type);
1310 @key[procedure] @AdaSubDefn{Delete} (File : @key[in] @key[out] File_Type);
1311 @key[procedure] @AdaSubDefn{Reset} (File : @key[in] @key[out] File_Type; Mode : @key[in] File_Mode);
1312 @key[procedure] @AdaSubDefn{Reset} (File : @key[in] @key[out] File_Type);
1313
1314 @key[function] @AdaSubDefn{Mode} (File : @key[in] File_Type) @key[return] File_Mode;
1315 @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] String;
1316 @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] String;
1317
1318 @key[function] @AdaSubDefn{Is_Open}(File : @key[in] File_Type) @key[return] Boolean;
1319
1320 --@RI{ Control of default input and output files}
1321
1322 @key[procedure] @AdaSubDefn{Set_Input} (File : @key[in] File_Type);
1323 @key[procedure] @AdaSubDefn{Set_Output}(File : @key[in] File_Type);
1324 @key[procedure] @AdaSubDefn{Set_Error} (File : @key[in] File_Type);
1325
1326 @key[function] @AdaSubDefn{Standard_Input} @key[return] File_Type;
1327 @key[function] @AdaSubDefn{Standard_Output} @key[return] File_Type;
1328 @key[function] @AdaSubDefn{Standard_Error} @key[return] File_Type;
1329
1330 @key[function] @AdaSubDefn{Current_Input} @key[return] File_Type;
1331 @key[function] @AdaSubDefn{Current_Output} @key[return] File_Type;
1332 @key[function] @AdaSubDefn{Current_Error} @key[return] File_Type;
1333
1334 @key[type] @AdaTypeDefn{File_Access} @key[is] @key[access] @key[constant] File_Type;
1335
1336 @key[function] @AdaSubDefn{Standard_Input} @key[return] File_Access;
1337 @key[function] @AdaSubDefn{Standard_Output} @key[return] File_Access;
1338 @key[function] @AdaSubDefn{Standard_Error} @key[return] File_Access;
1339
1340 @key[function] @AdaSubDefn{Current_Input} @key[return] File_Access;
1341 @key[function] @AdaSubDefn{Current_Output} @key[return] File_Access;
1342 @key[function] @AdaSubDefn{Current_Error} @key[return] File_Access;
1343
1344
1345 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0051],ARef=[AI95-00057-01]}
1346 --@RI{Buffer control}
1347 @key[procedure] @AdaSubDefn{Flush} (File : @key[in] @Chg{New=[],Old=[@key[out] ]}File_Type);
1348 @key[procedure] @AdaSubDefn{Flush};
1349
1350
1351 --@RI{ Specification of line and page lengths}
1352
1353 @key[procedure] @AdaSubDefn{Set_Line_Length}(File : @key[in] File_Type; To : @key[in] Count);
1354 @key[procedure] @AdaSubDefn{Set_Line_Length}(To : @key[in] Count);
1355
1356 @key[procedure] @AdaSubDefn{Set_Page_Length}(File : @key[in] File_Type; To : @key[in] Count);
1357 @key[procedure] @AdaSubDefn{Set_Page_Length}(To : @key[in] Count);
1358
1359 @key[function] @AdaSubDefn{Line_Length}(File : @key[in] File_Type) @key[return] Count;
1360 @key[function] @AdaSubDefn{Line_Length} @key[return] Count;
1361
1362 @key[function] @AdaSubDefn{Page_Length}(File : @key[in] File_Type) @key[return] Count;
1363 @key[function] @AdaSubDefn{Page_Length} @key[return] Count;
1364
1365 --@RI{ Column, Line, and Page Control}
1366
1367 @key[procedure] @AdaSubDefn{New_Line} (File : @key[in] File_Type;
1368 Spacing : @key[in] Positive_Count := 1);
1369 @key[procedure] @AdaSubDefn{New_Line} (Spacing : @key[in] Positive_Count := 1);
1370
1371 @key[procedure] @AdaSubDefn{Skip_Line} (File : @key[in] File_Type;
1372 Spacing : @key[in] Positive_Count := 1);
1373 @key[procedure] @AdaSubDefn{Skip_Line} (Spacing : @key[in] Positive_Count := 1);
1374
1375 @key[function] @AdaSubDefn{End_Of_Line}(File : @key[in] File_Type) @key[return] Boolean;
1376 @key[function] @AdaSubDefn{End_Of_Line} @key[return] Boolean;
1377
1378 @key[procedure] @AdaSubDefn{New_Page} (File : @key[in] File_Type);
1379 @key[procedure] @AdaSubDefn{New_Page};
1380
1381 @key[procedure] @AdaSubDefn{Skip_Page} (File : @key[in] File_Type);
1382 @key[procedure] @AdaSubDefn{Skip_Page};
1383
1384 @key[function] @AdaSubDefn{End_Of_Page}(File : @key[in] File_Type) @key[return] Boolean;
1385 @key[function] @AdaSubDefn{End_Of_Page} @key[return] Boolean;
1386
1387 @key[function] @AdaSubDefn{End_Of_File}(File : @key[in] File_Type) @key[return] Boolean;
1388 @key[function] @AdaSubDefn{End_Of_File} @key[return] Boolean;
1389
1390 @key[procedure] @AdaSubDefn{Set_Col} (File : @key[in] File_Type; To : @key[in] Positive_Count);
1391 @key[procedure] @AdaSubDefn{Set_Col} (To : @key[in] Positive_Count);
1392
1393 @key[procedure] @AdaSubDefn{Set_Line}(File : @key[in] File_Type; To : @key[in] Positive_Count);
1394 @key[procedure] @AdaSubDefn{Set_Line}(To : @key[in] Positive_Count);
1395
1396 @key[function] @AdaSubDefn{Col} (File : @key[in] File_Type) @key[return] Positive_Count;
1397 @key[function] @AdaSubDefn{Col} @key[return] Positive_Count;
1398
1399 @key[function] @AdaSubDefn{Line}(File : @key[in] File_Type) @key[return] Positive_Count;
1400 @key[function] @AdaSubDefn{Line} @key[return] Positive_Count;
1401
1402 @key[function] @AdaSubDefn{Page}(File : @key[in] File_Type) @key[return] Positive_Count;
1403 @key[function] @AdaSubDefn{Page} @key[return] Positive_Count;
1404
1405 --@RI{ Character Input-Output}
1406
1407 @key[procedure] @AdaSubDefn{Get}(File : @key[in] File_Type; Item : @key[out] Character);
1408 @key[procedure] @AdaSubDefn{Get}(Item : @key[out] Character);
1409
1410 @key[procedure] @AdaSubDefn{Put}(File : @key[in] File_Type; Item : @key[in] Character);
1411 @key[procedure] @AdaSubDefn{Put}(Item : @key[in] Character);
1412
1413 @key[procedure] @AdaSubDefn{Look_Ahead} (File : @key[in] File_Type;
1414 Item : @key[out] Character;
1415 End_Of_Line : @key[out] Boolean);
1416 @key[procedure] @AdaSubDefn{Look_Ahead} (Item : @key[out] Character;
1417 End_Of_Line : @key[out] Boolean);
1418
1419 @key[procedure] @AdaSubDefn{Get_Immediate}(File : @key[in] File_Type;
1420 Item : @key[out] Character);
1421 @key[procedure] @AdaSubDefn{Get_Immediate}(Item : @key[out] Character);
1422
1423 @key[procedure] @AdaSubDefn{Get_Immediate}(File : @key[in] File_Type;
1424 Item : @key[out] Character;
1425 Available : @key[out] Boolean);
1426 @key[procedure] @AdaSubDefn{Get_Immediate}(Item : @key[out] Character;
1427 Available : @key[out] Boolean);
1428
1429 --@RI{ String Input-Output}
1430
1431 @key[procedure] @AdaSubDefn{Get}(File : @key[in] File_Type; Item : @key[out] String);
1432 @key[procedure] @AdaSubDefn{Get}(Item : @key[out] String);
1433
1434 @key[procedure] @AdaSubDefn{Put}(File : @key[in] File_Type; Item : @key[in] String);
1435 @key[procedure] @AdaSubDefn{Put}(Item : @key[in] String);
1436
1437 @key[procedure] @AdaSubDefn{Get_Line}(File : @key[in] File_Type;
1438 Item : @key[out] String;
1439 Last : @key[out] Natural);
1440 @key[procedure] @AdaSubDefn{Get_Line}(Item : @key[out] String; Last : @key[out] Natural);
1441
1442 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00301-01]}
1443 @ChgAdded{Version=[2],Text=[ @key[function] @AdaSubDefn{Get_Line}(File : @key[in] File_Type) @key[return] String;
1444 @key[function] @AdaSubDefn{Get_Line} @key[return] String;]}
1445
1446 @key[procedure] @AdaSubDefn{Put_Line}(File : @key[in] File_Type; Item : @key[in] String);
1447 @key[procedure] @AdaSubDefn{Put_Line}(Item : @key[in] String);
1448
1449 --@RI{ Generic packages for Input-Output of Integer Types}
1450
1451 @key[generic]
1452 @key[type] Num @key[is] @key[range] <>;
1453 @key[package] @AdaPackDefn{Integer_IO} @key[is]
1454
1455 @AdaObjDefn{Default_Width} : Field := Num'Width;
1456 @AdaObjDefn{Default_Base} : Number_Base := 10;
1457
1458 @key[procedure] @AdaSubDefn{Get}(File : @key[in] File_Type;
1459 Item : @key[out] Num;
1460 Width : @key[in] Field := 0);
1461 @key[procedure] @AdaSubDefn{Get}(Item : @key[out] Num;
1462 Width : @key[in] Field := 0);
1463
1464 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
1465 @key[procedure] @AdaSubDefn{Put}(File : @key[in] File_Type;
1466 Item : @key[in] Num;
1467 Width : @key[in] Field := Default_Width;
1468 Base : @key[in] Number_Base := Default_Base);
1469 @key[procedure] @AdaSubDefn{Put}(Item : @key[in] Num;
1470 Width : @key[in] Field := Default_Width;
1471 Base : @key[in] Number_Base := Default_Base);
1472 @key[procedure] @AdaSubDefn{Get}(From : @key[in] String;
1473 Item : @key[out] Num;
1474 Last : @key[out] Positive)@Chg{Version=[5],New=[
1475 @key[with] Nonblocking],Old=[]};
1476 @key[procedure] @AdaSubDefn{Put}(To : @key[out] String;
1477 Item : @key[in] Num;
1478 Base : @key[in] Number_Base := Default_Base)@Chg{Version=[5],New=[
1479 @key[with] Nonblocking],Old=[]};
1480
1481 @key[end] Integer_IO;
1482
1483 @key[generic]
1484 @key[type] Num @key[is] @key[mod] <>;
1485 @key[package] @AdaPackDefn{Modular_IO} @key[is]
1486
1487 @AdaObjDefn{Default_Width} : Field := Num'Width;
1488 @AdaObjDefn{Default_Base} : Number_Base := 10;
1489
1490 @key[procedure] @AdaSubDefn{Get}(File : @key[in] File_Type;
1491 Item : @key[out] Num;
1492 Width : @key[in] Field := 0);
1493 @key[procedure] @AdaSubDefn{Get}(Item : @key[out] Num;
1494 Width : @key[in] Field := 0);
1495
1496 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
1497 @key[procedure] @AdaSubDefn{Put}(File : @key[in] File_Type;
1498 Item : @key[in] Num;
1499 Width : @key[in] Field := Default_Width;
1500 Base : @key[in] Number_Base := Default_Base);
1501 @key[procedure] @AdaSubDefn{Put}(Item : @key[in] Num;
1502 Width : @key[in] Field := Default_Width;
1503 Base : @key[in] Number_Base := Default_Base);
1504 @key[procedure] @AdaSubDefn{Get}(From : @key[in] String;
1505 Item : @key[out] Num;
1506 Last : @key[out] Positive)@Chg{Version=[5],New=[
1507 @key[with] Nonblocking],Old=[]};
1508 @key[procedure] @AdaSubDefn{Put}(To : @key[out] String;
1509 Item : @key[in] Num;
1510 Base : @key[in] Number_Base := Default_Base)@Chg{Version=[5],New=[
1511 @key[with] Nonblocking],Old=[]};
1512
1513 @key[end] Modular_IO;
1514
1515 --@RI{ Generic packages for Input-Output of Real Types}
1516
1517 @key[generic]
1518 @key[type] Num @key[is] @key[digits] <>;
1519 @key[package] @AdaPackDefn{Float_IO} @key[is]
1520
1521 @AdaObjDefn{Default_Fore} : Field := 2;
1522 @AdaObjDefn{Default_Aft} : Field := Num'Digits-1;
1523 @AdaObjDefn{Default_Exp} : Field := 3;
1524
1525 @key[procedure] @AdaSubDefn{Get}(File : @key[in] File_Type;
1526 Item : @key[out] Num;
1527 Width : @key[in] Field := 0);
1528 @key[procedure] @AdaSubDefn{Get}(Item : @key[out] Num;
1529 Width : @key[in] Field := 0);
1530
1531 @key[procedure] @AdaSubDefn{Put}(File : @key[in] File_Type;
1532 Item : @key[in] Num;
1533 Fore : @key[in] Field := Default_Fore;
1534 Aft : @key[in] Field := Default_Aft;
1535 Exp : @key[in] Field := Default_Exp);
1536 @key[procedure] @AdaSubDefn{Put}(Item : @key[in] Num;
1537 Fore : @key[in] Field := Default_Fore;
1538 Aft : @key[in] Field := Default_Aft;
1539 Exp : @key[in] Field := Default_Exp);
1540
1541 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
1542 @key[procedure] @AdaSubDefn{Get}(From : @key[in] String;
1543 Item : @key[out] Num;
1544 Last : @key[out] Positive)@Chg{Version=[5],New=[
1545 @key[with] Nonblocking],Old=[]};
1546 @key[procedure] @AdaSubDefn{Put}(To : @key[out] String;
1547 Item : @key[in] Num;
1548 Aft : @key[in] Field := Default_Aft;
1549 Exp : @key[in] Field := Default_Exp)@Chg{Version=[5],New=[
1550 @key[with] Nonblocking],Old=[]};
1551 @key[end] Float_IO;
1552
1553 @key[generic]
1554 @key[type] Num @key[is] @key[delta] <>;
1555 @key[package] @AdaPackDefn{Fixed_IO} @key[is]
1556
1557 @AdaObjDefn{Default_Fore} : Field := Num'Fore;
1558 @AdaObjDefn{Default_Aft} : Field := Num'Aft;
1559 @AdaObjDefn{Default_Exp} : Field := 0;
1560
1561 @key[procedure] @AdaSubDefn{Get}(File : @key[in] File_Type;
1562 Item : @key[out] Num;
1563 Width : @key[in] Field := 0);
1564 @key[procedure] @AdaSubDefn{Get}(Item : @key[out] Num;
1565 Width : @key[in] Field := 0);
1566
1567 @key[procedure] @AdaSubDefn{Put}(File : @key[in] File_Type;
1568 Item : @key[in] Num;
1569 Fore : @key[in] Field := Default_Fore;
1570 Aft : @key[in] Field := Default_Aft;
1571 Exp : @key[in] Field := Default_Exp);
1572 @key[procedure] @AdaSubDefn{Put}(Item : @key[in] Num;
1573 Fore : @key[in] Field := Default_Fore;
1574 Aft : @key[in] Field := Default_Aft;
1575 Exp : @key[in] Field := Default_Exp);
1576
1577 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
1578 @key[procedure] @AdaSubDefn{Get}(From : @key[in] String;
1579 Item : @key[out] Num;
1580 Last : @key[out] Positive)@Chg{Version=[5],New=[
1581 @key[with] Nonblocking],Old=[]};
1582 @key[procedure] @AdaSubDefn{Put}(To : @key[out] String;
1583 Item : @key[in] Num;
1584 Aft : @key[in] Field := Default_Aft;
1585 Exp : @key[in] Field := Default_Exp)@Chg{Version=[5],New=[
1586 @key[with] Nonblocking],Old=[]};
1587 @key[end] Fixed_IO;
1588
1589 @key[generic]
1590 @key[type] Num @key[is] @key[delta] <> @key[digits] <>;
1591 @key[package] @AdaPackDefn{Decimal_IO} @key[is]
1592
1593 @AdaObjDefn{Default_Fore} : Field := Num'Fore;
1594 @AdaObjDefn{Default_Aft} : Field := Num'Aft;
1595 @AdaObjDefn{Default_Exp} : Field := 0;
1596
1597 @key[procedure] @AdaSubDefn{Get}(File : @key[in] File_Type;
1598 Item : @key[out] Num;
1599 Width : @key[in] Field := 0);
1600 @key[procedure] @AdaSubDefn{Get}(Item : @key[out] Num;
1601 Width : @key[in] Field := 0);
1602
1603 @key[procedure] @AdaSubDefn{Put}(File : @key[in] File_Type;
1604 Item : @key[in] Num;
1605 Fore : @key[in] Field := Default_Fore;
1606 Aft : @key[in] Field := Default_Aft;
1607 Exp : @key[in] Field := Default_Exp);
1608 @key[procedure] @AdaSubDefn{Put}(Item : @key[in] Num;
1609 Fore : @key[in] Field := Default_Fore;
1610 Aft : @key[in] Field := Default_Aft;
1611 Exp : @key[in] Field := Default_Exp);
1612
1613 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
1614 @key[procedure] @AdaSubDefn{Get}(From : @key[in] String;
1615 Item : @key[out] Num;
1616 Last : @key[out] Positive)@Chg{Version=[5],New=[
1617 @key[with] Nonblocking],Old=[]};
1618 @key[procedure] @AdaSubDefn{Put}(To : @key[out] String;
1619 Item : @key[in] Num;
1620 Aft : @key[in] Field := Default_Aft;
1621 Exp : @key[in] Field := Default_Exp)@Chg{Version=[5],New=[
1622 @key[with] Nonblocking],Old=[]};
1623 @key[end] Decimal_IO;
1624
1625 --@RI{ Generic package for Input-Output of Enumeration Types}
1626
1627 @key[generic]
1628 @key[type] Enum @key[is] (<>);
1629 @key[package] @AdaPackDefn{Enumeration_IO} @key[is]
1630
1631 @AdaObjDefn{Default_Width} : Field := 0;
1632 @AdaObjDefn{Default_Setting} : Type_Set := Upper_Case;
1633
1634 @key[procedure] @AdaSubDefn{Get}(File : @key[in] File_Type;
1635 Item : @key[out] Enum);
1636 @key[procedure] @AdaSubDefn{Get}(Item : @key[out] Enum);
1637
1638 @key[procedure] @AdaSubDefn{Put}(File : @key[in] File_Type;
1639 Item : @key[in] Enum;
1640 Width : @key[in] Field := Default_Width;
1641 Set : @key[in] Type_Set := Default_Setting);
1642 @key[procedure] @AdaSubDefn{Put}(Item : @key[in] Enum;
1643 Width : @key[in] Field := Default_Width;
1644 Set : @key[in] Type_Set := Default_Setting);
1645
1646 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
1647 @key[procedure] @AdaSubDefn{Get}(From : @key[in] String;
1648 Item : @key[out] Enum;
1649 Last : @key[out] Positive)@Chg{Version=[5],New=[
1650 @key[with] Nonblocking],Old=[]};
1651 @key[procedure] @AdaSubDefn{Put}(To : @key[out] String;
1652 Item : @key[in] Enum;
1653 Set : @key[in] Type_Set := Default_Setting)@Chg{Version=[5],New=[
1654 @key[with] Nonblocking],Old=[]};
1655 @key[end] Enumeration_IO;
1656
1657 @keepnext@;--@RI{ Exceptions}
1658
1659 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0021-1]}
1660 @AdaExcDefn{Status_Error} : @key[exception] @key[renames] IO_Exceptions.Status_Error;
1661 @AdaExcDefn{Mode_Error} : @key[exception] @key[renames] IO_Exceptions.Mode_Error;
1662 @AdaExcDefn{Name_Error} : @key[exception] @key[renames] IO_Exceptions.Name_Error;
1663 @AdaExcDefn{Use_Error} : @key[exception] @key[renames] IO_Exceptions.Use_Error;
1664 @AdaExcDefn{Device_Error} : @key[exception] @key[renames] IO_Exceptions.Device_Error;
1665 @AdaExcDefn{End_Error} : @key[exception] @key[renames] IO_Exceptions.End_Error;
1666 @AdaExcDefn{Data_Error} : @key[exception] @key[renames] IO_Exceptions.Data_Error;
1667 @AdaExcDefn{Layout_Error} : @key[exception] @key[renames] IO_Exceptions.Layout_Error;@Chg{Version=[5],New=[],Old=[
1668 @key[private]
1669 ... -- @RI{not specified by the language}
1670 @key[end] Ada.Text_IO;]}
1671
1672 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
1673 @ChgAdded{Version=[5],Text=[ @key[package] @AdaPackDefn{Wide_File_Names} @key[is]]}
1674
1675 @ChgRef{Version=[5],Kind=[Added]}
1676 @ChgAdded{Version=[5],Text=[ -- @examcom{File management}]}
1677
1678 @ChgRef{Version=[5],Kind=[Added]}
1679 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Create} (File : @key[in out] File_Type;
1680 Mode : @key[in] File_Mode := Out_File;
1681 Name : @key[in] Wide_String := "";
1682 Form : @key[in] Wide_String := "");]}
1683
1684 @ChgRef{Version=[5],Kind=[Added]}
1685 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Open} (File : @key[in out] File_Type;
1686 Mode : @key[in] File_Mode;
1687 Name : @key[in] Wide_String;
1688 Form : @key[in] Wide_String := "");]}
1689
1690 @ChgRef{Version=[5],Kind=[Added]}
1691 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] Wide_String;]}
1692
1693 @ChgRef{Version=[5],Kind=[Added]}
1694 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] Wide_String;]}
1695
1696 @ChgRef{Version=[5],Kind=[Added]}
1697 @ChgAdded{Version=[5],Text=[ @key[end] Wide_File_Names;]}
1698
1699
1700 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
1701 @ChgAdded{Version=[5],Text=[ @key[package] @AdaPackDefn{Wide_Wide_File_Names} @key[is]]}
1702
1703 @ChgRef{Version=[5],Kind=[Added]}
1704 @ChgAdded{Version=[5],Text=[ -- @examcom{File management}]}
1705
1706 @ChgRef{Version=[5],Kind=[Added]}
1707 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Create} (File : @key[in out] File_Type;
1708 Mode : @key[in] File_Mode := Out_File;
1709 Name : @key[in] Wide_Wide_String := "";
1710 Form : @key[in] Wide_Wide_String := "");]}
1711
1712 @ChgRef{Version=[5],Kind=[Added]}
1713 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Open} (File : @key[in out] File_Type;
1714 Mode : @key[in] File_Mode;
1715 Name : @key[in] Wide_Wide_String;
1716 Form : @key[in] Wide_Wide_String := "");]}
1717
1718 @ChgRef{Version=[5],Kind=[Added]}
1719 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] Wide_Wide_String;]}
1720
1721 @ChgRef{Version=[5],Kind=[Added]}
1722 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] Wide_Wide_String;]}
1723
1724 @ChgRef{Version=[5],Kind=[Added]}
1725 @ChgAdded{Version=[5],Text=[ @key[end] Wide_Wide_File_Names;]}
1726
1727 @ChgRef{Version=[5],Kind=[Added]}
1728 @ChgAdded{Version=[5],Text=[@key[private]
1729 ... -- @RI{not specified by the language}
1730 @key[end] Ada.Text_IO;]}
1731 @end{Example}
1732
1733 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00360-01]}
1734 @ChgAdded{Version=[2],Text=[The type File_Type
1735 needs finalization@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}
1736 (see @RefSecNum{Assignment and Finalization}).]}
1737
1738 @end{StaticSem}
1739
1740 @begin{Incompatible83}
1741 @Defn{incompatibilities with Ada 83}
1742 Append_File is a new element of enumeration type File_Mode.
1743 @end{Incompatible83}
1744
1745 @begin{Extend83}
1746 @Defn{extensions to Ada 83}
1747 Get_Immediate, Look_Ahead, the subprograms for dealing with
1748 standard error, the type File_Access and its associated subprograms,
1749 and the
1750 generic packages Modular_IO and Decimal_IO are new in Ada 95.
1751 @end{Extend83}
1752
1753 @begin{Incompatible95}
1754 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00360-01]}
1755 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
1756 @B[Amendment Correction:] Text_IO.File_Type is defined to need finalization. If the
1757 restriction No_Nested_Finalization (see @RefSecNum{Tasking Restrictions})
1758 applies to the partition, and File_Type does not have a controlled part, it
1759 will not be allowed in local objects in Ada 2005 whereas it would be allowed
1760 in original Ada 95. Such code is not portable, as another Ada compiler
1761 may have a controlled part in File_Type, and thus would be illegal.]}
1762 @end{Incompatible95}
1763
1764 @begin{DiffWord95}
1765 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0051],ARef=[AI95-00057-01]}
1766 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the parameter mode
1767 of Flush; otherwise it could not be used on Standard_Output.]}
1768
1769 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
1770 @ChgAdded{Version=[2],Text=[The Text_IO.Get_Line functions are new;
1771 they are described in @RefSec{Input-Output of Characters and Strings}.]}
1772 @end{DiffWord95}
1773
1774 @begin{Incompatible2012}
1775 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0021-1]}
1776 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}
1777 The Wide_File_Names and Wide_Wide_File_Names
1778 nested packages are newly added to Ada.Text_IO.
1779 If an instance of Ada.Text_IO is referenced in a @nt{use_clause}, and
1780 an entity with one of those names is defined in some other package that is
1781 also referenced in a @nt{use_clause}, the user-defined entity may no longer be
1782 use-visible, resulting in errors. This should be rare and is easily fixed if
1783 it does occur.]}
1784 @end{Incompatible2012}
1785
1786
1787 @LabeledSubClause{Text File Management}
1788
1789 @begin{StaticSem}
1790 @Leading@;The only allowed file modes for text files are the modes In_File,
1791 Out_File, and Append_File.
1792 The subprograms given in subclause @RefSecNum{File Management} for the control of
1793 external files, and the function End_Of_File given in subclause
1794 @RefSecNum{Sequential Input-Output Operations} for
1795 sequential input-output, are also available for text files. There is
1796 also a version of End_Of_File that refers to the current default input
1797 file. For text files, the procedures have the following additional
1798 effects:
1799 @begin{Itemize}
1800 For the procedures Create and Open: After a file with mode Out_File or
1801 Append_File is opened, the page length and line length are unbounded (both have
1802 the conventional value zero). After a file (of any mode)
1803 is opened, the current column, current line, and current
1804 page numbers are set to one. If the mode is Append_File, it
1805 is implementation defined whether a page terminator will separate
1806 preexisting text in the file from the new text to be written.
1807 @begin{Reason}
1808 For a file with mode Append_File, although it may seem more
1809 sensible for Open to set the current column, line, and page number based on
1810 the number of pages in the file, the number of lines on the last
1811 page, and the number of columns in the last line, we rejected this
1812 approach because of implementation costs; it would require
1813 the implementation to scan the file before doing the append,
1814 or to do processing that would be equivalent in effect.
1815
1816 For similar reasons, there is no requirement to erase
1817 the last page terminator of the file, nor to insert
1818 an explicit page terminator in the case when the final
1819 page terminator of a file is represented implicitly by the
1820 implementation.
1821 @end{Reason}
1822
1823 For the procedure Close: If the file has the current mode Out_File
1824 or Append_File, has the effect of calling New_Page, unless the current
1825 page is already terminated; then outputs a file terminator.
1826
1827
1828 For the procedure Reset: If the file has the current mode Out_File
1829 or Append_File, has the effect of calling New_Page, unless the
1830 current page is already terminated; then outputs a file terminator.
1831 The current column, line, and page numbers are set to
1832 one, and the line and page lengths to Unbounded.
1833 If the new mode is Append_File, it is implementation defined whether
1834 a page terminator will separate preexisting text in the file from the
1835 new text to be written.
1836 @begin{Reason}
1837 The behavior of Reset should be similar to closing a file and
1838 reopening it with the given mode@end{reason}
1839 @end{Itemize}
1840
1841 The exception Mode_Error is propagated by the procedure Reset upon an
1842 attempt to change the mode of a file that is
1843 the current default
1844 input file, the current default output file,
1845 or the current default error file.
1846 @end{StaticSem}
1847
1848 @begin{Notes}
1849 @Leading@;An implementation can define the Form parameter of
1850 Create and Open to control effects including the following:
1851 @begin{itemize}
1852 the interpretation of line and column numbers for an interactive file,
1853 and
1854
1855 the interpretation of text formats in
1856 a file created by a foreign program.
1857 @end{itemize}
1858 @end{Notes}
1859
1860 @LabeledSubClause{Default Input, Output, and Error Files}
1861
1862 @begin{StaticSem}
1863 The following subprograms provide for the control of the particular
1864 default files that are used when a file parameter is omitted from a Get,
1865 Put, or other operation of text input-output described below,
1866 or when application-dependent error-related text is to be output.
1867 @begin{DescribeCode}
1868 @begin{Example}@Keepnext
1869 @key[procedure] Set_Input(File : @key[in] File_Type);
1870 @end{Example}
1871 Operates on a file of mode In_File. Sets the current default
1872 input file to File.
1873
1874 @Trailing@;The exception Status_Error is propagated if the given file is not
1875 open. The exception Mode_Error is propagated if the mode of the
1876 given file is not In_File.
1877
1878 @begin{Example}@Keepnext
1879 @key[procedure] Set_Output(File : @key[in] File_Type);
1880 @key[procedure] Set_Error (File : @key[in] File_Type);
1881 @end{Example}
1882 @Trailing@;Each operates on a file of mode Out_File or Append_File.
1883 Set_Output sets the current default output file to File.
1884 Set_Error sets the current default error file to File.
1885 The exception Status_Error is propagated if the given file is not
1886 open. The exception Mode_Error is propagated if the mode of the
1887 given file is not Out_File or Append_File.
1888
1889 @begin{Example}@Keepnext
1890 @key[function] Standard_Input @key[return] File_Type;
1891 @key[function] Standard_Input @key[return] File_Access;
1892 @end{Example}
1893 @Trailing@;Returns the standard input file (see @RefSecNum{Text Input-Output}),
1894 or an access value designating the standard input file, respectively.
1895
1896 @begin{Example}@Keepnext
1897 @key[function] Standard_Output @key[return] File_Type;
1898 @key[function] Standard_Output @key[return] File_Access;
1899 @end{Example}
1900 @Trailing@;Returns the standard output file (see @RefSecNum{Text Input-Output})
1901 or an access value designating the standard output file, respectively.
1902
1903 @begin{Example}@Keepnext
1904 @key[function] Standard_Error @key[return] File_Type;
1905 @key[function] Standard_Error @key[return] File_Access;
1906 @end{Example}
1907 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0052],ARef=[AI95-00194-01]}
1908 @Trailing@;Returns the standard error file (see @RefSecNum{Text Input-Output}),
1909 or an access value designating the standard @Chg{New=[error],Old=[output]} file, respectively.
1910
1911 @end{DescribeCode}
1912 @Comment{The following paragraph was originally in a DescribeCode section; but
1913 that clearly was not intended; I've fixed it. (This changes the indentation of
1914 the paragraph in the old version too, but the change is harmless.) RLB-21-08-2000}
1915 @Trailing@;The Form strings implicitly associated with the opening of
1916 Standard_Input, Standard_Output, and
1917 Standard_Error at the start of program execution are implementation defined.
1918 @begin{DescribeCode}
1919
1920 @begin{Example}@Keepnext
1921 @key[function] Current_Input @key[return] File_Type;
1922 @key[function] Current_Input @key[return] File_Access;
1923 @end{Example}
1924 @Trailing@;Returns the current default input file,
1925 or an access value designating the current default input file,
1926 respectively.
1927
1928 @begin{Example}@Keepnext
1929 @key[function] Current_Output @key[return] File_Type;
1930 @key[function] Current_Output @key[return] File_Access;
1931 @end{Example}
1932 @Trailing@;Returns the current default output file,
1933 or an access value designating the current default output file,
1934 respectively.
1935
1936 @begin{Example}@Keepnext
1937 @key[function] Current_Error @key[return] File_Type;
1938 @key[function] Current_Error @key[return] File_Access;
1939 @end{Example}
1940 @Trailing@;Returns the current default error file,
1941 or an access value designating the current default error file,
1942 respectively.
1943
1944 @begin{Example}@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0051],ARef=[AI95-00057-01]}@Keepnext
1945 @key[procedure] Flush (File : @key[in] @Chg{New=[],Old=[@key[out] ]}File_Type);
1946 @key[procedure] Flush;
1947 @end{Example}
1948 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0130-1]}
1949 @Redundant[The effect of Flush is the same as the corresponding subprogram
1950 in @Chg{Version=[4],New=[Sequential_IO (see @RefSecNum{File Management})],
1951 Old=[Streams.Stream_IO (see @RefSecNum[The Package Streams.Stream_IO])]}.]
1952 If File is not explicitly specified, Current_Output is used.
1953 @Comment{The first sentence is redundant for version 4 and later only, but
1954 I didn't want to delete the entire sentence and replace it (the only way to
1955 make that conditional).}
1956 @end{DescribeCode}
1957
1958 @begin{Discussion}
1959 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0052-1]}
1960 @ChgAdded{Version=[4],Text=[For the purpose of determining whether concurrent
1961 calls on text input-output subprograms are required to perform as specified,
1962 subprograms that implicitly operate on one of the default input-output files
1963 are considered to have a parameter of Current_Input or Current_Output (as
1964 appropriate). The result of Current_Output is considered to be overlapping
1965 with the file given to the latest call of Set_Output (or Standard_Output if
1966 Set_Output hasn't been called); a corresponding consideration applies to the
1967 result of Current_Input. See the introduction of
1968 @RefSecNum{Predefined Language Environment} for details.]}
1969 @end{Discussion}
1970 @end{StaticSem}
1971
1972 @begin{Erron}
1973 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0053],ARef=[AI95-00063-01]}
1974 @PDefn2{Term=(erroneous execution),Sec=(cause)}
1975 The execution of a program is erroneous if it @Chg{New=[invokes an operation on],
1976 Old=[attempts to use]} a current default
1977 input, default output, or default error file@Chg{New=[, and if the
1978 corresponding file object is closed or],Old=[ that]} no longer exists.
1979 @begin{Ramification}
1980 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0053],ARef=[AI95-00063-01]}
1981 @ChgAdded{Version=[1],Text=[Closing a default file, then setting the default
1982 file to another open file before accessing it is not erroneous.]}
1983 @end{Ramification}
1984
1985 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0053],ARef=[AI95-00063-01]}
1986 @ChgDeleted{Version=[1],Text=[If the Close operation is applied to a file
1987 object that is also serving as the default input, default output, or default
1988 error file, then subsequent operations on such a default file are erroneous.]}
1989 @end{Erron}
1990
1991 @begin{Notes}
1992 The standard input, standard output, and standard error
1993 files cannot be opened, closed, reset, or deleted, because the
1994 parameter File of the corresponding procedures has the mode @key[in] @key[out].
1995
1996 The standard input, standard output, and standard error files are different
1997 file objects, but not necessarily different external files.
1998 @end{Notes}
1999
2000 @begin{DiffWord95}
2001 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0051],ARef=[AI95-00057-01]}
2002 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the parameter mode
2003 of Flush; otherwise it could not be used on Standard_Output.]}
2004
2005 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0052],ARef=[AI95-00194-01]}
2006 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected Standard_Error so it
2007 refers to the correct file.]}
2008
2009 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0053],ARef=[AI95-00063-01]}
2010 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that execution
2011 is erroneous only when a closed default file is accessed.]}
2012 @end{DiffWord95}
2013
2014 @begin{DiffWord2012}
2015 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0130-1]}
2016 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Moved the definition of
2017 Flush to @RefSecNum{File Management}, as all input-output packages now
2018 have it.]}
2019 @end{DiffWord2012}
2020
2021
2022 @LabeledSubClause{Specification of Line and Page Lengths}
2023
2024 @begin{StaticSem}
2025 The subprograms described in this subclause are concerned with the line
2026 and page structure of a file of mode Out_File or Append_File. They operate
2027 either on
2028 the file given as the first parameter, or, in the absence of such a file
2029 parameter, on the current default output file. They provide for output
2030 of text with a specified maximum line length or page length. In these
2031 cases, line and page terminators are output implicitly and automatically
2032 when needed. When line and page lengths are unbounded (that is, when
2033 they have the conventional value zero), as in the case of a newly opened
2034 file, new lines and new pages are only started when explicitly called
2035 for.
2036
2037 In all cases, the exception Status_Error is propagated if the file to be
2038 used is not open; the exception Mode_Error is propagated if the mode of the
2039 file is not Out_File or Append_File.
2040 @begin{DescribeCode}
2041 @begin{Example}@Keepnext
2042 @key[procedure] Set_Line_Length(File : @key[in] File_Type; To : @key[in] Count);
2043 @key[procedure] Set_Line_Length(To : @key[in] Count);
2044 @end{Example}
2045 Sets the maximum line length of the specified output or
2046 append file to the number of characters specified by To. The value zero for
2047 To specifies an unbounded line length.
2048 @begin{Ramification}
2049 The setting
2050 does not affect the lengths of lines in the existing file, rather it only
2051 influences subsequent output operations.@end{ramification}
2052
2053 @Trailing@;The exception Use_Error is propagated if the specified line length
2054 is inappropriate for the associated external file.
2055
2056 @begin{Example}@Keepnext
2057 @key[procedure] Set_Page_Length(File : @key[in] File_Type; To : @key[in] Count);
2058 @key[procedure] Set_Page_Length(To : @key[in] Count);
2059 @end{Example}
2060 Sets the maximum page length of the specified output or append file to
2061 the number of lines specified by To. The value zero for To
2062 specifies an unbounded page length.
2063
2064 @Trailing@;The exception Use_Error is propagated if the specified page length
2065 is inappropriate for the associated external file.
2066
2067 @begin{Example}@Keepnext
2068 @key[function] Line_Length(File : @key[in] File_Type) @key[return] Count;
2069 @key[function] Line_Length @key[return] Count;
2070 @end{Example}
2071 @Trailing@;Returns the maximum line length currently set for the
2072 specified output or append file, or zero if the line length is unbounded.
2073
2074 @begin{Example}@Keepnext
2075 @key[function] Page_Length(File : @key[in] File_Type) @key[return] Count;
2076 @key[function] Page_Length @key[return] Count;
2077 @end{Example}
2078 Returns the maximum page length currently set for the
2079 specified output or append file, or zero if the page length is unbounded.
2080 @end{DescribeCode}
2081 @end{StaticSem}
2082
2083 @LabeledSubClause{Operations on Columns, Lines, and Pages}
2084
2085 @begin{StaticSem}
2086 The subprograms described in this subclause provide for explicit control
2087 of line and page structure; they operate either on the file given as the
2088 first parameter, or, in the absence of such a file parameter, on the
2089 appropriate (input or output) current default file. The exception
2090 Status_Error is propagated by any of these subprograms if the file to be
2091 used is not open.
2092 @begin{DescribeCode}
2093 @begin{Example}@Keepnext
2094 @key[procedure] New_Line(File : @key[in] File_Type; Spacing : @key[in] Positive_Count := 1);
2095 @key[procedure] New_Line(Spacing : @key[in] Positive_Count := 1);
2096 @end{Example}
2097
2098 Operates on a file of mode Out_File or Append_File.
2099
2100 For a Spacing of one: Outputs a line terminator and sets the
2101 current column number to one. Then increments the current
2102 line number by one, except in the case that the current line
2103 number is already greater than or equal to the maximum page
2104 length, for a bounded page length; in that case a page
2105 terminator is output, the current page number is incremented
2106 by one, and the current line number is set to one.
2107
2108 For a Spacing greater than one, the above actions are
2109 performed Spacing times.
2110
2111 @Trailing@;The exception Mode_Error is propagated if the mode is not
2112 Out_File or Append_File.
2113
2114 @begin{Example}@Keepnext
2115 @key[procedure] Skip_Line(File : @key[in] File_Type; Spacing : @key[in] Positive_Count := 1);
2116 @key[procedure] Skip_Line(Spacing : @key[in] Positive_Count := 1);
2117 @end{Example}
2118
2119 Operates on a file of mode In_File.
2120
2121 For a Spacing of one: Reads and discards all characters until
2122 a line terminator has been read, and then sets the current
2123 column number to one. If the line terminator is not
2124 immediately followed by a page terminator, the current line
2125 number is incremented by one. Otherwise, if the line
2126 terminator is immediately followed by a page terminator, then
2127 the page terminator is skipped, the current page number is
2128 incremented by one, and the current line number is set to one.
2129
2130 For a Spacing greater than one, the above actions are
2131 performed Spacing times.
2132
2133 @Trailing@;The exception Mode_Error is propagated if the mode is not In_File.
2134 The exception End_Error is propagated if an attempt is made to
2135 read a file terminator.
2136
2137 @begin{Example}@Keepnext
2138 @key[function] End_Of_Line(File : @key[in] File_Type) @key[return] Boolean;
2139 @key[function] End_Of_Line @key[return] Boolean;
2140 @end{Example}
2141 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2142 Operates on a file of mode In_File. Returns True if a line
2143 terminator or a file terminator is next;
2144 otherwise@Chg{Version=[3],New=[,],Old=[]} returns False.
2145
2146 @Trailing@;The exception Mode_Error is propagated if the mode is not In_File.
2147
2148 @begin{Example}@Keepnext
2149 @key[procedure] New_Page(File : @key[in] File_Type);
2150 @key[procedure] New_Page;
2151 @end{Example}
2152
2153 Operates on a file of mode Out_File or Append_File. Outputs a line
2154 terminator if the current line is not terminated, or if the
2155 current page is empty (that is, if the current column and line
2156 numbers are both equal to one). Then outputs a page
2157 terminator, which terminates the current page. Adds one to
2158 the current page number and sets the current column and line
2159 numbers to one.
2160
2161 @Trailing@;The exception Mode_Error is propagated if the mode is not
2162 Out_File or Append_File.
2163
2164 @begin{Example}@Keepnext
2165 @key[procedure] Skip_Page(File : @key[in] File_Type);
2166 @key[procedure] Skip_Page;
2167 @end{Example}
2168 Operates on a file of mode In_File. Reads and discards all
2169 characters and line terminators until a page terminator has
2170 been read. Then adds one to the current page number, and sets
2171 the current column and line numbers to one.
2172
2173 @Trailing@;The exception Mode_Error is propagated if the mode is not In_File.
2174 The exception End_Error is propagated if an attempt is made to
2175 read a file terminator.
2176
2177 @begin{Example}@Keepnext
2178 @key[function] End_Of_Page(File : @key[in] File_Type) @key[return] Boolean;
2179 @key[function] End_Of_Page @key[return] Boolean;
2180 @end{Example}
2181 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2182 Operates on a file of mode In_File. Returns True if the
2183 combination of a line terminator and a page terminator is
2184 next, or if a file terminator is next;
2185 otherwise@Chg{Version=[3],New=[,],Old=[]} returns False.
2186
2187 @Trailing@;The exception Mode_Error is propagated if the mode is not In_File.
2188
2189 @begin{Example}@Keepnext
2190 @key[function] End_Of_File(File : @key[in] File_Type) @key[return] Boolean;
2191 @key[function] End_Of_File @key[return] Boolean;
2192 @end{Example}
2193
2194 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
2195 Operates on a file of mode In_File. Returns True if a file
2196 terminator is next, or if the combination of a line, a page,
2197 and a file terminator is next;
2198 otherwise@Chg{Version=[3],New=[,],Old=[]} returns False.
2199
2200 @Trailing@;The exception Mode_Error is propagated if the mode is not In_File.
2201
2202 @end{DescribeCode}
2203 @Comment{The following paragraph was originally in a DescribeCode section; but
2204 that clearly was not intended; I've fixed it. (This changes the indentation of
2205 the paragraph in the old version too, but the change is harmless.) RLB-21-08-2000}
2206 The following subprograms provide for the control of the current
2207 position of reading or writing in a file. In all cases, the default
2208 file is the current output file.
2209 @begin{DescribeCode}
2210
2211 @begin{Example}@Keepnext
2212 @key[procedure] Set_Col(File : @key[in] File_Type; To : @key[in] Positive_Count);
2213 @key[procedure] Set_Col(To : @key[in] Positive_Count);
2214 @end{Example}
2215 @Leading@;If the file mode is Out_File or Append_File:
2216 @begin{itemize}
2217 If the value specified by To is greater than the current
2218 column number, outputs spaces, adding one to the current
2219 column number after each space, until the current column
2220 number equals the specified value. If the value
2221 specified by To is equal to the current column number,
2222 there is no effect. If the value specified by To is less
2223 than the current column number, has the effect of calling
2224 New_Line (with a spacing of one), then outputs (To @en 1)
2225 spaces, and sets the current column number to the
2226 specified value.
2227
2228 The exception Layout_Error is propagated if the value
2229 specified by To exceeds Line_Length when the line length
2230 is bounded (that is, when it does not have the
2231 conventional value zero).
2232 @end{itemize}
2233
2234 @Leading@;If the file mode is In_File:
2235 @begin{itemize}
2236 Reads (and discards) individual characters, line
2237 terminators, and page terminators, until the next
2238 character to be read has a column number that equals the
2239 value specified by To; there is no effect if the current
2240 column number already equals this value. Each transfer
2241 of a character or terminator maintains the current
2242 column, line, and page numbers in the same way as a Get
2243 procedure (see @RefSecNum{Get and Put Procedures}).
2244 (Short lines will be skipped
2245 until a line is reached that has a character at the
2246 specified column position.)
2247
2248 @Trailing@;The exception End_Error is propagated if an attempt is made
2249 to read a file terminator.
2250 @end{itemize}
2251
2252 @begin{Example}@Keepnext
2253 @key[procedure] Set_Line(File : @key[in] File_Type; To : @key[in] Positive_Count);
2254 @key[procedure] Set_Line(To : @key[in] Positive_Count);
2255 @end{Example}
2256
2257 @Leading@;If the file mode is Out_File or Append_File:
2258 @begin{itemize}
2259 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0038-1]}
2260 If the value specified by To is greater than the current
2261 line number, has the effect of repeatedly calling
2262 New_Line (with a spacing of one), until the current line
2263 number equals the specified value. If the value
2264 specified by To is equal to the current line number,
2265 there is no effect. If the value specified by To is less
2266 than the current line number, has the effect of calling
2267 New_Page followed@Chg{Version=[3],New=[, if To is greater
2268 than 1,],Old=[]} by a call of New_Line with a spacing
2269 equal to (To @en 1).
2270
2271 The exception Layout_Error is propagated if the value
2272 specified by To exceeds Page_Length when the page length
2273 is bounded (that is, when it does not have the
2274 conventional value zero).
2275 @end{itemize}
2276
2277 @Leading@;If the mode is In_File:
2278 @begin{itemize}
2279 Has the effect of repeatedly calling Skip_Line (with a
2280 spacing of one), until the current line number equals the
2281 value specified by To; there is no effect if the current
2282 line number already equals this value. (Short pages will
2283 be skipped until a page is reached that has a line at the
2284 specified line position.)
2285
2286 @Trailing@;The exception End_Error is propagated if an attempt is made
2287 to read a file terminator.
2288 @end{itemize}
2289 @begin{Example}@Keepnext
2290 @key[function] Col(File : @key[in] File_Type) @key[return] Positive_Count;
2291 @key[function] Col @key[return] Positive_Count;
2292 @end{Example}
2293
2294 Returns the current column number.
2295
2296 @Trailing@;The exception Layout_Error is propagated if this number exceeds
2297 Count'Last.
2298
2299 @begin{Example}@Keepnext
2300 @key[function] Line(File : @key[in] File_Type) @key[return] Positive_Count;
2301 @key[function] Line @key[return] Positive_Count;
2302 @end{Example}
2303
2304 Returns the current line number.
2305
2306 @Trailing@;The exception Layout_Error is propagated if this number exceeds
2307 Count'Last.
2308
2309 @begin{Example}@Keepnext
2310 @key[function] Page(File : @key[in] File_Type) @key[return] Positive_Count;
2311 @key[function] Page @key[return] Positive_Count;
2312 @end{Example}
2313 Returns the current page number.
2314
2315 @Trailing@;The exception Layout_Error is propagated if this number exceeds
2316 Count'Last.
2317
2318 @end{DescribeCode}
2319
2320 The column number, line number, or page number are allowed to exceed
2321 Count'Last (as a consequence of the input or output of sufficiently many
2322 characters, lines, or pages). These events do not cause any exception
2323 to be propagated.
2324 However, a call of Col, Line, or Page propagates the
2325 exception Layout_Error if the corresponding number exceeds Count'Last.
2326 @end{StaticSem}
2327
2328 @begin{Notes}
2329 A page terminator is always skipped whenever the preceding line
2330 terminator is skipped. An implementation may represent the combination
2331 of these terminators by a single character, provided that it is properly
2332 recognized on input.
2333 @end{Notes}
2334
2335 @begin{Inconsistent2005}
2336 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0038-1]}
2337 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}@b<Correction:>
2338 Fixed a glitch in Set_Line such that we could have called New_Line(0), which
2339 would have to raise Constraint_Error. It's now defined to work. The bug
2340 occurred in Ada 95 and Ada 2005. It's very unlikely that
2341 any real programs depend on this exception being raised.]}
2342 @end{Inconsistent2005}
2343
2344
2345 @LabeledSubClause{Get and Put Procedures}
2346
2347 @begin{StaticSem}
2348 The procedures Get and Put for items of the type Character, String,
2349 numeric types, and enumeration types are described in subsequent
2350 subclauses.
2351 Features of these procedures that are common to most of these
2352 types are described in this subclause. The Get and Put procedures for
2353 items of type Character and String deal with individual character
2354 values; the Get and Put procedures for numeric and enumeration types
2355 treat the items as lexical elements.
2356
2357 All procedures Get and Put have forms with a
2358 file parameter, written
2359 first. Where this parameter is omitted, the appropriate (input or
2360 output) current default file is understood to be specified. Each
2361 procedure Get operates on a
2362 file of mode In_File. Each procedure Put
2363 operates on a file of mode Out_File or Append_File.
2364
2365 All procedures Get and Put maintain the current column, line, and page
2366 numbers of the specified file: the effect of each of these procedures
2367 upon these numbers is the result of the effects of individual
2368 transfers of characters and of individual output or skipping of
2369 terminators. Each transfer of a character adds one to the current
2370 column number. Each output of a line terminator sets the current column
2371 number to one and adds one to the current line number. Each output of a
2372 page terminator sets the current column and line numbers to one and adds
2373 one to the current page number. For input, each skipping of a line
2374 terminator sets the current column number to one and adds one to the
2375 current line number; each skipping of a page terminator sets the current
2376 column and line numbers to one and adds one to the current page number.
2377 Similar considerations apply to the procedures Get_Line, Put_Line, and
2378 Set_Col.
2379
2380 Several Get and Put procedures, for numeric and enumeration types, have
2381 @i{format} parameters which specify field lengths; these parameters are of
2382 the nonnegative subtype Field of the type Integer.
2383
2384 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00223-01]}
2385 @Defn2{Term=[blank], Sec=(in text input for enumeration and numeric types)}
2386 Input-output of enumeration values uses the syntax of the corresponding
2387 lexical elements. Any Get procedure for an enumeration type begins by
2388 skipping any leading blanks, or line or page terminators. @Chg{Version=[2],
2389 New=[A],Old=[Get procedures
2390 for numeric or enumeration types start by skipping leading blanks, where
2391 a]} @i{blank} is defined as a space or a horizontal tabulation character.
2392 Next,
2393 characters are input only so long as the sequence input is an initial
2394 sequence of an identifier or of a character literal (in particular,
2395 input ceases when a line terminator is encountered). The character or
2396 line terminator that causes input to cease remains available for
2397 subsequent input.
2398
2399 For a numeric type, the Get procedures have a format parameter called
2400 Width. If the value given for this parameter is zero, the Get procedure
2401 proceeds in the same manner as for enumeration types, but using the
2402 syntax of numeric literals instead of that of enumeration literals. If
2403 a nonzero value is given, then exactly Width characters are input, or
2404 the characters up to a line terminator, whichever comes first; any
2405 skipped leading blanks are included in the count. The syntax used for
2406 numeric literals is an extended syntax that allows a leading sign (but
2407 no intervening blanks, or line or page terminators)
2408 and that also allows (for real types) an integer literal
2409 as well as forms that have digits only before the point
2410 or only after the point.
2411
2412 Any Put procedure, for an item of a numeric or an enumeration type,
2413 outputs the value of the item as a numeric literal, identifier, or
2414 character literal, as appropriate. This is preceded by leading spaces
2415 if required by the format parameters Width or Fore (as described in
2416 later subclauses), and then a minus sign for a negative value; for an
2417 enumeration type, the spaces follow instead of leading. The format
2418 given for a Put procedure is overridden if it is insufficiently wide,
2419 by using the minimum needed width.
2420
2421 Two further cases arise for Put procedures for numeric and enumeration
2422 types, if the line length of the specified output file is bounded (that
2423 is, if it does not have the conventional value zero). If the number of
2424 characters to be output does not exceed the maximum line length, but is
2425 such that they cannot fit on the current line, starting from the current
2426 column, then (in effect) New_Line is called (with a spacing of one)
2427 before output of the item. Otherwise, if the number of characters
2428 exceeds the maximum line length, then the exception Layout_Error is
2429 propagated and nothing is output.
2430
2431 The exception Status_Error is propagated by any of the procedures Get,
2432 Get_Line, Put, and Put_Line if the file to be used is not open. The
2433 exception Mode_Error is propagated by the procedures Get and Get_Line if the
2434 mode of the file to be used is not In_File; and by the procedures Put
2435 and Put_Line, if the mode is not Out_File or Append_File.
2436
2437 The exception End_Error is propagated by a Get procedure if an attempt is
2438 made to skip a file terminator. The exception Data_Error is propagated by a
2439 Get procedure if the sequence finally input is not a lexical element
2440 corresponding to the type, in particular if no characters were input;
2441 for this test, leading blanks are ignored; for an item of a numeric
2442 type, when a sign is input, this rule applies to the succeeding numeric
2443 literal. The exception Layout_Error is propagated by a Put procedure that
2444 outputs to a parameter of type String, if the length of the actual
2445 string is insufficient for the output of the item.
2446 @end{StaticSem}
2447
2448 @begin{Examples}
2449 In the examples, here and in subclauses
2450 @RefSecNum{Input-Output for Integer Types}
2451 and @RefSecNum{Input-Output for Real Types}, the string
2452 quotes and the lower case letter b are not transferred: they are shown
2453 only to reveal the layout and spaces.
2454
2455 @begin{Example}
2456 N : Integer;
2457 ...
2458 Get(N);
2459
2460 @tabclear()@tabset(P4, P22, P38)
2461 @RI[-- @\Characters at input @\Sequence input @\Value of N]
2462 @Comment{Blank line.}
2463 @RI[-- @\bb@en@|12535b @\@en@|12535 @\@en@|12535]
2464 @RI[-- @\bb12_535e1b @\12_535e1 @\125350]
2465 @RI[-- @\bb12_535e; @\12_535e @\(none) Data_Error raised]
2466 @end{Example}
2467
2468 @begin{WideAbove}
2469 @Leading@;Example of overridden width parameter:
2470 @end{WideAbove}
2471
2472 @begin{Example}
2473 Put(Item => -23, Width => 2); --@RI{ "@en@|23"}
2474 @end{Example}
2475 @end{Examples}
2476
2477 @begin{DiffWord95}
2478 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00223-01]}
2479 @ChgAdded{Version=[2],Text=[Removed conflicting text describing the
2480 skipping of blanks for a Get procedure.]}
2481 @end{DiffWord95}
2482
2483
2484 @LabeledSubClause{Input-Output of Characters and Strings}
2485
2486 @begin{StaticSem}
2487 @Leading@Keepnext@;For an item of type Character the following procedures are
2488 provided:
2489 @begin{DescribeCode}
2490 @begin{Example}@Keepnext
2491 @key[procedure] Get(File : @key[in] File_Type; Item : @key[out] Character);
2492 @key[procedure] Get(Item : @key[out] Character);
2493 @end{Example}
2494 After skipping any line terminators and any page terminators,
2495 reads the next character from the specified input file and
2496 returns the value of this character in the out parameter Item.
2497
2498 @Trailing@;The exception End_Error is propagated if an attempt is made to
2499 skip a file terminator.
2500
2501 @begin{Example}@Keepnext
2502 @key[procedure] Put(File : @key[in] File_Type; Item : @key[in] Character);
2503 @key[procedure] Put(Item : @key[in] Character);
2504 @end{Example}
2505 @Trailing@;If the line length of the specified output file is bounded
2506 (that is, does not have the conventional value zero), and the
2507 current column number exceeds it, has the effect of calling
2508 New_Line with a spacing of one. Then, or otherwise, outputs
2509 the given character to the file.
2510
2511 @begin{Example}@Keepnext
2512 @key[procedure] Look_Ahead (File : @key[in] File_Type;
2513 Item : @key[out] Character;
2514 End_Of_Line : @key[out] Boolean);
2515 @key[procedure] Look_Ahead (Item : @key[out] Character;
2516 End_Of_Line : @key[out] Boolean);
2517 @end{Example}
2518 @Trailing@ChgRef{Version=[1],Kind=[Revised]}
2519 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0038-1],ARef=[AI05-0264-1]}@Chg{Version=[3],
2520 New=[Status_Error is propagated if the file is not open. ],Old=[]}Mode_Error
2521 is propagated if
2522 the mode of the file is not In_File. Sets End_Of_Line to True if at end of
2523 line, including if at end of page or at end of file; in each of these cases
2524 the value of Item is not specified.
2525 @PDefn{unspecified}
2526 Otherwise@Chg{Version=[3],New=[,],Old=[]} End_Of_Line is set to
2527 False and Item is set to @Chg{New=[],Old=[the ]}the next character (without
2528 consuming it) from the file.
2529
2530 @begin{Example}@Keepnext
2531 @key[procedure] Get_Immediate(File : @key[in] File_Type;
2532 Item : @key[out] Character);
2533 @key[procedure] Get_Immediate(Item : @key[out] Character);
2534 @end{Example}
2535 @Trailing@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0038-1]}Reads
2536 the next character, either control or graphic, from the specified
2537 File or the default input file. @Chg{Version=[3],New=[Status_Error is
2538 propagated if the file is not open. ],Old=[]}Mode_Error is propagated
2539 if the mode of the
2540 file is not In_File. End_Error is propagated if at the end of the file.
2541 The current column, line and page numbers for the file are not affected.
2542
2543 @begin{Example}@Keepnext
2544 @key[procedure] Get_Immediate(File : @key[in] File_Type;
2545 Item : @key[out] Character;
2546 Available : @key[out] Boolean);
2547 @key[procedure] Get_Immediate(Item : @key[out] Character;
2548 Available : @key[out] Boolean);
2549 @end{Example}
2550 @Trailing@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0038-1]}If
2551 a character, either control or graphic, is available from the
2552 specified File or the default input file, then the character is read;
2553 Available is True and Item contains the value of this character. If a character
2554 is not available, then Available is False and the value of
2555 Item is not specified.
2556 @PDefn{unspecified}
2557 @Chg{Version=[3],New=[Status_Error is propagated if the file is
2558 not open. ],Old=[]}Mode_Error is propagated if the mode of the
2559 file is not In_File. End_Error is propagated if at the end of the file.
2560 The current column, line and page numbers for the file are not affected.
2561
2562 @end{DescribeCode}
2563 @Comment{The following paragraph was originally in a DescribeCode section; but
2564 that clearly was not intended; I've fixed it. (This changes the indentation of
2565 the paragraph in the old version too, but the change is harmless.) RLB-21-08-2000}
2566 @Leading@;
2567 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00301-01]}
2568 For an item of type String the following @Chg{Version=[2],New=[subprograms],
2569 Old=[procedures]} are provided:
2570 @begin{DescribeCode}
2571
2572 @begin{Example}@Keepnext
2573 @key[procedure] Get(File : @key[in] File_Type; Item : @key[out] String);
2574 @key[procedure] Get(Item : @key[out] String);
2575 @end{Example}
2576 @Trailing@;Determines the length of the given string and attempts that
2577 number of Get operations for successive characters of the
2578 string (in particular, no operation is performed if the string is null).
2579
2580 @begin{Example}@Keepnext
2581 @key[procedure] Put(File : @key[in] File_Type; Item : @key[in] String);
2582 @key[procedure] Put(Item : @key[in] String);
2583 @end{Example}
2584 @Trailing@;Determines the length of the given string and attempts that
2585 number of Put operations for successive characters of the
2586 string (in particular, no operation is performed if the string is null).
2587
2588 @begin{Example}
2589 @ChgRef{Version=[2],Kind=[Added]}
2590 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key{function} Get_Line(File : @key{in} File_Type) @key{return} String;
2591 @key{function} Get_Line @b<return> String;]}
2592 @end{Example}
2593 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00301-01]}
2594 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns a result string
2595 constructed by reading successive characters from the specified input file,
2596 and assigning them to successive characters of the result string. The result
2597 string has a lower bound of 1 and an upper bound of the number of characters
2598 read. Reading stops when the end of the line is met; Skip_Line is then (in
2599 effect) called with a spacing of 1.]}
2600
2601 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00301-01]}
2602 @ChgAdded{Version=[2],Type=[Trailing],Text=[Constraint_Error is raised if the
2603 length of the line exceeds Positive'Last; in this case, the line number and page
2604 number are unchanged, and the column number is unspecified but no less than
2605 it was before the call.@PDefn{unspecified} The exception End_Error is
2606 propagated if an attempt is made to skip a file terminator.]}
2607
2608 @begin{Ramification}
2609 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
2610 @ChgAdded{Version=[2],Text=[Precisely what is left in the file is unspecified
2611 if Constraint_Error is raised because the line doesn't fit in a String; it
2612 should be consistent with column number. This allows implementers to use
2613 whatever buffering scheme makes sense. But the line terminator is not
2614 skipped in this case.]}
2615 @end{Ramification}
2616
2617 @begin{Example}@Keepnext
2618 @key[procedure] Get_Line(File : @key[in] File_Type;
2619 Item : @key[out] String;
2620 Last : @key[out] Natural);
2621 @key[procedure] Get_Line(Item : @key[out] String;
2622 Last : @key[out] Natural);
2623 @end{Example}
2624 Reads successive characters from the specified input file and assigns
2625 them to successive characters of the specified string.
2626 Reading stops if the end of the string is met. Reading also stops if
2627 the end of the line is met before meeting the end of the string;
2628 in this case Skip_Line is (in effect) called with a spacing of 1.
2629 @PDefn{unspecified}
2630 The values of characters not assigned are not specified.
2631
2632 @Trailing@;If characters are read, returns in Last the index value such
2633 that Item(Last) is the last character assigned (the index of
2634 the first character assigned is Item'First). If no characters
2635 are read, returns in Last an index value that is one less than
2636 Item'First. The exception End_Error is propagated if an attempt
2637 is made to skip a file terminator.
2638
2639 @begin{Example}@Keepnext
2640 @key[procedure] Put_Line(File : @key[in] File_Type; Item : @key[in] String);
2641 @key[procedure] Put_Line(Item : @key[in] String);
2642 @end{Example}
2643 Calls the procedure Put for the given string, and then the
2644 procedure New_Line with a spacing of one.
2645 @end{DescribeCode}
2646 @end{StaticSem}
2647
2648 @begin{ImplAdvice}
2649 The Get_Immediate procedures should be implemented with unbuffered
2650 input. For a device such as a keyboard, input should be @lquotes@;available@rquotes@;
2651 if a key has already been typed, whereas for a disk file, input
2652 should always be available except at end of file. For a file
2653 associated with a keyboard-like device, any line-editing features
2654 of the underlying operating system should be disabled during
2655 the execution of Get_Immediate.
2656 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2657 Text=[Get_Immediate should be implemented with unbuffered input; input
2658 should be available immediately; line-editing should be disabled.]}]}
2659 @end{ImplAdvice}
2660
2661 @begin{Notes}
2662 Get_Immediate can be used to read a single key from the
2663 keyboard @lquotes@;immediately@rquotes@;; that is, without waiting for an end of line.
2664 In a call of Get_Immediate without the parameter Available,
2665 the caller will wait until a character is available.
2666
2667 In a literal string parameter of Put, the enclosing string bracket
2668 characters are not output. Each doubled string bracket character in the
2669 enclosed string is output as a single string bracket character, as a
2670 consequence of the rule for string literals (see @RefSecNum{String Literals}).
2671
2672 A string read by Get or written by Put can extend over several lines.
2673 An implementation is allowed to assume that certain external files do
2674 not contain page terminators, in which case Get_Line and Skip_Line can
2675 return as soon as a line terminator is read.
2676 @end{Notes}
2677
2678 @begin{Incompatible95}
2679 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
2680 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
2681 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
2682 The Get_Line functions are @Chg{Version=[3],New=[],Old=[newly ]}added
2683 to Ada.Text_IO.
2684 If Ada.Text_IO is referenced in a @nt{use_clause}, and a function Get_Line
2685 is defined in a package that is also referenced in a @nt{use_clause}, the
2686 user-defined Get_Line may no longer be use-visible, resulting in errors.
2687 This should be rare and is easily fixed if it does occur.]}
2688 @end{Incompatible95}
2689
2690 @begin{Extend95}
2691 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
2692 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2693 The Text_IO.Get_Line functions are new.]}
2694 @end{Extend95}
2695
2696 @begin{DiffWord2005}
2697 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0038-1]}
2698 @ChgAdded{Version=[3],Text=[@b<Correction:> Added missing wording about
2699 raising Status_Error to Look_Ahead and Get_Immediate.]}
2700 @end{DiffWord2005}
2701
2702
2703
2704 @LabeledSubClause{Input-Output for Integer Types}
2705
2706 @begin{StaticSem}
2707 The following procedures are defined in the generic packages Integer_IO
2708 and Modular_IO, which have to be
2709 instantiated for the appropriate signed
2710 integer or modular
2711 type respectively
2712 (indicated by Num in the specifications).
2713
2714 @Leading@;Values are output as decimal or based literals, without low line
2715 characters or exponent, and, for Integer_IO, preceded by a minus sign if negative. The
2716 format (which includes any leading spaces and minus sign) can be
2717 specified by an optional field width parameter. Values of widths of
2718 fields in output formats are of the nonnegative integer subtype Field.
2719 Values of bases are of the integer subtype Number_Base.
2720 @begin{Example}
2721 @Trailing@key[subtype] Number_Base @key[is] Integer @key[range] 2 .. 16;
2722 @end{Example}
2723
2724 @Leading@;The default field width and base to be used by output procedures are
2725 defined by the following variables that are declared in the generic
2726 packages Integer_IO and Modular_IO:
2727
2728 @begin{Example}
2729 @Trailing@;Default_Width : Field := Num'Width;
2730 Default_Base : Number_Base := 10;
2731 @end{Example}
2732
2733 @Leading@Keepnext@;The following procedures are provided:
2734 @begin{DescribeCode}
2735 @begin{Example}@Keepnext
2736 @key[procedure] Get(File : @key[in] File_Type; Item : @key[out] Num; Width : @key[in] Field := 0);
2737 @key[procedure] Get(Item : @key[out] Num; Width : @key[in] Field := 0);
2738 @end{Example}
2739 If the value of the parameter Width is zero, skips any leading
2740 blanks, line terminators, or page terminators, then
2741 reads a plus sign if present or (for a signed type only)
2742 a minus sign if present, then reads the longest possible
2743 sequence of characters matching the syntax of a numeric
2744 literal without a point.
2745 If a nonzero value of Width is supplied, then exactly Width
2746 characters are input, or the characters (possibly none) up to
2747 a line terminator, whichever comes first; any skipped leading
2748 blanks are included in the count.
2749
2750 Returns, in the parameter Item, the value of type Num
2751 that corresponds to the sequence input.
2752
2753 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0038-1]}
2754 @Trailing@;The exception Data_Error is propagated if the sequence of characters
2755 read does not form a legal integer literal or if the value obtained is
2756 not of the subtype Num@Chg{Version=[3],New=[],Old=[ (for Integer_IO) or
2757 is not in the base range of Num (for Modular_IO)]}.
2758
2759 @begin{Example}@Keepnext
2760 @key[procedure] Put(File : @key[in] File_Type;
2761 Item : @key[in] Num;
2762 Width : @key[in] Field := Default_Width;
2763 Base : @key[in] Number_Base := Default_Base);
2764 @comment{Blank Line}
2765 @key[procedure] Put(Item : @key[in] Num;
2766 Width : @key[in] Field := Default_Width;
2767 Base : @key[in] Number_Base := Default_Base);
2768 @end{Example}
2769 Outputs the value of the parameter Item as an integer literal,
2770 with no low lines, no exponent, and no leading zeros (but a
2771 single zero for the value zero), and a preceding minus sign
2772 for a negative value.
2773
2774 If the resulting sequence of characters to be output has fewer
2775 than Width characters, then leading spaces are first output to
2776 make up the difference.
2777
2778 @Trailing@;Uses the syntax for decimal literal if the parameter Base has
2779 the value ten (either explicitly or through Default_Base);
2780 otherwise, uses the syntax for based literal, with any letters
2781 in upper case.
2782
2783 @begin{Example}@Keepnext
2784 @key[procedure] Get(From : @key[in] String; Item : @key[out] Num; Last : @key[out] Positive);
2785 @end{Example}
2786 Reads an integer value from the beginning of the given string,
2787 following the same rules as the Get procedure that reads an
2788 integer value from a file, but treating the end of the string
2789 as a file terminator. Returns, in the parameter Item, the
2790 value of type Num that corresponds to the sequence input.
2791 Returns in Last the index value such that From(Last) is the
2792 last character read.
2793
2794 @Trailing@;The exception Data_Error is propagated if the sequence input does
2795 not have the required syntax or if the value obtained is not
2796 of the subtype Num.
2797
2798 @begin{Example}@Keepnext
2799 @key[procedure] Put(To : @key[out] String;
2800 Item : @key[in] Num;
2801 Base : @key[in] Number_Base := Default_Base);
2802 @end{Example}
2803 @Trailing@;Outputs the value of the parameter Item to the given string,
2804 following the same rule as for output to a file, using the
2805 length of the given string as the value for Width.
2806 @end{DescribeCode}
2807
2808 @Leading@;Integer_Text_IO is a library package that is a nongeneric equivalent
2809 to Text_IO.Integer_IO for the predefined type Integer:
2810 @begin{Example}
2811 @key[with] Ada.Text_IO;@ChildUnit{Parent=[Ada],Child=[Integer_@!Text_IO]}
2812 @key[package] Ada.Integer_Text_IO @key[is] @key[new] Ada.Text_IO.Integer_IO(Integer);
2813 @end{Example}
2814
2815 For each predefined signed integer type,
2816 a nongeneric equivalent to Text_IO.Integer_IO is provided,
2817 with names such as Ada.Long_Integer_Text_IO.
2818
2819
2820 @end{StaticSem}
2821
2822 @begin{ImplPerm}
2823
2824 The nongeneric equivalent packages may, but need not,
2825 be actual instantiations of the generic package for the appropriate
2826 predefined type.
2827
2828 @end{ImplPerm}
2829
2830 @begin{Notes}
2831 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0038-1]}
2832 @ChgDeleted{Version=[3],Text=[For Modular_IO, execution of Get propagates
2833 Data_Error if the sequence of
2834 characters read forms an integer literal outside the range
2835 0..Num'Last.]}
2836 @end{Notes}
2837 @begin{NotIso}
2838 @ChgAdded{Version=[3],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 24 and 25 were
2839 deleted.>}]}@Comment{This message should be deleted if the paragraphs
2840 are ever renumbered. This includes the next paragraph.}
2841 @end{NotIso}
2842
2843 @begin{Examples}
2844 @begin{Example}
2845 @ChgRef{Version=[1], Kind=[DeletedNoDelMsg]}
2846 @ChgDeleted[Version=[1],Text=<@ @;@comment{Empty paragraph to hang junk paragraph number from original RM}>]
2847
2848 @ChgRef{Version=[3], Kind=[Revised],ARef=[AI05-0298-1]}
2849 @Chg{Version=[3],New=[@key[subtype] Byte_Int @key[is] Integer @key[range] -127 .. 127;
2850 ],Old=[]}@key[package] Int_IO @key[is] @key[new] Integer_IO(@Chg{Version=[3],New=[Byte_Int],Old=[Small_Int]}); @key[use] Int_IO;
2851 --@RI{ default format used at instantiation,}
2852 --@RI{ Default_Width = 4, Default_Base = 10}
2853
2854 Put(126); --@RI{ "b126"}
2855 Put(-126, 7); --@RI{ "bbb@en@|126"}
2856 Put(126, Width => 13, Base => 2); --@RI{ "bbb2#1111110#"}
2857 @end{Example}
2858 @end{Examples}
2859
2860 @begin{Inconsistent2005}
2861 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0038-1]}
2862 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}@b<Correction:>
2863 Changed wording to make Integer_IO and Modular_IO raise Data_Error in the same
2864 way when the bounds of the subtype are exceeded. There is no value to
2865 different behavior, and all surveyed compilers already treat integer and
2866 modular values the same way. This could only cause a problem if a
2867 program was compiled with some unsurveyed compiler, and the Ada 95-defined
2868 behavior is expected for Modular_IO. But note that such code is not portable
2869 anyway, as most widely used compilers behave consistently with the
2870 new wording, so it is unlikely that such code exists.]}
2871 @end{Inconsistent2005}
2872
2873
2874 @LabeledSubClause{Input-Output for Real Types}
2875
2876 @begin{StaticSem}
2877 The following procedures are defined in the generic packages Float_IO,
2878 Fixed_IO, and Decimal_IO, which have to be instantiated for the
2879 appropriate floating point, ordinary fixed point, or decimal fixed point
2880 type respectively (indicated by Num in the specifications).
2881
2882 @Leading@;Values are output as decimal literals without low line characters.
2883 The format of each value output consists of a Fore field, a decimal point,
2884 an Aft field, and (if a nonzero Exp parameter is supplied) the letter E
2885 and an Exp field. The two possible formats thus correspond to:
2886
2887 @begin{Example}
2888 Fore . Aft
2889 @end{Example}
2890
2891 @Leading@;and to:
2892
2893 @begin{Example}
2894 Fore . Aft E Exp
2895 @end{Example}
2896
2897 without any spaces between these fields. The Fore field may include
2898 leading spaces, and a minus sign for negative values. The Aft field
2899 includes only decimal digits (possibly with trailing zeros). The Exp
2900 field includes the sign (plus or minus) and the exponent (possibly with
2901 leading zeros).
2902
2903 @Leading@;For floating point types, the default lengths of these fields are
2904 defined by the following variables that are declared in the generic
2905 package Float_IO:
2906
2907 @begin{Example}
2908 @Trailing@;Default_Fore : Field := 2;
2909 Default_Aft : Field := Num'Digits-1;
2910 Default_Exp : Field := 3;
2911 @end{Example}
2912
2913 @Leading@;For ordinary or decimal fixed point types, the default lengths of these
2914 fields are defined by the following variables that are declared in the
2915 generic packages Fixed_IO and Decimal_IO, respectively:
2916
2917 @begin{Example}
2918 @Trailing@;Default_Fore : Field := Num'Fore;
2919 Default_Aft : Field := Num'Aft;
2920 Default_Exp : Field := 0;
2921 @end{Example}
2922
2923 @Leading@Keepnext@;The following procedures are provided:
2924 @begin{DescribeCode}
2925 @begin{Example}@Keepnext
2926 @key[procedure] Get(File : @key[in] File_Type; Item : @key[out] Num; Width : @key[in] Field := 0);
2927 @key[procedure] Get(Item : @key[out] Num; Width : @key[in] Field := 0);
2928 @end{Example}
2929
2930 @Leading@;If the value of the parameter Width is zero, skips any leading
2931 blanks, line terminators, or page terminators, then reads the longest
2932 possible sequence of characters matching the syntax of any of the following
2933 (see @RefSecNum(Numeric Literals)):
2934 @begin[itemize]
2935 [+|@en]@nt[numeric_literal]
2936
2937 [+|@en]@nt[numeral].[@nt[exponent]]
2938
2939 [+|@en].@nt[numeral][@nt[exponent]]
2940
2941 [+|@en]@nt[base]#@nt[based_numeral].#[@nt[exponent]]
2942
2943 [+|@en]@nt[base]#.@nt[based_numeral]#[@nt[exponent]]
2944 @end{Itemize}
2945
2946
2947 If a nonzero value of Width is supplied, then exactly Width
2948 characters are input, or the characters (possibly none) up to
2949 a line terminator, whichever comes first; any skipped leading
2950 blanks are included in the count.
2951
2952 Returns in the parameter Item the value of type Num that
2953 corresponds to the sequence input, preserving the sign (positive
2954 if none has been specified) of a zero value if Num is a floating
2955 point type and Num'Signed_Zeros is True.
2956
2957 @Trailing@;The exception Data_Error is propagated if the sequence input does
2958 not have the required syntax or if the value obtained is not
2959 of the subtype Num.
2960
2961 @begin{Example}@Keepnext
2962 @key[procedure] Put(File : @key[in] File_Type;
2963 Item : @key[in] Num;
2964 Fore : @key[in] Field := Default_Fore;
2965 Aft : @key[in] Field := Default_Aft;
2966 Exp : @key[in] Field := Default_Exp);
2967 @comment{Blank Line}
2968 @key[procedure] Put(Item : @key[in] Num;
2969 Fore : @key[in] Field := Default_Fore;
2970 Aft : @key[in] Field := Default_Aft;
2971 Exp : @key[in] Field := Default_Exp);
2972 @end{Example}
2973 Outputs the value of the parameter Item as a decimal literal
2974 with the format defined by Fore, Aft and Exp. If the value is
2975 negative, or if Num is a floating point type where Num'Signed_Zeros is True and
2976 the value is a negatively signed zero, then
2977 a minus sign is included in the integer part.
2978 If Exp has the value zero, then the integer part to be output has
2979 as many digits as are needed to represent the integer part of
2980 the value of Item, overriding Fore if necessary, or consists
2981 of the digit zero if the value of Item has no integer part.
2982
2983 If Exp has a value greater than zero, then the integer part to
2984 be output has a single digit, which is nonzero except for the
2985 value 0.0 of Item.
2986
2987 In both cases, however, if the integer part to be output has
2988 fewer than Fore characters, including any minus sign, then
2989 leading spaces are first output to make up the difference.
2990 The number of digits of the fractional part is given by Aft,
2991 or is one if Aft equals zero.
2992 The value is rounded; a value of exactly one half in the last place
2993 is rounded away from zero.
2994
2995 @Trailing@;If Exp has the value zero, there is no exponent part. If Exp
2996 has a value greater than zero, then the exponent part to be
2997 output has as many digits as are needed to represent the
2998 exponent part of the value of Item (for which a single digit
2999 integer part is used), and includes an initial sign (plus or
3000 minus). If the exponent part to be output has fewer than Exp
3001 characters, including the sign, then leading zeros precede the
3002 digits, to make up the difference. For the value 0.0 of Item,
3003 the exponent has the value zero.
3004
3005 @begin{Example}@Keepnext
3006 @key[procedure] Get(From : @key[in] String; Item : @key[out] Num; Last : @key[out] Positive);
3007 @end{Example}
3008 Reads a real value from the beginning of the given string,
3009 following the same rule as the Get procedure that reads a real
3010 value from a file, but treating the end of the string as a
3011 file terminator. Returns, in the parameter Item, the value of
3012 type Num that corresponds to the sequence input. Returns in
3013 Last the index value such that From(Last) is the last
3014 character read.
3015
3016 @Trailing@;The exception Data_Error is propagated if the sequence input does
3017 not have the required syntax, or if the value obtained is not
3018 of the subtype Num.
3019
3020 @begin{Example}@Keepnext
3021 @key[procedure] Put(To : @key[out] String;
3022 Item : @key[in] Num;
3023 Aft : @key[in] Field := Default_Aft;
3024 Exp : @key[in] Field := Default_Exp);
3025 @end{Example}
3026 @Trailing@;Outputs the value of the parameter Item to the given string,
3027 following the same rule as for output to a file, using a value
3028 for Fore such that the sequence of characters output exactly
3029 fills the string, including any leading spaces.
3030 @end{DescribeCode}
3031
3032
3033 @Leading@;Float_Text_IO is a library package that is a nongeneric equivalent
3034 to Text_IO.Float_IO for the predefined type Float:
3035 @begin{Example}
3036 @key[with] Ada.Text_IO;@ChildUnit{Parent=[Ada],Child=[Float_@!Text_IO]}
3037 @key[package] Ada.Float_Text_IO @key[is] @key[new] Ada.Text_IO.Float_IO(Float);
3038 @end{Example}
3039
3040 For each predefined floating point type,
3041 a nongeneric equivalent to Text_IO.Float_IO is provided,
3042 with names such as Ada.Long_Float_Text_IO.
3043
3044
3045 @end{StaticSem}
3046
3047 @begin{ImplPerm}
3048
3049 An implementation may extend Get @Redundant[and Put] for floating point
3050 types to support special values such as infinities and NaNs.
3051
3052 @begin{Discussion}
3053 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
3054 See also the similar permission for the @Chg{Version=[3],New=[Wide_Wide_Value, ],Old=[]}
3055 Wide_Value@Chg{Version=[3],New=[, and Value attributes],Old=[attribute]}
3056 in @RefSecNum{Scalar Types}.
3057 @end{Discussion}
3058
3059
3060 The implementation of Put need not produce an output value with greater
3061 accuracy than is supported for the base subtype.
3062 The additional accuracy, if any,
3063 of the value produced by Put when the number of
3064 requested digits in the integer and fractional parts exceeds
3065 the required accuracy
3066 is implementation defined.
3067 @begin{Discussion}
3068 The required accuracy is thus Num'Base'Digits digits if Num is
3069 a floating point subtype.
3070 For a fixed point subtype the required accuracy is a function
3071 of the subtype's Fore, Aft, and Delta attributes.
3072 @end{Discussion}
3073
3074 @ImplDef{The accuracy of the value produced by Put.}
3075
3076
3077 The nongeneric equivalent packages may, but need not,
3078 be actual instantiations of the generic package for the appropriate
3079 predefined type.
3080
3081 @end{ImplPerm}
3082
3083 @begin{Notes}
3084 For an item with a positive value, if output to a string exactly fills
3085 the string without leading spaces, then output of the corresponding
3086 negative value will propagate Layout_Error.
3087
3088 The rules for the Value attribute
3089 (see @RefSecNum(Scalar Types)) and the rules for Get are based on the
3090 same set of formats.
3091 @end{Notes}
3092
3093 @begin{Examples}
3094 @begin{Example}
3095 @ChgRef{Version=[1], Kind=[Deleted]}
3096 @ChgDeleted[Version=[1],Text=<@ @;@comment{Empty paragraph to hang junk paragraph number from original RM}>]
3097
3098 @key[package] Real_IO @key[is] @key[new] Float_IO(Real); @key[use] Real_IO;
3099 --@RI{ default format used at instantiation, Default_Exp = 3}
3100
3101 X : Real := -123.4567; --@RI{ digits 8 (see @RefSecNum{Floating Point Types})}
3102
3103 @tabclear()@tabset(P50)
3104 Put(X); @RI[-- default format] @\@RI["@en@|1.2345670E+02"]
3105 Put(X, Fore => 5, Aft => 3, Exp => 2); @\@RI[-- "bbb@en@|1.235E+2"]
3106 Put(X, 5, 3, 0); @\@RI[-- "b@en@|123.457"]
3107 @end{Example}
3108 @end{Examples}
3109
3110 @LabeledSubClause{Input-Output for Enumeration Types}
3111
3112 @begin{StaticSem}
3113 The following procedures are defined in the generic package
3114 Enumeration_IO, which has to be instantiated for the appropriate
3115 enumeration type (indicated by Enum in the specification).
3116
3117 Values are output using either upper or lower case letters for
3118 identifiers. This is specified by the parameter Set, which is of the
3119 enumeration type Type_Set.
3120
3121 @begin{Example}
3122 @Trailing@key[type] Type_Set @key[is] (Lower_Case, Upper_Case);
3123 @end{Example}
3124
3125 @Leading@;The format (which includes any trailing spaces) can be specified
3126 by an optional field width parameter. The default field width and letter case
3127 are defined by the following variables that are declared in the generic
3128 package Enumeration_IO:
3129
3130 @begin{Example}
3131 @Trailing@;Default_Width : Field := 0;
3132 Default_Setting : Type_Set := Upper_Case;
3133 @end{Example}
3134
3135 @Leading@Keepnext@;The following procedures are provided:
3136 @begin{DescribeCode}
3137 @begin{Example}@Keepnext
3138 @key[procedure] Get(File : @key[in] File_Type; Item : @key[out] Enum);
3139 @key[procedure] Get(Item : @key[out] Enum);
3140 @end{Example}
3141 After skipping any leading blanks, line terminators, or page
3142 terminators, reads an identifier according to the syntax of
3143 this lexical element (lower and upper case being considered
3144 equivalent), or a character literal according to the syntax of
3145 this lexical element (including the apostrophes). Returns, in
3146 the parameter Item, the value of type Enum that corresponds to
3147 the sequence input.
3148
3149 @Trailing@;The exception Data_Error is propagated if the sequence input does
3150 not have the required syntax, or if the identifier or
3151 character literal does not correspond to a value of the
3152 subtype Enum.
3153
3154 @begin{Example}@Keepnext
3155 @key[procedure] Put(File : @key[in] File_Type;
3156 Item : @key[in] Enum;
3157 Width : @key[in] Field := Default_Width;
3158 Set : @key[in] Type_Set := Default_Setting);
3159 @comment{Blank Line}
3160 @key[procedure] Put(Item : @key[in] Enum;
3161 Width : @key[in] Field := Default_Width;
3162 Set : @key[in] Type_Set := Default_Setting);
3163 @end{Example}
3164 @Trailing@;Outputs the value of the parameter Item as an enumeration
3165 literal (either an identifier or a character literal). The
3166 optional parameter Set indicates whether lower case or upper
3167 case is used for identifiers; it has no effect for character
3168 literals. If the sequence of characters produced has fewer
3169 than Width characters, then trailing spaces are finally output
3170 to make up the difference. If Enum is a character type,
3171 the sequence of characters produced is as for
3172 Enum'Image(Item), as modified by the Width
3173 and Set parameters.
3174 @begin{Discussion}
3175 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
3176 For a character type, the literal might be a
3177 @Chg{Version=[3],New=[Wide_Wide_Character, ],Old=[]}Wide_Character@Chg{Version=[3],New=[,],Old=[]}
3178 or a control character.
3179 Whatever Image does for these things is appropriate here,
3180 too.
3181
3182 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0036-1]}
3183 @ChgAdded{Version=[3],Text=[The @ldquote@;characters produced@rdquote@;
3184 defines the @ldquote@;characters to be output@rdquote in the sense of
3185 @RefSecNum{Get and Put Procedures}, so a result that cannot fit on any bounded
3186 line will raise Layout_Error.]}
3187 @end{Discussion}
3188
3189 @begin{Example}@Keepnext
3190 @key[procedure] Get(From : @key[in] String; Item : @key[out] Enum; Last : @key[out] Positive);
3191 @end{Example}
3192 Reads an enumeration value from the beginning of the given
3193 string, following the same rule as the Get procedure that
3194 reads an enumeration value from a file, but treating the end
3195 of the string as a file terminator. Returns, in the parameter
3196 Item, the value of type Enum that corresponds to the sequence
3197 input. Returns in Last the index value such that From(Last)
3198 is the last character read.
3199
3200 @Trailing@;The exception Data_Error is propagated if the sequence input does
3201 not have the required syntax, or if the identifier or
3202 character literal does not correspond to a value of the
3203 subtype Enum.
3204 @begin{Honest}
3205 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
3206 For a character type, it is permissible for the implementation to make
3207 Get do the inverse of what Put does,
3208 in the case of wide@Chg{Version=[3],New=[ and wide_wide],Old=[]}
3209 @nt{character_literal}s and control characters.
3210 @end{Honest}
3211
3212 @begin{Example}@Keepnext
3213 @key[procedure] Put(To : @key[out] String;
3214 Item : @key[in] Enum;
3215 Set : @key[in] Type_Set := Default_Setting);
3216 @end{Example}
3217 @Trailing@;Outputs the value of the parameter Item to the given string,
3218 following the same rule as for output to a file, using the
3219 length of the given string as the value for Width.
3220 @end{DescribeCode}
3221
3222 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0054],ARef=[AI95-00007-01]}
3223 Although the specification of the generic package Enumeration_IO would allow
3224 instantiation for an @Chg{New=[integer],Old=[float]} type, this is not the
3225 intended purpose of this generic package, and the effect of such instantiations
3226 is not defined by the language.
3227 @end{StaticSem}
3228
3229 @begin{Notes}
3230 There is a difference between Put defined for characters, and for
3231 enumeration values. Thus
3232 @begin{Example}
3233 Ada.Text_IO.Put('A'); --@RI{ outputs the character A}
3234
3235 @key[package] Char_IO @key[is] @key[new] Ada.Text_IO.Enumeration_IO(Character);
3236 Char_IO.Put('A'); --@RI{ outputs the character 'A', between apostrophes}
3237 @end{Example}
3238
3239 The type Boolean is an enumeration type, hence Enumeration_IO can be
3240 instantiated for this type.
3241 @end{Notes}
3242
3243 @begin{DiffWord95}
3244 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0054],ARef=[AI95-00007-01]}
3245 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the wording to
3246 say Enumeration_IO can be instantiated with an integer type, not a float
3247 type.]}
3248 @end{DiffWord95}
3249
3250
3251 @LabeledAddedSubClause{Version=[2],Name=[Input-Output for Bounded Strings]}
3252
3253 @begin{Intro}
3254 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3255 @ChgAdded{Version=[2],Text=[The package Text_IO.Bounded_IO provides
3256 input-output in human-readable form for Bounded_Strings.]}
3257 @end{Intro}
3258
3259 @begin{StaticSem}
3260
3261 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3262 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The generic library
3263 package Text_IO.Bounded_IO has the following declaration:]}
3264
3265 @begin{Example}
3266 @ChgRef{Version=[2],Kind=[AddedNormal]}
3267 @ChgAdded{Version=[2],Text=[@key{with} Ada.Strings.Bounded;
3268 @key{generic}
3269 @key{with package} Bounded @key{is}
3270 @key{new} Ada.Strings.Bounded.Generic_Bounded_Length (<>);
3271 @key{package} Ada.Text_IO.Bounded_IO @key{is}@ChildUnit{Parent=[Ada.Text_IO],Child=[Bounded_IO]}]}
3272
3273 @ChgRef{Version=[2],Kind=[AddedNormal]}
3274 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Put}
3275 (File : @key{in} File_Type;
3276 Item : @key{in} Bounded.Bounded_String);]}
3277
3278 @ChgRef{Version=[2],Kind=[AddedNormal]}
3279 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Put}
3280 (Item : @key{in} Bounded.Bounded_String);]}
3281
3282 @ChgRef{Version=[2],Kind=[AddedNormal]}
3283 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Put_Line}
3284 (File : @key{in} File_Type;
3285 Item : @key{in} Bounded.Bounded_String);]}
3286
3287 @ChgRef{Version=[2],Kind=[AddedNormal]}
3288 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Put_Line}
3289 (Item : @key{in} Bounded.Bounded_String);]}
3290
3291 @ChgRef{Version=[2],Kind=[AddedNormal]}
3292 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Get_Line}
3293 (File : @key{in} File_Type)
3294 @key{return} Bounded.Bounded_String;]}
3295
3296 @ChgRef{Version=[2],Kind=[AddedNormal]}
3297 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Get_Line}
3298 @key{return} Bounded.Bounded_String;]}
3299
3300 @ChgRef{Version=[2],Kind=[AddedNormal]}
3301 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Get_Line}
3302 (File : @key{in} File_Type; Item : @key{out} Bounded.Bounded_String);]}
3303
3304 @ChgRef{Version=[2],Kind=[AddedNormal]}
3305 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Get_Line}
3306 (Item : @key{out} Bounded.Bounded_String);]}
3307
3308 @ChgRef{Version=[2],Kind=[AddedNormal]}
3309 @ChgAdded{Version=[2],Text=[@key{end} Ada.Text_IO.Bounded_IO;]}
3310 @end{Example}
3311
3312 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3313 @ChgAdded{Version=[2],Type=[Leading],Text=[For an item of type
3314 Bounded_String, the following subprograms are provided:]}
3315
3316 @begin{DescribeCode}
3317
3318 @begin{Example}
3319 @ChgRef{Version=[2],Kind=[AddedNormal]}
3320 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Put
3321 (File : @key{in} File_Type;
3322 Item : @key{in} Bounded.Bounded_String);]}
3323 @end{Example}
3324
3325 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3326 @ChgAdded{Version=[2],Text=[Equivalent to Text_IO.Put (File,
3327 Bounded.To_String(Item));]}
3328
3329 @begin{Example}
3330 @ChgRef{Version=[2],Kind=[AddedNormal]}
3331 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Put
3332 (Item : @key{in} Bounded.Bounded_String);]}
3333 @end{Example}
3334
3335 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3336 @ChgAdded{Version=[2],Text=[Equivalent to Text_IO.Put
3337 (Bounded.To_String(Item));]}
3338
3339 @begin{Example}
3340 @ChgRef{Version=[2],Kind=[AddedNormal]}
3341 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Put_Line
3342 (File : @key{in} File_Type;
3343 Item : @key{in} Bounded.Bounded_String);]}
3344 @end{Example}
3345
3346 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3347 @ChgAdded{Version=[2],Text=[Equivalent to Text_IO.Put_Line (File,
3348 Bounded.To_String(Item));]}
3349
3350 @begin{Example}
3351 @ChgRef{Version=[2],Kind=[AddedNormal]}
3352 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Put_Line
3353 (Item : @key{in} Bounded.Bounded_String);]}
3354 @end{Example}
3355
3356 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3357 @ChgAdded{Version=[2],Text=[Equivalent to Text_IO.Put_Line
3358 (Bounded.To_String(Item));]}
3359
3360 @begin{Example}
3361 @ChgRef{Version=[2],Kind=[AddedNormal]}
3362 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Get_Line
3363 (File : @key{in} File_Type)
3364 @key{return} Bounded.Bounded_String;]}
3365 @end{Example}
3366
3367 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3368 @ChgAdded{Version=[2],Text=[Returns
3369 Bounded.To_Bounded_String(Text_IO.Get_Line(File));]}
3370
3371 @begin{Example}
3372 @ChgRef{Version=[2],Kind=[AddedNormal]}
3373 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Get_Line
3374 @key{return} Bounded.Bounded_String;]}
3375 @end{Example}
3376
3377 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3378 @ChgAdded{Version=[2],Text=[Returns
3379 Bounded.To_Bounded_String(Text_IO.Get_Line);]}
3380
3381 @begin{Example}
3382 @ChgRef{Version=[2],Kind=[AddedNormal]}
3383 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Get_Line
3384 (File : @key{in} File_Type; Item : @key{out} Bounded.Bounded_String);]}
3385 @end{Example}
3386
3387 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3388 @ChgAdded{Version=[2],Text=[Equivalent to Item := Get_Line (File);]}
3389
3390 @begin{Example}
3391 @ChgRef{Version=[2],Kind=[AddedNormal]}
3392 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Get_Line
3393 (Item : @key{out} Bounded.Bounded_String);]}
3394 @end{Example}
3395
3396 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3397 @ChgAdded{Version=[2],Text=[Equivalent to Item := Get_Line;]}
3398 @end{DescribeCode}
3399 @end{StaticSem}
3400
3401 @begin{Extend95}
3402 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3403 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3404 Package Text_IO.Bounded_IO is new.]}
3405 @end{Extend95}
3406
3407
3408 @LabeledAddedSubClause{Version=[2],Name=[Input-Output for Unbounded Strings]}
3409
3410 @begin{Intro}
3411 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3412 @ChgAdded{Version=[2],Text=[The package Text_IO.Unbounded_IO provides
3413 input-output in human-readable form for Unbounded_Strings.]}
3414 @end{Intro}
3415
3416 @begin{StaticSem}
3417
3418 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3419 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The library package
3420 Text_IO.Unbounded_IO has the following declaration:]}
3421
3422 @begin{Example}
3423 @ChgRef{Version=[2],Kind=[AddedNormal]}
3424 @ChgAdded{Version=[2],Text=[@key{with} Ada.Strings.Unbounded;
3425 @key{package} Ada.Text_IO.Unbounded_IO @key{is}@ChildUnit{Parent=[Ada.Text_IO],Child=[Unbounded_IO]}]}
3426
3427 @ChgRef{Version=[2],Kind=[AddedNormal]}
3428 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Put}
3429 (File : @key{in} File_Type;
3430 Item : @key{in} Strings.Unbounded.Unbounded_String);]}
3431
3432 @ChgRef{Version=[2],Kind=[AddedNormal]}
3433 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Put}
3434 (Item : @key{in} Strings.Unbounded.Unbounded_String);]}
3435
3436 @ChgRef{Version=[2],Kind=[AddedNormal]}
3437 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Put_Line}
3438 (File : @key{in} File_Type;
3439 Item : @key{in} Strings.Unbounded.Unbounded_String);]}
3440
3441 @ChgRef{Version=[2],Kind=[AddedNormal]}
3442 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Put_Line}
3443 (Item : @key{in} Strings.Unbounded.Unbounded_String);]}
3444
3445 @ChgRef{Version=[2],Kind=[AddedNormal]}
3446 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Get_Line}
3447 (File : @key{in} File_Type)
3448 @key{return} Strings.Unbounded.Unbounded_String;]}
3449
3450 @ChgRef{Version=[2],Kind=[AddedNormal]}
3451 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Get_Line}
3452 @key{return} Strings.Unbounded.Unbounded_String;]}
3453
3454 @ChgRef{Version=[2],Kind=[AddedNormal]}
3455 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Get_Line}
3456 (File : @key{in} File_Type; Item : @key{out} Strings.Unbounded.Unbounded_String);]}
3457
3458 @ChgRef{Version=[2],Kind=[AddedNormal]}
3459 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Get_Line}
3460 (Item : @key{out} Strings.Unbounded.Unbounded_String);]}
3461
3462 @ChgRef{Version=[2],Kind=[AddedNormal]}
3463 @ChgAdded{Version=[2],Text=[@key{end} Ada.Text_IO.Unbounded_IO;]}
3464 @end{Example}
3465
3466 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3467 @ChgAdded{Version=[2],Type=[Leading],Text=[For an item of type
3468 Unbounded_String, the following subprograms are provided:]}
3469
3470 @begin{DescribeCode}
3471
3472 @begin{Example}
3473 @ChgRef{Version=[2],Kind=[AddedNormal]}
3474 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Put
3475 (File : @key{in} File_Type;
3476 Item : @key{in} Strings.Unbounded.Unbounded_String);]}
3477 @end{Example}
3478
3479 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3480 @ChgAdded{Version=[2],Text=[Equivalent to Text_IO.Put (File,
3481 Strings.Unbounded.To_String(Item));]}
3482
3483 @begin{Example}
3484 @ChgRef{Version=[2],Kind=[AddedNormal]}
3485 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Put
3486 (Item : @key{in} Strings.Unbounded.Unbounded_String);]}
3487 @end{Example}
3488
3489 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3490 @ChgAdded{Version=[2],Text=[Equivalent to Text_IO.Put
3491 (Strings.Unbounded.To_String(Item));]}
3492
3493 @begin{Example}
3494 @ChgRef{Version=[2],Kind=[AddedNormal]}
3495 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Put_Line
3496 (File : @key{in} File_Type;
3497 Item : @key{in} Strings.Unbounded.Unbounded_String);]}
3498 @end{Example}
3499
3500 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3501 @ChgAdded{Version=[2],Text=[Equivalent to Text_IO.Put_Line (File,
3502 Strings.Unbounded.To_String(Item));]}
3503
3504 @begin{Example}
3505 @ChgRef{Version=[2],Kind=[AddedNormal]}
3506 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Put_Line
3507 (Item : @key{in} Strings.Unbounded.Unbounded_String);]}
3508 @end{Example}
3509
3510 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3511 @ChgAdded{Version=[2],Text=[Equivalent to Text_IO.Put_Line
3512 (Strings.Unbounded.To_String(Item));]}
3513
3514 @begin{Example}
3515 @ChgRef{Version=[2],Kind=[AddedNormal]}
3516 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Get_Line
3517 (File : @key{in} File_Type)
3518 @key{return} Strings.Unbounded.Unbounded_String;]}
3519 @end{Example}
3520
3521 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3522 @ChgAdded{Version=[2],Text=[Returns
3523 Strings.Unbounded.To_Unbounded_String(Text_IO.Get_Line(File));]}
3524
3525 @begin{Example}
3526 @ChgRef{Version=[2],Kind=[AddedNormal]}
3527 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Get_Line
3528 @key{return} Strings.Unbounded.Unbounded_String;]}
3529 @end{Example}
3530
3531 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3532 @ChgAdded{Version=[2],Text=[Returns
3533 Strings.Unbounded.To_Unbounded_String(Text_IO.Get_Line);]}
3534
3535 @begin{Example}
3536 @ChgRef{Version=[2],Kind=[AddedNormal]}
3537 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Get_Line
3538 (File : @key{in} File_Type; Item : @key{out} Strings.Unbounded.Unbounded_String);]}
3539 @end{Example}
3540
3541 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3542 @ChgAdded{Version=[2],Text=[Equivalent to Item := Get_Line (File);]}
3543
3544 @begin{Example}
3545 @ChgRef{Version=[2],Kind=[AddedNormal]}
3546 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Get_Line
3547 (Item : @key{out} Strings.Unbounded.Unbounded_String);]}
3548 @end{Example}
3549
3550 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3551 @ChgAdded{Version=[2],Text=[Equivalent to Item := Get_Line;]}
3552 @end{DescribeCode}
3553 @end{StaticSem}
3554
3555 @begin{Extend95}
3556 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3557 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3558 Package Text_IO.Unbounded_IO is new.]}
3559 @end{Extend95}
3560
3561
3562 @LabeledRevisedClause{Version=[1],New=[Wide Text Input-Output and Wide Wide Text Input-Output],Old=[Wide Text Input-Output]}
3563
3564 @begin{Intro}
3565 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
3566 The @Chg{Version=[2],New=[packages],Old=[package]} Wide_Text_IO
3567 @Chg{Version=[2],New=[and Wide_Wide_Text_IO provide],Old=[provides]} facilities
3568 for input and output in human-readable form. Each file is read or
3569 written sequentially, as a sequence of wide characters
3570 @Chg{Version=[2],New=[(or wide wide characters) ],Old=[]}grouped
3571 into lines, and as a sequence of lines grouped into pages.
3572 @end{Intro}
3573
3574 @begin{StaticSem}
3575 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01],ARef=[AI95-00301-01]}
3576 @ChildUnit{Parent=[Ada],Child=[Wide_@!Text_IO]}
3577 The specification of package Wide_Text_IO is the same as that for
3578 Text_IO, except that in each Get,
3579 Look_Ahead, Get_Immediate,
3580 Get_Line, Put, and Put_Line @Chg{Version=[2],New=[subprogram],Old=[procedure]},
3581 any occurrence of Character is replaced by Wide_Character, and any
3582 occurrence of String is replaced by Wide_String.@Chg{Version=[2],New=[
3583 @ChildUnit{Parent=[Ada],Child=[Integer_@!Wide_@!Text_IO]}
3584 @ChildUnit{Parent=[Ada],Child=[Float_@!Wide_@!Text_IO]}
3585 Nongeneric equivalents of Wide_Text_IO.Integer_IO
3586 and Wide_Text_IO.@!Float_IO are provided (as for Text_IO)
3587 for each predefined numeric type,
3588 with names such as Ada.Integer_@!Wide_Text_IO,
3589 Ada.Long_@!Integer_@!Wide_Text_IO,
3590 Ada.Float_@!Wide_Text_IO,
3591 Ada.Long_@!Float_@!Wide_Text_IO.],Old=[]}
3592
3593 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01],ARef=[AI95-00301-01]}
3594 @Chg{Version=[2],New=[
3595 @ChildUnit{Parent=[Ada],Child=[Wide_Wide_@!Text_IO]}
3596 The specification of package Wide_Wide_Text_IO is the same as that for
3597 Text_IO, except that in each Get,
3598 Look_Ahead, Get_Immediate,
3599 Get_Line, Put, and Put_Line subprogram,
3600 any occurrence of Character is replaced by Wide_Wide_Character, and any
3601 occurrence of String is replaced by Wide_Wide_String.
3602 @ChildUnit{Parent=[Ada],Child=[Integer_@!Wide_Wide_@!Text_IO]}
3603 @ChildUnit{Parent=[Ada],Child=[Float_@!Wide_Wide_@!Text_IO]}
3604 Nongeneric equivalents of Wide_Wide_Text_IO.Integer_IO
3605 and Wide_Wide_@!Text_IO.@!Float_IO are provided (as for Text_IO)
3606 for each predefined numeric type,
3607 with names such as Ada.Integer_@!Wide_Wide_@!Text_IO,
3608 Ada.Long_@!Integer_@!Wide_Wide_@!Text_IO,
3609 Ada.Float_@!Wide_Wide_@!Text_IO,
3610 Ada.Long_@!Float_@!Wide_Wide_@!Text_IO.],
3611 Old=[
3612 @ChildUnit{Parent=[Ada],Child=[Integer_@!Wide_@!Text_IO]}
3613 @ChildUnit{Parent=[Ada],Child=[Float_@!Wide_@!Text_IO]}
3614 Nongeneric equivalents of Wide_Text_IO.Integer_IO
3615 and Wide_Text_IO.@!Float_IO are provided (as for Text_IO)
3616 for each predefined numeric type,
3617 with names such as Ada.Integer_@!Wide_Text_IO,
3618 Ada.Long_@!Integer_@!Wide_Text_IO,
3619 Ada.Float_@!Wide_Text_IO,
3620 Ada.Long_@!Float_@!Wide_Text_IO.]}
3621
3622 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01],ARef=[AI95-00428-01]}
3623 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0004-1],ARef=[AI05-0092-1]}
3624 @ChgAdded{Version=[2],Text=[
3625 @ChildUnit{Parent=[Ada.Wide_@!Text_IO],Child=[Wide_Bounded_IO]}
3626 @ChildUnit{Parent=[Ada.Wide_Wide_@!Text_IO],Child=[Wide_Wide_Bounded_IO]}
3627 The specification of package Wide_Text_IO.Wide_@!Bounded_IO is the same as that
3628 for Text_IO.Bounded_IO, except that any occurrence of Bounded_String is
3629 replaced by @Chg{Version=[3],New=[Bounded_@!Wide_@!String],Old=[Wide_@!Bounded_@!String]},
3630 and any occurrence of package Bounded is
3631 replaced by Wide_Bounded. The specification of package
3632 @Chg{Version=[3],New=[Wide_Wide_@!Text_IO.Wide_Wide_@!Bounded_IO],
3633 Old=[Wide_Wide_@!Text_IO.Wide_@!Bounded_IO]} is the same as that for
3634 Text_IO.@!Bounded_IO, except that any occurrence of Bounded_@!String is
3635 replaced by @Chg{Version=[3],New=[Bounded_@!Wide_Wide_@!String],
3636 Old=[Wide_Wide_@!Bounded_@!String]}, and any occurrence of package Bounded
3637 is replaced by Wide_Wide_@!Bounded.]}
3638
3639 @begin{Honest}
3640 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
3641 @ChgAdded{Version=[3],Text=[@ldquote@;package Bounded@rdquote refers
3642 to both the package Ada.Strings.Bounded and the formal package
3643 parameter named Bounded.]}
3644 @end{Honest}
3645
3646 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01],ARef=[AI95-00301-01]}
3647 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0092-1]}
3648 @ChgAdded{Version=[2],Text=[
3649 @ChildUnit{Parent=[Ada.Wide_@!Text_IO],Child=[Wide_Unbounded_IO]}
3650 @ChildUnit{Parent=[Ada.Wide_Wide_@!Text_IO],Child=[Wide_Wide_Unbounded_IO]}
3651 The specification of package Wide_Text_IO.@!Wide_Unbounded_IO is the same as that
3652 for Text_IO.@!Unbounded_IO, except that any occurrence of Unbounded_@!String is
3653 replaced by @Chg{Version=[3],New=[Unbounded_@!Wide_@!String],Old=[Wide_@!Unbounded_@!String]},
3654 and any occurrence of package Unbounded is
3655 replaced by Wide_@!Unbounded. The specification of package
3656 Wide_Wide_Text_IO.Wide_Wide_@!Unbounded_IO is the same as that for
3657 Text_IO.Unbounded_IO, except that any occurrence of Unbounded_String is
3658 replaced by @Chg{Version=[3],New=[Unbounded_@!Wide_Wide_@!String],
3659 Old=[Wide_Wide_@!Unbounded_@!String]}, and any occurrence of package Unbounded
3660 is replaced by Wide_Wide_@!Unbounded.]}
3661 @end{StaticSem}
3662
3663 @begin{Extend83}
3664 @Defn{extensions to Ada 83}
3665 Support for Wide_Character and Wide_String I/O is new in Ada 95.
3666 @end{Extend83}
3667
3668 @begin{Extend95}
3669 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
3670 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3671 Package Wide_Wide_Text_IO is new. Be glad it wasn't called
3672 Double_Wide_Text_IO (for use in trailer parks) or Really_Wide_Text_IO.]}
3673
3674 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00301-01]}
3675 @ChgAdded{Version=[2],Text=[Packages
3676 Wide_Text_IO.Wide_Unbounded_IO and
3677 Wide_Wide_Text_IO.Wide_Wide_Unbounded_IO are also new.]}
3678
3679 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00428-01]}
3680 @ChgAdded{Version=[2],Text=[Packages
3681 Wide_Text_IO.Wide_Bounded_IO and
3682 Wide_Wide_Text_IO.Wide_Wide_Bounded_IO are new as well.]}
3683 @end{Extend95}
3684
3685
3686 @begin{DiffWord2005}
3687 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0092-1]}
3688 @ChgAdded{Version=[3],Text=[@B<Correction>: Corrected the names of
3689 various entities in the above description. Since the previously named
3690 entities don't exist and the intent is obvious, this is just considered
3691 a presentation change.]}
3692 @end{DiffWord2005}
3693
3694
3695 @LabeledClause{Stream Input-Output}
3696 @begin{Intro}
3697
3698 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
3699 The packages Streams.Stream_IO, Text_IO.Text_Streams, @Chg{Version=[2],
3700 New=[],Old=[and ]}Wide_Text_IO.Text_Streams@Chg{Version=[2],New=[, and
3701 Wide_Wide_Text_IO.Text_Streams],Old=[]} provide stream-oriented operations
3702 on files.
3703 @end{Intro}
3704
3705 @begin{Diffword95}
3706 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
3707 @ChgAdded{Version=[2],Text=[Included package Wide_Wide_Text_IO.Text_Streams
3708 in this description.]}
3709 @end{Diffword95}
3710
3711
3712 @LabeledSubClause{The Package Streams.Stream_IO}
3713
3714 @begin{Intro}
3715 @Defn{heterogeneous input-output}
3716 @Redundant[The subprograms in the child package Streams.Stream_IO provide control
3717 over stream files. Access to a stream file is either sequential,
3718 via a call on Read or Write to transfer an array of stream elements,
3719 or positional (if supported by the implementation for the given file),
3720 by specifying a relative index for an element. Since a stream
3721 file can be converted to a Stream_Access value, calling stream-oriented
3722 attribute subprograms of different element types with the same
3723 Stream_Access value provides heterogeneous input-output.]
3724 See @RefSecNum{Streams} for a general discussion of streams.
3725 @end{Intro}
3726
3727 @begin{StaticSem}
3728 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
3729 @ChgAdded{Version=[1],Text=[The elements of a stream file are stream elements.
3730 If positioning is
3731 supported for the specified external file, a current index and current size
3732 are maintained for the file as described in @RefSecNum(Sequential and Direct Files).
3733 If positioning is not supported, a current index is not maintained, and the
3734 current size is implementation defined.@Defn2{Term=(Current index),
3735 Sec=(of an open stream file)}@Defn2{Term=(Current size),Sec=(of a stream file)}]}
3736 @ChgImpldef{Version=[1],Kind=[Added],Text=[@ChgAdded{Version=[1],
3737 Text=[Current size for a stream file for which positioning is not supported.]}]}
3738
3739 @Leading@;The library package Streams.Stream_IO has the following declaration:
3740 @begin(example)
3741 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0283-1]}
3742 @key(with) Ada.IO_Exceptions;@ChildUnit{Parent=[Ada.Streams],Child=[Stream_@!IO]}
3743 @key(package) Ada.Streams.Stream_IO @key(is)@Chg{Version=[3],New=[
3744 @key(pragma) Preelaborate(Stream_IO);],Old=[]}
3745
3746 @key[type] @AdaTypeDefn{Stream_Access} @key[is] @key[access] @key[all] Root_Stream_Type'Class;
3747
3748 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0102-1]}
3749 @key(type) @AdaTypeDefn{File_Type} @key(is) @key(limited) @key(private);@Chg{Version=[4],New=[
3750 @key(pragma) Preelaborable_Initialization(File_Type);],Old=[]}
3751
3752 @key(type) @AdaTypeDefn{File_Mode} @key(is) (In_File, Out_File, Append_File);
3753
3754 @key[type] @AdaTypeDefn{Count} @key[is] @key[range] 0 .. @RI[implementation-defined];
3755 @key[subtype] @AdaSubtypeDefn{Name=[Positive_Count],Of=[Count]} @key[is] Count @key[range] 1 .. Count'Last;
3756 -- @RI(Index into file, in stream elements.)
3757
3758 @key(procedure) @AdaSubDefn{Create} (File : @key(in) @key(out) File_Type;
3759 Mode : @key(in) File_Mode := Out_File;
3760 Name : @key(in) String := "";
3761 Form : @key(in) String := "");
3762
3763 @key(procedure) @AdaSubDefn{Open} (File : @key(in) @key(out) File_Type;
3764 Mode : @key(in) File_Mode;
3765 Name : @key(in) String;
3766 Form : @key(in) String := "");
3767
3768 @key(procedure) @AdaSubDefn{Close} (File : @key(in) @key(out) File_Type);
3769 @key(procedure) @AdaSubDefn{Delete} (File : @key(in) @key(out) File_Type);
3770 @key(procedure) @AdaSubDefn{Reset} (File : @key(in) @key(out) File_Type; Mode : @key(in) File_Mode);
3771 @key(procedure) @AdaSubDefn{Reset} (File : @key(in) @key(out) File_Type);
3772
3773 @key(function) @AdaSubDefn{Mode} (File : @key(in) File_Type) @key(return) File_Mode;
3774 @key(function) @AdaSubDefn{Name} (File : @key(in) File_Type) @key(return) String;
3775 @key(function) @AdaSubDefn{Form} (File : @key(in) File_Type) @key(return) String;
3776
3777 @key(function) @AdaSubDefn{Is_Open} (File : @key(in) File_Type) @key(return) Boolean;
3778 @key(function) @AdaSubDefn{End_Of_File} (File : @key(in) File_Type) @key(return) Boolean;
3779
3780 @key(function) @AdaSubDefn{Stream} (File : @key(in) File_Type) @key(return) Stream_Access;
3781 -- @RI(Return stream access for use with T'Input and T'Output)
3782
3783 @ChgRef{Version=[1], Kind=[Deleted]}
3784 @ChgDeleted[Version=[1],Text=<@ @;@comment{Empty paragraph to hang junk paragraph number from original RM}>]
3785
3786 -- @RI(Read array of stream elements from file)
3787 @key(procedure) @AdaSubDefn{Read} (File : @key(in) File_Type;
3788 Item : @key(out) Stream_Element_Array;
3789 Last : @key(out) Stream_Element_Offset;
3790 From : @key(in) Positive_Count);
3791
3792 @key(procedure) @AdaSubDefn{Read} (File : @key(in) File_Type;
3793 Item : @key(out) Stream_Element_Array;
3794 Last : @key(out) Stream_Element_Offset);
3795
3796 @ChgRef{Version=[1], Kind=[Deleted]}
3797 @ChgDeleted[Version=[1],Text=<@ @;@comment{Empty paragraph to hang junk paragraph number from original RM}>]
3798
3799 -- @RI(Write array of stream elements into file)
3800 @key(procedure) @AdaSubDefn{Write} (File : @key(in) File_Type;
3801 Item : @key(in) Stream_Element_Array;
3802 To : @key(in) Positive_Count);
3803
3804 @key(procedure) @AdaSubDefn{Write} (File : @key(in) File_Type;
3805 Item : @key(in) Stream_Element_Array);
3806
3807 @ChgRef{Version=[1], Kind=[Deleted]}
3808 @ChgDeleted[Version=[1],Text=<@ @;@comment{Empty paragraph to hang junk paragraph number from original RM}>]
3809
3810 -- @RI(Operations on position within file)
3811
3812 @key[procedure] @AdaSubDefn{Set_Index}(File : @key[in] File_Type; To : @key[in] Positive_Count);
3813
3814 @key[function] @AdaSubDefn{Index}(File : @key[in] File_Type) @key[return] Positive_Count;
3815 @key[function] @AdaSubDefn{Size} (File : @key[in] File_Type) @key[return] Count;
3816
3817 @key(procedure) @AdaSubDefn{Set_Mode}(File : @key(in) @key(out) File_Type; Mode : @key(in) File_Mode);
3818
3819 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0051],ARef=[AI95-00057-01]}
3820 @key(procedure) @AdaSubDefn{Flush}(File : @key(in) @Chg{New=[],Old=[@key(out) ]}File_Type);
3821
3822
3823 -- @RI(exceptions)
3824 @AdaExcDefn{Status_Error} : @key(exception) @key(renames) IO_Exceptions.Status_Error;
3825 @AdaExcDefn{Mode_Error} : @key(exception) @key(renames) IO_Exceptions.Mode_Error;
3826 @AdaExcDefn{Name_Error} : @key(exception) @key(renames) IO_Exceptions.Name_Error;
3827 @AdaExcDefn{Use_Error} : @key(exception) @key(renames) IO_Exceptions.Use_Error;
3828 @AdaExcDefn{Device_Error} : @key(exception) @key(renames) IO_Exceptions.Device_Error;
3829 @AdaExcDefn{End_Error} : @key(exception) @key(renames) IO_Exceptions.End_Error;
3830 @AdaExcDefn{Data_Error} : @key(exception) @key(renames) IO_Exceptions.Data_Error;
3831
3832 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
3833 @ChgAdded{Version=[5],Text=[ @key[package] @AdaPackDefn{Wide_File_Names} @key[is]]}
3834
3835 @ChgRef{Version=[5],Kind=[Added]}
3836 @ChgAdded{Version=[5],Text=[ -- @examcom{File management}]}
3837
3838 @ChgRef{Version=[5],Kind=[Added]}
3839 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Create} (File : @key[in out] File_Type;
3840 Mode : @key[in] File_Mode := Out_File;
3841 Name : @key[in] Wide_String := "";
3842 Form : @key[in] Wide_String := "");]}
3843
3844 @ChgRef{Version=[5],Kind=[Added]}
3845 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Open} (File : @key[in out] File_Type;
3846 Mode : @key[in] File_Mode;
3847 Name : @key[in] Wide_String;
3848 Form : @key[in] Wide_String := "");]}
3849
3850 @ChgRef{Version=[5],Kind=[Added]}
3851 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] Wide_String;]}
3852
3853 @ChgRef{Version=[5],Kind=[Added]}
3854 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] Wide_String;]}
3855
3856 @ChgRef{Version=[5],Kind=[Added]}
3857 @ChgAdded{Version=[5],Text=[ @key[end] Wide_File_Names;]}
3858
3859
3860 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0021-1]}
3861 @ChgAdded{Version=[5],Text=[ @key[package] @AdaPackDefn{Wide_Wide_File_Names} @key[is]]}
3862
3863 @ChgRef{Version=[5],Kind=[Added]}
3864 @ChgAdded{Version=[5],Text=[ -- @examcom{File management}]}
3865
3866 @ChgRef{Version=[5],Kind=[Added]}
3867 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Create} (File : @key[in out] File_Type;
3868 Mode : @key[in] File_Mode := Out_File;
3869 Name : @key[in] Wide_Wide_String := "";
3870 Form : @key[in] Wide_Wide_String := "");]}
3871
3872 @ChgRef{Version=[5],Kind=[Added]}
3873 @ChgAdded{Version=[5],Text=[ @key[procedure] @AdaSubDefn{Open} (File : @key[in out] File_Type;
3874 Mode : @key[in] File_Mode;
3875 Name : @key[in] Wide_Wide_String;
3876 Form : @key[in] Wide_Wide_String := "");]}
3877
3878 @ChgRef{Version=[5],Kind=[Added]}
3879 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Name} (File : @key[in] File_Type) @key[return] Wide_Wide_String;]}
3880
3881 @ChgRef{Version=[5],Kind=[Added]}
3882 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Form} (File : @key[in] File_Type) @key[return] Wide_Wide_String;]}
3883
3884 @ChgRef{Version=[5],Kind=[Added]}
3885 @ChgAdded{Version=[5],Text=[ @key[end] Wide_Wide_File_Names;]}
3886
3887 @key[private]
3888 ... -- @RI{not specified by the language}
3889 @key(end) Ada.Streams.Stream_IO;
3890 @end(example)
3891
3892 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00360-01]}
3893 @ChgAdded{Version=[2],Text=[The type File_Type
3894 needs finalization@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}
3895 (see @RefSecNum{Assignment and Finalization}).]}
3896
3897 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00283-01]}
3898 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0130-1]}
3899 The subprograms @Chg{Version=[2],New=[given in subclause
3900 @RefSecNum(File Management) for the control of external files (],Old=[]}Create,
3901 Open, Close, Delete, Reset, Mode, Name,
3902 Form,@Chg{Version=[2],New=[@Chg{Version=[4],New=[],Old=[ and]}],Old=[]}
3903 Is_Open@Chg{Version=[2],New=[@Chg{Version=[4],New=[, and Flush],Old=[]})
3904 are available for stream files],
3905 Old=[, and End_of_File have the same effect as the corresponding
3906 subprograms in Sequential_IO (see @RefSecNum(File Management))]}.
3907
3908 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00283-01]}
3909 @ChgAdded{Version=[2],Type=[Leading],Text=[The End_Of_File function:]}
3910 @begin{Itemize}
3911 @ChgRef{Version=[2],Kind=[Added]}
3912 @ChgAdded{Version=[2],Text=[Propagates Mode_Error if the mode of the file
3913 is not In_File;]}
3914
3915 @ChgRef{Version=[2],Kind=[Added]}
3916 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]}
3917 @ChgAdded{Version=[2],Text=[If positioning is supported for the given external
3918 file, the function returns True if the current index exceeds the size of the
3919 external file; otherwise@Chg{Version=[3],New=[,],Old=[]}
3920 it returns False;]}
3921
3922 @ChgRef{Version=[2],Kind=[Added]}
3923 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]}
3924 @ChgAdded{Version=[2],Text=[If positioning is not supported for the given
3925 external file, the function returns True if no more elements can be read from
3926 the given file; otherwise@Chg{Version=[3],New=[,],Old=[]}
3927 it returns False.]}
3928 @end{Itemize}
3929
3930 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
3931 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00085-01]}
3932 @ChgAdded{Version=[1],Text=[The Set_Mode
3933 procedure @Chg{Version=[2],New=[sets],Old=[changes]} the mode of the
3934 file. If the new mode is Append_File, the file is positioned to its end;
3935 otherwise, the position in the file is unchanged.]}
3936
3937 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
3938 @ChgRef{Version=[4],Kind=[DeletedAdded],ARef=[AI12-0130-1]}
3939 @ChgAdded{Version=[1],Text=[@Chg{Version=[4],New=[],Old=[The Flush procedure
3940 synchronizes the external file with the internal file (by flushing any internal
3941 buffers) without closing the file or changing the position. Mode_Error is
3942 propagated if the mode of the file is In_File.]}]}
3943
3944 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0056],ARef=[AI95-00001-01]}
3945 The Stream function returns a Stream_Access result from a File_Type
3946 object, thus allowing the stream-oriented attributes Read, Write,
3947 Input, and Output to be used on the same file for multiple types.
3948 @Chg{New=[Stream propagates Status_Error if File is not open.],Old=[]}
3949
3950 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00256-01]}
3951 The procedures Read and Write are equivalent to the corresponding operations
3952 in the package Streams. Read propagates Mode_Error if the mode of File is
3953 not In_File. Write propagates Mode_Error if the mode of File is not
3954 Out_File or Append_File. The Read procedure with a Positive_Count
3955 parameter starts reading at the specified index.
3956 The Write procedure with a Positive_Count
3957 parameter starts writing at the specified index.@Chg{Version=[2],New=[ For
3958 a file that supports positioning, Read without a Positive_Count parameter
3959 starts reading at the current index, and Write without a Positive_Count
3960 parameter starts writing at the current index.],Old=[]}
3961
3962 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
3963 @ChgAdded{Version=[1],Text=[The Size function returns the current size of the
3964 file.]}
3965
3966 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0055],ARef=[AI95-00026-01]}
3967 The Index function returns the current @Chg{New=[],Old=[file ]}index@Chg{New=[],
3968 Old=[, as a count (in stream elements) from the beginning of the file.
3969 The position of the first element in the file is 1]}.
3970 @begin{Ramification}
3971 @ChgRef{Version=[1],Kind=[Deleted]}
3972 @ChgNote{This ramification is now part of the official wording.}
3973 @ChgDeleted{Version=[1],Text=[The notion of Index for Stream_IO is analogous
3974 to that of Index in Direct_IO, except that the former is measured in
3975 Stream_Element units, whereas the latter is in terms of Element_Type values.]}
3976 @end{Ramification}
3977
3978 The Set_Index procedure sets the current index to the
3979 specified value.
3980
3981 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
3982 @ChgAdded{Version=[1],Type=[Leading],Text=[If positioning is supported for the
3983 external file, the current index is maintained as follows:]}
3984
3985 @begin{Itemize}
3986 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
3987 @ChgAdded{Version=[1],Text=[For Open and Create, if the Mode parameter is
3988 Append_File, the current index is set to the current size of the file plus one;
3989 otherwise, the current index is set to one.]}
3990
3991 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
3992 @ChgAdded{Version=[1],Text=[For Reset, if the Mode parameter is Append_File, or
3993 no Mode parameter is given and the current mode is Append_File, the current
3994 index is set to the current size of the file plus one; otherwise, the current
3995 index is set to one.]}
3996
3997 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
3998 @ChgAdded{Version=[1],Text=[For Set_Mode, if the new mode is Append_File, the
3999 current index is set to current size plus one; otherwise, the current index is
4000 unchanged.]}
4001
4002 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
4003 @ChgAdded{Version=[1],Text=[For Read and Write without a Positive_Count
4004 parameter, the current index is incremented by the number of stream elements
4005 read or written.]}
4006
4007 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0055],ARef=[AI95-00026-01]}
4008 @ChgAdded{Version=[1],Text=[For Read and Write with a Positive_Count parameter,
4009 the value of the current index is set to the value of the Positive_Count
4010 parameter plus the number of stream elements read or written.]}
4011 @end{Itemize}
4012
4013 If positioning is not supported for the given file, then a call
4014 of Index or Set_Index propagates Use_Error. Similarly, a call of
4015 Read or Write with a Positive_Count parameter propagates Use_Error.
4016
4017 @begin{ImplNote}
4018 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00085-01]}
4019 @ChgAdded{Version=[2],Text=[It is permissible for an implementation to
4020 implement mode Append_File using the Unix append mode (the
4021 O_APPEND bit). Such an implementation does not support positioning when
4022 the mode is Append_File, and therefore the operations listed above must
4023 raise Use_Error. This is acceptable as there is no requirement that any
4024 particular file support positioning; therefore it is acceptable that a
4025 file support positioning when opened with mode Out_File, and the same file
4026 not support positioning when opened with mode Append_File. But it is not
4027 acceptable for a file to support positioning (by allowing the above
4028 operations), but to do something other than the defined semantics (that is,
4029 always write at the end, even when explicitly commanded to write somewhere
4030 else).]}
4031 @end{ImplNote}
4032
4033 @begin{NotIso}
4034 @ChgAdded{Version=[2],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 34 through 36
4035 were deleted.>}]}@Comment{This message should be
4036 deleted if the paragraphs are ever renumbered.}
4037 @end{NotIso}
4038 @ChgRef{Version=[1],Kind=[DeletedNoDelMsg],Ref=[8652/0055],ARef=[AI95-00026-01]}
4039 @ChgDeleted{Version=[1],Text=[The Size function returns the current size of
4040 the file, in stream elements.]}
4041
4042 @ChgRef{Version=[1],Kind=[DeletedNoDelMsg],Ref=[8652/0055],ARef=[AI95-00026-01]}
4043 @ChgDeleted{Version=[1],Text=[The Set_Mode procedure changes the mode of the
4044 file. If the new mode is Append_File, the file is positioned to its end;
4045 otherwise, the position in the file is unchanged.]}
4046
4047 @ChgRef{Version=[1],Kind=[DeletedNoDelMsg],Ref=[8652/0055],ARef=[AI95-00026-01]}
4048 @ChgDeleted{Version=[1],Text=[The Flush procedure synchronizes the external
4049 file with the internal file (by flushing any internal buffers) without closing
4050 the file or changing the position.
4051 Mode_Error is propagated if the mode of the file is In_File.]}
4052 @end{StaticSem}
4053 @begin{Erron}
4054 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0056],ARef=[AI95-00001-01]}
4055 @ChgAdded{Version=[1],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}
4056 If the File_Type object passed to the Stream function is later
4057 closed or finalized, and the stream-oriented attributes are subsequently
4058 called (explicitly or implicitly) on the Stream_Access value returned by
4059 Stream, execution is erroneous. This rule applies even if the File_Type object
4060 was opened again after it had been closed.]}
4061 @begin{Reason}
4062 @ChgRef{Version=[1],Kind=[Added]}
4063 @ChgAdded{Version=[1],Text=[These rules are analogous to the rule for the result of the
4064 Current_Input, Current_Output, and Current_Error functions. These rules make
4065 it possible to represent a value of (some descendant of) Root_Stream_Type which
4066 represents a file as an access value, with a null value corresponding to a
4067 closed file.]}
4068 @end{Reason}
4069 @end{Erron}
4070
4071 @begin{Inconsistent95}
4072 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00283-01]}
4073 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
4074 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
4075 @b[Amendment Correction:] The description of the subprograms for
4076 managing files was corrected so that they do not require truncation of the
4077 external file @em a stream file is not a sequential file. An Ada 95
4078 program that expects truncation of the stream file
4079 @Chg{Version=[3],New=[might],Old=[may]} not work under Ada 2005.
4080 Note that the Ada 95 standard was ambiguous on this point (the normative
4081 wording seemed to require truncation, but didn't explain where; the
4082 AARM notes seemed to expect behavior like Direct_IO), and implementations
4083 varied widely. Therefore, as a practical matter, code that depends on
4084 stream truncation @Chg{Version=[3],New=[might],Old=[may]} not work
4085 even in Ada 95; deleting the file before
4086 opening it provides truncation that works in both Ada 95 and Ada 2005.]}
4087 @end{Inconsistent95}
4088
4089 @begin{Incompatible95}
4090 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00360-01]}
4091 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
4092 @B[Amendment Correction:] Stream_IO.File_Type is defined to need finalization. If the
4093 restriction No_Nested_Finalization (see @RefSecNum{Tasking Restrictions})
4094 applies to the partition, and File_Type does not have a controlled part, it
4095 will not be allowed in local objects in Ada 2005 whereas it would be allowed
4096 in original Ada 95. Such code is not portable, as another Ada compiler
4097 may have a controlled part in File_Type, and thus would be illegal.]}
4098 @end{Incompatible95}
4099
4100 @begin{DiffWord95}
4101 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0051],ARef=[AI95-00057-01]}
4102 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the parameter mode
4103 of Flush; otherwise it could not be used on Standard_Output.]}
4104
4105 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0055],ARef=[AI95-00026-01],ARef=[AI95-00256-01]}
4106 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to describe the
4107 effects of the various operations on the current index. The Amendment adds
4108 an explanation of the use of current index for Read and Write.]}
4109
4110 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0056],ARef=[AI95-00001-01]}
4111 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that Stream can
4112 raise Status_Error, and clarified that using a Stream_Access whose file
4113 has been closed is erroneous.]}
4114
4115 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00085-01]}
4116 @ChgAdded{Version=[2],Text=[Clarified that Set_Mode can
4117 be called with the current mode.]}
4118 @end{DiffWord95}
4119
4120 @begin{Extend2005}
4121 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0283-1]}
4122 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
4123 Package Ada.Streams.Stream_IO is now preelaborated, allowing it to be
4124 used in more contexts (including in distributed systems). Note that it
4125 is @i<not> a remote types package; File_Type objects cannot be
4126 passed between partitions.]}
4127 @end{Extend2005}
4128
4129 @begin{Incompatible2012}
4130 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0021-1]}
4131 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}
4132 The Wide_File_Names and Wide_Wide_File_Names
4133 nested packages are newly added to Ada.Streaam_IO.
4134 If an instance of Ada.Stream_IO is referenced in a @nt{use_clause}, and
4135 an entity with one of those names is defined in some other package that is
4136 also referenced in a @nt{use_clause}, the user-defined entity may no longer be
4137 use-visible, resulting in errors. This should be rare and is easily fixed if
4138 it does occur.]}
4139 @end{Incompatible2012}
4140
4141 @begin{Extend2012}
4142 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0102-1]}
4143 @ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}
4144 @b{Corrigendum:} Type Ada.Streams.Stream_IO.File_Type now has
4145 preelaborable initialization. This allows declaring library-level
4146 file objects in preelaborable packages (an oversight from the
4147 change above).]}
4148 @end{Extend2012}
4149
4150 @begin{Diffword2012}
4151 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0130-1]}
4152 @ChgAdded{Version=[4],Text=[@b{Corrigendum:} The definition of the Flush
4153 procedure was moved to @RefSecNum{File Management}, so that it could be
4154 shared by all of the I/O packages.]}
4155 @end{Diffword2012}
4156
4157
4158 @LabeledSubClause{The Package Text_IO.Text_Streams}
4159 @begin{Intro}
4160 The package Text_IO.Text_Streams provides a function for treating
4161 a text file as a stream.
4162 @end{Intro}
4163
4164 @begin{StaticSem}
4165 @Leading@;The library package Text_IO.Text_Streams has the following declaration:
4166 @begin{example}
4167 @key[with] Ada.Streams;@ChildUnit{Parent=[Ada.Text_IO],Child=[Text_@!Streams]}
4168 @key[package] Ada.Text_IO.Text_Streams @key[is]
4169 @key[type] @AdaTypeDefn{Stream_Access} @key[is] @key[access] @key[all] Streams.Root_Stream_Type'Class;
4170
4171 @key[function] @AdaSubDefn{Stream} (File : @key[in] File_Type) @key[return] Stream_Access;
4172 @key[end] Ada.Text_IO.Text_Streams;
4173 @end{example}
4174
4175 The Stream function has the same effect as the corresponding function
4176 in Streams.Stream_IO.
4177 @end{StaticSem}
4178 @begin[Notes]
4179 The ability to obtain a stream for a text file allows Current_Input,
4180 Current_Output, and Current_Error to be processed with the functionality
4181 of streams, including the mixing of text and binary input-output,
4182 and the mixing of binary input-output for different types.
4183
4184 Performing operations on the stream associated with a text file does not
4185 affect the column, line, or page counts.
4186 @end[Notes]
4187
4188
4189 @LabeledSubClause{The Package Wide_Text_IO.Text_Streams}
4190 @begin{Intro}
4191 The package Wide_Text_IO.Text_Streams provides a function for treating
4192 a wide text file as a stream.
4193 @end{Intro}
4194
4195 @begin{StaticSem}
4196 @Leading@;The library package Wide_Text_IO.Text_Streams
4197 has the following declaration:
4198 @begin{example}
4199 @key[with] Ada.Streams;@ChildUnit{Parent=[Ada.Wide_@!Text_IO],Child=[Text_@!Streams]}
4200 @key[package] Ada.Wide_Text_IO.Text_Streams @key[is]
4201 @key[type] @AdaTypeDefn{Stream_Access} @key[is] @key[access] @key[all] Streams.Root_Stream_Type'Class;
4202
4203 @key[function] @AdaSubDefn{Stream} (File : @key[in] File_Type) @key[return] Stream_Access;
4204 @key[end] Ada.Wide_Text_IO.Text_Streams;
4205 @end{example}
4206
4207 The Stream function has the same effect as the corresponding function
4208 in Streams.Stream_IO.
4209 @end{StaticSem}
4210
4211
4212 @LabeledAddedSubClause{Version=[2],Name=[The Package Wide_Wide_Text_IO.Text_Streams]}
4213
4214 @begin{Intro}
4215 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4216 @ChgAdded{Version=[2],Text=[The package Wide_Wide_Text_IO.Text_Streams provides
4217 a function for treating a wide wide text file as a stream.]}
4218 @end{Intro}
4219
4220 @begin{StaticSem}
4221 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4222 @ChgAdded{Version=[2],Type=[Leading],Text=[@Leading@;The library package
4223 Wide_Wide_Text_IO.Text_Streams has the following declaration:]}
4224 @begin{example}
4225 @ChgRef{Version=[2],Kind=[AddedNormal]}
4226 @ChgAdded{Version=[2],Text=[@key[with] Ada.Streams;@ChildUnit{Parent=[Ada.Wide_Wide_@!Text_IO],Child=[Text_@!Streams]}
4227 @key[package] Ada.Wide_Wide_Text_IO.Text_Streams @key[is]
4228 @key[type] @AdaTypeDefn{Stream_Access} @key[is] @key[access] @key[all] Streams.Root_Stream_Type'Class;]}
4229
4230 @ChgRef{Version=[2],Kind=[AddedNormal]}
4231 @ChgAdded{Version=[2],Text=[ @key[function] @AdaSubDefn{Stream} (File : @key[in] File_Type) @key[return] Stream_Access;
4232 @key[end] Ada.Wide_Wide_Text_IO.Text_Streams;]}
4233 @end{example}
4234
4235 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4236 @ChgAdded{Version=[2],Text=[The Stream function has the same effect as the
4237 corresponding function in Streams.Stream_IO.]}
4238 @end{StaticSem}
4239
4240 @begin{Extend95}
4241 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4242 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4243 Package Wide_Wide_Text_IO.Text_Streams is new.]}
4244 @end{Extend95}
4245
4246
4247 @LabeledClause{Exceptions in Input-Output}
4248 @begin{Intro}
4249 The package IO_Exceptions defines the exceptions needed by the
4250 predefined input-output packages.
4251 @end{Intro}
4252
4253 @begin{StaticSem}
4254 @Leading@;The library package IO_Exceptions has the following declaration:
4255 @begin{Example}
4256 @key[package] Ada.IO_Exceptions @key[is]@ChildUnit{Parent=[Ada],Child=[IO_Exceptions]}
4257 @key[pragma] Pure(IO_Exceptions);
4258
4259 @AdaExcDefn{Status_Error} : @key[exception];
4260 @AdaExcDefn{Mode_Error} : @key[exception];
4261 @AdaExcDefn{Name_Error} : @key[exception];
4262 @AdaExcDefn{Use_Error} : @key[exception];
4263 @AdaExcDefn{Device_Error} : @key[exception];
4264 @AdaExcDefn{End_Error} : @key[exception];
4265 @AdaExcDefn{Data_Error} : @key[exception];
4266 @AdaExcDefn{Layout_Error} : @key[exception];
4267
4268 @key[end] Ada.IO_Exceptions;
4269 @end{Example}
4270
4271 If more than one error condition exists, the corresponding exception
4272 that appears earliest in the following list is the one that is propagated.
4273
4274 The exception Status_Error is propagated by an attempt to operate upon a
4275 file that is not open, and by an attempt to open a file that is already
4276 open.
4277
4278 The exception Mode_Error is propagated by an attempt to read from, or test
4279 for the end of, a file whose current mode is Out_File or Append_File, and
4280 also by an
4281 attempt to write to a file whose current mode is In_File. In the case
4282 of Text_IO, the exception Mode_Error is also propagated by specifying a file
4283 whose current mode is Out_File or Append_File in a call of Set_Input, Skip_Line,
4284 End_Of_Line, Skip_Page, or End_Of_Page; and by specifying a file whose
4285 current mode is In_File in a call of Set_Output, Set_Line_Length,
4286 Set_Page_Length, Line_Length, Page_Length, New_Line, or New_Page.
4287
4288 The exception Name_Error is propagated by a call of Create or Open if the
4289 string given for the parameter Name does not allow the identification of
4290 an external file. For example, this exception is propagated if the string
4291 is improper, or, alternatively, if either none or more than one external
4292 file corresponds to the string.
4293
4294 The exception Use_Error is propagated if an operation is attempted that is
4295 not possible for reasons that depend on characteristics of the external
4296 file. For example, this exception is propagated by the procedure Create,
4297 among other circumstances, if the given mode is Out_File but the form
4298 specifies an input only device, if the parameter Form specifies invalid
4299 access rights, or if an external file with the given name already exists
4300 and overwriting is not allowed.
4301
4302 The exception Device_Error is propagated if an input-output operation cannot
4303 be completed because of a malfunction of the underlying system.
4304
4305 The exception End_Error is propagated by an attempt to skip (read past) the
4306 end of a file.
4307
4308 The exception Data_Error can be propagated by the
4309 procedure Read (or by the Read attribute) if the
4310 element read cannot be interpreted as a value of the required subtype.
4311 This exception is also propagated by a procedure Get (defined in the package
4312 Text_IO) if the input character sequence fails to satisfy the required
4313 syntax, or if the value input does not belong to the range of the
4314 required subtype.
4315
4316 The exception Layout_Error is propagated (in text input-output) by Col,
4317 Line, or Page if the value returned exceeds Count'Last. The exception
4318 Layout_Error is also propagated on output by an attempt to set column or
4319 line numbers in excess of specified maximum line or page lengths,
4320 respectively (excluding the unbounded cases). It is also propagated by an
4321 attempt to Put too many characters to a string.
4322
4323 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0262-1]}
4324 @ChgAdded{Version=[3],Text=[These exceptions are also propagated by various
4325 other language-defined packages and operations, see the definition of those
4326 entities for other reasons that these exceptions are propagated.]}
4327
4328 @begin{Reason}
4329 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0299-1]}
4330 @ChgAdded{Version=[3],Text=[This @Chg{Version=[3],New=[subclause],Old=[clause]}
4331 is based in Ada 95. Later versions of
4332 Ada (starting with Technical Corrigendum 1) have added a number of additional
4333 places and reasons that cause these exceptions. In particular, TC1 says that
4334 stream attributes need to raise End_Error in some circumstances; Amendment 1
4335 adds Ada.Directories and a number of new places and reasons that Name_Error and
4336 Use_Error are raised. There are more. We don't want to try to update this text
4337 (or even this note!) for every possible reason and place that might raise one
4338 of these exceptions, so we add this blanket statement.]}
4339 @end{Reason}
4340
4341 @end{StaticSem}
4342
4343
4344 @begin{DocReq}
4345 The implementation shall document the conditions under which
4346 Name_Error, Use_Error and Device_Error are propagated.
4347 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],Text=[
4348 The conditions under which Io_Exceptions.Name_Error, Io_Exceptions.Use_Error,
4349 and Io_Exceptions.Device_Error are propagated.]}]}
4350 @end{DocReq}
4351
4352
4353 @begin{ImplPerm}
4354 If the associated check is too complex, an implementation need
4355 not propagate Data_Error as part of a procedure Read
4356 (or the Read attribute) if the value read cannot be interpreted as a value
4357 of the required subtype.
4358 @begin{Ramification}
4359 An example where the implementation may choose not to
4360 perform the check is an enumeration type with a representation clause
4361 with @lquotes@;holes@rquotes@; in the range of internal codes.@end{ramification}
4362 @end{ImplPerm}
4363
4364 @begin{Erron}
4365 @PDefn2{Term=(erroneous execution),Sec=(cause)}@Redundant[If the element read
4366 by the procedure Read (or by the Read attribute)
4367 cannot be interpreted as a value of the required subtype,
4368 but this is not detected and Data_Error is not propagated,
4369 then the resulting value can be abnormal,
4370 and subsequent references to the value
4371 can lead to erroneous execution,
4372 as explained in @RefSecNum{Data Validity}.
4373 @PDefn{normal state of an object}
4374 @PDefn{abnormal state of an object}]
4375 @end{Erron}
4376
4377 @LabeledClause{File Sharing}
4378
4379 @begin{RunTime}
4380 @PDefn{unspecified}
4381 @Leading@;It is not specified by the language whether the same external file
4382 can be associated with more than one file object. If such sharing
4383 is supported by the implementation, the following effects are defined:
4384 @begin{itemize}
4385 Operations on one text file object do not affect the column,
4386 line, and page numbers of any other file object.
4387
4388 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0057],ARef=[AI95-00050-01]}
4389 @ChgDeleted{Version=[1],Text=[Standard_Input and Standard_Output are associated
4390 with distinct external files, so operations on one of these files cannot affect
4391 operations on the other file. In particular, reading from
4392 Standard_Input does not affect the current page, line, and column
4393 numbers for Standard_Output, nor does writing to Standard_Output
4394 affect the current page, line, and column numbers for Standard_Input.]}
4395
4396 For direct and stream files, the current index is a
4397 property of each file object;
4398 an operation on one file object does not affect the current
4399 index of any other file object.
4400
4401 For direct and stream files, the current size of the file is a property of
4402 the external file.
4403 @end{itemize}
4404
4405 All other effects are identical.
4406 @end{RunTime}
4407
4408 @begin{DiffWord95}
4409 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0057],ARef=[AI95-00050-01]}
4410 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Removed the incorrect statement
4411 that the external files associated with the standard input, standard output,
4412 and standard error files are distinct.]}
4413 @end{DiffWord95}