HELP! - Source code stripper using perl

Discussion in 'Perl Misc' started by Gamja, May 3, 2005.

  1. Gamja

    Gamja Guest

    Hi all.

    I need a source code stripper that removes some patterns from C or C++
    files. A file contains the patterns should be loaded on runtime. I
    want to remove all comments following "//" and my own decoration.
    Please recommend a proper regular expression to match the these
    patterns.

    What I want to do is as following.

    --BEFORE--
    AAA
    // debug begin
    my_own_debug_function(blah, blah, blah);
    ....
    // debug end
    BBB
    this_function_should_be_removed(a,
    b,
    c);
    CCC
    // debug begin
    DDD
    // debug end
    EEE
    --AFTER (line count of each line should be leaved as it is)--
    AAA




    BBB



    CCC



    EEE
    ---------

    Thanks in advance.

    Best regards,
    Gamja
     
    Gamja, May 3, 2005
    #1
    1. Advertising

  2. (Gamja) wrote in news:41c41b7.0505030752.4d3b8c57
    @posting.google.com:

    > What I want to do is as following.
    >
    > --BEFORE--
    > AAA
    > // debug begin
    > my_own_debug_function(blah, blah, blah);
    > ...
    > // debug end
    > BBB
    > this_function_should_be_removed(a,
    > b,
    > c);
    > CCC
    > // debug begin
    > DDD
    > // debug end
    > EEE
    > --AFTER (line count of each line should be leaved as it is)--
    > AAA
    >
    >
    >
    >
    > BBB
    >
    >
    >
    > CCC
    >
    >
    >
    > EEE


    use strict;
    use warnings;

    while(<DATA>) {
    if( m#^// debug begin# .. m#^// debug end# ) {
    print "\n";
    next;
    }

    if( /^this_function_should_be_removed\(/ ... /\);$/ ) {
    print "\n";
    next;
    }

    print;
    }

    __END__
    AAA
    // debug begin
    my_own_debug_function(blah, blah, blah);
    ....
    // debug end
    BBB
    this_function_should_be_removed(a,
    b,
    c);
    CCC
    // debug begin
    DDD
    // debug end
    EEE
     
    A. Sinan Unur, May 3, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PkingTom

    DCOM & email stripper

    PkingTom, Jul 28, 2003, in forum: C Programming
    Replies:
    2
    Views:
    352
    PkingTom
    Jul 29, 2003
  2. PkingTom

    Re: DCOM & email stripper

    PkingTom, Jul 29, 2003, in forum: C Programming
    Replies:
    1
    Views:
    310
    Bertrand Mollinier Toublet
    Jul 29, 2003
  3. MSmith

    Diary of a Stripper.

    MSmith, Mar 13, 2008, in forum: Java
    Replies:
    1
    Views:
    350
  4. MSmith

    Diary of a Stripper.

    MSmith, Mar 13, 2008, in forum: C Programming
    Replies:
    2
    Views:
    510
    Richard
    Mar 13, 2008
  5. funduk
    Replies:
    0
    Views:
    272
    funduk
    Nov 4, 2008
Loading...

Share This Page