      SUBROUTINE MAIN
      LOGICAL*1 ARG(400)
      INTEGER GETARG, OPEN, CTOI, ADDSET
      INTEGER FD, I, J, L, U, LP, LIST(200), PAGSIZ, PFLAG, JUNK
      PFLAG = 0
      I = 1
      PAGSIZ = 1
      LIST(1) = -1
      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 (32Husage:  pl [-pn] numbers [file].)
23003 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. ARG(2) .NE. 0))GOTO 23005
      CALL DOFLAG(ARG, PFLAG, PAGSIZ)
      GOTO 23001
23005 CONTINUE
      IF(.NOT.(LIST(1) .EQ. -1))GOTO 23007
      LP = GNUM (ARG, LIST)
      GOTO 23008
23007 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45 .AND. ARG(2) .EQ. 0))GOTO 23009
      FD = 1
      GOTO 23010
23009 CONTINUE
      FD = OPEN(ARG, 1)
23010 CONTINUE
      IF(.NOT.(FD .EQ. -3))GOTO 23011
      CALL CANT(ARG)
23011 CONTINUE
      IF(.NOT.(LIST(1) .EQ. -1))GOTO 23013
      CALL ERROR (32Husage:  pl [-pn] numbers [file].)
23013 CONTINUE
      CALL PLINES(FD, LIST, PAGSIZ)
      IF(.NOT.(FD .NE. 1))GOTO 23015
      CALL CLOSE(FD)
23015 CONTINUE
23008 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      IF(.NOT.(LIST(1) .EQ. -1))GOTO 23017
      CALL ERROR (32Husage:  pl [-pn] numbers [file].)
23017 CONTINUE
      IF(.NOT.(FD .EQ. -3))GOTO 23019
      CALL PLINES(1, LIST, PAGSIZ)
23019 CONTINUE
      RETURN
      END
      SUBROUTINE DOFLAG (ARG, PFLAG, PAGSIZ)
      LOGICAL*1 ARG(100)
      INTEGER PFLAG, PAGSIZ
      INTEGER CTOI
      IF(.NOT.(ARG(2) .EQ. 112 .OR. ARG(2) .EQ. 80))GOTO 23021
      PFLAG = 1
      J = 3
      PAGSIZ = CTOI(ARG, J)
      IF(.NOT.(PAGSIZ .LT. 0 .OR. ARG(J) .NE. 0))GOTO 23023
      CALL ERROR(14Hbad page size.)
23023 CONTINUE
      IF(.NOT.(PAGSIZ .EQ. 0))GOTO 23025
      PAGSIZ = 23
23025 CONTINUE
      GOTO 23022
23021 CONTINUE
      CALL REMARK (26Hignoring invalid argument.)
23022 CONTINUE
      RETURN
      END
      INTEGER FUNCTION GET(N, BUF, FD)
      INTEGER N, FD
      LOGICAL*1 BUF(3000)
      INTEGER I
      LOGICAL*1 GETCH, C
      I = 1
      M = N
23027 IF(.NOT.(M .GT. 0))GOTO 23029
23030 IF(.NOT.(GETCH(C, FD) .NE. -1))GOTO 23031
      IF(.NOT.(I .LT. 3000))GOTO 23032
      BUF(I) = C
      I = I + 1
23032 CONTINUE
      IF(.NOT.(C .EQ. 10))GOTO 23034
      GOTO 23031
23034 CONTINUE
      GOTO 23030
23031 CONTINUE
      IF(.NOT.(C .EQ. -1))GOTO 23036
      GOTO 23029
23036 CONTINUE
23028 M = M - 1
      GOTO 23027
23029 CONTINUE
      BUF(I) = 0
      IF(.NOT.(C .EQ. -1))GOTO 23038
      GET=(-1)
      RETURN
23038 CONTINUE
      GET=(N)
      RETURN
      END
      INTEGER FUNCTION GNUM (ARG, LIST)
      INTEGER LIST(100), LP, J
      LOGICAL*1 ARG(100)
      INTEGER CTOI
      LP = 0
      J=1
23040 IF(.NOT.(ARG(J) .NE. 0))GOTO 23042
      LP = LP + 1
      IF(.NOT.(LP .GT. 200))GOTO 23043
      CALL ERROR (17Htoo many numbers.)
23043 CONTINUE
      LIST(LP) = CTOI(ARG, J)
      IF(.NOT.(LIST(LP) .LE. 0))GOTO 23045
      CALL ERROR (11Hbad number.)
23045 CONTINUE
      IF(.NOT.(ARG(J) .EQ. 45))GOTO 23047
      J = J + 1
      U = CTOI(ARG, J)
      L = LIST(LP)
      IF(.NOT.( U .LT. L))GOTO 23049
      CALL ERROR(10Hbad range.)
23049 CONTINUE
      L = L + 1
23051 IF(.NOT.(L .LE. U))GOTO 23053
      LP = LP + 1
      IF(.NOT.(LP .GT. 200))GOTO 23054
      CALL ERROR (17Htoo many numbers.)
23054 CONTINUE
      LIST(LP) = L
23052 L = L + 1
      GOTO 23051
23053 CONTINUE
23047 CONTINUE
23056 IF(.NOT.(ARG(J) .EQ. 44 .OR. ARG(J) .EQ. 32 .OR. ARG(J) .EQ. 9))GO
     *TO 23057
      J = J + 1
      GOTO 23056
23057 CONTINUE
23041 GOTO 23040
23042 CONTINUE
      IF(.NOT.(LP+1 .GT. 200))GOTO 23058
      CALL ERROR (17Htoo many numbers.)
23058 CONTINUE
      LIST(LP+1) = -1
      CALL SHELL (LIST, LP)
      GNUM = LP
      RETURN
      END
      SUBROUTINE PLINES(FD, LIST, PAGSIZ)
      INTEGER FD, LIST(200), PAGSIZ
      INTEGER I, J, N, GET, SKIP, LEN, JUNK
      LOGICAL*1 BUF(3000)
      N = 0
      I = 1
23060 IF(.NOT.(LIST(I) .NE. -1))GOTO 23062
      IF(.NOT.(SKIP(PAGSIZ*(LIST(I) - N - 1), FD) .EQ. -1))GOTO 23063
      RETURN
23063 CONTINUE
      LEN = GET(PAGSIZ, BUF, FD)
      J = I
23065 IF(.NOT.(LIST(J) .EQ. LIST(I)))GOTO 23067
      CALL PUTLIN(BUF, 2)
23066 I = I + 1
      GOTO 23065
23067 CONTINUE
      IF(.NOT.(LEN .EQ. -1))GOTO 23068
      RETURN
23068 CONTINUE
      N = LIST(J)
23061 GOTO 23060
23062 CONTINUE
      IF(.NOT.(FD .EQ. 1))GOTO 23070
      JUNK = SKIP(HUGE, FD)
23070 CONTINUE
      RETURN
      END
      SUBROUTINE SHELL (V, N)
      INTEGER GAP, I, J, JG, K, N, V(100)
      GAP=N/2
23072 IF(.NOT.(GAP.GT.0))GOTO 23074
      I=GAP+1
23075 IF(.NOT.(I.LE.N))GOTO 23077
      J=I-GAP
23078 IF(.NOT.(J.GT.0))GOTO 23080
      JG = J + GAP
      IF(.NOT.(V(J) .LE. V(JG)))GOTO 23081
      GOTO 23080
23081 CONTINUE
      K = V(J)
      V(J) = V(JG)
      V(JG) = K
23079 J=J-GAP
      GOTO 23078
23080 CONTINUE
23076 I=I+1
      GOTO 23075
23077 CONTINUE
23073 GAP=GAP/2
      GOTO 23072
23074 CONTINUE
      RETURN
      END
      INTEGER FUNCTION SKIP(N, FD)
      INTEGER N, FD
      INTEGER M
      LOGICAL*1 GETCH, C
      M = N
23083 IF(.NOT.(M .GT. 0))GOTO 23085
23086 IF(.NOT.(GETCH(C, FD) .NE. -1))GOTO 23087
      IF(.NOT.(C .EQ. 10))GOTO 23088
      GOTO 23087
23088 CONTINUE
      GOTO 23086
23087 CONTINUE
      IF(.NOT.(C .EQ. -1))GOTO 23090
      GOTO 23085
23090 CONTINUE
23084 M = M - 1
      GOTO 23083
23085 CONTINUE
      IF(.NOT.(C .EQ. -1))GOTO 23092
      SKIP=(-1)
      RETURN
23092 CONTINUE
      SKIP=(N)
      RETURN
      END
