views:

239

answers:

4

How to make source code free of the following

  1. Remove dead codes that are more than few lines between /* c++ codes */
  2. Change more than one line breaks to one
  3. Remove modified user name and date /*-------- MODIFICATION DONE by xyz on ------------*/

I have used a code formatter tool to get a nice formatted code but stuck with code with above items.Is there any way to make sure codes like above doesn't get in to svn and automatically formatted code gets into the source.

A: 

Code Chameleon.. have u tried this

Dakshinamurthy
+1  A: 

You can use regular expression and Unix(Linux) command like sed | find | grep | awk | ... to edit code . see this page to understand regular expression .

SjB
I think there is some quote along the lines of: *When people have a problem they think "I know, I will use a regular expression"; now they have two problems.* Unfortunately regular expressions don't mix too well with most languages...
Matthieu M.
Agreed. Fortunately, for the purposes of this question, parsing full C++ isn't necessary, only parsing to the level of the C preprocessor is required (which, assuming your code doesn't use odd constructs, is pretty easy). A simple lexer/parser should be able to identify/remove the parts needed.
stusmith
A: 

#2 could be easily detected using regular expressions and rewritten automatically.

The other two options are somewhat more difficult. Unless these problems are extremely pervasive throughout the code base and are making it difficult to read the code, I'm not sure it's worth using a tool to try to clean it all up. Instead, remove the commented out code yourself as you're working on each file/module over time. This means that instead of relying on a tool to detect the correct code pieces to remove you're inspecting it yourself, improving reliability of the cleanup (and allows you to leave comments and clean up other code while you're there). Additionally since you're already modifying the file you should also be retesting the code as well. Finally this also prevents making commits that are just sweeping code reformatting.

Mark B
A: 

Have a look at gcov

Autopulated