      SUBROUTINE MAIN
      LOGICAL*1 NAME(40), ARG(512), 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)
      LOGICAL*1 USESTR(36)
      LOGICAL*1 FSUFF(11)
      LOGICAL*1 ISUFF(7)
      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/
      DATA USESTR(1)/117/,USESTR(2)/115/,USESTR(3)/97/,USESTR(4)/103/,US
     *ESTR(5)/101/,USESTR(6)/58/,USESTR(7)/32/,USESTR(8)/32/,USESTR(9)/9
     *7/,USESTR(10)/114/,USESTR(11)/103/,USESTR(12)/115/,USESTR(13)/32/,
     *USESTR(14)/91/,USESTR(15)/45/,USESTR(16)/118/,USESTR(17)/93/,USEST
     *R(18)/32/,USESTR(19)/116/,USESTR(20)/111/,USESTR(21)/111/,USESTR(2
     *2)/108/,USESTR(23)/32/,USESTR(24)/91/,USESTR(25)/97/,USESTR(26)/11
     *4/,USESTR(27)/103/,USESTR(28)/117/,USESTR(29)/109/,USESTR(30)/101/
     *,USESTR(31)/110/,USESTR(32)/116/,USESTR(33)/115/,USESTR(34)/93/,US
     *ESTR(35)/46/,USESTR(36)/0/
      DATA FSUFF(1)/46/,FSUFF(2)/115/,FSUFF(3)/104/,FSUFF(4)/0/,FSUFF(5)
     */46/,FSUFF(6)/116/,FSUFF(7)/115/,FSUFF(8)/107/,FSUFF(9)/0/,FSUFF(1
     *0)/10/,FSUFF(11)/0/
      DATA ISUFF(1)/46/,ISUFF(2)/116/,ISUFF(3)/115/,ISUFF(4)/107/,ISUFF(
     *5)/0/,ISUFF(6)/10/,ISUFF(7)/0/
      CALL QUERY(USESTR)
      VERBOS = 0
      I=1
23000 IF (.NOT.(GETARG(I, ARG, 512) .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 BADARG(ARG)
23006 CONTINUE
23004 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      IF (.NOT.(GETARG(I, NAME, 40) .EQ. -1))GOTO 23007
      CALL ERROR(USESTR)
23007 CONTINUE
      K = 1
      COUNT = 1
23009 IF (.NOT.(GETARG(I, ARG, 512) .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
      CALL IMPATH(ARG)
      TYPE = LOCCOM(NAME, ARG, FSUFF, 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
      CALL STRCPY(IMAGE, NAME)
      IF (.NOT.(LOCCOM(SH, ARG, ISUFF, 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 STCOPY(NAME, 1, ARG, I)
      N=1
23023 IF (.NOT.(ARGS(N) .NE. 0))GOTO 23025
      IF (.NOT.(ARGS(N) .EQ. 32 .OR. ARGS(N) .EQ. 9))GOTO 23026
      GOTO 23025
23026 CONTINUE
23024 N=N+1
      GOTO 23023
23025 CONTINUE
      CALL SCOPY(ARGS, N, ARG, I)
      I=1
23028 IF (.NOT.(ARG(I) .NE. 0))GOTO 23030
      IF (.NOT.(I .LT. 256))GOTO 23031
      ARGS(I) = ARG(I)
      GOTO 23032
23031 CONTINUE
      GOTO 23030
23032 CONTINUE
23029 I=I+1
      GOTO 23028
23030 CONTINUE
      ARGS(I) = 0
23022 CONTINUE
23019 CONTINUE
23018 CONTINUE
      IF (.NOT.(VERBOS .EQ. 1))GOTO 23033
      CALL REMARK(ARGS)
23033 CONTINUE
      IF (.NOT.(SSPAWN(IMAGE, ARGS, PID, 119) .EQ. -3))GOTO 23035
      CALL REMARK(ARGS)
      CALL REMARK(44H** Error spawning this command from args. **)
23035 CONTINUE
      RETURN
      END
      SUBROUTINE PACKIT(N, IN, OUT, OUTPTR, SIZE)
      INTEGER N, OUTPTR, SIZE, LEN
      INTEGER LENGTH
      LOGICAL*1 IN(100), OUT(100)
      IF (.NOT.(N .GT. 1))GOTO 23037
      IF (.NOT.(OUTPTR .LT. SIZE))GOTO 23039
      CALL CHCOPY(32, OUT, OUTPTR)
      GOTO 23040
23039 CONTINUE
      CALL SIZERR(OUT, OUTPTR)
23040 CONTINUE
23037 CONTINUE
      LEN = LENGTH(IN)
      IF (.NOT.(OUTPTR+LEN .GE. SIZE))GOTO 23041
      CALL SIZERR(OUT, OUTPTR)
23041 CONTINUE
      CALL STCOPY(IN, 1, 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
