      SUBROUTINE MAIN
      LOGICAL*1 ARG(400)
      INTEGER N, I, FD
      INTEGER CTOI, GETARG, OPEN
      N = 23
      I=1
23000 IF(.NOT.(GETARG(I, ARG, 400) .NE. -1))GOTO 23002
      IF(.NOT.(ARG(1) .EQ. 63 .AND. ARG(2) .EQ. 0))GOTO 23003
      CALL ERROR (26Husage:  tail [-n] [files].)
      GOTO 23004
23003 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. ARG(2) .NE. 0))GOTO 23005
      J = 2
      N = CTOI(ARG, J)
      IF(.NOT.(N .LE. 0))GOTO 23007
      CALL ERROR (13Hinvalid size.)
23007 CONTINUE
      GOTO 23006
23005 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. ARG(2) .EQ. 0))GOTO 23009
      FD = 1
      CALL PTAIL (N, FD)
      GOTO 23010
23009 CONTINUE
      FD = OPEN(ARG, 1)
      IF(.NOT.(FD .EQ. -3))GOTO 23011
      CALL CANT(ARG)
23011 CONTINUE
      CALL PTAIL (N, FD)
      CALL CLOSE(FD)
23010 CONTINUE
23006 CONTINUE
23004 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      IF(.NOT.(FD .EQ. -3))GOTO 23013
      CALL PTAIL (N, 1)
23013 CONTINUE
      RETURN
      END
      SUBROUTINE PTAIL (NLINS, FD)
      INTEGER N, FD, NLINS
      LOGICAL*1 BUF(3000)
      LOGICAL*1 GETCH
      INTEGER HEAD, TAIL, I
      HEAD = 1
      TAIL = 1
      N = NLINS
23015 IF(.NOT.(GETCH(BUF(TAIL), FD) .NE. -1))GOTO 23016
      TAIL = MOD(TAIL, 3000) + 1
      IF(.NOT.(TAIL .EQ. HEAD))GOTO 23017
      HEAD = MOD(HEAD, 3000) + 1
23017 CONTINUE
      GOTO 23015
23016 CONTINUE
      I = TAIL
23019 IF(.NOT.(I .NE. HEAD))GOTO 23021
      I = I - 1
      IF(.NOT.(I .EQ. 0))GOTO 23022
      I = 3000
23022 CONTINUE
      IF(.NOT.(BUF(I) .EQ. 10))GOTO 23024
      N = N - 1
      IF(.NOT.(N .LT. 0))GOTO 23026
      I = MOD(I, 3000) + 1
      GOTO 23021
23026 CONTINUE
23024 CONTINUE
23020 GOTO 23019
23021 CONTINUE
      HEAD = I
23028 IF(.NOT.(HEAD .NE. TAIL))GOTO 23030
      CALL PUTCH(BUF(HEAD), 2)
23029 HEAD = MOD(HEAD, 3000) + 1
      GOTO 23028
23030 CONTINUE
      RETURN
      END
