      INTEGER FUNCTION SSPAWN(IMAGE, ARGS, PID, WAIT)
      LOGICAL*1 IMAGE(40), ARGS(256), PID(7), LOCAL(6), WAIT, MCRLIN(80)
     *, FILARG(40)
      LOGICAL*1 CLOWER
      REAL MCR
      INTEGER EQUAL, UNIT, CREATE, LENGTH, N, ERRSB(8), IDS, BCKSPN
      COMMON / CSPAWN / EFN, IFFORE, IFBACK, IFBAST, FOREPC(7), BACKPC(7
     *), TASKNM(7), PRIOST(5)
      INTEGER EFN
      INTEGER IFFORE
      INTEGER IFBACK
      INTEGER IFBAST
      LOGICAL*1 FOREPC
      LOGICAL*1 BACKPC
      LOGICAL*1 TASKNM
      LOGICAL*1 PRIOST
      DATA LOCAL/108, 111, 99, 97, 108, 0/
      data mcr/6RMCR.../
      IF(.NOT.(CLOWER(WAIT) .EQ. 98))GOTO 23000
      SSPAWN=(BCKSPN(IMAGE, ARGS, PID))
      RETURN
23000 CONTINUE
      CALL SCOPY(IMAGE, 1, MCRLIN, 1)
      CALL FOLD(MCRLIN)
      IF(.NOT.(EQUAL(MCRLIN, LOCAL) .EQ. 1))GOTO 23002
      CALL SCOPY(ARGS, 1, MCRLIN, 1)
      GOTO 23003
23002 CONTINUE
      CALL GENPNM(1, PID)
      CALL ARGFIL(PID, FILARG)
      UNIT = CREATE(FILARG, 2)
      IF(.NOT.(UNIT .EQ. -3))GOTO 23004
      SSPAWN = -3
      RETURN
23004 CONTINUE
      IF(.NOT.(LENGTH(ARGS) .GT. 0))GOTO 23006
      CALL PUTLIN(ARGS, UNIT)
      GOTO 23007
23006 CONTINUE
      CALL PUTCH(32, UNIT)
23007 CONTINUE
      CALL PUTCH(10, UNIT)
      CALL CLOSE(UNIT)
      CALL GENRUN(IMAGE, PID, PRIOST, MCRLIN)
23003 CONTINUE
      N = LENGTH(MCRLIN)
      EFN = 7
      CALL EXTPNM(MCRLIN, FOREPC)
      CALL SCOPY(FOREPC, 1, PID, 1)
      IFFORE = 1
      CALL WTQIO(1024, 8)
      call spawn(mcr,,, efn,, errsb,, mcrlin, n, 0,, ids)
      IF(.NOT.(IDS .LE. 0))GOTO 23008
      IFFORE = 0
      SSPAWN = -3
      GOTO 23009
23008 CONTINUE
      CALL STOPFR(7, IDS)
      IFFORE = 0
      IF(.NOT.(ERRSB(1) .GT. 1))GOTO 23010
      SSPAWN = -3
      GOTO 23011
23010 CONTINUE
      SSPAWN = 0
23011 CONTINUE
23009 CONTINUE
      CALL WTQIO(768, 8)
      RETURN
      END
      INTEGER FUNCTION GENPNM(PNUM, PID)
      LOGICAL*1 PARENT(7), PID(7)
      INTEGER INIT, PNUM, SPERR
      DATA INIT/1/
      IF(.NOT.(INIT .EQ. 1))GOTO 23012
      CALL GETPNM(PARENT)
      IF(.NOT.((PARENT(1) .EQ. 36 .OR. PARENT(1) .EQ. 46) .AND. (PARENT(
     *2) .EQ. 84 .OR. PARENT(2) .EQ. 66)))GOTO 23014
      IF(.NOT.(PARENT(6) .EQ. 57))GOTO 23016
      SPERR = 1
      GOTO 23017
23016 CONTINUE
      SPERR = 0
      PARENT(6) = PARENT(6) + 1
23017 CONTINUE
      GOTO 23015
23014 CONTINUE
      CALL GTTY(PARENT)
      PARENT(1) = 36
      IF(.NOT.(PARENT(4) .EQ. 58))GOTO 23018
      PARENT(4) = PARENT(3)
      PARENT(3) = 48
23018 CONTINUE
      PARENT(5) = 46
      PARENT(6) = 49
23015 CONTINUE
      PARENT(7) = 0
      INIT = 0
23012 CONTINUE
      IF(.NOT.(SPERR .EQ. 1))GOTO 23020
      GENPNM = -3
      GOTO 23021
23020 CONTINUE
      GENPNM = 0
      CALL SCOPY(PARENT, 1, PID, 1)
23021 CONTINUE
      RETURN
      END
      SUBROUTINE GENRUN(IMAGE, PID, PRIO, LINE)
      LOGICAL*1 IMAGE(100), PID(100), LINE(100), PRIO(100)
      INTEGER I
      LOGICAL*1 INS(5)
      LOGICAL*1 TASK(7)
      LOGICAL*1 PRIOST(6)
      LOGICAL*1 RUN(10)
      DATA INS(1)/105/,INS(2)/110/,INS(3)/115/,INS(4)/32/,INS(5)/0/
      DATA TASK(1)/47/,TASK(2)/116/,TASK(3)/97/,TASK(4)/115/,TASK(5)/107
     */,TASK(6)/61/,TASK(7)/0/
      DATA PRIOST(1)/47/,PRIOST(2)/112/,PRIOST(3)/114/,PRIOST(4)/105/,PR
     *IOST(5)/61/,PRIOST(6)/0/
      DATA RUN(1)/46/,RUN(2)/47/,RUN(3)/114/,RUN(4)/117/,RUN(5)/110/,RUN
     *(6)/61/,RUN(7)/114/,RUN(8)/101/,RUN(9)/109/,RUN(10)/0/
      I = 1
      CALL STCOPY(INS, 1, LINE, I)
      CALL STCOPY(IMAGE, 1, LINE, I)
      CALL STCOPY(TASK, 1, LINE, I)
      CALL STCOPY(PID, 1, LINE, I)
      CALL STCOPY(PRIOST, 1, LINE, I)
      CALL STCOPY(PRIO, 1, LINE, I)
      CALL SCOPY(RUN, 1, LINE, I)
      RETURN
      END
      INTEGER FUNCTION GETMSG(BUF)
      LOGICAL*1 BUF(100), TEMP(40)
      INTEGER UNIT, OPEN, N, GETLIN, OLDMAK
      CALL GETPNM(BUF)
      IF(.NOT.((BUF(1) .EQ. 36 .OR. BUF(1) .EQ. 46) .AND. BUF(2) .NE. BU
     *F(1)))GOTO 23022
      CALL ARGFIL(BUF, TEMP)
      UNIT = OPEN(TEMP, 1)
      IF(.NOT.(UNIT .EQ. -3))GOTO 23024
      BUF(1) = 32
      N = 2
      GOTO 23025
23024 CONTINUE
      N = GETLIN(BUF, UNIT)
      CALL CLOSE(UNIT)
      CALL REMOVE(TEMP)
23025 CONTINUE
      BUF(N) = 0
      GETMSG = N - 1
      GOTO 23023
23022 CONTINUE
      GETMSG = OLDMAK(BUF)
23023 CONTINUE
      RETURN
      END
      SUBROUTINE GTTY(TTY)
      LOGICAL*1 TTY(100)
      INTEGER IDS, OTOC
      COMMON / CSCLUN / LUNDAT(6)
      LOGICAL*1 BBUF(12)
      INTEGER LUNDAT
      EQUIVALENCE (LUNDAT(1), BBUF(1))
      CALL GETLUN(8, LUNDAT, IDS)
      TTY(1) = BBUF(1)
      TTY(2) = BBUF(2)
      BBUF(4) = 0
      IDS = OTOC(LUNDAT(2), TTY(3), 4) + 3
      TTY(IDS) = 58
      TTY(IDS+1) = 0
      RETURN
      END
      SUBROUTINE EXTPNM(LIN, TASK)
      LOGICAL*1 LIN(100), TASK(7)
      INTEGER J, I
      INTEGER SMATCH, EQUAL, LENGTH
      LOGICAL*1 TSKEQU(6)
      LOGICAL*1 TSKEQL(6)
      LOGICAL*1 RUN(4)
      DATA TSKEQU(1)/84/,TSKEQU(2)/65/,TSKEQU(3)/83/,TSKEQU(4)/75/,TSKEQ
     *U(5)/61/,TSKEQU(6)/0/
      DATA TSKEQL(1)/116/,TSKEQL(2)/97/,TSKEQL(3)/115/,TSKEQL(4)/107/,TS
     *KEQL(5)/61/,TSKEQL(6)/0/
      DATA RUN(1)/82/,RUN(2)/85/,RUN(3)/78/,RUN(4)/0/
      J = 0
      I=1
23026 IF(.NOT.(LIN(I) .NE. 0))GOTO 23028
      J = SMATCH(LIN, I, TSKEQU)
      IF(.NOT.(J .GT. 0))GOTO 23029
      GOTO 23028
23029 CONTINUE
      J = SMATCH(LIN, I, TSKEQL)
      IF(.NOT.(J .GT. 0))GOTO 23031
      GOTO 23028
23031 CONTINUE
23027 I=I+1
      GOTO 23026
23028 CONTINUE
      IF(.NOT.(J .GT. 0))GOTO 23033
      I = 1
23035 IF(.NOT.(LIN(J) .NE. 0 .AND. LIN(J) .NE. 47 .AND. I .LT. 7))GOTO 2
     *3037
      TASK(I) = LIN(J)
      I = I + 1
23036 J=J+1
      GOTO 23035
23037 CONTINUE
      TASK(I) = 0
      GOTO 23034
23033 CONTINUE
      I=1
23038 IF(.NOT.(I .LE. 3 .AND. LIN(I) .NE. 0))GOTO 23040
      TASK(I) = LIN(I)
23039 I=I+1
      GOTO 23038
23040 CONTINUE
      TASK(I) = 0
      CALL UPPER(TASK)
      IF(.NOT.(EQUAL(TASK, RUN) .EQ. 1))GOTO 23041
      I = 1
      GOTO 23042
23041 CONTINUE
      I = I - 1
23042 CONTINUE
      CALL GTTY(TASK(I))
      IF(.NOT.(I .GT. 1))GOTO 23043
      TASK(I) = LIN(I)
23043 CONTINUE
      J = INDEX(TASK, 58)
      IF(.NOT.(J .LT. 7))GOTO 23045
      TASK(J) = 0
      GOTO 23046
23045 CONTINUE
      TASK(7) = 0
23046 CONTINUE
23034 CONTINUE
      I=LENGTH(TASK)+1
23047 IF(.NOT.(I .LT. 7))GOTO 23049
      TASK(I) = 32
23048 I=I+1
      GOTO 23047
23049 CONTINUE
      TASK(I) = 0
      CALL UPPER(TASK)
      RETURN
      END
      INTEGER FUNCTION SMATCH(LIN, FROM, PAT)
      LOGICAL*1 LIN(100), PAT(100)
      INTEGER FROM, I, J
      I = FROM
      J=1
23050 IF(.NOT.(PAT(J) .NE. 0))GOTO 23052
      IF(.NOT.(LIN(I) .NE. PAT(J)))GOTO 23053
      SMATCH = 0
      RETURN
23053 CONTINUE
      I = I + 1
23051 J=J+1
      GOTO 23050
23052 CONTINUE
      SMATCH = I
      RETURN
      END
      INTEGER FUNCTION KILL(PROCES)
      LOGICAL*1 PROCES(7), BUF(26)
      INTEGER IDS
      REAL TASK
      LOGICAL*1 DOTS(4)
      DATA DOTS(1)/46/,DOTS(2)/46/,DOTS(3)/46/,DOTS(4)/0/
      CALL SCOPY(PROCES, 1, BUF, 1)
      CALL UPPER(BUF)
      CALL IRAD50(6, BUF, TASK)
      IF(.NOT.(PROCES(1) .EQ. 36))GOTO 23055
      CALL SEND(TASK, BUF,, IDS)
      GOTO 23056
23055 CONTINUE
      CALL ABORT(TASK, IDS)
      IF(.NOT.(IDS .LT. 0))GOTO 23057
      CALL CONCAT(DOTS, PROCES, BUF)
      CALL UPPER(BUF)
      CALL IRAD50(6, BUF, TASK)
      CALL ABORT(TASK, IDS)
23057 CONTINUE
23056 CONTINUE
      IF(.NOT.(IDS .LT. 0))GOTO 23059
      KILL = -3
      GOTO 23060
23059 CONTINUE
      KILL = 0
23060 CONTINUE
      RETURN
      END
      SUBROUTINE ENBINT
      LOGICAL*1 NAME(7)
      INTEGER NEWAST, OLDAST
      INTEGER EQUAL
      EXTERNAL CTCAST
      LOGICAL*1 SHL(4)
      DATA SHL(1)/46/,SHL(2)/83/,SHL(3)/72/,SHL(4)/0/
      CALL GETPNM(NAME)
      NAME(4) = 0
      CALL UPPER(NAME)
      IF(.NOT.(EQUAL(NAME, SHL) .EQ. 1))GOTO 23061
      CALL GETADR(NEWAST, CTCAST)
      CALL SRDA(NEWAST, OLDAST)
23061 CONTINUE
      RETURN
      END
      SUBROUTINE INTSRV
      INTEGER JUNK
      INTEGER KILL
      COMMON / CSPAWN / EFN, IFFORE, IFBACK, IFBAST, FOREPC(7), BACKPC(7
     *), TASKNM(7), PRIOST(5)
      INTEGER EFN
      INTEGER IFFORE
      INTEGER IFBACK
      INTEGER IFBAST
      LOGICAL*1 FOREPC
      LOGICAL*1 BACKPC
      LOGICAL*1 TASKNM
      LOGICAL*1 PRIOST
      IF(.NOT.(IFFORE .EQ. 1))GOTO 23063
      JUNK = KILL(FOREPC)
      IFFORE = 0
23063 CONTINUE
      RETURN
      END
      INTEGER FUNCTION BCKSPN(IMAGE, ARGS, PID)
      LOGICAL*1 IMAGE(40), ARGS(256), PID(7)
      REAL BSPAWN
      LOGICAL*1 FILE(40)
      INTEGER IDS, INT, I, NEWAST, OLDAST
      INTEGER INDEX, CREATE, RCSTDR
      LOGICAL*1 SEED(4)
      DATA SEED(1)/98/,SEED(2)/99/,SEED(3)/107/,SEED(4)/0/
	data bspawn/6RBSPAWN/, newast/0/
      CALL SCRATF(SEED, FILE)
      INT = CREATE(FILE, 2)
      IF(.NOT.(INT .NE. -3))GOTO 23065
      CALL PUTLIN(IMAGE, INT)
      CALL PUTCH(10, INT)
      CALL PUTLIN(ARGS, INT)
      CALL PUTCH(10, INT)
      CALL CLOSE(INT)
      I = INDEX(FILE, 93) + 1
      CALL SCOPY(FILE, I, FILE, 1)
      CALL SRDA(NEWAST, OLDAST)
      CALL SEND(BSPAWN, FILE,, IDS)
      IF(.NOT.(IDS .NE. 1))GOTO 23067
      INT = -3
      GOTO 23068
23067 CONTINUE
      IF(.NOT.(RCSTDR(BSPAWN, FILE) .NE. 1))GOTO 23069
      CALL RECEIV(BSPAWN, FILE,, IDS)
23069 CONTINUE
      INT = FILE(5)
      IF(.NOT.(INT .EQ. 0))GOTO 23071
      CALL SCOPY(FILE, 6, PID, 1)
      GOTO 23072
23071 CONTINUE
      INT = -3
23072 CONTINUE
23068 CONTINUE
      CALL CRDA(OLDAST)
23065 CONTINUE
      BCKSPN=(INT)
      RETURN
      END
