openpkg/man.sh

Mon, 28 Jan 2013 17:37:18 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 28 Jan 2013 17:37:18 +0100
changeset 758
a2c6460cfb16
parent 13
cb59d6afeb61
permissions
-rw-r--r--

Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.

     1 #!@l_prefix@/lib/openpkg/bash
     2 ##
     3 ##  man -- OpenPKG Tool Chain "man" command
     4 ##  Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/>
     5 ##
     6 ##  This software is property of the OpenPKG GmbH, DE MUC HRB 160208.
     7 ##  All rights reserved. Licenses which grant limited permission to use,
     8 ##  copy, modify and distribute this software are available from the
     9 ##  OpenPKG GmbH.
    10 ##
    11 ##  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
    12 ##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    13 ##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    14 ##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
    15 ##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    16 ##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    17 ##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    18 ##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    19 ##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    20 ##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    21 ##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    22 ##  SUCH DAMAGE.
    23 ##
    25 #   configuration
    26 prefix="@l_prefix@"
    28 #   minimum command line parsing
    29 opt_h=no
    30 while [ 1 ]; do
    31     case "$1" in
    32         -h | --help ) opt_h=yes; shift ;;
    33         * ) break ;;
    34     esac
    35 done
    36 if [ ".$opt_h" = .yes ]; then
    37     echo "openpkg:man:USAGE: openpkg man [--help] [<section>] <command>"
    38     exit 0
    39 fi
    40 if [ $# -eq 1 ]; then
    41     man_page="$1"
    42 elif [ $# -eq 2 ]; then
    43     man_sect="$1"
    44     man_page="$2"
    45 else
    46     echo "openpkg:man:ERROR: invalid number of arguments" 1>&2
    47     exit 1
    48 fi
    50 #   determine path to commands
    51 openpkg_tools="${OPENPKG_TOOLS}"
    52 openpkg_tools_cmdpath="${OPENPKG_TOOLS_CMDPATH}"
    53 if [ ".${openpkg_tools}" != . -a ".${openpkg_tools_cmdpath}" = . ]; then
    54     openpkg_tools_cmdpath="${openpkg_tools}/cmd:@"
    55 fi
    56 cmdpath="${prefix}/libexec/openpkg"
    57 if [ -d "${prefix}/libexec/openpkg-tools" ]; then
    58     cmdpath="${prefix}/libexec/openpkg-tools:${cmdpath}"
    59 fi
    60 if [ -d "${prefix}/libexec/openpkg-audit" ]; then
    61     cmdpath="${prefix}/libexec/openpkg-audit:${cmdpath}"
    62 fi
    63 if [ ".${openpkg_tools_cmdpath}" != . ]; then
    64     cmdpath=`echo "${openpkg_tools_cmdpath}" | sed -e "s;@;${cmdpath};"`
    65 fi
    66 openpkg_tools_cmdpath=`echo "${cmdpath}" | sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'`
    68 #   search for manual page in OpenPKG Tool Chain
    69 man_file=""
    70 man_type=""
    71 OIFS="$IFS"; IFS=":"
    72 for dir in ${openpkg_tools_cmdpath}; do
    73     IFS="$OIFS"
    74     for file in $dir/$man_page.${man_sect-"1"} $dir/$man_page.[1-9]; do
    75         if [ -f "$file" ]; then
    76             man_file="$file"
    77             man_type="roff"
    78             if [ ".$man_sect" = . ]; then
    79                 man_sect=`echo "$man_file" |\
    80                     sed -e 's;^;X;' -e 's;^X.*\.\([1-9]\)$;\1;' -e 's;^X.*;;'`
    81             fi
    82             break
    83         fi
    84     done
    85     if [ ".$man_type" = . ]; then
    86         for file in $dir/$man_page.pod $dir/$man_page.pl $dir/$man_page.sh; do
    87             if [ -f "$file" ]; then
    88                 if [ ".`grep '^=pod' $file`" != . ]; then
    89                     man_file="$file"
    90                     man_type="pod"
    91                     break
    92                 fi
    93             fi
    94         done
    95     fi
    96     if [ ".$man_type" != . ]; then
    97         break
    98     fi
    99 done
   100 IFS="$OIFS"
   101 if [ ".$man_type" != . ]; then
   102     #   determine POD to Roff converter
   103     pod2roff=""
   104     if [ ".$man_type" = .pod ]; then
   105         pod2roff=`$prefix/lib/openpkg/shtool path -p "$prefix/bin:$PATH" pod2man`
   106         if [ ".$pod2roff" = . ]; then
   107             echo "openpkg:man:ERROR: unable to find POD to Roff converter (pod2man)" 1>&2
   108             exit 1
   109         fi
   110         if [ ".$man_sect" = . ]; then
   111             man_sect=1
   112         fi
   113         pod2roff="$pod2roff --section=${man_sect}"
   114         pod2roff="$pod2roff --release=\"$man_page(${man_sect})\""
   115         pod2roff="$pod2roff --center=OpenPKG --date=OpenPKG"
   116         pod2roff="$pod2roff --quotes=none"
   117     fi
   119     #   determine Roff to ASCII converter
   120     roff2ascii=`$prefix/lib/openpkg/shtool path -p "$prefix/bin:$PATH" nroff groff`
   121     if [ ".$roff2ascii" = . ]; then
   122         echo "openpkg:man:ERROR: unable to find Roff to ASCII converter (nroff, groff)" 1>&2
   123         exit 1
   124     fi
   125     roff2ascii="$roff2ascii -man"
   126     case "$roff2ascii" in
   127         */groff ) roff2ascii="$roff2ascii -Tascii" ;;
   128     esac
   130     #   determine pager
   131     pager="$PAGER"
   132     if [ ".$pager" = . ]; then
   133         pager=`$prefix/lib/openpkg/shtool path -p "$prefix/bin:$PATH" less more cat`
   134     fi
   135     if [ ".$pager" = . ]; then
   136         echo "openpkg:man:ERROR: unable to find text viewer ($PAGER, less, more, cat)" 1>&2
   137         exit 1
   138     fi
   140     #   render the manual page to the TTY
   141     if [ ".$man_type" = .roff ]; then
   142         eval "$roff2ascii $man_file | $pager"
   143     elif [ ".$man_type" = .pod ]; then
   144         eval "$pod2roff $man_file | $roff2ascii | $pager"
   145     fi
   146     exit 0
   147 fi
   149 #   fallback to the man(1) command
   150 MANPATH="$prefix/man:$prefix/local/man:${MANPATH-/usr/man}:/usr/man:/usr/share/man"
   151 export MANPATH
   152 eval "exec man $man_sect $man_page"

mercurial