This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [fixincludes] work around non-GNU sed
- From: Bruce Korb <bkorb at gnu dot org>
- To: Gerald Pfeifer <gerald at pfeifer dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 09 Jan 2009 12:50:34 -0800
- Subject: Re: [fixincludes] work around non-GNU sed
- References: <alpine.LSU.1.99.0901091947400.12007@acrux.dbai.tuwien.ac.at>
- Reply-to: bkorb at gnu dot org
Gerald Pfeifer wrote:
> I am not proud of this patch, but -- it works, and gets us rid of
> a bogus test failure on FreeBSD since it only revolves around the
> replacement text we inject, not the actual fixing.
>
> Tested on i386-unknown-freebsd6.4.
>
> And for the record, multi-line sed expressions like this _do_ make
> my head hurt, too. ;-)
*I* think it's great! Also, be glad you're not playing with the original
multiple-10's-of-lines of sed hackery in the middle of millions of lines
of obtuse shell script (viz. the fixincludes script of 10 years ago....)
Anyway, I got to looking at this sed script and am wondering, "why use
sed at all?"
Fundamentally, you are replacing this:
> struct wedge {
> Widget old, new; /* fixinc check FAILS ON BSD */
> };
> extern Wedged( Widget new, Widget old );
with this:
> struct wedge {
> #ifdef __cplusplus
> Widget old, c_new;
> #else
> Widget old, new; /* fixinc check FAILS ON BSD */
> #endif
> };
> extern Wedged( Widget c_new, Widget old );
Which seems much more easily accomplished with two fixes:
select = "^([ \t]+Widget[ \t]+old,[ \t]+)(new;.*)\n";
c-fix = format;
c-fix-arg = <<- _EOF_
#ifdef __cplusplus
%1c_%2
#else
%0
#endif
_EOF_;
select = "(Widget[ \t].*[, \t])(new[^a-zA-Z0-9_])";
c-fix = format;
c-fix-arg = '%1c_%2';
It's two fixes, but avoids the fork and exec of sed, plus the
issues with incompatible sed programs. :)
I haven't tested this 'cuz I'm at my day job, but it looks like
it'd work to me....
Either is fine by me since neither will fire unless there's work
to be done.
Cheers - Bruce