Purpose: generate a webpage documenting a script.
Usage: script_page script
Fills in fields in template.html, assumed to be in the working directory.
Changelog:
2023-236 initial development
2023-246 exit on error
2025-182 fix newlines and backslashes
Source code (perhaps slightly corrupted) is as follows.
if [ -z "$1" ] || ! [ -f "$1" ]
then
echo "${0}: expected script filename"
exit 1
fi
SCRIPT_NAME="${1%.*}"
SUFFIX="${1##*.}"
PURPOSE=`sed '2 s/^.* - //; 2 p; d' <"$1"`
USAGE=`sed '3 s/^\(#\|--\) usage: //; 3 p; d' <"$1"`
DESC=`sed '/^\(#\|--\)$/,$ d; 1,3 d; s/^\(#\|--\) //' <"$1"`
CHLOG=`sed '1,/^\(#\|--\) Changelog:$/ d; /^\(#\|--\)$/,$ d; s/^\(#\|--\) //; s/^/
/' <"$1"`
SRC=`sed '1,/^$/ d' <"$1"`
PAGE_NAME="${SCRIPT_NAME}.html"
cp template.html "$PAGE_NAME"
BELL=`printf '\x07'`
bs() {
for I in $(seq "$1")
do
printf '\'
done
}
sub() {
RV=`printf '%s' "$2" | paste -sd "${BELL}"`
RV=`printf '%s\n' "$RV" | sed "s/$(bs 2)\(.\)/$(bs 4)\/g; s/${BELL}/$(bs 2)n/g"`
SC="s${BELL}\$$1${BELL}$RV${BELL}g"
sed -i "$SC" "$PAGE_NAME"
}
sub script_name "$SCRIPT_NAME"
sub suffix "$SUFFIX"
sub purpose "$PURPOSE"
sub usage "$USAGE"
sub description "$DESC"
sub changelog "$CHLOG"
sub source "$SRC"