Explain the table of contents script better, and simplify it a bit

This commit is contained in:
w0rp 2017-09-10 19:52:01 +01:00
parent 9d24cc4047
commit 65e6e50bf8
1 changed files with 8 additions and 8 deletions

View File

@ -19,7 +19,7 @@ toc_end_line="$(expr "$toc_start_line" + "$toc_section_size" - 2)"
toc_file="$(mktemp -t table-of-contents.XXXXXXXX)"
heading_file="$(mktemp -t headings.XXXXXXXX)"
unsorted_toc_file="$(mktemp -t ale.txt.XXXXXXXX)"
tagged_toc_file="$(mktemp -t ale.txt.XXXXXXXX)"
sorted_toc_file="$(mktemp -t sorted-ale.txt.XXXXXXXX)"
sed -n "$toc_start_line,$toc_end_line"p doc/ale.txt \
@ -43,6 +43,8 @@ exit_code=0
in_section=0
section_index=0
# Prefix numbers to table of contents entries so that sections aren't mixed up
# with sub-sections when they are sorted.
while read -r; do
if [[ "$REPLY" =~ ^\ ]]; then
if ! ((in_section)); then
@ -56,17 +58,15 @@ while read -r; do
fi
fi
echo "$section_index $REPLY" >> "$unsorted_toc_file"
echo "$section_index $REPLY" >> "$tagged_toc_file"
done < "$toc_file"
sort -h "$unsorted_toc_file" | sed 's/[0-9]\+//' > "$sorted_toc_file"
sed -i.bak 's/[0-9]\+//' "$unsorted_toc_file"
rm -f "$unsorted_toc_file".bak
# Sort the sections and sub-sections and remove the tags.
sort -h "$tagged_toc_file" | sed 's/[0-9]\+ //' > "$sorted_toc_file"
echo 'Check for bad ToC sorting:'
echo
diff -U2 "$sorted_toc_file" "$unsorted_toc_file" || exit_code=$?
diff -U2 "$sorted_toc_file" "$toc_file" || exit_code=$?
echo 'Check for mismatched ToC and headings:'
echo
@ -74,7 +74,7 @@ diff -U3 "$toc_file" "$heading_file" || exit_code=$?
rm "$toc_file"
rm "$heading_file"
rm "$unsorted_toc_file"
rm "$tagged_toc_file"
rm "$sorted_toc_file"
exit "$exit_code"