diff options
author | 2024-06-04 04:24:27 +0100 | |
---|---|---|
committer | 2024-06-12 08:06:42 +0100 | |
commit | f0ceaf3607b88982bad6bc9954d9e14f7b8f512c (patch) | |
tree | 0cb11f6e877716dacc0ccc889d9da0c46f898a65 | |
parent | Promote _print_args() to the public function, quote_args() (diff) | |
download | gentoo-functions-f0ceaf3607b88982bad6bc9954d9e14f7b8f512c.tar.gz gentoo-functions-f0ceaf3607b88982bad6bc9954d9e14f7b8f512c.tar.bz2 gentoo-functions-f0ceaf3607b88982bad6bc9954d9e14f7b8f512c.zip |
Reposition the declaration of quote_args()
So as to maintain an alphabetical order.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
-rw-r--r-- | functions.sh | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/functions.sh b/functions.sh index a9af6b6..f440dab 100644 --- a/functions.sh +++ b/functions.sh @@ -540,6 +540,59 @@ 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. +# +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 # only have an effect where EINFO_VERBOSE is true. @@ -840,59 +893,6 @@ _is_visible() } # -# 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(). # _select_by_mtime() { |