Module Simula

Class RTS_Printfile

All Implemented Interfaces:
Runnable

public class RTS_Printfile extends RTS_Outfile
System class PrintFile.

The class "printfile" defines a class for line printer oriented output.

 class printfile;
 begin integer   LINE, LINES_PER_PAGE, SPACING, PAGE;
       integer procedure line;  line := LINE;
       integer procedure page;  page := PAGE;
       Boolean procedure open(fileimage);  text fileimage; 
       Boolean procedure close; 
       procedure linesperpage(n); integer n; 
       procedure spacing(n); integer n; 
       procedure eject(n);  integer n; 
       procedure outimage; 
       procedure outrecord; 
 
       SPACING := 1;
       LINES_PER_PAGE := ... ;
          ...
 end printfile;
 

An object of the class "printfile" is used to represent a line printer oriented output file. The class is a subclass of "outfile". A file image normally represents a line on a printed page.

It is a property of this class that "outfile" attributes, which are redeclared at "printfile" level, are not accessible to the user's program through explicit qualification (qua). Thus these "outfile" procedures ("open", "close", "outimage", "outrecord") may be envisaged as including the following initial code:

               procedure X...;
               inspect this outfile
                  when printfile do X...
                  otherwise ...;
 

Note: Consequently, possible implicit calls of outimage from outchar, close and the item-oriented output procedures are understood to invoke "printfile.outimage".

The variable LINE indicates the ordinal number of the next line to be printed (on the current page), provided that no implicit or explicit "eject" statement occurs. Its value is accessible through the procedure "line". Note that the value of LINE may be greater than LINES_PER_PAGE (see 10.7.5).

The variable PAGE indicates the ordinal number of the current page. Its value may be retrieved by means of procedure "page".

Link to GitHub: Source File.

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

    • _DEFAULT_LINES_PER_PAGE

      private int _DEFAULT_LINES_PER_PAGE
      The default LINES_PER_PAGE = 66
    • _SPACING

      private int _SPACING
      The current SPACING.
    • _LINE

      private int _LINE
      The current LINE
    • _PAGE

      private int _PAGE
      The current PAGE
    • _LINES_PER_PAGE

      int _LINES_PER_PAGE
      The current lines per page
  • Constructor Details

    • RTS_Printfile

      public RTS_Printfile(RTS_RTObject SL, RTS_TXT FN)
      Create a new _Printfile
      Parameters:
      SL - staticLink
      FN - file name
  • Method Details

    • _STM

      public RTS_Printfile _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_Outfile
      Returns:
      a pointer to this _RTObject
    • line

      public int line()
      Return the current line number.
      Returns:
      the current line number
    • page

      public int page()
      Return the current page number.
      Returns:
      the current page number
    • open

      public boolean open(RTS_TXT image)
      Procedure open.
       Boolean procedure open(fileimage);  text fileimage;
       if ... then
       begin ... 
          image :- fileimage;
          PAGE  := 0;
          LINE  := 1;
          setpos(1);
          eject(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. *

      Overrides:
      open in class RTS_Outfile
      Parameters:
      image - the givent image
      Returns:
      true if successful, otherwise false.
    • close

      public boolean close()
      Procedure close.
       Boolean procedure close;
       if OPEN then
       begin ... ! 
          if pos ne 1 then outimage;
          
          eject(LINES_PER_PAGE);
          PAGE := ... ;
          LINE := 0;
          SPACING := 1;
          LINES_PER_PAGE:= ... ;
          
          
          image :- notext;
          ... ; ! perform closing actions on external file;
          OPEN  := false;
          close := 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.

      The procedure "close" calls "outimage" if the position indicator is not equal to 1.

      If successful, "close" returns true. In addition, PAGE, LINE, SPACING, LINES_PER_PAGE, OPEN and "image" are reinitiated.

      Overrides:
      close in class RTS_Outfile
      Returns:
      true if successful, otherwise false.
    • linesperpage

      public int linesperpage(int n)
      Procedure linesperpage.
       integer procedure linesperpage(n); integer n;
          begin
             linesperpage := LINES_PER_PAGE;
             LINES_PER_PAGE:= if n > 0 then n
                               else if n < 0 then maxint
                                else  ... ; ! default value;
       

      The variable LINES_PER_PAGE indicates the maximum number of physical lines that may be printed on each page, including intervening blank lines. An implementation-defined value is assigned to the variable at the time of object generation, and when the printfile is closed. The value of the variable may be retreived by a call on "linesperpage"; in addition the variable is givan a new value as follows.

      If the parameter to "linesperpage" is zero, LINES_PER_PAGE is reset to the original value (assigned at object generation). A parameter value less than zero may be used to indicate an "infinite" value of LINES_PER_PAGE, thus avoiding any automatic calls on "eject".

      Parameters:
      n - the requested lines per page
      Returns:
      the new lines per page
    • spacing

      public void spacing(int n)
      Procedure spacing.
       procedure spacing(n); integer n;
                  if  0<=n and n<=LINES_PER_PAGE  then SPACING := n
                  else  error("..." ! Parameter out of range; );
       

      The variable SPACING represents the value by which the variable LINE is incremented after the next printing operation. Its value may be changed by the procedure "spacing". A call on the procedure "spacing" with a parameter less than zero or greater than LINES_PER_PAGE constitutes an error. The effect of a a parameter to "spacing" which is equal to zero may be defined as forcing successive printing operations on the same physical line. Note, however, that on some physical media this may not be possible, in which case spacing(0) has the same effect as spacing(1) (i.e. no overprinting).

      Parameters:
      n - line increment
      Throws:
      RTS_SimulaRuntimeError - if n is out of range
    • eject

      public void eject(int n)
      Procedure eject.
       procedure eject(n); integer n;
         if not OPEN then error("..." ! file closed;)
         else if n <= 0 then error("..." ! Parameter out of range;)
         else begin
            if n > LINES_PER_PAGE then n := 1;
            if n <= LINE then
            begin
               ... ; ! change to new page on external file;
               PAGE := PAGE + 1
            end;
            ... ; ! move to line "n" on current (external) page;
            LINE := n
       end eject;
       

      The procedure "eject" is used to position to a certain line identified by the parameter, n. The variable "PAGE" is incremented by one each time an explicit or implicit "eject" implies a new page.

      The following cases can be distinguished:

            n <= 0                 : error
            n >  LINES_PER_PAGE    : Equivalent to eject (1)
            n <= LINE              : Position to line number n on the next page
            n >  LINE              : Position to line number n on the current page
       
      The tests above are performed in the given sequence.
      Parameters:
      n - requested line number
      Throws:
      RTS_SimulaRuntimeError - if the operation fail
    • writeImage

      protected void writeImage(String ident, String img, boolean blank)
      Description copied from class: RTS_Outfile
      Output utility: Used by outimage, outrecord and breakoutimage.

      Redefined in PrintFile

      Overrides:
      writeImage in class RTS_Outfile
      Parameters:
      ident - identifier used in error message
      img - the image to output
      blank - true if the image should be blank-filled after the output operation