medit/doc/makedocs

74 lines
1.7 KiB
Bash
Executable File

#! /bin/sh
# makedocs INPUT
srcdir=`cd \`dirname $1\` && pwd`
thisdir=`pwd`
infile="$1"
outfile="$thisdir"/`basename $infile .t2t`.html
outdir="$thisdir/help"
shift
stamp="$1"
shift
rm -f stamp-help.tmp
for arg; do
if [ ! -f "$arg" ]; then
echo "OOPS" >&2
else
(cd $srcdir && md5sum "$arg") >> stamp-help.tmp
fi
done
if [ -z "$TXT2TAGS" ]; then
TXT2TAGS=txt2tags
fi
SPLITY="perl -I$srcdir $srcdir/splity/splity.pl"
SPLITY_INDEX="$srcdir/splity/index-template.html"
SPLITY_PAGE="$srcdir/splity/page-template.html"
if test ! -f "$infile"; then
echo "Input file '$infile' does not exist"
exit 1
fi
if test ! -e "$outdir"; then
echo "Directory $outdir does not exist"
exit 1
fi
$TXT2TAGS --version >/dev/null 2>/dev/null || {
echo "*** WARNING: txt2tags has not been found, docs will not be regenerated ***" >&2
exit 0
}
generate () {
$TXT2TAGS --outfile=$2 $1 || exit 1
(cd "$outdir" && $SPLITY -index $SPLITY_INDEX -page $SPLITY_PAGE $2) || exit 1
}
write_sections () {
echo "#ifndef HELP_SECTIONS_H" > $2
echo "#define HELP_SECTIONS_H" >> $2
echo "" >> $2
for s in `grep '@@.*@@' $1 | sed 's/.*@@\(.*\)@@.*/\1/'`; do
echo "#define HELP_SECTION_`echo $s | tr '[a-z]' '[A-Z]' | tr -- - _` \"$s\"" >> $2
done
echo "" >> $2
echo "#endif /* HELP_SECTIONS_H */" >> $2
}
generate $infile $outfile || exit 1
write_sections $outfile help-sections.h.tmp || exit 1
cmp -s help-sections.h.tmp help-sections.h || cp help-sections.h.tmp help-sections.h || exit 1
rm -f help-sections.h.tmp
rm $outfile || exit 1
if cmp -s stamp-help.tmp "$stamp"; then
touch "$stamp" || exit 1
else
mv stamp-help.tmp "$stamp" || exit 1
fi
rm -f stamp-help.tmp