diff --git a/CMake/allexec2man.sh b/CMake/allexec2man.sh index b8a68a18ef..1d4722f750 100755 --- a/CMake/allexec2man.sh +++ b/CMake/allexec2man.sh @@ -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 diff --git a/CMake/exec2man.sh b/CMake/exec2man.sh index b0807fc614..30268e5300 100755 --- a/CMake/exec2man.sh +++ b/CMake/exec2man.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Convert the output of an MLPACK executable into a man page. This assumes that +# Convert the output of an mlpack executable into a man page. This assumes that # the CLI subsystem is used to output help, that the executable is properly # documented, and that the program is run in the directory that the executable # is in. Usually, this is used by CMake on Linux/UNIX systems to generate the @@ -11,13 +11,36 @@ # 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=$("$exec" --version | sed 's/^.* \([^ ]*\)\.$/\1/') + # Generate the synopsis. # First, required options. -reqoptions=`./"$name" -h | \ - awk '/Required options:/,/Options:/' | \ +reqoptions="$("$exec" --help | \ + awk '/Required input options:/,/Optional input options:/' | \ grep '^ --' | \ sed 's/^ --/--/' | \ sed 's/^--[A-Za-z0-9_-]* (\(-[A-Za-z0-9]\))/\1/' | \ @@ -27,11 +50,11 @@ 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 | \ - awk '/Options:/,/For further information,/' | \ +options="$("$exec" -h | \ + awk '/Optional input options:/,/For further information,/' | \ grep '^ --' | \ sed 's/^ --/--/' | \ grep -v -- '--help' | \ @@ -48,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 [-h] [-v] $reqoptions $options"; +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 /' | \ @@ -65,16 +88,16 @@ synopsis="$name [-h] [-v] $reqoptions $options"; # 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./' | \ + sed 's/^distribution of mlpack./ distribution of mlpack./' | \ awk -v syn="$synopsis" \ '{ if (NR == 1) print "NAME\n '"$name"' - "tolower($0)"\nSYNOPSIS\n "syn" \nDESCRIPTION\n" ; else print } ' | \ sed '/^[^ ]/ y/qwertyuiopasdfghjklzxcvbnm:/QWERTYUIOPASDFGHJKLZXCVBNM /' | \ sed 's/ / /g' | \ - awk '/NAME/,/REQUIRED OPTIONS/ { print; } /ADDITIONAL INFORMATION/,0 { print; } /REQUIRED OPTIONS/,/ADDITIONAL INFORMATION/ { if (!/REQUIRED_OPTIONS/ && !/OPTIONS/ && !/ADDITIONAL INFORMATION/) { if (/ --/) { printf "\n" } sub(/^[ ]*/, ""); sub(/ [ ]*/, " "); printf "%s ", $0; } else { if (!/REQUIRED OPTIONS/ && !/ADDITIONAL INFORMATION/) { print "\n"$0; } } }' | \ + awk '/NAME/,/.*OPTIONS/ { if (!/.*OPTIONS/) { print; } } /ADDITIONAL INFORMATION/,0 { print; } /.*OPTIONS/,/ADDITIONAL INFORMATION/ { if (!/REQUIRED INPUT OPTIONS/ && !/OPTIONAL INPUT OPTIONS/ && !/OPTIONAL OUTPUT OPTIONS/ && !/ADDITIONAL INFORMATION/) { if (/ --/) { printf "\n" } sub(/^[ ]*/, ""); sub(/ [ ]*/, " "); printf "%s ", $0; } else { if (!/ADDITIONAL INFORMATION/) { print "\n"$0; } } }' | \ sed 's/ ADDITIONAL INFORMATION/\n\nADDITIONAL INFORMATION/' | \ - txt2man -P mlpack -t "$name" -d 1 | \ + txt2man -t "$name" -s 1 -r "mlpack-$version" -v "User Commands" | \ sed "s/^'/\\\\(aq/" > "$output" diff --git a/src/mlpack/methods/rann/ra_model_impl.hpp b/src/mlpack/methods/rann/ra_model_impl.hpp index 093ce74d10..7e4753603c 100644 --- a/src/mlpack/methods/rann/ra_model_impl.hpp +++ b/src/mlpack/methods/rann/ra_model_impl.hpp @@ -222,7 +222,7 @@ bool& SingleModeVisitor::operator()(RAType* ra) const { if (ra) return ra->SingleMode(); - throw std::runtime_error("no rank-approximate model is intialized"); + throw std::runtime_error("no rank-approximate model is initialized"); } //! Exposes the referenceSet of the given RAType. @@ -231,7 +231,7 @@ const arma::mat& ReferenceSetVisitor::operator()(RAType* ra) const { if (ra) return ra->ReferenceSet(); - throw std::runtime_error("no rank-approximate model is intialized"); + throw std::runtime_error("no rank-approximate model is initialized"); } //! Exposes the Naive() method of the given RAType instance. @@ -240,7 +240,7 @@ bool& NaiveVisitor::operator()(RAType* ra) const { if (ra) return ra->Naive(); - throw std::runtime_error("no rank-approximate search model is intialized"); + throw std::runtime_error("no rank-approximate search model is initialized"); } //! For cleaning memory