git: e85a6f8dff96 - main - man: fix redirect for locales and file arguments

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sat, 03 Feb 2024 01:36:18 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=e85a6f8dff96d33e7139a67f5b02dafaace0974c

commit e85a6f8dff96d33e7139a67f5b02dafaace0974c
Author:     Mohamed Akram <mohd.akram@outlook.com>
AuthorDate: 2024-02-02 23:26:20 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-02-03 01:34:59 +0000

    man: fix redirect for locales and file arguments
    
    Use the locale-specific path for localized pages and the appropriate parent
    directory for file arguments when handling redirects.
    
    Signed-off-by: Mohamed Akram <mohd.akram@outlook.com>
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/1019
---
 usr.bin/man/man.sh | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh
index 4be38083462c..fd51648757a9 100755
--- a/usr.bin/man/man.sh
+++ b/usr.bin/man/man.sh
@@ -297,7 +297,7 @@ manpath_warnings() {
 	fi
 }
 
-# Usage: man_check_for_so page path
+# Usage: man_check_for_so path
 # Returns: True if able to resolve the file, false if it ended in tears.
 # Detects the presence of the .so directive and causes the file to be
 # redirected to another source file.
@@ -317,7 +317,7 @@ man_check_for_so() {
 		.so*)	trim "${line#.so}"
 			decho "$manpage includes $tstr"
 			# Glob and check for the file.
-			if ! check_man "$path/$tstr" ""; then
+			if ! check_man "$1/$tstr" ""; then
 				decho "  Unable to find $tstr"
 				return 1
 			fi
@@ -501,7 +501,12 @@ man_find_and_display() {
 			unset use_cat
 			manpage="$1"
 			setup_cattool "$manpage"
-			if man_check_for_so "$manpage" "$(dirname \"$manpage"")"; then
+			p=$(cd "$(dirname "$manpage")" && pwd)
+			case "$(basename "$p")" in
+				man*|cat*) p=$p/.. ;;
+				*) p=$p/../.. ;;
+			esac
+			if man_check_for_so "$p"; then
 				found_page=yes
 				man_display_page
 			fi
@@ -520,7 +525,7 @@ man_find_and_display() {
 
 				# Check if there is a MACHINE specific manpath.
 				if find_file $p $sect $MACHINE "$1"; then
-					if man_check_for_so "$manpage" $p; then
+					if man_check_for_so $p; then
 						found_page=yes
 						man_display_page
 						if [ -n "$aflag" ]; then
@@ -534,7 +539,7 @@ man_find_and_display() {
 				# Check if there is a MACHINE_ARCH
 				# specific manpath.
 				if find_file $p $sect $MACHINE_ARCH "$1"; then
-					if man_check_for_so "$manpage" $p; then
+					if man_check_for_so $p; then
 						found_page=yes
 						man_display_page
 						if [ -n "$aflag" ]; then
@@ -547,7 +552,7 @@ man_find_and_display() {
 
 				# Check plain old manpath.
 				if find_file $p $sect '' "$1"; then
-					if man_check_for_so "$manpage" $p; then
+					if man_check_for_so $p; then
 						found_page=yes
 						man_display_page
 						if [ -n "$aflag" ]; then