2018-05-01 12:18:03 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
2017-09-10 18:42:45 +00:00
|
|
|
|
|
|
|
# This script checks that the table of contents for the supported tools is
|
|
|
|
# sorted, and that the table matches the files.
|
|
|
|
|
2019-02-13 21:22:02 +00:00
|
|
|
toc_section_start_line="$(
|
|
|
|
grep -m1 -n '^7\..*\*ale-other-integration-options\*' doc/ale.txt \
|
|
|
|
| sed 's/\([0-9]*\).*/\1/' \
|
|
|
|
)"
|
|
|
|
toc_start_offset="$( \
|
|
|
|
tail -n +"$toc_section_start_line" doc/ale.txt \
|
|
|
|
| grep -m1 -n '^ .*\.\.\.' \
|
2017-09-10 18:42:45 +00:00
|
|
|
| sed 's/\([0-9]*\).*/\1/' \
|
|
|
|
)"
|
|
|
|
# shellcheck disable=SC2003
|
2019-02-13 21:22:02 +00:00
|
|
|
toc_start_line="$(expr "$toc_section_start_line" + "$toc_start_offset" - 1)"
|
2017-09-10 18:42:45 +00:00
|
|
|
toc_section_size="$( \
|
|
|
|
tail -n +"$toc_start_line" doc/ale.txt \
|
2019-02-13 21:22:02 +00:00
|
|
|
| grep -m1 -n '^===*$' \
|
2017-09-10 18:42:45 +00:00
|
|
|
| sed 's/\([0-9]*\).*/\1/' \
|
|
|
|
)"
|
|
|
|
# shellcheck disable=SC2003
|
2019-02-13 21:22:02 +00:00
|
|
|
toc_end_line="$(expr "$toc_start_line" + "$toc_section_size" - 4)"
|
2017-09-10 18:42:45 +00:00
|
|
|
|
|
|
|
toc_file="$(mktemp -t table-of-contents.XXXXXXXX)"
|
|
|
|
heading_file="$(mktemp -t headings.XXXXXXXX)"
|
2017-09-10 18:52:01 +00:00
|
|
|
tagged_toc_file="$(mktemp -t ale.txt.XXXXXXXX)"
|
2017-09-10 18:42:45 +00:00
|
|
|
sorted_toc_file="$(mktemp -t sorted-ale.txt.XXXXXXXX)"
|
|
|
|
|
|
|
|
sed -n "$toc_start_line,$toc_end_line"p doc/ale.txt \
|
2019-02-13 21:22:02 +00:00
|
|
|
| sed 's/^ \( *[^.][^.]*\)\.\.*|\(..*\)|/\1, \2/' \
|
2017-09-10 18:42:45 +00:00
|
|
|
> "$toc_file"
|
|
|
|
|
|
|
|
# Get all of the doc files in a natural sorted order.
|
2020-11-28 17:44:19 +00:00
|
|
|
doc_files="$(/usr/bin/env ls -1v doc | grep '^ale-' | sed 's/^/doc\//' | paste -sd ' ' -)"
|
2017-09-10 18:42:45 +00:00
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
2017-10-24 23:27:40 +00:00
|
|
|
grep -h '\*ale-.*-options\|^[a-z].*\*ale-.*\*$' $doc_files \
|
2017-09-10 18:42:45 +00:00
|
|
|
| sed 's/^/ /' \
|
|
|
|
| sed 's/ALE Shell Integration/ALE sh Integration/' \
|
2018-11-07 08:33:14 +00:00
|
|
|
| sed 's/ALE BibTeX Integration/ALE bib Integration/' \
|
2017-10-22 08:42:36 +00:00
|
|
|
| sed 's/ ALE \(.*\) Integration/\1/' \
|
|
|
|
| sed 's/ *\*\(..*\)\*$/, \1/' \
|
|
|
|
| tr '[:upper:]' '[:lower:]' \
|
2017-09-10 18:42:45 +00:00
|
|
|
| sed 's/objective-c/objc/' \
|
|
|
|
| sed 's/c++/cpp/' \
|
|
|
|
> "$heading_file"
|
|
|
|
|
|
|
|
exit_code=0
|
|
|
|
in_section=0
|
|
|
|
section_index=0
|
|
|
|
|
2017-09-10 18:52:01 +00:00
|
|
|
# Prefix numbers to table of contents entries so that sections aren't mixed up
|
|
|
|
# with sub-sections when they are sorted.
|
2017-09-10 18:42:45 +00:00
|
|
|
while read -r; do
|
|
|
|
if [[ "$REPLY" =~ ^\ ]]; then
|
|
|
|
if ! ((in_section)); then
|
|
|
|
let section_index='section_index + 1'
|
|
|
|
in_section=1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if ((in_section)); then
|
|
|
|
let section_index='section_index + 1'
|
|
|
|
in_section=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-09-10 18:52:01 +00:00
|
|
|
echo "$section_index $REPLY" >> "$tagged_toc_file"
|
2017-09-10 18:42:45 +00:00
|
|
|
done < "$toc_file"
|
|
|
|
|
2017-09-10 18:52:01 +00:00
|
|
|
# Sort the sections and sub-sections and remove the tags.
|
2017-10-22 08:42:36 +00:00
|
|
|
sort -sn "$tagged_toc_file" | sed 's/[0-9][0-9]* //' > "$sorted_toc_file"
|
2017-09-10 18:42:45 +00:00
|
|
|
|
|
|
|
echo 'Check for bad ToC sorting:'
|
|
|
|
echo
|
2017-09-10 18:52:01 +00:00
|
|
|
diff -U2 "$sorted_toc_file" "$toc_file" || exit_code=$?
|
2017-09-10 18:42:45 +00:00
|
|
|
|
|
|
|
echo 'Check for mismatched ToC and headings:'
|
|
|
|
echo
|
|
|
|
diff -U3 "$toc_file" "$heading_file" || exit_code=$?
|
|
|
|
|
|
|
|
rm "$toc_file"
|
|
|
|
rm "$heading_file"
|
2017-09-10 18:52:01 +00:00
|
|
|
rm "$tagged_toc_file"
|
2017-09-10 18:42:45 +00:00
|
|
|
rm "$sorted_toc_file"
|
|
|
|
|
|
|
|
exit "$exit_code"
|