cscope:如何使用cscope使用命令行搜索符号?

kak*_*kyo 7 c c++ vim emacs cscope

我在网上找到的所有cscope教程都谈到了如何使用cscope的交互模式来搜索vim和emacs等编辑器中的符号.但我认为应该可以在终端发出命令来做类似的事情

cscope -d -some_options <my symbol>
Run Code Online (Sandbox Code Playgroud)

我应该能够在stdout中看到结果列表,而不必进入ncurse UI并在那里做所有事情.我认为这是可能的,因为"唯一"的前端cbrowser可以在其TclTK UI中执行类似的操作.但不幸的是,代码远远超出了我.

但是,我没有找到有关此功能的文档.

我是在做梦,还是有无证件的做法?

谢谢!

UPDATE

一些进展:如果我使用sub-dir结构制作一个包含少量文件的小项目.然后rici的答案开箱即用.使用更大的项目(数千个具有复杂文件夹结构的文件).即使cscope.out和cscope.files存在于项目文件夹的根目录(也是我当前的工作目录),我从同一个命令和相同的符号中得不到任何东西.我怀疑该命令存在可伸缩性问题.我也试过命令

cat cscope.files | xargs cscope -d -L1 <symbol> -i
Run Code Online (Sandbox Code Playgroud)

无济于事.

UPDATE

非常离奇!我试着用其他一些符号.原来,我正在搜索的特定符号无法使用命令行显示.但我试过的所有其他符号都有效.并且cbrowser找到"失败"符号没有问题.无论如何,我只是运气不好.我将在命令行中单独询问有关此异常的问题.

我认为里奇的答案是正确的.

ric*_*ici 20

你可能正在寻找这个:

cscope -L1<symbol>
Run Code Online (Sandbox Code Playgroud)

您也可以使用-d,但如果您正在修改文件,那么cscope更新它的数据库是有好处的.

-L表示"执行单个面向行的命令",并且下面的数字(1在这种情况下)也可以作为单独的选项编写,是特定的命令,该手册页混淆地称之为"字段"."字段"由交互式cscope提示给出; 为方便起见,我添加了数字."this"指的是数字后面的文字; 请记住,这是一种模式,因此您不一定要输入完整的符号.

 0 Find this C symbol:
 1 Find this function definition:
 2 Find functions called by this function:
 3 Find functions calling this function:
 4 Find this text string:
 5 Change this text string:
 6 Find this egrep pattern:
 7 Find this file:
 8 Find files #including this file:
Run Code Online (Sandbox Code Playgroud)


max*_*zig 6

您可以使用-R版本调用 cscope进行递归搜索。例如:

cscope -d -f/path/to/cscope.out -R -L1 some_symbol
Run Code Online (Sandbox Code Playgroud)

(搜索 some_symbol 的定义)

cscope -d -f/path/to/cscope.out -R -L3 some_symbol
Run Code Online (Sandbox Code Playgroud)

(显示调用 some_symbol 的所有位置)

-f如果 cscope.out 位于当前工作目录中,您可以省略该选项。

请注意,如果-R省略了索引符号,上述调用将产生零结果。非常旧的 cscope 版本不支持-R. 例如,版本 15.8a 确实支持它。

的可能值列表-L是:

0: Find this C symbol
1: Find this definition
2: Find functions called by this function
3: Find functions calling this function
4: Find this text string
6: Find this egrep pattern
7: Find this file
8: Find files #including this file
9: Find places where this symbol is assigned a value
Run Code Online (Sandbox Code Playgroud)

-R创建cscope.out文件时也可以使用该选项,例如:

cscope -bR
Run Code Online (Sandbox Code Playgroud)