|
From: | Nidhin Joseph |
Subject: | Re: Help on M4 Usage |
Date: | Fri, 29 Apr 2016 20:47:01 +0530 |
On 04/29/2016 08:56 AM, Nidhin Joseph wrote:
> Hi,
> I'm stuck with a doubt regarding M4 usage. I want M4 to identify quoted
> strings and replace the quotes along with the key.
>
> For example,
> I have a definition inside .m4 file as
> define_m4(MY_CUSTOM_KEY, 50 );
>
> And now in my source file, I have two funtion calls
> getApproximateValue(MY_CUSTOM_KEY);
> getApproximateValue("MY_CUSTOM_KEY");
>
> After running M4, what I'm expecting is
> getApproximateValue(50);
> getApproximateValue(50); //replace the quotes also
The only way to also replace the quotes is if the quotes are part of the
macro name (perhaps possible with the unreleased 2.0 branch of m4
playing games with syntax definitions of what makes a macro, but you'd
still have to define two macros, one named MY_CUSTOM_KEY and one named
"MY_CUSTOM_KEY", and it still won't help you if there is any whitespace
in the string alongside MY_CUSTOM_KEY).
It would also be possible to write an m4 macro named
getApproximateValue() that can do conditional things to its body (if the
body appears unquoted, keep it unquoted; if the body appears quoted,
then strip those quotes), but that's a new macro getApproximateValue()
and not something you can do with your existing MY_CUSTOM_KEY macro.
> But what I'm getting is simple macro expansion as shown below.
> getApproximateValue(50);
> getApproximateValue("50")
Indeed, that's all the more M4 is really capable of - expanding a macro
CANNOT affect the text that was contextually outside the bounds of the
macro name or () argument list.
>
> I understand, M4 is working as expected. Could you please help me to know
> whether my requirement is achievable without modifying the .M4 definition
> file?
I'm coming up blank; looks like you'll have to modify your .M4
definition file.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[Prev in Thread] | Current Thread | [Next in Thread] |