Question

I am attempting to replace if with if( using GNU m4 1.4.14 and I am receiving ERROR: end of file in argument list when trying:

define(`if', `if(')
define(`then', `){')
define(`fi', `}')

if foo then bar() fi

I have tried escaping the parentheses but that caused m4 to error after a brief period of time saying it's out of memory. Scanning through the manual, I found nothing related to this problem.

Upon changing the name of the macro to 'IF' or something other than 'if', it works as expected, which leads me to believe it's evaluating itself repeatedly.

If so, how can I define a macro that is evaluated only once? Otherwise, what should I look into to fix this?

EDIT I found a way around this issue by processing twice, once to convert if to _IF and the next to convert _IF to if(. I assume there's a better way to do this, so this is only a temporary solution in my eyes.

Was it helpful?

Solution

You need to prevent m4 from attempting to re-expanding the replacements. Do so by double quoting:

define(`if', ``if('')
define(`then', `){')
define(`fi', `}')

if foo then bar() fi
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top