diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2010-02-19 09:54:05 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2010-02-19 09:54:05 (GMT) |
commit | e6e4973e6ac3dd76e4de51082f4ecf53f5ac7eb4 (patch) | |
tree | 42d57232c0a6716e2d8860a40bb5c09e62af49fe /unix | |
parent | 75bf2508e3fdda7b0fb86b63d1cb8e14954cd880 (diff) | |
download | tcl-e6e4973e6ac3dd76e4de51082f4ecf53f5ac7eb4.zip tcl-e6e4973e6ac3dd76e4de51082f4ecf53f5ac7eb4.tar.gz tcl-e6e4973e6ac3dd76e4de51082f4ecf53f5ac7eb4.tar.bz2 |
[Bug 2954638]: Correct behaviour of manual page installer. Also added armouring
to check that assumptions about the initial state are actually valid (e.g.,
look for existing input file).
Diffstat (limited to 'unix')
-rwxr-xr-x | unix/installManPage | 103 |
1 files changed, 76 insertions, 27 deletions
diff --git a/unix/installManPage b/unix/installManPage index 993d097..e636db7 100755 --- a/unix/installManPage +++ b/unix/installManPage @@ -1,12 +1,29 @@ #!/bin/sh -ZIP=: +######################################################################## +### Parse Options +### + +Gzip=: +SymOrLoc="" +Gz="" +Suffix="" + while true; do case $1 in - -s | --symlinks ) S="-s ";; - -z | --compress ) ZIP=$2; shift ;; - -e | --extension ) Z=$2; shift ;; - -s | --suffix ) SUFFIX=$2; shift ;; + -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 ;; *) break ;; esac shift @@ -16,16 +33,32 @@ if test "$#" != 2; then exit 1 fi -MANPAGE=$1 -DIR=$2 -test -z "$S" && S="$DIR/" +######################################################################## +### 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 +### # A sed script to parse the alternative names out of a man page. # # Backslashes are trippled in the sed script, because it is in # backticks which doesn't pass backslashes literally. # -NAMES=`sed -n ' +Names=`sed -n ' # Look for a line, that starts with .SH NAME # optionally allow NAME to be surrounded # by quotes. @@ -40,28 +73,44 @@ NAMES=`sed -n ' s/ \\\-.*// # print the result and exit p;q - }' $MANPAGE` + }' $ManPage` + +if test -z $Names ; then + echo "warning: no target names found in $ManPage" +fi -case $MANPAGE in - *.1) SECTION=1 ;; - *.3) SECTION=3 ;; - *.n) SECTION=n ;; +######################################################################## +### Remaining Set Up +### + +case $ManPage in + *.1) Section=1 ;; + *.3) Section=3 ;; + *.n) Section=n ;; + *) echo "unknown section for $ManPage" + exit 2 ;; esac -SRCDIR=`dirname $MANPAGE` +SrcDir=`dirname $ManPage` + +######################################################################## +### Process Page to Create Target Pages +### -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 +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 else - rm -f $DIR/$f $DIR/$f.* - ln $S$FIRST$Z $DIR/$f$Z + ln $SymOrLoc$First$Gz $Dir/$Target$Gz fi done + +######################################################################## +exit 0 |