From: g_dotzel@tron.gun.de (Guenter Dotzel)
Newsgroups: comp.lang.modula2
Subject: Re^2: argc and *argv in Modula-2 ?
Date: 10 Apr 92 07:00:04 GMT

robart%agora.uucp@USENET.ZER wrote on Thu, 04-02-1992 at 00:53 h
under the subject 'Re: argc and *argv in Modula-2 ?':

> From: robart@agora.uucp (Robert Barton)
> Subject: Re: argc and *argv in Modula-2 ?
> Message-ID: <1992Apr2.005359.13785@agora.uucp>
> Organization: Organization
> 
> In article <23U676368B@tron.gun.de> g_dotzel@tron.gun.de (Guenter Dotzel) writes:
> >> 
> >MODULE mod_copy;
> >FROM ProgramArgs IMPORT IsArgPresent, ArgChan;
> >FROM IOResult IMPORT ReadResult, ReadResults;
> >FROM TextIO IMPORT WriteString, ReadToken, SkipLine, ReadString;
> >
> >TYPE fnam = ARRAY[0..254] OF CHAR;
> >VAR from, to: fnam;
> >
> >BEGIN
> >  IF (ReadResult(ArgChan()) <> endOfInput) THEN ReadToken(ArgChan(), from);
> >    IF (ReadResult(ArgChan()) <> endOfInput) THEN ReadToken(ArgChan(), to);
> >    ELSE (* ... *)
> >    END;
> >  ELSE (* ... *)
> >  END;
> >END mod_copy.
> 
>   Where does endOfInput come from?  You haven't shown it being imported
> from anywhere.

Of course, from IOResult (ReadResults). Here comes the definition:
----cut here----
DEFINITION MODULE IOResult;

  (* Obtain read results on specified channels *)

IMPORT 
  IOConsts;
FROM IOChan IMPORT 
  ChanId;

TYPE
  ReadResults = IOConsts.ReadResults;

  (*
    ReadResults = (
      notKnown,     (* no read result is set *)
      allRight,     (* data is as expected or as required *)
      outOfRange,   (* data cannot be represented *)
      wrongFormat,  (* data not in expected format *)
      endOfLine,    (* end of line seen before expected data *)
      endOfInput    (* end of input seen before expected data *)
    );
  *)

PROCEDURE ReadResult(cid: ChanId): ReadResults;
  (* Returns the result for the last read operation on the channel. *)

END IOResult.
----cut here----
DEFINITION MODULE IOConsts;

  (* Types and constants for input/output modules *)

  (* The following type is used to classify the result of an input operation *)

TYPE
  ReadResults = (
    notKnown,    (* no read result is set *)
    allRight,    (* data is as expected or as required *)
    outOfRange,  (* data cannot be represented *)
    wrongFormat, (* data not in expected format *)
    endOfLine,   (* end of line seen before expected data *)
    endOfInput   (* end of input seen before expected data *)
  );

END IOConsts.
----cut here----
DEFINITION MODULE IOChan;

  (* Types and procedures forming the interface to channels for
     device-independent data transfer modules
  *)

IMPORT IOConsts, ChanConsts, SYSTEM;

TYPE
  ChanId;
    (* Values of this type are used to identify channels *)

  (* There is one pre-defined value identifying an invalid channel on which
     no data transfer operations are available.  It may be used to
     initialize variables of type ChanId.
  *)

PROCEDURE InvalidChan () : ChanId;
  (* Returns the value identifying the invalid channel. *)

(* For each of the following operations, if the device supports the
   operation on the channel, the behaviour of the procedure conforms with
   the description below.  The full behaviour is defined for each device
   module.  If the device does not support the operation on the channel,
   the behaviour of the procedure is to raise the exception notAvailable.
*)


  (* Text operations - these perform any required translation between
     the internal and external representation of text.
  *)

PROCEDURE Look (cid: ChanId; VAR ch: CHAR; VAR res: IOConsts.ReadResults);
  (* If there is a character as the next item in the given input stream,
     assigns its value to the parameter ch without removing it from the
     stream.  Otherwise, the value of the parameter ch is not defined.  The
     parameter res and the stored read result are set to the value
     allRight, endOfLine, or endOfInput.
  *)

PROCEDURE Skip (cid: ChanId);
  (* If the input has ended, the exception skipAtEnd is raised, otherwise,
     the next character or line mark in the input stream is removed and the
     stored read result is set to the value allRight.
  *)

PROCEDURE SkipLook (cid: ChanId; VAR ch: CHAR; VAR res: IOConsts.ReadResults);
  (* If the stream has ended, the exception skipAtEnd is raised,
     otherwise, the next character or line mark in the input stream is
     removed.  If there is a character as the next item in the given input
     stream, assigns its value to the parameter ch without removing it from
     the stream.  Otherwise, the value of the parameter ch is not defined.
     The parameter res and the stored read result are set to the value
     allRight, endOfLine, or endOfInput.
  *)

PROCEDURE TextRead (cid: ChanId; to: SYSTEM.ADDRESS; maxChars: CARDINAL;
                    VAR charsRead: CARDINAL);
  (* Reads at most maxChars characters from the current line and assigns
     corresponding values to successive locations, starting at the address
     given by the parameter to, and continuing at increments corresponding
     to the address difference between successive components of an ARRAY OF
     CHAR.  The number of characters read is assigned to the parameter
     charsRead.  The stored read result is set to the value allRight,
     endOfLine, or endOfInput.
  *)

PROCEDURE TextWrite (cid: ChanId; from: SYSTEM.ADDRESS; charsToWrite: CARDINAL);

  (* Writes a number of characters given by the value of the parameter
     charsToWrite, starting at the address given by the parameter from, and
     continuing at increments corresponding to the address difference
     between successive components of an ARRAY OF CHAR.
  *)

PROCEDURE WriteLn (cid: ChanId);
  (* Writes a line mark over the channel *)

  (* Direct binary operations *)

PROCEDURE RawRead (cid: ChanId; to: SYSTEM.ADDRESS; maxLocs: CARDINAL;
                   VAR locsRead: CARDINAL);
  (* Reads at most maxLocs items and assigns corresponding values to
     successive locations starting at the address given by the parameter
     to.  The number of items read is assigned to the parameter locsRead.
     The stored read result is set to the value allRight, or endOfInput.
  *)

PROCEDURE RawWrite (cid: ChanId; from: SYSTEM.ADDRESS; locsToWrite: CARDINAL);
  (* Writes a number of items given by the value of the parameter
     locsToWrite from successive locations starting at the address given by
     the parameter from.
  *)

  (* Common operations *)

PROCEDURE GetName (cid: ChanId; VAR s: ARRAY OF CHAR);
  (* Copies to the parameter s a name associated with the channel,
     possibly truncated (depending on the capacity of s). *)

PROCEDURE Reset (cid: ChanId);
  (* Reset to a state defined by the device module. *)

PROCEDURE Flush (cid: ChanId);
  (* Flush any data buffered by the device module out to the destination. *)


  (* Access to read results *)

PROCEDURE SetReadResult (cid: ChanId; res: IOConsts.ReadResults);
  (* Sets the read result value for the channel to the value res. *)

PROCEDURE ReadResult (cid: ChanId) : IOConsts.ReadResults;
  (* Returns the stored read result value for the channel
     (This is initially the value notKnown).
  *)


  (* Users can discover which flags actually apply to a channel *)

PROCEDURE CurrentFlags (cid: ChanId) : ChanConsts.FlagSet;
  (* Returns the set of flags that currently apply to the given channel. *)


  (* The following exceptions are defined for this module and its clients *)

TYPE
  ChanExceptions =
    (ChanNoException,
       (* there is no exception in this context *)
     notChanException,
       (* there is an exception in this context, but from another source *)
     wrongDevice,
       (* device specific operation on wrong device *)
     notAvailable,
       (* operation attempted that is not available on that channel *)
     skipAtEnd,
       (* attempt to skip data from a stream that has ended *)
     softDeviceError,
       (* device specific recoverable error *)
     hardDeviceError,
       (* device specific non-recoverable error *)
     textParseError,
       (* input data does not correspond to a character or line mark -
       optional detection *)
     notAChannel
       (* given value does not identify a channel - optional detection *)
    );

PROCEDURE ChanException () : ChanExceptions;
  (* Returns the ChanException value for the current context. *)

  (* When a device procedure detects a device error, it raises the exception
     softDeviceError or hardDeviceError.  If these exceptions are handled, the
     following facilities may be used to discover an implementation-defined
     error number for the channel.
  *)

TYPE
  DeviceErrNum = INTEGER;

PROCEDURE DeviceError (cid: ChanId) : DeviceErrNum;
  (* If a device error exception has been raised, returns the error
     number stored by the device module.
  *)

END IOChan.
----cut here----
DEFINITION MODULE ChanConsts;

  (* Common types and values for device open requests and results *)

  (* Device modules may allow combinations of the following flags to be given
     when a channel is opened.  A channel opening procedure may not be able
     to accept or honour all combinations.
  *)

TYPE
  ChanFlags = (
    readFlag,
      (* input operations are requested/available *)
    writeFlag,
      (* output operations are requested/available *)
    oldFlag,
      (* a file may/must/did exist before the channel was opened *)
    textFlag,
      (* text operations are requested/available *)
    binaryFlag,
      (* binary operations are requested/available *)
    interactiveFlag,
      (* interactive use is requested/applies *)
    echoFlag
      (* echoing by interactive device on removal of characters from input
         stream requested/applies
      *)
  );

  FlagSet = SET OF ChanFlags;

  (* Singleton values of FlagSet, to allow for example, read + write *)

CONST
  read = FlagSet{readFlag};
    (* input operations are requested/available *)
  write = FlagSet{writeFlag};
    (* output operations are requested/available *)
  old = FlagSet{oldFlag};
    (* a file may/must/did exist before the channel was opened *)
  text = FlagSet{textFlag};
    (* text operations are requested/available *)
  binary = FlagSet{binaryFlag};
    (* binary operations are requested/available *)
  interactive = FlagSet{interactiveFlag};
    (* interactive use is requested/applies *)
  echo = FlagSet{echoFlag};
    (* echoing by interactive device on removal of characters from input
    stream requested/applies *)

  (* Possible results of open requests *)

TYPE
  OpenResults =
    (opened,
       (* the open succeeded as requested *)
     wrongNameFormat,
       (* given name is in the wrong format for the implementation *)
     wrongFlags,
       (* given flags include a value that does not apply to the device *)
     tooManyOpen,
       (* this device cannot support any more open channels *)
     outOfChans,
       (* no more channels can be allocated *)
     wrongPermissions,
       (* file or directory permissions do not allow request *)
     noRoomOnDevice,
       (* storage limits on the device prevent the open *)
     noSuchFile,
       (* a needed file does not exist *)
     fileExists,
       (* a file of the given name already exists when a new one is required *)
     wrongFileType,
       (* the file is of the wrong type to support the required operations *)
     noTextOperations,
       (* text operations have been requested but are not supported *)
     noBinaryOperations,
       (* binary operations have been requested but are not supported *)
     noMixedOperations,
       (* text and binary operations have been requested but they
          are not supported in combination *)
     otherProblem
       (* open failed for some other reason *)
     );

END ChanConsts.
----cut here----

Need more? The set of definitions incl. the number/string conversions and
SysClock modules was uploaded into 
              CompuServe's CodePort Forum (Lib 11 "ISO Modula-2").

> >PS.: Please don't tell me that your compiler kit doesn't include these modules
> >  (talk to your compiler developer/vendor)!
> 
>   Which compilers (if any) do include these modules?

ModulaWare's MVR V3.16 (released Friday, 13-Mar-1992)
  An implementation note was posted in this newsgroup late March '92
  Source code in Modula-2 is available under certain conditions. Most
  modules are portable by recompilation.
  Please contact ModulaWare GmbH, Email/Internet: 100023.2527@compuserve.com

Cheers,
G~unter Dotzel
Email: g_dotzel@ame.nbg.sub.org