C PARSE COMMAND LINE FOR ARGUMENTS C C This subroutine parses a given line into substrings C corresponding to arguments contained in the line. C The line may be supplied by the user on entry to the C subroutine if the first element of is nonzero. C Otherwise it attempts to retrieve the MCR command line C which activated the current task. This will be successful C if the task was installed with a task name ...XXX and run C as XXX cmd.line.... It will also work if the task is not C installed but run as RUN taskname/CMD="XXX cmd.line..." C Note that in both cases the first word is the command name C which is skipped by this routine. C If it cannot retrieve a command line, the user is prompted C with a colon for the command line, which is entered without C the command name at the beginning. C It then breaks up the rest of the command line into a C series of argument substrings. Each argument is terminated C by a space or a comma, and may have leading spaces. Two C commas together give a zero length argument. C The entire command line is returned in , and C is filled with the starting subscript into for each C argument. is set to the actual number of arguments C found. must be an integer array with at least as C many elements as there will be arguments. C On return, the first argument is LINE(IARG(1)), and has c length LENGTH(LINE(IARG(1))), and may be treated by use of C the variable length character string routines. Each such C substring is terminated by a zero byte which replaces the C terminator (comma or space). C It also allows command lines which consist of a single C argument of the form @filename, where the filename must C include extension. The routine will then read the first C line from the named file and use that as the new command C line. This line should include the command name before C the first argument as if it were given to MCR. This feature C is used when passing long command lines to routines through C CCL commands, where only about 40 bytes are available for C arguments. C should be declared as a byte array with at least C 82 elements. If the @filename feature is to be used, it C should have as much as 128 elements. C C C David Villeneuve C Division of Physics M23A C National Research Council C Ottawa Ont. K1A 0R6 C 613-993-9975 C SUBROUTINE PARSCL (LINE, IARG, NARG) BYTE LINE(1) INTEGER IARG(1) LOGICAL PAREN C C ATTEMPT TO RETRIEVE MCR COMMAND LINE UNLESS LINE IS GIVEN C NARG = 0 !ASSUME NO ARGS IFF (LINE(1) .EQ. 0) THEN { !LINE NOT GIVEN ON ENTRY CALL GETMCR (LINE, LLINE) !ATTEMPT TO RETRIEVE MCR LINE C C COULD NOT GET COMMAND LINE, PROMPT FOR ONE C 10 IFF (LLINE .LE. 0) THEN { !NO CMD LINE, PROMPT FOR LINE WRITE (5,%%) FORMAT (' : ', $) READ (5,%%) LLINE, (LINE(K),K=1,LLINE) FORMAT (Q, 80A1) IF (LLINE .LE. 0) RETURN LINE(LLINE+1) = 0 J1 = 1 !NO TASK NAME IN THE LINE } C C GOT A COMMAND LINE, DROP FIRST NAME ON LINE C ELSE { !DROP TASK NAME FROM FRONT LINE(LLINE+1) = 0 FOR J1=1,LLINE IF (LINE(J1) .EQ. ' ') GO TO 50 RETURN !NO ARGS ON LINE 50 } } C C A LINE WAS GIVEN AS THE FIRST ARGUMENT, USE IT C ELSE { J1 = 1 LLINE = 0 FOR J=1,4096 { !FIND LENGTH OF GIVEN LINE IF (LINE(J) .EQ. 0) GO TO 20 LLINE = LLINE+1 } 20 } C C SCAN THROUGH LINE, ENTERING START ADR OF EACH ARG INTO IARG C REPEAT { FOR J=J1,LLINE !SKIP LEADING BLANKS IF (LINE(J) .NE. ' ') GO TO 100 GO TO 500 !LAST ARG WAS ONLY BLANKS 100 NARG = NARG+1 IARG(NARG) = J !ENTER ARGUMENT ADR IN TABLE J1 = J PAREN = .FALSE. !TRUE WHEN INSIDE [uic] FOR J=J1,LLINE !LOOK FOR END OF ARG { IFF (LINE(J) .EQ. '[') THEN PAREN = .TRUE. ELSEIF (LINE(J) .EQ. ']') THEN PAREN = .FALSE. ELSEIF (.NOT. PAREN .AND. (LINE(J) .EQ. ',' .OR. LINE(J) .EQ. ' ' )) THEN GO TO 200 } GO TO 500 !LAST ARG C C PUT ZERO BYTE AT END OF ARGUMENT SUBSTRING C 200 LINE(J) = 0 !OVER TOP OF TERMINATOR J1 = J+1 !CONTINUE WITH NEXT CHARACTER } C C FINISHED PARSING LINE, CHECK FOR @FILENAME AS FIRST ARGUMENT. C WE USE LUN 5 FOR THIS SINCE WE DON'T WANT TO TIE UP ANY OTHERS. C 500 IFF (NARG .EQ. 1 .AND. LINE(IARG(1)) .EQ. '@') THEN { CALL CLOSE (5) CALL ASNLUN (5, 'SY', 0) CALL FDBSET (5, 'READONLY') CALL ASSIGN (5, LINE(IARG(1)+1)) READ (5,%%) LLINE, (LINE(K), K=1,LLINE) FORMAT (Q, 128A1) CALL CLOSE (5) CALL ASNLUN (5, 'TI', 0) CALL ASSIGN (5, 'TI:') NARG = 0 GO TO 10 } RETURN END FUNCTION PARVAL (LINE, IARG, NARG, INDEX, DEFALT) C C This is a companion routine to PARSCL, which is assumed to have been C called first. This routine will return a real number corresponding C to one of the arguments which was given on the command line. C The first three arguments are the same as those given in the C call to PARSCL. INDEX is the number of the argument which is C desired, from 1 up. DEFALT is the default value which is returned C if the desired argument was not given on the command line. C INTEGER IARG(1) BYTE LINE(1) C PARVAL = DEFALT IF (INDEX .GT. NARG) RETURN C L = LENGTH( LINE(IARG(INDEX)) ) IF (L .LE. 0) RETURN PARVAL = FPCONV( LINE(IARG(INDEX)), L, 1, LAST ) C RETURN END