HELP! - Source code stripper using perl

G

Gamja

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
 
A

A. Sinan Unur

(e-mail address removed) (Gamja) wrote in @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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top