From nobody Wed Jan 26 11:28:02 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 713CB19828DD; Wed, 26 Jan 2022 11:28:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JkM0L2ZBsz3k73; Wed, 26 Jan 2022 11:28:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643196482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Mhl7r9svp5rMHr7/Kt+ZG9geE48+W3AdzWz61dROF78=; b=yMfmWsUjHo6fgdmHMzUrYtuaAmVdyalUFp7vl4fsAsTVY0GQNsYCVA1RsYUGGZ7xyammw1 XCNsABWXD3Ch+fhElmLobyFlqzKr9gBaMqAs5YWcvR0qrgl/lEIwXG1u8XOkFL3X5xay9Y 1yc8XoSIBrTKpGC/D0RKpn9hgl7vMqFepoNaEfvsyNdavvSskZZFko8IZSQn+MWkRVQ1S8 wt3vywzTFR/tBgJKkkxzlkJ1zM5F3Ggv4czzTN9WY+Wp4IfLzGZsOA500BsOVIogCDXY9M Aoh/2/W+7a7rYqSjVjQDRJP4al9REpg9XFWVxBOtQEnX0xDlvI/iFP1yPEZXEQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 397D41C822; Wed, 26 Jan 2022 11:28:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20QBS2XG070037; Wed, 26 Jan 2022 11:28:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20QBS2UX070036; Wed, 26 Jan 2022 11:28:02 GMT (envelope-from git) Date: Wed, 26 Jan 2022 11:28:02 GMT Message-Id: <202201261128.20QBS2UX070036@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Fernando Apestegu=C3=ADa?= Subject: git: 1594084f3fa8 - main - man(1): Add full search (-K) flag List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fernape X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1594084f3fa8daf95c0d8cdbd6487939506e268a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643196482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Mhl7r9svp5rMHr7/Kt+ZG9geE48+W3AdzWz61dROF78=; b=rpVmsfst4yqcaHjFqRMWIYSLJuvu5KGA71+o20e2tCOJkZBSyjT7AR1AWu9Vvg+cH3BH2s wPvWuz5reK5BHd5z6fCUQ6oxI0pfcGoYVZjUYFVBatpyvnJWJT58/HzShz5AfXqKRihWxu jWPZVPT7Em6NdRP7YoI8k1a8XHv2X6rzwSCpzeARHtEep092aFEuf8kT27b2y9XXoxcdQI Gz/HJQUjUg5Q+CT4n6gGKYgRf5MjAuaoD/J/kE1nhlyQgFSyTHblIsMuC+WzI+TYqTa9xA Tq4hroeT854MDKr4lxV3vi9OPkdoUDANaPKmhB/Cd4Shn7D0Ftmx033Fgferag== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643196482; a=rsa-sha256; cv=none; b=A039Bl/dzm6xQ345uPbES/5y/RpglTYufksrXF36FphhesE82DstLqUs0GfH0b4WbLQKTJ fqjvlR9I7dbWCH31GuS1anWuKUjNaAXeqywd0bQ4AX8EjOf5W063tZmbH/UOcHsnHs5TrB awnN7NsueLu6s8YtxZjjjkU+ghZIgwAedFv8MxXarwK552U/uDRI5HV/2NmB9NKc2cSWH4 +yAs6YM41wrpFMCrZXKWn4F0Kqa7fbIOnSYP5VfZWoSoriQbRjkVAUyMtVCbKW8UGIWGv6 srcg/1ZuUoZEQjPVvHjh3Z2XIgF0+sOZX+WdrWVHqQiSnzMHf4P5YJPtTkCPmw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by fernape (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=1594084f3fa8daf95c0d8cdbd6487939506e268a commit 1594084f3fa8daf95c0d8cdbd6487939506e268a Author: Fernando ApesteguĂ­a AuthorDate: 2022-01-25 12:12:27 +0000 Commit: Fernando ApesteguĂ­a CommitDate: 2022-01-26 11:24:20 +0000 man(1): Add full search (-K) flag This flag allows a full text search on man pages. Although this is a last resort option, it can be useful to pin point a certain man page. It can be used with -S to narrow the search. Unlike the Linux version, the search takes place in the rendered text so it avoids false-positives when the text is found in comments in the source files. It relies on `grep(1)` and `mandoc(1)` to do its job. Add flag documentation and EXAMPLES to the manual page (bump .Dd). Usage example: man -w -K '\' -S 1:8 Reviewed By: ceri, emaste, pauamma_gundo.com Approved by: manpages (bcr@), debdrup@ Differential Revision: https://reviews.freebsd.org/D30984 --- usr.bin/man/man.1 | 19 ++++++++++++++++++- usr.bin/man/man.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/usr.bin/man/man.1 b/usr.bin/man/man.1 index 42fd60a86164..9a611eff3005 100644 --- a/usr.bin/man/man.1 +++ b/usr.bin/man/man.1 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 9, 2021 +.Dd January 26, 2022 .Dt MAN 1 .Os .Sh NAME @@ -43,6 +43,9 @@ .Op Ar mansect .Ar page ... .Nm +.Fl K +.Ar regexp ... +.Nm .Fl f .Ar keyword ... .Nm @@ -93,6 +96,14 @@ Options that .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 +.Dq Li "grep -E" . +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 @@ manual page: $ 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 , diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh index 084f4a06829b..2c2f1bf648de 100755 --- a/usr.bin/man/man.sh +++ b/usr.bin/man/man.sh @@ -548,8 +548,10 @@ man_parse_args() { local IFS cmd_arg OPTIND=1 - 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 ;; @@ -570,7 +572,11 @@ man_parse_args() { 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 ;; @@ -711,7 +717,7 @@ man_setup_locale() { # 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)' @@ -965,14 +971,49 @@ do_apropos() { 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 grep(1) flags + gflags="-H" + + # wflag implies -l for grep(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 | + grep -E ${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"