xref: /freebsd/usr.bin/man/man.sh (revision fb2971ccd2bab42f5406f919812ceb8e014773ea)
1#! /bin/sh
2#
3#  Copyright (c) 2010 Gordon Tetlow
4#  All rights reserved.
5#
6#  Redistribution and use in source and binary forms, with or without
7#  modification, are permitted provided that the following conditions
8#  are met:
9#  1. Redistributions of source code must retain the above copyright
10#     notice, this list of conditions and the following disclaimer.
11#  2. Redistributions in binary form must reproduce the above copyright
12#     notice, this list of conditions and the following disclaimer in the
13#     documentation and/or other materials provided with the distribution.
14#
15#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18#  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21#  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22#  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23#  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25#  SUCH DAMAGE.
26#
27# $FreeBSD$
28
29# Usage: add_to_manpath path
30# Adds a variable to manpath while ensuring we don't have duplicates.
31# Returns true if we were able to add something. False otherwise.
32add_to_manpath() {
33	case "$manpath" in
34	*:$1)	decho "  Skipping duplicate manpath entry $1" 2 ;;
35	$1:*)	decho "  Skipping duplicate manpath entry $1" 2 ;;
36	*:$1:*)	decho "  Skipping duplicate manpath entry $1" 2 ;;
37	*)	if [ -d "$1" ]; then
38			decho "  Adding $1 to manpath"
39			manpath="$manpath:$1"
40			return 0
41		fi
42		;;
43	esac
44
45	return 1
46}
47
48# Usage: build_manlocales
49# Builds a correct MANLOCALES variable.
50build_manlocales() {
51	# If the user has set manlocales, who are we to argue.
52	if [ -n "$MANLOCALES" ]; then
53		return
54	fi
55
56	parse_configs
57
58	# Trim leading colon
59	MANLOCALES=${manlocales#:}
60
61	decho "Available manual locales: $MANLOCALES"
62}
63
64# Usage: build_manpath
65# Builds a correct MANPATH variable.
66build_manpath() {
67	local IFS
68
69	# If the user has set a manpath, who are we to argue.
70	if [ -n "$MANPATH" ]; then
71		return
72	fi
73
74	search_path
75
76	decho "Adding default manpath entries"
77	IFS=:
78	for path in $man_default_path; do
79		add_to_manpath "$path"
80	done
81	unset IFS
82
83	parse_configs
84
85	# Trim leading colon
86	MANPATH=${manpath#:}
87
88	decho "Using manual path: $MANPATH"
89}
90
91# Usage: check_cat catglob
92# Checks to see if a cat glob is available.
93check_cat() {
94	if exists "$1"; then
95		use_cat=yes
96		catpage=$found
97		decho "    Found catpage $catpage"
98		return 0
99	else
100		return 1
101	fi
102}
103
104# Usage: check_man manglob catglob
105# Given 2 globs, figures out if the manglob is available, if so, check to
106# see if the catglob is also available and up to date.
107check_man() {
108	if exists "$1"; then
109		# We have a match, check for a cat page
110		manpage=$found
111		decho "    Found manpage $manpage"
112
113		if exists "$2" && is_newer $found $manpage; then
114			# cat page found and is newer, use that
115			use_cat=yes
116			catpage=$found
117			decho "    Using catpage $catpage"
118		else
119			# no cat page or is older
120			unset use_cat
121			decho "    Skipping catpage: not found or old"
122		fi
123		return 0
124	fi
125
126	return 1
127}
128
129# Usage: decho "string" [debuglevel]
130# Echoes to stderr string prefaced with -- if high enough debuglevel.
131decho() {
132	if [ $debug -ge ${2:-1} ]; then
133		echo "-- $1" >&2
134	fi
135}
136
137# Usage: exists glob
138# Returns true if glob resolves to a real file.
139exists() {
140	local IFS
141
142	# Don't accidentally inherit callers IFS (breaks perl manpages)
143	unset IFS
144
145	# Use some globbing tricks in the shell to determine if a file
146	# exists or not.
147	set +f
148	set -- "$1" $1
149	set -f
150
151	if [ "$1" != "$2" -a -r "$2" ]; then
152		found="$2"
153		return 0
154	fi
155
156	return 1
157}
158
159# Usage: find_file path section subdir pagename
160# Returns: true if something is matched and found.
161# Search the given path/section combo for a given page.
162find_file() {
163	local manroot catroot mann man0 catn cat0
164
165	manroot="$1/man$2"
166	catroot="$1/cat$2"
167	if [ -n "$3" ]; then
168		manroot="$manroot/$3"
169		catroot="$catroot/$3"
170	fi
171
172	if [ ! -d "$manroot" ]; then
173		return 1
174	fi
175	decho "  Searching directory $manroot" 2
176
177	mann="$manroot/$4.$2*"
178	man0="$manroot/$4.0*"
179	catn="$catroot/$4.$2*"
180	cat0="$catroot/$4.0*"
181
182	# This is the behavior as seen by the original man utility.
183	# Let's not change that which doesn't seem broken.
184	if check_man "$mann" "$catn"; then
185		return 0
186	elif check_man "$man0" "$cat0"; then
187		return 0
188	elif check_cat "$catn"; then
189		return 0
190	elif check_cat "$cat0"; then
191		return 0
192	fi
193
194	return 1
195}
196
197# Usage: is_newer file1 file2
198# Returns true if file1 is newer than file2 as calculated by mtime.
199is_newer() {
200	if [ $(stat -f %m $1) -gt $(stat -f %m $2) ]; then
201		decho "    mtime: $1 newer than $2" 3
202		return 0
203	else
204		decho "    mtime: $1 older than $2" 3
205		return 1
206	fi
207}
208
209# Usage: manpath_parse_args "$@"
210# Parses commandline options for manpath.
211manpath_parse_args() {
212	local cmd_arg
213
214	while getopts 'Ldq' cmd_arg; do
215		case "${cmd_arg}" in
216		L)	Lflag=Lflag ;;
217		d)	debug=$(( $debug + 1 )) ;;
218		q)	qflag=qflag ;;
219		*)	manpath_usage ;;
220		esac
221	done >&2
222}
223
224# Usage: manpath_usage
225# Display usage for the manpath(1) utility.
226manpath_usage() {
227	echo 'usage: manpath [-Ldq]' >&2
228	exit 1
229}
230
231# Usage: manpath_warnings
232# Display some warnings to stderr.
233manpath_warnings() {
234	if [ -z "$Lflag" -a -n "$MANPATH" ]; then
235		echo "(Warning: MANPATH environment variable set)" >&2
236	fi
237
238	if [ -n "$Lflag" -a -n "$MANLOCALES" ]; then
239		echo "(Warning: MANLOCALES environment variable set)" >&2
240	fi
241}
242
243# Usage: man_display_page
244# Display either the manpage or catpage depending on the use_cat variable
245man_display_page() {
246	local EQN COL NROFF PIC TBL TROFF REFER VGRIND
247	local IFS l nroff_dev pipeline preproc_arg tool
248
249	# We are called with IFS set to colon. This causes really weird
250	# things to happen for the variables that have spaces in them.
251	unset IFS
252
253	# If we are supposed to use a catpage and we aren't using troff(1)
254	# just zcat the catpage and we are done.
255	if [ -z "$tflag" -a -n "$use_cat" ]; then
256		if [ -n "$wflag" ]; then
257			echo "$catpage (source: $manpage)"
258			ret=0
259		else
260			if [ $debug -gt 0 ]; then
261				decho "Command: $ZCAT $catpage | $PAGER"
262				ret=0
263			else
264				eval "$ZCAT $catpage | $PAGER"
265				ret=$?
266			fi
267		fi
268		return
269	fi
270
271	# Okay, we are using the manpage, do we just need to output the
272	# name of the manpage?
273	if [ -n "$wflag" ]; then
274		echo "$manpage"
275		ret=0
276		return
277	fi
278
279	# So, we really do need to parse the manpage. First, figure out the
280	# device flag (-T) we have to pass to eqn(1) and groff(1). Then,
281	# setup the pipeline of commands based on the user's request.
282
283	# Apparently the locale flags are switched on where the manpage is
284	# found not just the locale env variables.
285	nroff_dev="ascii"
286	case "X${use_locale}X${manpage}" in
287	XyesX*/${man_lang}*${man_charset}/*)
288		# I don't pretend to know this; I'm just copying from the
289		# previous version of man(1).
290		case "$man_charset" in
291		KOI8-R)		nroff_dev="koi8-r" ;;
292		ISO8859-1)	nroff_dev="latin1" ;;
293		ISO8859-15)	nroff_dev="latin1" ;;
294		UTF-8)		nroff_dev="utf8" ;;
295		*)		nroff_dev="ascii" ;;
296		esac
297
298		NROFF="$NROFF -T$nroff_dev -dlocale=$man_lang.$man_charset"
299		EQN="$EQN -T$nroff_dev"
300
301		# Allow language specific calls to override the default
302		# set of utilities.
303		l=$(echo $man_lang | tr [:lower:] [:upper:])
304		for tool in EQN COL NROFF PIC TBL TROFF REFER VGRIND; do
305			eval "$tool=\${${tool}_$l:-\$$tool}"
306		done
307		;;
308	*)	NROFF="$NROFF -Tascii"
309		EQN="$EQN -Tascii"
310		;;
311	esac
312
313	if [ -n "$MANROFFSEQ" ]; then
314		set -- -$MANROFFSEQ
315		while getopts 'egprtv' preproc_arg; do
316			case "${preproc_arg}" in
317			e)	pipeline="$pipeline | $EQN" ;;
318			g)	;; # Ignore for compatability.
319			p)	pipeline="$pipeline | $PIC" ;;
320			r)	pipeline="$pipeline | $REFER" ;;
321			t)	pipeline="$pipeline | $TBL"; use_col=yes ;;
322			v)	pipeline="$pipeline | $VGRIND" ;;
323			*)	usage ;;
324			esac
325		done
326		# Strip the leading " | " from the resulting pipeline.
327		pipeline="${pipeline#" | "}"
328	else
329		pipeline="$TBL"
330		use_col=yes
331	fi
332
333	if [ -n "$tflag" ]; then
334		pipeline="$pipeline | $TROFF"
335	else
336		pipeline="$pipeline | $NROFF"
337
338		if [ -n "$use_col" ]; then
339			pipeline="$pipeline | $COL"
340		fi
341
342		pipeline="$pipeline | $PAGER"
343	fi
344
345	if [ $debug -gt 0 ]; then
346		decho "Command: $ZCAT $manpage | $pipeline"
347		ret=0
348	else
349		eval "$ZCAT $manpage | $pipeline"
350		ret=$?
351	fi
352}
353
354# Usage: man_find_and_display page
355# Search through the manpaths looking for the given page.
356man_find_and_display() {
357	local found_page locpath p path sect
358
359	# Check to see if it's a file. But only if it has a '/' in
360	# the filename.
361	case "$1" in
362	*/*)	if [ -f "$1" -a -r "$1" ]; then
363			decho "Found a usable page, displaying that"
364			found_page=yes
365			unset use_cat
366			manpage="$1"
367			man_display_page
368			return
369		fi
370		;;
371	esac
372
373	IFS=:
374	for sect in $MANSECT; do
375		decho "Searching section $sect" 2
376		for path in $MANPATH; do
377			for locpath in $locpaths; do
378				p=$path/$locpath
379				p=${p%/.} # Rid ourselves of the trailing /.
380
381				# Check if there is a MACHINE specific manpath.
382				if find_file $p $sect $MACHINE "$1"; then
383					found_page=yes
384					man_display_page
385					if [ -n "$aflag" ]; then
386						continue 2
387					else
388						return
389					fi
390				fi
391
392				# Check if there is a MACHINE_ARCH
393				# specific manpath.
394				if find_file $p $sect $MACHINE_ARCH "$1"; then
395					found_page=yes
396					man_display_page
397					if [ -n "$aflag" ]; then
398						continue 2
399					else
400						return
401					fi
402				fi
403
404				# Check plain old manpath.
405				if find_file $p $sect '' "$1"; then
406					found_page=yes
407					man_display_page
408					if [ -n "$aflag" ]; then
409						continue 2
410					else
411						return
412					fi
413				fi
414			done
415		done
416	done
417	unset IFS
418
419	# Nothing? Well, we are done then.
420	if [ -z "$found_page" ]; then
421		echo "No manual entry for $1" >&2
422		ret=1
423		return
424	fi
425}
426
427# Usage: man_parse_args "$@"
428# Parses commandline options for man.
429man_parse_args() {
430	local IFS cmd_arg
431
432	while getopts 'M:P:S:adfhkm:op:tw' cmd_arg; do
433		case "${cmd_arg}" in
434		M)	MANPATH=$OPTARG ;;
435		P)	PAGER=$OPTARG ;;
436		S)	MANSECT=$OPTARG ;;
437		a)	aflag=aflag ;;
438		d)	debug=$(( $debug + 1 )) ;;
439		f)	fflag=fflag ;;
440		h)	man_usage 0 ;;
441		k)	kflag=kflag ;;
442		m)	mflag=$OPTARG ;;
443		o)	oflag=oflag ;;
444		p)	MANROFFSEQ=$OPTARG ;;
445		t)	tflag=tflag ;;
446		w)	wflag=wflag ;;
447		*)	man_usage ;;
448		esac
449	done >&2
450
451	shift $(( $OPTIND - 1 ))
452
453	# Check the args for incompatible options.
454	case "${fflag}${kflag}${tflag}${wflag}" in
455	fflagkflag*)	echo "Incompatible options: -f and -k"; man_usage ;;
456	fflag*tflag*)	echo "Incompatible options: -f and -t"; man_usage ;;
457	fflag*wflag)	echo "Incompatible options: -f and -w"; man_usage ;;
458	*kflagtflag*)	echo "Incompatible options: -k and -t"; man_usage ;;
459	*kflag*wflag)	echo "Incompatible options: -k and -w"; man_usage ;;
460	*tflagwflag)	echo "Incompatible options: -t and -w"; man_usage ;;
461	esac
462
463	# Short circuit for whatis(1) and apropos(1)
464	if [ -n "$fflag" ]; then
465		do_whatis "$@"
466		exit
467	fi
468
469	if [ -n "$kflag" ]; then
470		do_apropos "$@"
471		exit
472	fi
473
474	IFS=:
475	for sect in $man_default_sections; do
476		if [ "$sect" = "$1" ]; then
477			decho "Detected manual section as first arg: $1"
478			MANSECT="$1"
479			shift
480			break
481		fi
482	done
483	unset IFS
484
485	pages="$*"
486}
487
488# Usage: man_setup
489# Setup various trivial but essential variables.
490man_setup() {
491	# Setup machine and architecture variables.
492	if [ -n "$mflag" ]; then
493		MACHINE_ARCH=${mflag%%:*}
494		MACHINE=${mflag##*:}
495	fi
496	if [ -z "$MACHINE_ARCH" ]; then
497		MACHINE_ARCH=$(sysctl -n hw.machine_arch)
498	fi
499	if [ -z "$MACHINE" ]; then
500		MACHINE=$(sysctl -n hw.machine)
501	fi
502	decho "Using architecture: $MACHINE_ARCH:$MACHINE"
503
504	setup_pager
505
506	# Setup manual sections to search.
507	if [ -z "$MANSECT" ]; then
508		MANSECT=$man_default_sections
509	fi
510	decho "Using manual sections: $MANSECT"
511
512	build_manpath
513	man_setup_locale
514}
515
516# Usage: man_setup_locale
517# Setup necessary locale variables.
518man_setup_locale() {
519	# Setup locale information.
520	if [ -n "$oflag" ]; then
521		decho "Using non-localized manpages"
522		unset use_locale
523	elif [ -n "$LC_ALL" ]; then
524		parse_locale "$LC_ALL"
525	elif [ -n "$LC_CTYPE" ]; then
526		parse_locale "$LC_CTYPE"
527	elif [ -n "$LANG" ]; then
528		parse_locale "$LANG"
529	fi
530
531	if [ -n "$use_locale" ]; then
532		locpaths="${man_lang}_${man_country}.${man_charset}"
533		locpaths="$locpaths:$man_lang.$man_charset"
534		if [ "$man_lang" != "en" ]; then
535			locpaths="$locpaths:en.$man_charset"
536		fi
537		locpaths="$locpaths:."
538	else
539		locpaths="."
540	fi
541	decho "Using locale paths: $locpaths"
542}
543
544# Usage: man_usage [exitcode]
545# Display usage for the man utility.
546man_usage() {
547	echo 'Usage:'
548	echo ' man [-adho] [-t | -w] [-M manpath] [-P pager] [-S mansect]'
549	echo '     [-m arch[:machine]] [-p [eprtv]] [mansect] page [...]'
550	echo ' man -f page [...] -- Emulates whatis(1)'
551	echo ' man -k page [...] -- Emulates apropos(1)'
552
553	# When exit'ing with -h, it's not an error.
554	exit ${1:-1}
555}
556
557# Usage: parse_configs
558# Reads the end-user adjustable config files.
559parse_configs() {
560	local IFS file files
561
562	if [ -n "$parsed_configs" ]; then
563		return
564	fi
565
566	unset IFS
567
568	# Read the global config first in case the user wants
569	# to override config_local.
570	if [ -r "$config_global" ]; then
571		parse_file "$config_global"
572	fi
573
574	# Glob the list of files to parse.
575	set +f
576	files=$(echo $config_local)
577	set -f
578
579	for file in $files; do
580		if [ -r "$file" ]; then
581			parse_file "$file"
582		fi
583	done
584
585	parsed_configs='yes'
586}
587
588# Usage: parse_file file
589# Reads the specified config files.
590parse_file() {
591	local file line tstr var
592
593	file="$1"
594	decho "Parsing config file: $file"
595	while read line; do
596		decho "  $line" 2
597		case "$line" in
598		\#*)		decho "    Comment" 3
599				;;
600		MANPATH*)	decho "    MANPATH" 3
601				trim "${line#MANPATH}"
602				add_to_manpath "$tstr"
603				;;
604		MANLOCALE*)	decho "    MANLOCALE" 3
605				trim "${line#MANLOCALE}"
606				manlocales="$manlocales:$tstr"
607				;;
608		MANCONFIG*)	decho "    MANCONFIG" 3
609				trim "${line#MANCONF}"
610				config_local="$tstr"
611				;;
612		# Set variables in the form of FOO_BAR
613		*_*[\ \	]*)	var="${line%%[\ \	]*}"
614				trim "${line#$var}"
615				eval "$var=\"$tstr\""
616				decho "    Parsed $var" 3
617				;;
618		esac
619	done < "$file"
620}
621
622# Usage: parse_locale localestring
623# Setup locale variables for proper parsing.
624parse_locale() {
625	local lang_cc
626
627	case "$1" in
628	C)				;;
629	POSIX)				;;
630	[a-z][a-z]_[A-Z][A-Z]\.*)	lang_cc="${1%.*}"
631					man_lang="${1%_*}"
632					man_country="${lang_cc#*_}"
633					man_charset="${1#*.}"
634					use_locale=yes
635					return 0
636					;;
637	*)				echo 'Unknown locale, assuming C' >&2
638					;;
639	esac
640
641	unset use_locale
642}
643
644# Usage: search_path
645# Traverse $PATH looking for manpaths.
646search_path() {
647	local IFS p path
648
649	decho "Searching PATH for man directories"
650
651	IFS=:
652	for path in $PATH; do
653		# Do a little special casing since the base manpages
654		# are in /usr/share/man instead of /usr/man or /man.
655		case "$path" in
656		/bin|/usr/bin)	add_to_manpath "/usr/share/man" ;;
657		*)	if add_to_manpath "$path/man"; then
658				:
659			elif add_to_manpath "$path/MAN"; then
660				:
661			else
662				case "$path" in
663				*/bin)	p="${path%/bin}/man"
664					add_to_manpath "$p"
665					;;
666				*)	;;
667				esac
668			fi
669			;;
670		esac
671	done
672	unset IFS
673
674	if [ -z "$manpath" ]; then
675		decho '  Unable to find any manpaths, using default'
676		manpath=$man_default_path
677	fi
678}
679
680# Usage: search_whatis cmd [arglist]
681# Do the heavy lifting for apropos/whatis
682search_whatis() {
683	local IFS bad cmd f good key keywords loc opt out path rval wlist
684
685	cmd="$1"
686	shift
687
688	whatis_parse_args "$@"
689
690	build_manpath
691	build_manlocales
692	setup_pager
693
694	if [ "$cmd" = "whatis" ]; then
695		opt="-w"
696	fi
697
698	f='whatis'
699
700	IFS=:
701	for path in $MANPATH; do
702		if [ \! -d "$path" ]; then
703			decho "Skipping non-existent path: $path" 2
704			continue
705		fi
706
707		if [ -f "$path/$f" -a -r "$path/$f" ]; then
708			decho "Found whatis: $path/$f"
709			wlist="$wlist $path/$f"
710		fi
711
712		for loc in $MANLOCALES; do
713			if [ -f "$path/$loc/$f" -a -r "$path/$loc/$f" ]; then
714				decho "Found whatis: $path/$loc/$f"
715				wlist="$wlist $path/$loc/$f"
716			fi
717		done
718	done
719	unset IFS
720
721	if [ -z "$wlist" ]; then
722		echo "$cmd: no whatis databases in $MANPATH" >&2
723		exit 1
724	fi
725
726	rval=0
727	for key in $keywords; do
728		out=$(grep -Ehi $opt -- "$key" $wlist)
729		if [ -n "$out" ]; then
730			good="$good\\n$out"
731		else
732			bad="$bad\\n$key: nothing appropriate"
733			rval=1
734		fi
735	done
736
737	# Strip leading carriage return.
738	good=${good#\\n}
739	bad=${bad#\\n}
740
741	if [ -n "$good" ]; then
742		echo -e "$good" | $PAGER
743	fi
744
745	if [ -n "$bad" ]; then
746		echo -e "$bad" >&2
747	fi
748
749	exit $rval
750}
751
752# Usage: setup_pager
753# Correctly sets $PAGER
754setup_pager() {
755	# Setup pager.
756	if [ -z "$PAGER" ]; then
757		PAGER="more -s"
758	fi
759	decho "Using pager: $PAGER"
760}
761
762# Usage: trim string
763# Trims whitespace from beginning and end of a variable
764trim() {
765	tstr=$1
766	while true; do
767		case "$tstr" in
768		[\ \	]*)	tstr="${tstr##[\ \	]}" ;;
769		*[\ \	])	tstr="${tstr%%[\ \	]}" ;;
770		*)		break ;;
771		esac
772	done
773}
774
775# Usage: whatis_parse_args "$@"
776# Parse commandline args for whatis and apropos.
777whatis_parse_args() {
778	local cmd_arg
779	while getopts 'd' cmd_arg; do
780		case "${cmd_arg}" in
781		d)	debug=$(( $debug + 1 )) ;;
782		*)	whatis_usage ;;
783		esac
784	done >&2
785
786	shift $(( $OPTIND - 1 ))
787
788	keywords="$*"
789}
790
791# Usage: whatis_usage
792# Display usage for the whatis/apropos utility.
793whatis_usage() {
794	echo "usage: $cmd [-d] keyword [...]"
795	exit 1
796}
797
798
799
800# Supported commands
801do_apropos() {
802	search_whatis apropos "$@"
803}
804
805do_man() {
806	man_parse_args "$@"
807	if [ -z "$pages" ]; then
808		echo 'What manual page do you want?' >&2
809		exit 1
810	fi
811	man_setup
812
813	for page in $pages; do
814		decho "Searching for $page"
815		man_find_and_display "$page"
816	done
817
818	exit ${ret:-0}
819}
820
821do_manpath() {
822	manpath_parse_args "$@"
823	if [ -z "$qflag" ]; then
824		manpath_warnings
825	fi
826	if [ -n "$Lflag" ]; then
827		build_manlocales
828		echo $MANLOCALES
829	else
830		build_manpath
831		echo $MANPATH
832	fi
833	exit 0
834}
835
836do_whatis() {
837	search_whatis whatis "$@"
838}
839
840EQN=/usr/bin/eqn
841COL=/usr/bin/col
842NROFF='/usr/bin/groff -S -Wall -mtty-char -man'
843PIC=/usr/bin/pic
844TBL=/usr/bin/tbl
845TROFF='/usr/bin/groff -S -man'
846REFER=/usr/bin/refer
847VGRIND=/usr/bin/vgrind
848ZCAT='/usr/bin/zcat -f'
849
850debug=0
851man_default_sections='1:1aout:8:2:3:n:4:5:6:7:9:l'
852man_default_path='/usr/share/man:/usr/share/openssl/man:/usr/local/man'
853
854config_global='/etc/man.conf'
855
856# This can be overridden via a setting in /etc/man.conf.
857config_local='/usr/local/etc/man.d/*.conf'
858
859# Set noglobbing for now. I don't want spurious globbing.
860set -f
861
862case "$0" in
863*apropos)	do_apropos "$@" ;;
864*manpath)	do_manpath "$@" ;;
865*whatis)	do_whatis "$@" ;;
866*)		do_man "$@" ;;
867esac
868