生成cscope.out的bash脚本

来源:互联网 发布:mac的照片如何导出ipad 编辑:程序博客网 时间:2024/06/08 12:26

生成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 -1fisrc_path=$1project_path=~/cscope/$2current_dir=$(PWD)mkdir -p $project_pathcd $project_pathfind_arg=""make_find_argecho "find" $src_path " " $find_argfind_str="find "find_str+=$src_pathfind_str+=" "find_str+=$find_argeval $find_str > cscope.filescscope -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 -1fisrc_path=$1project_path=~/cscope/$2main

在脚本验证过程中,貌似发现cscope两个限制:

1、文件名长度限制:最长只支持250个字符。

2、重复文件名的文件解析会失败。

原创粉丝点击