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