PDA

View Full Version : Search for patterns in source code



MiamiCuse
10-23-2005, 11:25 AM
I am using Visual Studio 6.0 and code is in C/C++. Commercial software with over 2000 source files scattered all over. Trying to get a handle on doing some estimates on various tasks.

Is there a way in VS6.0 that allows one to do "Find In Files..." with some complex search criteria?

For example, I would like to search for lines in files that contains the string "alloc" or "malloc" or "calloc" or "realloc" which does NOT contain the string "sizeof". Is there a way to do this?

I also would like to have a line count (how many lines are there in all these files when the search pattern matches), and a file count (how many files do these lines occured in).

If they can be configures to ignore lines that preceeds with "//" or in the middle of a /*...*/ block or even inside of a #if 0 ... #endif even better.

This is just one example, I need to do dozens of different searches to make an assessment on how bad the code is and decide whether we hack/patch or refactor or whatever.

Also we use CVS source code control which creates a admin directory with duplicate code that will double the count, is there a way to "include subfolder" but not to include subfolders of a specific name?

Thanks,

MC

dwks
10-23-2005, 12:07 PM
For example, I would like to search for lines in files that contains the string "alloc" or "malloc" or "calloc" or "realloc" which does NOT contain the string "sizeof". Is there a way to do this?
Try grep or perl or something similar.



I also would like to have a line count (how many lines are there in all these files when the search pattern matches), and a file count (how many files do these lines occured in).

I'm pretty sure you can do that with grep/perl.



If they can be configures to ignore lines that preceeds with "//" or in the middle of a /*...*/ block or even inside of a #if 0 ... #endif even better.

That's easy, too, in perl.


is there a way to "include subfolder" but not to include subfolders of a specific name?
You should be able to manage that, too.

MiamiCuse
10-23-2005, 04:17 PM
There is no way to do this within VS6? One benefit of doing it in that environment is I can pull up files selectively from the search results.

alphaoide
10-23-2005, 11:28 PM
In my VS.NET's "Find In Files...," you could select whether to use Regular Expression. Consult the VS6 help file if you could do the same thing.