summaryrefslogtreecommitdiffstats
path: root/unix/installManPage
diff options
context:
space:
mode:
Diffstat (limited to 'unix/installManPage')
-rwxr-xr-xunix/installManPage132
1 files changed, 41 insertions, 91 deletions
diff --git a/unix/installManPage b/unix/installManPage
index 4d615bf..93fd925 100755
--- a/unix/installManPage
+++ b/unix/installManPage
@@ -1,29 +1,12 @@
#!/bin/sh
-########################################################################
-### Parse Options
-###
-
-Gzip=:
-SymOrLoc=""
-Gz=""
-Suffix=""
-
+ZIP=:
while true; do
case $1 in
- -s | --symlinks ) SymOrLoc="-s " ;;
- -z | --compress ) Gzip=$2; shift ;;
- -e | --extension ) Gz=$2; shift ;;
- -x | --suffix ) Suffix=$2; shift ;;
- -*) cat <<EOF
-Unknown option "$1". Supported options:
- -s Use symbolic links for manpages with multiple names.
- -z PROG Use PROG to compress manual pages.
- -e EXT Defines the extension added by -z PROG when compressing.
- -x SUFF Defines an extra extension suffix to use.
-Option names may not be combined getopt-style.
-EOF
- exit 1 ;;
+ -s | --symlinks ) S="-s ";;
+ -z | --compress ) ZIP=$2; shift ;;
+ -e | --extension ) Z=$2; shift ;;
+ -s | --suffix ) SUFFIX=$2; shift ;;
*) break ;;
esac
shift
@@ -33,85 +16,52 @@ if test "$#" != 2; then
exit 1
fi
-########################################################################
-### Parse Required Arguments
-###
-
-ManPage=$1
-Dir=$2
-if test -f $ManPage ; then : ; else
- echo "source manual page file must exist"
- exit 1
-fi
-if test -d $Dir ; then : ; else
- echo "target directory must exist"
- exit 1
-fi
-test -z "$SymOrLoc" && SymOrLoc="$Dir/"
-
-########################################################################
-### Extract Target Names from Manual Page
-###
+MANPAGE=$1
+DIR=$2
+test -z "$S" && S="$DIR/"
# A sed script to parse the alternative names out of a man page.
#
+# /^\\.SH NAME/{ ;# Look for a line, that starts with .SH NAME
+# s/^.*$// ;# Delete the content of this line from the buffer
+# n ;# Read next line
+# s/,//g ;# Remove all commas ...
+# s/\\\ //g ;# .. and backslash-escaped spaces.
+# s/ \\\-.*// ;# Delete from \- to the end of line
+# p ;# print the result
+# q ;# exit
+# }
+#
# Backslashes are trippled in the sed script, because it is in
-# backticks which doesn't pass backslashes literally.
+# backticks which don't pass backslashes literally.
#
-Names=`sed -n '
-# Look for a line that starts with .SH NAME
- /^\.SH NAME/{
-# Read next line
+# Please keep the commented version above updated if you
+# change anything to the script below.
+NAMES=`sed -n '
+ /^\\.SH NAME/{
+ s/^.*$//
n
-# Remove all commas ...
s/,//g
-# ... and backslash-escaped spaces.
s/\\\ //g
-# Delete from \- to the end of line
s/ \\\-.*//
-# Convert all non-space non-alphanum sequences
-# to single underscores.
- s/[^ A-Za-z0-9][^ A-Za-z0-9]*/_/g
-# print the result and exit
- p;q
- }' $ManPage`
-
-if test -z "$Names" ; then
- echo "warning: no target names found in $ManPage"
-fi
-
-########################################################################
-### Remaining Set Up
-###
+ p
+ q
+ }' $MANPAGE`
-case $ManPage in
- *.1) Section=1 ;;
- *.3) Section=3 ;;
- *.n) Section=n ;;
- *) echo "unknown section for $ManPage"
- exit 2 ;;
-esac
-
-SrcDir=`dirname $ManPage`
-
-########################################################################
-### Process Page to Create Target Pages
-###
-
-First=""
-for Target in $Names; do
- Target=$Target.$Section$Suffix
- rm -f $Dir/$Target $Dir/$Target.*
- if test -z "$First" ; then
- First=$Target
- sed -e "/man\.macros/r $SrcDir/man.macros" -e "/man\.macros/d" \
- $ManPage > $Dir/$First
- chmod 444 $Dir/$First
- $Gzip $Dir/$First
+SECTION=`echo $MANPAGE | sed 's/.*\(.\)$/\1/'`
+SRCDIR=`dirname $MANPAGE`
+FIRST=""
+for f in $NAMES; do
+ f=$f.$SECTION$SUFFIX
+ if test -z "$FIRST" ; then
+ FIRST=$f
+ rm -f $DIR/$FIRST $DIR/$FIRST.*
+ sed -e "/man\.macros/r $SRCDIR/man.macros" -e "/man\.macros/d" \
+ $MANPAGE > $DIR/$FIRST
+ chmod 444 $DIR/$FIRST
+ $ZIP $DIR/$FIRST
else
- ln $SymOrLoc$First$Gz $Dir/$Target$Gz
+ rm -f $DIR/$f $DIR/$f.*
+ ln $S$FIRST$Z $DIR/$f$Z
fi
done
-
-########################################################################
-exit 0