aboutsummaryrefslogtreecommitdiff
path: root/build/check-awk.awk
blob: 425867ef8d12e5ebd45b5bd006d63e33039fb2d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# This script is used to check that a given awk executable
# implements the match() and substr() functions appropriately.
#
# These were introduced in nawk/gawk, but the original awk
# does not have them.
#
BEGIN {
    RSTART=0
    RLENGTH=0
    s1="A real world example"
    if (! match(s1,"world")) {
        print "Fail match"
    } else if (RSTART != 8) {
        print "Fail RSTART ="RSTART
    } else if (RLENGTH != 5) {
        print "Fail RLENGTH ="RLENGTH
    } else {
        s2=substr(s1,RSTART,RLENGTH)
        if (s2 != "world") {
            print "Fail substr="s2
        } else {
            print "Pass"
        }
    }
}