autoconf
[Top][All Lists]
Advanced

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

M4 String Functions + Macro Expansion


From: Noah Misch
Subject: M4 String Functions + Macro Expansion
Date: Thu, 16 Dec 2004 00:37:56 -0800
User-agent: Mutt/1.5.6i

How does one coax a string macro into considering a string, expanded?

Consider this macro:

# Foo(EXPRESSION)
# ---------------
# Emit expression with the right prologue.
m4_define([Foo],
[m4_bregexp([$1], [special], [Special prologue.])[]dnl
$1])

For maximum user flexibility, the emitted copy of $1 undergoes expansion.  We
should make the prologue decision based on the expansion of $1 also, since that
is what will actually appear in output.

The `[$1]' tolerates every string, but then m4_bregexp examines the literal
value of $1.  Plain `$1' lets $1 expand but cannot protect parentheses or
commas.  `m4_quote($1)' protects commas but not parentheses.  Something like
`m4_translit([$1], [(),], [/^!])' with corresponding adjustments to any patterns
expands $1 and handles parentheses and commas present in literal $1, but commas
and parentheses in the expansion of $1 still lose.

I tried `m4_expand_quoted([$1])' with this macro,

m4_define([m4_expand_quoted],
[m4_changequote(,)[m4_changequote([,])$1[]m4_changequote(,)]m4_changequote([,])])

but the M4 scanning rules make that ineffective; the same problems dogs
m4_noquote in this role.  Then I tried diversions:

m4_define([m4_expand_quoted],
[m4_divert(500)m4_changequote(,)[m4_changequote([,])$1[]dnl
m4_changequote(,)]m4_changequote([,])m4_undivert(500)])

That does not help, either; M4 does not rescan the undiverted text.  This?

m4_define([m4_expand_quoted],
[m4_syscmd([cat >myfile <<_m4eof]
m4_changequote(,)[m4_changequote([,])[]dnl
$1[]dnl
m4_changequote(,)]m4_changequote([,])
[_m4eof
])[]dnl
m4_include([myfile])[]dnl
])

No, the unquoted $1 in the call to m4_syscmd brings us to the original problem.

I hope I have missed a general solution.  Ideas?




reply via email to

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