: ${chapter_digits:=2}
mv ch00.html start.html
export chapter_digits A
for A in ch*.html; do
	N=`perl -e '$ENV{A} =~ /([1-9][0-9]*)/; print $1'`
	echo $A
	{
	cat start.html "$A"
	echo
	echo "<p>"
	prev_chapter="ch`printf %0${chapter_digits}d $[ $N - 1 ]`.html"
	next_chapter="ch`printf %0${chapter_digits}d $[ $N + 1 ]`.html"
	if [ -e "$prev_chapter" ]; then
		echo -n "<a href=\"$prev_chapter\">prev</a> "
	fi
		echo -n "<a href=\".\">up</a> "
	if [ -e "$next_chapter" ]; then
		echo -n "<a href=\"$next_chapter\">next</a> "
	fi
	echo
	echo "</p>"
	echo
	echo '</body>'
	echo '</html>'
	} >"$A.1"
	mv "$A.1" "$A"
done
rm start.html
