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