summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/dist/s_string
blob: e547133b9ee4fcaa615af805c44763a0c1016ff1 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh -
#
# Check spelling in comments and quoted strings from the source files.

t=__wt.$$
trap 'rm -f $t' 0 1 2 3 13 15

# Insulate against locale-specific sort order
LC_ALL=C
export LC_ALL

# If aspell has not been installed, quit
type aspell > /dev/null 2>&1 || {
    echo "$0 skipped: aspell not found"
    exit 0
}

# replace:
#    Create a replacement list of spelling words. This is here because the
# words we ignore changes over time and it's worth periodically collapsing
# the list. Don't it too often, the list is correct for many different aspell
# catalogs and generating a shorter list on any single system will break other
# systems.
replace() {
    aspell --mode=ccpp --lang=en_US list < ../$1 |
    sort -u |
    comm -12 /dev/stdin s_string.ok
}

# check:
#    Check the spelling of an individual file.
check() {
    # Strip out git hashes, which are seven character hex strings.
    # Strip out double quote char literals ('"'), they confuse aspell.
    # Strip out calls to __wt_getopt so the option lists don't have to be spelling words.
    # Strip out C-style hex constants.
    sed -e 's/ [0-9a-f]\{7\} / /g' -e "s/'\"'//g" -e 's/__wt_getopt([^()]*)//' -e 's/0x[[:xdigit:]]\{1,\}/ /g' ../$2 |
    aspell --lang=en_US $1 list |
    sort -u |
    comm -23 /dev/stdin s_string.ok > $t
    test -s $t && {
        echo "==== $2"
        cat $t
    }
}

# List of files to spellchk.
l=$(cd .. &&
    find bench examples ext src test -name '*.[chsy]' &&
    find src -name '*.in' &&
    find test -name '*.cpp')

usage()
{
    echo 'usage: s_string [-r]' >&2
    exit 1
}

exit_val=0
while :
    do case "$1" in
    -r)            # -r builds replacement list of OK words
        for f in $l; do
            replace $f
        done | sort -u > $t

        # Between aspell versions 0.60.7-20110707 and 0.60.8 the following program names have been
        # added to the dictionary and are no longer considered spelling errors. This means
        # that building a replacement list of words with the newer version of aspell will omit them
        # from s_string.ok, and subsequently running s_string with older aspell version will
        # report spelling errors. Manually whitelist these names to address this.
        prog_names="AWS AWS's MongoDB MONGODB PostgreSQL sanitizer sanitizers"
        for name in $prog_names; do
            echo $name >> $t
        done
        sort -u -o $t $t

	if ! diff $t s_string.ok >/dev/null 2>&1; then
            echo "The string.ok list will be updated to remove words that are no longer needed."
            cp $t s_string.ok
            exit_val=1
        else
            echo "No need to update the string.ok list."
        fi
        shift;;
    *)
        test "$#" -eq 0 || usage
        break;;
    esac
done

# Check source files.
for f in $l; do
    check "--mode=ccpp" $f
done

exit $exit_val