m4-discuss
[Top][All Lists]
Advanced

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

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


From: Eric Blake
Subject: Re: Process only sections of a file? (newbie)
Date: Fri, 17 Sep 2010 10:08:20 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Mnenhy/0.8.3 Thunderbird/3.1.3

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   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

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