来自 Cscope (15.7a) 的帮助消息部分说明:
反复按 RETURN 键移动到所需的输入字段,键入
要搜索的图案,然后按 RETURN 键。对于前 4 和
最后 2 个输入字段,模式可以是 regcomp(3) 正则表达式。
如果搜索成功,您可以使用这些单字符命令:
所指的输入字段如下:
找到这个 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 项目,我有 2015 年 4 月的 Cscope 15.8b 的源代码。在目录 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 或更高版本中大多是新的。
另请参阅 SourceForge 的 Cscope Issue 294。它交叉引用了这个问题。