      SUBROUTINE MAIN
      INTEGER GETARG, CREATE, OPEN, CTOI, NLCOPY
      LOGICAL*1 BUF(512), OUTF(40)
      INTEGER NL, I, J, IN, USEIN, OUT
      DATA OUTF(1), OUTF(2) / 120, 0/
      CALL QUERY(33Husage:  split [-n] [file [name]].)
      NL = 1000
      USEIN = 0
      IN = 1
      I=1
23000 IF (.NOT.(GETARG(I,BUF,512).NE.-1))GOTO 23002
      IF (.NOT.(BUF(1) .EQ. 45))GOTO 23003
      IF (.NOT.(BUF(2) .EQ. 0))GOTO 23005
      USEIN = 1
      GOTO 23006
23005 CONTINUE
      J = 2
      NL = MAX0(CTOI(BUF,J), 1)
23006 CONTINUE
      GOTO 23004
23003 CONTINUE
      IF (.NOT.(USEIN .EQ. 0))GOTO 23007
      IN = OPEN(BUF,1)
      IF (.NOT.(IN .EQ. -3))GOTO 23009
      CALL CANT(BUF)
23009 CONTINUE
      USEIN = 1
      GOTO 23008
23007 CONTINUE
      CALL SCOPY(BUF, 1, OUTF, 1)
23008 CONTINUE
23004 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
23011 CONTINUE
      CALL EXTNAM(OUTF, BUF)
      OUT = CREATE(BUF, 2)
      IF (.NOT.(OUT .EQ. -3))GOTO 23014
      CALL CANT(BUF)
23014 CONTINUE
      IF (.NOT.(NLCOPY(IN, OUT, NL) .EQ. -1))GOTO 23016
      GOTO 23013
23016 CONTINUE
      CALL CLOSE(OUT)
23012 GOTO 23011
23013 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 23018
      APPEND(2) = 97
      APPEND(1) = APPEND(1) + 1
      IF (.NOT.(APPEND(1) .GT. 122))GOTO 23020
      CALL ERROR (18Hout of file names.)
23020 CONTINUE
23018 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(512)
      INTEGER GETLIN
      INTEGER IN, OUT, N, I
      I=1
23022 IF (.NOT.(I.LE.N))GOTO 23024
      IF (.NOT.(GETLIN(BUF,IN) .EQ. -1))GOTO 23025
      NLCOPY = -1
      RETURN
23025 CONTINUE
      CALL PUTLIN(BUF, OUT)
23023 I=I+1
      GOTO 23022
23024 CONTINUE
      NLCOPY = 0
      RETURN
      END
