Debian Codegraph @

source_2005/pre_io.mss

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