]> git.cameronkatri.com Git - freebsd-patches.git/blob - man-1-Use-mandoc-1-man.patch
diff(1)-Add-color-support.patch: Fix formating
[freebsd-patches.git] / man-1-Use-mandoc-1-man.patch
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
5 mandoc
6
7 This still includes manpath(1), because mandoc doesn't read
8 configuration files from /usr/local/etc/man.d/*
9 ---
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
29
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
47 +++ /dev/null
48 @@ -1,8 +0,0 @@
49 -# $FreeBSD$
50 -
51 -SCRIPTS= man.sh
52 -LINKS= ${BINDIR}/man ${BINDIR}/manpath
53 -
54 -MAN= man.1 manpath.1 man.conf.5
55 -
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
61 +++ /dev/null
62 @@ -1,411 +0,0 @@
63 -.\"-
64 -.\" Copyright (c) 2010 Gordon Tetlow
65 -.\" All rights reserved.
66 -.\"
67 -.\" Redistribution and use in source and binary forms, with or without
68 -.\" modification, are permitted provided that the following conditions
69 -.\" are met:
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.
75 -.\"
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
86 -.\" SUCH DAMAGE.
87 -.\"
88 -.\" $FreeBSD$
89 -.\"
90 -.Dd January 9, 2021
91 -.Dt MAN 1
92 -.Os
93 -.Sh NAME
94 -.Nm man
95 -.Nd display online manual documentation pages
96 -.Sh SYNOPSIS
97 -.Nm
98 -.Op Fl adho
99 -.Op Fl t | w
100 -.Op Fl M Ar manpath
101 -.Op Fl P Ar pager
102 -.Op Fl S Ar mansect
103 -.Op Fl m Ar arch Ns Op : Ns Ar machine
104 -.Op Fl p Op Ar eprtv
105 -.Op Ar mansect
106 -.Ar page ...
107 -.Nm
108 -.Fl f
109 -.Ar keyword ...
110 -.Nm
111 -.Fl k
112 -.Ar keyword ...
113 -.Sh DESCRIPTION
114 -The
115 -.Nm
116 -utility finds and displays online manual documentation pages.
117 -If
118 -.Ar mansect
119 -is provided,
120 -.Nm
121 -restricts the search to the specific section of the manual.
122 -.Pp
123 -The sections of the manual are:
124 -.Bl -enum -offset indent -compact
125 -.It
126 -.Fx
127 -General Commands Manual
128 -.It
129 -.Fx
130 -System Calls Manual
131 -.It
132 -.Fx
133 -Library Functions Manual
134 -.It
135 -.Fx
136 -Kernel Interfaces Manual
137 -.It
138 -.Fx
139 -File Formats Manual
140 -.It
141 -.Fx
142 -Games Manual
143 -.It
144 -.Fx
145 -Miscellaneous Information Manual
146 -.It
147 -.Fx
148 -System Manager's Manual
149 -.It
150 -.Fx
151 -Kernel Developer's Manual
152 -.El
153 -.Pp
154 -Options that
155 -.Nm
156 -understands:
157 -.Bl -tag -width indent
158 -.It Fl M Ar manpath
159 -Forces a specific colon separated manual path instead of the default
160 -search path.
161 -See
162 -.Xr manpath 1 .
163 -Overrides the
164 -.Ev MANPATH
165 -environment variable.
166 -.It Fl P Ar pager
167 -Use specified pager.
168 -Defaults to
169 -.Dq Li "less -sR"
170 -if color support is enabled, or
171 -.Dq Li "less -s" .
172 -Overrides the
173 -.Ev MANPAGER
174 -environment variable, which in turn overrides the
175 -.Ev PAGER
176 -environment variable.
177 -.It Fl S Ar mansect
178 -Restricts manual sections searched to the specified colon delimited list.
179 -Defaults to
180 -.Dq Li 1:8:2:3:3lua:n:4:5:6:7:9:l .
181 -Overrides the
182 -.Ev MANSECT
183 -environment variable.
184 -.It Fl a
185 -Display all manual pages instead of just the first found for each
186 -.Ar page
187 -argument.
188 -.It Fl d
189 -Print extra debugging information.
190 -Repeat for increased verbosity.
191 -Does not display the manual page.
192 -.It Fl f
193 -Emulate
194 -.Xr whatis 1 .
195 -.It Fl h
196 -Display short help message and exit.
197 -.It Fl k
198 -Emulate
199 -.Xr apropos 1 .
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.
203 -See
204 -.Sx IMPLEMENTATION NOTES
205 -for how this option changes the default behavior.
206 -Overrides the
207 -.Ev MACHINE_ARCH
208 -and
209 -.Ev MACHINE
210 -environment variables.
211 -.It Fl o
212 -Force use of non-localized manual pages.
213 -See
214 -.Sx IMPLEMENTATION NOTES
215 -for how locale specific searches work.
216 -Overrides the
217 -.Ev LC_ALL , LC_CTYPE ,
218 -and
219 -.Ev LANG
220 -environment variables.
221 -.It Fl p Op Cm eprtv
222 -Use the list of given preprocessors before running
223 -.Xr nroff 1
224 -or
225 -.Xr troff 1 .
226 -Valid preprocessors arguments:
227 -.Pp
228 -.Bl -tag -width indent -compact
229 -.It Cm e
230 -.Xr eqn 1
231 -.It Cm p
232 -.Xr pic 1
233 -.It Cm r
234 -.Xr refer 1
235 -.It Cm t
236 -.Xr tbl 1
237 -.It Cm v
238 -.Xr vgrind 1
239 -.El
240 -.Pp
241 -Overrides the
242 -.Ev MANROFFSEQ
243 -environment variable.
244 -.It Fl t
245 -Send manual page source through
246 -.Xr troff 1
247 -allowing transformation of the manual pages to other formats.
248 -.It Fl w
249 -Display the location of the manual page instead of the contents of
250 -the manual page.
251 -.El
252 -.Sh IMPLEMENTATION NOTES
253 -.Ss Locale Specific Searches
254 -The
255 -.Nm
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 ,
260 -or
261 -.Ev LANG .
262 -If set,
263 -.Nm
264 -will search for locale specific manual pages using the following logic:
265 -.Pp
266 -.Bl -item -offset indent -compact
267 -.It
268 -.Va lang Ns _ Ns Va country Ns . Ns Va charset
269 -.It
270 -.Va lang Ns . Ns Va charset
271 -.It
272 -.Li en Ns . Ns Va charset
273 -.El
274 -.Pp
275 -For example, if
276 -.Ev LC_ALL
277 -is set to
278 -.Dq Li ja_JP.eucJP ,
279 -.Nm
280 -will search the following paths when considering section 1 manual pages in
281 -.Pa /usr/share/man :
282 -.Pp
283 -.Bl -item -offset indent -compact
284 -.It
285 -.Pa /usr/share/man/ja_JP.eucJP/man1
286 -.It
287 -.Pa /usr/share/man/ja.eucJP/man1
288 -.It
289 -.Pa /usr/share/man/en.eucJP/man1
290 -.It
291 -.Pa /usr/share/man/man1
292 -.El
293 -.Ss Platform Specific Searches
294 -The
295 -.Nm
296 -utility supports platform specific manual pages.
297 -The search behavior is dictated by the
298 -.Fl m
299 -option or the
300 -.Ev MACHINE_ARCH
301 -and
302 -.Ev MACHINE
303 -environment variables.
304 -For example, if
305 -.Ev MACHINE_ARCH
306 -is set to
307 -.Dq Li aarch64
308 -and
309 -.Ev MACHINE
310 -is set to
311 -.Dq Li arm64 ,
312 -.Nm
313 -will search the following paths when considering section 4 manual pages in
314 -.Pa /usr/share/man :
315 -.Pp
316 -.Bl -item -offset indent -compact
317 -.It
318 -.Pa /usr/share/man/man4/aarch64
319 -.It
320 -.Pa /usr/share/man/man4/arm64
321 -.It
322 -.Pa /usr/share/man/man4
323 -.El
324 -.Ss Displaying Specific Manual Files
325 -The
326 -.Nm
327 -utility also supports displaying a specific manual page if passed a path
328 -to the file as long as it contains a
329 -.Ql /
330 -character.
331 -.Sh ENVIRONMENT
332 -The following environment variables affect the execution of
333 -.Nm :
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
338 -.Xr locale 1
339 -command.
340 -See
341 -.Sx IMPLEMENTATION NOTES
342 -for details.
343 -Influenced by the
344 -.Fl o
345 -option.
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"
350 -and
351 -.Dq Li "sysctl hw.machine"
352 -is used respectively.
353 -See
354 -.Sx IMPLEMENTATION NOTES
355 -for details.
356 -Corresponds to the
357 -.Fl m
358 -option.
359 -.It Ev MANPATH
360 -The standard search path used by
361 -.Xr man 1
362 -may be changed by specifying a path in the
363 -.Ev MANPATH
364 -environment variable.
365 -Invalid paths, or paths without manual databases, are ignored.
366 -Overridden by
367 -.Fl M .
368 -If
369 -.Ev MANPATH
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.
376 -.It Ev MANROFFSEQ
377 -Used to determine the preprocessors for the manual source before running
378 -.Xr nroff 1
379 -or
380 -.Xr troff 1 .
381 -If unset, defaults to
382 -.Xr tbl 1 .
383 -Corresponds to the
384 -.Fl p
385 -option.
386 -.It Ev MANSECT
387 -Restricts manual sections searched to the specified colon delimited list.
388 -Corresponds to the
389 -.Fl S
390 -option.
391 -.It Ev MANWIDTH
392 -If set to a numeric value, used as the width manpages should be displayed.
393 -Otherwise, if set to a special value
394 -.Dq Li tty ,
395 -and output is to a terminal,
396 -the pages may be displayed over the whole width of the screen.
397 -.It Ev MANCOLOR
398 -If set, enables color support.
399 -.It Ev MANPAGER
400 -Program used to display files.
401 -.Pp
402 -If unset, and color support is enabled,
403 -.Dq Li "less -sR"
404 -is used.
405 -.Pp
406 -If unset, and color support is disabled, then
407 -.Ev PAGER
408 -is used.
409 -If that has no value either,
410 -.Dq Li "less -s"
411 -is used.
412 -.El
413 -.Sh FILES
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.
419 -.El
420 -.Sh EXIT STATUS
421 -.Ex -std
422 -.Sh EXAMPLES
423 -Show the manual page for
424 -.Xr stat 2 :
425 -.Bd -literal -offset indent
426 -$ man 2 stat
427 -.Ed
428 -.Pp
429 -Show all manual pages for
430 -.Ql stat .
431 -.Bd -literal -offset indent
432 -$ man -a stat
433 -.Ed
434 -.Pp
435 -List manual pages which match the regular expression either in the title or in
436 -the body:
437 -.Bd -literal -offset indent
438 -$ man -k '\e<copy\e>.*archive'
439 -.Ed
440 -.Pp
441 -Show the manual page for
442 -.Xr ls 1
443 -and use
444 -.Xr cat 1
445 -as pager:
446 -.Bd -literal -offset indent
447 -$ man -P cat ls
448 -.Ed
449 -.Pp
450 -Show the location of the
451 -.Xr ls 1
452 -manual page:
453 -.Bd -literal -offset indent
454 -$ man -w ls
455 -.Ed
456 -.Pp
457 -.Sh SEE ALSO
458 -.Xr apropos 1 ,
459 -.Xr intro 1 ,
460 -.Xr mandoc 1 ,
461 -.Xr manpath 1 ,
462 -.Xr whatis 1 ,
463 -.Xr intro 2 ,
464 -.Xr intro 3 ,
465 -.Xr intro 3lua ,
466 -.Xr intro 4 ,
467 -.Xr intro 5 ,
468 -.Xr man.conf 5 ,
469 -.Xr intro 6 ,
470 -.Xr intro 7 ,
471 -.Xr mdoc 7 ,
472 -.Xr intro 8 ,
473 -.Xr intro 9
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
478 +++ /dev/null
479 @@ -1,1032 +0,0 @@
480 -#! /bin/sh
481 -#
482 -# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
483 -#
484 -# Copyright (c) 2010 Gordon Tetlow
485 -# All rights reserved.
486 -#
487 -# Redistribution and use in source and binary forms, with or without
488 -# modification, are permitted provided that the following conditions
489 -# are met:
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.
495 -#
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
506 -# SUCH DAMAGE.
507 -#
508 -# $FreeBSD$
509 -
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.
513 -add_to_manpath() {
514 - case "$manpath" in
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"
521 - return 0
522 - fi
523 - ;;
524 - esac
525 -
526 - return 1
527 -}
528 -
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
534 - return
535 - fi
536 -
537 - parse_configs
538 -
539 - # Trim leading colon
540 - MANLOCALES=${manlocales#:}
541 -
542 - decho "Available manual locales: $MANLOCALES"
543 -}
544 -
545 -# Usage: build_manpath
546 -# Builds a correct MANPATH variable.
547 -build_manpath() {
548 - local IFS
549 -
550 - # If the user has set a manpath, who are we to argue.
551 - if [ -n "$MANPATH" ]; then
552 - case "$MANPATH" in
553 - *:) PREPEND_MANPATH=${MANPATH} ;;
554 - :*) APPEND_MANPATH=${MANPATH} ;;
555 - *::*)
556 - PREPEND_MANPATH=${MANPATH%%::*}
557 - APPEND_MANPATH=${MANPATH#*::}
558 - ;;
559 - *) return ;;
560 - esac
561 - fi
562 -
563 - if [ -n "$PREPEND_MANPATH" ]; then
564 - IFS=:
565 - for path in $PREPEND_MANPATH; do
566 - add_to_manpath "$path"
567 - done
568 - unset IFS
569 - fi
570 -
571 - search_path
572 -
573 - decho "Adding default manpath entries"
574 - IFS=:
575 - for path in $man_default_path; do
576 - add_to_manpath "$path"
577 - done
578 - unset IFS
579 -
580 - parse_configs
581 -
582 - if [ -n "$APPEND_MANPATH" ]; then
583 - IFS=:
584 - for path in $APPEND_MANPATH; do
585 - add_to_manpath "$path"
586 - done
587 - unset IFS
588 - fi
589 - # Trim leading colon
590 - MANPATH=${manpath#:}
591 -
592 - decho "Using manual path: $MANPATH"
593 -}
594 -
595 -# Usage: check_cat catglob
596 -# Checks to see if a cat glob is available.
597 -check_cat() {
598 - if exists "$1"; then
599 - use_cat=yes
600 - catpage=$found
601 - setup_cattool $catpage
602 - decho " Found catpage $catpage"
603 - return 0
604 - else
605 - return 1
606 - fi
607 -}
608 -
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.
612 -check_man() {
613 - if exists "$1"; then
614 - # We have a match, check for a cat page
615 - manpage=$found
616 - setup_cattool $manpage
617 - decho " Found manpage $manpage"
618 -
619 - if [ -n "${use_width}" ]; then
620 - # non-standard width
621 - unset use_cat
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
625 - use_cat=yes
626 - catpage=$found
627 - setup_cattool $catpage
628 - decho " Using catpage $catpage"
629 - else
630 - # no cat page or is older
631 - unset use_cat
632 - decho " Skipping catpage: not found or old"
633 - fi
634 - return 0
635 - fi
636 -
637 - return 1
638 -}
639 -
640 -# Usage: decho "string" [debuglevel]
641 -# Echoes to stderr string prefaced with -- if high enough debuglevel.
642 -decho() {
643 - if [ $debug -ge ${2:-1} ]; then
644 - echo "-- $1" >&2
645 - fi
646 -}
647 -
648 -# Usage: exists glob
649 -# Returns true if glob resolves to a real file.
650 -exists() {
651 - local IFS
652 -
653 - # Don't accidentally inherit callers IFS (breaks perl manpages)
654 - unset IFS
655 -
656 - # Use some globbing tricks in the shell to determine if a file
657 - # exists or not.
658 - set +f
659 - set -- "$1" $1
660 - set -f
661 -
662 - if [ "$1" != "$2" -a -r "$2" ]; then
663 - found="$2"
664 - return 0
665 - fi
666 -
667 - return 1
668 -}
669 -
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.
673 -find_file() {
674 - local manroot catroot mann man0 catn cat0
675 -
676 - manroot="$1/man$2"
677 - catroot="$1/cat$2"
678 - if [ -n "$3" ]; then
679 - manroot="$manroot/$3"
680 - catroot="$catroot/$3"
681 - fi
682 -
683 - if [ ! -d "$manroot" -a ! -d "$catroot" ]; then
684 - return 1
685 - fi
686 - decho " Searching directory $manroot" 2
687 -
688 - mann="$manroot/$4.$2*"
689 - man0="$manroot/$4.0*"
690 - catn="$catroot/$4.$2*"
691 - cat0="$catroot/$4.0*"
692 -
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
696 - return 0
697 - elif check_man "$man0" "$cat0"; then
698 - return 0
699 - elif check_cat "$catn"; then
700 - return 0
701 - elif check_cat "$cat0"; then
702 - return 0
703 - fi
704 -
705 - return 1
706 -}
707 -
708 -# Usage: is_newer file1 file2
709 -# Returns true if file1 is newer than file2 as calculated by mtime.
710 -is_newer() {
711 - if ! [ "$1" -ot "$2" ]; then
712 - decho " mtime: $1 not older than $2" 3
713 - return 0
714 - else
715 - decho " mtime: $1 older than $2" 3
716 - return 1
717 - fi
718 -}
719 -
720 -# Usage: manpath_parse_args "$@"
721 -# Parses commandline options for manpath.
722 -manpath_parse_args() {
723 - local cmd_arg
724 -
725 - while getopts 'Ldq' cmd_arg; do
726 - case "${cmd_arg}" in
727 - L) Lflag=Lflag ;;
728 - d) debug=$(( $debug + 1 )) ;;
729 - q) qflag=qflag ;;
730 - *) manpath_usage ;;
731 - esac
732 - done >&2
733 -}
734 -
735 -# Usage: manpath_usage
736 -# Display usage for the manpath(1) utility.
737 -manpath_usage() {
738 - echo 'usage: manpath [-Ldq]' >&2
739 - exit 1
740 -}
741 -
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
747 - fi
748 -}
749 -
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
756 -
757 - unset IFS
758 - if [ -n "$catpage" ]; then
759 - return 0
760 - fi
761 -
762 - # We need to loop to accommodate multiple .so directives.
763 - while true
764 - do
765 - line=$($cattool $manpage | head -1)
766 - case "$line" in
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"
772 - return 1
773 - fi
774 - ;;
775 - *) break ;;
776 - esac
777 - done
778 -
779 - return 0
780 -}
781 -
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
786 -
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.
789 - unset IFS
790 -
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)"
796 - ret=0
797 - else
798 - if [ $debug -gt 0 ]; then
799 - decho "Command: $cattool $catpage | $MANPAGER"
800 - ret=0
801 - else
802 - eval "$cattool $catpage | $MANPAGER"
803 - ret=$?
804 - fi
805 - fi
806 - return
807 - fi
808 -
809 - # Okay, we are using the manpage, do we just need to output the
810 - # name of the manpage?
811 - if [ -n "$wflag" ]; then
812 - echo "$manpage"
813 - ret=0
814 - return
815 - fi
816 -
817 - if [ -n "$use_width" ]; then
818 - mandoc_args="-O width=${use_width}"
819 - fi
820 - testline="mandoc -Tlint -Wunsupp >/dev/null 2>&1"
821 - if [ -n "$tflag" ]; then
822 - pipeline="mandoc -Tps $mandoc_args"
823 - else
824 - pipeline="mandoc $mandoc_args | $MANPAGER"
825 - fi
826 -
827 - if ! eval "$cattool $manpage | $testline" ;then
828 - if which -s groff; then
829 - man_display_page_groff
830 - else
831 - echo "This manpage needs groff(1) to be rendered" >&2
832 - echo "First install groff(1): " >&2
833 - echo "pkg install groff " >&2
834 - ret=1
835 - fi
836 - return
837 - fi
838 -
839 - if [ $debug -gt 0 ]; then
840 - decho "Command: $cattool $manpage | $pipeline"
841 - ret=0
842 - else
843 - eval "$cattool $manpage | $pipeline"
844 - ret=$?
845 - fi
846 -}
847 -
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
853 -
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.
857 -
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" ;;
870 - esac
871 -
872 - NROFF="$NROFF -T$nroff_dev"
873 - EQN="$EQN -T$nroff_dev"
874 -
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"
880 - ;;
881 - */${man_lang}.${man_charset}/*)
882 - NROFF="$NROFF -dlocale=$man_lang.$man_charset"
883 - ;;
884 - esac
885 -
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}"
891 - done
892 - ;;
893 - *) NROFF="$NROFF -Tascii"
894 - EQN="$EQN -Tascii"
895 - ;;
896 - esac
897 -
898 - if [ -z "$MANCOLOR" ]; then
899 - NROFF="$NROFF -P-c"
900 - fi
901 -
902 - if [ -n "${use_width}" ]; then
903 - NROFF="$NROFF -rLL=${use_width}n -rLT=${use_width}n"
904 - fi
905 -
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" ;;
916 - *) usage ;;
917 - esac
918 - done
919 - # Strip the leading " | " from the resulting pipeline.
920 - pipeline="${pipeline#" | "}"
921 - else
922 - pipeline="$TBL"
923 - fi
924 -
925 - if [ -n "$tflag" ]; then
926 - pipeline="$pipeline | $TROFF"
927 - else
928 - pipeline="$pipeline | $NROFF | $MANPAGER"
929 - fi
930 -
931 - if [ $debug -gt 0 ]; then
932 - decho "Command: $cattool $manpage | $pipeline"
933 - ret=0
934 - else
935 - eval "$cattool $manpage | $pipeline"
936 - ret=$?
937 - fi
938 -}
939 -
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
944 -
945 - # Check to see if it's a file. But only if it has a '/' in
946 - # the filename.
947 - case "$1" in
948 - */*) if [ -f "$1" -a -r "$1" ]; then
949 - decho "Found a usable page, displaying that"
950 - unset use_cat
951 - manpage="$1"
952 - setup_cattool $manpage
953 - if man_check_for_so $manpage $(dirname $manpage); then
954 - found_page=yes
955 - man_display_page
956 - fi
957 - return
958 - fi
959 - ;;
960 - esac
961 -
962 - IFS=:
963 - for sect in $MANSECT; do
964 - decho "Searching section $sect" 2
965 - for path in $MANPATH; do
966 - for locpath in $locpaths; do
967 - p=$path/$locpath
968 - p=${p%/.} # Rid ourselves of the trailing /.
969 -
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
973 - found_page=yes
974 - man_display_page
975 - if [ -n "$aflag" ]; then
976 - continue 2
977 - else
978 - return
979 - fi
980 - fi
981 - fi
982 -
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
987 - found_page=yes
988 - man_display_page
989 - if [ -n "$aflag" ]; then
990 - continue 2
991 - else
992 - return
993 - fi
994 - fi
995 - fi
996 -
997 - # Check plain old manpath.
998 - if find_file $p $sect '' "$1"; then
999 - if man_check_for_so $manpage $p; then
1000 - found_page=yes
1001 - man_display_page
1002 - if [ -n "$aflag" ]; then
1003 - continue 2
1004 - else
1005 - return
1006 - fi
1007 - fi
1008 - fi
1009 - done
1010 - done
1011 - done
1012 - unset IFS
1013 -
1014 - # Nothing? Well, we are done then.
1015 - if [ -z "$found_page" ]; then
1016 - echo "No manual entry for $1" >&2
1017 - ret=1
1018 - return
1019 - fi
1020 -}
1021 -
1022 -# Usage: man_parse_args "$@"
1023 -# Parses commandline options for man.
1024 -man_parse_args() {
1025 - local IFS cmd_arg
1026 -
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 ;;
1032 - a) aflag=aflag ;;
1033 - d) debug=$(( $debug + 1 )) ;;
1034 - f) fflag=fflag ;;
1035 - h) man_usage 0 ;;
1036 - k) kflag=kflag ;;
1037 - m) mflag=$OPTARG ;;
1038 - o) oflag=oflag ;;
1039 - p) MANROFFSEQ=$OPTARG ;;
1040 - t) tflag=tflag ;;
1041 - w) wflag=wflag ;;
1042 - *) man_usage ;;
1043 - esac
1044 - done >&2
1045 -
1046 - shift $(( $OPTIND - 1 ))
1047 -
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 ;;
1056 - esac
1057 -
1058 - # Short circuit for whatis(1) and apropos(1)
1059 - if [ -n "$fflag" ]; then
1060 - do_whatis "$@"
1061 - exit
1062 - fi
1063 -
1064 - if [ -n "$kflag" ]; then
1065 - do_apropos "$@"
1066 - exit
1067 - fi
1068 -
1069 - IFS=:
1070 - for sect in $man_default_sections; do
1071 - if [ "$sect" = "$1" ]; then
1072 - decho "Detected manual section as first arg: $1"
1073 - MANSECT="$1"
1074 - shift
1075 - break
1076 - fi
1077 - done
1078 - unset IFS
1079 -
1080 - pages="$*"
1081 -}
1082 -
1083 -# Usage: man_setup
1084 -# Setup various trivial but essential variables.
1085 -man_setup() {
1086 - # Setup machine and architecture variables.
1087 - if [ -n "$mflag" ]; then
1088 - MACHINE_ARCH=${mflag%%:*}
1089 - MACHINE=${mflag##*:}
1090 - fi
1091 - if [ -z "$MACHINE_ARCH" ]; then
1092 - MACHINE_ARCH=$($SYSCTL -n hw.machine_arch)
1093 - fi
1094 - if [ -z "$MACHINE" ]; then
1095 - MACHINE=$($SYSCTL -n hw.machine)
1096 - fi
1097 - decho "Using architecture: $MACHINE_ARCH:$MACHINE"
1098 -
1099 - setup_pager
1100 -
1101 - # Setup manual sections to search.
1102 - if [ -z "$MANSECT" ]; then
1103 - MANSECT=$man_default_sections
1104 - fi
1105 - decho "Using manual sections: $MANSECT"
1106 -
1107 - build_manpath
1108 - man_setup_locale
1109 - man_setup_width
1110 -}
1111 -
1112 -# Usage: man_setup_width
1113 -# Set up page width.
1114 -man_setup_width() {
1115 - local sizes
1116 -
1117 - unset use_width
1118 - case "$MANWIDTH" in
1119 - [0-9]*)
1120 - if [ "$MANWIDTH" -gt 0 2>/dev/null ]; then
1121 - use_width=$MANWIDTH
1122 - fi
1123 - ;;
1124 - [Tt][Tt][Yy])
1125 - if { sizes=$($STTY size 0>&3 2>/dev/null); } 3>&1; then
1126 - set -- $sizes
1127 - if [ $2 -gt 80 ]; then
1128 - use_width=$(($2-2))
1129 - fi
1130 - fi
1131 - ;;
1132 - esac
1133 - if [ -n "$use_width" ]; then
1134 - decho "Using non-standard page width: ${use_width}"
1135 - else
1136 - decho 'Using standard page width'
1137 - fi
1138 -}
1139 -
1140 -# Usage: man_setup_locale
1141 -# Setup necessary locale variables.
1142 -man_setup_locale() {
1143 - local lang_cc
1144 - local locstr
1145 -
1146 - locpaths='.'
1147 - man_charset='US-ASCII'
1148 -
1149 - # Setup locale information.
1150 - if [ -n "$oflag" ]; then
1151 - decho 'Using non-localized manpages'
1152 - else
1153 - # Use the locale tool to give us proper locale information
1154 - eval $( $LOCALE )
1155 -
1156 - if [ -n "$LANG" ]; then
1157 - locstr=$LANG
1158 - else
1159 - locstr=$LC_CTYPE
1160 - fi
1161 -
1162 - case "$locstr" in
1163 - C) ;;
1164 - C.UTF-8) ;;
1165 - POSIX) ;;
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"
1175 - fi
1176 - locpaths="$locpaths:."
1177 - ;;
1178 - *) echo 'Unknown locale, assuming C' >&2
1179 - ;;
1180 - esac
1181 - fi
1182 -
1183 - decho "Using locale paths: $locpaths"
1184 -}
1185 -
1186 -# Usage: man_usage [exitcode]
1187 -# Display usage for the man utility.
1188 -man_usage() {
1189 - echo 'Usage:'
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)'
1194 -
1195 - # When exit'ing with -h, it's not an error.
1196 - exit ${1:-1}
1197 -}
1198 -
1199 -# Usage: parse_configs
1200 -# Reads the end-user adjustable config files.
1201 -parse_configs() {
1202 - local IFS file files
1203 -
1204 - if [ -n "$parsed_configs" ]; then
1205 - return
1206 - fi
1207 -
1208 - unset IFS
1209 -
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"
1214 - fi
1215 -
1216 - # Glob the list of files to parse.
1217 - set +f
1218 - files=$(echo $config_local)
1219 - set -f
1220 -
1221 - for file in $files; do
1222 - if [ -r "$file" ]; then
1223 - parse_file "$file"
1224 - fi
1225 - done
1226 -
1227 - parsed_configs='yes'
1228 -}
1229 -
1230 -# Usage: parse_file file
1231 -# Reads the specified config files.
1232 -parse_file() {
1233 - local file line tstr var
1234 -
1235 - file="$1"
1236 - decho "Parsing config file: $file"
1237 - while read line; do
1238 - decho " $line" 2
1239 - case "$line" in
1240 - \#*) decho " Comment" 3
1241 - ;;
1242 - MANPATH*) decho " MANPATH" 3
1243 - trim "${line#MANPATH}"
1244 - add_to_manpath "$tstr"
1245 - ;;
1246 - MANLOCALE*) decho " MANLOCALE" 3
1247 - trim "${line#MANLOCALE}"
1248 - manlocales="$manlocales:$tstr"
1249 - ;;
1250 - MANCONFIG*) decho " MANCONFIG" 3
1251 - trim "${line#MANCONFIG}"
1252 - config_local="$tstr"
1253 - ;;
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
1259 - ;;
1260 - esac
1261 - done < "$file"
1262 -}
1263 -
1264 -# Usage: search_path
1265 -# Traverse $PATH looking for manpaths.
1266 -search_path() {
1267 - local IFS p path
1268 -
1269 - decho "Searching PATH for man directories"
1270 -
1271 - IFS=:
1272 - for path in $PATH; do
1273 - if add_to_manpath "$path/man"; then
1274 - :
1275 - elif add_to_manpath "$path/MAN"; then
1276 - :
1277 - else
1278 - case "$path" in
1279 - */bin) p="${path%/bin}/share/man"
1280 - add_to_manpath "$p"
1281 - p="${path%/bin}/man"
1282 - add_to_manpath "$p"
1283 - ;;
1284 - esac
1285 - fi
1286 - done
1287 - unset IFS
1288 -
1289 - if [ -z "$manpath" ]; then
1290 - decho ' Unable to find any manpaths, using default'
1291 - manpath=$man_default_path
1292 - fi
1293 -}
1294 -
1295 -# Usage: search_whatis cmd [arglist]
1296 -# Do the heavy lifting for apropos/whatis
1297 -search_whatis() {
1298 - local IFS bad cmd f good key keywords loc opt out path rval wlist
1299 -
1300 - cmd="$1"
1301 - shift
1302 -
1303 - whatis_parse_args "$@"
1304 -
1305 - build_manpath
1306 - build_manlocales
1307 - setup_pager
1308 -
1309 - if [ "$cmd" = "whatis" ]; then
1310 - opt="-w"
1311 - fi
1312 -
1313 - f='whatis'
1314 -
1315 - IFS=:
1316 - for path in $MANPATH; do
1317 - if [ \! -d "$path" ]; then
1318 - decho "Skipping non-existent path: $path" 2
1319 - continue
1320 - fi
1321 -
1322 - if [ -f "$path/$f" -a -r "$path/$f" ]; then
1323 - decho "Found whatis: $path/$f"
1324 - wlist="$wlist $path/$f"
1325 - fi
1326 -
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"
1331 - fi
1332 - done
1333 - done
1334 - unset IFS
1335 -
1336 - if [ -z "$wlist" ]; then
1337 - echo "$cmd: no whatis databases in $MANPATH" >&2
1338 - exit 1
1339 - fi
1340 -
1341 - rval=0
1342 - for key in $keywords; do
1343 - out=$(grep -Ehi $opt -- "$key" $wlist)
1344 - if [ -n "$out" ]; then
1345 - good="$good\\n$out"
1346 - else
1347 - bad="$bad\\n$key: nothing appropriate"
1348 - rval=1
1349 - fi
1350 - done
1351 -
1352 - # Strip leading carriage return.
1353 - good=${good#\\n}
1354 - bad=${bad#\\n}
1355 -
1356 - if [ -n "$good" ]; then
1357 - echo -e "$good" | $MANPAGER
1358 - fi
1359 -
1360 - if [ -n "$bad" ]; then
1361 - echo -e "$bad" >&2
1362 - fi
1363 -
1364 - exit $rval
1365 -}
1366 -
1367 -# Usage: setup_cattool page
1368 -# Finds an appropriate decompressor based on extension
1369 -setup_cattool() {
1370 - case "$1" in
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' ;;
1377 - esac
1378 -}
1379 -
1380 -# Usage: setup_pager
1381 -# Correctly sets $MANPAGER
1382 -setup_pager() {
1383 - # Setup pager.
1384 - if [ -z "$MANPAGER" ]; then
1385 - if [ -n "$MANCOLOR" ]; then
1386 - MANPAGER="less -sR"
1387 - else
1388 - if [ -n "$PAGER" ]; then
1389 - MANPAGER="$PAGER"
1390 - else
1391 - MANPAGER="less -s"
1392 - fi
1393 - fi
1394 - fi
1395 - decho "Using pager: $MANPAGER"
1396 -}
1397 -
1398 -# Usage: trim string
1399 -# Trims whitespace from beginning and end of a variable
1400 -trim() {
1401 - tstr=$1
1402 - while true; do
1403 - case "$tstr" in
1404 - [\ \ ]*) tstr="${tstr##[\ \ ]}" ;;
1405 - *[\ \ ]) tstr="${tstr%%[\ \ ]}" ;;
1406 - *) break ;;
1407 - esac
1408 - done
1409 -}
1410 -
1411 -# Usage: whatis_parse_args "$@"
1412 -# Parse commandline args for whatis and apropos.
1413 -whatis_parse_args() {
1414 - local cmd_arg
1415 - while getopts 'd' cmd_arg; do
1416 - case "${cmd_arg}" in
1417 - d) debug=$(( $debug + 1 )) ;;
1418 - *) whatis_usage ;;
1419 - esac
1420 - done >&2
1421 -
1422 - shift $(( $OPTIND - 1 ))
1423 -
1424 - keywords="$*"
1425 -}
1426 -
1427 -# Usage: whatis_usage
1428 -# Display usage for the whatis/apropos utility.
1429 -whatis_usage() {
1430 - echo "usage: $cmd [-d] keyword [...]"
1431 - exit 1
1432 -}
1433 -
1434 -
1435 -
1436 -# Supported commands
1437 -do_apropos() {
1438 - [ $(stat -f %i /usr/bin/man) -ne $(stat -f %i /usr/bin/apropos) ] && \
1439 - exec apropos "$@"
1440 - search_whatis apropos "$@"
1441 -}
1442 -
1443 -do_man() {
1444 - man_parse_args "$@"
1445 - if [ -z "$pages" ]; then
1446 - echo 'What manual page do you want?' >&2
1447 - exit 1
1448 - fi
1449 - man_setup
1450 -
1451 - for page in $pages; do
1452 - decho "Searching for $page"
1453 - man_find_and_display "$page"
1454 - done
1455 -
1456 - exit ${ret:-0}
1457 -}
1458 -
1459 -do_manpath() {
1460 - manpath_parse_args "$@"
1461 - if [ -z "$qflag" ]; then
1462 - manpath_warnings
1463 - fi
1464 - if [ -n "$Lflag" ]; then
1465 - build_manlocales
1466 - echo $MANLOCALES
1467 - else
1468 - build_manpath
1469 - echo $MANPATH
1470 - fi
1471 - exit 0
1472 -}
1473 -
1474 -do_whatis() {
1475 - [ $(stat -f %i /usr/bin/man) -ne $(stat -f %i /usr/bin/whatis) ] && \
1476 - exec whatis "$@"
1477 - search_whatis whatis "$@"
1478 -}
1479 -
1480 -# User's PATH setting decides on the groff-suite to pick up.
1481 -EQN=eqn
1482 -NROFF='groff -S -P-h -Wall -mtty-char -man'
1483 -PIC=pic
1484 -REFER=refer
1485 -TBL=tbl
1486 -TROFF='groff -S -man'
1487 -VGRIND=vgrind
1488 -
1489 -LOCALE=/usr/bin/locale
1490 -STTY=/bin/stty
1491 -SYSCTL=/sbin/sysctl
1492 -
1493 -debug=0
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'
1497 -
1498 -config_global='/etc/man.conf'
1499 -
1500 -# This can be overridden via a setting in /etc/man.conf.
1501 -config_local='/usr/local/etc/man.d/*.conf'
1502 -
1503 -# Set noglobbing for now. I don't want spurious globbing.
1504 -set -f
1505 -
1506 -case "$0" in
1507 -*apropos) do_apropos "$@" ;;
1508 -*manpath) do_manpath "$@" ;;
1509 -*whatis) do_whatis "$@" ;;
1510 -*) do_man "$@" ;;
1511 -esac
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
1520 +MAN+= man.1
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"
1529 .endif
1530 diff --git a/usr.bin/manpath/Makefile b/usr.bin/manpath/Makefile
1531 new file mode 100644
1532 index 00000000000..20a05f68a62
1533 --- /dev/null
1534 +++ b/usr.bin/manpath/Makefile
1535 @@ -0,0 +1,7 @@
1536 +# $FreeBSD$
1537 +
1538 +SCRIPTS= manpath.sh
1539 +
1540 +MAN= manpath.1 man.conf.5
1541 +
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
1558 --- /dev/null
1559 +++ b/usr.bin/manpath/manpath.sh
1560 @@ -0,0 +1,289 @@
1561 +#! /bin/sh
1562 +#
1563 +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
1564 +#
1565 +# Copyright (c) 2010 Gordon Tetlow
1566 +# All rights reserved.
1567 +#
1568 +# Redistribution and use in source and binary forms, with or without
1569 +# modification, are permitted provided that the following conditions
1570 +# are met:
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.
1576 +#
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
1587 +# SUCH DAMAGE.
1588 +#
1589 +# $FreeBSD$
1590 +
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.
1594 +add_to_manpath() {
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"
1602 + return 0
1603 + fi
1604 + ;;
1605 + esac
1606 +
1607 + return 1
1608 +}
1609 +
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
1615 + return
1616 + fi
1617 +
1618 + parse_configs
1619 +
1620 + # Trim leading colon
1621 + MANLOCALES=${manlocales#:}
1622 +
1623 + decho "Available manual locales: $MANLOCALES"
1624 +}
1625 +
1626 +# Usage: build_manpath
1627 +# Builds a correct MANPATH variable.
1628 +build_manpath() {
1629 + local IFS
1630 +
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} ;;
1636 + *::*)
1637 + PREPEND_MANPATH=${MANPATH%%::*}
1638 + APPEND_MANPATH=${MANPATH#*::}
1639 + ;;
1640 + *) return ;;
1641 + esac
1642 + fi
1643 +
1644 + if [ -n "$PREPEND_MANPATH" ]; then
1645 + IFS=:
1646 + for path in $PREPEND_MANPATH; do
1647 + add_to_manpath "$path"
1648 + done
1649 + unset IFS
1650 + fi
1651 +
1652 + search_path
1653 +
1654 + decho "Adding default manpath entries"
1655 + IFS=:
1656 + for path in $man_default_path; do
1657 + add_to_manpath "$path"
1658 + done
1659 + unset IFS
1660 +
1661 + parse_configs
1662 +
1663 + if [ -n "$APPEND_MANPATH" ]; then
1664 + IFS=:
1665 + for path in $APPEND_MANPATH; do
1666 + add_to_manpath "$path"
1667 + done
1668 + unset IFS
1669 + fi
1670 + # Trim leading colon
1671 + MANPATH=${manpath#:}
1672 +
1673 + decho "Using manual path: $MANPATH"
1674 +}
1675 +
1676 +# Usage: decho "string" [debuglevel]
1677 +# Echoes to stderr string prefaced with -- if high enough debuglevel.
1678 +decho() {
1679 + if [ $debug -ge ${2:-1} ]; then
1680 + echo "-- $1" >&2
1681 + fi
1682 +}
1683 +
1684 +# Usage: manpath_parse_args "$@"
1685 +# Parses commandline options for manpath.
1686 +manpath_parse_args() {
1687 + local cmd_arg
1688 +
1689 + while getopts 'Ldq' cmd_arg; do
1690 + case "${cmd_arg}" in
1691 + L) Lflag=Lflag ;;
1692 + d) debug=$(( $debug + 1 )) ;;
1693 + q) qflag=qflag ;;
1694 + *) manpath_usage ;;
1695 + esac
1696 + done >&2
1697 +}
1698 +
1699 +# Usage: manpath_usage
1700 +# Display usage for the manpath(1) utility.
1701 +manpath_usage() {
1702 + echo 'usage: manpath [-Ldq]' >&2
1703 + exit 1
1704 +}
1705 +
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
1711 + fi
1712 +}
1713 +
1714 +# Usage: parse_configs
1715 +# Reads the end-user adjustable config files.
1716 +parse_configs() {
1717 + local IFS file files
1718 +
1719 + if [ -n "$parsed_configs" ]; then
1720 + return
1721 + fi
1722 +
1723 + unset IFS
1724 +
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"
1729 + fi
1730 +
1731 + # Glob the list of files to parse.
1732 + set +f
1733 + files=$(echo $config_local)
1734 + set -f
1735 +
1736 + for file in $files; do
1737 + if [ -r "$file" ]; then
1738 + parse_file "$file"
1739 + fi
1740 + done
1741 +
1742 + parsed_configs='yes'
1743 +}
1744 +
1745 +# Usage: parse_file file
1746 +# Reads the specified config files.
1747 +parse_file() {
1748 + local file line tstr var
1749 +
1750 + file="$1"
1751 + decho "Parsing config file: $file"
1752 + while read line; do
1753 + decho " $line" 2
1754 + case "$line" in
1755 + \#*) decho " Comment" 3
1756 + ;;
1757 + MANPATH*) decho " MANPATH" 3
1758 + trim "${line#MANPATH}"
1759 + add_to_manpath "$tstr"
1760 + ;;
1761 + MANLOCALE*) decho " MANLOCALE" 3
1762 + trim "${line#MANLOCALE}"
1763 + manlocales="$manlocales:$tstr"
1764 + ;;
1765 + MANCONFIG*) decho " MANCONFIG" 3
1766 + trim "${line#MANCONFIG}"
1767 + config_local="$tstr"
1768 + ;;
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
1774 + ;;
1775 + esac
1776 + done < "$file"
1777 +}
1778 +
1779 +# Usage: search_path
1780 +# Traverse $PATH looking for manpaths.
1781 +search_path() {
1782 + local IFS p path
1783 +
1784 + decho "Searching PATH for man directories"
1785 +
1786 + IFS=:
1787 + for path in $PATH; do
1788 + if add_to_manpath "$path/man"; then
1789 + :
1790 + elif add_to_manpath "$path/MAN"; then
1791 + :
1792 + else
1793 + case "$path" in
1794 + */bin) p="${path%/bin}/share/man"
1795 + add_to_manpath "$p"
1796 + p="${path%/bin}/man"
1797 + add_to_manpath "$p"
1798 + ;;
1799 + esac
1800 + fi
1801 + done
1802 + unset IFS
1803 +
1804 + if [ -z "$manpath" ]; then
1805 + decho ' Unable to find any manpaths, using default'
1806 + manpath=$man_default_path
1807 + fi
1808 +}
1809 +
1810 +# Usage: trim string
1811 +# Trims whitespace from beginning and end of a variable
1812 +trim() {
1813 + tstr=$1
1814 + while true; do
1815 + case "$tstr" in
1816 + [\ \ ]*) tstr="${tstr##[\ \ ]}" ;;
1817 + *[\ \ ]) tstr="${tstr%%[\ \ ]}" ;;
1818 + *) break ;;
1819 + esac
1820 + done
1821 +}
1822 +
1823 +do_manpath() {
1824 + manpath_parse_args "$@"
1825 + if [ -z "$qflag" ]; then
1826 + manpath_warnings
1827 + fi
1828 + if [ -n "$Lflag" ]; then
1829 + build_manlocales
1830 + echo $MANLOCALES
1831 + else
1832 + build_manpath
1833 + echo $MANPATH
1834 + fi
1835 + exit 0
1836 +}
1837 +
1838 +debug=0
1839 +man_default_path='/usr/share/man:/usr/share/openssl/man:/usr/local/share/man:/usr/local/man'
1840 +
1841 +config_global='/etc/man.conf'
1842 +
1843 +# This can be overridden via a setting in /etc/man.conf.
1844 +config_local='/usr/local/etc/man.d/*.conf'
1845 +
1846 +# Set noglobbing for now. I don't want spurious globbing.
1847 +set -f
1848 +
1849 +do_manpath "$@"
1850 --
1851 2.32.0
1852