michael@13: #!@l_prefix@/lib/openpkg/bash michael@13: ## michael@13: ## man -- OpenPKG Tool Chain "man" command michael@428: ## Copyright (c) 2000-2012 OpenPKG GmbH michael@13: ## michael@428: ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208. michael@428: ## All rights reserved. Licenses which grant limited permission to use, michael@428: ## copy, modify and distribute this software are available from the michael@428: ## OpenPKG GmbH. michael@13: ## michael@428: ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED michael@13: ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF michael@13: ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. michael@13: ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR michael@13: ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@13: ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@13: ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF michael@13: ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND michael@13: ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, michael@13: ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT michael@13: ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@13: ## SUCH DAMAGE. michael@13: ## michael@13: michael@13: # configuration michael@13: prefix="@l_prefix@" michael@13: michael@13: # minimum command line parsing michael@13: opt_h=no michael@13: while [ 1 ]; do michael@13: case "$1" in michael@13: -h | --help ) opt_h=yes; shift ;; michael@13: * ) break ;; michael@13: esac michael@13: done michael@13: if [ ".$opt_h" = .yes ]; then michael@13: echo "openpkg:man:USAGE: openpkg man [--help] [
] " michael@13: exit 0 michael@13: fi michael@13: if [ $# -eq 1 ]; then michael@13: man_page="$1" michael@13: elif [ $# -eq 2 ]; then michael@13: man_sect="$1" michael@13: man_page="$2" michael@13: else michael@13: echo "openpkg:man:ERROR: invalid number of arguments" 1>&2 michael@13: exit 1 michael@13: fi michael@13: michael@13: # determine path to commands michael@13: openpkg_tools="${OPENPKG_TOOLS}" michael@13: openpkg_tools_cmdpath="${OPENPKG_TOOLS_CMDPATH}" michael@13: if [ ".${openpkg_tools}" != . -a ".${openpkg_tools_cmdpath}" = . ]; then michael@13: openpkg_tools_cmdpath="${openpkg_tools}/cmd:@" michael@13: fi michael@13: cmdpath="${prefix}/libexec/openpkg" michael@13: if [ -d "${prefix}/libexec/openpkg-tools" ]; then michael@13: cmdpath="${prefix}/libexec/openpkg-tools:${cmdpath}" michael@13: fi michael@13: if [ -d "${prefix}/libexec/openpkg-audit" ]; then michael@13: cmdpath="${prefix}/libexec/openpkg-audit:${cmdpath}" michael@13: fi michael@13: if [ ".${openpkg_tools_cmdpath}" != . ]; then michael@13: cmdpath=`echo "${openpkg_tools_cmdpath}" | sed -e "s;@;${cmdpath};"` michael@13: fi michael@13: openpkg_tools_cmdpath=`echo "${cmdpath}" | sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'` michael@13: michael@13: # search for manual page in OpenPKG Tool Chain michael@13: man_file="" michael@13: man_type="" michael@13: OIFS="$IFS"; IFS=":" michael@13: for dir in ${openpkg_tools_cmdpath}; do michael@13: IFS="$OIFS" michael@13: for file in $dir/$man_page.${man_sect-"1"} $dir/$man_page.[1-9]; do michael@13: if [ -f "$file" ]; then michael@13: man_file="$file" michael@13: man_type="roff" michael@13: if [ ".$man_sect" = . ]; then michael@13: man_sect=`echo "$man_file" |\ michael@13: sed -e 's;^;X;' -e 's;^X.*\.\([1-9]\)$;\1;' -e 's;^X.*;;'` michael@13: fi michael@13: break michael@13: fi michael@13: done michael@13: if [ ".$man_type" = . ]; then michael@13: for file in $dir/$man_page.pod $dir/$man_page.pl $dir/$man_page.sh; do michael@13: if [ -f "$file" ]; then michael@13: if [ ".`grep '^=pod' $file`" != . ]; then michael@13: man_file="$file" michael@13: man_type="pod" michael@13: break michael@13: fi michael@13: fi michael@13: done michael@13: fi michael@13: if [ ".$man_type" != . ]; then michael@13: break michael@13: fi michael@13: done michael@13: IFS="$OIFS" michael@13: if [ ".$man_type" != . ]; then michael@13: # determine POD to Roff converter michael@13: pod2roff="" michael@13: if [ ".$man_type" = .pod ]; then michael@13: pod2roff=`$prefix/lib/openpkg/shtool path -p "$prefix/bin:$PATH" pod2man` michael@13: if [ ".$pod2roff" = . ]; then michael@13: echo "openpkg:man:ERROR: unable to find POD to Roff converter (pod2man)" 1>&2 michael@13: exit 1 michael@13: fi michael@13: if [ ".$man_sect" = . ]; then michael@13: man_sect=1 michael@13: fi michael@13: pod2roff="$pod2roff --section=${man_sect}" michael@13: pod2roff="$pod2roff --release=\"$man_page(${man_sect})\"" michael@13: pod2roff="$pod2roff --center=OpenPKG --date=OpenPKG" michael@13: pod2roff="$pod2roff --quotes=none" michael@13: fi michael@13: michael@13: # determine Roff to ASCII converter michael@13: roff2ascii=`$prefix/lib/openpkg/shtool path -p "$prefix/bin:$PATH" nroff groff` michael@13: if [ ".$roff2ascii" = . ]; then michael@13: echo "openpkg:man:ERROR: unable to find Roff to ASCII converter (nroff, groff)" 1>&2 michael@13: exit 1 michael@13: fi michael@13: roff2ascii="$roff2ascii -man" michael@13: case "$roff2ascii" in michael@13: */groff ) roff2ascii="$roff2ascii -Tascii" ;; michael@13: esac michael@13: michael@13: # determine pager michael@13: pager="$PAGER" michael@13: if [ ".$pager" = . ]; then michael@13: pager=`$prefix/lib/openpkg/shtool path -p "$prefix/bin:$PATH" less more cat` michael@13: fi michael@13: if [ ".$pager" = . ]; then michael@13: echo "openpkg:man:ERROR: unable to find text viewer ($PAGER, less, more, cat)" 1>&2 michael@13: exit 1 michael@13: fi michael@13: michael@13: # render the manual page to the TTY michael@13: if [ ".$man_type" = .roff ]; then michael@13: eval "$roff2ascii $man_file | $pager" michael@13: elif [ ".$man_type" = .pod ]; then michael@13: eval "$pod2roff $man_file | $roff2ascii | $pager" michael@13: fi michael@13: exit 0 michael@13: fi michael@13: michael@13: # fallback to the man(1) command michael@13: MANPATH="$prefix/man:$prefix/local/man:${MANPATH-/usr/man}:/usr/man:/usr/share/man" michael@13: export MANPATH michael@13: eval "exec man $man_sect $man_page" michael@13: