      SUBROUTINE MAIN
      INTEGER GETARG, CTOI, OPEN, GETLIN, PRTNL
      INTEGER I, J, TT, NLINES, INPUT
      LOGICAL*1 BUF(512)
      LOGICAL*1 TERML(4)
      DATA TERML(1)/84/,TERML(2)/73/,TERML(3)/58/,TERML(4)/0/
      DATA NLINES /22/
      DATA INPUT /0/
      CALL QUERY(27Husage:  crt [-n] [file] ...)
      TT = OPEN(TERML, 1)
      IF (.NOT.(TT .EQ. -3))GOTO 23000
      CALL CANT(TERML)
23000 CONTINUE
      I=1
23002 IF (.NOT.(GETARG(I,BUF,512).NE.-1))GOTO 23004
      IF (.NOT.(BUF(1) .EQ. 45 .AND. BUF(2) .EQ. 0))GOTO 23005
      INT = 1
      GOTO 23006
23005 CONTINUE
      IF (.NOT.(BUF(1) .EQ. 45))GOTO 23007
      J = 2
      NLINES = MAX0(CTOI(BUF,J), 1)
      GOTO 23003
23007 CONTINUE
      INT = OPEN(BUF,1)
      IF (.NOT.(INT .EQ. -3))GOTO 23009
      CALL CANT(BUF)
23009 CONTINUE
23008 CONTINUE
23006 CONTINUE
      INPUT = 1
      IF (.NOT.(PRTNL(INT, NLINES, TT) .EQ. -1))GOTO 23011
      GOTO 23004
23011 CONTINUE
      IF (.NOT.(INT .NE. 1))GOTO 23013
      CALL CLOSE(INT)
23013 CONTINUE
23003 I=I+1
      GOTO 23002
23004 CONTINUE
      IF (.NOT.(INPUT .EQ. 0))GOTO 23015
      CALL PRTNL(1, NLINES, TT)
23015 CONTINUE
      RETURN
      END
      INTEGER FUNCTION PRTNL(INT, NL, TT)
      INTEGER INT, NL, TT, PROMPT
      INTEGER GETLIN
      LOGICAL*1 BUF(512)
      DATA PROMPT /0/
      PRTNL = 0
23017 CONTINUE
      IF (.NOT.(PROMPT .EQ. 1))GOTO 23020
      PRTNL = GETLIN(BUF,TT)
      IF (.NOT.(PRTNL .EQ. -1))GOTO 23022
      PROMPT = 0
      RETURN
23022 CONTINUE
      IF (.NOT.(BUF(1) .EQ. 113 .OR. BUF(1) .EQ. 81))GOTO 23024
      PROMPT = 0
      RETURN
23024 CONTINUE
23020 CONTINUE
      J=1
23026 IF (.NOT.(J.LE.NL))GOTO 23028
      PROMPT = 1
      IF (.NOT.(GETLIN(BUF, INT) .EQ. -1))GOTO 23029
      RETURN
23029 CONTINUE
      CALL PUTLIN(BUF, 2)
23027 J=J+1
      GOTO 23026
23028 CONTINUE
23018 GOTO 23017
23019 CONTINUE
      RETURN
      END
