[Top][All Lists]

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

Re: How to patsubst the result of an include?

From: Gary V. Vaughan
Subject: Re: How to patsubst the result of an include?
Date: Mon, 07 Feb 2005 13:27:21 +0000
User-agent: Mozilla Thunderbird 0.9 (X11/20041103)

Hi Stepan,

Stepan Kasal wrote:
> On Fri, Feb 04, 2005 at 05:53:49PM +0000, Gary V. Vaughan wrote:
>>>     define(`include_orig', defn(`include'))
>>>     define(`include', `indirq(`include_orig', $1)')
> ...
>>Actually, with the attached implementation, that won't work because when
>>GNU M4 puts a file on the input stack (ala include) any partial string
>>that doesn't come from the stack is lost :-(  So it still doesn't solve
>>Matthew's problem.
> Do I understand correctly that
>       qindir(`include', `file')
> wouldn't work?

That depends what you mean by not work. Certainly the open and close quotes
added to the input stack by m4_qindir() are dropped and ignored:

$ echo 'a, b' > foo
$ m4
qindir(`include', `foo')
a, b

define(a, z)

qindir(`include', `foo')
z, b

a, b

But as you can see, undivert does the right thing here anyway.  I almost
made m4_qindir() recognise calls to m4_include() and redirect to
m4_undivert(), but that would be a hack so I restrained myself.  And in
anycase, the output of undivert is not rescanned, and doesn't help Matthew any
with sustituting the contents of a file:

patsubst(undivert(`foo'), `b', `x')
a, b

>  (And perhaps would even emit a spurious right quote string?)

No the right quote is lost too.

> Please let me discuss a problem which is not too much unrelated:
> the following code:
>       define(`x', -'-)
>       define(y, defn(`x'))
>       y
> expands to:
>       --'
> while I believe it should expand to:
>       -'-


> I think that there should be a special ``token type'' for treating defn
> and qindir: the token would carry a string, adn as soon as the token is
> expanded, it would immediately expand to the string.
> In other words, you'd place the string on the stack, but when m4 proceeds
> to do the next expansion of the string, it'd be somehow instructed to
> jump over the string (as if it would find a matching right quote there).
> Since we know the expansion will follow immediately, we could implement
> this hack via one global variable, which would tell the ``expand loop''
> that it should jump to the destination; the ``expand loop'' would clear
> the variable as soon as the message is received and the jump is done.

So that the expansion of a defn or qindir is never rescanned?  I guess
that is the case already for defn.  So far, so good...

> The result of this would be that
>       qindir(`include', `file')
> would include the file literally, even if it contains unmatched right
> quotes.

The implementation I wrote last week does that already, so I'm not sure
what this buys?  (except that it would fix your defn bug, above, of course)

$ echo "a-'-b" > foo
$ m4
define(a, z)dnl
qindir(`include', `foo')dnl
define(y, qindir(`include', `foo'))dnl

> What do you think?

I think that fixing the dropped quote bug in the stack handling, and running
with my existing implementation does the right thing without perturbing the
code so much...

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

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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