      SUBROUTINE MAIN
      LOGICAL*1 BUF(512)
      INTEGER GTWORD
      CALL QUERY(26Husage:  txtrpl patfile ...)
      CALL INIPAT(BUF)
23000 IF (.NOT.(GTWORD(BUF, 1) .NE. -1))GOTO 23001
      CALL REPLAC(BUF, 2)
      GOTO 23000
23001 CONTINUE
      RETURN
      END
      LOGICAL*1 FUNCTION GTCH(C, INT)
      LOGICAL*1 C
      INTEGER INT
      LOGICAL*1 GETCH
      COMMON / CUNGET / PBCHAR
      LOGICAL*1 PBCHAR
      IF (.NOT.(PBCHAR .NE. 0))GOTO 23002
      C = PBCHAR
      PBCHAR = 0
      GOTO 23003
23002 CONTINUE
      C = GETCH(C, INT)
23003 CONTINUE
      GTCH=(C)
      RETURN
      END
      INTEGER FUNCTION GTWORD(BUF, INT)
      LOGICAL*1 BUF(512), C
      INTEGER INT
      INTEGER I, T
      LOGICAL*1 GTCH
      INTEGER TYPE, LENGTH
      C = GTCH(BUF(1), INT)
      IF (.NOT.(C .EQ. -1))GOTO 23004
      GTWORD=(-1)
      RETURN
23004 CONTINUE
      IF (.NOT.(TYPE(C) .NE. 1))GOTO 23006
      BUF(2) = 0
      GOTO 23007
23006 CONTINUE
      I=2
23008 IF (.NOT.(GTCH(C, INT) .NE. -1))GOTO 23010
      T = TYPE(C)
      IF (.NOT.(T .NE. 1 .AND. T .NE. 2 .AND. T .NE. 95))GOTO 23011
      GOTO 23010
23011 CONTINUE
      BUF(I) = C
23012 CONTINUE
23009 I=I+1
      GOTO 23008
23010 CONTINUE
      CALL UNGTCH(C, INT)
      BUF(I) = 0
23007 CONTINUE
      GTWORD=(LENGTH(BUF))
      RETURN
      END
      SUBROUTINE INIPAT(BUF)
      LOGICAL*1 BUF(512), PAT(512), FILE(40)
      INTEGER I, J, JUNK
      INTEGER INT
      INTEGER GETARG, GETLIN, GETWRD, LENGTH
      INTEGER OPEN
      INTEGER MEM( 5000)
      LOGICAL*1 CMEM(10000)
      EQUIVALENCE (CMEM(1),MEM(1))
      COMMON/CDSMEM/MEM
      COMMON / CUNGET / PBCHAR
      LOGICAL*1 PBCHAR
      PBCHAR = 0
      CALL TBINIT(5000)
      I=1
23013 IF (.NOT.(GETARG(I, FILE, 40) .NE. -1))GOTO 23015
      INT = OPEN(FILE, 1)
      IF (.NOT.(INT .EQ. -3))GOTO 23016
      CALL CANT(FILE)
23016 CONTINUE
23018 IF (.NOT.(GETLIN(BUF, INT) .NE. -1))GOTO 23019
      J = 1
      JUNK = GETWRD(BUF, J, PAT)
      CALL SKIPBL(BUF, J)
      CALL SCOPY(BUF, J, BUF, 1)
      J = LENGTH(BUF)
      BUF(J) = 0
      CALL TBINST(PAT, BUF)
      GOTO 23018
23019 CONTINUE
      CALL CLOSE(INT)
23014 I=I+1
      GOTO 23013
23015 CONTINUE
      RETURN
      END
      SUBROUTINE UNGTCH(C, INT)
      LOGICAL*1 C
      INTEGER INT
      COMMON / CUNGET / PBCHAR
      LOGICAL*1 PBCHAR
      IF (.NOT.(PBCHAR .NE. 0))GOTO 23020
      CALL ERROR(45HAttempt to push back more than one character.)
23020 CONTINUE
      PBCHAR = C
      RETURN
      END
      SUBROUTINE REPLAC(BUF, OUT)
      LOGICAL*1 BUF(512), DEFN(512)
      INTEGER OUT
      INTEGER TBLOOK
      IF (.NOT.(TBLOOK(BUF, DEFN) .EQ. 1))GOTO 23022
      CALL PUTLIN(DEFN, OUT)
      GOTO 23023
23022 CONTINUE
      CALL PUTLIN(BUF, OUT)
23023 CONTINUE
      RETURN
      END
