makeusage.sh 933 Bytes
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#! /bin/sh
# Convert a pod file into a usage function for the GeographicLib utilities.

SOURCE=$1
NAME=`basename $SOURCE .pod`
VERSION=$2

(
cat<<EOF
int usage(int retval, bool brief) {
  if (brief)
    ( retval ? std::cerr : std::cout ) << "Usage:\n\\
EOF

pod2man $SOURCE | nroff -c -man 2>/dev/null | col -b -x |
sed -e 1,/SYNOPSIS/d -e '/^$/,$d' -e 's/  / /g' -e 's/$/\\n\\/' -e 's/"/\\"/g'

cat <<EOF
\n\\
For full documentation type:\n\\
    $NAME --help\n\\
or visit:\n\\
    https://geographiclib.sourceforge.io/$VERSION/$NAME.1.html\n";
  else
    ( retval ? std::cerr : std::cout ) << "Man page:\n\\
EOF

pod2man $SOURCE | nroff -c -man 2>/dev/null | col -b -x | head --lines -4 |
tail --lines +5 | sed -e 's/\\/\\\\/g' -e 's/$/\\n\\/' -e 's/"/\\"/g'

cat <<EOF
";
  return retval;
}
EOF
) | # Break long strings assuming that files don't contain the ~ character
tr '\n' '~' | sed -e's/\\~/"~"/g' -e's/""//g' | tr '~' '\n'