      SUBROUTINE MAIN
      LOGICAL*1 NAME(40), ARG(400), ARGS(256), IMAGE(40), PID(7)
      INTEGER K, I, N, TYPE, VERBOS, COUNT
      INTEGER GETARG, GETLIN, LENGTH, LOCCOM, SSPAWN
      LOGICAL*1 SH(3)
      LOGICAL*1 LOCAL(6)
      DATA SH(1)/115/,SH(2)/104/,SH(3)/0/
      DATA LOCAL(1)/108/,LOCAL(2)/111/,LOCAL(3)/99/,LOCAL(4)/97/,LOCAL(5
     *)/108/,LOCAL(6)/0/
      VERBOS = 0
      I=1
23000 IF(.NOT.(GETARG(I, ARG, 400) .NE. -1))GOTO 23002
      IF(.NOT.(ARG(1) .NE. 45))GOTO 23003
      GOTO 23002
23003 CONTINUE
      IF(.NOT.(ARG(2) .EQ. 118 .OR. ARG(2) .EQ. 86))GOTO 23005
      VERBOS = 1
      GOTO 23006
23005 CONTINUE
      CALL PUTLIN(ARG, 3)
      CALL REMARK(29H : ignoring invalid argument.)
23006 CONTINUE
23004 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      IF(.NOT.(GETARG(I, NAME, 40) .EQ. -1))GOTO 23007
      CALL ERROR(35Husage:  args [-v] tool [arguments].)
23007 CONTINUE
      K = 1
      COUNT = 1
23009 IF(.NOT.(GETARG(I, ARG, 400) .NE. -1))GOTO 23011
      CALL PACKIT(COUNT, ARG, ARGS, K, 256)
      COUNT = COUNT + 1
23010 I=I+1
      GOTO 23009
23011 CONTINUE
      N=GETLIN(ARG, 1)
23012 IF(.NOT.(N .NE. -1))GOTO 23014
      IF(.NOT.(N .GT. 1))GOTO 23015
      ARG(N) = 0
      CALL PACKIT(COUNT, ARG, ARGS, K, 256)
      COUNT = COUNT + 1
23015 CONTINUE
23013 N=GETLIN(ARG, 1)
      GOTO 23012
23014 CONTINUE
      ARGS(K) = 0
      ARG(1) = 0
      I = 2
      CALL MAILID(IMAGE, ARG(I))
      I = I + LENGTH(ARG(I)) + 1
      CALL GETDIR(2, 6, ARG(I))
      I = I + LENGTH(ARG(I)) + 1
      CALL GETDIR(1, 6, ARG(I))
      I = I + LENGTH(ARG(I)) + 1
      ARG(I) = 10
      ARG(I+1) = 0
      TYPE = LOCCOM(NAME, ARG, IMAGE)
      IF(.NOT.(TYPE .EQ. -3))GOTO 23017
      CALL SCOPY(LOCAL, 1, IMAGE, 1)
      GOTO 23018
23017 CONTINUE
      IF(.NOT.(TYPE .EQ. 12))GOTO 23019
      IF(.NOT.(LOCCOM(SH, ARG, IMAGE) .NE. 60))GOTO 23021
      CALL ERROR(31HCannot locate shell image file.)
      GOTO 23022
23021 CONTINUE
      I = 1
      CALL STCOPY(SH, 1, ARG, I)
      CALL CHCOPY(32, ARG, I)
      CALL SCOPY(ARGS, 1, ARG, I)
      I=1
23023 IF(.NOT.(ARG(I) .NE. 0))GOTO 23025
      IF(.NOT.(I .LT. 256))GOTO 23026
      ARGS(I) = ARG(I)
      GOTO 23027
23026 CONTINUE
      GOTO 23025
23027 CONTINUE
23024 I=I+1
      GOTO 23023
23025 CONTINUE
      ARGS(I) = 0
23022 CONTINUE
23019 CONTINUE
23018 CONTINUE
      IF(.NOT.(VERBOS .EQ. 1))GOTO 23028
      CALL REMARK(ARGS)
23028 CONTINUE
      IF(.NOT.(SSPAWN(IMAGE, ARGS, PID, 119) .EQ. -3))GOTO 23030
      CALL REMARK(ARGS)
      CALL REMARK(44H** Error spawning this command from args. **)
23030 CONTINUE
      RETURN
      END
      SUBROUTINE PACKIT(N, IN, OUT, OUTPTR, SIZE)
      INTEGER N, OUTPTR, SIZE, J, LEN
      INTEGER LENGTH, INDEX
      LOGICAL*1 IN(100), OUT(100)
      LOGICAL*1 REDIR(4)
      DATA REDIR(1)/60/,REDIR(2)/62/,REDIR(3)/63/,REDIR(4)/0/
      IF(.NOT.(N .GT. 1))GOTO 23032
      IF(.NOT.(OUTPTR .LT. SIZE))GOTO 23034
      CALL CHCOPY(32, OUT, OUTPTR)
      GOTO 23035
23034 CONTINUE
      CALL SIZERR(OUT, OUTPTR)
23035 CONTINUE
23032 CONTINUE
      J = 1
      IF(.NOT.(IN(1) .EQ. 64))GOTO 23036
      IF(.NOT.(INDEX(REDIR, IN(2)) .GT. 0))GOTO 23038
      J = 2
23038 CONTINUE
23036 CONTINUE
      LEN = LENGTH(IN(J))
      IF(.NOT.(OUTPTR+LEN .GE. SIZE))GOTO 23040
      CALL SIZERR(OUT, OUTPTR)
23040 CONTINUE
      CALL STCOPY(IN, J, OUT, OUTPTR)
      RETURN
      END
      SUBROUTINE SIZERR(BUF, N)
      INTEGER N
      LOGICAL*1 BUF(100)
      BUF(N) = 0
      CALL REMARK(BUF)
      CALL ERROR(28H** Command line too long. **)
      RETURN
      END
