From nobody Mon Feb 12 15:49:36 2024 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 4TYTRN2HWZz5B35F; Mon, 12 Feb 2024 15:49:36 +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 4TYTRN1nChz43d2; Mon, 12 Feb 2024 15:49:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707752976; 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=+6zewjqAezCa6FDjOOwh2RPKgxt2ltFBQ7q4KMOUvmw=; b=fmEPO7QKbhAFKoGmX0X7O9WxXpp8Ga/LETYKApx1inT3GXQWgYwWYbtwfwlDkpfoLQjaNH yVsRPgjsx5fcXDkZBqn4EMohKA+/QMjfi/EqOTliDmVlpXzuogjn/WKbYB2hNzdQIATCgh dua0SI/0ZL/voLn0gTZNHkR0voGRJtJ95XgKWuxujW7t5sRLuMs8EmpGDBFVCWIjhf1L+O g4imaLnzdHmZdoZ4gstJkK+grhVTpJ8D0Y6DAqyahm9AoK4GZaf7NIzMEMp/zHm13L+KRU rNLV+sHCp6zHwUBfDwispUJBefn/673IE26Svuw2lgbScguX7EtChOeIJ5lM9w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707752976; a=rsa-sha256; cv=none; b=oJfujimVf+3+Nubh8pYEXcGjcBRfk4XMsSL4kTPhiYa6GSeMilcn78QBrzUO8YxgJWpbBe jSOZa+3DqdIdYu6Xvo/ERKlYNVQw1oeXv8UdNHPxuJLPk1ZQ3HLSLlDeSbwboIFii+DTbL jiDlvpO6VSJcU51pRKE13C5KMRrmnqmFs8aPmSiLYExKkX8vs7Da0F4RYp2IsU1ixkox2Y z6NLnBWJ2pas47MDDcO0k50NFLIg3OkqE7h00j9G+yxergNfeAtwD6I/X+OSvqHmut70EA lzif34UeM7iiU6t3foTNeG1i2jobZu5us2NQinDGCbKRmx+y4vxYCPbIuEiCWw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707752976; 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=+6zewjqAezCa6FDjOOwh2RPKgxt2ltFBQ7q4KMOUvmw=; b=mWpaDWyh142bGfN/B63OP0lsZ1HdI3lwd8cdo18J5SFxwAAD0t7TszjjsSNM6TxJV6qOGg vdklsDFJCIRY0+7SLWELS3983HQDdclBFCLWnpb884DhesFZmAXtNzTKcaIEIaOo7i+i81 CO4la6AZT2gB1Nkjf0v4PCtI6lAEHceyFdVcF+OuYiWZJrorRlzo1YPuk6rtVJOlrnyx0l h9yiaauz/5CPSDrpn7URd43zCocbqMZkNnzph7QUjL16wpIPFy9lS7V4K4XR+a+87Vk25s RB3XsmxTSeMr3LX5clIiH+JNmY+Ktx5C4aza8QFZULgfcQO8HnQkFX3hDhAAzA== 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 4TYTRN0r4PzY2Y; Mon, 12 Feb 2024 15:49:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41CFnaLm010088; Mon, 12 Feb 2024 15:49:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41CFna3d010085; Mon, 12 Feb 2024 15:49:36 GMT (envelope-from git) Date: Mon, 12 Feb 2024 15:49:36 GMT Message-Id: <202402121549.41CFna3d010085@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Wolfram Schneider Subject: git: b8f3f97c5ce2 - stable/13 - man(1): Support custom sections 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: wosch X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b8f3f97c5ce240c156fab0205e0e3938196ed1e2 Auto-Submitted: auto-generated The branch stable/13 has been updated by wosch: URL: https://cgit.FreeBSD.org/src/commit/?id=b8f3f97c5ce240c156fab0205e0e3938196ed1e2 commit b8f3f97c5ce240c156fab0205e0e3938196ed1e2 Author: Wolfram Schneider AuthorDate: 2023-06-27 13:51:24 +0000 Commit: Wolfram Schneider CommitDate: 2024-02-12 15:41:01 +0000 man(1): Support custom sections PR: 271830 Signed-off-by: Mohamed Akram Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/764 (cherry picked from commit 8edb6fb572f29578877fdac3c30f718e589a0360 - needed for further bugfixes) --- usr.bin/man/man.sh | 76 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh index 1d9eb423b707..6ddeb62a3764 100755 --- a/usr.bin/man/man.sh +++ b/usr.bin/man/man.sh @@ -68,6 +68,25 @@ build_manlocales() { decho "Available manual locales: $MANLOCALES" } +# Usage: build_mansect +# Builds a correct MANSECT variable. +build_mansect() { + # If the user has set mansect, who are we to argue. + if [ -n "$MANSECT" ]; then + return + fi + + parse_configs + + # Trim leading colon + MANSECT=${mansect#:} + + if [ -z "$MANSECT" ]; then + MANSECT=$man_default_sections + fi + decho "Using manual sections: $MANSECT" +} + # Usage: build_manpath # Builds a correct MANPATH variable. build_manpath() { @@ -547,10 +566,10 @@ man_find_and_display() { fi } -# Usage: man_parse_args "$@" +# Usage: man_parse_opts "$@" # Parses commandline options for man. -man_parse_args() { - local IFS cmd_arg +man_parse_opts() { + local cmd_arg OPTIND=1 while getopts 'M:P:S:adfhkm:op:tw' cmd_arg; do @@ -594,19 +613,6 @@ man_parse_args() { do_apropos "$@" exit fi - - IFS=: - for sect in $man_default_sections; do - if [ "$sect" = "$1" ]; then - decho "Detected manual section as first arg: $1" - MANSECT="$1" - shift - break - fi - done - unset IFS - - pages="$*" } # Usage: man_setup @@ -626,14 +632,8 @@ man_setup() { decho "Using architecture: $MACHINE_ARCH:$MACHINE" setup_pager - - # Setup manual sections to search. - if [ -z "$MANSECT" ]; then - MANSECT=$man_default_sections - fi - decho "Using manual sections: $MANSECT" - build_manpath + build_mansect man_setup_locale man_setup_width } @@ -780,6 +780,10 @@ parse_file() { trim "${line#MANCONFIG}" config_local="$tstr" ;; + MANSECT*) decho " MANSECT" 3 + trim "${line#MANSECT}" + mansect="$mansect:$tstr" + ;; # Set variables in the form of FOO_BAR *_*[\ \ ]*) var="${line%%[\ \ ]*}" trim "${line#$var}" @@ -972,13 +976,29 @@ do_apropos() { } do_man() { - man_parse_args "$@" - if [ -z "$pages" ]; then - echo 'What manual page do you want?' >&2 - exit 1 - fi + local IFS + + man_parse_opts "$@" man_setup + shift $(( $OPTIND - 1 )) + IFS=: + for sect in $MANSECT; do + if [ "$sect" = "$1" ]; then + decho "Detected manual section as first arg: $1" + MANSECT="$1" + shift + break + fi + done + unset IFS + pages="$*" + + if [ -z "$pages" ]; then + echo 'What manual page do you want?' >&2 + exit 1 + fi + for page in "$pages"; do decho "Searching for \"$page\"" man_find_and_display "$page"