[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
m4_quote [was: fix AT_SETUP's sh-escaping]
From: |
Eric Blake |
Subject: |
m4_quote [was: fix AT_SETUP's sh-escaping] |
Date: |
Wed, 25 Oct 2006 06:27:05 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Joel E. Denny on 10/25/2006 2:20 AM:
> On Mon, 23 Oct 2006, Paul Eggert wrote:
>
>> First, shouldn't that m4_dquote be m4_quote?
>
> As far as I can tell, m4_quote does nothing. That is, the quotes it adds
> are just stripped immediately upon return. I'm really not sure why
> m4_quote exists, but maybe I'm just missing something.
It exists for expanding relatively arbitrary parameters inside nested
macros. For example, in the upcoming M4 1.4.8 manual, I have the
following example of a foreach macro (converted here to m4sugar syntax):
# foreachq(x, `item_1, item_2, ..., item_n', stmt)
# quoted list, simple version
m4_define([foreachq], [m4_pushdef([$1])_foreachq($@)m4_popdef([$1])])
m4_define([_arg1], [$1])
m4_define([_foreachq], [m4_if(m4_quote($2), [], [],
[m4_define([$1], [_arg1($2)])$3[]$0([$1], [m4_shift($2)], [$3])])])
If you don't use m4_quote, then the unquoted expansion of $2 inside the
first argument of m4_if will lead to syntax errors if $2 contains unquoted
commas.
However, I don't recommend the above foreachq macro - it is quadratic in
behavior (the m4 1.4.8 manual documents it as an example of what not to
do, then provides a better solution later). Instead, use m4_foreach
already provided by m4sugar, which already solves the problem in a linear
fashion.
m4_quote still will not protect you from unquoted close parentheses, so if
your arbitrary text is likely to be a portable shell case statement, you
are already in quoting trouble. There is an item on the M4 2.0 todo list
to add a new builtin that can handle truly arbitrary text, regardless of
unquoted commas or close parentheses, but that has not been implemented yet.
- --
Life is short - so eat dessert first!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFP1gZ84KuGfSFAYARAjT5AKCp06GcjTwiBov6wMQakerI67xEQQCgn+NN
Z5k3YqvMjFfc3w64ezZjaEQ=
=VIJ+
-----END PGP SIGNATURE-----
- Re: fix AT_SETUP's sh-escaping, Joel E. Denny, 2006/10/22
- Message not available
- Message not available
- Re: fix AT_SETUP's sh-escaping, Paul Eggert, 2006/10/23
- Re: fix AT_SETUP's sh-escaping, Joel E. Denny, 2006/10/25
- m4_quote [was: fix AT_SETUP's sh-escaping],
Eric Blake <=
- Re: m4_quote [was: fix AT_SETUP's sh-escaping], Joel E. Denny, 2006/10/26
- Re: m4_quote [was: fix AT_SETUP's sh-escaping], Eric Blake, 2006/10/26
- Re: m4_quote, Paul Eggert, 2006/10/26
- Re: m4_quote, Joel E. Denny, 2006/10/26
- Re: m4_quote, Eric Blake, 2006/10/26
- Re: fix AT_SETUP's sh-escaping, Stepan Kasal, 2006/10/25
- Re: fix AT_SETUP's sh-escaping, Paul Eggert, 2006/10/25
- Re: fix AT_SETUP's sh-escaping, Joel E. Denny, 2006/10/26
- Re: fix AT_SETUP's sh-escaping, Stepan Kasal, 2006/10/26
- Re: fix AT_SETUP's sh-escaping, Joel E. Denny, 2006/10/26