是否可以让 Cscope 一次返回多个 C 符号的搜索结果?
我有一个包含一堆 header(.h)
和 .c
文件的大型项目,我想找到 foo()< 的所有实例
和 bar()
(可能更多)同时出现在我的项目中。
目前,当我执行 cscope -d
时,我可以一次搜索一个 C 符号,但我如何才能执行以下操作:
找到这个 C 符号:foo ||栏
。 (这不起作用)
所以,简而言之,我希望 Cscope 搜索能够用作逻辑或。如何实现?
最佳答案
来自 Cscope (15.7a) 的帮助消息部分说:
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:
所指的输入字段是这些:
找到这个 C 符号:
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:
正则表达式匹配不适用于两个文本字符串操作或 egrep
模式。然而,帮助没有明确说明它使用扩展的正则表达式,尽管研究源代码表明它确实如此。
在 SourceForge 的 Cscope 项目中,我有 Cscope 15.8b 的源代码从 2015 年 4 月开始。在目录 cscope-15.8b/src
中是文件 find.c
。在 find.c
的第 712ff 行,有代码:
712 /* see if the pattern is a regular expression */
713 if (strpbrk(pattern, "^.[{*+$") != NULL) {
714 isregexp = YES;
715 } else {
如果它发现列出的正则表达式元字符之一,它会使用扩展的正则表达式模式。问题是,该字符列表不包括 |
或 (
,它们也是元字符。
当代码更改为:
712 /* see if the pattern is a regular expression */
713 if (strpbrk(pattern, "^.[{*+$|(") != NULL) {
714 isregexp = YES;
715 } else {
并重新编译,然后我可以成功搜索foo|bar
。如果没有更改,cscope
报告 foo|bar
不是有效的 C 符号 — 这是正确的,但没有帮助。
如果您能找到源代码,类似的更改可能会有所帮助。
当我使用 Cscope 15.7a 时,即使包含列出的字符之一似乎也不会打开扩展正则表达式,但它确实允许简单(基本)正则表达式工作。例如,err_(remark|error)$
包含 $
,但不匹配任何内容。使用 err.*
确实有效;使用 err_[er][er][mo][ar]r.*
不起作用。因此,似乎正则表达式支持在 Cscope 15.8 或相关版本中大多是新的。
另见 Cscope Issue 294在 SourceForge。它交叉引用了这个问题。
关于c - 如何使用 cscope 一次搜索多个 C 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231149/