Is it possible to loop through the list of macro names given by dumpdef? I want to process certain macros which have a certain prefix in their name.


dumpdef writes the list of macros with their definition into a file. In standard m4, that file is standard error, so the only way to get at it is with a redirection that's external to the m4 script. GNU m4 provides the debugfile macro to redirect the output to a file which can be read back with input, but you can't rely on a specific implementation of m4 in autoconf.

Even if you manage to get hold at the output from dumpdef, the format of the output is not specified. You can use index and substr to break a string into lines, but that assumes that the implementation prints out one macro per line, which isn't guaranteed; furthermore, macro values can contain newlines. With GNU m4, the output is ambiguous: you can't distinguish

define(`foo', `hello')
define(`fooo', `world')


 define(`foo', `hello
 fooo:   world')

Assuming that the m4 implementation prints one macro per line and follows the name with a colon, you can gather potential macro names this way and use ifdef to check whether they are indeed macro names. But you're at the mercy of an implementation that doesn't use the same debugging print format.

The best way to solve your problem is probably outside m4.

| improve this answer | |
  • You're right, I need fix the higher layers so as not to put the burden of looping on m4. Thanks. – Rnet Dec 22 '14 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.