[Bug 271830] man: ignores MANSECT and -S

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 05 Jun 2023 09:46:19 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=271830

--- Comment #4 from Mohamed Akram <mohd.akram@outlook.com> ---
Comment on attachment 242606
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=242606
patch to fix the issue

--- man.sh.orig 2023-06-05 09:11:06.617877000 +0000
+++ man.sh      2023-06-05 09:43:16.432524000 +0000
@@ -562,7 +562,7 @@
                P)      MANPAGER=$OPTARG ;;
                S)      MANSECT=$OPTARG ;;
                a)      aflag=aflag ;;
-               d)      debug=$(( $debug + 1 )) ;;
+               d)      ;; # handled in man_setup
                f)      fflag=fflag ;;
                h)      man_usage 0 ;;
                k)      kflag=kflag ;;
@@ -603,7 +603,7 @@
        fi

        IFS=:
-       for sect in $man_default_sections; do
+       for sect in $MANSECT; do
                if [ "$sect" = "$1" ]; then
                        decho "Detected manual section as first arg: $1"
                        MANSECT="$1"
@@ -619,6 +619,15 @@
 # Usage: man_setup
 # Setup various trivial but essential variables.
 man_setup() {
+       local cmd_arg
+       # Parse the debug flag prior to everything
+       OPTIND=1
+       while getopts ':d' cmd_arg; do
+               case "${cmd_arg}" in
+               d)      debug=$(( $debug + 1 )) ;;
+               esac
+       done
+
        # Setup machine and architecture variables.
        if [ -n "$mflag" ]; then
                MACHINE_ARCH=${mflag%%:*}
@@ -787,8 +796,8 @@
                                trim "${line#MANCONFIG}"
                                config_local="$tstr"
                                ;;
-               # Set variables in the form of FOO_BAR
-               *_*[\ \ ]*)     var="${line%%[\ \       ]*}"
+               # Set other variables
+               *[\ \   ]*)     var="${line%%[\ \       ]*}"
                                trim "${line#$var}"
                                eval "$var=\"$tstr\""
                                decho "    Parsed $var" 3
@@ -1008,12 +1017,12 @@
 }

 do_man() {
+       man_setup "$@"
        man_parse_args "$@"
        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

-- 
You are receiving this mail because:
You are the assignee for the bug.