diff options
author | Mohamed Akram <mohd.akram@outlook.com> | 2023-06-27 13:51:24 +0000 |
---|---|---|
committer | Warner Losh <imp@FreeBSD.org> | 2023-06-27 13:51:27 +0000 |
commit | 8edb6fb572f29578877fdac3c30f718e589a0360 (patch) | |
tree | fb0cded16c9423061f4232d7802dc2bbe6e2455f /usr.bin/man | |
parent | a6c0d801ca5934bb9b9cca6870ea7406d5db0641 (diff) | |
download | src-8edb6fb572f29578877fdac3c30f718e589a0360.tar.gz src-8edb6fb572f29578877fdac3c30f718e589a0360.zip |
Diffstat (limited to 'usr.bin/man')
-rwxr-xr-x | usr.bin/man/man.sh | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh index aa7d1287405a..2b20c4394733 100755 --- a/usr.bin/man/man.sh +++ b/usr.bin/man/man.sh @@ -69,6 +69,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() { @@ -548,10 +567,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 'K:M:P:S:adfhkm:op:tw' cmd_arg; do @@ -601,19 +620,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 @@ -633,14 +639,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 } @@ -787,6 +787,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}" @@ -1008,12 +1012,28 @@ do_full_search() { } do_man() { - man_parse_args "$@" + 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" -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 |