      SUBROUTINE MAIN
      LOGICAL*1 EXP(128,10), PAT(128,10), LIN(400), ARG(128)
      INTEGER I, GETARG, EXCEPT, ANDPAT, COUNT, ELEVEL, ITOC, GETPAT, MC
     *OUNT, GETLIN, MATCHD, STATUS, GMATCH, INDEX
      DATA EXCEPT/0/
      DATA ANDPAT/0/
      DATA COUNT /0/
      DATA ELEVEL/0/
      I=1
23000 IF(.NOT.(GETARG(I, ARG, 128) .NE. -1))GOTO 23002
      IF(.NOT.(ARG(1) .EQ. 63 .AND. ARG(2) .EQ. 0))GOTO 23003
      CALL FINERR
      GOTO 23004
23003 CONTINUE
      IF(.NOT.(ARG(1) .EQ. 45))GOTO 23005
      CALL SCOPY(ARG, 1, LIN, 1)
      CALL FOLD(LIN)
      IF(.NOT.(INDEX(LIN, 97) .GT. 0))GOTO 23007
      ANDPAT = 1
23007 CONTINUE
      IF(.NOT.(INDEX(LIN, 99) .GT. 0))GOTO 23009
      COUNT = 1
23009 CONTINUE
      IF(.NOT.(INDEX(LIN, 120) .GT. 0))GOTO 23011
      EXCEPT = 1
23011 CONTINUE
      GOTO 23006
23005 CONTINUE
      IF(.NOT.(ELEVEL .LT. 10))GOTO 23013
      ELEVEL = ELEVEL + 1
      CALL SCOPY(ARG, 1, EXP(1, ELEVEL), 1)
      GOTO 23014
23013 CONTINUE
      CALL PUTLIN(43HMaximum number of expressions permitted is , 3)
      STATUS = ITOC(10, ARG, 128)
      CALL ERROR(ARG)
23014 CONTINUE
23006 CONTINUE
23004 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      IF(.NOT.(ELEVEL .EQ. 0))GOTO 23015
      CALL FINERR
23015 CONTINUE
      I=1
23017 IF(.NOT.(I .LE. ELEVEL))GOTO 23019
      IF(.NOT.(GETPAT(EXP(1,I), PAT(1,I)) .EQ. -3))GOTO 23020
      CALL PUTLIN(17Hillegal pattern: , 3)
      CALL ERROR(EXP(1,I))
23020 CONTINUE
23018 I=I+1
      GOTO 23017
23019 CONTINUE
      MCOUNT = 0
23022 IF(.NOT.(GETLIN(LIN, 1) .NE. -1))GOTO 23023
      MATCHD = GMATCH(LIN, PAT, ELEVEL, ANDPAT)
      IF(.NOT.((MATCHD .EQ. 1 .AND. EXCEPT .EQ. 0) .OR. (MATCHD .EQ. 0 .
     *AND. EXCEPT .EQ. 1)))GOTO 23024
      IF(.NOT.(COUNT .EQ. 1))GOTO 23026
      MCOUNT = MCOUNT + 1
      GOTO 23027
23026 CONTINUE
      CALL PUTLIN(LIN, 2)
23027 CONTINUE
23024 CONTINUE
      GOTO 23022
23023 CONTINUE
      IF(.NOT.(COUNT .EQ. 1))GOTO 23028
      CALL PUTDEC(MCOUNT, 1)
      CALL PUTC(10)
23028 CONTINUE
      RETURN
      END
      INTEGER FUNCTION AMATCH(LIN, FROM, PAT)
      LOGICAL*1 LIN(400), PAT(128)
      INTEGER OMATCH, PATSIZ
      INTEGER FROM, I, J, OFFSET, STACK
      STACK = 0
      OFFSET = FROM
      J = 1
23030 IF(.NOT.(PAT(J) .NE. 0))GOTO 23032
      IF(.NOT.(PAT(J) .EQ. 42))GOTO 23033
      STACK = J
      J = J + 4
      I = OFFSET
23035 IF(.NOT.(LIN(I) .NE. 0))GOTO 23037
      IF(.NOT.(OMATCH(LIN, I, PAT, J) .EQ. 0))GOTO 23038
      GOTO 23037
23038 CONTINUE
23036 GOTO 23035
23037 CONTINUE
      PAT(STACK+1) = I - OFFSET
      PAT(STACK+3) = OFFSET
      OFFSET = I
      GOTO 23034
23033 CONTINUE
      IF(.NOT.(OMATCH(LIN, OFFSET, PAT, J) .EQ. 0))GOTO 23040
23042 IF(.NOT.(STACK .GT. 0))GOTO 23044
      IF(.NOT.(PAT(STACK+1) .GT. 0))GOTO 23045
      GOTO 23044
23045 CONTINUE
23043 STACK = PAT(STACK+2)
      GOTO 23042
23044 CONTINUE
      IF(.NOT.(STACK .LE. 0))GOTO 23047
      AMATCH = 0
      RETURN
23047 CONTINUE
      PAT(STACK+1) = PAT(STACK+1) - 1
      J = STACK + 4
      OFFSET = PAT(STACK+3) + PAT(STACK+1)
23040 CONTINUE
23034 CONTINUE
23031 J = J + PATSIZ(PAT, J)
      GOTO 23030
23032 CONTINUE
      AMATCH = OFFSET
      RETURN
      END
      SUBROUTINE DODASH(VALID, ARRAY, I, SET, J, MAXSET)
      LOGICAL*1 ESC
      INTEGER ADDSET, INDEX
      INTEGER I, J, JUNK, K, LIMIT, MAXSET
      LOGICAL*1 ARRAY(100), SET(MAXSET), VALID(100)
      I = I + 1
      J = J - 1
      LIMIT = INDEX(VALID, ESC(ARRAY, I))
      K = INDEX(VALID, SET(J))
23049 IF(.NOT.(K .LE. LIMIT))GOTO 23051
      JUNK = ADDSET(VALID(K), SET, J, MAXSET)
23050 K = K + 1
      GOTO 23049
23051 CONTINUE
      RETURN
      END
      LOGICAL*1 FUNCTION ESC(ARRAY, I)
      LOGICAL*1 ARRAY(100)
      INTEGER I
      IF(.NOT.(ARRAY(I) .NE. 64))GOTO 23052
      ESC = ARRAY(I)
      GOTO 23053
23052 CONTINUE
      IF(.NOT.(ARRAY(I+1) .EQ. 0))GOTO 23054
      ESC = 64
      GOTO 23055
23054 CONTINUE
      I = I + 1
      IF(.NOT.(ARRAY(I) .EQ. 110 .OR. ARRAY(I) .EQ. 78))GOTO 23056
      ESC = 10
      GOTO 23057
23056 CONTINUE
      IF(.NOT.(ARRAY(I) .EQ. 116 .OR. ARRAY(I) .EQ. 84))GOTO 23058
      ESC = 9
      GOTO 23059
23058 CONTINUE
      ESC = ARRAY(I)
23059 CONTINUE
23057 CONTINUE
23055 CONTINUE
23053 CONTINUE
      RETURN
      END
      SUBROUTINE FILSET(DELIM, ARRAY, I, SET, J, MAXSET)
      LOGICAL*1 ESC
      INTEGER ADDSET, INDEX
      INTEGER I, J, JUNK, MAXSET
      LOGICAL*1 ARRAY(100), DELIM, SET(MAXSET)
      LOGICAL*1 DIGITS(11)
      LOGICAL*1 LOWALF(27)
      LOGICAL*1 UPALF(27)
      DATA DIGITS(1)/48/, DIGITS(2)/49/, DIGITS(3)/50/
      DATA DIGITS(4)/51/, DIGITS(5)/52/, DIGITS(6)/53/
      DATA DIGITS(7)/54/, DIGITS(8)/55/, DIGITS(9)/56/
      DATA DIGITS(10)/57/, DIGITS(11)/0/
      DATA LOWALF(01)/97/
      DATA LOWALF(02)/98/
      DATA LOWALF(03)/99/
      DATA LOWALF(04)/100/
      DATA LOWALF(05)/101/
      DATA LOWALF(06)/102/
      DATA LOWALF(07)/103/
      DATA LOWALF(08)/104/
      DATA LOWALF(09)/105/
      DATA LOWALF(10)/106/
      DATA LOWALF(11)/107/
      DATA LOWALF(12)/108/
      DATA LOWALF(13)/109/
      DATA LOWALF(14)/110/
      DATA LOWALF(15)/111/
      DATA LOWALF(16)/112/
      DATA LOWALF(17)/113/
      DATA LOWALF(18)/114/
      DATA LOWALF(19)/115/
      DATA LOWALF(20)/116/
      DATA LOWALF(21)/117/
      DATA LOWALF(22)/118/
      DATA LOWALF(23)/119/
      DATA LOWALF(24)/120/
      DATA LOWALF(25)/121/
      DATA LOWALF(26)/122/
      DATA LOWALF(27)/0/
      DATA UPALF(01) /65/
      DATA UPALF(02) /66/
      DATA UPALF(03) /67/
      DATA UPALF(04) /68/
      DATA UPALF(05) /69/
      DATA UPALF(06) /70/
      DATA UPALF(07) /71/
      DATA UPALF(08) /72/
      DATA UPALF(09) /73/
      DATA UPALF(10) /74/
      DATA UPALF(11) /75/
      DATA UPALF(12) /76/
      DATA UPALF(13) /77/
      DATA UPALF(14) /78/
      DATA UPALF(15) /79/
      DATA UPALF(16) /80/
      DATA UPALF(17) /81/
      DATA UPALF(18) /82/
      DATA UPALF(19) /83/
      DATA UPALF(20) /84/
      DATA UPALF(21) /85/
      DATA UPALF(22) /86/
      DATA UPALF(23) /87/
      DATA UPALF(24) /88/
      DATA UPALF(25) /89/
      DATA UPALF(26) /90/
      DATA UPALF(27) /0/
23060 IF(.NOT.(ARRAY(I) .NE. DELIM .AND. ARRAY(I) .NE. 0))GOTO 23062
      IF(.NOT.(ARRAY(I) .EQ. 64))GOTO 23063
      JUNK = ADDSET(ESC(ARRAY, I), SET, J, MAXSET)
      GOTO 23064
23063 CONTINUE
      IF(.NOT.(ARRAY(I) .NE. 45))GOTO 23065
      JUNK = ADDSET(ARRAY(I), SET, J, MAXSET)
      GOTO 23066
23065 CONTINUE
      IF(.NOT.(J .LE. 1 .OR. ARRAY(I+1) .EQ. 0))GOTO 23067
      JUNK = ADDSET(45, SET, J, MAXSET)
      GOTO 23068
23067 CONTINUE
      IF(.NOT.(INDEX(DIGITS, SET(J-1)) .GT. 0))GOTO 23069
      CALL DODASH(DIGITS, ARRAY, I, SET, J, MAXSET)
      GOTO 23070
23069 CONTINUE
      IF(.NOT.(INDEX(LOWALF, SET(J-1)) .GT. 0))GOTO 23071
      CALL DODASH(LOWALF, ARRAY, I, SET, J, MAXSET)
      GOTO 23072
23071 CONTINUE
      IF(.NOT.(INDEX(UPALF, SET(J-1)) .GT. 0))GOTO 23073
      CALL DODASH(UPALF, ARRAY, I, SET, J, MAXSET)
      GOTO 23074
23073 CONTINUE
      JUNK = ADDSET(45, SET, J, MAXSET)
23074 CONTINUE
23072 CONTINUE
23070 CONTINUE
23068 CONTINUE
23066 CONTINUE
23064 CONTINUE
23061 I = I + 1
      GOTO 23060
23062 CONTINUE
      RETURN
      END
      INTEGER FUNCTION GETCCL(ARG, I, PAT, J)
      LOGICAL*1 ARG(128), PAT(128)
      INTEGER ADDSET
      INTEGER I, J, JSTART, JUNK
      I = I + 1
      IF(.NOT.(ARG(I) .EQ.  33))GOTO 23075
      JUNK = ADDSET(110, PAT, J, 128)
      I = I + 1
      GOTO 23076
23075 CONTINUE
      JUNK = ADDSET(91, PAT, J, 128)
23076 CONTINUE
      JSTART = J
      JUNK = ADDSET(0, PAT, J, 128)
      CALL FILSET(93, ARG, I, PAT, J, 128)
      PAT(JSTART) = J - JSTART - 1
      IF(.NOT.(ARG(I) .EQ. 93))GOTO 23077
      GETCCL = 0
      GOTO 23078
23077 CONTINUE
      GETCCL = -3
23078 CONTINUE
      RETURN
      END
      INTEGER FUNCTION GETPAT(ARG, PAT)
      INTEGER ARG(128), PAT(128)
      INTEGER MAKPAT
      GETPAT = MAKPAT(ARG, 1, 0, PAT)
      RETURN
      END
      INTEGER FUNCTION LOCATE(C, PAT, OFFSET)
      LOGICAL*1 C, PAT(128)
      INTEGER I, OFFSET
      I = OFFSET + PAT(OFFSET)
23079 IF(.NOT.(I .GT. OFFSET))GOTO 23081
      IF(.NOT.(C .EQ. PAT(I)))GOTO 23082
      LOCATE = 1
      RETURN
23082 CONTINUE
23080 I = I - 1
      GOTO 23079
23081 CONTINUE
      LOCATE = 0
      RETURN
      END
      INTEGER FUNCTION MAKPAT(ARG, FROM, DELIM, PAT)
      LOGICAL*1 ESC
      LOGICAL*1 ARG(128), DELIM, PAT(128)
      INTEGER ADDSET, GETCCL, STCLOS
      INTEGER FROM, I, J, JUNK, LASTCL, LASTJ, LJ
      J = 1
      LASTJ = 1
      LASTCL = 0
      I = FROM
23084 IF(.NOT.(ARG(I) .NE. DELIM .AND. ARG(I) .NE. 0))GOTO 23086
      LJ = J
      IF(.NOT.(ARG(I) .EQ. 63))GOTO 23087
      JUNK = ADDSET(63, PAT, J, 128)
      GOTO 23088
23087 CONTINUE
      IF(.NOT.(ARG(I) .EQ. 37 .AND. I .EQ. FROM))GOTO 23089
      JUNK = ADDSET(37, PAT, J, 128)
      GOTO 23090
23089 CONTINUE
      IF(.NOT.(ARG(I) .EQ. 36 .AND. ARG(I + 1) .EQ. DELIM))GOTO 23091
      JUNK = ADDSET(36, PAT, J, 128)
      GOTO 23092
23091 CONTINUE
      IF(.NOT.(ARG(I) .EQ. 91))GOTO 23093
      IF(.NOT.(GETCCL(ARG, I, PAT, J) .EQ. -3))GOTO 23095
      GOTO 23086
23095 CONTINUE
      GOTO 23094
23093 CONTINUE
      IF(.NOT.((ARG(I) .EQ. 42 .OR. ARG(I) .EQ. 43) .AND. I .GT. FROM))G
     *OTO 23097
      LJ = LASTJ
      IF(.NOT.(PAT(LJ) .EQ. 37 .OR. PAT(LJ) .EQ. 36 .OR. PAT(LJ) .EQ. 42
     * .OR. PAT(LJ) .EQ. 43))GOTO 23099
      GOTO 23086
23099 CONTINUE
      IF(.NOT.(ARG(I) .EQ. 43))GOTO 23101
      LASTJ = J
23103 IF(.NOT.(LJ .LT. LASTJ))GOTO 23105
      JUNK = ADDSET(PAT(LJ), PAT, J, 128)
23104 LJ = LJ + 1
      GOTO 23103
23105 CONTINUE
23101 CONTINUE
      LASTCL = STCLOS(PAT, J, LASTJ, LASTCL)
      GOTO 23098
23097 CONTINUE
      JUNK = ADDSET(97, PAT, J, 128)
      JUNK = ADDSET(ESC(ARG, I), PAT, J, 128)
23098 CONTINUE
23094 CONTINUE
23092 CONTINUE
23090 CONTINUE
23088 CONTINUE
      LASTJ = LJ
23085 I = I + 1
      GOTO 23084
23086 CONTINUE
      IF(.NOT.(ARG(I) .NE. DELIM))GOTO 23106
      MAKPAT = -3
      GOTO 23107
23106 CONTINUE
      IF(.NOT.(ADDSET(0, PAT, J, 128) .EQ. 0))GOTO 23108
      MAKPAT = -3
      GOTO 23109
23108 CONTINUE
      MAKPAT = I
23109 CONTINUE
23107 CONTINUE
      RETURN
      END
      INTEGER FUNCTION MATCH(LIN, PAT)
      LOGICAL*1 LIN(400), PAT(128)
      INTEGER AMATCH
      INTEGER I
      I = 1
23110 IF(.NOT.(LIN(I) .NE. 0))GOTO 23112
      IF(.NOT.(AMATCH(LIN, I, PAT) .GT. 0))GOTO 23113
      MATCH = 1
      RETURN
23113 CONTINUE
23111 I = I + 1
      GOTO 23110
23112 CONTINUE
      MATCH = 0
      RETURN
      END
      INTEGER FUNCTION OMATCH(LIN, I, PAT, J)
      LOGICAL*1 LIN(400), PAT(128)
      INTEGER LOCATE
      INTEGER BUMP, I, J
      OMATCH = 0
      IF(.NOT.(LIN(I) .EQ. 0))GOTO 23115
      RETURN
23115 CONTINUE
      BUMP = -1
      IF(.NOT.(PAT(J) .EQ. 97))GOTO 23117
      IF(.NOT.(LIN(I) .EQ. PAT(J + 1)))GOTO 23119
      BUMP = 1
23119 CONTINUE
      GOTO 23118
23117 CONTINUE
      IF(.NOT.(PAT(J) .EQ. 37))GOTO 23121
      IF(.NOT.(I .EQ. 1))GOTO 23123
      BUMP = 0
23123 CONTINUE
      GOTO 23122
23121 CONTINUE
      IF(.NOT.(PAT(J) .EQ. 63))GOTO 23125
      IF(.NOT.(LIN(I) .NE. 10))GOTO 23127
      BUMP = 1
23127 CONTINUE
      GOTO 23126
23125 CONTINUE
      IF(.NOT.(PAT(J) .EQ. 36))GOTO 23129
      IF(.NOT.(LIN(I) .EQ. 10))GOTO 23131
      BUMP = 0
23131 CONTINUE
      GOTO 23130
23129 CONTINUE
      IF(.NOT.(PAT(J) .EQ. 91))GOTO 23133
      IF(.NOT.(LOCATE(LIN(I), PAT, J + 1) .EQ. 1))GOTO 23135
      BUMP = 1
23135 CONTINUE
      GOTO 23134
23133 CONTINUE
      IF(.NOT.(PAT(J) .EQ. 110))GOTO 23137
      IF(.NOT.(LIN(I) .NE. 10 .AND. LOCATE(LIN(I), PAT, J + 1) .EQ. 0))G
     *OTO 23139
      BUMP = 1
23139 CONTINUE
      GOTO 23138
23137 CONTINUE
      CALL ERROR(23Hin omatch: cant happen.)
23138 CONTINUE
23134 CONTINUE
23130 CONTINUE
23126 CONTINUE
23122 CONTINUE
23118 CONTINUE
      IF(.NOT.(BUMP .GE. 0))GOTO 23141
      I = I + BUMP
      OMATCH = 1
23141 CONTINUE
      RETURN
      END
      INTEGER FUNCTION PATSIZ(PAT, N)
      LOGICAL*1 PAT(128)
      INTEGER N
      IF(.NOT.(PAT(N) .EQ. 97))GOTO 23143
      PATSIZ = 2
      GOTO 23144
23143 CONTINUE
      IF(.NOT.(PAT(N) .EQ. 37 .OR. PAT(N) .EQ. 36 .OR. PAT(N) .EQ. 63))G
     *OTO 23145
      PATSIZ = 1
      GOTO 23146
23145 CONTINUE
      IF(.NOT.(PAT(N) .EQ. 91 .OR. PAT(N) .EQ. 110))GOTO 23147
      PATSIZ = PAT(N + 1) + 2
      GOTO 23148
23147 CONTINUE
      IF(.NOT.(PAT(N) .EQ. 42))GOTO 23149
      PATSIZ = 4
      GOTO 23150
23149 CONTINUE
      CALL ERROR(23Hin patsiz: cant happen.)
23150 CONTINUE
23148 CONTINUE
23146 CONTINUE
23144 CONTINUE
      RETURN
      END
      INTEGER FUNCTION STCLOS(PAT, J, LASTJ, LASTCL)
      LOGICAL*1 PAT(128)
      INTEGER ADDSET
      INTEGER J, JP, JT, JUNK, LASTCL, LASTJ
      JP = J - 1
23151 IF(.NOT.(JP .GE. LASTJ))GOTO 23153
      JT = JP + 4
      JUNK = ADDSET(PAT(JP), PAT, JT, 128)
23152 JP = JP - 1
      GOTO 23151
23153 CONTINUE
      J = J + 4
      STCLOS = LASTJ
      JUNK = ADDSET(42, PAT, LASTJ, 128)
      JUNK = ADDSET(0, PAT, LASTJ, 128)
      JUNK = ADDSET(LASTCL, PAT, LASTJ, 128)
      JUNK = ADDSET(0, PAT, LASTJ, 128)
      RETURN
      END
      INTEGER FUNCTION GMATCH(LIN, PAT, ELEVEL, ANDPAT)
      INTEGER ELEVEL, ANDPAT, MATCH, I, STATUS
      LOGICAL*1 LIN(100), PAT(128, 10)
      GMATCH = ANDPAT
      I=1
23154 IF(.NOT.(I .LE. ELEVEL))GOTO 23156
      STATUS = MATCH(LIN, PAT(1,I))
      IF(.NOT.(ANDPAT .EQ. 0 .AND. STATUS .EQ. 1))GOTO 23157
      GMATCH = 1
      GOTO 23156
23157 CONTINUE
      IF(.NOT.(ANDPAT .EQ. 1 .AND. STATUS .EQ. 0))GOTO 23159
      GMATCH = 0
      GOTO 23156
23159 CONTINUE
23158 CONTINUE
23155 I=I+1
      GOTO 23154
23156 CONTINUE
      RETURN
      END
      SUBROUTINE FINERR
      CALL ERROR(47Husage:  find [-acx] expression [expression ...])
      RETURN
      END
