views:

28

answers:

2

I have been getting very frustrated recently in dealing with a massive bulk of legacy code which I am trying to get familiar with.

Say I try to search for a particular function call, I get loads of results that turn out to be completely irrelevant; some of them are easy to spot, eg a comment saying

// Fixed functionality in foo() so don't need to handle this here any more

But others are much harder to spot manually, because they turn out to be calls from other functions in modules that are only compiled in certain cases, or are part of a much larger block of code that is #if 0'd out in its entirety.

What I'd like would be a search tool that would allow me to search for a term and give me the choice to include or exclude commented out or #if 0'd out code. Then the search results would be displayed alongside a list of #defines that are required in order for that snippet of code to be relevant.

I'm working in C / C++, but other than the specific comment syntax I guess the techniques should be more generally applicable.

Does such a tool exist?

A: 

Not entirely what you're after, but I find this quite handy.

GrepWin - A free visual "grep" tool for searching files.

I find it quite helpful because:

  • Its a separate app (doesn't lock up my editor)
  • Handles Regular expressions
  • Its fast
  • Can specify what folder to search, and what filetypes (handles regex's here too)
  • Can limit by file size
  • Can include subdirs (or exclude by regex)
  • etc.
scunliffe
That is interesting, thank you!
Vicky
A: 

Almost any decent source browser will let you go to where a function is defined, and/or list all the calls of that function and take you directly to a call site. This will normally be based on a fairly complete parse of the source code so it will ignore comments, code that's excluded by the preprocessor, and so on (in fact, in at least one case, the parser used by the source browser is almost certainly better than the one used in the compiler itself).

Jerry Coffin
I normally use Visual Studio, but this is a legacy project which would be hard to get building in VS (correct me if I'm wrong, but don't you need to be able to actually build a project in VS to get the source browsing to work?) It was originally developed with some other tool that I don't have access to, and even if I did it's so old that I doubt it would have intelligent source browsing. Effectively what I have is a big mess of C / C++ source and header files. Are there really any source browsers (for Win or Linux) that could cope with that intelligently despite the lack of structure?
Vicky
@Vicky:that's open to some question. At least some of the source browsing in VS works without actually running the compiler -- they use a separate parser for the browsing than actual compiling. It still has to be something that can be parsed though, so working would depend on age and degree of grunginess.
Jerry Coffin