在一个大的程序中,如果想快速了解这个程序的结构,那么cscope是必不可少的一个工具他的具体配置是:
1。在你想要查看的程序目录中建立一个cscope.file文件,命令:find . -name '*.cpp' -o -name '*.h' > cscope.files
2。命令:cscope -bq ,产成三个文件cscope.in.out、cscope.out、cscope.po.out
3。命令:ctags -L cscope.files 以后就可以用了
vimrc中要添加几行
" for cscope auto loading
if has("cscope")
set csprg=cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
nmap <C-/>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-/>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-/>d :cs find d <C-R>=expand("<cword>")<CR><CR>
endif
然后在用vi打开文件,光标停留在你想看的函数或者变量上,按ctrl+/ 之后在按 s/g/c/t/e/f/i/d之中的一个
s:
查找C语言符号,即查找函数名、宏、枚举值等出现的地方
g:
查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
d:
查找本函数调用的函数
c:
查找调用本函数的函数
t:
查找指定的字符串
e:
查找egrep模式,相当于egrep功能,但查找速度快多了
f:
查找并打开文件,类似vim的find功能
i:
查找包含本文件的文
查完后按ctrl+o 可以退回到原来查的那个文件