Programming, for all ages and all languages.
Neo
Member
Posts: 842 Joined: Wed Oct 18, 2006 9:01 am
Post
by Neo » Thu Mar 31, 2005 7:15 am
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?
Only Human
mystran
Post
by mystran » Thu Mar 31, 2005 12:50 pm
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
)
Neo
Member
Posts: 842 Joined: Wed Oct 18, 2006 9:01 am
Post
by Neo » Fri Apr 01, 2005 5:49 am
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?
Only Human
erikgreenwald
Post
by erikgreenwald » Sat Apr 16, 2005 4:09 pm
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
Neo
Member
Posts: 842 Joined: Wed Oct 18, 2006 9:01 am
Post
by Neo » Sat Apr 16, 2005 10:02 pm
Which is perfectly correct.
Did you expect something else?
Only Human
erikgreenwald
Post
by erikgreenwald » Sun Apr 17, 2005 8:29 am
Actually, it was completely expected... I was (and still am) trying to figure out exactly what you're looking for a workaround to?
-Erik
Neo
Member
Posts: 842 Joined: Wed Oct 18, 2006 9:01 am
Post
by Neo » Sun Apr 17, 2005 9:25 pm
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.
Only Human