autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: avoiding undesired macro expansion after AS_TR_CPP


From: Bruno Haible
Subject: Re: avoiding undesired macro expansion after AS_TR_CPP
Date: Sat, 5 Jun 2010 13:14:24 +0200
User-agent: KMail/1.9.9

Hi Eric,

> The question ... is whether AS_TR_CPP([abc]) should output a quoted
> string (which is a change in behavior, but arguably more like
> m4_toupper), or a raw string (no worse than what we have today, but
> where AS_TR_CPP([[abc]]) would work where today it doesn't).
> ...
> It's a bug fix either way, so which way do you prefer?

Since you mentioned m4_toupper, here's a comparison of m4_toupper,
m4_tolower, AS_TR_SH, AS_TR_CPP. To get the big picture.

========================== configure.ac ========================
AC_INIT

m4_define([Gregor_Samsa], [Gregor_Samsa_argexpanded])

m4_define([FOO_BAR], [FOO_BAR_argexpanded])

m4_define([GREGOR_SAMSA], [undesired substitution on result])
m4_define([GREGOR_SAMSA_ARGEXPANDED], [arg expanded and undesired substitution 
on result])

m4_define([foo_bar], [undesired substitution on result])
m4_define([foo_bar_argexpanded], [arg expanded and undesired substitution on 
result])

XXX_HERE

dnl Test with m4_tolower:
[gl_]m4_tolower(FOO_BAR)
[gl_]m4_quote(m4_tolower(FOO_BAR))
[gl_]m4_tolower([FOO_BAR])
[gl_]m4_quote(m4_tolower([FOO_BAR]))
[gl_]m4_tolower([[FOO_BAR]])
[gl_]m4_quote(m4_tolower([[FOO_BAR]]))

dnl Test with m4_toupper:
[gl_]m4_toupper(Gregor_Samsa)
[gl_]m4_quote(m4_toupper(Gregor_Samsa))
[gl_]m4_toupper([Gregor_Samsa])
[gl_]m4_quote(m4_toupper([Gregor_Samsa]))
[gl_]m4_toupper([[Gregor_Samsa]])
[gl_]m4_quote(m4_toupper([[Gregor_Samsa]]))

dnl Test with AS_TR_SH:
[gl_]AS_TR_SH(FOO_BAR)
[gl_]m4_quote(AS_TR_SH(FOO_BAR))
[gl_]AS_TR_SH([FOO_BAR])
[gl_]m4_quote(AS_TR_SH([FOO_BAR]))
[gl_]AS_TR_SH([[FOO_BAR]])
[gl_]m4_quote(AS_TR_SH([[FOO_BAR]]))

dnl Test with AS_TR_CPP:
[gl_]AS_TR_CPP(Gregor_Samsa)
[gl_]m4_quote(AS_TR_CPP(Gregor_Samsa))
[gl_]AS_TR_CPP([Gregor_Samsa])
[gl_]m4_quote(AS_TR_CPP([Gregor_Samsa]))
[gl_]AS_TR_CPP([[Gregor_Samsa]])
[gl_]m4_quote(AS_TR_CPP([[Gregor_Samsa]]))

AC_OUTPUT
========================================================================
$ autoconf

produces:

-------------------------------------------------------------
gl_foo_bar_argexpanded
gl_foo_bar_argexpanded
gl_foo_bar
gl_foo_bar
gl_[foo_bar]
gl_[foo_bar]

gl_GREGOR_SAMSA_ARGEXPANDED
gl_GREGOR_SAMSA_ARGEXPANDED
gl_GREGOR_SAMSA
gl_GREGOR_SAMSA
gl_[GREGOR_SAMSA]
gl_[GREGOR_SAMSA]

gl_FOO_BAR_argexpanded
gl_FOO_BAR_argexpanded
gl_FOO_BAR_argexpanded
gl_FOO_BAR_argexpanded
gl_FOO_BAR
gl_FOO_BAR

gl_arg expanded and undesired substitution on result
gl_arg expanded and undesired substitution on result
gl_arg expanded and undesired substitution on result
gl_arg expanded and undesired substitution on result
gl_undesired substitution on result
gl_undesired substitution on result
-------------------------------------------------------------

So this means that currently:
  - m4_tolower and m4_toupper operate in the same way:
    They expand their arg if it is unquoted, and they don't
    expand their result.
  - AS_TR_SH and AS_TR_CPP expand their arg if it unquoted or single-quoted.
  - AS_TR_SH does not expand its result.
  - AS_TR_CPP expands its result.

The difference between m4_tolower and m4_toupper on one side and
AS_TR_SH and AS_TR_CPP on the other side - does it require single-quoting
or double-quoting to avoid argument expansion - is a bit surprising, but
may be due to the fact that m4_tolower and m4_toupper come from m4
whereas AS_TR_SH and AS_TR_CPP follow the autoconf conventions.
I'm not asking to change that.

I'm only asking to make AS_TR_CPP not expand its result. In other words,
I want the result of above autoconf run to be:

-------------------------------------------------------------
gl_foo_bar_argexpanded
gl_foo_bar_argexpanded
gl_foo_bar
gl_foo_bar
gl_[foo_bar]
gl_[foo_bar]

gl_GREGOR_SAMSA_ARGEXPANDED
gl_GREGOR_SAMSA_ARGEXPANDED
gl_GREGOR_SAMSA
gl_GREGOR_SAMSA
gl_[GREGOR_SAMSA]
gl_[GREGOR_SAMSA]

gl_FOO_BAR_argexpanded
gl_FOO_BAR_argexpanded
gl_FOO_BAR_argexpanded
gl_FOO_BAR_argexpanded
gl_FOO_BAR
gl_FOO_BAR

gl_GREGOR_SAMSA_ARGEXPANDED
gl_GREGOR_SAMSA_ARGEXPANDED
gl_GREGOR_SAMSA_ARGEXPANDED
gl_GREGOR_SAMSA_ARGEXPANDED
gl_GREGOR_SAMSA
gl_GREGOR_SAMSA
-------------------------------------------------------------

This would make AS_TR_CPP consistent with AS_TR_SH.

You are free to convert my sample code into a test case ;-)

Bruno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]