Tweak manpage-generation scripts {,all}exec2man.sh

Allow executable being documented by exec2man.sh to be specified with
a relative path.

Output cogent usage instructions when invoked incorrectly.

Use politically correct $(...) as `...` has been deprecated by
glorious POSIX.

Allow allexec2man.sh to use relative paths to exec2man.sh
This commit is contained in:
Barak A. Pearlmutter
2018-04-06 15:14:28 +01:00
parent 87e50cd982
commit 8af6c2e7cf
2 changed files with 46 additions and 21 deletions
+18 -13
View File
@@ -1,22 +1,27 @@
#!/bin/bash
#
# Convert all of the executables in this directory that are not tests to man
# pages in the given directory.
#
# Usage:
# allexec2man.sh /full/path/of/exec2man.sh output_directory/
#
# For the executable 'cheese', the file 'cheese.1.gz' will be created in the
# output directory.
set -e
if [ $# != 2 ]; then
echo "Convert all of the executables in this directory that are not tests to man"
echo "pages in the given directory."
echo
echo "Usage:"
echo " allexec2man.sh /full/path/of/exec2man.sh output_directory/"
echo
echo "For the executable 'cheese', the file 'cheese.1.gz' will be created in the"
echo "output directory."
exit 1
fi
exec2man="$1"
outdir="$2"
mkdir -p "$outdir"
for program in `find . -perm /u=x,g=x,o=x -iname 'mlpack_*' | \
for program in $(find . -type f -executable -iname 'mlpack_*' | \
grep -v '[.]$' | \
grep -v '_test$' | \
sed 's|^./||'`; do
grep -v '_test$'); do
echo "Generating man page for $program...";
"$1" "$program" "$outdir/$program.1"
"$exec2man" "$program" "$outdir/$program.1"
gzip -f "$outdir/$program.1"
done
+28 -8
View File
@@ -11,15 +11,35 @@
# No warranties...
#
# @author Ryan Curtin
name="$1"
set -e
if [ $# != 2 ]; then
echo "Generates man page from the help text of an mlpack utility program."
echo "Usage: $0 mlpack_executable generated-man-page.1"
exit 1
fi
exec="$1"
name="$(basename "$exec")"
output="$2"
if [ "$name" = "$exec" ]; then
# if no directory prefix with explict ./ to avoid path search
exec="./$exec"
fi
if [ ! -x "$exec" ]; then
echo "error: cannot find executable file $exec"
exit 1
fi
# Get the version.
version=`./"$name" --version | sed 's/^.* \([^ ]*\)\.$/\1/'`
version=$("$exec" --version | sed 's/^.* \([^ ]*\)\.$/\1/')
# Generate the synopsis.
# First, required options.
reqoptions=`./"$name" -h | \
reqoptions="$("$exec" --help | \
awk '/Required input options:/,/Optional input options:/' | \
grep '^ --' | \
sed 's/^ --/--/' | \
@@ -30,10 +50,10 @@ reqoptions=`./"$name" -h | \
sed 's/\(^--[A-Za-z0-9_-]* \[[A-Za-z0-9]*\]\) [^[].*/\1/' | \
tr '\n' ' ' | \
sed 's/\[//g' | \
sed 's/\]//g'`
sed 's/\]//g')"
# Then, regular options.
options=`./"$name" -h | \
options="$("$exec" -h | \
awk '/Optional input options:/,/For further information,/' | \
grep '^ --' | \
sed 's/^ --/--/' | \
@@ -51,12 +71,12 @@ options=`./"$name" -h | \
sed 's/\(-[A-Za-z0-9]\)\( [^a-z]\)/\[\1\]\2/g' | \
sed 's/\(--[A-Za-z0-9_-]*\)\( [^a-z]\)/\[\1\]\2/g' | \
sed 's/\(-[A-Za-z0-9] [a-z]*\) /\[\1\] /g' | \
sed 's/\(--[A-Za-z0-9_-]* [a-z]*\) /\[\1\] /g'`
sed 's/\(--[A-Za-z0-9_-]* [a-z]*\) /\[\1\] /g')"
synopsis="$name $reqoptions $options [-h -v]";
# Preview the whole thing first.
#./$name -h | \
#"$exec" -h | \
# awk -v syn="$synopsis" \
# '{ if (NR == 1) print "NAME\n '$name' - "tolower($0)"\nSYNOPSIS\n "syn" \nDESCRIPTION\n" ; else print } ' | \
# sed '/^[^ ]/ y/qwertyuiopasdfghjklzxcvbnm:/QWERTYUIOPASDFGHJKLZXCVBNM /' | \
@@ -68,7 +88,7 @@ synopsis="$name $reqoptions $options [-h -v]";
# helps avoid 'man' warnings).
# The sed line at the end removes accidental macros from the output, replacing
# single-quotes at the beginning of a line with the troff escape code \(aq.
./"$name" -h | \
"$exec" -h | \
sed 's/^For further information/Additional Information\n\n For further information/' | \
sed 's/^consult the documentation/ consult the documentation/' | \
sed 's/^distribution of mlpack./ distribution of mlpack./' | \