git: 1024a7c061ed - stable/13 - man(1): support spaces in filenames
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 12 Feb 2024 15:49:38 UTC
The branch stable/13 has been updated by wosch:
URL: https://cgit.FreeBSD.org/src/commit/?id=1024a7c061ed5cb34f5f3730f70432b5c01c9a12
commit 1024a7c061ed5cb34f5f3730f70432b5c01c9a12
Author: Wolfram Schneider <wosch@FreeBSD.org>
AuthorDate: 2024-01-13 16:16:55 +0000
Commit: Wolfram Schneider <wosch@FreeBSD.org>
CommitDate: 2024-02-12 15:45:52 +0000
man(1): support spaces in filenames
The globbing function in exists() needs to handle white spaces.
PR: 275978
Reviewed by: kevans, bapt, emaste
Differential Revision: https://reviews.freebsd.org/D43222
MFC after: 1 week
(cherry picked from commit e3c7b76fa8105929ae9a785e5ffc44274b1b0a81)
(cherry picked from commit 7169c947ab4150a539f2af6c9dcf3ab4344b0033)
---
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 ecc73733b560..8cce52148699 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