You can even go one step further:?
?
pushdef(`define', `builtin(`define', `$1',?
~ `ifelse(`$#', `0', ``$1'', `$2')')')?
?
to make define always treat new macros like this. Hmm, maybe I should?
mention that in the manual.?


Oh... that's very clever. And is exactly what I was wanting to do orig. However 
I can't seem to make your example?work.
1) Is the tilda ~ really part of the syntax or is that a typo/email conversion 
problem?
2) Even when I remove the ~,?text?substitution seems to work but the instances 
without parens are also getting substituted. And thats the orig problem I was 
attempting to fix.
I would love to get your idea working !!

As an extension to you idea?I tried the following.....
define(`mydefine',`ifelse(`$#',`0',``$1'',`$2')')

Than when I "define" my user macros I use "mydefine" instead of "define" and it 
works?as expected. In my solution you have to be willing to use a unique name 
such as mydefine instead of redefining built in "define" itself. What is also 
interesting is that in my solution the my userMacros are never actually getting 
formal "define" cmds?in m4, it more of a conditional substitution on the fly.

In the end the idea of not having to place the ifelse structure into every 
userMacro define is great. And to that end I would love to see how to make both 
your and my solution work.



-----Original Message-----
From: Eric Blake <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]; m4-discuss@gnu.org
Sent: Wed, 30 Apr 2008 9:35 pm
Subject: Re: Filter user macro invocation


-----BEGIN PGP SIGNED MESSAGE-----?
Hash: SHA1?
?
[you should probably keep the list in the loop, as this is an interesting?
topic for other people to learn from]?
?
According to [EMAIL PROTECTED] on 4/30/2008 8:44 AM:?
| Thanks...?
| Using your clues I was able to find and comprehend the ifelse example. I?
| have now updated all my user-macro defines with the ifelse structure and?
| this now prevents general string text from causing a full substitution.?
?
You can even go one step further:?
?
pushdef(`define', `builtin(`define', `$1',?
~ `ifelse(`$#', `0', ``$1'', `$2')')')?
?
to make define always treat new macros like this. Hmm, maybe I should?
mention that in the manual.?
?
|?
| Do you have time for another??
| When the argument of a macro define spans multiple lines... is it?
| possible to to get the starting column for lines 2,3,... to line up with?
| the starting column of the 1st line. It appears that the 1st line starts?
| at the column at which the macroName was detected and that the?
| subsequent lines are added at newline col1. How do I force the later?
| lines to line up with the same starting col location as the 1st line in?
| the substituted output? I suspect this would require some sort?
| of location tracking tab/space function.?
?
According to wikipedia, m4 is Turing Complete, so yes this is possible.?
But determining how to do it, and whether it is possible to do?
efficiently, is another matter :)?
?
|?
| resulting output is ...?
| // export real CeffAvgLH_ ....?
| export real CeffAvgPwr_ ....?
|?
| I would like to some how get it to do...?
| // export real CeffAvgLH_ ....?
| export real CeffAvgPwr_ ....?
?
Autoconf tackles this with the m4_text_wrap macro, as part of the m4sugar?
wrapper around m4:?
http://git.sv.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/m4sugar/m4sugar.m4?
?
Look around line 1953. This is a very involved macro, with lots of?
involved work and preliminary macro definitions earlier in the file to?
make this pull off nicely. For help in understanding it, recall that?
m4sugar uses changequote([,]), and prefixes all builtins with m4_; the?
basic idea behind this macro is that it splits the original string at all?
whitespace, then outputs one word at a time with wrapping taken care of?
along the way.?
?
To be honest, m4sugar cheats a bit - it relies on a post-processing pass?
to strip trailing blanks and convert quadrigraphs. This task becomes even?
harder if you must handle unbalanced quotes in the output without a?
post-processing pass.?
?
- --?
Don't work too hard, make some time for fun as well!?
?
Eric Blake [EMAIL PROTECTED]
-----BEGIN PGP SIGNATURE-----?
Version: GnuPG v1.4.9 (Cygwin)?
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg?
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org?
?
iEYEARECAAYFAkgZHlAACgkQ84KuGfSFAYCHbgCfexkoeCFCkJIycfJKJnLksyhO?
d40AoKmTfmZQY/96Lj5ikyLq1GClxeB+?
=REwV?
-----END PGP SIGNATURE-----?

_______________________________________________
m4-discuss mailing list
m4-discuss@gnu.org
http://lists.gnu.org/mailman/listinfo/m4-discuss

Reply via email to