Is it possible to have Cscope return search results for multiple C symbols at once ?
I have a huge project with a bunch of header(.h)
and .c
files and I want to find all instances of foo()
and bar()
( maybe more ) in my project at once.
Currently, when I do a cscope -d
, I am able to search for one C symbol at a time, but how can i do the following :
Find this C symbol: foo || bar
. ( This doesn't work )
So, in short I want the Cscope search to be able to work as a logical OR. How can this be achieved ?
The help message from Cscope (15.7a) says in part:
Press the RETURN key repeatedly to move to the desired input field, type the pattern to search for, and then press the RETURN key. For the first 4 and last 2 input fields, the pattern can be a regcomp(3) regular expression. If the search is successful, you can use these single-character commands:
and the input fields referred to are these:
Find this C symbol: Find this global definition: Find functions called by this function: Find functions calling this function: Find this text string: Change this text string: Find this egrep pattern: Find this file: Find files #including this file:
The regex matching doesn't apply to the two text string operations or the egrep
pattern. However, the help doesn't explicitly say that it uses extended regular expressions, though studying the source code shows that it does.
From the Cscope project at SourceForge, I have the source for Cscope 15.8b from April 2015. In the directory cscope-15.8b/src
is the file find.c
. In find.c
, at line 712ff, there is the code:
712 /* see if the pattern is a regular expression */
713 if (strpbrk(pattern, "^.[{*+$") != NULL) {
714 isregexp = YES;
715 } else {
If it spots one of the regex metacharacters listed, it uses extended regular expression mode. The trouble is, that list of characters does not include either |
or (
, both of which are metacharacters too.
When the code is changed to:
712 /* see if the pattern is a regular expression */
713 if (strpbrk(pattern, "^.[{*+$|(") != NULL) {
714 isregexp = YES;
715 } else {
and recompiled, then I can search for foo|bar
successfully. Without the change, cscope
reports that foo|bar
is not a valid C symbol — which is correct but not helpful.
A similar change may be beneficial if you can find the source code.
When I use Cscope 15.7a, even including one of the characters listed doesn't seem to turn on extended regular expressions, but it does allow simple (basic) regular expressions to work. For example, err_(remark|error)$
includes the $
, but doesn't match anything. Using err.*
does work; using err_[er][er][mo][ar]r.*
doesn't work. So, it seems that regex-support is mostly new in Cscope 15.8 or thereabouts.
See also Cscope Issue 294 at SourceForge. It cross-references this question.