[comp.lang.pascal] Programming ... Pascal

start@chief.UUCP (CompuInvest BBS system ) (02/24/89)

How does one set up a program to read in parameters from the command line?

Ex. :

Shell> pascal.prg -param1 -param2
                   ^^^^^^  ^^^^^^
                   ||||||  ||||||
How does one accomplish this in standard (ISO) Pascal, if it is even
possible?  Or, if turbo Pascal will accomlish this, how?

I am using a Pascal compiler for my Amiga (Metacomco's MCC Pascal V2).

Any help, of course would be appreciated!


Thanks,

Robert Cooper

fargo@pawl.rpi.edu (Ethan M. Young) (02/28/89)

In article <495@chief.UUCP> start@chief.UUCP (CompuInvest BBS system ) writes:
>
>How does one set up a program to read in parameters from the command line?
>
>Ex. :
>
>Shell> pascal.prg -param1 -param2
>                   ^^^^^^  ^^^^^^
>                   ||||||  ||||||
>How does one accomplish this in standard (ISO) Pascal, if it is even
>possible?  Or, if turbo Pascal will accomlish this, how?
>

In Turbo Pascal (at least 3.0), there are two variables called ParamCount and
ParamStr.  ParamCount is of type integer and contains the number of blank-
separated parameters on the command line.  

ParamStr is an ARRAY of strings, each string being the appropriate parameter,
starting at index 1 (It may be 0)

If I remember correctly, standard Pascal has no method on reading in the com-
mand line parameters.  It is completely implementation specific.

Thank you and happy hunting!   Internet: fargo@pawl.rpi.edu
    ____    [> SB <]                     fargo@{paraguay|uruguay}.acm.rpi.edu
   /__      -=>??<=-        Bitnet (??): usergac0@rpitsmts.bitnet
  /   ARGO : 3000 years of regression from the year 4990

mikej@pyr1.acs.udel.EDU (Michael Jacobs) (02/28/89)

In article <772@rpi.edu> fargo@pawl.rpi.edu (Ethan M. Young) writes:
>In article <495@chief.UUCP> start@chief.UUCP (CompuInvest BBS system ) writes:
>>How does one set up a program to read in parameters from the command line?
>>Shell> pascal.prg -param1 -param2
>
>In Turbo Pascal (at least 3.0), there are two variables called ParamCount and
>ParamStr.  ParamCount is of type integer and contains the number of blank-
>separated parameters on the command line.  
>
>ParamStr is an ARRAY of strings, each string being the appropriate parameter,
>starting at index 1 (It may be 0)

It's not an array, it's a function.  It makes a difference wether you use
()'s or []'s.  The parameter of the ParamStr function is the ordinal number
of the parameter you want.  ParamStr(0) will return the name of the 
program you executed.

Mike J, The Grey Sysop...   |  Ancient Spirits of Evil, transform this
Temporal Hitchhiker         |  decayed form into Mumm-ra, the Ever Living!
mikej@vax1.acs.udel.EDU     |  

abcscnuk@csuna.csun.edu (Naoto Kimura) (02/28/89)

In article <495@chief.UUCP> start@chief.UUCP (CompuInvest BBS system ) writes:
>
>How does one set up a program to read in parameters from the command line?
>
>Ex. :
>
>Shell> pascal.prg -param1 -param2
>                   ^^^^^^  ^^^^^^
>                   ||||||  ||||||
>How does one accomplish this in standard (ISO) Pascal, if it is even
>possible?  Or, if turbo Pascal will accomlish this, how?
>
>I am using a Pascal compiler for my Amiga (Metacomco's MCC Pascal V2).
>
>Any help, of course would be appreciated!
>
>
>Thanks,
>
>Robert Cooper

Hmmmm... I seem to remember such a similar query just a month ago...

As far as I know, there is no standard way of doing so.   There is
still some hope, because many implementations of pascal will have
ways to access the command line.

Here are some implementations that I know of that allow access to the
command line parameters:

(VM/CMS)
PASCAL/VS	If I recall, R0 is used to point to the unparsed command
		line string.   You had to write some assembly code to
		be able to gain access to it.   There was also a
		way to gain access to the parsed arguments (though they
		were limited to 8 characters).

(MS/PC-DOS)
Turbo Pascal	Use the ParamCount function to find out how many
		argument strings there were, and the ParamStr(n)
		function to get the n'th argument string.  Version 5.0
		allows you to use ParamStr(0) to get the fully qualified
		filename of the executable.  You could probably also
		look somewhere in the PSP.

(NOS)
CDC Pascal	There is an include file to access parts of the command line.
		You had to use either a function or procedure to obtain the
		value of a option.

(Unix)
Berkeley	This compiler allows access to the argument count and
		argument strings via the 'argc' function and the
		'argv' function.

                //-n-\\			 Naoto Kimura
        _____---=======---_____		 (abcscnuk@csuna.csun.edu)
    ====____\   /.. ..\   /____====
  //         ---\__O__/---         \\	Enterprise... Surrender or we'll
  \_\                             /_/	send back your *&^$% tribbles !!

chan@valhalla.ee.rochester.edu (03/01/89)

To: abcscnuk@csuna.csun.edu
In-Reply-To: <1719@csuna.csun.edu>
References: <495@chief.UUCP>

!In article <495@chief.UUCP> start@chief.UUCP (CompuInvest BBS system ) writes:
!>
!>How does one set up a program to read in parameters from the command line?
!>
!>Ex. :
!>
!>Shell> pascal.prg -param1 -param2
!>                   ^^^^^^  ^^^^^^
!>                   ||||||  ||||||
!>How does one accomplish this in standard (ISO) Pascal, if it is even
!>possible?  Or, if turbo Pascal will accomlish this, how?
!>
!>I am using a Pascal compiler for my Amiga (Metacomco's MCC Pascal V2).
!>
!> Any help, of course would be appreciated!
!>
!>
!>Thanks,
!>
!>Robert Cooper
!
!Hmmmm... I seem to remember such a similar query just a month ago...
!
!As far as I know, there is no standard way of doing so.   There is
!still some hope, because many implementations of pascal will have
!ways to access the command line.
!
!Here are some implementations that I know of that allow access to the
!command line parameters:
!
!(VM/CMS)
!PASCAL/VS	If I recall, R0 is used to point to the unparsed command
!		line string.   You had to write some assembly code to
!		be able to gain access to it.   There was also a
!		way to gain access to the parsed arguments (though they
!		were limited to 8 characters).
!

If I am right, PARMS is a function with no argument in VSPASCAL 
that will return command line arguments in the form of a string.
If you want to know more, I can look up the detail for you.

-dan.