tags:

views:

13

answers:

1

Hi

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: http://stackoverflow.com/questions/1567668/in-m4s-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  A: 

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++
++
waffleman