[comp.sys.atari.st] ARGV definition

dag@per2.UUCP (Daniel A. Glasser) (04/13/89)

This is posted for a friend who works at Mark Williams Company and does
not have direct access to news.  Please E-mail replies to rec@mwc.uucp.

--------------------------------------------------------
Subject: ARGV definition

For those who don't have MWC documentation, or do but don't RTFM, here
is the definition of the MWC argument passing convention.  I'm quoting
from the 1986 manual, but the text, and the convention, hasn't changed
in substance.  This is the from the article for 'crts0.o' which I found
by following the cross-references from 'argv'.

"The runtime startup module, crts0.o, is the first code executed when
"your program is run.  As its first action, it parses the environment
"string list passed by TOS into a vector of string pointers.  This
"vector is saved in the variable external char **environ, for the use
"of the library routine getenv(), and passed as the parameter char **
"envp[], for the information of the function main().
"
"If the environment vector contains a parameter named ARGV, then the
"run time start-up assumes that the program was executed by msh (or
"by some other program that agrees that programs should have arguments),
"and that the remainder of the environment vector is an argument vector
"that should be passed as the parameter char *argv[] to the function
"main().
"
"If the argument ARGV has a value, such as ARGV=CCAP??, then the
"value should consist of characters from the set [CAPF?].  The char-
"acters describe the origin of the system file handles as Console,
"Auxiliary port, Printer port, File, or unknown.  The runtime startup
"stores the value of ARGV, if it exists, into the external variable
"char *_iovector for the use of the routines that emulate the
"functions of the COHERENT operating system.
"
"If no ARGV parameter is found in the environment, then the run time
"start-up program assumes that the program was executed by a simple
"GEMDOS Pexec().  The buffer cmdtail is parsed to form the argument
"vector for main().  ARGV[0] is supplied by the external variable
"char _cmdname[], which should be supplied by your program, or it
"will be set to ? by the library.  The value of the variable _iovector
"will be set to the default CCAP?????????????????????????;.

The only change which I can detect in the latest revision of the
manual is that the crack about '(or by some other program which
agrees that programs should have arguments)' has been toned down.
I've always been a little caustic on this subject, :-).

The only change in the implementation not yet noted in the article
is that the default value of argv[0] is now the empty string in
accordance with the draft proposed ANS c language.

Quoted material is Copyright (c) 1986 by Mark Williams Company.

-- rec --
-------- End of forwarded posting ----------
-- 
 _____________________________________________________________________________
    Daniel A. Glasser                           One of those things that goes
    uwvax!per2!dag                              "BUMP!!!(ouch)" in the night. 
 ---Persoft, Inc.---------465 Science Drive-------Madison, WI 53711-----------

apratt@atari.UUCP (Allan Pratt) (04/15/89)

In article <845@per2.UUCP> rec@mwc.uucp 
(Roger Critchlow @ Mark Williams Company) writes:
> [material deleted]
>
> "If the environment vector contains a parameter named ARGV, then the
> "run time start-up assumes that the program was executed by msh (...)
>
> Quoted material is Copyright (c) 1986 by Mark Williams Company.
> 
> -- rec --

This is the root of the problem, isn't it? There's no validation of the
arguments.  It could be that the program's PARENT was executed by msh,
and the program itself was executed by something which didn't know a
thing about ARGV. 

If every MWC tool and ARGV-compatible program checked to see if the
"ARGV" in its environment was really meant for its use, we'd have
much smaller objections to ARGV.

As it happens, the person(s) who wrote the execve code for the MWC
library DID leave a hook for validation: they made sure the command-line
length byte held 0x7f, which is the highest possible number this byte
can legally hold.  I always assumed the MWC startup code could say, "If
my command-line length byte isn't 0x7f, the ARGV in my environment can't
be meant for me."

Then ignorant programs which simply passed ARGV on to their children
wouldn't be harmed, because the children would know that the args aren't
meant for them.  The other problems of ignorant programs finding strange
things in their environments (each "argument" string appears as a
separate environment variables) are minor by comparison. 

============================================
Opinions expressed above do not necessarily	-- Allan Pratt, Atari Corp.
reflect those of Atari Corp. or anyone else.	  ...ames!atari!apratt