1*3ee4fc2aSCody Peter Mello#!/bin/bash
2*3ee4fc2aSCody Peter Mello
3*3ee4fc2aSCody Peter Melloif [[ -z "$AWK" || -z "$WORKDIR" ]]; then
4*3ee4fc2aSCody Peter Mello    printf '$AWK and $WORKDIR must be set\n' >&2
5*3ee4fc2aSCody Peter Mello    exit 1
6*3ee4fc2aSCody Peter Mellofi
7*3ee4fc2aSCody Peter Mello
8*3ee4fc2aSCody Peter MelloTEMP1=$WORKDIR/test.temp.1
9*3ee4fc2aSCody Peter MelloTEMP2=$WORKDIR/test.temp.2
10*3ee4fc2aSCody Peter Mello
11*3ee4fc2aSCody Peter MelloRESULT=0
12*3ee4fc2aSCody Peter Mello
13*3ee4fc2aSCody Peter Mellofail() {
14*3ee4fc2aSCody Peter Mello	echo "$1" >&2
15*3ee4fc2aSCody Peter Mello	RESULT=1
16*3ee4fc2aSCody Peter Mello}
17*3ee4fc2aSCody Peter Mello
18*3ee4fc2aSCody Peter Melloecho T.recache: test re cache in b.c
19*3ee4fc2aSCody Peter Mello	# thanks to ross ridge for this horror
20*3ee4fc2aSCody Peter Mello
21*3ee4fc2aSCody Peter Melloecho b > $TEMP1
22*3ee4fc2aSCody Peter Mello$AWK '
23*3ee4fc2aSCody Peter MelloBEGIN {
24*3ee4fc2aSCody Peter Mello        #
25*3ee4fc2aSCody Peter Mello        # Fill up DFA cache with run-time REs that have all been
26*3ee4fc2aSCody Peter Mello        # used twice.
27*3ee4fc2aSCody Peter Mello        #
28*3ee4fc2aSCody Peter Mello        CACHE_SIZE=64
29*3ee4fc2aSCody Peter Mello        for(i = 0; i < CACHE_SIZE; i++) {
30*3ee4fc2aSCody Peter Mello                for(j = 0; j < 2; j++) {
31*3ee4fc2aSCody Peter Mello                        "" ~ i "";
32*3ee4fc2aSCody Peter Mello                }
33*3ee4fc2aSCody Peter Mello        }
34*3ee4fc2aSCody Peter Mello        #
35*3ee4fc2aSCody Peter Mello        # Now evalutate an expression that uses two run-time REs
36*3ee4fc2aSCody Peter Mello        # that have never been used before.  The second RE will
37*3ee4fc2aSCody Peter Mello        # push the first out of the cache while the first RE is
38*3ee4fc2aSCody Peter Mello        # still needed.
39*3ee4fc2aSCody Peter Mello        #
40*3ee4fc2aSCody Peter Mello        x = "a"
41*3ee4fc2aSCody Peter Mello        reg1 = "[Aa]"
42*3ee4fc2aSCody Peter Mello        reg2 = "A"
43*3ee4fc2aSCody Peter Mello        sub(reg1, x ~ reg2 ? "B" : "b", x)
44*3ee4fc2aSCody Peter Mello
45*3ee4fc2aSCody Peter Mello        print x
46*3ee4fc2aSCody Peter Mello}
47*3ee4fc2aSCody Peter Mello' > $TEMP2
48*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.recache'
49*3ee4fc2aSCody Peter Mello
50*3ee4fc2aSCody Peter Melloexit $RESULT
51