[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 12/13: [gdiffmk]: Refactor to stop using expr(1).
From: |
G. Branden Robinson |
Subject: |
[groff] 12/13: [gdiffmk]: Refactor to stop using expr(1). |
Date: |
Mon, 25 Dec 2023 20:38:55 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 173588377b17787785f85ca366303517c21074a7
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Dec 23 17:50:46 2023 -0600
[gdiffmk]: Refactor to stop using expr(1).
* contrib/gdiffmk/gdiffmk.sh (RequiresArgument): Refactor to use shell
parameter expansion instead of expr(1), to avoid potential use of
external command and quirk in FreeBSD's implementation.
* ANNOUNCE:
* PROBLEMS: Drop caveat.
---
ANNOUNCE | 3 ---
PROBLEMS | 13 -------------
contrib/gdiffmk/ChangeLog | 6 ++++++
contrib/gdiffmk/gdiffmk.sh | 26 +++++++++++++++-----------
4 files changed, 21 insertions(+), 27 deletions(-)
diff --git a/ANNOUNCE b/ANNOUNCE
index b53af0717..ca0e7b68f 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -138,9 +138,6 @@ o Some portability issues are known to affect groff's
gdiffmk utility.
gdiffmk does not work with BusyBox diff (which does not implement GNU
diff's "-D" option).
- gdiffmk does not work on FreeBSD due to specifics of that platform's
- expr(1) implementation.
-
o GNU tools, or otherwise POSIX-conforming ones, are generally required
to build on Solaris 10 or 11. See the "PROBLEMS" file in the
distribution archive.
diff --git a/PROBLEMS b/PROBLEMS
index cdac1d98f..b5a832667 100644
--- a/PROBLEMS
+++ b/PROBLEMS
@@ -40,19 +40,6 @@ Some portability issues are known to affect groff's gdiffmk
utility.
- gdiffmk does not work with BusyBox diff (which does not implement GNU
diff's "-D" option).
-- gdiffmk does not work on FreeBSD due to specifics of that platform's
- expr(1) implementation.
-
- gdiffmk uses the expr(1) command to parse its arguments. FreeBSD has
- extended the syntax of its expr command in a non-backward compatible
- way that it claims better conforms with POSIX's utility syntax
- guidelines with respect to option processing: however, POSIX mandates
- no options for expr. Other implementations of expr do not support
- traditional Unix-style options ('-a', '-b', ...), and perhaps as a
- consequence do not follow FreeBSD's interpretation of the guidelines.
- You way want to set $EXPR_COMPAT in your shell environment. We hope
- to have a workaround for this behavior in a future release.
-
----------------------------------------------------------------------
[groff 1.19.2]
diff --git a/contrib/gdiffmk/ChangeLog b/contrib/gdiffmk/ChangeLog
index ebc4bb2f9..aeeb76486 100644
--- a/contrib/gdiffmk/ChangeLog
+++ b/contrib/gdiffmk/ChangeLog
@@ -1,3 +1,9 @@
+2023-12-23 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * gdiffmk.sh (RequiresArgument): Refactor to use shell parameter
+ expansion instead of expr(1), to avoid potential use of external
+ command and quirk in FreeBSD's implementation.
+
2023-12-23 G. Branden Robinson <g.branden.robinson@gmail.com>
* gdiffmk.sh (FileRead, main): Revise wording of diagnostic
diff --git a/contrib/gdiffmk/gdiffmk.sh b/contrib/gdiffmk/gdiffmk.sh
index 2f9a3e784..8945f8543 100644
--- a/contrib/gdiffmk/gdiffmk.sh
+++ b/contrib/gdiffmk/gdiffmk.sh
@@ -141,23 +141,27 @@ DELETEMARK='*'
MARK1='[['
MARK2=']]'
+# Given an option with an expected argument, echo the option argument.
+# Return 0 if caller should further shift its argument list; 1 if not.
RequiresArgument () {
- # Process flags that take either concatenated or
- # separated values.
case "$1" in
-??*)
- expr "$1" : '-.\(.*\)'
+ optarg=${1#-?}
+ option=${option%${optarg}}
+
+ if test -z "${optarg}"
+ then
+ Exit 2 "option '${option}' requires an argument"
+ fi
+
+ echo "${optarg}"
return 1
;;
+ *)
+ echo "$2"
+ return 0
+ ;;
esac
-
- if test $# -lt 2
- then
- Exit 2 "option '$1' requires an argument"
- fi
-
- echo "$2"
- return 0
}
HAVE_TEST_EF_OPTION=@HAVE_TEST_EF_OPTION@
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 12/13: [gdiffmk]: Refactor to stop using expr(1).,
G. Branden Robinson <=