need help with reinplace

Joshua Root jmr at macports.org
Sat Nov 3 00:10:30 UTC 2018


On 2018-11-3 10:23 , Helmut K. C. Tessarek wrote:
> I've been trying for hours now, but I'm not sure where the problem is.
> Either there's an issue with escaping or there's a bug somewhere. I know
> regex, but this is ridiculous. It's not working and I can't figure out why.
> 
> I want to replace the following line in configure.ac
> AC_INIT([tmux], next-2.9)
> with
> AC_INIT([tmux], next-2.9 (${version}))
> 
> The
> 
> reinplace -E "s|^AC_INIT\(\[tmux\],
> (next-\[0-9\]+\.\[0-9\]+)\)$|AC_INIT(\[tmux\], \\1 ${version})|g"
> ${worksrcpath}/configure.ac
> 
> With that I get an error message: invalid command name "0-9"
> 
> Weird, but ok. Then I tried to escape the [] character class brackets
> and got the following:
> Warning: reinplace s|^AC_INIT([tmux],
> (next-[0-9]+.[0-9]+))$|AC_INIT([tmux], \1 20181031-b1ad075)|g didn't
> change anything in ....
> 
> So it seems, it parses the grouping brackets as literal brackets and I'm
> really at a loss here.
> 
> What is going on?
> 
> With sed a working version would look like this:
> sed -E "s/AC_INIT\(\[tmux\], (next-[0-9]+\.[0-9]+)\)/AC_INIT([tmux], \\1
> (${version}))/g"
> 
> Anyhow, can someone please let me know what I am doing wrong and how to
> fix this?

This is one of those annoying situations in which more than one layer
needs escaping. Both the Tcl parser and sed assign a special meaning to
brackets and substitute backslash-escaped characters, so they need to be
protected from both. You could use braces to stop the Tcl parser from
substituting anything, but you do want to substitute ${version}.

This works:

set reinplace_cmd {s/AC_INIT\(\[tmux\],
(next-[0-9]+\.[0-9]+)\)/AC_INIT([tmux], \1 (}
append reinplace_cmd ${version} {))/g}
reinplace -E $reinplace_cmd ${worksrcpath}/configure.ac

And so does this:

set reinplace_cmd [subst -nobackslashes -nocommands
{s/AC_INIT\(\[tmux\], (next-[0-9]+\.[0-9]+)\)/AC_INIT([tmux], \1
(${version}))/g}]
reinplace -E $reinplace_cmd ${worksrcpath}/configure.ac

- Josh


More information about the macports-dev mailing list