[Top][All Lists]

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

Re: Is it possible to expand macro just once?

From: Eric Blake
Subject: Re: Is it possible to expand macro just once?
Date: Mon, 12 Oct 2020 07:24:22 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1

On 10/12/20 5:27 AM, Wolf wrote:

Not subscribed to the list, so please CC.

That's standard practice anyway ;)

I have m4 template that contains macro, that I do not know the value of
(provided by user). That can lead to user setting the macro to name of
another macro, like:

        $ echo foo | m4 -Dfoo=bar -Dbar=baz

Now, I understand why it happens and that it is expected. However, due
to reason stated above, I need the macro to expand just once, so that
the snippet above would produce `bar`. Is there a way to do so?

In general, if the user is providing you text rather than something that should expand as a macro that needs further recursive interpretation, you should use defn() to get at that text:

$ echo 'changequote([,])defn([foo])' | m4 -Dfoo=bar -Dbar=baz

But keep in mind that defn does NOT perform any interpolation of $, which may introduce its own oddities if the user supplied a macro definition containing $ that you aren't expanding as a macro.

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

reply via email to

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