1

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?

Community
  • 1
  • 1
MageSlayer
  • 421
  • 4
  • 12

1 Answers1

2

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
  • 4,159
  • 10
  • 39
  • 63