C++ 如何为具有.c、.cpp和.h文件的项目使用cscope?
我正在从事一个需要了解编译器源代码的项目。为了浏览llvm的源代码,我尝试在源代码的根目录中使用cscope和以下命令: cscope-R*C++ 如何为具有.c、.cpp和.h文件的项目使用cscope?,c++,c,llvm,cscope,C++,C,Llvm,Cscope,我正在从事一个需要了解编译器源代码的项目。为了浏览llvm的源代码,我尝试在源代码的根目录中使用cscope和以下命令: cscope-R* 但它不起作用。因为主要有.cpp和.h文件,但也有一些.c文件。所以现在我不知道如何让cscope工作了?有人能帮忙吗?为了涵盖我们庞大的代码库,我有一个脚本,看起来有点像这样,用于构建cscope索引。我改为/的原因是,我有到源文件的完整文件路径,这使工作更加顺畅 cd / find -L /home/adrianc/code -name "*.c" -
但它不起作用。因为主要有.cpp和.h文件,但也有一些.c文件。所以现在我不知道如何让cscope工作了?有人能帮忙吗?为了涵盖我们庞大的代码库,我有一个脚本,看起来有点像这样,用于构建cscope索引。我改为/的原因是,我有到源文件的完整文件路径,这使工作更加顺畅
cd /
find -L /home/adrianc/code -name "*.c" -o -name "*.cc" -o -name "*.h" > /home/adrianc/code/cscope.files
cd /home/adrianc/code
/usr/local/bin/cscope -b -icscope.files -q -u
也可能值得一看
您可以使用以下命令从llvm源目录树的根目录执行所需任务:
touch tags.lst
find | grep "\.c$" >> tags.lst
find | grep "\.cpp$" >> tags.lst
find | grep "\.h$" >> tags.lst
cscope -i tags.lst
它将创建cscope.out文件,该文件与cscope一起用于浏览代码。希望有帮助 列出项目中所有
C++
文件的一种方便方法是使用该工具:一个为源代码搜索而优化的类似grep的命令(在某些发行版中,例如Ubuntu,该工具称为ack grep
)。您可以这样运行它:
ack -f --cpp > cscope.files
输出是指向所有
.cpp
,.h
,.cc
.hpp
文件的路径,因为这仍然是最流行的条目。stdin thingy可能是同时添加的,也可能不是,但它让它看起来很优雅:
find -regex '.*\.\(c\|h\|cpp\|cxx\|hh\|hpp\|hxx\)$' | cscope -i- -b -q
我的.bashrc中有以下内容,使事情变得更简单。运行
cscope\u build()
生成数据库,运行cscope
启动cscope工具
# Use vim to edit files
export CSCOPE_EDITOR=`which vim`
# Generate cscope database
function cscope_build() {
# Generate a list of all source files starting from the current directory
# The -o means logical or
find . -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" > cscope.files
# -q build fast but larger database
# -R search symbols recursively
# -b build the database only, don't fire cscope
# -i file that contains list of file paths to be processed
# This will generate a few cscope.* files
cscope -q -R -b -i cscope.files
# Temporary files, remove them
# rm -f cscope.files cscope.in.out cscope.po.out
echo "The cscope database is generated"
}
# -d don't build database, use kscope_generate explicitly
alias cscope="cscope -d"
做3次
find | grep
有点浪费。您完全可以将egrep
或grep-E
与单个find
:find一起使用-键入f-print | grep-E'\(c(pp)| h)$'>cscope.files
。是的,你是对的。实际上我写它是为了让事情更容易理解。但无论如何,这不是明智的做法。cscope-R'
或cscope$(find-iregex.+\.[chp]+')
我几乎觉得添加这一点很愚蠢,因为其他任何解决方案在质量上都没有问题,我通常不是那种“但管道需要一个过程”的人,但是find
可以很好地找到与模式匹配的文件:find-正则表达式“*\。\(c\|cpp\| h\)$”
。您只需要知道GNUfind
默认使用,这需要比通常更多的反斜杠,并且模式必须匹配整行,因此在开始时需要使用*
。请注意,您需要添加引号(“…”
)在tags.lst
中的文件路径周围,以防它们包含空格。谢谢您的回答!只需执行find-L-name“*.cc”-o-name“*.h”>cscope.files
就可以了。对于像我这样的懒惰用户来说:“sudo-apt-get-install-ack”得到我:“ack-Kanji-code-converter”,不是同一个工具。读了20秒后,我发现是‘sudo apt get install ack grep’