make m4 see macro when macro ends with same character as string following macro

人走茶凉 提交于 2020-01-04 14:20:53

问题


I'm working on a system that uses M4 to expand some files out, but I'm getting a problem with the expansion in certain cases. The convention for definition / macro naming (which I'd rather not change if possible) is __<name>__ (i.e. double leading and trailing underscores.) So this expands correctly:

define(`__ROOT__', `/home/mydir')
...
__ROOT__/bin

gives

/home/mydir/bin

but,

define(`__PREFIX__', `App_Mnemonic')
...
__PREFIX___some_service

should give:

App_Mnemonic_some_service

but gives

__PREFIX___some_service

(i.e. it missed the expansion)

I presume the lack of space between the trailing underscore of the macro and the valid underscore of the underlying text is confusing m4. Is there anything I can do about this? Can I delimit the macro with silent braces, for example, like enviromnment variables?


回答1:


Deceptively simple really, all I had to do in the underlying text was change this:

__PREFIX___some_service

for this:

__PREFIX__()_some_service

It looks a bit clunky perhaps, but it is a macro after all and there's no need to change the macro definition. So this can stay as it is:

define(`__PREFIX__', `App_Mnemonic')


来源:https://stackoverflow.com/questions/6814117/make-m4-see-macro-when-macro-ends-with-same-character-as-string-following-macro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!