xref: /titanic_52/usr/src/cmd/ast/libshell/common/scripts/shman.sh (revision 906afcb89d0412cc073b95c2d701a804a8cdb62c)
1*906afcb8SAndy Fiddaman#!/usr/bin/ksh93
2*906afcb8SAndy Fiddaman
3*906afcb8SAndy Fiddaman#
4*906afcb8SAndy Fiddaman# CDDL HEADER START
5*906afcb8SAndy Fiddaman#
6*906afcb8SAndy Fiddaman# The contents of this file are subject to the terms of the
7*906afcb8SAndy Fiddaman# Common Development and Distribution License (the "License").
8*906afcb8SAndy Fiddaman# You may not use this file except in compliance with the License.
9*906afcb8SAndy Fiddaman#
10*906afcb8SAndy Fiddaman# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*906afcb8SAndy Fiddaman# or http://www.opensolaris.org/os/licensing.
12*906afcb8SAndy Fiddaman# See the License for the specific language governing permissions
13*906afcb8SAndy Fiddaman# and limitations under the License.
14*906afcb8SAndy Fiddaman#
15*906afcb8SAndy Fiddaman# When distributing Covered Code, include this CDDL HEADER in each
16*906afcb8SAndy Fiddaman# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*906afcb8SAndy Fiddaman# If applicable, add the following below this CDDL HEADER, with the
18*906afcb8SAndy Fiddaman# fields enclosed by brackets "[]" replaced with your own identifying
19*906afcb8SAndy Fiddaman# information: Portions Copyright [yyyy] [name of copyright owner]
20*906afcb8SAndy Fiddaman#
21*906afcb8SAndy Fiddaman# CDDL HEADER END
22*906afcb8SAndy Fiddaman#
23*906afcb8SAndy Fiddaman
24*906afcb8SAndy Fiddaman#
25*906afcb8SAndy Fiddaman# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
26*906afcb8SAndy Fiddaman#
27*906afcb8SAndy Fiddaman
28*906afcb8SAndy Fiddaman# Solaris needs /usr/xpg6/bin:/usr/xpg4/bin because the tools in /usr/bin are not POSIX-conformant
29*906afcb8SAndy Fiddamanexport PATH=/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin
30*906afcb8SAndy Fiddaman
31*906afcb8SAndy Fiddaman# Make sure all math stuff runs in the "C" locale to avoid problems
32*906afcb8SAndy Fiddaman# with alternative # radix point representations (e.g. ',' instead of
33*906afcb8SAndy Fiddaman# '.' in de_DE.*-locales). This needs to be set _before_ any
34*906afcb8SAndy Fiddaman# floating-point constants are defined in this script).
35*906afcb8SAndy Fiddamanif [[ "${LC_ALL}" != "" ]] ; then
36*906afcb8SAndy Fiddaman    export \
37*906afcb8SAndy Fiddaman        LC_MONETARY="${LC_ALL}" \
38*906afcb8SAndy Fiddaman        LC_MESSAGES="${LC_ALL}" \
39*906afcb8SAndy Fiddaman        LC_COLLATE="${LC_ALL}" \
40*906afcb8SAndy Fiddaman        LC_CTYPE="${LC_ALL}"
41*906afcb8SAndy Fiddaman        unset LC_ALL
42*906afcb8SAndy Fiddamanfi
43*906afcb8SAndy Fiddamanexport LC_NUMERIC=C
44*906afcb8SAndy Fiddaman
45*906afcb8SAndy Fiddamanfunction fatal_error
46*906afcb8SAndy Fiddaman{
47*906afcb8SAndy Fiddaman	print -u2 "${progname}: $*"
48*906afcb8SAndy Fiddaman	exit 1
49*906afcb8SAndy Fiddaman}
50*906afcb8SAndy Fiddaman
51*906afcb8SAndy Fiddamanfunction debug_print
52*906afcb8SAndy Fiddaman{
53*906afcb8SAndy Fiddaman	# don't use "--" here to allow "-f" for formatting
54*906afcb8SAndy Fiddaman#	print -u2 "$@"
55*906afcb8SAndy Fiddaman	return 0
56*906afcb8SAndy Fiddaman}
57*906afcb8SAndy Fiddaman
58*906afcb8SAndy Fiddaman# Build a list of compound variables calculated from MANPATH and
59*906afcb8SAndy Fiddaman# locale which contain...
60*906afcb8SAndy Fiddaman# "manpath_element" - the MANPATH element this entry belongs to
61*906afcb8SAndy Fiddaman# "dir"             - physical directory of "manpath_element"
62*906afcb8SAndy Fiddaman# "sect"            - section (if "manpath_element" is something like /usr/share/man,1b)
63*906afcb8SAndy Fiddaman# ... and put the result in the array named by argv[1]
64*906afcb8SAndy Fiddamanfunction enumerate_mandirs
65*906afcb8SAndy Fiddaman{
66*906afcb8SAndy Fiddaman	nameref md=$1
67*906afcb8SAndy Fiddaman	typeset manpath_element dir sect manlang
68*906afcb8SAndy Fiddaman	integer i=0
69*906afcb8SAndy Fiddaman
70*906afcb8SAndy Fiddaman	if [[ "${LC_MESSAGES}" != "" ]] ; then
71*906afcb8SAndy Fiddaman		manlang="${LC_MESSAGES}"
72*906afcb8SAndy Fiddaman	else
73*906afcb8SAndy Fiddaman		manlang="${LANG}"
74*906afcb8SAndy Fiddaman	fi
75*906afcb8SAndy Fiddaman
76*906afcb8SAndy Fiddaman	print -r -- "${MANPATH//:/$'\n'}" | while read manpath_element ; do
77*906afcb8SAndy Fiddaman		# strip section from manpath elements like "/usr/share/man,1b"
78*906afcb8SAndy Fiddaman		dir="${manpath_element/~(E)(.*),(.*)/\1}"
79*906afcb8SAndy Fiddaman		sect="${manpath_element/~(E)(.*),(.*)/\2}"
80*906afcb8SAndy Fiddaman		[[ "${sect}" == "${dir}" ]] && sect=""
81*906afcb8SAndy Fiddaman
82*906afcb8SAndy Fiddaman		if [[ "${manlang}" != "" && -d "${dir}/${manlang}" ]] ; then
83*906afcb8SAndy Fiddaman			md+=(
84*906afcb8SAndy Fiddaman				manpath_element="${manpath_element}"
85*906afcb8SAndy Fiddaman				dir="${dir}/${manlang}"
86*906afcb8SAndy Fiddaman				sect="${sect}"
87*906afcb8SAndy Fiddaman			)
88*906afcb8SAndy Fiddaman		fi
89*906afcb8SAndy Fiddaman		if [[ -d "${dir}" ]] ; then
90*906afcb8SAndy Fiddaman			md+=(
91*906afcb8SAndy Fiddaman				manpath_element="${manpath_element}"
92*906afcb8SAndy Fiddaman				dir="${dir}"
93*906afcb8SAndy Fiddaman				sect="${sect}"
94*906afcb8SAndy Fiddaman			)
95*906afcb8SAndy Fiddaman		fi
96*906afcb8SAndy Fiddaman	done
97*906afcb8SAndy Fiddaman
98*906afcb8SAndy Fiddaman	return 0
99*906afcb8SAndy Fiddaman}
100*906afcb8SAndy Fiddaman
101*906afcb8SAndy Fiddamanfunction enumerate_mansects
102*906afcb8SAndy Fiddaman{
103*906afcb8SAndy Fiddaman	nameref ms=$1
104*906afcb8SAndy Fiddaman	nameref mandir_node=$2
105*906afcb8SAndy Fiddaman	typeset mancf="${mandir_node.dir}/man.cf"
106*906afcb8SAndy Fiddaman	typeset x s l
107*906afcb8SAndy Fiddaman
108*906afcb8SAndy Fiddaman	if [[ "${mandir_node.sect}" != "" ]] ; then
109*906afcb8SAndy Fiddaman		x="${mandir_node.sect}"
110*906afcb8SAndy Fiddaman	elif [[ "${MANSECTS}" != "" ]] ; then
111*906afcb8SAndy Fiddaman		x="${MANSECTS//,/$'\n'}"
112*906afcb8SAndy Fiddaman	elif [[ -f "${mancf}" && -r "${mancf}" ]] ; then
113*906afcb8SAndy Fiddaman		x="$(egrep -v '^#|^[[:space:]]*$' <"${mancf}" | egrep '^MANSECTS=')"
114*906afcb8SAndy Fiddaman		x="${x/MANSECTS=}/"
115*906afcb8SAndy Fiddaman		x="${x//,/$'\n'}"
116*906afcb8SAndy Fiddaman	else
117*906afcb8SAndy Fiddaman		x="$(cd "${mandir_node.dir}" ; \
118*906afcb8SAndy Fiddaman			ls -1d ~(El)(sman|man).*/ | \
119*906afcb8SAndy Fiddaman			while read s ; do \
120*906afcb8SAndy Fiddaman				s="${s/~(El)(sman|man)/}" ; \
121*906afcb8SAndy Fiddaman				s="${s/~(Er)\//}" ; \
122*906afcb8SAndy Fiddaman				print -r -- "$s" ; \
123*906afcb8SAndy Fiddaman			done)"
124*906afcb8SAndy Fiddaman	fi
125*906afcb8SAndy Fiddaman
126*906afcb8SAndy Fiddaman	while read l ; do
127*906afcb8SAndy Fiddaman		[[ "${l}" != ~(Elr)[[:blank:]]* ]] && ms+=( "${l}" )
128*906afcb8SAndy Fiddaman#		print -- "sect=$l"
129*906afcb8SAndy Fiddaman	done <<<"${x}"
130*906afcb8SAndy Fiddaman
131*906afcb8SAndy Fiddaman#	printf "enumerate_mansects: found %d entries.\n" ${#ms[@]}
132*906afcb8SAndy Fiddaman
133*906afcb8SAndy Fiddaman	return 0
134*906afcb8SAndy Fiddaman}
135*906afcb8SAndy Fiddaman
136*906afcb8SAndy Fiddaman# wrapper around more/less
137*906afcb8SAndy Fiddamanfunction browse_manpage
138*906afcb8SAndy Fiddaman{
139*906afcb8SAndy Fiddaman	typeset tmpdirname
140*906afcb8SAndy Fiddaman	typeset doc_filename="$1"
141*906afcb8SAndy Fiddaman	typeset doc_title="$2"
142*906afcb8SAndy Fiddaman
143*906afcb8SAndy Fiddaman	# squish characters in filename which are not allowed in a filesystem
144*906afcb8SAndy Fiddaman	# (currently '/')
145*906afcb8SAndy Fiddaman	doc_title="${doc_title//\//}"
146*906afcb8SAndy Fiddaman
147*906afcb8SAndy Fiddaman	# check if we have "less" installed, if not fall back to /usr/xpg4/bin/more
148*906afcb8SAndy Fiddaman	if which less >/dev/null 2>&1 ; then
149*906afcb8SAndy Fiddaman		# use "cat" here to avoid that "less" may try funny things
150*906afcb8SAndy Fiddaman		cat <"${doc_filename}" | less -I -M $"--prompt=MManual\ page\ ${doc_title}\ ?ltline\ %lt?L/%L.:"
151*906afcb8SAndy Fiddaman	else
152*906afcb8SAndy Fiddaman		tmpdirname="$(mktemp -t -d "shman_${PPID}_$$_XXXXXX")"
153*906afcb8SAndy Fiddaman
154*906afcb8SAndy Fiddaman		mkdir -p "${tmpdirname}" || { print -u2 -f $"Couldn't create tmp. dir %s\n" "${tmpdirname}" ; return 1 ; }
155*906afcb8SAndy Fiddaman
156*906afcb8SAndy Fiddaman		(
157*906afcb8SAndy Fiddaman			cd "${tmpdirname}"
158*906afcb8SAndy Fiddaman
159*906afcb8SAndy Fiddaman			# note: we need to support /dev/stdin
160*906afcb8SAndy Fiddaman			cat <"${doc_filename}" >"./${doc_title}"
161*906afcb8SAndy Fiddaman
162*906afcb8SAndy Fiddaman			/usr/xpg4/bin/more "${doc_title}"
163*906afcb8SAndy Fiddaman
164*906afcb8SAndy Fiddaman			rm -f "${doc_title}"
165*906afcb8SAndy Fiddaman		)
166*906afcb8SAndy Fiddaman
167*906afcb8SAndy Fiddaman		rmdir "${tmpdirname}"
168*906afcb8SAndy Fiddaman	fi
169*906afcb8SAndy Fiddaman
170*906afcb8SAndy Fiddaman	return 0
171*906afcb8SAndy Fiddaman}
172*906afcb8SAndy Fiddaman
173*906afcb8SAndy Fiddaman# /usr/bin/man <keyword>
174*906afcb8SAndy Fiddamanfunction show_manpage
175*906afcb8SAndy Fiddaman{
176*906afcb8SAndy Fiddaman	compound -a mandirs
177*906afcb8SAndy Fiddaman	integer i
178*906afcb8SAndy Fiddaman	integer j
179*906afcb8SAndy Fiddaman
180*906afcb8SAndy Fiddaman	enumerate_mandirs mandirs
181*906afcb8SAndy Fiddaman#	debug_print -- "${mandirs[@]}"
182*906afcb8SAndy Fiddaman
183*906afcb8SAndy Fiddaman	integer num_mandirs=${#mandirs[@]}
184*906afcb8SAndy Fiddaman
185*906afcb8SAndy Fiddaman	for ((i=0 ; i < num_mandirs ; i++ )) ; do
186*906afcb8SAndy Fiddaman		typeset mandir="${mandirs[i].dir}"
187*906afcb8SAndy Fiddaman
188*906afcb8SAndy Fiddaman		typeset -a mansects
189*906afcb8SAndy Fiddaman		enumerate_mansects mansects "mandirs[$i]"
190*906afcb8SAndy Fiddaman
191*906afcb8SAndy Fiddaman		integer num_mansects="${#mansects[@]}"
192*906afcb8SAndy Fiddaman#		debug_print -- "mansects=${mansects[@]}"
193*906afcb8SAndy Fiddaman
194*906afcb8SAndy Fiddaman		for ((j=0 ; j < num_mansects ; j++ )) ; do
195*906afcb8SAndy Fiddaman			typeset mansect="${mansects[j]}"
196*906afcb8SAndy Fiddaman
197*906afcb8SAndy Fiddaman			# try 1: SGML manpage
198*906afcb8SAndy Fiddaman			typeset match="${mandir}/sman${mansect}/${manname}.${mansect}"
199*906afcb8SAndy Fiddaman			if [[ -r "${match}" ]] ; then
200*906afcb8SAndy Fiddaman				typeset note nlink
201*906afcb8SAndy Fiddaman
202*906afcb8SAndy Fiddaman				# follow SGML links if needed (needs rework, including protection against link loops)
203*906afcb8SAndy Fiddaman				while true ; do
204*906afcb8SAndy Fiddaman					debug_print -f "match: %s\n" "${match}"
205*906afcb8SAndy Fiddaman
206*906afcb8SAndy Fiddaman					tmp="$(cd "${mandir}" ; LC_MESSAGES=C /usr/lib/sgml/sgml2roff "${match}")"
207*906afcb8SAndy Fiddaman					read note nlink <<<"${tmp}"
208*906afcb8SAndy Fiddaman
209*906afcb8SAndy Fiddaman					if [[ "${note}" == ".so" ]] ; then
210*906afcb8SAndy Fiddaman						match="${nlink}"
211*906afcb8SAndy Fiddaman					else
212*906afcb8SAndy Fiddaman						break
213*906afcb8SAndy Fiddaman					fi
214*906afcb8SAndy Fiddaman				done
215*906afcb8SAndy Fiddaman
216*906afcb8SAndy Fiddaman				tbl <<<"${tmp}" | eqn | nroff -u0 -Tlp -man - | col -x | browse_manpage /dev/stdin "${manname}(${mansect})"
217*906afcb8SAndy Fiddaman				return 0
218*906afcb8SAndy Fiddaman			fi
219*906afcb8SAndy Fiddaman
220*906afcb8SAndy Fiddaman			# try 2: troff manpage
221*906afcb8SAndy Fiddaman			match="${mandir}/man${mansect}/${manname}.${mansect}"
222*906afcb8SAndy Fiddaman			if [[ -r "${match}" ]] ; then
223*906afcb8SAndy Fiddaman				debug_print -f "match: %s\n" "${match}"
224*906afcb8SAndy Fiddaman				tbl <"${match}" | eqn | nroff -u0 -Tlp -man - | col -x | browse_manpage /dev/stdin "${manname}(${mansect})"
225*906afcb8SAndy Fiddaman				return 0
226*906afcb8SAndy Fiddaman			fi
227*906afcb8SAndy Fiddaman		done
228*906afcb8SAndy Fiddaman		unset mansects num_mansects
229*906afcb8SAndy Fiddaman	done
230*906afcb8SAndy Fiddaman
231*906afcb8SAndy Fiddaman	printf $"No manual entry for %s.\n" "${manname}"
232*906afcb8SAndy Fiddaman	return 0
233*906afcb8SAndy Fiddaman}
234*906afcb8SAndy Fiddaman
235*906afcb8SAndy Fiddaman# /usr/bin/man -l <keyword>
236*906afcb8SAndy Fiddamanfunction list_manpages
237*906afcb8SAndy Fiddaman{
238*906afcb8SAndy Fiddaman	compound -a mandirs
239*906afcb8SAndy Fiddaman
240*906afcb8SAndy Fiddaman	enumerate_mandirs mandirs
241*906afcb8SAndy Fiddaman	#debug_print -- "${mandirs[@]}"
242*906afcb8SAndy Fiddaman
243*906afcb8SAndy Fiddaman	integer num_mandirs=${#mandirs[@]}
244*906afcb8SAndy Fiddaman
245*906afcb8SAndy Fiddaman	for ((i=0 ; i < num_mandirs ; i++ )) ; do
246*906afcb8SAndy Fiddaman		typeset mandir="${mandirs[i].dir}"
247*906afcb8SAndy Fiddaman
248*906afcb8SAndy Fiddaman		typeset -a mansects
249*906afcb8SAndy Fiddaman		enumerate_mansects mansects "mandirs[$i]"
250*906afcb8SAndy Fiddaman
251*906afcb8SAndy Fiddaman		integer num_mansects="${#mansects[@]}"
252*906afcb8SAndy Fiddaman#		debug_print -- "mansects=${mansects[@]}"
253*906afcb8SAndy Fiddaman
254*906afcb8SAndy Fiddaman		for ((j=0 ; j < num_mansects ; j++ )) ; do
255*906afcb8SAndy Fiddaman			mansect="${mansects[j]}"
256*906afcb8SAndy Fiddaman
257*906afcb8SAndy Fiddaman			# try 1: SGML manpage
258*906afcb8SAndy Fiddaman			match="${mandir}/sman${mansect}/${manname}.${mansect}"
259*906afcb8SAndy Fiddaman			if [[ -r "${match}" ]] ; then
260*906afcb8SAndy Fiddaman				printf "%s (%s)\t-M %s\n" "${manname}" "${mansect}" "${mandir}"
261*906afcb8SAndy Fiddaman				continue
262*906afcb8SAndy Fiddaman			fi
263*906afcb8SAndy Fiddaman
264*906afcb8SAndy Fiddaman			# try 2: troff manpage
265*906afcb8SAndy Fiddaman			match="${mandir}/man${mansect}/${manname}.${mansect}"
266*906afcb8SAndy Fiddaman			if [[ -r "${match}" ]] ; then
267*906afcb8SAndy Fiddaman				printf "%s (%s)\t-M %s\n" "${manname}" "${mansect}" "${mandir}"
268*906afcb8SAndy Fiddaman				continue
269*906afcb8SAndy Fiddaman			fi
270*906afcb8SAndy Fiddaman		done
271*906afcb8SAndy Fiddaman		unset mansects num_mansects
272*906afcb8SAndy Fiddaman	done
273*906afcb8SAndy Fiddaman
274*906afcb8SAndy Fiddaman	return 0
275*906afcb8SAndy Fiddaman}
276*906afcb8SAndy Fiddaman
277*906afcb8SAndy Fiddaman# /usr/bin/appropos
278*906afcb8SAndy Fiddamanfunction list_keywords
279*906afcb8SAndy Fiddaman{
280*906afcb8SAndy Fiddaman	typeset -a mandirs
281*906afcb8SAndy Fiddaman	typeset name namesec title
282*906afcb8SAndy Fiddaman
283*906afcb8SAndy Fiddaman	enumerate_mandirs mandirs
284*906afcb8SAndy Fiddaman	#debug_print -- "${mandirs[@]}"
285*906afcb8SAndy Fiddaman
286*906afcb8SAndy Fiddaman	integer num_mandirs=${#mandirs[@]}
287*906afcb8SAndy Fiddaman
288*906afcb8SAndy Fiddaman	for ((i=0 ; i < num_mandirs ; i++ )) ; do
289*906afcb8SAndy Fiddaman		typeset mandir="${mandirs[i].dir}"
290*906afcb8SAndy Fiddaman		typeset windexfile="${mandir}/windex"
291*906afcb8SAndy Fiddaman
292*906afcb8SAndy Fiddaman		if [[ ! -r "${windexfile}" ]] ; then
293*906afcb8SAndy Fiddaman			print -u2 -f $"%s: Can't open %s.\n" "${progname}" "${windexfile}"
294*906afcb8SAndy Fiddaman			continue
295*906afcb8SAndy Fiddaman		fi
296*906afcb8SAndy Fiddaman
297*906afcb8SAndy Fiddaman		while IFS=$'\t' read name namesec title ; do
298*906afcb8SAndy Fiddaman			if [[ "${name}${namesec}${title}" == ~(Fi)${manname} ]] ; then
299*906afcb8SAndy Fiddaman				printf "%s\t%s\t%s\n" "${name}" "${namesec}" "${title}"
300*906afcb8SAndy Fiddaman			fi
301*906afcb8SAndy Fiddaman		done <"${windexfile}"
302*906afcb8SAndy Fiddaman	done
303*906afcb8SAndy Fiddaman
304*906afcb8SAndy Fiddaman	return 0
305*906afcb8SAndy Fiddaman}
306*906afcb8SAndy Fiddaman
307*906afcb8SAndy Fiddamanfunction usage
308*906afcb8SAndy Fiddaman{
309*906afcb8SAndy Fiddaman	OPTIND=0
310*906afcb8SAndy Fiddaman	getopts -a "${progname}" "${man_usage}" OPT '-?'
311*906afcb8SAndy Fiddaman	exit 2
312*906afcb8SAndy Fiddaman}
313*906afcb8SAndy Fiddaman
314*906afcb8SAndy Fiddaman# program start
315*906afcb8SAndy Fiddamanbuiltin basename
316*906afcb8SAndy Fiddamanbuiltin cat
317*906afcb8SAndy Fiddamanbuiltin date
318*906afcb8SAndy Fiddaman
319*906afcb8SAndy Fiddamantypeset progname="$(basename "${0}")"
320*906afcb8SAndy Fiddaman
321*906afcb8SAndy Fiddamantypeset -r man_usage=$'+
322*906afcb8SAndy Fiddaman[-?\n@(#)\$Id: shman (Roland Mainz) 2009-12-02 \$\n]
323*906afcb8SAndy Fiddaman[-author?Roland Mainz <roland.mainz@nrubsig.org>]
324*906afcb8SAndy Fiddaman[-author?Roland Mainz <roland.mainz@sun.com>]
325*906afcb8SAndy Fiddaman[+NAME?man - find and display reference manual pages]
326*906afcb8SAndy Fiddaman[+DESCRIPTION?The man command displays information from the reference
327*906afcb8SAndy Fiddaman	manuals. It displays complete manual pages that you select
328*906afcb8SAndy Fiddaman	by name, or one-line summaries selected  either  by  keyword
329*906afcb8SAndy Fiddaman	(-k), or by the name of an associated file (-f). If no
330*906afcb8SAndy Fiddaman	manual page is located, man prints an error message.]
331*906afcb8SAndy Fiddaman[+?write me.]
332*906afcb8SAndy Fiddaman[k:keyword?Prints out one-line summaries from the windex database (table of contents) that
333*906afcb8SAndy Fiddaman	contain any of the given  keywords. The windex database is created using
334*906afcb8SAndy Fiddaman	catman(1M).]
335*906afcb8SAndy Fiddaman[l:list?Lists all manual  pages  found  matching name within the search path.]
336*906afcb8SAndy Fiddaman[M:mpath?Specifies an alternate search  path  for manual  pages. path is a colon-separated
337*906afcb8SAndy Fiddaman	list of directories that contain  manual page directory subtrees. For example, if
338*906afcb8SAndy Fiddaman	path  is  /usr/share/man:/usr/local/man, man  searches  for  name in the standard
339*906afcb8SAndy Fiddaman	location, and then /usr/local/man.  When used  with  the -k or -f options, the -M
340*906afcb8SAndy Fiddaman	option must appear first. Each directory in  the  path is assumed to contain subdirectories of the form man* or sman*  ,
341*906afcb8SAndy Fiddaman	one  for each section. This option overrides the MANPATH environment variable.]:[path]
342*906afcb8SAndy Fiddaman[s:section?Specifies sections of the manual for man to search. The directories searched for
343*906afcb8SAndy Fiddaman	name are limited to those specified by section. section can be a numerical
344*906afcb8SAndy Fiddaman	digit, perhaps followed by one or more letters to match the desired section of
345*906afcb8SAndy Fiddaman	the manual, for example,  "3libucb". Also, section can be a word, for example,
346*906afcb8SAndy Fiddaman	local, new, old, public. section can also be a letter.
347*906afcb8SAndy Fiddaman	To specify multiple sections, separate each section with
348*906afcb8SAndy Fiddaman	a comma. This option overrides the MANPATH environment variable and the man.cf
349*906afcb8SAndy Fiddaman	file.
350*906afcb8SAndy Fiddaman	See Search Path below for an explanation of how man conducts its search.]:[section]
351*906afcb8SAndy Fiddaman
352*906afcb8SAndy Fiddamanname
353*906afcb8SAndy Fiddaman
354*906afcb8SAndy Fiddaman[+SEE ALSO?\bksh93\b(1), \bman\b(1)]
355*906afcb8SAndy Fiddaman'
356*906afcb8SAndy Fiddaman
357*906afcb8SAndy Fiddamantypeset do_list=false
358*906afcb8SAndy Fiddamantypeset do_keyword=false
359*906afcb8SAndy Fiddaman
360*906afcb8SAndy Fiddamanwhile getopts -a "${progname}" "${man_usage}" OPT ; do
361*906afcb8SAndy Fiddaman#    printmsg "## OPT=|${OPT}|, OPTARG=|${OPTARG}|"
362*906afcb8SAndy Fiddaman	case ${OPT} in
363*906afcb8SAndy Fiddaman		M)	MANPATH="${OPTARG}"	;;
364*906afcb8SAndy Fiddaman		l)	do_list=true		;;
365*906afcb8SAndy Fiddaman		k)	do_keyword=true		;;
366*906afcb8SAndy Fiddaman		s)	MANSECTS="${OPTARG}"	;;
367*906afcb8SAndy Fiddaman		*)	usage			;;
368*906afcb8SAndy Fiddaman	esac
369*906afcb8SAndy Fiddamandone
370*906afcb8SAndy Fiddamanshift $((OPTIND-1))
371*906afcb8SAndy Fiddaman
372*906afcb8SAndy Fiddaman# cd /usr/man; LC_MESSAGES=C /usr/lib/sgml/sgml2roff /usr/man/sman1as/asadmin-list-timers.1as  | tbl | eqn | nroff -u0 -Tlp -man -  | col -x > /tmp/mpLQaqac
373*906afcb8SAndy Fiddaman
374*906afcb8SAndy Fiddaman# prechecks
375*906afcb8SAndy Fiddaman(( $# > 0 )) || usage
376*906afcb8SAndy Fiddaman
377*906afcb8SAndy Fiddaman# process arguments
378*906afcb8SAndy Fiddamanwhile (( $# > 0 )) ; do
379*906afcb8SAndy Fiddaman	typeset manname="$1"
380*906afcb8SAndy Fiddaman	shift
381*906afcb8SAndy Fiddaman
382*906afcb8SAndy Fiddaman	debug_print -f "# searching for %s ...\n" "${manname}"
383*906afcb8SAndy Fiddaman
384*906afcb8SAndy Fiddaman	if ${do_keyword} ; then
385*906afcb8SAndy Fiddaman		list_keywords
386*906afcb8SAndy Fiddaman	elif ${do_list} ; then
387*906afcb8SAndy Fiddaman		list_manpages
388*906afcb8SAndy Fiddaman	else
389*906afcb8SAndy Fiddaman		show_manpage
390*906afcb8SAndy Fiddaman	fi
391*906afcb8SAndy Fiddamandone
392*906afcb8SAndy Fiddaman
393*906afcb8SAndy Fiddaman# todo: better exit codes
394*906afcb8SAndy Fiddamanexit 0
395*906afcb8SAndy Fiddaman# EOF.
396