From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0E1011582ED for ; Fri, 21 Jun 2024 13:14:23 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0B141E2A96; Fri, 21 Jun 2024 13:14:20 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DA235E2A8E for ; Fri, 21 Jun 2024 13:14:19 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E7A4C33D3CF for ; Fri, 21 Jun 2024 13:14:17 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 3EBC61D56 for ; Fri, 21 Jun 2024 13:14:15 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1718176002.f0ceaf3607b88982bad6bc9954d9e14f7b8f512c.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: f0ceaf3607b88982bad6bc9954d9e14f7b8f512c X-VCS-Branch: master Date: Fri, 21 Jun 2024 13:14:15 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 55f0c047-b8ac-48fd-b1d5-7cc688b379d9 X-Archives-Hash: 20f84d0eaec127598c417b7fc9a2ed68 commit: f0ceaf3607b88982bad6bc9954d9e14f7b8f512c Author: Kerin Millar plushkava net> AuthorDate: Tue Jun 4 03:24:27 2024 +0000 Commit: Sam James gentoo org> CommitDate: Wed Jun 12 07:06:42 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=f0ceaf36 Reposition the declaration of quote_args() So as to maintain an alphabetical order. Signed-off-by: Kerin Millar plushkava.net> functions.sh | 106 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/functions.sh b/functions.sh index a9af6b6..f440dab 100644 --- a/functions.sh +++ b/functions.sh @@ -539,6 +539,59 @@ parallel_run() ! rmdir -- "${statedir}" 2>/dev/null } +# +# 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. +# +quote_args() +{ + awk -v q=\' -f - -- "$@" <<-'EOF' + BEGIN { + argc = ARGC + ARGC = 1 + for (arg_idx = 1; arg_idx < argc; arg_idx++) { + arg = ARGV[arg_idx] + if (arg !~ /[\001-\037\177]/) { + gsub(q, q "\\" q q, arg) + word = q arg q + } else { + # Use $'' quoting per Issue 8 + if (ord_by["\001"] == "") { + for (i = 1; i < 32; i++) { + char = sprintf("%c", i) + ord_by[char] = i + } + ord_by["\177"] = 127 + } + word = "$'" + for (i = 1; i <= length(arg); i++) { + char = substr(arg, i, 1) + if (char == "\\") { + word = word "\\\\" + } else if (char == q) { + word = word "\\'" + } else { + ord = ord_by[char] + if (ord != "") { + word = word "\\" sprintf("%03o", ord) + } else { + word = word char + } + } + } + word = word q + } + line = line word + if (arg_idx < argc - 1) { + line = line " " + } + } + print line + } + EOF +} + # # Declare the vebegin, veerror, veindent, veinfo, veinfon, veoutdent and vewarn # functions. These differ from their non-v-prefixed counterparts in that they @@ -839,59 +892,6 @@ _is_visible() ! case $1 in *[[:graph:]]*) false ;; esac } -# -# 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. -# -quote_args() -{ - awk -v q=\' -f - -- "$@" <<-'EOF' - BEGIN { - argc = ARGC - ARGC = 1 - for (arg_idx = 1; arg_idx < argc; arg_idx++) { - arg = ARGV[arg_idx] - if (arg !~ /[\001-\037\177]/) { - gsub(q, q "\\" q q, arg) - word = q arg q - } else { - # Use $'' quoting per Issue 8 - if (ord_by["\001"] == "") { - for (i = 1; i < 32; i++) { - char = sprintf("%c", i) - ord_by[char] = i - } - ord_by["\177"] = 127 - } - word = "$'" - for (i = 1; i <= length(arg); i++) { - char = substr(arg, i, 1) - if (char == "\\") { - word = word "\\\\" - } else if (char == q) { - word = word "\\'" - } else { - ord = ord_by[char] - if (ord != "") { - word = word "\\" sprintf("%03o", ord) - } else { - word = word char - } - } - } - word = word q - } - line = line word - if (arg_idx < argc - 1) { - line = line " " - } - } - print line - } - EOF -} - # # See the definitions of oldest() and newest(). #