m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Filter user macro invocation


From: Eric Blake
Subject: Re: Filter user macro invocation
Date: Wed, 30 Apr 2008 19:35:12 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080213 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

-----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 address@hidden 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             address@hidden
-----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-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]