1 From a867d7705c78cce909bb05496339cd84b08fbaf3 Mon Sep 17 00:00:00 2001
2 From: Cameron Katri <me@cameronkatri.com>
3 Date: Tue, 20 Jul 2021 13:25:03 -0400
4 Subject: [PATCH] man(1): Remove FreeBSD's man(1) and use the man util from
7 This still includes manpath(1), because mandoc doesn't read
8 configuration files from /usr/local/etc/man.d/*
10 usr.bin/Makefile | 2 +-
11 usr.bin/man/Makefile | 8 -
12 usr.bin/man/man.1 | 411 ---------
13 usr.bin/man/man.sh | 1032 ----------------------
14 usr.bin/mandoc/Makefile | 4 +-
15 usr.bin/manpath/Makefile | 7 +
16 usr.bin/{man => manpath}/Makefile.depend | 0
17 usr.bin/{man => manpath}/man.conf.5 | 0
18 usr.bin/{man => manpath}/manpath.1 | 0
19 usr.bin/manpath/manpath.sh | 289 ++++++
20 10 files changed, 300 insertions(+), 1453 deletions(-)
21 delete mode 100644 usr.bin/man/Makefile
22 delete mode 100644 usr.bin/man/man.1
23 delete mode 100755 usr.bin/man/man.sh
24 create mode 100644 usr.bin/manpath/Makefile
25 rename usr.bin/{man => manpath}/Makefile.depend (100%)
26 rename usr.bin/{man => manpath}/man.conf.5 (100%)
27 rename usr.bin/{man => manpath}/manpath.1 (100%)
28 create mode 100755 usr.bin/manpath/manpath.sh
30 diff --git a/usr.bin/Makefile b/usr.bin/Makefile
31 index 206da7154ac..072cf1122b8 100644
32 --- a/usr.bin/Makefile
33 +++ b/usr.bin/Makefile
34 @@ -235,7 +235,7 @@ SUBDIR.${MK_MAIL}+= from
35 SUBDIR.${MK_MAIL}+= mail
36 SUBDIR.${MK_MAIL}+= msgs
37 SUBDIR.${MK_MAKE}+= bmake
38 -SUBDIR.${MK_MAN_UTILS}+= man
39 +SUBDIR.${MK_MAN_UTILS}+= manpath
40 SUBDIR.${MK_NETCAT}+= nc
41 SUBDIR.${MK_NIS}+= ypcat
42 SUBDIR.${MK_NIS}+= ypmatch
43 diff --git a/usr.bin/man/Makefile b/usr.bin/man/Makefile
44 deleted file mode 100644
45 index dc3748e2627..00000000000
46 --- a/usr.bin/man/Makefile
52 -LINKS= ${BINDIR}/man ${BINDIR}/manpath
54 -MAN= man.1 manpath.1 man.conf.5
56 -.include <bsd.prog.mk>
57 diff --git a/usr.bin/man/man.1 b/usr.bin/man/man.1
58 deleted file mode 100644
59 index 42fd60a8616..00000000000
60 --- a/usr.bin/man/man.1
64 -.\" Copyright (c) 2010 Gordon Tetlow
65 -.\" All rights reserved.
67 -.\" Redistribution and use in source and binary forms, with or without
68 -.\" modification, are permitted provided that the following conditions
70 -.\" 1. Redistributions of source code must retain the above copyright
71 -.\" notice, this list of conditions and the following disclaimer.
72 -.\" 2. Redistributions in binary form must reproduce the above copyright
73 -.\" notice, this list of conditions and the following disclaimer in the
74 -.\" documentation and/or other materials provided with the distribution.
76 -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
77 -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78 -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
79 -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
80 -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
81 -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
82 -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
83 -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
84 -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
85 -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
95 -.Nd display online manual documentation pages
103 -.Op Fl m Ar arch Ns Op : Ns Ar machine
104 -.Op Fl p Op Ar eprtv
116 -utility finds and displays online manual documentation pages.
121 -restricts the search to the specific section of the manual.
123 -The sections of the manual are:
124 -.Bl -enum -offset indent -compact
127 -General Commands Manual
133 -Library Functions Manual
136 -Kernel Interfaces Manual
145 -Miscellaneous Information Manual
148 -System Manager's Manual
151 -Kernel Developer's Manual
157 -.Bl -tag -width indent
159 -Forces a specific colon separated manual path instead of the default
165 -environment variable.
167 -Use specified pager.
170 -if color support is enabled, or
174 -environment variable, which in turn overrides the
176 -environment variable.
178 -Restricts manual sections searched to the specified colon delimited list.
180 -.Dq Li 1:8:2:3:3lua:n:4:5:6:7:9:l .
183 -environment variable.
185 -Display all manual pages instead of just the first found for each
189 -Print extra debugging information.
190 -Repeat for increased verbosity.
191 -Does not display the manual page.
196 -Display short help message and exit.
200 -.It Fl m Ar arch Ns Op : Ns Ar machine
201 -Override the default architecture and machine settings allowing lookup of
202 -other platform specific manual pages.
204 -.Sx IMPLEMENTATION NOTES
205 -for how this option changes the default behavior.
210 -environment variables.
212 -Force use of non-localized manual pages.
214 -.Sx IMPLEMENTATION NOTES
215 -for how locale specific searches work.
217 -.Ev LC_ALL , LC_CTYPE ,
220 -environment variables.
221 -.It Fl p Op Cm eprtv
222 -Use the list of given preprocessors before running
226 -Valid preprocessors arguments:
228 -.Bl -tag -width indent -compact
243 -environment variable.
245 -Send manual page source through
247 -allowing transformation of the manual pages to other formats.
249 -Display the location of the manual page instead of the contents of
252 -.Sh IMPLEMENTATION NOTES
253 -.Ss Locale Specific Searches
256 -utility supports manual pages in different locales.
257 -The search behavior is dictated by the first of three
258 -environment variables with a nonempty string:
259 -.Ev LC_ALL , LC_CTYPE ,
264 -will search for locale specific manual pages using the following logic:
266 -.Bl -item -offset indent -compact
268 -.Va lang Ns _ Ns Va country Ns . Ns Va charset
270 -.Va lang Ns . Ns Va charset
272 -.Li en Ns . Ns Va charset
278 -.Dq Li ja_JP.eucJP ,
280 -will search the following paths when considering section 1 manual pages in
281 -.Pa /usr/share/man :
283 -.Bl -item -offset indent -compact
285 -.Pa /usr/share/man/ja_JP.eucJP/man1
287 -.Pa /usr/share/man/ja.eucJP/man1
289 -.Pa /usr/share/man/en.eucJP/man1
291 -.Pa /usr/share/man/man1
293 -.Ss Platform Specific Searches
296 -utility supports platform specific manual pages.
297 -The search behavior is dictated by the
303 -environment variables.
313 -will search the following paths when considering section 4 manual pages in
314 -.Pa /usr/share/man :
316 -.Bl -item -offset indent -compact
318 -.Pa /usr/share/man/man4/aarch64
320 -.Pa /usr/share/man/man4/arm64
322 -.Pa /usr/share/man/man4
324 -.Ss Displaying Specific Manual Files
327 -utility also supports displaying a specific manual page if passed a path
328 -to the file as long as it contains a
332 -The following environment variables affect the execution of
334 -.Bl -tag -width ".Ev MANROFFSEQ"
335 -.It Ev LC_ALL , LC_CTYPE , LANG
336 -Used to find locale specific manual pages.
337 -Valid values can be found by running the
341 -.Sx IMPLEMENTATION NOTES
346 -.It Ev MACHINE_ARCH , MACHINE
347 -Used to find platform specific manual pages.
348 -If unset, the output of
349 -.Dq Li "sysctl hw.machine_arch"
351 -.Dq Li "sysctl hw.machine"
352 -is used respectively.
354 -.Sx IMPLEMENTATION NOTES
360 -The standard search path used by
362 -may be changed by specifying a path in the
364 -environment variable.
365 -Invalid paths, or paths without manual databases, are ignored.
370 -begins with a colon, it is appended to the default list;
371 -if it ends with a colon, it is prepended to the default list;
372 -or if it contains two adjacent colons,
373 -the standard search path is inserted between the colons.
374 -If none of these conditions are met, it overrides the
375 -standard search path.
377 -Used to determine the preprocessors for the manual source before running
381 -If unset, defaults to
387 -Restricts manual sections searched to the specified colon delimited list.
392 -If set to a numeric value, used as the width manpages should be displayed.
393 -Otherwise, if set to a special value
395 -and output is to a terminal,
396 -the pages may be displayed over the whole width of the screen.
398 -If set, enables color support.
400 -Program used to display files.
402 -If unset, and color support is enabled,
406 -If unset, and color support is disabled, then
409 -If that has no value either,
414 -.Bl -tag -width indent -compact
415 -.It Pa /etc/man.conf
416 -System configuration file.
417 -.It Pa /usr/local/etc/man.d/*.conf
418 -Local configuration files.
423 -Show the manual page for
425 -.Bd -literal -offset indent
429 -Show all manual pages for
431 -.Bd -literal -offset indent
435 -List manual pages which match the regular expression either in the title or in
437 -.Bd -literal -offset indent
438 -$ man -k '\e<copy\e>.*archive'
441 -Show the manual page for
446 -.Bd -literal -offset indent
450 -Show the location of the
453 -.Bd -literal -offset indent
474 diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh
475 deleted file mode 100755
476 index f31c464fcc8..00000000000
477 --- a/usr.bin/man/man.sh
482 -# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
484 -# Copyright (c) 2010 Gordon Tetlow
485 -# All rights reserved.
487 -# Redistribution and use in source and binary forms, with or without
488 -# modification, are permitted provided that the following conditions
490 -# 1. Redistributions of source code must retain the above copyright
491 -# notice, this list of conditions and the following disclaimer.
492 -# 2. Redistributions in binary form must reproduce the above copyright
493 -# notice, this list of conditions and the following disclaimer in the
494 -# documentation and/or other materials provided with the distribution.
496 -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
497 -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
498 -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
499 -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
500 -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
501 -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
502 -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
503 -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
504 -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
505 -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
510 -# Usage: add_to_manpath path
511 -# Adds a variable to manpath while ensuring we don't have duplicates.
512 -# Returns true if we were able to add something. False otherwise.
515 - *:$1) decho " Skipping duplicate manpath entry $1" 2 ;;
516 - $1:*) decho " Skipping duplicate manpath entry $1" 2 ;;
517 - *:$1:*) decho " Skipping duplicate manpath entry $1" 2 ;;
518 - *) if [ -d "$1" ]; then
519 - decho " Adding $1 to manpath"
520 - manpath="$manpath:$1"
529 -# Usage: build_manlocales
530 -# Builds a correct MANLOCALES variable.
531 -build_manlocales() {
532 - # If the user has set manlocales, who are we to argue.
533 - if [ -n "$MANLOCALES" ]; then
539 - # Trim leading colon
540 - MANLOCALES=${manlocales#:}
542 - decho "Available manual locales: $MANLOCALES"
545 -# Usage: build_manpath
546 -# Builds a correct MANPATH variable.
550 - # If the user has set a manpath, who are we to argue.
551 - if [ -n "$MANPATH" ]; then
553 - *:) PREPEND_MANPATH=${MANPATH} ;;
554 - :*) APPEND_MANPATH=${MANPATH} ;;
556 - PREPEND_MANPATH=${MANPATH%%::*}
557 - APPEND_MANPATH=${MANPATH#*::}
563 - if [ -n "$PREPEND_MANPATH" ]; then
565 - for path in $PREPEND_MANPATH; do
566 - add_to_manpath "$path"
573 - decho "Adding default manpath entries"
575 - for path in $man_default_path; do
576 - add_to_manpath "$path"
582 - if [ -n "$APPEND_MANPATH" ]; then
584 - for path in $APPEND_MANPATH; do
585 - add_to_manpath "$path"
589 - # Trim leading colon
590 - MANPATH=${manpath#:}
592 - decho "Using manual path: $MANPATH"
595 -# Usage: check_cat catglob
596 -# Checks to see if a cat glob is available.
598 - if exists "$1"; then
601 - setup_cattool $catpage
602 - decho " Found catpage $catpage"
609 -# Usage: check_man manglob catglob
610 -# Given 2 globs, figures out if the manglob is available, if so, check to
611 -# see if the catglob is also available and up to date.
613 - if exists "$1"; then
614 - # We have a match, check for a cat page
616 - setup_cattool $manpage
617 - decho " Found manpage $manpage"
619 - if [ -n "${use_width}" ]; then
620 - # non-standard width
622 - decho " Skipping catpage: non-standard page width"
623 - elif exists "$2" && is_newer $found $manpage; then
624 - # cat page found and is newer, use that
627 - setup_cattool $catpage
628 - decho " Using catpage $catpage"
630 - # no cat page or is older
632 - decho " Skipping catpage: not found or old"
640 -# Usage: decho "string" [debuglevel]
641 -# Echoes to stderr string prefaced with -- if high enough debuglevel.
643 - if [ $debug -ge ${2:-1} ]; then
648 -# Usage: exists glob
649 -# Returns true if glob resolves to a real file.
653 - # Don't accidentally inherit callers IFS (breaks perl manpages)
656 - # Use some globbing tricks in the shell to determine if a file
662 - if [ "$1" != "$2" -a -r "$2" ]; then
670 -# Usage: find_file path section subdir pagename
671 -# Returns: true if something is matched and found.
672 -# Search the given path/section combo for a given page.
674 - local manroot catroot mann man0 catn cat0
678 - if [ -n "$3" ]; then
679 - manroot="$manroot/$3"
680 - catroot="$catroot/$3"
683 - if [ ! -d "$manroot" -a ! -d "$catroot" ]; then
686 - decho " Searching directory $manroot" 2
688 - mann="$manroot/$4.$2*"
689 - man0="$manroot/$4.0*"
690 - catn="$catroot/$4.$2*"
691 - cat0="$catroot/$4.0*"
693 - # This is the behavior as seen by the original man utility.
694 - # Let's not change that which doesn't seem broken.
695 - if check_man "$mann" "$catn"; then
697 - elif check_man "$man0" "$cat0"; then
699 - elif check_cat "$catn"; then
701 - elif check_cat "$cat0"; then
708 -# Usage: is_newer file1 file2
709 -# Returns true if file1 is newer than file2 as calculated by mtime.
711 - if ! [ "$1" -ot "$2" ]; then
712 - decho " mtime: $1 not older than $2" 3
715 - decho " mtime: $1 older than $2" 3
720 -# Usage: manpath_parse_args "$@"
721 -# Parses commandline options for manpath.
722 -manpath_parse_args() {
725 - while getopts 'Ldq' cmd_arg; do
726 - case "${cmd_arg}" in
728 - d) debug=$(( $debug + 1 )) ;;
730 - *) manpath_usage ;;
735 -# Usage: manpath_usage
736 -# Display usage for the manpath(1) utility.
738 - echo 'usage: manpath [-Ldq]' >&2
742 -# Usage: manpath_warnings
743 -# Display some warnings to stderr.
744 -manpath_warnings() {
745 - if [ -n "$Lflag" -a -n "$MANLOCALES" ]; then
746 - echo "(Warning: MANLOCALES environment variable set)" >&2
750 -# Usage: man_check_for_so page path
751 -# Returns: True if able to resolve the file, false if it ended in tears.
752 -# Detects the presence of the .so directive and causes the file to be
753 -# redirected to another source file.
754 -man_check_for_so() {
755 - local IFS line tstr
758 - if [ -n "$catpage" ]; then
762 - # We need to loop to accommodate multiple .so directives.
765 - line=$($cattool $manpage | head -1)
767 - .so*) trim "${line#.so}"
768 - decho "$manpage includes $tstr"
769 - # Glob and check for the file.
770 - if ! check_man "$path/$tstr*" ""; then
771 - decho " Unable to find $tstr"
782 -# Usage: man_display_page
783 -# Display either the manpage or catpage depending on the use_cat variable
784 -man_display_page() {
785 - local IFS pipeline testline
787 - # We are called with IFS set to colon. This causes really weird
788 - # things to happen for the variables that have spaces in them.
791 - # If we are supposed to use a catpage and we aren't using troff(1)
792 - # just zcat the catpage and we are done.
793 - if [ -z "$tflag" -a -n "$use_cat" ]; then
794 - if [ -n "$wflag" ]; then
795 - echo "$catpage (source: $manpage)"
798 - if [ $debug -gt 0 ]; then
799 - decho "Command: $cattool $catpage | $MANPAGER"
802 - eval "$cattool $catpage | $MANPAGER"
809 - # Okay, we are using the manpage, do we just need to output the
810 - # name of the manpage?
811 - if [ -n "$wflag" ]; then
817 - if [ -n "$use_width" ]; then
818 - mandoc_args="-O width=${use_width}"
820 - testline="mandoc -Tlint -Wunsupp >/dev/null 2>&1"
821 - if [ -n "$tflag" ]; then
822 - pipeline="mandoc -Tps $mandoc_args"
824 - pipeline="mandoc $mandoc_args | $MANPAGER"
827 - if ! eval "$cattool $manpage | $testline" ;then
828 - if which -s groff; then
829 - man_display_page_groff
831 - echo "This manpage needs groff(1) to be rendered" >&2
832 - echo "First install groff(1): " >&2
833 - echo "pkg install groff " >&2
839 - if [ $debug -gt 0 ]; then
840 - decho "Command: $cattool $manpage | $pipeline"
843 - eval "$cattool $manpage | $pipeline"
848 -# Usage: man_display_page_groff
849 -# Display the manpage using groff
850 -man_display_page_groff() {
851 - local EQN NROFF PIC TBL TROFF REFER VGRIND
852 - local IFS l nroff_dev pipeline preproc_arg tool
854 - # So, we really do need to parse the manpage. First, figure out the
855 - # device flag (-T) we have to pass to eqn(1) and groff(1). Then,
856 - # setup the pipeline of commands based on the user's request.
858 - # If the manpage is from a particular charset, we need to setup nroff
859 - # to properly output for the correct device.
860 - case "${manpage}" in
861 - *.${man_charset}/*)
862 - # I don't pretend to know this; I'm just copying from the
863 - # previous version of man(1).
864 - case "$man_charset" in
865 - KOI8-R) nroff_dev="koi8-r" ;;
866 - ISO8859-1) nroff_dev="latin1" ;;
867 - ISO8859-15) nroff_dev="latin1" ;;
868 - UTF-8) nroff_dev="utf8" ;;
869 - *) nroff_dev="ascii" ;;
872 - NROFF="$NROFF -T$nroff_dev"
873 - EQN="$EQN -T$nroff_dev"
875 - # Iff the manpage is from the locale and not just the charset,
876 - # then we need to define the locale string.
877 - case "${manpage}" in
878 - */${man_lang}_${man_country}.${man_charset}/*)
879 - NROFF="$NROFF -dlocale=$man_lang.$man_charset"
881 - */${man_lang}.${man_charset}/*)
882 - NROFF="$NROFF -dlocale=$man_lang.$man_charset"
886 - # Allow language specific calls to override the default
887 - # set of utilities.
888 - l=$(echo $man_lang | tr [:lower:] [:upper:])
889 - for tool in EQN NROFF PIC TBL TROFF REFER VGRIND; do
890 - eval "$tool=\${${tool}_$l:-\$$tool}"
893 - *) NROFF="$NROFF -Tascii"
898 - if [ -z "$MANCOLOR" ]; then
899 - NROFF="$NROFF -P-c"
902 - if [ -n "${use_width}" ]; then
903 - NROFF="$NROFF -rLL=${use_width}n -rLT=${use_width}n"
906 - if [ -n "$MANROFFSEQ" ]; then
907 - set -- -$MANROFFSEQ
908 - while getopts 'egprtv' preproc_arg; do
909 - case "${preproc_arg}" in
910 - e) pipeline="$pipeline | $EQN" ;;
911 - g) ;; # Ignore for compatibility.
912 - p) pipeline="$pipeline | $PIC" ;;
913 - r) pipeline="$pipeline | $REFER" ;;
914 - t) pipeline="$pipeline | $TBL" ;;
915 - v) pipeline="$pipeline | $VGRIND" ;;
919 - # Strip the leading " | " from the resulting pipeline.
920 - pipeline="${pipeline#" | "}"
925 - if [ -n "$tflag" ]; then
926 - pipeline="$pipeline | $TROFF"
928 - pipeline="$pipeline | $NROFF | $MANPAGER"
931 - if [ $debug -gt 0 ]; then
932 - decho "Command: $cattool $manpage | $pipeline"
935 - eval "$cattool $manpage | $pipeline"
940 -# Usage: man_find_and_display page
941 -# Search through the manpaths looking for the given page.
942 -man_find_and_display() {
943 - local found_page locpath p path sect
945 - # Check to see if it's a file. But only if it has a '/' in
948 - */*) if [ -f "$1" -a -r "$1" ]; then
949 - decho "Found a usable page, displaying that"
952 - setup_cattool $manpage
953 - if man_check_for_so $manpage $(dirname $manpage); then
963 - for sect in $MANSECT; do
964 - decho "Searching section $sect" 2
965 - for path in $MANPATH; do
966 - for locpath in $locpaths; do
968 - p=${p%/.} # Rid ourselves of the trailing /.
970 - # Check if there is a MACHINE specific manpath.
971 - if find_file $p $sect $MACHINE "$1"; then
972 - if man_check_for_so $manpage $p; then
975 - if [ -n "$aflag" ]; then
983 - # Check if there is a MACHINE_ARCH
984 - # specific manpath.
985 - if find_file $p $sect $MACHINE_ARCH "$1"; then
986 - if man_check_for_so $manpage $p; then
989 - if [ -n "$aflag" ]; then
997 - # Check plain old manpath.
998 - if find_file $p $sect '' "$1"; then
999 - if man_check_for_so $manpage $p; then
1002 - if [ -n "$aflag" ]; then
1014 - # Nothing? Well, we are done then.
1015 - if [ -z "$found_page" ]; then
1016 - echo "No manual entry for $1" >&2
1022 -# Usage: man_parse_args "$@"
1023 -# Parses commandline options for man.
1027 - while getopts 'M:P:S:adfhkm:op:tw' cmd_arg; do
1028 - case "${cmd_arg}" in
1029 - M) MANPATH=$OPTARG ;;
1030 - P) MANPAGER=$OPTARG ;;
1031 - S) MANSECT=$OPTARG ;;
1033 - d) debug=$(( $debug + 1 )) ;;
1037 - m) mflag=$OPTARG ;;
1039 - p) MANROFFSEQ=$OPTARG ;;
1046 - shift $(( $OPTIND - 1 ))
1048 - # Check the args for incompatible options.
1049 - case "${fflag}${kflag}${tflag}${wflag}" in
1050 - fflagkflag*) echo "Incompatible options: -f and -k"; man_usage ;;
1051 - fflag*tflag*) echo "Incompatible options: -f and -t"; man_usage ;;
1052 - fflag*wflag) echo "Incompatible options: -f and -w"; man_usage ;;
1053 - *kflagtflag*) echo "Incompatible options: -k and -t"; man_usage ;;
1054 - *kflag*wflag) echo "Incompatible options: -k and -w"; man_usage ;;
1055 - *tflagwflag) echo "Incompatible options: -t and -w"; man_usage ;;
1058 - # Short circuit for whatis(1) and apropos(1)
1059 - if [ -n "$fflag" ]; then
1064 - if [ -n "$kflag" ]; then
1070 - for sect in $man_default_sections; do
1071 - if [ "$sect" = "$1" ]; then
1072 - decho "Detected manual section as first arg: $1"
1084 -# Setup various trivial but essential variables.
1086 - # Setup machine and architecture variables.
1087 - if [ -n "$mflag" ]; then
1088 - MACHINE_ARCH=${mflag%%:*}
1089 - MACHINE=${mflag##*:}
1091 - if [ -z "$MACHINE_ARCH" ]; then
1092 - MACHINE_ARCH=$($SYSCTL -n hw.machine_arch)
1094 - if [ -z "$MACHINE" ]; then
1095 - MACHINE=$($SYSCTL -n hw.machine)
1097 - decho "Using architecture: $MACHINE_ARCH:$MACHINE"
1101 - # Setup manual sections to search.
1102 - if [ -z "$MANSECT" ]; then
1103 - MANSECT=$man_default_sections
1105 - decho "Using manual sections: $MANSECT"
1112 -# Usage: man_setup_width
1113 -# Set up page width.
1114 -man_setup_width() {
1118 - case "$MANWIDTH" in
1120 - if [ "$MANWIDTH" -gt 0 2>/dev/null ]; then
1121 - use_width=$MANWIDTH
1125 - if { sizes=$($STTY size 0>&3 2>/dev/null); } 3>&1; then
1127 - if [ $2 -gt 80 ]; then
1128 - use_width=$(($2-2))
1133 - if [ -n "$use_width" ]; then
1134 - decho "Using non-standard page width: ${use_width}"
1136 - decho 'Using standard page width'
1140 -# Usage: man_setup_locale
1141 -# Setup necessary locale variables.
1142 -man_setup_locale() {
1147 - man_charset='US-ASCII'
1149 - # Setup locale information.
1150 - if [ -n "$oflag" ]; then
1151 - decho 'Using non-localized manpages'
1153 - # Use the locale tool to give us proper locale information
1156 - if [ -n "$LANG" ]; then
1166 - [a-z][a-z]_[A-Z][A-Z]\.*)
1167 - lang_cc="${locstr%.*}"
1168 - man_lang="${locstr%_*}"
1169 - man_country="${lang_cc#*_}"
1170 - man_charset="${locstr#*.}"
1171 - locpaths="$locstr"
1172 - locpaths="$locpaths:$man_lang.$man_charset"
1173 - if [ "$man_lang" != "en" ]; then
1174 - locpaths="$locpaths:en.$man_charset"
1176 - locpaths="$locpaths:."
1178 - *) echo 'Unknown locale, assuming C' >&2
1183 - decho "Using locale paths: $locpaths"
1186 -# Usage: man_usage [exitcode]
1187 -# Display usage for the man utility.
1190 - echo ' man [-adho] [-t | -w] [-M manpath] [-P pager] [-S mansect]'
1191 - echo ' [-m arch[:machine]] [-p [eprtv]] [mansect] page [...]'
1192 - echo ' man -f page [...] -- Emulates whatis(1)'
1193 - echo ' man -k page [...] -- Emulates apropos(1)'
1195 - # When exit'ing with -h, it's not an error.
1199 -# Usage: parse_configs
1200 -# Reads the end-user adjustable config files.
1202 - local IFS file files
1204 - if [ -n "$parsed_configs" ]; then
1210 - # Read the global config first in case the user wants
1211 - # to override config_local.
1212 - if [ -r "$config_global" ]; then
1213 - parse_file "$config_global"
1216 - # Glob the list of files to parse.
1218 - files=$(echo $config_local)
1221 - for file in $files; do
1222 - if [ -r "$file" ]; then
1223 - parse_file "$file"
1227 - parsed_configs='yes'
1230 -# Usage: parse_file file
1231 -# Reads the specified config files.
1233 - local file line tstr var
1236 - decho "Parsing config file: $file"
1237 - while read line; do
1240 - \#*) decho " Comment" 3
1242 - MANPATH*) decho " MANPATH" 3
1243 - trim "${line#MANPATH}"
1244 - add_to_manpath "$tstr"
1246 - MANLOCALE*) decho " MANLOCALE" 3
1247 - trim "${line#MANLOCALE}"
1248 - manlocales="$manlocales:$tstr"
1250 - MANCONFIG*) decho " MANCONFIG" 3
1251 - trim "${line#MANCONFIG}"
1252 - config_local="$tstr"
1254 - # Set variables in the form of FOO_BAR
1255 - *_*[\ \ ]*) var="${line%%[\ \ ]*}"
1256 - trim "${line#$var}"
1257 - eval "$var=\"$tstr\""
1258 - decho " Parsed $var" 3
1264 -# Usage: search_path
1265 -# Traverse $PATH looking for manpaths.
1269 - decho "Searching PATH for man directories"
1272 - for path in $PATH; do
1273 - if add_to_manpath "$path/man"; then
1275 - elif add_to_manpath "$path/MAN"; then
1279 - */bin) p="${path%/bin}/share/man"
1280 - add_to_manpath "$p"
1281 - p="${path%/bin}/man"
1282 - add_to_manpath "$p"
1289 - if [ -z "$manpath" ]; then
1290 - decho ' Unable to find any manpaths, using default'
1291 - manpath=$man_default_path
1295 -# Usage: search_whatis cmd [arglist]
1296 -# Do the heavy lifting for apropos/whatis
1298 - local IFS bad cmd f good key keywords loc opt out path rval wlist
1303 - whatis_parse_args "$@"
1309 - if [ "$cmd" = "whatis" ]; then
1316 - for path in $MANPATH; do
1317 - if [ \! -d "$path" ]; then
1318 - decho "Skipping non-existent path: $path" 2
1322 - if [ -f "$path/$f" -a -r "$path/$f" ]; then
1323 - decho "Found whatis: $path/$f"
1324 - wlist="$wlist $path/$f"
1327 - for loc in $MANLOCALES; do
1328 - if [ -f "$path/$loc/$f" -a -r "$path/$loc/$f" ]; then
1329 - decho "Found whatis: $path/$loc/$f"
1330 - wlist="$wlist $path/$loc/$f"
1336 - if [ -z "$wlist" ]; then
1337 - echo "$cmd: no whatis databases in $MANPATH" >&2
1342 - for key in $keywords; do
1343 - out=$(grep -Ehi $opt -- "$key" $wlist)
1344 - if [ -n "$out" ]; then
1345 - good="$good\\n$out"
1347 - bad="$bad\\n$key: nothing appropriate"
1352 - # Strip leading carriage return.
1356 - if [ -n "$good" ]; then
1357 - echo -e "$good" | $MANPAGER
1360 - if [ -n "$bad" ]; then
1361 - echo -e "$bad" >&2
1367 -# Usage: setup_cattool page
1368 -# Finds an appropriate decompressor based on extension
1371 - *.bz) cattool='/usr/bin/bzcat' ;;
1372 - *.bz2) cattool='/usr/bin/bzcat' ;;
1373 - *.gz) cattool='/usr/bin/zcat' ;;
1374 - *.lzma) cattool='/usr/bin/lzcat' ;;
1375 - *.xz) cattool='/usr/bin/xzcat' ;;
1376 - *) cattool='/usr/bin/zcat -f' ;;
1380 -# Usage: setup_pager
1381 -# Correctly sets $MANPAGER
1384 - if [ -z "$MANPAGER" ]; then
1385 - if [ -n "$MANCOLOR" ]; then
1386 - MANPAGER="less -sR"
1388 - if [ -n "$PAGER" ]; then
1391 - MANPAGER="less -s"
1395 - decho "Using pager: $MANPAGER"
1398 -# Usage: trim string
1399 -# Trims whitespace from beginning and end of a variable
1404 - [\ \ ]*) tstr="${tstr##[\ \ ]}" ;;
1405 - *[\ \ ]) tstr="${tstr%%[\ \ ]}" ;;
1411 -# Usage: whatis_parse_args "$@"
1412 -# Parse commandline args for whatis and apropos.
1413 -whatis_parse_args() {
1415 - while getopts 'd' cmd_arg; do
1416 - case "${cmd_arg}" in
1417 - d) debug=$(( $debug + 1 )) ;;
1418 - *) whatis_usage ;;
1422 - shift $(( $OPTIND - 1 ))
1427 -# Usage: whatis_usage
1428 -# Display usage for the whatis/apropos utility.
1430 - echo "usage: $cmd [-d] keyword [...]"
1436 -# Supported commands
1438 - [ $(stat -f %i /usr/bin/man) -ne $(stat -f %i /usr/bin/apropos) ] && \
1440 - search_whatis apropos "$@"
1444 - man_parse_args "$@"
1445 - if [ -z "$pages" ]; then
1446 - echo 'What manual page do you want?' >&2
1451 - for page in $pages; do
1452 - decho "Searching for $page"
1453 - man_find_and_display "$page"
1460 - manpath_parse_args "$@"
1461 - if [ -z "$qflag" ]; then
1464 - if [ -n "$Lflag" ]; then
1475 - [ $(stat -f %i /usr/bin/man) -ne $(stat -f %i /usr/bin/whatis) ] && \
1477 - search_whatis whatis "$@"
1480 -# User's PATH setting decides on the groff-suite to pick up.
1482 -NROFF='groff -S -P-h -Wall -mtty-char -man'
1486 -TROFF='groff -S -man'
1489 -LOCALE=/usr/bin/locale
1491 -SYSCTL=/sbin/sysctl
1494 -man_default_sections='1:8:2:3:3lua:n:4:5:6:7:9:l'
1495 -man_default_path='/usr/share/man:/usr/share/openssl/man:/usr/local/share/man:/usr/local/man'
1496 -cattool='/usr/bin/zcat -f'
1498 -config_global='/etc/man.conf'
1500 -# This can be overridden via a setting in /etc/man.conf.
1501 -config_local='/usr/local/etc/man.d/*.conf'
1503 -# Set noglobbing for now. I don't want spurious globbing.
1507 -*apropos) do_apropos "$@" ;;
1508 -*manpath) do_manpath "$@" ;;
1509 -*whatis) do_whatis "$@" ;;
1512 diff --git a/usr.bin/mandoc/Makefile b/usr.bin/mandoc/Makefile
1513 index 55e13fa6485..7b323e4ee55 100644
1514 --- a/usr.bin/mandoc/Makefile
1515 +++ b/usr.bin/mandoc/Makefile
1516 @@ -10,10 +10,12 @@ MAN= mandoc.1 eqn.7 mandoc_char.7 tbl.7 man.7 mdoc.7 roff.7
1517 MLINKS= mandoc.1 mdocml.1
1518 .if ${MK_MAN_UTILS} != no
1519 MAN+= apropos.1 makewhatis.8
1521 MLINKS+= apropos.1 whatis.1
1522 LINKS= ${BINDIR}/mandoc ${BINDIR}/whatis \
1523 ${BINDIR}/mandoc ${BINDIR}/makewhatis \
1524 - ${BINDIR}/mandoc ${BINDIR}/apropos
1525 + ${BINDIR}/mandoc ${BINDIR}/apropos \
1526 + ${BINDIR}/mandoc ${BINDIR}/man
1527 .elif defined(BOOTSTRAPPING)
1528 .error "MK_MAN_UTILS should be set to yes when bootstrapping"
1530 diff --git a/usr.bin/manpath/Makefile b/usr.bin/manpath/Makefile
1531 new file mode 100644
1532 index 00000000000..20a05f68a62
1534 +++ b/usr.bin/manpath/Makefile
1538 +SCRIPTS= manpath.sh
1540 +MAN= manpath.1 man.conf.5
1542 +.include <bsd.prog.mk>
1543 diff --git a/usr.bin/man/Makefile.depend b/usr.bin/manpath/Makefile.depend
1544 similarity index 100%
1545 rename from usr.bin/man/Makefile.depend
1546 rename to usr.bin/manpath/Makefile.depend
1547 diff --git a/usr.bin/man/man.conf.5 b/usr.bin/manpath/man.conf.5
1548 similarity index 100%
1549 rename from usr.bin/man/man.conf.5
1550 rename to usr.bin/manpath/man.conf.5
1551 diff --git a/usr.bin/man/manpath.1 b/usr.bin/manpath/manpath.1
1552 similarity index 100%
1553 rename from usr.bin/man/manpath.1
1554 rename to usr.bin/manpath/manpath.1
1555 diff --git a/usr.bin/manpath/manpath.sh b/usr.bin/manpath/manpath.sh
1556 new file mode 100755
1557 index 00000000000..1bec8ef4882
1559 +++ b/usr.bin/manpath/manpath.sh
1563 +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
1565 +# Copyright (c) 2010 Gordon Tetlow
1566 +# All rights reserved.
1568 +# Redistribution and use in source and binary forms, with or without
1569 +# modification, are permitted provided that the following conditions
1571 +# 1. Redistributions of source code must retain the above copyright
1572 +# notice, this list of conditions and the following disclaimer.
1573 +# 2. Redistributions in binary form must reproduce the above copyright
1574 +# notice, this list of conditions and the following disclaimer in the
1575 +# documentation and/or other materials provided with the distribution.
1577 +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1578 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1579 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1580 +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1581 +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1582 +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1583 +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1584 +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1585 +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1586 +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1591 +# Usage: add_to_manpath path
1592 +# Adds a variable to manpath while ensuring we don't have duplicates.
1593 +# Returns true if we were able to add something. False otherwise.
1595 + case "$manpath" in
1596 + *:$1) decho " Skipping duplicate manpath entry $1" 2 ;;
1597 + $1:*) decho " Skipping duplicate manpath entry $1" 2 ;;
1598 + *:$1:*) decho " Skipping duplicate manpath entry $1" 2 ;;
1599 + *) if [ -d "$1" ]; then
1600 + decho " Adding $1 to manpath"
1601 + manpath="$manpath:$1"
1610 +# Usage: build_manlocales
1611 +# Builds a correct MANLOCALES variable.
1612 +build_manlocales() {
1613 + # If the user has set manlocales, who are we to argue.
1614 + if [ -n "$MANLOCALES" ]; then
1620 + # Trim leading colon
1621 + MANLOCALES=${manlocales#:}
1623 + decho "Available manual locales: $MANLOCALES"
1626 +# Usage: build_manpath
1627 +# Builds a correct MANPATH variable.
1631 + # If the user has set a manpath, who are we to argue.
1632 + if [ -n "$MANPATH" ]; then
1633 + case "$MANPATH" in
1634 + *:) PREPEND_MANPATH=${MANPATH} ;;
1635 + :*) APPEND_MANPATH=${MANPATH} ;;
1637 + PREPEND_MANPATH=${MANPATH%%::*}
1638 + APPEND_MANPATH=${MANPATH#*::}
1644 + if [ -n "$PREPEND_MANPATH" ]; then
1646 + for path in $PREPEND_MANPATH; do
1647 + add_to_manpath "$path"
1654 + decho "Adding default manpath entries"
1656 + for path in $man_default_path; do
1657 + add_to_manpath "$path"
1663 + if [ -n "$APPEND_MANPATH" ]; then
1665 + for path in $APPEND_MANPATH; do
1666 + add_to_manpath "$path"
1670 + # Trim leading colon
1671 + MANPATH=${manpath#:}
1673 + decho "Using manual path: $MANPATH"
1676 +# Usage: decho "string" [debuglevel]
1677 +# Echoes to stderr string prefaced with -- if high enough debuglevel.
1679 + if [ $debug -ge ${2:-1} ]; then
1684 +# Usage: manpath_parse_args "$@"
1685 +# Parses commandline options for manpath.
1686 +manpath_parse_args() {
1689 + while getopts 'Ldq' cmd_arg; do
1690 + case "${cmd_arg}" in
1692 + d) debug=$(( $debug + 1 )) ;;
1694 + *) manpath_usage ;;
1699 +# Usage: manpath_usage
1700 +# Display usage for the manpath(1) utility.
1702 + echo 'usage: manpath [-Ldq]' >&2
1706 +# Usage: manpath_warnings
1707 +# Display some warnings to stderr.
1708 +manpath_warnings() {
1709 + if [ -n "$Lflag" -a -n "$MANLOCALES" ]; then
1710 + echo "(Warning: MANLOCALES environment variable set)" >&2
1714 +# Usage: parse_configs
1715 +# Reads the end-user adjustable config files.
1717 + local IFS file files
1719 + if [ -n "$parsed_configs" ]; then
1725 + # Read the global config first in case the user wants
1726 + # to override config_local.
1727 + if [ -r "$config_global" ]; then
1728 + parse_file "$config_global"
1731 + # Glob the list of files to parse.
1733 + files=$(echo $config_local)
1736 + for file in $files; do
1737 + if [ -r "$file" ]; then
1738 + parse_file "$file"
1742 + parsed_configs='yes'
1745 +# Usage: parse_file file
1746 +# Reads the specified config files.
1748 + local file line tstr var
1751 + decho "Parsing config file: $file"
1752 + while read line; do
1755 + \#*) decho " Comment" 3
1757 + MANPATH*) decho " MANPATH" 3
1758 + trim "${line#MANPATH}"
1759 + add_to_manpath "$tstr"
1761 + MANLOCALE*) decho " MANLOCALE" 3
1762 + trim "${line#MANLOCALE}"
1763 + manlocales="$manlocales:$tstr"
1765 + MANCONFIG*) decho " MANCONFIG" 3
1766 + trim "${line#MANCONFIG}"
1767 + config_local="$tstr"
1769 + # Set variables in the form of FOO_BAR
1770 + *_*[\ \ ]*) var="${line%%[\ \ ]*}"
1771 + trim "${line#$var}"
1772 + eval "$var=\"$tstr\""
1773 + decho " Parsed $var" 3
1779 +# Usage: search_path
1780 +# Traverse $PATH looking for manpaths.
1784 + decho "Searching PATH for man directories"
1787 + for path in $PATH; do
1788 + if add_to_manpath "$path/man"; then
1790 + elif add_to_manpath "$path/MAN"; then
1794 + */bin) p="${path%/bin}/share/man"
1795 + add_to_manpath "$p"
1796 + p="${path%/bin}/man"
1797 + add_to_manpath "$p"
1804 + if [ -z "$manpath" ]; then
1805 + decho ' Unable to find any manpaths, using default'
1806 + manpath=$man_default_path
1810 +# Usage: trim string
1811 +# Trims whitespace from beginning and end of a variable
1816 + [\ \ ]*) tstr="${tstr##[\ \ ]}" ;;
1817 + *[\ \ ]) tstr="${tstr%%[\ \ ]}" ;;
1824 + manpath_parse_args "$@"
1825 + if [ -z "$qflag" ]; then
1828 + if [ -n "$Lflag" ]; then
1839 +man_default_path='/usr/share/man:/usr/share/openssl/man:/usr/local/share/man:/usr/local/man'
1841 +config_global='/etc/man.conf'
1843 +# This can be overridden via a setting in /etc/man.conf.
1844 +config_local='/usr/local/etc/man.d/*.conf'
1846 +# Set noglobbing for now. I don't want spurious globbing.