本文主要是介绍生成cscope.out的bash脚本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
生成cscope.out的bash脚本,接收两个参数,第一个是源文件路径,第二个是存放cscope.out文件的目录名。
修改和make_find_arg()里面的FILETYPES和FILENAMES数组,就可以修改和增删cscope需要解析的文件。
#########################################################################
# File Name: makescope.sh
# Author: tintinr
# mail: tintinr@gmail.com
# Created Time: 日 8/ 4 10:51:38 2013
#########################################################################
#!/bin/bashmake_find_arg()
{# 文件类型,如*.cFILETYPES=("c" "cc" "cpp" "h" "mk" 'sh' "java" "S")# 文件名,如MakefileFILENAMES=("Makefile" "makefile")for each_file_type in ${FILETYPES[@]}doif [ -n "$find_arg" ]thensingle_find_arg=" -o "elsesingle_find_arg=""fisingle_find_arg+="-name \"*." single_find_arg+=$each_file_typesingle_find_arg+="\" "find_arg+=$single_find_argdonefor each_file in ${FILENAMES[@]}dosingle_find_arg=" -o -name \""single_find_arg+=$each_filesingle_find_arg+="\" "find_arg+=$single_find_argdone
}usage()
{echo "Usage: makescope src_path project_name"echo "==src_path: source root path"echo "==project_name: cscope db will be stored in ~/cscope/project_name/ dir"
}if [ $# -ne 2 ]
thenusagereturn -1
fisrc_path=$1
project_path=~/cscope/$2current_dir=$(PWD)
mkdir -p $project_path
cd $project_pathfind_arg=""
make_find_arg
echo "find" $src_path " " $find_arg
find_str="find "
find_str+=$src_path
find_str+=" "
find_str+=$find_arg
eval $find_str > cscope.files
cscope -bkq -i cscope.filescd $current_dir
功能虽然实现了,但是看上去有些丑,重构之:
#########################################################################
# File Name: makescope.sh
# Author: tintinr
# mail: tintinr@gmail.com
# Created Time: 日 8/ 4 10:51:38 2013
#########################################################################
#!/bin/bashmake_find_name_arg()
{file_prefix=$1declare -a file_types=("${!2}")for each_file in ${file_types[@]}doif [ -n "$find_arg" ]thensingle_find_arg="-o "elsesingle_find_arg=""fisingle_find_arg+="-name \""single_find_arg+=$file_prefixsingle_find_arg+=$each_filesingle_find_arg+="\" "find_arg+=$single_find_argdone
}make_find_arg()
{# 文件类型,如*.clocal FILETYPES=("c" "cc" "cpp" "h" "mk" 'sh' "java" "S")# 文件名,如Makefilelocal FILENAMES=("Makefile" "makefile")make_find_name_arg "*." FILETYPES[@]make_find_name_arg "" FILENAMES[@]
}build_ecsope_file()
{find_arg=""make_find_arg#echo "find" $src_path " " $find_argfind_str="find "find_str+=$src_pathfind_str+=" "find_str+=$find_argeval $find_str > cscope.files
}usage()
{echo "Usage: makescope src_path project_name"echo "==src_path: source root path"echo "==project_name: cscope db will be stored in ~/cscope/project_name/ dir"
}main()
{current_dir=$(PWD)mkdir -p $project_pathcd $project_pathbuild_ecsope_filecscope -bkq -i cscope.filescd $current_dir
}if [ $# -ne 2 ]
thenusagereturn -1
fisrc_path=$1
project_path=~/cscope/$2
main
在脚本验证过程中,貌似发现cscope两个限制:
1、文件名长度限制:最长只支持250个字符。
2、重复文件名的文件解析会失败。
这篇关于生成cscope.out的bash脚本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!