Re: patsubst: multiline text

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.general
Organization Red Hat
Message-ID <[email protected]>
On 09/06/2010 09:57 AM, clemens fischer wrote:
> My problem is with the newlines in the text, I'm unable to match the
> portions before and after them.  I already tried a number of
> combinations, with and without literal newlines in {regex}, using eg.
> {^\(.+?\)\n} or {^\(.+?\)\\n} or {^\([^\\n]\)+} for {regex}, but the
> statements in m4.info referring to the emacs regex syntax seem to need
> qualification, so to speak.  I've also tried to "define({_nl_},<literal
> newline here>)" or using that literal directly, nothing helps.

Thanks for the question.

Unfortunately, there is admittedly a problem with the current regex 
implementation - it is line based, rather than argument based, so you 
can't really get at newlines directly.  Ultimately, the right fix is to 
add another argument to the various regex macros that lets you set flags 
(line vs. argument, case insensitive, maybe others?) for how a given 
regex will behave.

On the other hand, since it is all line based, it may be easier than you 
think.  First, note that this inserts spaces on every line:

patsubst({ml_text}, {^}, {  })

Then, if you concatenate text before the first line, then a second pass 
can clean up the first line:

patsubst({-}patsubst({{ml_text}}, {^}, {  }), {^-  }, {- })

(Untested, but hopefully gives you enough ideas).

-- 
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.