      SUBROUTINE MAIN
      LOGICAL*1 EXP(128,10), PAT(128,10), LIN(512), ARG(128)
      INTEGER I, GETARG, EXCEPT, ANDPAT, COUNT, ELEVEL, ITOC, GETPAT, MC
     *OUNT, GETLIN, MATCHD, STATUS, GMATCH, INDEX
      LOGICAL*1 USESTR(48)
      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
     *02/,USESTR(10)/105/,USESTR(11)/110/,USESTR(12)/100/,USESTR(13)/32/
     *,USESTR(14)/91/,USESTR(15)/45/,USESTR(16)/97/,USESTR(17)/99/,USEST
     *R(18)/120/,USESTR(19)/93/,USESTR(20)/32/,USESTR(21)/101/,USESTR(22
     *)/120/,USESTR(23)/112/,USESTR(24)/114/,USESTR(25)/101/,USESTR(26)/
     *115/,USESTR(27)/115/,USESTR(28)/105/,USESTR(29)/111/,USESTR(30)/11
     *0/,USESTR(31)/32/,USESTR(32)/91/,USESTR(33)/101/,USESTR(34)/120/,U
     *SESTR(35)/112/,USESTR(36)/114/,USESTR(37)/101/,USESTR(38)/115/,USE
     *STR(39)/115/,USESTR(40)/105/,USESTR(41)/111/,USESTR(42)/110/,USEST
     *R(43)/93/,USESTR(44)/32/,USESTR(45)/46/,USESTR(46)/46/,USESTR(47)/
     *46/,USESTR(48)/0/
      DATA EXCEPT/0/
      DATA ANDPAT/0/
      DATA COUNT /0/
      DATA ELEVEL/0/
      CALL QUERY(USESTR)
      I=1
23000 IF (.NOT.(GETARG(I, ARG, 128) .NE. -1))GOTO 23002
      IF (.NOT.(ARG(1) .EQ. 45))GOTO 23003
      CALL SCOPY(ARG, 1, LIN, 1)
      CALL FOLD(LIN)
      IF (.NOT.(INDEX(LIN, 97) .GT. 0))GOTO 23005
      ANDPAT = 1
23005 CONTINUE
      IF (.NOT.(INDEX(LIN, 99) .GT. 0))GOTO 23007
      COUNT = 1
23007 CONTINUE
      IF (.NOT.(INDEX(LIN, 120) .GT. 0))GOTO 23009
      EXCEPT = 1
23009 CONTINUE
      GOTO 23004
23003 CONTINUE
      IF (.NOT.(ELEVEL .LT. 10))GOTO 23011
      ELEVEL = ELEVEL + 1
      CALL SCOPY(ARG, 1, EXP(1, ELEVEL), 1)
      GOTO 23012
23011 CONTINUE
      CALL PUTLIN(43HMaximum number of expressions permitted is , 3)
      STATUS = ITOC(10, ARG, 128)
      CALL ERROR(ARG)
23012 CONTINUE
23004 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      IF (.NOT.(ELEVEL .EQ. 0))GOTO 23013
      CALL ERROR(USESTR)
23013 CONTINUE
      I=1
23015 IF (.NOT.(I .LE. ELEVEL))GOTO 23017
      IF (.NOT.(GETPAT(EXP(1,I), PAT(1,I)) .EQ. -3))GOTO 23018
      CALL PUTLIN(17Hillegal pattern: , 3)
      CALL ERROR(EXP(1,I))
23018 CONTINUE
23016 I=I+1
      GOTO 23015
23017 CONTINUE
      MCOUNT = 0
23020 IF (.NOT.(GETLIN(LIN, 1) .NE. -1))GOTO 23021
      MATCHD = GMATCH(LIN, PAT, ELEVEL, ANDPAT)
      IF (.NOT.((MATCHD .EQ. 1 .AND. EXCEPT .EQ. 0) .OR. (MATCHD .EQ. 0 
     *.AND. EXCEPT .EQ. 1)))GOTO 23022
      IF (.NOT.(COUNT .EQ. 1))GOTO 23024
      MCOUNT = MCOUNT + 1
      GOTO 23025
23024 CONTINUE
      CALL PUTLIN(LIN, 2)
23025 CONTINUE
23022 CONTINUE
      GOTO 23020
23021 CONTINUE
      IF (.NOT.(COUNT .EQ. 1))GOTO 23026
      CALL PUTINT(MCOUNT, 1,2)
      CALL PUTCH(10,2)
23026 CONTINUE
      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
23028 IF (.NOT.(I .LE. ELEVEL))GOTO 23030
      STATUS = MATCH(LIN, PAT(1,I))
      IF (.NOT.(ANDPAT .EQ. 0 .AND. STATUS .EQ. 1))GOTO 23031
      GMATCH = 1
      GOTO 23030
23031 CONTINUE
      IF (.NOT.(ANDPAT .EQ. 1 .AND. STATUS .EQ. 0))GOTO 23033
      GMATCH = 0
      GOTO 23030
23033 CONTINUE
23032 CONTINUE
23029 I=I+1
      GOTO 23028
23030 CONTINUE
      RETURN
      END
