Module Simula

Class RTS_File

All Implemented Interfaces:
Runnable
Direct Known Subclasses:
RTS_Bytefile, RTS_Imagefile

public class RTS_File extends RTS_CLASS
System class File.
    class file(FILENAME);  value FILENAME;  text FILENAME;
    begin Boolean OPEN;
       text procedure filename;  filename :- copy(FILENAME);
       Boolean procedure isopen; isopen := OPEN;
       Boolean procedure setaccess(mode);  text mode; ... 10.1.1;
 
       if FILENAME = notext then error("...");
    end file;
 

"File" is the common prefix class for all input/output classes.

A file is either open or inaccessible as indicated by the variable "OPEN". The procedure "isopen" returns the current value of "OPEN". A file is initially inaccessible (e.g. closed).

Each file object has a text attribute FILENAME. This text value must at "open" identify an external file which, through an implementation-defined mechanism, becomes associated with the file object. If the parameter value is notext, a run-time error occurs.

The procedure "filename" retrieves the value of FILENAME.

Link to GitHub: Source File.

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

    • FILE_NAME

      protected final RTS_TXT FILE_NAME
      The file name.
    • _OPEN

      protected boolean _OPEN
      The OPEN indicator.
    • _CREATE

      protected RTS_File._CreateAction _CREATE
      CREATE: Action is performed as 'open'
    • _PURGE

      protected boolean _PURGE
      PURGE: Action is performed at 'close'

      The value "purge" implies that the external file may be deleted by the environment when it is closed (in the sense that it becomes inaccessible to further program access). The value "nopurge" implies no such deletion.

    • _CANREAD

      protected boolean _CANREAD
      If the value is true, input operations can be performed.

      This mode is relevant only for direct files.

    • _CANWRITE

      protected boolean _CANWRITE
      If the value is true, output operations can be performed.

      This mode is relevant only for direct files.

    • _APPEND

      protected boolean _APPEND
      The output to the file is added to the existing contents of the file.

      If the value is true, output to the file is added to the existing contents of the file. The value false implies for a sequential file that, after "close", the external file will contain only the output produced while the file was open.

      The mode is not relevant for in(byte)files.

    • _CHARSET

      protected Charset _CHARSET
      The current character set when encode/decode files.
    • _DEFAULT_BYTESIZE

      protected final int _DEFAULT_BYTESIZE
      The default BYTESIXE is 8 in this implementation.
      See Also:
    • _SYNCHRONOUS

      protected boolean _SYNCHRONOUS
      The access mode SYNCHRONOUS.

      It is available for Out- files and Direct- files. For Outfile/OutBytefile, each write operation will be followed by a flush to ensure that the underlying storage device is updated. For Directfile/DirectBytefile the underlaying Java RandomAccessFile will be created open for reading and writing, and also require that every update to the file's content or metadata be written synchronously to the underlying storage device.

    • _FONT

      protected Font _FONT
      The current Font.
    • _ORIENTATION

      protected int _ORIENTATION
      The current paper orientation.
    • _ASK_PAPER

      protected boolean _ASK_PAPER
      Indicator to decide whether to ask, by a dialog, for the paper and orientation.
    • _LEFT_MARGIN

      protected double _LEFT_MARGIN
      The papar's current left margin
    • _RIGHT_MARGIN

      protected double _RIGHT_MARGIN
      The papar's current right margin
    • _TOP_MARGIN

      protected double _TOP_MARGIN
      The papar's current top margin
    • _BOT_MARGIN

      protected double _BOT_MARGIN
      The papar's current bottom margin
  • Constructor Details

    • RTS_File

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

    • _STM

      public RTS_File _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_RTObject
      Returns:
      a pointer to this _RTObject
    • filename

      public RTS_TXT filename()
      Returns the filename.
      Returns:
      the filename
    • isopen

      public boolean isopen()
      Returns true when this file is open.
      Returns:
      true when this file is open
    • trySelectFile

      protected File trySelectFile(String fileName)
      Try to select a file named 'fileName'.

      If no file exists with that fileName it will try several possibilities:

      • First it will search the Option.RUNTIME_USER_DIR
      • Second, system properties "user.dir" and "java.class.path".parent
      • Finally, a JFileChooser dialog is opened to let the user select the file
      Parameters:
      fileName - the given fale name
      Returns:
      the resulting file or null
    • setaccess

      public boolean setaccess(RTS_TXT mode)
      External file access control.

      Certain attributes (not specified in the file outline) control the access to the external file. The values of these attributes are set when the file object is opened or closed, from a set of default values possibly modified by successive calls to the procedure "setaccess".

      The standard attribute modes are SHARED, APPEND, CREATE, READWRITE, BYTESIZE, REWIND and PURGE.

      The parameter "mode" to procedure "setaccess" contains one of the standard values as given above, namely "shared", "noshared", "append", "noappend", "create", "nocreate", "anycreate", "readonly", "writeonly", "readwrite", "bytesize:X" (where X is a positive integer), "rewind", "norewind", "purge" and "nopurge".

      It is recommended that implementation-defined parameter values have the percent character % as the first character of the text.

      Unrecognized modes are ignored and "setaccess" then returns the value false. The value is true otherwise.

      See Simula Standard Chapter 10, INPUT-OUTPUT.

      Parameters:
      mode - the access mode text
      Returns:
      true if mode is recognized, otherwise false.
    • setCharset

      protected boolean setCharset(String id)
      Set new Charset.
      Parameters:
      id - charset identifier
      Returns:
      true if the operation was successful, otherwise false
    • setFont

      protected boolean setFont(String id)
      Set new Font.
      Parameters:
      id - font identifier
      Returns:
      true if the operation was successful, otherwise false
    • setMargins

      protected boolean setMargins(String id)
      Utility: Set paper margins.
      Parameters:
      id - an margin string "top:left:bottom:right"
      Returns:
      true if the operation was successful, otherwise false
    • doCreateAction

      protected File doCreateAction()
      Do the Create action.
      Returns:
      the File
    • doPurgeAction

      protected void doPurgeAction()
      Do the Purge action
    • TRACE_OPEN

      protected void TRACE_OPEN(String mss)
      Utility: Trace file open.
      Parameters:
      mss - a trace message