Module Simula

Class RTS_Infile

All Implemented Interfaces:
Runnable

public class RTS_Infile extends RTS_Imagefile
System class Infile.
 imagefile class infile;
     begin Boolean ENDFILE;
        Boolean procedure endfile;  endfile:= ENDFILE;
        Boolean procedure open(fileimage); text fileimage;
        Boolean procedure close;
        procedure inimage; 
        Boolean procedure inrecord; 
        character procedure inchar; 
        Boolean procedure lastitem; 
        text procedure intext(w); integer w; 
        integer procedure inint; 
        long real procedure inreal;
        integer procedure infrac;
 
        ENDFILE:= true
        ...
     end infile;
 

An object of the class "infile" is used to represent an image-oriented sequential input file.

The variable ENDFILE is true whenever the file object is closed or the external file is exhausted (i.e. "end of file" has been encountered). The procedure "endfile" gives access to the value of ENDFILE.

Link to GitHub: Source File.

Author:
SIMULA Standards Group, Øystein Myhre Andersen
  • Field Details

    • lineReader

      private BufferedReader lineReader
      The BufferedReader used.
    • rest

      private String rest
      Utility variable
  • Constructor Details

    • RTS_Infile

      public RTS_Infile(RTS_RTObject SL, RTS_TXT FN)
      Create a new _Infile.
      Parameters:
      SL - staticLink
      FN - FILENAME
  • Method Details

    • _STM

      public RTS_Infile _STM()
      Description copied from class: RTS_RTObject
      Method representing the Statements in this Block
      This method is virtual and must be redefined in blocks.
      Overrides:
      _STM in class RTS_Imagefile
      Returns:
      a pointer to this _RTObject
    • open

      public boolean open(RTS_TXT image)

      Procedure open.

        Boolean procedure open(fileimage);  text fileimage;
            if ... then begin ...  ! see 10.1.2;
               ENDFILE := false;
               image   :- fileimage;
               image   := notext;
               setpos(length+1);
               open    := OPEN := true;
            end open;
       

      Procedure "open" establishes the association with an external file (as identified by FILENAME), checks the access modes and causes corresponding opening actions on the external file. If the external file is closed, it is opened.

      If successful, "open" returns true and sets ENDFILE false. In addition, "image" references the parameter "fileimage" which is space-filled.

      Parameters:
      image - the givent image
      Returns:
      true if successful, otherwise false.
    • close

      public boolean close()
      Procedure close.
       Boolean procedure close;
            if OPEN then
            begin ... ; ! perform closing actions ...;
               image :- notext;
               OPEN  := false;
               close := ENDFILE := true
       end close;
       

      Procedure "close" causes closing actions on the external file, as specified by the access modes. In addition, the association between the file object and the external file is dissolved. If possible, the external file is closed.

      If successful, "close" returns true. In addition, OPEN is false, ENDFILE is true and "image" references notext.

      Returns:
      true if successful, otherwise false.
    • endfile

      public boolean endfile()
      Procedure endfile.

      Returns true whenever the file object is closed or the external file is exhausted (i.e. "end of file" has been encountered).

      Returns:
      the resulting boolean value
    • inimage

      public void inimage()
      Procedure Inimage.
       procedure inimage;
         if ENDFILE then error("...")
         else begin
            ... ; ! attempt to transfer external image to "image";
            if ... ! "image" too short; then error("...")
            else if ... ! there was no more to read;
            then begin
                   ENDFILE := true;
                   image   :- "!25!" end
            else  ... ; ! pad "image" with space(s);
            setpos(1)
       end inimage;
       

      The procedure "inimage" performs the transfer of an external file image into "image". A run-time error occurs if "image" is notext or too short to contain the external image. If it is longer than the external image, the latter is left-adjusted within "image" and the remainder of the text is filled with spaces. The position indicator is set to one.

      Note: If an "end of file" is encountered, EM ('!25!') is generated as a single character external image, and the variable ENDFILE is given the value true. A call on "inimage" or "inrecord" when ENDFILE already has the value true constitutes a run-time error.

      Overrides:
      inimage in class RTS_Imagefile
      Throws:
      RTS_SimulaRuntimeError - if inimage fail
    • inrecord

      public boolean inrecord()
      Procedure inrecord.
        Boolean procedure inrecord;
           if not OPEN or ENDFILE then error("...")
           else begin
              ... ; ! transfer external image to "image" (no space-filling);
              if ... ! no more to read;
              then begin
                 ENDFILE        := true;
                 setpos(1);
                 image.putchar('!25!') end  Note - POS = 2 now
              else begin
                 setpos(... !number of characters transferred + 1; );
                 inrecord:= not ...! whole external image received?;
              end if
        end inrecord;
       

      The procedure "inrecord" is similar to "inimage" with the following exceptions. Whenever the number of characters accessible in the external image is less than "length", the rest of "image" is left unchanged. The part of the "image" that was changed is from pos 1 upto (but not including) the resulting value of POS. Moreover, if the external image is too long, only the "length" first characters are input. The value returned by the procedure is true and the remaining characters may be input through subsequent "inrecord" (or possibly "inimage") statements. Otherwise, if the input of the external image was completed, the value false is returned.

      Note: If an "end of file" is encountered, EM ('!25!') is generated as a single character external image, and the variable ENDFILE is given the value true. A call on "inimage" or "inrecord" when ENDFILE already has the value true constitutes a run-time error.

      Returns:
      true if a partial record is read, otherwise false
      Throws:
      RTS_SimulaRuntimeError - if inrecord fail