According to Chris Penev on 2/19/2010 8:56 PM: > Thanks for the report. Yes, double-quoting the first argument of > translit > would make the macro more robust. But this particular example was drawn > from a real-life example (on the gnulib list), where single-quoting was > sufficient for that context, under the assumption that no one will > use the > macro on a C function name that collides with a macro name. So I'm > debating between changing the example in situ, vs. adding a link to > another section in the final chapter on improved examples, to further > discuss that issue.
I want to get m4 1.4.14 out the door, so I went ahead and wrote this patch. I went with the in-place improvements. Thanks again for the report, which implies you were carefully reading the manual. -- Eric Blake ebl...@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
From bb29a1dc5aa04da98c1ea57082d4151ed8691b1c Mon Sep 17 00:00:00 2001 From: Eric Blake <ebl...@redhat.com> Date: Wed, 24 Feb 2010 16:20:45 -0700 Subject: [PATCH] Improve parsing example. * doc/m4.texinfo (Input processing): Double-quote argument to translit, for robustness. * THANKS: Update. Reported by Chris Penev. Signed-off-by: Eric Blake <ebl...@redhat.com> --- ChangeLog | 8 ++++++++ doc/m4.texinfo | 15 +++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84799d0..9c3e8f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-02-24 Eric Blake <ebl...@redhat.com> + + Improve parsing example. + * doc/m4.texinfo (Input processing): Double-quote argument to + translit, for robustness. + * THANKS: Update. + Reported by Chris Penev. + 2010-01-29 Eric Blake <e...@byu.net> Document upcoming release. diff --git a/doc/m4.texinfo b/doc/m4.texinfo index aec1d6a..db7aff4 100644 --- a/doc/m4.texinfo +++ b/doc/m4.texinfo @@ -1268,13 +1268,15 @@ Input processing to shell scripts, can be visually unappealing), and fixes the quoting issues so that the capitalization occurs when the macro @samp{gl_STRING_MODULE_INDICATOR} is invoked, rather then when it is -defined. +defined. It also adds another layer of quoting to the first argument of +...@code{translit}, to ensure that the output will be rescanned as a string +rather than a potential uppercase macro name needing further expansion. @example changequote([,])dnl define([gl_STRING_MODULE_INDICATOR], [dnl comment - GNULIB_[]translit([$1], [a-z], [A-Z])=1dnl + GNULIB_[]translit([[$1]], [a-z], [A-Z])=1dnl ])dnl gl_STRING_MODULE_INDICATOR([strcase]) @result{} GNULIB_STRCASE=1 @@ -1283,7 +1285,7 @@ Input processing The parsing of the first line is unchanged. The second line sees the name of the macro to define, then sees the discarded @sa...@key{nl}} and two spaces, as before. But this time, the next token is -...@samp{[dnl comm...@key{nl}@ @ GNULIB_[]translit([$1], [a-z], +...@samp{[dnl comm...@key{nl}@ @ GNULIB_[]translit([[$1]], [a-z], [A-Z])=1...@key{nl}]}, which includes nested quotes, followed by @samp{)} to end the macro definition and @samp{dnl} to skip the newline. No early expansion of @code{translit} occurs, so the entire @@ -1300,10 +1302,11 @@ Input processing not affect output. Then the token @samp{translit} is encountered. This time, the arguments to @code{translit} are parsed as @samp{(}, -...@samp{[strcase]}, @samp{,}, @samp{ }, @samp{[a-z]}, @samp{,}, @samp{ }, +...@samp{[[strcase]]}, @samp{,}, @samp{ }, @samp{[a-z]}, @samp{,}, @samp{ }, @samp{[A-Z]}, and @samp{)}. The two spaces are discarded, and the -translit results in the desired result @samp{STRCASE}. This is -rescanned, but since it is not a macro name, it is output literally. +translit results in the desired result @samp{[STRCASE]}. This is +rescanned, but since it is a string, the quotes are stripped and the +only output is a literal @samp{STRCASE}. Then the scanner sees @samp{=} and @samp{1}, which are output literally, followed by @samp{dnl} which discards the rest of the definition of @code{gl_STRING_MODULE_INDICATOR}. The newline at the -- 1.6.6.1
signature.asc
Description: OpenPGP digital signature
_______________________________________________ M4-patches mailing list M4-patches@gnu.org http://lists.gnu.org/mailman/listinfo/m4-patches