The branch main has been updated by wosch:

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

commit e3c7b76fa8105929ae9a785e5ffc44274b1b0a81
Author:     Wolfram Schneider <wo...@freebsd.org>
AuthorDate: 2024-01-13 16:16:55 +0000
Commit:     Wolfram Schneider <wo...@freebsd.org>
CommitDate: 2024-01-13 16:16:55 +0000

    man(1): support spaces in filenames
    
    The globbing function in exists() needs to handle white spaces.
    
    PR:          275978
    Reviewed by: kevans, bapt, emaste
    MFC after:   1 week
---
 usr.bin/man/man.sh | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh
index 7e2151295ba7..777726f880db 100755
--- a/usr.bin/man/man.sh
+++ b/usr.bin/man/man.sh
@@ -191,7 +191,9 @@ decho() {
 }
 
 # Usage: exists glob
-# Returns true if glob resolves to a real file.
+#
+# Returns true if glob resolves to a real file and store the first
+# found filename in the variable $found
 exists() {
        local IFS
 
@@ -201,14 +203,16 @@ exists() {
        # Use some globbing tricks in the shell to determine if a file
        # exists or not.
        set +f
-       set -- "$1" $1
+       for file in "$1"*
+       do
+               if [ -r "$file" ]; then
+                       found="$file"
+                       set -f
+                       return 0
+               fi
+       done
        set -f
 
-       if [ "$1" != "$2" -a -r "$2" ]; then
-               found="$2"
-               return 0
-       fi
-
        return 1
 }
 
@@ -230,10 +234,10 @@ find_file() {
        fi
        decho "  Searching directory $manroot" 2
 
-       mann="$manroot/$4.$2*"
-       man0="$manroot/$4.0*"
-       catn="$catroot/$4.$2*"
-       cat0="$catroot/$4.0*"
+       mann="$manroot/$4.$2"
+       man0="$manroot/$4.0"
+       catn="$catroot/$4.$2"
+       cat0="$catroot/$4.0"
 
        # This is the behavior as seen by the original man utility.
        # Let's not change that which doesn't seem broken.
@@ -313,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 "$path/$tstr" ""; then
                                decho "  Unable to find $tstr"
                                return 1
                        fi

Reply via email to