Contents
Up
Previous
Next


The textio package


The textio package is a built-in package provided for performing input and output to text files and with the screen and keyboard. The following is the package declaration corresponding to the textio package.
package textio is
  type line is access string;
  type text is file of string;
  type side is (right, left);
  subtype width is natural;
  
  file input: text is in "std_input";
  file output: text is out "std_output";
  
  procedure readline(f: in text; l: out line);
  function endline(l: in line);
  procedure writeline(f: in text; l: in line);

  procedure read(l: inout line; value: out bit;
                 good: out boolean);
  procedure read(l: inout line; value: out bit);

  procedure read(l: inout line; value: out bit_vector;
                 good: out boolean);
  procedure read(l: inout line; value: out bit_vector);

  procedure read(l: inout line; value: out boolean;
                 good: out boolean);
  procedure read(l: inout line; value: out boolean);

  procedure read(l: inout line; value: out character;
                 good: out boolean);
  procedure read(l: inout line; value: out character);

  procedure read(l: inout line; value: out integer;
                 good: out boolean);
  procedure read(l: inout line; value: out integer);

  procedure read(l: inout line; value: out real;
                 good: out boolean);
  procedure read(l: inout line; value: out real);

  procedure read(l: inout line; value: out string;
                 good: out boolean);
  procedure read(l: inout line; value: out string);

  procedure read(l: inout line; value: out time;
                 good: out boolean);
  procedure read(l: inout line; value: out time);

  procedure write(l: inout line; value: in bit;
                  justified: in side:=right; field: in width:=0);

  procedure write(l: inout line; value: in bit_vector;
                  justified: in side:=right; field: in width:=0);

  procedure write(l: inout line; value: in boolean;
                  justified: in side:=right; field: in width:=0);

  procedure write(l: inout line; value: in character;
                  justified: in side:=right; field: in width:=0);

  procedure write(l: inout line; value: in integer;
                  justified: in side:=right; field: in width:=0);

  procedure write(l: inout line; value: in string;
                  justified: in side:=right; field: in width:=0);

  procedure write(l: inout line; value: in real;
                  justified: in side:=right; field: in width:=0;
                  digits: in natural:=0);

  procedure write(l: inout line; value: in time;
                  justified: in side:=right; field: in width:=0;
                  units: in time:=ns); 

This package declares a file type named text that can be used to read and write to and from text files. The predefined file, input, is a special file that designates the keyboard input. Anything written to the special predefined file, output, is displayed on the screen.

The readline and writeline procedures are used to read and write from text files. The readline procedure reads one text line from the input file and puts it in the line variable passed in. The writeline procedure writes the contents of the line variable passed in and makes that line an empty string. The endfile function can be used as with normal files to determine if an input file has reached the end.

The many read and write procedures read and write values to and from a string. The read procedure attempts to read a value of the type of the value variable. If the read procedure is used with the good output, then good is set to true if the read operation was successful. For example, the read procedure for integer values could be used to read from the string "3", but the read procedure for bit values would be unsuccessful because 3 is not a valid value for the bit type. Every time a value is read from a line, that portion of the string is removed until it is eventually empty. The endline function returns true if the line passed in is empty.

The write procedure writes a value to a string by appending it to the end of the string passed in. The justified parameter can be used to specify if the text is left- or right-justified in its field width. The field width is specified by the field parameter. If this parameter is zero, then the field width is whatever width is required. The write procedure for real values has an extra parameter, digits. This parameter is the number of digits of precision that will be used. If this parameter is zero, then the standard exponent form is used. The write procedure for the time type also has an extra parameter, unit. This parameter specifies what unit to use.