Page 1 of 1
m4 macros
Posted: Thu Mar 31, 2005 7:15 am
by Neo
I need to define a few macros. These macros may have the text pattern that is same as the macro name inside them.
For e.g.
Code: Select all
define(`Fn1',`
Fn1: First line
Fn1: Second line
Fn1: Third Line
')
define(`Fn2',`
Fn2: First Line
Fn1: Second line
Fn1: Third Line
')
and when I call it like this
I get a screen that goes on printing blanks.
How do I do get this to work properly?
Re:m4 macros
Posted: Thu Mar 31, 2005 12:50 pm
by mystran
You need to prevent expansion. The m4 manual tells you that you can do this by quoting. Basicly, add some dummy `' around or inside the token you don't want to match as a macro name. Something like:
Code: Select all
define(`fn1',`
`fn1': First line
')
(oh, and I don't know any M4, just reading the manual here
)
Re:m4 macros
Posted: Fri Apr 01, 2005 5:49 am
by Neo
I did read that too. But used the wrong damn quotes.
Anyway there is a sort of problem. If I have many macros defined there and one of them has the text pattern that is the name of another macro, then I get into a nice jam.
Anyone has some idea for a workaround for this?
Re:m4 macros
Posted: Sat Apr 16, 2005 4:09 pm
by erikgreenwald
Hrm, I must be misunderstanding the current issue with his, because when I do
Code: Select all
define(Fn1,`
`Fn1': Plop
`Fn1': Splort
')
define(Fn2,`
`Fn2': Pop
`Fn1': Boom
`Fn1': Blammo
')
Fn1
Fn2
I get this out of m4...
Code: Select all
Fn1: Plop
Fn1: Splort
Fn2: Pop
Fn1: Boom
Fn1: Blammo
which seems to be what you're asking for?
-Erik
Re:m4 macros
Posted: Sat Apr 16, 2005 10:02 pm
by Neo
Which is perfectly correct.
Did you expect something else?
Re:m4 macros
Posted: Sun Apr 17, 2005 8:29 am
by erikgreenwald
Actually, it was completely expected... I was (and still am) trying to figure out exactly what you're looking for a workaround to?
-Erik
Re:m4 macros
Posted: Sun Apr 17, 2005 9:25 pm
by Neo
Neo wrote:
Code: Select all
define(`Fn1',`
Fn1: First line
Fn1: Second line
Fn1: Third Line
')
.....
I did not use quotes correctly. It is working fine now.