Index: usr.bin/man/man.1 =================================================================== --- usr.bin/man/man.1 +++ usr.bin/man/man.1 @@ -43,6 +43,9 @@ .Op Ar mansect .Ar page ... .Nm +.Fl K +.Ar regexp ... +.Nm .Fl f .Ar keyword ... .Nm @@ -93,6 +96,14 @@ .Nm understands: .Bl -tag -width indent +.It Fl K Ar regexp +Does a full text search in all manual pages. +.Ar regexp +is a regular expression as understood by +.Xr egrep 1 . +This option requires +.Xr mandoc 1 . +This is a slow operation. .It Fl M Ar manpath Forces a specific colon separated manual path instead of the default search path. @@ -392,8 +403,14 @@ $ man -w ls .Ed .Pp +Show the location of manual pages in sections 1 and 8 which contain the word +.Ql arm : +.Bd -literal -offset indent +$ ./man -w -K '\e' -S 1:8 +.Ed .Sh SEE ALSO .Xr apropos 1 , +.Xr egrep 1 , .Xr intro 1 , .Xr mandoc 1 , .Xr manpath 1 , Index: usr.bin/man/man.sh =================================================================== --- usr.bin/man/man.sh +++ usr.bin/man/man.sh @@ -545,8 +545,10 @@ man_parse_args() { local IFS cmd_arg - while getopts 'M:P:S:adfhkm:op:tw' cmd_arg; do + while getopts 'K:M:P:S:adfhkm:op:tw' cmd_arg; do case "${cmd_arg}" in + K) Kflag=Kflag + REGEXP=$OPTARG ;; M) MANPATH=$OPTARG ;; P) MANPAGER=$OPTARG ;; S) MANSECT=$OPTARG ;; @@ -567,7 +569,11 @@ shift $(( $OPTIND - 1 )) # Check the args for incompatible options. - case "${fflag}${kflag}${tflag}${wflag}" in + + case "${Kflag}${fflag}${kflag}${tflag}${wflag}" in + Kflagfflag*) echo "Incompatible options: -K and -f"; man_usage ;; + Kflag*kflag*) echo "Incompatible options: -K and -k"; man_usage ;; + Kflag*tflag) echo "Incompatible options: -K and -t"; man_usage ;; fflagkflag*) echo "Incompatible options: -f and -k"; man_usage ;; fflag*tflag*) echo "Incompatible options: -f and -t"; man_usage ;; fflag*wflag) echo "Incompatible options: -f and -w"; man_usage ;; @@ -708,7 +714,7 @@ # Display usage for the man utility. man_usage() { echo 'Usage:' - echo ' man [-adho] [-t | -w] [-M manpath] [-P pager] [-S mansect]' + echo ' man [-adho] [-t | -w] [-K regexp] [-M manpath] [-P pager] [-S mansect]' echo ' [-m arch[:machine]] [-p [eprtv]] [mansect] page [...]' echo ' man -f page [...] -- Emulates whatis(1)' echo ' man -k page [...] -- Emulates apropos(1)' @@ -961,14 +967,49 @@ search_whatis apropos "$@" } +# Usage: do_full_search reg_exp +# Do a full search of the regular expression passed +# as parameter in all man pages +do_full_search() { + local gflags re + re=${1} + + # Build egrep(1) flags + gflags="-H" + + # wflag implies -l for egrep(1) + if [ -n "$wflag" ]; then + gflags="${gflags} -l" + fi + + gflags="${gflags} --label" + + set +f + for mpath in $(echo "${MANPATH}" | tr : [:blank:]); do + for section in $(echo "${MANSECT}" | tr : [:blank:]); do + for manfile in ${mpath}/man${section}/*.${section}*; do + mandoc "${manfile}" 2>/dev/null | + egrep ${gflags} "${manfile}" -e ${re} + done + done + done + set -f +} + do_man() { man_parse_args "$@" - if [ -z "$pages" ]; then + if [ -z "$pages" -a -z "${Kflag}" ]; then echo 'What manual page do you want?' >&2 exit 1 fi man_setup + if [ ! -z "${Kflag}" ]; then + # Short circuit because -K flag does a sufficiently + # different thing like not showing the man page at all + do_full_search "${REGEXP}" + fi + for page in $pages; do decho "Searching for $page" man_find_and_display "$page"