tags:

views:

55

answers:

3

Hi,

I am having a look af a big C++ project with more than 100 files. Given a certain function name, how can one find just using bash tools like find or grep, the declaration and the defintion of a function?

Thanks

A: 

If you have the convention that the function definition starts at the beginning of a line, then you can use:

find . -exec egrep '^fn' '{}' ';' >/dev/null -print

if you want to limit to headers, you can put -name *.h before the -exec

NB if you want to do this a lot, look at "tags" and friends fire keeping an up-to-date index which would be faster in future.

AlBlue
A: 

Try ack, which is way better than grep. Color highlighting, the works...

$ ack funcion_name

Prints out all uses of function_name searching recursively through source files, it also is smart enough to ignore .svn and other metadata

Sam Post
A: 

in the very simplest case,

grep -ER '^.*(.*);' file  #find declaration.

as for definition, its a bit tricky if you want to get the whole defintion. (ie. from opening braces to closing). you might want to show what you want to get by using a sample C++ file

ghostdog74