* lib/m4sugar/m4sh.m4 (_AS_TR_CPP_LITERAL): Avoid underquoting. (_AS_TR_CPP_INDIR): Handle all polymorphic variables. * tests/m4sh.at (AS@&t@_TR_SH and AS@&t@_TR_CPP): New test. * NEWS: Document the fix. Reported by Bruno Haible. Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> --- > I will post my patch as a reply, once I run it through the testsuite to > check for any regressions. Testsuite ran without problems, so I'll be committing this. Note that AS_TR_SH([[abc]]) still results in 'abc', while AS_TR_SH([[[abc]]]) results in '_abc_' (that is, it resulted in the transliteration of '[abc]'). Both AS_TR_SH and AS_TR_CPP have some m4 magic where they can see through macro names, such that: m4_define([foo],[bar]) AS_TR_CPP([foo]) results in BAR (that is, it behaves as if you had done AS_TR_CPP(foo) in the first place). This magic is necessary because of the fact that AS_VAR_PUSHDEF is frequently used with AS_TR_*, and it results in macro names that must be expanded in advance while still allowing typical clients to use normal quoting rules rather than having to special case AS_VAR_PUSHDEF. m4_toupper and m4_tolower do not have this magic of seeing through quoted macro args (nor should they). ChangeLog | 7 +++++ NEWS | 2 + lib/m4sugar/m4sh.m4 | 4 +- tests/m4sh.at | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c31e0e..00c9096 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2010-07-02 Eric Blake <eblake@xxxxxxxxxx> + Make AS_TR_SH and AS_TR_CPP similar. + * lib/m4sugar/m4sh.m4 (_AS_TR_CPP_LITERAL): Avoid underquoting. + (_AS_TR_CPP_INDIR): Handle all polymorphic variables. + * tests/m4sh.at (AS@&t@_TR_SH and AS@&t@_TR_CPP): New test. + * NEWS: Document the fix. + Reported by Bruno Haible. + Reduce startup cost of autotest. * lib/autotest/general.m4 (_AT_FINISH) <banners>: Rather than doing a recursive find, limit ourselves to top ChangeLog only. diff --git a/NEWS b/NEWS index cb1ffbd..53f34c0 100644 --- a/NEWS +++ b/NEWS @@ -43,6 +43,8 @@ GNU Autoconf NEWS - User visible changes. Furthermore, a new macro, AS_LITERAL_WORD_IF, adds an additional level of checking that no whitespace occurs in literals. +** The macros AS_TR_SH and AS_TR_CPP no longer expand their results. + ** The following macros are now documented: AS_BOX diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index 2a4faf3..e1d03d9 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -1816,12 +1816,12 @@ m4_define([_AS_TR_CPP], ])([], [$0_INDIR], [$0_LITERAL])([$1])]) m4_define([_AS_TR_CPP_LITERAL], -[m4_translit([$1], +[m4_translit([[$1]], [*[]]]m4_dquote(m4_defn([m4_cr_letters])m4_defn([m4_cr_not_symbols2]))[, [P[]]]m4_dquote(m4_defn([m4_cr_LETTERS])m4_for(,1,255,,[[_]]))[)]) m4_define([_AS_TR_CPP_INDIR], -[`AS_ECHO(["$1"]) | $as_tr_cpp`]) +[`AS_ECHO(["_AS_ESCAPE([[$1]], [`], [\])"]) | $as_tr_cpp`]) # _AS_TR_PREPARE diff --git a/tests/m4sh.at b/tests/m4sh.at index f5ea7e2..bd915c0 100644 --- a/tests/m4sh.at +++ b/tests/m4sh.at @@ -1169,6 +1169,78 @@ ok 16 AT_CLEANUP +## --------------------- ## +## AS_TR_SH, AS_TR_CPP. ## +## --------------------- ## + +AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP]) + +AT_DATA_M4SH([script.as], [[dnl +AS_INIT +m4_define([abc], [hI])m4_define([ABC], [Hi]) +m4_define([hi], [oops])m4_define([HI], [OOPS]) +echo AS_TR_SH(abc) AS_TR_SH(aBc) AS_TR_SH(ABC) +echo AS_TR_SH([abc]) AS_TR_SH([aBc]) AS_TR_SH([ABC]) +echo AS_TR_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[ABC]]) +echo AS_TR_CPP(abc) AS_TR_CPP(aBc) AS_TR_CPP(ABC) +echo AS_TR_CPP([abc]) AS_TR_CPP([aBc]) AS_TR_CPP([ABC]) +echo AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]]) +echo === +[var=abc vAr=aBc VAR=ABC] +echo AS_TR_SH($var) AS_TR_SH($vAr) AS_TR_SH($VAR) +echo AS_TR_SH([$var]) AS_TR_SH([$vAr]) AS_TR_SH([$VAR]) +echo AS_TR_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$VAR]]) +echo AS_TR_CPP($var) AS_TR_CPP($vAr) AS_TR_CPP($VAR) +echo AS_TR_CPP([$var]) AS_TR_CPP([$vAr]) AS_TR_CPP([$VAR]) +echo AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]]) +echo === +var=abc vAr=aBc VAR=ABC +echo AS_TR_SH(`echo abc`) AS_TR_SH(`echo aBc`) AS_TR_SH(`echo ABC`) +echo AS_TR_SH([`echo abc`]) AS_TR_SH([`echo aBc`]) AS_TR_SH([`echo ABC`]) +echo AS_TR_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`echo ABC`]]) +echo AS_TR_CPP(`echo abc`) AS_TR_CPP(`echo aBc`) AS_TR_CPP(`echo ABC`) +echo AS_TR_CPP([`echo abc`]) AS_TR_CPP([`echo aBc`]) AS_TR_CPP([`echo ABC`]) +echo AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]]) +echo === +echo AS_TR_SH([a.b/c+*-]) +echo AS_TR_CPP([a.b/c+*-]) +var=a.b/c+*- +echo AS_TR_SH([$var]) +echo AS_TR_CPP([$var]) +]]) + +AT_CHECK_M4SH +AT_CHECK([$CONFIG_SHELL ./script], [], +[[hI aBc Hi +hI aBc Hi +abc aBc ABC +HI ABC HI +HI ABC HI +ABC ABC ABC +=== +abc aBc ABC +abc aBc ABC +abc aBc ABC +ABC ABC ABC +ABC ABC ABC +ABC ABC ABC +=== +hI aBc Hi +hI aBc Hi +abc aBc ABC +HI ABC HI +HI ABC HI +ABC ABC ABC +=== +a_b_cpp_ +A_B_C_P_ +a_b_cpp_ +A_B_C_P_ +]]) + +AT_CLEANUP + + ## ---------- ## ## AS_VAR_*. ## ## ---------- ## -- 1.7.1 _______________________________________________ Autoconf mailing list Autoconf@xxxxxxx http://lists.gnu.org/mailman/listinfo/autoconf