      SUBROUTINE MAIN
      LOGICAL*1 ARG(128), LIN(512), NEW(512), TO(132)
      INTEGER FROM(132), PAT(132, 10)
      INTEGER ADDSET, AMATCH, GETARG, GETLIN, GETPAT, GETSUB
      INTEGER GMATCH, INDEXC, ITOC
      INTEGER ANDPAT, EXCEPT, FRARG, I, JUNK, K, LASTM, M, NARG
      INTEGER NPAT, STATUS, TOARG
      LOGICAL*1 USESTR(45)
      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)/9
     *9/,USESTR(10)/104/,USESTR(11)/32/,USESTR(12)/91/,USESTR(13)/45/,US
     *ESTR(14)/97/,USESTR(15)/120/,USESTR(16)/93/,USESTR(17)/32/,USESTR(
     *18)/91/,USESTR(19)/101/,USESTR(20)/120/,USESTR(21)/112/,USESTR(22)
     */114/,USESTR(23)/101/,USESTR(24)/115/,USESTR(25)/115/,USESTR(26)/1
     *05/,USESTR(27)/111/,USESTR(28)/110/,USESTR(29)/93/,USESTR(30)/32/,
     *USESTR(31)/46/,USESTR(32)/46/,USESTR(33)/46/,USESTR(34)/32/,USESTR
     *(35)/102/,USESTR(36)/114/,USESTR(37)/111/,USESTR(38)/109/,USESTR(3
     *9)/32/,USESTR(40)/91/,USESTR(41)/116/,USESTR(42)/111/,USESTR(43)/9
     *3/,USESTR(44)/46/,USESTR(45)/0/
      CALL QUERY(USESTR)
      EXCEPT = 0
      ANDPAT = 0
      NARG = 0
      I = 1 
23000 IF (.NOT.(GETARG( I, ARG, 128) .NE. -1 ))GOTO 23002
      IF (.NOT.( ARG(1) .EQ. 45 ))GOTO 23003
      CALL STRCPY( ARG, LIN)
      CALL FOLD(LIN)
      IF (.NOT.( INDEXC( LIN, 97) .GT. 0 ))GOTO 23005
      ANDPAT = 1
23005 CONTINUE
      IF (.NOT.( INDEXC( LIN, 120) .GT. 0 ))GOTO 23007
      EXCEPT = 1
23007 CONTINUE
      CALL DELARG(I)
      I = I - 1
      GOTO 23004
23003 CONTINUE
      NARG = NARG + 1
23004 CONTINUE
23001 I = I + 1 
      GOTO 23000
23002 CONTINUE
      IF (.NOT.( NARG .EQ. 0 ))GOTO 23009
      CALL ERROR(USESTR)
      GOTO 23010
23009 CONTINUE
      IF (.NOT.( NARG .EQ. 1 .OR. NARG .EQ. 2 ))GOTO 23011
      FRARG = 1
      TOARG = 2
      NPAT = 1
      GOTO 23012
23011 CONTINUE
      TOARG = NARG
      FRARG = NARG - 1
      NPAT = NARG - 2
23012 CONTINUE
23010 CONTINUE
      IF (.NOT.( NPAT .GT. 10 ))GOTO 23013
      CALL PUTLIN( 45H? Maximum number of expressions permitted is , 3)
      I = ITOC( 10, ARG, 128)
      CALL ERROR(ARG)
23013 CONTINUE
      JUNK = GETARG( FRARG, ARG, 128)
      IF (.NOT.( GETPAT( ARG, FROM) .EQ. -3 ))GOTO 23015
      CALL ERROR( 27H? Illegal fromexpr pattern. )
23015 CONTINUE
      IF (.NOT.( GETARG( TOARG, ARG, 128) .EQ. -1 ))GOTO 23017
      ARG(1) = 0
23017 CONTINUE
      IF (.NOT.( GETSUB( ARG, TO) .EQ. -3 ))GOTO 23019
      CALL ERROR( 17H? Illegal toexpr. )
23019 CONTINUE
      I = 1 
23021 IF (.NOT.(I .LE. NPAT ))GOTO 23023
      JUNK = GETARG( I, ARG, 128)
      IF (.NOT.( GETPAT( ARG, PAT( 1, I) ) .EQ. -3 ))GOTO 23024
      CALL PUTLIN( 19H? Illegal pattern: , 3)
      CALL ERROR(ARG)
23024 CONTINUE
23022 I = I + 1 
      GOTO 23021
23023 CONTINUE
23026 IF (.NOT.( GETLIN( LIN, 1) .NE. -1 ))GOTO 23027
      STATUS = GMATCH( LIN, PAT, NPAT, ANDPAT)
      IF (.NOT.( ( STATUS .EQ. 1 .AND. EXCEPT .EQ. 0 ) .OR. ( STATUS .EQ
     *. 0 .AND. EXCEPT .EQ. 1 ) ))GOTO 23028
      K = 1
      LASTM = 0
      I = 1 
23030 IF (.NOT.(LIN(I) .NE. 0 ))GOTO 23032
      M = AMATCH( LIN, I, FROM)
      IF (.NOT.( M .GT. 0 .AND. LASTM .NE. M ))GOTO 23033
      CALL CATSUB( LIN, I, M, TO, NEW, K, 512)
      LASTM = M
23033 CONTINUE
      IF (.NOT.( M .EQ. 0 .OR. M .EQ. I ))GOTO 23035
      JUNK = ADDSET( LIN(I), NEW, K, 512)
      I = I + 1
      GOTO 23036
23035 CONTINUE
      I = M
23036 CONTINUE
23031 GOTO 23030
23032 CONTINUE
      IF (.NOT.( ADDSET( 0, NEW, K, 512) .EQ. 0 ))GOTO 23037
      K = 512
      JUNK = ADDSET( 0, NEW, K, 512)
      CALL REMARK( 18H? Line truncated:. )
      CALL PUTLIN( NEW, 3)
      CALL PUTCH( 10, 3)
23037 CONTINUE
      CALL PUTLIN( NEW, 2)
      GOTO 23029
23028 CONTINUE
      CALL PUTLIN( LIN, 2)
23029 CONTINUE
      GOTO 23026
23027 CONTINUE
      RETURN
      END
      INTEGER FUNCTION GMATCH( LIN, PAT, ELEVEL, ANDPAT)
      LOGICAL*1 LIN(100)
      INTEGER ANDPAT, ELEVEL, I, PAT(132, 10), STATUS
      INTEGER MATCH
      I = 1 
23039 IF (.NOT.(I .LE. ELEVEL ))GOTO 23041
      STATUS = MATCH( LIN, PAT( 1, I) )
      IF (.NOT.( ANDPAT .EQ. 0 .AND. STATUS .EQ. 1 ))GOTO 23042
      GMATCH=(1)
      RETURN
23042 CONTINUE
      IF (.NOT.( ANDPAT .EQ. 1 .AND. STATUS .EQ. 0 ))GOTO 23044
      GMATCH=(0)
      RETURN
23044 CONTINUE
23043 CONTINUE
23040 I = I + 1 
      GOTO 23039
23041 CONTINUE
      GMATCH=(ANDPAT)
      RETURN
      END
