Re: Strings to Macro

Eric Blake <[email protected]> Fri, 20 Jan 2017 17:12:33 -0600
Newsgroups gmane.comp.gnu.m4.general
Organization Red Hat, Inc.
Message-ID <[email protected]>
On 01/19/2017 09:50 PM, Varghese Paul wrote:
>  Hi all,
> 
> Nedd a help on the below program. How can i convert the formatted strings
> to MARCO ?. In the below program i am not able to replace the FORMATTED
> strings to macro.
> 
> 

> 
> forloop(`i', `1', APP_DOMAINS,
> ``VARIABLE_APP_PORT'i'

So you are trying to construct a macro name to be called, where each
iteration of the loop constructs another macro name.  The problem with
your approach is that there is no way to expand i without first parsing
over the string `VARIABLE_APP_PORT', making that text ineligible for
rescanning.  Sounds like you want to use indir:

forloop(`i', `1', APP_DOMAINS,
`indir(`VARIABLE_APP_PORT'i)'
)

Or, if you want to stick to straight POSIX m4, you'll have to write a
helper macro that concatenates two arguments and then scans the overall
result for a macro name:

define(`concat', `$1$2')dnl
forloop(`i',`1',APP_DOMAINS,
`concat(`VARIABLE_APP_PORT',i)'
)


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc (application/pgp-signature, 604 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJYgplhAAoJEKeha0olJ0Nq7YsIAK770RNcmLFS0kehIVSmAXjZ
o2S6363TpulKTa3XXVXzrz6tE10azahnMmH/Xc9wol1NwLzujQqllawB+2oFL/Cv
1ZIOtxI2ohVxGOK3s7miwnyinMMpdGNTbxIQvwWPQ03C9zGuNkyEZAa99WuCi4wO
4P7fve41VG2/YZoD0TI1X95f/MpKBFmVcyDNN0erZ3FJISp2T8429GVOozdo9B+p
u7dkKbwbHax6sTSCFH7rc+GqzKFbtVV0c/48xbq5w7XhMMjaD5qxm0xLavcic3Ng
Jxrx64MHUSCEIuws6OXXGNhcuVSsj090TGZZISC6Hyb2ak44dzQoId2QPf7irCw=
=DP0/
-----END PGP SIGNATURE-----