Jean-Marc Lasgouttes wrote:
> Andre> On Tue, Nov 30, 2004 at 10:29:34AM +0100, Jean-Marc Lasgouttes
> Andre> wrote:
>>> I would be willing to remove them if I had a good explanation of
>>> the trade off involved. I understand they got removed from
>>> 1.4.0cvs, but then they used to be a gain when they got added. Does
>>> that mean that only old compilers had a use for it?
> 
> Andre> Someone (Lars or I...) did some comparison a while ago and the
> Andre> outcome was that it was not worthwhile (anymore).
> 
> Yes, I found the thread, and it says that even with 2.95 there is no
> difference.
> 
> How do I write a script to remove them? Angus?

It was quite complex actually. Anyway, I think that the attached will do 
the trick. Use it something like:

$ for file in src/*.[Ch]
do
  sed -f pragma.sed trial.sed > tmp
  cmp -s $file tmp || {
    diff -u $file tmp
    mv -i tmp $file
  }
done

I've tested it with buffer.[Ch], which do contain the #pragma line within a
        #ifdef __GNUG__
        ...
        #endif
block and with BoostFormat.h, which contains stuff other than #pragma 
within this block. It works in both cases.

In all cases, the loop will ask you if you wish to overwrite the file, so 
it should be perfectly safe. So long as you remain awake...

-- 
Angus
/^[     ]*\#[   ]*ifdef[        ]\{1,\}__GNUG__/{
  :loop

# If we're not at the end of the script.
  $!{
    # Grab a new line of data and delete everything up
    # to the embedded newline
    N
    s/.*\n//

    # If this is the end of the #if ... #endif block
    /^[         ]*\#[   ]*endif/{
      # Move the contents of the hold space into the pattern space.
      # Empty the hold.
      s/.*//
      x
      s/^\n//

      # If the pattern space is not empty, then wrap it in
      # #ifdef __GNUG__ .... #endif
      /^$/!s/\(.*\)/#ifdef __GNUG__\
\1\
#endif/

      # Go to the end of the script.
      b
    }

    # We haven't reached the end of the #if ... #endif block.

    # if the line is #pragma {implementation,interface} then remove it
    /^[         ]*#[    ]*pragma[       ]\{1,\}interface[       ]*$/{
      s/.*//
      b continue
    }
    /^[         ]*#[    ]*pragma[       ]\{1,\}implementation[  ]*$/{
      s/.*//
      b continue
    }

    # The line contained something other than #pragma, so save it.
    H

    # Grab another line.
:continue
    bloop
  }
}

Reply via email to