      SUBROUTINE MAIN
      LOGICAL*1 BUF(512)
      INTEGER FD, TT
      INTEGER OPEN
      INTEGER I, INPUT, J, MODE, NLINES
      INTEGER CTOI, GETARG, GETLIN, PRTNL, STMODE
      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, 3)
      IF (.NOT.( TT .EQ. -3 ))GOTO 23000
      CALL CANT(TERML)
23000 CONTINUE
      MODE = STMODE( TT, 1)
      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
      FD = 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
      FD = OPEN( BUF, 1)
      IF (.NOT.( FD .EQ. -3 ))GOTO 23009
      CALL CANT(BUF)
23009 CONTINUE
23008 CONTINUE
23006 CONTINUE
      INPUT = 1
      IF (.NOT.( PRTNL( FD, NLINES, TT) .EQ. -1 ))GOTO 23011
      GOTO 23004
23011 CONTINUE
      IF (.NOT.( FD .NE. 1 ))GOTO 23013
      CALL CLOSE(FD)
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( FD, NL, TT)
      LOGICAL*1 BUF(512), C
      LOGICAL*1 GETCH
      INTEGER FD, TT
      INTEGER NL, PRMPT, MODE
      INTEGER GETLIN, GTMODE
      LOGICAL*1 RPSTR(25)
      LOGICAL*1 PSTR(1)
      DATA RPSTR(1)/13/,RPSTR(2)/10/,RPSTR(3)/91/,RPSTR(4)/80/,RPSTR(5)/
     *114/,RPSTR(6)/101/,RPSTR(7)/115/,RPSTR(8)/115/,RPSTR(9)/32/,RPSTR(
     *10)/83/,RPSTR(11)/80/,RPSTR(12)/65/,RPSTR(13)/67/,RPSTR(14)/69/,RP
     *STR(15)/32/,RPSTR(16)/102/,RPSTR(17)/111/,RPSTR(18)/114/,RPSTR(19)
     */32/,RPSTR(20)/109/,RPSTR(21)/111/,RPSTR(22)/114/,RPSTR(23)/101/,R
     *PSTR(24)/93/,RPSTR(25)/0/
      DATA PSTR(1)/0/
      DATA PRMPT /0/
      PRTNL = 0
      MODE = GTMODE(TT)
23017 CONTINUE
      IF (.NOT.( PRMPT .EQ. 1 ))GOTO 23020
      IF (.NOT.(MODE .NE. 0))GOTO 23022
      CALL PUTLIN(RPSTR, TT)
      PRTNL = GETCH(C, TT)
      IF (.NOT.(C .GE. 32))GOTO 23024
      CALL PUTCH(C, TT)
23024 CONTINUE
      GOTO 23023
23022 CONTINUE
      PRTNL = PROMPT(PSTR, BUF, TT)
      C = BUF(1)
23023 CONTINUE
      IF (.NOT.( PRTNL .EQ. 26 .OR. PRTNL .EQ. -1 ))GOTO 23026
      PRMPT = 0
      PRTNL=(-1)
      RETURN
23026 CONTINUE
      IF (.NOT.( C .EQ. 113 .OR. C .EQ. 81 ))GOTO 23028
      PRMPT = 0
      RETURN
23028 CONTINUE
      IF (.NOT.(MODE .NE. 0))GOTO 23030
      CALL PUTCH(13, TT)
23030 CONTINUE
23020 CONTINUE
      J = 1 
23032 IF (.NOT.(J .LE. NL ))GOTO 23034
      PRMPT = 1
      IF (.NOT.( GETLIN( BUF, FD) .EQ. -1 ))GOTO 23035
      RETURN
23035 CONTINUE
      CALL PUTLIN( BUF, 2)
23033 J = J + 1 
      GOTO 23032
23034 CONTINUE
23018 GOTO 23017
23019 CONTINUE
      RETURN
      END
