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