How to match newlines in GNU M4 _properly_

风流意气都作罢 提交于 2019-12-13 02:41:37

问题


I am trying to craft a macro replacing newlines.

My first try was:

    define(`m4_pascal_str',`
     patsubst(`$1',`^\(.*\)$',`\1++')
')

m4_pascal_str(`

11

22 33 44
')

define(zz,`

11

22 33 44
')
m4_pascal_str(`zz')

That gives correct answer when not using intermediate macro, and match only last newline otherwise. See results below:

 ++

++
11++
++
22 33 44++

++

11

22 33 44
++

Then I found similar question: in m4's patsubst, how do I replace newlines with spaces?

So, I just made:

define(`m4_pascal_str',`
     patsubst(`$1',`
',`++')
')

m4_pascal_str(`

11

22 33 44
')

define(zz,`

11

22 33 44
')
m4_pascal_str(`zz')

It gives:

 ++++11++++22 33 44++

11

22 33 44

The last alternative suffers the same problem. Any suggestions?


回答1:


For the last line try removing the quoting around the zz. When I did this I got the same result for both m4_pascal_str calls:

     ++
++
11++
++
22 33 44++
++




     ++
++
11++
++
22 33 44++
++


来源:https://stackoverflow.com/questions/3078827/how-to-match-newlines-in-gnu-m4-properly

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