From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 30-MAR-1993 22:08:36.25
To:	Info-VAX@KL.SRI.COM
CC:	
Subj:	Re: Getting parameters.

In article <0096A48C.2D192E00.19784@obu.arknet.edu>, 
			    John Selph <selp001@obu.arknet.edu> writes:
>	I have seen lots of talk about telling the VAX how to send 
>parameters to a program.  I have done that a lot.  You see, I am a junior 
>CS major.  We have looked at system service routines (there are only a few 
>million).  What I want to know is how to get the command line parameters 
>from a VAX program.  The language isn't that important, since I know:  
>VAXpascal, VAX assembly, VAX fortran, etc.  I would prefer a demo in either 
>assembly or pascal.  Note that even though I know C, we don't have a C 
>compiler for our VAX so that won't help me.  Thanks!

    There are several ways to retrieve the command line within a program
written in an HLL.  The usual recommendation is LIB$GET_FOREIGN.  However,
it is even easier to use CLI$GET_VALUE($LINE).  I forget which volume
of the Run Time Library Routines it's in, but you will find the CLI routines
documented there.  If you're going to parse up the command line yourself,
that's about all you need to know.  If you'd like to put a nice DCL look
and feel on it, use the CLI$ routines along with a .CLD file so you can
define parameters and qualifiers.  

    I'm sure Arne Vaxhxj (sp?) can supply a better example in Pascal, but 
I'll include a Fortran program, and an associated .CLD filem that I was 
fooling around with in order to better understand LIB$GET_FOREIGN and the 
CLI$xxx, especially when invoked via RUN, a foreign command, MCR, or the
DCL verb defined by SET COMMAND TEST.

		Cheers, Ken
--
 Dr. Kenneth H. Fairfield    |   Internet: Fairfield@Slac.Stanford.Edu
 SLAC, P.O.Box 4349, MS 98   |   DECnet:   45537::FAIRFIELD (45537=SLACVX)
 Stanford, CA   94309        |   FAX:      (415) 926-4335
 ----------------------------------------------------------------------------
 These opinions are mine, not SLAC's, Stanford's, nor the DOE's...

--------------cut/here----------TEST.FOR-------------cut/here----------------

	PROGRAM TEST

	IMPLICIT NONE

	INCLUDE '($LIBDTDEF)'

	INTEGER*4 LIB$GET_FOREIGN, CLI$DCL_PARSE, CLI$PRESENT
	INTEGER*4 CLI$GET_VALUE, CLI$DISPATCH, GLB_ERROR, LENX
	INTEGER*4 LIB$INIT_DATE_TIME_CONTEXT, LIB$FORMAT_DATE_TIME

	EXTERNAL  TEST_CLD, CLI$_PRESENT,CLI$_ABSENT,CLI$_NEGATED

	INTEGER*4 ISS, LCMD, LLIN, LVAL, LVRB, LFOR, LSPC,LSH
	INTEGER*4 TIME_CTX, LEN_TIME
	CHARACTER*255 COMMAND, LINE, VALUE
	CHARACTER*31  TIMDAT_CTX /'|!Y4-!MN0-!D0|!H04:!M0:!S0.!C2|'/
	CHARACTER*80  TODAY
	character*16  TIMDAT
	CHARACTER*4 VERB

	ISS = CLI$GET_VALUE ('$VERB', LINE, LLIN)
	IF (.NOT.ISS) THEN
	  ISS = GLB_ERROR('CLI$GET_VALUE - $VERB/1',ISS)
	  CALL EXIT (ISS)
	ENDIF
	VERB = LINE(1:LLIN)
	LVRB = LLIN
	WRITE (6, *) ' $VERB/1 = ',VERB(1:LVRB)


	ISS = CLI$GET_VALUE ('$LINE', LINE, LLIN)
	IF (.NOT.ISS) THEN
	  ISS = GLB_ERROR('CLI$GET_VALUE - $LINE/1',ISS)
	  CALL EXIT (ISS)
	ENDIF
	WRITE (6, *) ' $LINE/2 = ',LINE(1:LLIN)

	LFOR = .TRUE.

	LSPC = INDEX(LINE(1:LLIN), ' ') - 1
	IF (LSPC.GT.1) LLIN = MIN(LLIN,LSPC)
	LSH  = INDEX(LINE(1:LLIN), '/') - 1
	IF (LSH.GT.1) LLIN = MIN(LLIN,LSH)
	LLIN = MIN (LLIN, 4)

	IF (VERB(1:LVRB).EQ.'TEST' .AND. LINE(1:LLIN).EQ.VERB(1:LLIN))
     >    LFOR = .FALSE.


	ISS = LIB$GET_FOREIGN (COMMAND, , LCMD)
	IF (.NOT.ISS) THEN
	  ISS = GLB_ERROR('LIB$GET_FOREIGN',ISS)
	  CALL EXIT (ISS)
	ENDIF

	LCMD = LENX(COMMAND)
	IF (LFOR) THEN
          WRITE (6,*) ' Invoked as a Foreign command, by MCR or RUN.'
          IF (LCMD.GT.0) THEN
            WRITE (6,*) ' COMMAND is: ', COMMAND(1:LCMD), '.'
            ISS = CLI$DCL_PARSE('TEST '//COMMAND(1:LCMD), TEST_CLD,,,)
            IF (.NOT.ISS) THEN
              ISS = GLB_ERROR('CLI$DCL_PARSE', ISS)
              CALL EXIT (ISS)
            ENDIF
          ELSE
            ISS = CLI$DCL_PARSE('TEST', TEST_CLD)
            IF (.NOT.ISS) THEN
              ISS = GLB_ERROR('CLI$DCL_PARSE', ISS)
              CALL EXIT (ISS)
            ENDIF
          ENDIF
        ENDIF

	ISS = LIB$INIT_DATE_TIME_CONTEXT (TIME_CTX, 
     >					  LIB$K_OUTPUT_FORMAT,
     >					  TIMDAT_CTX)
	IF (.NOT.ISS) THEN
	  ISS = GLB_ERROR('LIB$INIT_DATE_TIME_CONTEXT',ISS)
	  CALL EXIT(ISS)
	ENDIF
        
	TODAY = ' '
	CALL STR$TRIM (TODAY,TODAY,LEN_TIME)
	WRITE (6,*) 'The length of a single, blank character is ',
     >		    LEN_TIME
	ISS = LIB$FORMAT_DATE_TIME (TODAY,, TIME_CTX, LEN_TIME,
     >		        (LIB$M_DATE_FIELDS .OR. LIB$M_TIME_FIELDS))
	IF (.NOT.ISS) THEN
	  ISS = GLB_ERROR('LIB$FORMAT_DATE_TIME',ISS)
	  CALL EXIT(ISS)
	ENDIF

	TIMDAT = TODAY
	TIMDAT(11:11) = ':'
	WRITE (6,*) ' Today''s date and time is ',TIMDAT
	

	ISS = CLI$GET_VALUE ('$VERB', LINE, LLIN)
	IF (.NOT.ISS) THEN
	  ISS = GLB_ERROR('CLI$GET_VALUE - $VERB/2',ISS)
	  CALL EXIT (ISS)
	ENDIF
	WRITE (6, *) ' $VERB/2 = ',LINE(1:LLIN)

	ISS = CLI$GET_VALUE ('$LINE', LINE, LLIN)
	IF (.NOT.ISS) THEN
	  ISS = GLB_ERROR('CLI$GET_VALUE - $LINE/2',ISS)
	  CALL EXIT (ISS)
	ENDIF
	WRITE (6, *) ' $LINE/2 = ',LINE(1:LLIN)

	ISS =CLI$PRESENT('Q1')
	IF (ISS.NE.%LOC(CLI$_ABSENT)) THEN
    	  CALL CLI$GET_VALUE('Q1',VALUE,LVAL)
          IF (ISS.EQ.%LOC(CLI$_PRESENT)) THEN
    	    WRITE (6,*) ' Q1 present, value = "',VALUE(1:LVAL),'"'
	  ELSEIF (ISS.EQ.%LOC(CLI$_NEGATED)) THEN
    	    WRITE (6,*) ' Q1 negated, value = "',VALUE(1:LVAL),'"'
	  ENDIF
	ENDIF

	ISS =CLI$PRESENT('Q2')
	IF (ISS.NE.%LOC(CLI$_ABSENT)) THEN
	  CALL TEST_PROC
    	  CALL CLI$GET_VALUE('Q2',VALUE,LVAL)
          IF (ISS.EQ.%LOC(CLI$_PRESENT)) THEN
    	    WRITE (6,*) ' Q2 present, value = "',VALUE(1:LVAL),'"'
	  ELSEIF (ISS.EQ.%LOC(CLI$_NEGATED)) THEN
    	    WRITE (6,*) ' Q2 negated, value = "',VALUE(1:LVAL),'"'
	  ENDIF
	ENDIF



	CALL EXIT
	END

	INTEGER*4 FUNCTION TEST_PROC
	WRITE (6,*) ' Entered TEST_PROC'
	TEST_PROC = .TRUE.
	RETURN
	END

--------------cut/here----------TEST.FOR-------------cut/here----------------
--------------cut/here----------TEST.CLD-------------cut/here----------------

    DEFINE VERB TEST
    IMAGE TPC$USER:[FAIRFIELD.STAGE]TEST
    QUALIFIER Q1, NEGATABLE, VALUE(REQUIRED)  
    QUALIFIER Q2, SYNTAX=ALT, VALUE(REQUIRED)  
    DISALLOW  Q1 AND Q2
    PARAMETER P1, VALUE(TYPE=$FILE)
DEFINE SYNTAX ALT
    PARAMETER P1, VALUE(TYPE=$NUMBER)

--------------cut/here----------TEST.CLD-------------cut/here----------------

