🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #83

Re: argc and *argv in Modula-2 ?

#83
From: Guenter Dotzel
Date: Tue, 07 Apr 1992 07:00
141 lines
5112 bytes
INFO-M2\%UCF1VM.BITNET%cmsa.Berkeley.EDU@USENET.ZER wrote on Tue, 03-31-1992 at 09:15 h
under the subject 'argc and *argv in Modula-2 ?':

> Someone was how 'argc' and '*argv' could be implemented in Modula-2.
> 
> Modula2 library is not standardized as C library is. How to implement these
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> two C procedure depends on computer and M2 implementation which you use.
> I you, for example, used PC and TopSpeed IDE, the answer you could find in
> module Lib.
> 
> DEFINITION MODULE Lib;
> PROCEDURE ParamStr(VAR S: ARRAY OF CHAR; N: CARDINAL);
> PROCEDURE ParamCount();
> END Lib.

Oh, Oh! Please, take a look at the ISO M2 Standard I/O-Library:

DEFINITION MODULE ProgramArgs;

  (* Access to program arguments *)

IMPORT IOChan;

TYPE
  ChanId = IOChan.ChanId;

PROCEDURE ArgChan () : ChanId;
  (* The returned value identifies a channel for reading program arguments *)

PROCEDURE IsArgPresent () : BOOLEAN;
  (* Tests if there is a current argument to read from.
     If not, read <= IOChan.CurrentFlags() will be FALSE, and attempting to
     read from the argument channel will cause the exception notAvailable
     to be raised.
     Initially, and after a reset operation on the channel, if there are no
     program arguments a call of IsArgPresent returns FALSE, otherwise
     input is taken from the first argument to the program, as defined for
     the implementation.
  *)

PROCEDURE NextArg;
  (* If there is another argument, causes subsequent input from the
     argument device to come from the start of the next argument.  Otherwise
     there is no argument to read from, and a call of IsArgPresent will
     return FALSE.
  *)

END ProgramArgs.

DEFINITION MODULE IOChan;
  (* Types and procedures forming the interface to channels for
     device-independent data transfer modules
  *)
IMPORT IOConsts, ChanConsts, SYSTEM;

[.................................rest cut out to keep the message short...]

DEFINITION MODULE IOConsts;

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

[.................................rest cut out to keep the message short...]

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.
  *)

[.................................rest cut out to keep the message short...]

> In the case of using VAX and Logitech M2 for it, the answer would be
> completely different:
> 
> %FOREIGN DEFINITION MODULE CLI$;
>
> [....$.........$.........$...........VMS dependent stuff cut out.....]
>
> END CLI$.

Oh, oh, take care! That's recreational programming :-)
Use the ISO M2 I/O-Lib now! You don't have one for your compiler?
Did you ask Logitech for an upgrade/update? 

----->commercial starts here:
We have implemented the full ISO M2 I/O-Lib module set for VAX/VMS.
It's part of ModulaWare's MVR V3.16 release, available since 13-Mar-1992. 
<-----commercial ends here.

And here is my favorite copy text file example; it runs on VAX/VMS,
believe it or not. When installed as a foreign command you could 
invoke it with the command:

$ ISOCopy in_file out_file

MODULE ISOCopy;
(* copy a textfile from file arg1 to arg2 using the ISO M2 I/O-Library *)
FROM ProgramArgs IMPORT IsArgPresent, ArgChan;
FROM IOResult IMPORT ReadResults, ReadResult;  
FROM SeqFile IMPORT OpenRead, OpenWrite, OpenResults, Close, ChanId, read, write;
FROM TextIO IMPORT ReadRestLine, SkipLine, WriteLn, WriteString;
TYPE fnam: ARRAY [0..254] OF CHAR;
VAR in,out: fnam;
  ores: OpenResults;
  input, output: ChanId;
  line: ARRAY[0..8191] OF CHAR;
BEGIN
  IF (ReadResult(ArgChan()) <> endOfInput) THEN
    ReadToken(ArgChan(), in);
    IF (ReadResult(ArgChan()) <> endOfInput) THEN
      ReadToken(ArgChan(), out);
      OpenRead(input, in, read, ores); 
      OpenWrite(output, out, write, ores);
      ReadRestLine(input, line);
      WHILE ReadResult(input) <> endOfInput DO
        IF ReadResult(input) = allRight THEN 
          WriteString(output, line); WriteLn(output);
        ELSE WriteLn(output);
        END;
        SkipLine(input); ReadRestLine(input, line);
      END;
      Close(input);
      Close(output);
    END;
  END;
END ISOCopy.

> Good luck!
  You need it!
> Anes Sadikovic

Cheers, G~unter

Guenter Dotzel, ModulaWare GmbH, Wilhelmstr. 17A, D-W 8520 Erlangen/F.R.Germany
Tel. +49 (9131) 208395, Fax +49 (9131) 28205. 
E-mail/Internet:  g_dotzel@ame.nbg.sub.org 
E-Mail/CompuServe:100023.2527@compuserve.com  GO CODEPORT! (ISO Modula-2)
Technical Details
Message-ID: <246386365P@tron.gun.de>
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!sol.ctr.columbia.edu!ira.uka.de!smurf.sub.org!easix.GUN.de!tron

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!sol.ctr.columbia.edu!ira.uka.de!smurf.sub.org!easix.GUN.de!tron
From: g_dotzel@tron.gun.de (Guenter Dotzel)
Newsgroups: comp.lang.modula2
Subject: Re: argc and *argv in Modula-2 ?
Message-ID: <246386365P@tron.gun.de>
Date: Tue, 7 Apr 92 07:00:28 GMT
Lines: 142