3 # Copyright (C) 2019-2023 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This script intends to facilitate spell checking of source/doc files.
19 # - transforms the files into a list of lowercase words
20 # - prefixes each word with the frequency
21 # - filters out words within a frequency range
22 # - sorts the words, longest first
24 # If '-c' is passed as option, it operates on the C comments only, rather than
29 # $ files=$(find gdb -type f -name "*.c" -o -name "*.h")
30 # $ ./gdb/contrib/words.sh -c $files
32 # it generates a list of ~15000 words prefixed with frequency.
34 # This could be used to generate a dictionary that is kept as part of the
35 # sources, against which new code can be checked, generating a warning or
36 # error. The hope is that misspellings would trigger this frequently, and rare
37 # words rarely, otherwise the burden of updating the dictionary would be too
42 # $ files=$(find gdb -type f -name "*.c" -o -name "*.h")
43 # $ ./gdb/contrib/words.sh -c -f 1 $files
45 # it generates a list of ~5000 words with frequency 1.
47 # This can be used to scan for misspellings manually.
53 while [ $# -gt 0 ]; do
66 if [ "$maxfreq" = "" ]; then
73 if [ "$minfreq" = "" ]; then
84 if [ "$minfreq" = "" ] && [ "$maxfreq" = "" ]; then
90 trap 'rm -f "$awkfile"' EXIT
92 cat > "$awkfile" <<EOF
103 sub(/.*\/\*/, "", line)
107 sub(/\*\/.*/, "", line)
131 -e 's/[!"?;:%^$~#{}`&=@,. \t\/_()|<>\+\*-]/\n/g' \
135 -e 's/[0-9][0-9]*/\n/g' \
137 |
tr '[:upper:]' '[:lower:]' \
140 |
awk "{ if (($minfreq == 0 || $minfreq <= \$1) \
141 && ($maxfreq == 0 || \$1 <= $maxfreq)) { print \$0; } }" \
142 |
awk '{ print length($0) " " $0; }' \