      SUBROUTINE MAIN
      LOGICAL*1 EXP(128,10), PAT(128,10), LIN(512), ARG(128), INFILE(40)
      INTEGER I, GETARG, EXCEPT, ANDPAT, COUNT, ELEVEL, ITOC, GETPAT, MC
     *OUNT, GETLIN, MATCHD, STATUS, GMATCH, INDEX, INT, OPEN
      LOGICAL*1 USESTR(51)
      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
     *14/,USESTR(10)/101/,USESTR(11)/115/,USESTR(12)/111/,USESTR(13)/108
     */,USESTR(14)/118/,USESTR(15)/101/,USESTR(16)/32/,USESTR(17)/91/,US
     *ESTR(18)/45/,USESTR(19)/97/,USESTR(20)/99/,USESTR(21)/120/,USESTR(
     *22)/93/,USESTR(23)/32/,USESTR(24)/101/,USESTR(25)/120/,USESTR(26)/
     *112/,USESTR(27)/114/,USESTR(28)/101/,USESTR(29)/115/,USESTR(30)/11
     *5/,USESTR(31)/105/,USESTR(32)/111/,USESTR(33)/110/,USESTR(34)/32/,
     *USESTR(35)/91/,USESTR(36)/101/,USESTR(37)/120/,USESTR(38)/112/,USE
     *STR(39)/114/,USESTR(40)/101/,USESTR(41)/115/,USESTR(42)/115/,USEST
     *R(43)/105/,USESTR(44)/111/,USESTR(45)/110/,USESTR(46)/93/,USESTR(4
     *7)/32/,USESTR(48)/46/,USESTR(49)/46/,USESTR(50)/46/,USESTR(51)/0/
      DATA EXCEPT/0/
      DATA ANDPAT/0/
      DATA COUNT /0/
      DATA ELEVEL/0/
      CALL QUERY(USESTR)
      CALL ADRFIL(INFILE)
      INT = OPEN(INFILE, 1)
      IF (.NOT.(INT .EQ. -3))GOTO 23000
      CALL CANT(INFILE)
23000 CONTINUE
      I=1
23002 IF (.NOT.(GETARG(I, ARG, 128) .NE. -1))GOTO 23004
      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 FOLD(ARG)
      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
23003 I=I+1
      GOTO 23002
23004 CONTINUE
      IF (.NOT.(ELEVEL .EQ. 0))GOTO 23015
      CALL ERROR(USESTR)
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, INT) .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 PUTINT(MCOUNT, 1,2)
      CALL PUTCH(10,2)
23028 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
23030 IF (.NOT.(I .LE. ELEVEL))GOTO 23032
      STATUS = MATCH(LIN, PAT(1,I))
      IF (.NOT.(ANDPAT .EQ. 0 .AND. STATUS .EQ. 1))GOTO 23033
      GMATCH = 1
      GOTO 23032
23033 CONTINUE
      IF (.NOT.(ANDPAT .EQ. 1 .AND. STATUS .EQ. 0))GOTO 23035
      GMATCH = 0
      GOTO 23032
23035 CONTINUE
23034 CONTINUE
23031 I=I+1
      GOTO 23030
23032 CONTINUE
      RETURN
      END
