Go to the first, previous, next, last section, table of contents.


A.10.7 Input-Output of Characters and Strings

Static Semantics

  1. For an item of type Character the following procedures are provided:
  2. procedure Get(File : in File_Type; Item : out Character);
    procedure Get(Item : out Character);
    
    1. After skipping any line terminators and any page terminators, reads the next character from the specified input file and returns the value of this character in the out parameter Item.
    2. The exception End_Error is propagated if an attempt is made to skip a file terminator.

  1. procedure Put(File : in File_Type; Item : in Character);
    procedure Put(Item : in Character);
    
    1. If the line length of the specified output file is bounded (that is, does not have the conventional value zero), and the current column number exceeds it, has the effect of calling New_Line with a spacing of one. Then, or otherwise, outputs the given character to the file.

  1. procedure Look_Ahead (File        : in  File_Type;
                          Item        : out Character;
                          End_Of_Line : out Boolean);
    
    procedure Look_Ahead (Item        : out Character;
                          End_Of_Line : out Boolean);
    
    1. Mode_Error is propagated if the mode of the file is not In_File. Sets End_Of_Line to True if at end of line, including if at end of page or at end of file; in each of these cases the value of Item is not specified. Otherwise End_Of_Line is set to False and Item is set to the the next character (without consuming it) from the file.

  1. procedure Get_Immediate(File : in  File_Type;
                            Item : out Character);
    
    procedure Get_Immediate(Item : out Character);
    
    1. Reads the next character, either control or graphic, from the specified File or the default input file. Mode_Error is propagated if the mode of the file is not In_File. End_Error is propagated if at the end of the file. The current column, line and page numbers for the file are not affected.

  1. procedure Get_Immediate(File      : in  File_Type;
                            Item      : out Character;
                            Available : out Boolean);
    
    procedure Get_Immediate(Item      : out Character;
                            Available : out Boolean);
    
    1. If a character, either control or graphic, is available from the specified File or the default input file, then the character is read; Available is True and Item contains the value of this character. If a character is not available, then Available is False and the value of Item is not specified. Mode_Error is propagated if the mode of the file is not In_File. End_Error is propagated if at the end of the file. The current column, line and page numbers for the file are not affected.

  1. For an item of type String the following procedures are provided:
  2. procedure Get(File : in File_Type; Item : out String);
    procedure Get(Item : out String);
    
    1. Determines the length of the given string and attempts that number of Get operations for successive characters of the string (in particular, no operation is performed if the string is null).

  1. procedure Put(File : in File_Type; Item : in String);
    procedure Put(Item : in String);
    
    1. Determines the length of the given string and attempts that number of Put operations for successive characters of the string (in particular, no operation is performed if the string is null).

  1. procedure Get_Line(File : in     File_Type;
                       Item :    out String;
                       Last :    out Natural);
    
    procedure Get_Line(Item : out String; Last : out Natural);
    
    1. Reads successive characters from the specified input file and assigns them to successive characters of the specified string. Reading stops if the end of the string is met. Reading also stops if the end of the line is met before meeting the end of the string; in this case Skip_Line is (in effect) called with a spacing of 1. The values of characters not assigned are not specified.
    2. If characters are read, returns in Last the index value such that Item(Last) is the last character assigned (the index of the first character assigned is Item'First). If no characters are read, returns in Last an index value that is one less than Item'First. The exception End_Error is propagated if an attempt is made to skip a file terminator.

  1. procedure Put_Line(File : in File_Type; Item : in String);
    procedure Put_Line(Item : in String);
    
    1. Calls the procedure Put for the given string, and then the procedure New_Line with a spacing of one.

Implementation Advice

  1. The Get_Immediate procedures should be implemented with unbuffered input. For a device such as a keyboard, input should be "available" if a key has already been typed, whereas for a disk file, input should always be available except at end of file. For a file associated with a keyboard-like device, any line-editing features of the underlying operating system should be disabled during the execution of Get_Immediate.

    NOTES

  2. (26) Get_Immediate can be used to read a single key from the keyboard "immediately"; that is, without waiting for an end of line. In a call of Get_Immediate without the parameter Available, the caller will wait until a character is available.
  3. (27) In a literal string parameter of Put, the enclosing string bracket characters are not output. Each doubled string bracket character in the enclosed string is output as a single string bracket character, as a consequence of the rule for string literals, See section 2.6 String Literals.
  4. (28) A string read by Get or written by Put can extend over several lines. An implementation is allowed to assume that certain external files do not contain page terminators, in which case Get_Line and Skip_Line can return as soon as a line terminator is read.


Go to the first, previous, next, last section, table of contents.