        SUBROUTINE CLIARGS(LCHAR,STRING,ITYPE,LARG)
!****************************************************************************
!*                                                                          *
!*  COPYRIGHT (c) 1982                                                      *
!*  By Westinghouse Electric Corporation                                    *
!*                                                                          *
!*  THIS SOFTWARE IS FURNISHED WITHOUT LICENSE AND MAY BE USED AND COPIED   *
!*  ONLY WITH THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.                  *
!*                                                                          *
!*  THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE    *
!*  AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY WESTINGHOUSE.            *
!*                                                                          *
!*  WESTINGHOUSE ASSUMES NO RESPONSIBILITY FOR THE USE OR  RELIABILITY      *
!*  OF THIS SOFTWARE.                                                       *
!*                                                                          *
!****************************************************************************
C               This routine gets the CLI string and sends it to CLIPARSE
C       which returns the separate elements one at a time.  In order to
C       force the DCL (CLI) to pass the string intact, it is necessary to
C       define a symbol in the following manner:
C               To execute a program called PROGRAM.EXE in directory [XXX]
C       on disk DBA1, define:
C
C               PROG :== $DBA1:[XXX]PROGRAM
C
C       This would then be execute via:
C
C               PROG/QUAL1 NAME/QUAL2 NAME/QUAL3 ..........etc.
C
C       The subroutine arguments are defined as follows:
C
C       Name    In/Out  Type    Function
C       LCHAR   IN/OUT  I4      This variable serves as both a flag and
C                               indicates the next character to be processed
C                               from CLISTR.  It MUST be called with a variable,
C                               not a constant, since its value will be changed.
C                               It should initially be set to 0
C       STRING  OUT     STRING  This variable will receive each token in turn
C                               as it is parsed from the CLI input string.
C                               Items are defined as either objects or
C                               qualifiers. Thus in the string TEAR/W XYZ/ABC
C                               TEAR and XYZ are objects, W and ABC are qual-
C                               ifiers.
C       ITYPE   OUT     I4      This variable indicates the type of token
C                               being returned and also serves as a flag
C                               of no more data or error encountered.
C                               ITYPE=-1        Error (STRING too short)
C                               ITYPE=0         No More Data (LCHAR also set 0)
C                               ITYPE=1         Object being returned
C                               ITYPE=2         Qualifier being returned
C       LARG    OUT     I4      Number of characters loaded into STRING
C
        CHARACTER*(*) STRING
        INTEGER*4 A(7)
        EXTERNAL SYS$CLI
C
        A(1)=1
        IF(LCHAR.LE.0) CALL SYS$CLI(%REF(A))
        CALL CLIPARSE(A(3),LCHAR,STRING,ITYPE,LARG)
        RETURN
        END
C
C
C

        SUBROUTINE CLIPARSE(CLISTR,LCHAR,STRING,ITYPE,LARG)
C               This routine parses the CLI string sent by CLIARGS
C       and returns the separate elements one at a time. The subroutine
C       arguments are deefined as follows:
C
C       Name    In/Out  Type    Function
C       CLISTR  IN      STRING  This is the input string from the CLI
C                               and will normally be obtained via CLIARGS
C       LCHAR   IN/OUT  I4      This variable serves as both a flag and
C                               indicates the next character to be processed
C                               from CLISTR.  It MUST be called with a variable,
C                               not a constant, since its value will be changed.
C                               It should initially be set to 0
C       STRING  OUT     STRING  This variable will receive each token in turn
C                               as it is parsed from the CLI input string.
C                               Items are defined as either objects or
C                               qualifiers. Thus in the string TEAR/W XYZ/ABC
C                               TEAR and XYZ are objects, W and ABC are qual-
C                               ifiers.
C       ITYPE   OUT     I4      This variable indicates the type of token
C                               being returned and also serves as a flag
C                               of no more data or error encountered.
C                               ITYPE=-1        Error (STRING too short)
C                               ITYPE=0         No More Data (LCHAR also set 0)
C                               ITYPE=1         Object being returned
C                               ITYPE=2         Qualifier being returned
C
C       LARG    OUT     I4      Number of characters loaded into STRING
C
        CHARACTER *(*) CLISTR,STRING
        CHARACTER CH
C
        LCLI=LEN(CLISTR)
        LSTR=LEN(STRING)
        STRING=' '
        IF(LCHAR.LT.0) LCHAR=0
        LCHAR=LCHAR+1                   !Increment the character pointer
        IF(LCHAR.GT.LCLI) THEN
          ITYPE=0
          LCHAR=0
          RETURN
        ENDIF
C
C       ICHAR should now point to the first character of either a qualifier
C       or an object.  If a qualifier, it must start with a (/).  If not,
C       assume it is an object.
C
        ITYPE=1                                 !Assume an object
        IF(CLISTR(LCHAR:LCHAR).EQ.'/') THEN
          ITYPE=2                               !Must be a qualifier
          LCHAR=LCHAR+1
        ENDIF
C
C       Look for '/' or blank to terminate this token
C
        I=1
 100    IF(LCHAR.LE.LCLI) THEN
          CH=CLISTR(LCHAR:LCHAR)
          IF(CH.NE.'/' .AND. CH.NE.' ') THEN
            IF(I.LE.LSTR) THEN
              STRING(I:I)=CH
              LARG=I
              I=I+1
              LCHAR=LCHAR+1
            ELSE
C              TYPE *,'CLIARGS:CLIPARSE ERROR:'
C              TYPE *,' SUPPLIED STRING TOO SHORT'
C              ITYPE=-1
C              LCHAR=0
              LCHAR=LCHAR-1
              RETURN
            ENDIF
          ELSE
            IF(CH.EQ.'/') LCHAR=LCHAR-1
            RETURN
          ENDIF
        ELSE
          RETURN
        ENDIF
        GO TO 100
        END
