对于C头文件,可以防止像头文件的多次包含:你如何做一个ifdef后卫m4宏文件包括?
#ifndef MY_FOO_H
#define MY_FOO_H
[...]
#endif
我怎样才能做到同样的事情在M4,使得多个include()
到同一个文件宏调用只会造成内容被包括一次?
具体来说,我想这样做,包括使用宏changequote
(我不dnl
的杂波我的代码)的IFDEF后卫:
原来,当我这样做时,多夹杂物仍然会损坏报价:
changequote_file.m4:
ifdef(my_foo_m4,,define(my_foo_m4,1)
changequote([,])
)
changequote_invocation.m4:
include(changequote_file.m4)
After first include invocation:
[I should not have brackets around me]
`I should have normal m4 quotes around me'
include(changequote_file.m4)
After second include invocation:
[I should not have brackets around me]
`I should have normal m4 quotes around me'
调用与m4 changequote_invocation.m4
产量:
After first include invocation:
I should not have brackets around me
`I should have normal m4 quotes around me'
After second include invocation:
[I should not have brackets around me]
`I should have normal m4 quotes around me'
我认为这是正常情况下的工作,(并回答我的问题,所以谢谢!)。推文是我做了一些有点疯狂的事情,因为我们不能将m4解释为和'作为引号,因为下一个工具使用这些字符作为有效输入,并且我们不希望用户必须做另一个字符串转义。我试图导入一个执行'changequote'命令的文件,但只有'changequote'执行一次,无论执行多少次。无论如何,我会发布另一个问题,并让你挖掘出一些非常疯狂的老m4 hackery。 –
2011-03-18 20:46:04
因此,在您的changequote文件中使用上述内容。 – geekosaur 2011-03-18 20:48:52
啊,你已经扔下了战书。让我发布代码,看看你是否可以摧毁它:-) – 2011-03-18 21:16:03