commit:     a46a94768d76cd1f52cc7d6743575887fa416407
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Jun  6 00:23:54 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Jun 12 07:06:42 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=a46a9476

Have quote_args() respect POSIXLY_CORRECT for Issue 7 conformance

Also, markedly improve the comment that documents the function.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 functions.sh | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/functions.sh b/functions.sh
index f440dab..79cd06a 100644
--- a/functions.sh
+++ b/functions.sh
@@ -540,19 +540,29 @@ parallel_run()
 }
 
 #
-# Prints the positional parameters in a manner that approximates the behaviour
-# of the ${*@Q} expansion in bash. The output shall be POSIX sh compatible as 
of
-# Issue 8. This should probably be made to exist as a standalone awk script.
+# Prints the positional parameters in a format that may be reused as shell
+# input. For each considered, it shall be determined whether its value contains
+# any non-printable characters in lieu of the US-ASCII character set. If no 
such
+# characters are found, the value shall have each instance of <apostrophe> be
+# replaced by <apostrophe><backslash><apostrophe><apostrophe> before being
+# enclosed by a pair of <apostrophe> characters. Otherwise, non-printable
+# characters shall be replaced by octal escape sequences, <apostrophe> by
+# <backslash><apostrophe> and <backslash> by <backslash><backslash>, prior to
+# the value being given a prefix of <dollar-sign><apostrophe> and a suffix of
+# <apostrophe>, per Issue 8. Finally, the resulting values shall be printed as
+# <space> separated. The latter quoting strategy can be suppressed by setting
+# the POSIXLY_CORRECT variable as non-empty in the environment.
 #
 quote_args()
 {
        awk -v q=\' -f - -- "$@" <<-'EOF'
                BEGIN {
+                       strictly_posix = length(ENVIRON["POSIXLY_CORRECT"])
                        argc = ARGC
                        ARGC = 1
                        for (arg_idx = 1; arg_idx < argc; arg_idx++) {
                                arg = ARGV[arg_idx]
-                               if (arg !~ /[\001-\037\177]/) {
+                               if (strictly_posix || arg !~ /[\001-\037\177]/) 
{
                                        gsub(q, q "\\" q q, arg)
                                        word = q arg q
                                } else {

Reply via email to