      SUBROUTINE MAIN
      INTEGER GETARG, CREATE, OPEN, CTOI, NLCOPY
      LOGICAL*1 BUF(400), OUTF(40)
      INTEGER NL, I, J, IN, USEIN, OUT
      DATA OUTF(1), OUTF(2) / 120, 0/
      NL = 1000
      USEIN = 0
      IN = 1
      I=1
23000 IF(.NOT.(GETARG(I,BUF,400).NE.-1))GOTO 23002
      IF(.NOT.(BUF(1) .EQ. 63 .AND. BUF(2) .EQ. 0))GOTO 23003
      CALL ERROR (33Husage:  split [-n] [file [name]].)
      GOTO 23004
23003 CONTINUE
      IF(.NOT.(BUF(1) .EQ. 45))GOTO 23005
      IF(.NOT.(BUF(2) .EQ. 0))GOTO 23007
      USEIN = 1
      GOTO 23008
23007 CONTINUE
      J = 2
      NL = MAX0(CTOI(BUF,J), 1)
23008 CONTINUE
      GOTO 23006
23005 CONTINUE
      IF(.NOT.(USEIN .EQ. 0))GOTO 23009
      IN = OPEN(BUF,1)
      IF(.NOT.(IN .EQ. -3))GOTO 23011
      CALL CANT(BUF)
23011 CONTINUE
      USEIN = 1
      GOTO 23010
23009 CONTINUE
      CALL SCOPY(BUF, 1, OUTF, 1)
23010 CONTINUE
23006 CONTINUE
23004 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
23013 CONTINUE
      CALL EXTNAM(OUTF, BUF)
      OUT = CREATE(BUF, 2)
      IF(.NOT.(OUT .EQ. -3))GOTO 23016
      CALL CANT(BUF)
23016 CONTINUE
      IF(.NOT.(NLCOPY(IN, OUT, NL) .EQ. -1))GOTO 23018
      GOTO 23015
23018 CONTINUE
      CALL CLOSE(OUT)
23014 GOTO 23013
23015 CONTINUE
      RETURN
      END
      SUBROUTINE EXTNAM (FILE, NAME)
      LOGICAL*1 FILE(100), NAME(100), APPEND(3)
      INTEGER LENGTH
      DATA APPEND(1), APPEND(2), APPEND(3) /97, 97, 0/
      CALL SCOPY(FILE, 1, NAME, 1)
      IF(.NOT.(APPEND(2) .GT. 122))GOTO 23020
      APPEND(2) = 97
      APPEND(1) = APPEND(1) + 1
      IF(.NOT.(APPEND(1) .GT. 122))GOTO 23022
      CALL ERROR (18Hout of file names.)
23022 CONTINUE
23020 CONTINUE
      CALL SCOPY(APPEND, 1, NAME, LENGTH(NAME)+1)
      APPEND(2) = APPEND(2) + 1
      RETURN
      END
      INTEGER FUNCTION NLCOPY (IN, OUT, N)
      LOGICAL*1 BUF(400)
      INTEGER GETLIN
      INTEGER IN, OUT, N, I
      I=1
23024 IF(.NOT.(I.LE.N))GOTO 23026
      IF(.NOT.(GETLIN(BUF,IN) .EQ. -1))GOTO 23027
      NLCOPY = -1
      RETURN
23027 CONTINUE
      CALL PUTLIN(BUF, OUT)
23025 I=I+1
      GOTO 23024
23026 CONTINUE
      NLCOPY = 0
      RETURN
      END
