      SUBROUTINE MAIN
      LOGICAL*1 ARG(512)
      INTEGER GETARG, OPEN, CTOI, ADDSET
      INTEGER FD, I, J, L, U, LP, LIST(200), PAGSIZ, PFLAG, JUNK
      LOGICAL*1 USESTR(38)
      DATA USESTR(1)/117/,USESTR(2)/115/,USESTR(3)/97/,USESTR(4)/103/,US
     *ESTR(5)/101/,USESTR(6)/58/,USESTR(7)/32/,USESTR(8)/32/,USESTR(9)/1
     *12/,USESTR(10)/108/,USESTR(11)/32/,USESTR(12)/91/,USESTR(13)/45/,U
     *SESTR(14)/112/,USESTR(15)/60/,USESTR(16)/110/,USESTR(17)/62/,USEST
     *R(18)/93/,USESTR(19)/32/,USESTR(20)/110/,USESTR(21)/117/,USESTR(22
     *)/109/,USESTR(23)/98/,USESTR(24)/101/,USESTR(25)/114/,USESTR(26)/1
     *15/,USESTR(27)/32/,USESTR(28)/91/,USESTR(29)/102/,USESTR(30)/105/,
     *USESTR(31)/108/,USESTR(32)/101/,USESTR(33)/93/,USESTR(34)/32/,USES
     *TR(35)/46/,USESTR(36)/46/,USESTR(37)/46/,USESTR(38)/0/
      CALL QUERY(USESTR)
      PFLAG = 0
      I = 1
      PAGSIZ = 1
      LIST(1) = -1
      I=1
23000 IF (.NOT.(GETARG(I, ARG, 512) .NE. -1))GOTO 23002
      IF (.NOT.(ARG(1) .EQ. 45 .AND. ARG(2) .NE. 0))GOTO 23003
      CALL DOFLAG(ARG, PFLAG, PAGSIZ)
      GOTO 23001
23003 CONTINUE
      IF (.NOT.(LIST(1) .EQ. -1))GOTO 23005
      LP = GNUM (ARG, LIST)
      GOTO 23006
23005 CONTINUE
      IF (.NOT.(ARG(1) .EQ. 45 .AND. ARG(2) .EQ. 0))GOTO 23007
      FD = 1
      GOTO 23008
23007 CONTINUE
      FD = OPEN(ARG, 1)
23008 CONTINUE
      IF (.NOT.(FD .EQ. -3))GOTO 23009
      CALL CANT(ARG)
23009 CONTINUE
      IF (.NOT.(LIST(1) .EQ. -1))GOTO 23011
      CALL ERROR (USESTR)
23011 CONTINUE
      CALL PLINES(FD, LIST, PAGSIZ)
      IF (.NOT.(FD .NE. 1))GOTO 23013
      CALL CLOSE(FD)
23013 CONTINUE
23006 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      IF (.NOT.(LIST(1) .EQ. -1))GOTO 23015
      CALL ERROR (USESTR)
23015 CONTINUE
      IF (.NOT.(FD .EQ. -3))GOTO 23017
      CALL PLINES(1, LIST, PAGSIZ)
23017 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 23019
      PFLAG = 1
      J = 3
      PAGSIZ = CTOI(ARG, J)
      IF (.NOT.(PAGSIZ .LT. 0 .OR. ARG(J) .NE. 0))GOTO 23021
      CALL ERROR(14Hbad page size.)
23021 CONTINUE
      IF (.NOT.(PAGSIZ .EQ. 0))GOTO 23023
      PAGSIZ = 23
23023 CONTINUE
      GOTO 23020
23019 CONTINUE
      CALL REMARK (26Hignoring invalid argument.)
23020 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
23025 IF (.NOT.(M .GT. 0))GOTO 23027
23028 IF (.NOT.(GETCH(C, FD) .NE. -1))GOTO 23029
      IF (.NOT.(I .LT. 3000))GOTO 23030
      BUF(I) = C
      I = I + 1
23030 CONTINUE
      IF (.NOT.(C .EQ. 10))GOTO 23032
      GOTO 23029
23032 CONTINUE
      GOTO 23028
23029 CONTINUE
      IF (.NOT.(C .EQ. -1))GOTO 23034
      GOTO 23027
23034 CONTINUE
23026 M = M - 1
      GOTO 23025
23027 CONTINUE
      BUF(I) = 0
      IF (.NOT.(C .EQ. -1))GOTO 23036
      GET=(-1)
      RETURN
23036 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
23038 IF (.NOT.(ARG(J) .NE. 0))GOTO 23040
      LP = LP + 1
      IF (.NOT.(LP .GT. 200))GOTO 23041
      CALL ERROR (17Htoo many numbers.)
23041 CONTINUE
      LIST(LP) = CTOI(ARG, J)
      IF (.NOT.(LIST(LP) .LE. 0))GOTO 23043
      CALL ERROR (11Hbad number.)
23043 CONTINUE
      IF (.NOT.(ARG(J) .EQ. 45))GOTO 23045
      J = J + 1
      U = CTOI(ARG, J)
      L = LIST(LP)
      IF (.NOT.( U .LT. L))GOTO 23047
      CALL ERROR(10Hbad range.)
23047 CONTINUE
      L = L + 1
23049 IF (.NOT.(L .LE. U))GOTO 23051
      LP = LP + 1
      IF (.NOT.(LP .GT. 200))GOTO 23052
      CALL ERROR (17Htoo many numbers.)
23052 CONTINUE
      LIST(LP) = L
23050 L = L + 1
      GOTO 23049
23051 CONTINUE
23045 CONTINUE
23054 IF (.NOT.(ARG(J) .EQ. 44 .OR. ARG(J) .EQ. 32 .OR. ARG(J) .EQ. 9))G
     *OTO 23055
      J = J + 1
      GOTO 23054
23055 CONTINUE
23039 GOTO 23038
23040 CONTINUE
      IF (.NOT.(LP+1 .GT. 200))GOTO 23056
      CALL ERROR (17Htoo many numbers.)
23056 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
23058 IF (.NOT.(LIST(I) .NE. -1))GOTO 23060
      IF (.NOT.(SKIP(PAGSIZ*(LIST(I) - N - 1), FD) .EQ. -1))GOTO 23061
      RETURN
23061 CONTINUE
      LEN = GET(PAGSIZ, BUF, FD)
      J = I
23063 IF (.NOT.(LIST(J) .EQ. LIST(I)))GOTO 23065
      CALL PUTLIN(BUF, 2)
23064 I = I + 1
      GOTO 23063
23065 CONTINUE
      IF (.NOT.(LEN .EQ. -1))GOTO 23066
      RETURN
23066 CONTINUE
      N = LIST(J)
23059 GOTO 23058
23060 CONTINUE
      IF (.NOT.(FD .EQ. 1))GOTO 23068
      JUNK = SKIP(30000, FD)
23068 CONTINUE
      RETURN
      END
      SUBROUTINE SHELL (V, N)
      INTEGER GAP, I, J, JG, K, N, V(100)
      GAP=N/2
23070 IF (.NOT.(GAP.GT.0))GOTO 23072
      I=GAP+1
23073 IF (.NOT.(I.LE.N))GOTO 23075
      J=I-GAP
23076 IF (.NOT.(J.GT.0))GOTO 23078
      JG = J + GAP
      IF (.NOT.(V(J) .LE. V(JG)))GOTO 23079
      GOTO 23078
23079 CONTINUE
      K = V(J)
      V(J) = V(JG)
      V(JG) = K
23077 J=J-GAP
      GOTO 23076
23078 CONTINUE
23074 I=I+1
      GOTO 23073
23075 CONTINUE
23071 GAP=GAP/2
      GOTO 23070
23072 CONTINUE
      RETURN
      END
      INTEGER FUNCTION SKIP(N, FD)
      INTEGER N, FD
      INTEGER M
      LOGICAL*1 GETCH, C
      M = N
23081 IF (.NOT.(M .GT. 0))GOTO 23083
23084 IF (.NOT.(GETCH(C, FD) .NE. -1))GOTO 23085
      IF (.NOT.(C .EQ. 10))GOTO 23086
      GOTO 23085
23086 CONTINUE
      GOTO 23084
23085 CONTINUE
      IF (.NOT.(C .EQ. -1))GOTO 23088
      GOTO 23083
23088 CONTINUE
23082 M = M - 1
      GOTO 23081
23083 CONTINUE
      IF (.NOT.(C .EQ. -1))GOTO 23090
      SKIP=(-1)
      RETURN
23090 CONTINUE
      SKIP=(N)
      RETURN
      END
