diff options
author | Gregory M. Turner <gmt@be-evil.net> | 2013-10-11 02:26:46 -0700 |
---|---|---|
committer | Gregory M. Turner <gmt@be-evil.net> | 2013-10-11 02:29:35 -0700 |
commit | d759db113bbd98c7dca029c292f1a484f9a18654 (patch) | |
tree | ef46d43f084a974027be34626144c8c314966d79 /eclass/my-god-its-full-of-quotation-marks.eclass | |
parent | eclass/autotools-utils: add autotools-utils_run_in_build_dir convenience API (diff) | |
download | gmt-d759db113bbd98c7dca029c292f1a484f9a18654.tar.gz gmt-d759db113bbd98c7dca029c292f1a484f9a18654.tar.bz2 gmt-d759db113bbd98c7dca029c292f1a484f9a18654.zip |
eclass/my-god-its-full-of-quotation-marks: new eclass
Refactor duplicated my-god-its-full-of-quotation-marks "pretty"-printer
functions into shared, dedicated eclass. Also change implementation not
to add quotes to foo=bar inputs, but only to foo=bar\ baz inputs, and to
add '\' -> '\\' and '"' -> '\"' pseudo-escapes to output so that these
characters will not introduce ambiguities in the output, if they are
present in the input.
Signed-off-by: Gregory M. Turner <gmt@be-evil.net>
Diffstat (limited to 'eclass/my-god-its-full-of-quotation-marks.eclass')
-rw-r--r-- | eclass/my-god-its-full-of-quotation-marks.eclass | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/eclass/my-god-its-full-of-quotation-marks.eclass b/eclass/my-god-its-full-of-quotation-marks.eclass new file mode 100644 index 0000000..69f5083 --- /dev/null +++ b/eclass/my-god-its-full-of-quotation-marks.eclass @@ -0,0 +1,59 @@ +# Copyright 1999-2013 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +# @ECLASS: my-god-its-full-of-quotation-marks.eclass +# @MAINTAINER: +# Gregory M. Turner <gmt@be-evil.net> +# @AUTHOR: +# Gregory M. Turner <gmt@be-evil.net +# @BLURB: pretty printing for lists of arguments possibly containing spaces +# @DESCRIPTION: +# my-god-its-full-of-quotation-marks.eclass provides, unsurprisingly, perhaps, the +# my-god-its-full-of-quotation-marks function. + +# @FUNCTION: my-god-its-full-of-quotation-marks +# @USAGE: [list of moderately sane string arguments, each possibly containing spaces] +# @RETURN: 0 +# @DESCRIPTION: +# Pretty printer for configure-type arguments, which simply dumps its arguments +# back to stdout after adding quotation marks to ensure unambiguous display +# when some of the arguments may include spaces. Note that this is designed for +# consumption by human eyeballs, not parsers!!! Use printf "%q" for the latter. +# Here we concern ourselves only with dismbiguating the display of (otherwise +# presumptively pre-sanitized) lists of arguments which may contain spaces. +# +# Also replaces any backslashes in the arguments with double-backslashes, and then +# any quotation marks in the arguments with \". These pseudo-escapes +# should preserve disambiguation in the face of quotation-mark- or backslash-containing +# arguments. +my-god-its-full-of-quotation-marks() { + local foo bar + for foo in "$@" ; do + # add a space if bar is nonempty + bar="${bar}${bar:+ }" + # add pseudo-escapes for '\' and '"' + foo="${foo//\\/\\\\}" + foo="${foo//\"/\\\"}" + case $foo in + "") + bar="${bar}\"\"" + ;; + *\ *=*) + # jesus, wtf + bar="${bar}\"${foo}\"" + ;; + *=*\ *) + bar="${bar}${foo%%=*}=\"${foo#*=}\"" + ;; + *\ *) + bar="${bar}\"${foo}\"" + ;; + *) + bar="${bar}${foo}" + ;; + esac + done + echo "${bar}" +} + |