Universal-ctags
$ git clone https://github.com/universal-ctags/ctags.git
$ cd ctags
$ ./autogen.sh
$ ./configure --prefix=/usr
$ make
$ sudo make install
gtags + gtags-cscope (global)
DL: Here (目前版本6.6.8, 往下找)
$ ./configure --with-universal-ctags=/usr/bin/ctags --prefix=/usr
$ make
$ sudo make install
$ cp /usr/local/share/gtags/gtags.conf ~/.gtags.conf (給vim用)
靠這些插件來使用
vim-gutentags
gutentags_plus
ref:
Vim 8 中 C/C++ 符号索引:GTags 篇
- E609: Cscope error:
似乎是整個的路徑如果有空白,比方說 "/home/user/Foo\ Bar/",這樣的話所產生的 cscope.out 就不能讀
- tags靠這些插件的設定,放在 ~/.cache/tags 要定期整理一下,會滿肥的
"----------------------------------------------"
"----------------------------------------------"
"----------------------------------------------"
"----------------------------------------------"
"----------------------------------------------"
Install
csope:
$ find ./ -type f -name "*.c" -o -name "*.h" -o -name "*.cpp" > cscope.files
$ cscope -Rbqk -i cscope.files
R : 將目錄及子目錄底下的所有文件都建立索引
b : 僅建立關聯數據庫,不導入使用者介面
q : 建立cscope.in.out和cscope.po.out,可增快搜尋速度
k : 不搜尋預設會include進來的函式(/usr/include)
vim command:
:cs help
cscope commands:
add : Add a new database (Usage: add file|dir [pre-path] [flags])
find : Query for a pattern (Usage: find c|d|e|f|g|i|s|t name)
c: Find functions calling this function
d: Find functions called by this function
e: Find this egrep pattern
f: Find this file
g: Find this definition
i: Find files #including this file
s: Find this C symbol
t: Find assignments to
help : Show this message (Usage: help)
kill : Kill a connection (Usage: kill #)
reset: Reinit all connections (Usage: reset)
show : Show connections (Usage: show)
:cs f g target_name
or
ctrl + [
ctrl + o
or
ctrl + ] ~ jump to function
ctrl + T ~ go back to function
Update cscope database
:cs reset
cstag:
$ ctags -R --exclude=.git
vim command:
1. :ts target_name
cs.sh
#!/bin/bash
function usageExit()
{
cat >&2 << EOF
cs.sh [options]
options:
-h, --help Show this menu
-s language monitor_path It will add more info attended in cscope.files, language: c, py, java
-r Remove the cscope.* and tags files in current folder
-e Stop the process
EOF
exit 0
}
function checkArgExit()
{
if [[ $# -lt 2 ]]; then
echo "Missing argument for option $1" >&2
exit 1
fi
}
START=0
END=0
REMOVE=0
P1=
P2=
# Parse arguments
if [ $# -lt 1 ]; then
usageExit
else
while [ -n "$1" ]; do
case "$1" in
-h|--help)
usageExit
;;
-s|--start)
checkArgExit $@
START=1
P1=$2 #language
P2=$3 #path
shift 3
;;
-e|--end)
END=1
shift 1
;;
-r|--remove)
REMOVE=1
shift 1
;;
*)
echo "Unknown option $1" >&2
echo >&2
usageExit
;;
esac
done
fi
function Main()
{
if [ ! -d ~/.tmp/ ];then
echo "mkdir"
mkdir ~/.tmp
fi
#echo P1=$1, P2=$2
if [ "$1" = "c" ] || [ "$1" = "cpp" ]; then
#echo "c and cpp"
find "$(pwd -P)" -name "*.h" -o -name "*.c" -o -name "*.cpp" -o -name "*.cc" >> ~/.tmp/cscope.files
elif [ "$1" = "py" ]; then
#echo python
find "$(pwd -P)" -name '*.py' >> ~/.tmp/cscope.files
elif [ "$1" = "java" ]; then
#echo java
find "$(pwd -P)" -name '*.java' >> ~/.tmp/cscope.files
else
echo "not support language"
fi
#R: Recurse directories for files (目錄下遞迴建立索引)
#b: Build the cross-reference only
#q: Build an inverted index for quick symbol searching (建立 cscope.in.out 和 cscope.po.out,以便增快搜尋速度)
#k: Kernel Mode - don’t use /usr/include for #include files (不索引 /usr/include)
#cscope -bqk
#ctags -R --exclude=.svn --exclude=.git
if [ -f ~/.tmp/cscope.files ];then
cd ~/.tmp/
cscope -bqk
ctags -R --exclude=.svn --exclude=.git --fields=+iaS --extra=+q $2
fi
sleep 10
if [ -f ~/.tmp/cscope.out ];then
mv cscope.* tags $2
sync
fi
cd $2
}
if [ "$START" -eq 1 ]; then
while true;
do
Main $P1 $P2
done
exit 1
fi
if [ "$END" -eq 1 ]; then
kill $(ps -ef | grep -v grep | grep 'bin/cs.sh' | awk -F " " 'NR==1 {print $2}')
exit 0
fi
if [ "$REMOVE" -eq 1 ]; then
rm -rf cscope.* tags
rm -rf ~/.tmp/cscope.*
exit 0
fi
usage:
$ cs.sh -s c /home/ubuntu/project1 &
$ cs.sh -e
沒有留言:
張貼留言