m4-discuss
[Top][All Lists]
Advanced

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

Re: Print literal $0 value


From: Grant Taylor
Subject: Re: Print literal $0 value
Date: Sat, 7 Jul 2018 19:15:51 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

On 07/07/2018 05:29 PM, Charlie Sale wrote:
Hello M4

Hi,

I am trying to write an m4 macro that has the literal $0 character in its expansion. Basically, I'm trying to do something like this:

define(`my_macro', `/$1/ { print $0 }')
my_macro(`foo')
--> /foo/ { print $0 }

Whenever I use the above macro, it turns into this unterminating recursive loop that re-expands the macro in the back. I am aware that the token $0 prints the name of the defined macro in M4, but I would like to print the literal characters instead. How can I do this?

Does the following do what you want?

define(`my_macro', `/$1/ { print $`'0 }')

Each additional `' delays expansion until the next round of parsing. So you could end up with something like this:

define(`my_macro', `/$1/ { print $````''''0 }')

What happens is the inner most `' is removed each parse cycle. So the above would only expand $0 on the 5th parsing cycle. (If you had that many.)

At least that's my understanding.



--
Grant. . . .
unix || die

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


reply via email to

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