This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: libstdc++ configure time


On Mon, Mar 19, 2001 at 10:33:12PM -0800, Richard Henderson wrote:
> All of these fail if the input string contains commas.  There
> was a reason that I had the ugly quoting that I did.  It might
> well be possible to do better that I'd done though...

The following appears to dtrt wrt embedded commas without undoing much
of the readability cleanups you'd done (thanks).  Somehow I hadn't thought
about the implications of immediately nested quoting until I saw what
you did for ACQD.


r~



changequote([,])divert(-1)
# Escape characters that cannot appear in shell single and double
# quoted strings, respectively.
#
define(ACQS, [patsubst([$1], ['], ['\\''])])
define(ACQD, [patsubst([$1],[["\]], [\\\&])])

# Protect various sorts of strings from echo.
# _0? - no special protection needed
# _1? - only needs backslash escaped
# _2? - only needs a leading dash escaped
# _3? - needs both, or needs one of them but contains at signs
#
# Mode 3 uses this map:
#	@	@0
#	\	@1
#	-	@2
#
# The _?i macros set up the quoting scheme.  The funny nested quotation
# deals with input strings containing embedded commas.  There is one
# level of quotation for every level of nested function call.
#
define(_AC_GEN_FILE_0i, [_AC_GEN_FILE_0o([$1],$3[]indir([$4],[[$2]])$3)])
define(_AC_GEN_FILE_1i,
	[_AC_GEN_FILE_1o([$1],$3[]indir([$4],translit([[[$2]]], \, @))$3)])
define(_AC_GEN_FILE_2i,
	[_AC_GEN_FILE_2o([$1],$3[]indir([$4],translit([[[$2]]], -, @))$3)])
define(_AC_GEN_FILE_3i,
	[_AC_GEN_FILE_3o([$1],$3[]indir([$4],
	patsubst(patsubst(patsubst([[[[[$2]]]]], @, @0), \\, @1), -, @2))$3)])

# The _?o macros undo the quoting when the shell script is run.
#
define(_AC_GEN_FILE_0o, [echo $2 $1])
define(_AC_GEN_FILE_1o, [echo $2 | tr @ \\\\ $1])
define(_AC_GEN_FILE_2o, [echo $2 | tr @ - $1])
define(_AC_GEN_FILE_3o,
	[echo $2 | sed -e 's/@2/-/g' -e 's/@1/\\/g' -e 's/@0/@/g' $1])

# _AC_GEN_FILE(target-file, text, quote, quote-fn)
# forwards to the appropriate echo-protection macro.
#
define(_AC_GEN_FILE,
[_AC_GEN_FILE_DISPATCH(
ifelse(regexp([$2], ^-), -1, n, y)[]dnl
ifelse(index([$2], \), -1, n, y)[]dnl
ifelse(index([$2], @), -1, n, y), $@)])
define(_AC_GEN_FILE_DISPATCH,
[ifelse($1, nnn,	[_AC_GEN_FILE_0i(shift($@))],
	$1, nny,	[_AC_GEN_FILE_0i(shift($@))],
	$1, nyn,	[_AC_GEN_FILE_1i(shift($@))],
	$1, ynn,	[_AC_GEN_FILE_2i(shift($@))],
			[_AC_GEN_FILE_3i(shift($@))])])

# Macros for user consumption.
#
define(AC_CREATE_FILE,   [_AC_GEN_FILE([>$1],  [$2], ["], [ACQD])])
define(AC_CREATE_FILE_Q, [_AC_GEN_FILE([>$1],  [$2], ['], [ACQS])])
define(AC_APPEND_FILE,   [_AC_GEN_FILE([>>$1], [$2], ["], [ACQD])])
define(AC_APPEND_FILE_Q, [_AC_GEN_FILE([>>$1], [$2], ['], [ACQS])])

# and a specific use
define(AC_DEFINE,
[AC_APPEND_FILE_Q(confdefs.h,
	ifelse(eval([$# >= 2]), 1, [[#define $1 $2]], [[#define $1 1]]))])

traceon
divert(0)dnl
AC_DEFINE(CASE_A, hi)
AC_DEFINE(CASE_B, "\n")
AC_DEFINE(CASE_C, "@home\n")
AC_DEFINE(CASE_D, '\'')
AC_APPEND_FILE_Q(confdefs.h, -n)
AC_APPEND_FILE_Q(confdefs.h, -n "@home\n")
AC_APPEND_FILE(confdefs.h,
[
int main()
{
  printf("Hello, World!\n");
  return 0;
}])


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]