-
Notifications
You must be signed in to change notification settings - Fork 36
/
check.sh
executable file
·175 lines (169 loc) · 5.44 KB
/
check.sh
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
usage() {
echo "$0 COMMAND [section]"
echo ""
echo "Where COMMAND is one of:"
echo ""
echo "hyperlink Show a list of unused hyperlinks."
echo "passive Show sentences with passive voice."
echo "weasel Show sentences with weasel words."
echo "dupe Show sentences with duplicate words."
echo "diction Show sentences with poor phrasing."
echo "long Show sentences that are too long."
echo "uncovered Show topics without coverage."
echo "all Perform all checks."
echo
echo "Examples:"
echo
echo "$0 all Check all issues in all sections"
echo "$0 all 04 Check all issues in section 04"
echo "$0 passive 00 Check for passive voice in section 00"
}
irregulars="awoken|\
been|born|beat|\
become|begun|bent|\
beset|bet|bid|\
bidden|bound|bitten|\
bled|blown|broken|\
bred|brought|broadcast|\
built|burnt|burst|\
bought|cast|caught|\
chosen|clung|come|\
cost|crept|cut|\
dealt|dug|dived|\
done|drawn|dreamt|\
driven|drunk|eaten|fallen|\
fed|felt|fought|found|\
fit|fled|flung|flown|\
forbidden|forgotten|\
foregone|forgiven|\
forsaken|frozen|\
gotten|given|gone|\
ground|grown|hung|\
heard|hidden|hit|\
held|hurt|kept|knelt|\
knit|known|laid|led|\
leapt|learnt|left|\
lent|let|lain|lighted|\
lost|made|meant|met|\
misspelt|mistaken|mown|\
overcome|overdone|overtaken|\
overthrown|paid|pled|proven|\
put|quit|read|rid|ridden|\
rung|risen|run|sawn|said|\
seen|sought|sold|sent|\
set|sewn|shaken|shaven|\
shorn|shed|shone|shod|\
shot|shown|shrunk|shut|\
sung|sunk|sat|slept|\
slain|slid|slung|slit|\
smitten|sown|spoken|sped|\
spent|spilt|spun|spit|\
split|spread|sprung|stood|\
stolen|stuck|stung|stunk|\
stridden|struck|strung|\
striven|sworn|swept|\
swollen|swum|swung|taken|\
taught|torn|told|thought|\
thrived|thrown|thrust|\
trodden|understood|upheld|\
upset|woken|worn|woven|\
wed|wept|wound|won|\
withheld|withstood|wrung|\
written"
weasels="many|various|very|fairly|several|extremely\
|exceedingly|quite|remarkably|few|surprisingly\
|mostly|largely|huge|tiny|((are|is) a number)\
|excellent|interestingly|significantly\
|substantially|clearly|vast|relatively|completely"
for file in `ls textbook`; do
# Enforce one sentence per line
sed -i.bak -E -e "s/([a-zA-Z])([.!?]) /\1\2\n/g" textbook/$file
rm textbook/$file.bak
done
# Fix line endings
if [[ $OS == "Windows_NT" ]]; then
dos2unix textbook/*.md
fi
if [ $# = 2 ]; then
section=$2
else
section=""
fi
# Check for problems
if [ $# = 0 ]; then
usage
exit
# Hyperlink check
elif [ $1 = "hyperlink" ]; then
./generate.sh html
echo
grep -E -e "href=|id=" build/CompilerDesign.html | grep -v "TOC" | sed -E -e "s/.*(id|href)=\"[#]?([^\"]+)\".*/\2/" | sort | uniq -u | grep -E -v -e "http|mailto" | while read line; do
grep -E -n -H -e "$line" textbook/$section* | while read innerline; do
echo "Broken hyperlink: $innerline"
done
done
# Passive voice check, adapted from:
# http://matt.might.net/articles/shell-scripts-for-passive-voice-weasel-words-duplicates/
elif [ $1 = "passive" ]; then
grep -E -r -n -i "\\b(am|are|were|being|is|been|was|be)\\b[ ]*(\w+ed|($irregulars))\\b" textbook/$section* | egrep -v '>TODO' | while read line; do
echo "Passive voice: $line"
done
# Weasel word check, adapted from the same source.
# These words make prose worse.
elif [ $1 = "weasel" ]; then
egrep -E -r -n -i "\\b($weasels)\\b" textbook/$section* | while read line; do
echo "Weasel word: $line"
done
# Count sentence length. Sentences longer than 20 words are too long.
elif [ $1 = "long" ]; then
for file in `ls textbook/$section*`; do
cat -n "$file" | tr -d "[:punct:]" | while read line; do
length=`echo "$line" | wc -w`
if [ $length -gt 20 ]; then
echo "Long sentence ($length words): $file: $line"
fi
done
done
# Duplicate word check. Sentences should not repeat themselves.
elif [ $1 = "dupe" ]; then
for file in `ls textbook/$section*`; do
cat -n "$file" | tr -d "[:punct:]" | sed -E -e "s/\\b(a|as|an|and|the|is|in|it|was|were|to|from|of)\\b//gI" | while read line; do
dupe=`echo "$line" | tr " " "\n" | sort -f | uniq -d`
if [ "$dupe" ]; then
dupes=`echo $dupe | tr '\n' ' '`
lineno=`echo $line | sed -E -e "s/([0-9]+).*/\1/"`
echo "Duplicate words ($dupes): $file: $lineno"
fi
done
done
# Warn about poor phrasing. Requires diction. http://www.gnu.org/software/diction/
elif [ $1 = "diction" ]; then
dictionCommand="$(which diction)"
if [ -z "$dictionCommand" ]; then
dictionCommand="dependencies/diction/bin/diction.exe"
fi
if [ ! -e "$dictionCommand" ]; then
echo "ERROR: install required dependencies first. Run:"
echo
echo " ./generate.sh install"
echo
exit
fi
"$dictionCommand" -b -s textbook/$section*
# Check for uncovered topics. To indicate coverage, copy the topic line to wherever the text covers the topic.
elif [ $1 = "uncovered" ]; then
cat textbook/$section* | grep -E -e "^[0-9]\.[0-9]" | sort | uniq -u | while read line; do
echo "Topic without coverage: $line"
done
elif [ $1 = "all" ]; then
$0 hyperlink "$section"
$0 passive "$section"
$0 weasel "$section"
$0 dupe "$section"
$0 long "$section"
$0 uncovered "$section"
$0 diction "$section"
else
usage
fi