ISO Modula-2 Standard I/O-Lib test progr 
Author Message
 ISO Modula-2 Standard I/O-Lib test progr

                            Test & Example programs
                                    for the
                         ISO Modula-2 Standard I/O-Library

                       by G~unter Dotzel, Elmar Baumgart
        ModulaWare GmbH, Wilhelmstr. 17A, D-W 8520 Erlangen/F.R.Germany
                 Tel. +49 (9131) 208395, Fax +49 (9131) 28205.


     All statements contained in this summary concerning ISO Modula-2 and
it's Standard Library constitute our personal opinion. This text and the
associated example and test programs (TestPos.MOD and TestExam.MOD)
can be freely distributed under the provision that the full, unmodified
text of this file is included.

                    What's ISO-Modula-2's Standard Library?

     The final design of ISO Modula-2's Standard Library is the result of six
years design effort. One of the goals was full portability of applications
based on the Standard Library. The object-oriented design makes the Standard
Library extensible in the sense that new devices can be attached easily. The
formal specification of the semantics of all library procedures in VDM-SL
(Vienna Definition Method -Semantic Language) in combination with rigorous
exceptions definition allows the use of the library in safety critical

     The outcome is different to any commercially available Modula-2 library.
One of the most unusual, but nevertheless attractive feature is that line-
mark characters in text files can't be touched.

     The definition modules of the I/O-, CharClass and SysClock Standard
Library are contained in the file STDLIB.ARC in Lib 11 of CompuServe's
CodePort forum.

                             Part 1: Module TestPos
                   written by Elmar Baumgart/ModulaWare GmbH

     Module TestPos is one of many example programs used to  test ModulaWare's
implementation of the Standard library. TestPos imports the Standard library
modules  RndFile, SeqFile, STextIO, SWholeIO, TextIO, RawIO, IOResult and
ProgramArgs. The main purpose of the example program  is to test the file
positioning procedures of RndFile.

     TestPos opens three files, called DATA, INSERT and SEARCH. The three file
names are program argument parameters. If under VMS, the executable image
TestPos.EXE is installed as a foreign command, e.g. using the declarative

$TestPos :== $Device:[dir]TestPos.EXE

     the program arguments are specified in the command line, e.g.

$TestPos hash.dat insert.txt search.txt

     Otherwise, when started with the VMS $Run-command, ProgramArgs prompts
for the arguments (_$).

     If at the start of the program the hash [Wirt 86] table file DATA does
not exist, a new file binary is created and initialized. Otherwise, an
existing file is opened for read and write. Since the hash table has fixed
file size, an existing file is first checked for correct file size. In our
example with 3877 strings of 40 characters each, the total file size is 155080

     INSERT and SEARCH are any text files, opened for read only. TestPos reads
the file INSERT and inserts all string tokens (TextIO.ReadToken) into DATA
until end-of-file. Then file SEARCH is read and all tokens are looked-up in
DATA. A simple test would be to call TestPos with identical INSERT and SEARCH
file, e.g.:

$Run TestPos

_$ hash.dat testpos.mod testpos.mod

     After insertion of all tokens of the input file TestPos.MOD, all tokens of
the file TestPos.MOD to be searched are already contained in hash.dat.

Literature: [Wirth 86] Niklaus Wirth: Algorithms & Data Structures,
  Prentice/Hall International, 1986. (Explains "hashing" in Modula-2)

                           Part 2: Module TestExample
                   written by Elmar Baumgart/ModulaWare GmbH

     Module TestExample is another example program used to test ModulaWare's
implementation of the Standard library. It's unusual in that it also reads
backwards through a file. TestExample illustrates the use of the ISO Modula-2
Standard I/O-Library for creating, writing, reading, rewriting, and appending
to/from a text file. Also, the just created text file is opened as binary
random file and read forward and backward using the positioning procedures of
RndFile. When reading backards there is no end-of-file detection (better
called start-of-file). This is why the program terminates with an unhandled
exception. Detailed comments are contained in the program source TestExam.MOD.

The console output of this program is self-explaining:

   small test program
   initial file status:
     10 times foo
     10 times foo
     10 times foo
     10 times foo
     10 times foo
     10 times foo
     10 times foo
     10 times foo
     10 times foo
     10 times foo
   status after Rewrite:
     and now 5 times bar
     and now 5 times bar
     and now 5 times bar
     and now 5 times bar
     and now 5 times bar
   status after OpenAppend:
     and now 5 times bar
     and now 5 times bar
     and now 5 times bar
     and now 5 times bar
     and now 5 times bar
     makes 7 lines total
     makes 7 lines total
   now reading binary :-)
     and now 5 times bar
     and now 5 times bar
     and now 5 times bar
     and now 5 times bar
     and now 5 times bar
     makes 7 lines total
     makes 7 lines total
   now reading from eof to start

   latot senil 7 sekam  
   latot senil 7 sekam  
   rab semit 5 won dna  
   rab semit 5 won dna  
   rab semit 5 won dna  
   rab semit 5 won dna  
   rab semit 5 won dna

   EXCEPTION encountered
   m2-iso-lib-err: posRange exception
   ...procedure call trace follows...

   The module TestPos and TestExample are now part of ModulaWare's MVR V3.16B
distribution kit (VAX/VMS Modula-2 Compiler Kit with ISO Modula-2 extensions).
Both examples and this text was extracted from "The ModulaTor", ModulaWare's
monthly, non-commercial Modula-2 & Oberon-2 & Edison-2 Newsletter.

Suggestions and improvements are welcome!

                       ModulaWare's Implementation Notes
                                     of the
      ISO Modula-2 I/O-, Number/String Conversions, CharClass and SysClock

                         Framstag, the 13/14-Mar-1992
                       by G~unter Dotzel, Elmar Baumgart

     With the VAX/VMS Modula-2 Compiler distribution kit, release MVR
V3.16B/14-Mar-1992, ModulaWare is one of the first commercial Modula-2
compiler developer/vendor who provides an implementation of the ISO Modula-2
I/O-, Number/String Conversions, CharClass and SysClock modules to their
supported licensees.  The implementation modules were developed by Elmar
Baumgart from scratch. In less than 500 hours he wrote and debugged more
than 5000 lines of Modula-2 source code. Most of the modules are portable by
re-compilation; some are VMS (operating system) specific and some are VAX
(machine) specific . The source code is available under certain conditions
(please contact ModulaWare).

     ModulaWare's VAX/VMS Modula-2 Compiler (MVR) already incorporates many of
the ISO  Modula-2 language extensions, such as COMPLEX, LONGCOMPLEX, RE, IM,

     Among the features not yet supported are recursive procedure types as
used in the modules ConvTypes, LongConv, RealConv and  WholeConv (used type
ScanProc). Type ADDRESS is temporarily used instead. Also function procedures
that return structured values, such as an ARRAY [...] OF SYSTEM.LOC as
declared in RndFile are not yet supported by MVR; SYSTEM.QUADWORD (8 Bytes) is
temporarily used instead. In the distribution kit, these differences are
commented in the respective definition modules. Also, the ISO Modila-2 system
module EXCEPTIONS was simulated.

     Additionally one auxiliary module Arg_Prompt is provided to be able to
change the prompt string for program arguments for programs not installed as
foreign commands under VMS.

     We avoided the use of the pervasives BITSET and SIZE in all of the
Standard library modules. This was to avoid problems associated with the
pervasive type BITSET (according to the 3rd Working Draft, BITSET has to be
imported from SYSTEM). As agreed at the 6th ISO meeting, Jul-1992, BITSET is
pervasive again. SIZE can no longer be imported from SYSTEM, because SIZE is
pervasive in ISO Modula-2. This didn't change at the 6th ISO meeting.

  There are
         22 IO-modules
          7 number/string conversions' modules
          1 CharClass module
         15 auxiliary modules
  total: 45 modules

  There are
         -2 foreign definition modules without implementation.

  When recompiled there are in
  total  43 object files

  OK    = implemented and tested
  (OK)  = still work to do
  *     = portable by recompilation
  uses  = VMS specific functions
  (..)  = ... not implemented

EXCEPTIONS    OK (temporary auxilliary module, definition is not yet
                  consistent with ISO M2. When this system module is known
                  by the compiler: remove status parameter, provide in compiler)
CharClass     OK *
ConvTypes     OK * (ScanProc not ISO M2, recursive procedure types = ADDRESS;
                    change is marked in .DEF file)

VMS_Real      OK uses knowledge about internal representation of reals
Real_Aux      OK uses knowledge about internal representation of reals
Whole_Aux     OK *
Long_Aux      OK uses knowledge about internal representation of reals

WholeStr      OK uses OTS$, FOR$
RealStr       OK
LongStr       OK

WholeConv     OK *
RealConv      OK *
LongConv      OK *

Chan_Alloc    OK *
IOConsts      OK *
ChanConsts    OK *
IOChan       (OK) (Exceptions) *
IOLink       (OK) (Exceptions) *
Close_Handler OK *

RawIO         OK *
TextIO        OK *
RealIO        OK *
LongIO        OK *
WholeIO       OK *
IOResult      OK *

SRawIO        OK *
STextIO       OK *
SRealIO       OK *
SLongIO       OK *
SWholeIO      OK *
SIOResult     OK *

Arg_Prompt    OK * provides prompt string used if not installed as foreign
                   command. "_$" is default prompt string. Allows to modify
                   the default prompt. See Arg_Prompt.DEF file.
ProgramArgs   OK
  (VMS converts to uppercase letters! If not installed as a
   foreign command, a prompt will be given when reading the first time
   from the argument channel. See Arg_Prompt)

Null_Device   OK *
StdChans      OK *

FOR_CVT       OK %FOREIGN, no implementation  uses FOR$, OTS$
ISO_LibMsg    OK * (not consequently in all modules imported !!!)
BM_           OK %FOREIGN, no implementation  (BlockMove module, STR$COPY_R)
RMS_Interface OK uses RMSFiles, RMSDefinitions...
VMS_IOLib     OK uses RMSDefinitions

TermFile      OK uses ISO_TTIO
RndFile       OK uses RMS_Interface, definition of type FilePos is not yet ISO
                 conform (SYSTEM.QUADWORD instead of ARRAY[0..3] OF SYSTEM.LOC)
SeqFile       OK uses RMS_Interface
StreamFile    OK uses RMS_Interface

VMS Systemcalls used:



  MODULE LongStr;

  MODULE ProgramArgs;

  MODULE RealStr;

  MODULE RMS_Interface;
    RMSFiles.Read, .Write, .Truncate, .Find, .Get



  MODULE SysClock;

  MODULE WholeStr;

Rationale for record formats/Implementation notes:

   When creating new files,
    RFM$UDF record format was chosen for binary files
    RFM$STM record format was chosen for text files
    All other record formats (RFMs) are supported read-only.

    - the stream-formats were used to simplify and improve the efficiency
      of the file positioning procedures.
    - RFM$FIX for binary files caused problems with eof-detection and
      RFM$VAR, which is the VMS default text format, doesn't allow
      the positioning functionality as required by the Standard library.

   When opening old files:
   - sequential read access is possible for files of any file type
     using block I/O (binary) or record-get (text), depending on the
     record format of the input file.

Implementation notes on TermFile:

  Channels to the Terminal can be created using both line-mode and
  single-character-mode without echo.
  - Channels with different modes can be opened at the same time
  - Read/write to these channels can be mixed
  This is a not-required functionality of the Standard.

  Program input data normally provided from the keyboard can be supplied
  from the command files that invokes the image.
  Input and output may be redirected using VMS's RUN process feature
  (when run as a detached process):


  When the RUN-command is excecuted from within a comand file, quotes have
  to be used:


  Note, that logicals require a $DEFINE/GROUP declaration for detached

  Example for running TestPos as a detached process (see TestPos.COM)

    $DEFINE/GROUP hash   sys$disk:[]hash.lis! hash table data file
    $DEFINE/GROUP insert sys$disk:[]testpos.mod! sample input file
    $DEFINE/GROUP find   sys$disk:[]testpos.mod! same sample search file
    $OPEN/Write testposinp testpos.INP
    $WRITE testposinp "hash insert find"! program input parameters
    $CLOSE testposinp
    $RUN testpos-

  Note, that re-directed output does not always create a new version of
   a file. The output is appended to an existing file and only the revision
   date changes (this is functionality of LIB$PUT_OUTPUT).

Filenames in SeqFile, RndFile, StreamFile.Open* procedures:
  Logical names are first translated using the VMS service SYS$TRNLNM in the
  following sequence: 'LNM$PROCESS'; 'LNM$JOB'; 'LNM$GROUP'; 'LNM$SYSTEM';

G~unter Dotzel [100023,2527]/22-Mar-1992

Fri, 09 Sep 1994 15:00:05 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Modules of ISO Modula-2 Standard Lib.

2. ISO Standard Lib.

3. ISO modula-2 standard TeX source: missing fonts

4. ISO Modula-2 Standard Library Definitions

5. ISO M2 I/O-Lib test file: TestPos.MOD

6. ISO M2 I/O-Lib test file: TestExam.MOD

7. ISO Modula-2 compliance tests

8. Testing of ISO Modula-2 StandLib modules.

9. ISO M2 Std Lib Defs .ARC

10. ISO M2 Std Lib Defs .ARC

11. branching in proposed ISO standard

12. ISO Standards Documents


Powered by phpBB® Forum Software