Re: Process only sections of a file? (newbie)

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.general
Organization Red Hat
Message-ID <[email protected]>
On 09/17/2010 09:40 AM, Gary wrote:
> Eric Blake wrote:
>> On 09/15/2010 03:49 AM, Gary wrote:
>>> Sorry if this is obviously documented somewhere, but I couldn't find it
>>> (or perhaps found it and didn't understand it...).
>>>
>>> What I would like to do is only have m4 process certain sections of a
>>> file delimited by some given sequence (in my case outside<?php ... ?>
>>> tags). Is that possible?
>>
>> changecom(`<?php', `?>') will treat all<?php...?>  sequences as
>> comments, and thus not do any m4 processing of that portion of the text.
>
> Oh heck. TFM says "the first newline after a # ends the comment", so I
> don't think I can use this.

Only if you are using the default comment delimiters, which are '#' and 
'newline'.  But if you use changecom, then the comment delimiters are 
what YOU asked for, which can be '<?php' and '?>', without regards to 
newlines.

> I've got the problem that m4's include macro clashes with php's include
> statement. Any ideas how I can get around it? Could I, say, tell m4 that
> it should use #include instead of include?

Unfortunately, #include is not a valid macro name by default; if your 
version of m4 1.4.x was built with changeword support, then you can make 
that work, but changeword is an obsolete feature (to be replaced by 
changesyntax in the eventual m4 2.0) because it slows down m4 by an 
order of magnitude.

But what you CAN do is redefine m4 builtins to have a different name, so 
that they no longer clash with the rest of your text.  The manual gives 
several examples of this, but a short summary would be:

define(`m4include', defn(`include'))undefine(`include')
include(xyz) - php's include
m4include(`file') - m4's include

In fact, autoconf has invented the m4sugar wrapper language around m4, 
where all m4 macros have been redefined into the m4_ namespace, for this 
very reason.

-- 
Eric Blake   [email protected]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.