Sunday, April 1, 2012

Applying filter to results in cscope

I had always wanted cscope to be a little more intelligent and let me specify the range of search results, which may be very handy when you are browsing a large project and want to look into a particular file instead of whole project. Of course one way is to put the results in a file and use your shell scripting skills (but do you really want to do that ??).

Googling didn't give any useful results, so I decided to spend my Sunday to do some useful work, and added support in cscope to apply filters to search. Here is what it can do currently.

a) Apply filename filter to your "Find C symbols"
b) You can tell cscope to not include the patterns from a particular file.
c) It supports logical OR (I didn't try other regex)

Snapshots below.

=> Search of i_nlink in linux codebase 500 instances like below

 => But I'm really interested in the places where its accessed in vfs_code. (Notice the message "(Filtered with : vfs)" at top.

=> Soon I realize, I was only interested in looking at header files (look at filter string at the top of screen)

=> Or not so, actually in only 'C' files.


=> I want all references from directory and lock files.

Download the source code from here and compile it as below.

a) ./configure
b) make
c) src/cscope -R

Njoy !!