[comp.sys.atari.st] command line arguments

psurge@cs.utexas.edu (Troy Carpenter) (01/05/91)

I am programming in either Personal Pascal or Modula 2.  I have this question:

How does one get a program in either of these languages to use arguments passed
from the command line.  For instance, say I wanted to write a .TTP dialer
called "dial".  From the command line I would type:

dial [number]

How do I get the program to recognize the variable "number" in either Personal
Pascal or Modula 2 (Modula 2 preferred).

Thanks in advance.


                                Troy Carpenter
                        Department of Computer Sciences
                        THE University of Texas, Austin
                              psurge@cs.utexas.edu

"You're so open minded that your brain leaked out" - Steve Taylor

*>>>>>>>>>>>>>>>>>> The best thing in life costs exactly that <<<<<<<<<<<<<<<*
 

davidli@simvax.labmed.umn.edu (01/07/91)

In article <16531@cs.utexas.edu>, psurge@cs.utexas.edu (Troy Carpenter) writes:
> How does one get a program in either of these languages to use arguments passed
> from the command line.

Personal Pascal 2 has special subprograms (called CMD_ARGS and CMD_GETARG())
to perform this function.  They were also available in Personal Pascal 1.

usage is describe on page 6-198 of the PP 2 manual and 6-94 of the PP 1
manual.  Basically:

Cmd_Args is an integer function which returns the number of arguments in the
TOS command line buffer.

Cmd_GetArg( i, request) is a procedure which assigns the requested command line
argument to the argument ('request' is a string variable, 'i' is an integer.

As for Modula-2, it would depend upon WHICH Modula-2 compiler you were using
and the nature of the libraries included with the compiler.

-- 

David Paschall-Zimbel		davidli@simvax.labmed.umn.edu

wolfram@cip-s06.informatik.rwth-aachen.de (Wolfram Roesler) (01/25/91)

psurge@cs.utexas.edu (Troy Carpenter) writes:

>How does one get a program in either of these languages to use arguments passed
>from the command line. 

It's quite easy if you get the adress of your program's basepage. The adress of
the command line as passed to the program is found in the basepage (sorry I don't
know the precise offset). This is a pointer to a string of bytes terminated
with a 0-byte. I dont know houw to get this using Pascal or M2.

Getting hold of the program's calling name is not possible by legal means. You
can of course check the basepage for the paren't basepage, check this one for
the user stackpointer and use that in turn to get the parameters of the last
command executed, which is Pexec with one of the parameters being the calling
path of your program.

My recommendation: turn to the true programming languages, use C and leave that
problem to the runtime library. Pascal and M2 aren't made to fool arount in the
system on a level as deep as that one needs to know that a byte is 8 bits long. :-)

Greetings to US, give my regards to JR