[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.
From: |
Gary V. Vaughan |
Subject: |
Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265] |
Date: |
Thu, 21 Oct 2004 16:03:12 +0100 |
User-agent: |
Mozilla Thunderbird 0.8 (X11/20040913) |
Hi Noah,
Noah Misch wrote:
> On Wed, Oct 20, 2004 at 09:45:46PM +0100, Gary V. Vaughan wrote:
>
>
>> (func_quote_for_eval): Four space indent margin for functions!
>
>
> Does this deserve mention in HACKING?
Yes, good point. I'll do that presently.
>> +# Save mangling of backslash escaped dollars by the above. Running this
>> +# substitution after double_quote_subst notices and corrects expansion
>> +# of already escaped meta-chars. \$x -> double_quote_subst -> \\$x,
>> +# which doesn't protect $x from expansion. To correct this we do:
>> +# \\$x -> sed_double_backslash -> \\\$x, properly protecting $x.
>> +sed_double_backslash='s/\([[^\\]]\)\\\\$/\1\\\\\\$/g'
>
>
> I am glad you caught that. The first $ does need a \,
Oops. Thanks.
> and I believe the \ in
> the character class does not need one.
Although GNU sed may manage without (I haven't checked), BSD sed does need it
(otherwise \] becomes an atom, and the character class is then unterminated).
> That said, this substitution handles
> 'x\$y', but it does not seem to handle '\$y' (no non-backslash preceding
> character) or 'x\\\$y'. I believe this variant does so:
>
> # Re-`\' parameter expansions in output of double_quote_subst that were
> # `\'-ed in input to the same. If an odd number of `\' preceded a '$'
> # in input to double_quote_subst, that '$' was protected from expansion.
> # Since each input `\' is now two `\'s, look for any number of runs of
> # four `\'s followed by two `\'s and then a '$'. `\' that '$'. Note
> # that the embedded single quotes serve only to enhance readability.
> sed_double_backslash='s/\(\(^\|[^\]\)\(\\\\''\\\\''\)*\)''\\\\''\$/\1\\\\''\\''\$/g'
Indeed. Excellent idea. I hadn't thought of nesting capture groups like
that, and decided that multiple expressions to catch increasingly rare odd-
numbered backslash counts into $double_quote_subst wasn't worth the effort.
And I forgot about the left anchored \$x case altogether :-/
Unfortunately, alternation is not very portable (Apple's sed doesn't support
it at all), so we need two expressions. The following works for me. I'll
patch HEAD and branch-2-0 shortly if noone complains that it fails for them...
sed_double_backslash='
s/^\(''\\\\''\\\\''\)*''\\\\''\$/\1''\\\\''\\$/;
s/\([[^\\]]\(''\\\\''\\\\''\)*\)''\\\\''\$/\1''\\\\''\\$/g'
Cheers,
Gary.
--
Gary V. Vaughan ())_. address@hidden,gnu.org}
Research Scientist ( '/ http://tkd.kicks-ass.net
GNU Hacker / )= http://www.gnu.org/software/libtool
Technical Author `(_~)_ http://sources.redhat.com/autobook
signature.asc
Description: OpenPGP digital signature
- FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265], Gary V. Vaughan, 2004/10/20
- Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265], Noah Misch, 2004/10/20
- Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265],
Gary V. Vaughan <=
- Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265], Noah Misch, 2004/10/22
- Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265], Gary V. Vaughan, 2004/10/22
- Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265], Noah Misch, 2004/10/22
- Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265], Gary V. Vaughan, 2004/10/22
- Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265], Noah Misch, 2004/10/22
- Re: FYI: fix dollar handling in func_quote_for_expand [libtool--devo--1.0--patch-265], Gary V. Vaughan, 2004/10/22