-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbdb.sh
More file actions
executable file
·147 lines (114 loc) · 3.01 KB
/
bdb.sh
File metadata and controls
executable file
·147 lines (114 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/sh
prj_dir=~/prj
#*****************************************************************************************************************************************
#
#___________________________________FUNCTION
#
#*****************************************************************************************************************************************
create_cscope_db()
{
if [ -z "$1" ];then
exit 1
fi
src_dir=$1
db_name=cscope.out
if [ -z "$src_dir" ];then
echo "src_dir NULL"
exit 1
fi
target_dir=$prj_dir/`basename $src_dir`
if [ ! -d $target_dir ];then
mkdir -p $target_dir
fi
find $src_dir -type f \( -name "*.cc" -or -name "*.cpp" -or -name "*.c" -or -name "*.hpp" -or -name "*.h" \) > $target_dir/cscope.files
cscope -RbqU -i $target_dir/cscope.files -f$target_dir/$db_name
}
create_ctags_db()
{
if [ -z "$1" ];then
exit 1
fi
target_dir=$prj_dir/`basename $1`
if [ ! -d $target_dir ];then
mkdir -p $target_dir
fi
cscope_file=$target_dir/cscope.files
if [ ! -e $cscope_file ];then
echo "$cscope_file does not exist!!!"
exit 1
fi
ctags -R --c++-kinds=+px --fields=+iaS --extra=+q -f $target_dir/tags -L $target_dir/cscope.files
}
create_lookup_tag()
{
if [ -z "$1" ];then
exit 1
fi
src_dir=$1
target_dir=$prj_dir/`basename $src_dir`
if [ ! -d $target_dir ];then
mkdir -p $target_dir
fi
echo -e "!_TAG_FILE_SORTED\t2\t/2=foldcase/" > $target_dir/filetags
find $src_dir -type f \( -name "*.cc" -or -name "*.cpp" -or -name "*.hpp" -or -name "*.c" -or -name "*.h" -or -name "*.xml" \) -printf "%f\t%p\t1\n" | sort -f >> $target_dir/filetags
}
whether_delete_proj_dir()
{
if [ $# -lt 2 ];then
exit 1
fi
if [ -z "$1" ];then
exit 1
fi
target_dir=$prj_dir/`basename $1`
prompt=$2
if [ -z "$target_dir" ];then
echo "target_dir NULL"
exit 1
fi
yes_or_no="n"
if $prompt;then
read -p "Do you want to remove old database? " yes_or_no
fi
case $yes_or_no in
y|Y|yes|YES)
yes=true
;;
n|N|no|NO)
yes=false
;;
*)
echo "Invalid input"
exit 1
;;
esac
if $yes;then
rm -rf $target_dir
fi
}
create_index()
{
# Check if you installed cscope and ctags
if [ ! -e `which cscope` ]; then
echo "cscope is not installed. Please install first."
exit 0
fi
if [ ! -e `which ctags` ];then
echo "ctags is not installed. Please install first."
exit 0
fi
whether_delete_proj_dir $1 false
create_cscope_db $1
create_ctags_db $1
create_lookup_tag $1
}
#///////////////////////////////////////////////////////////////////////////////////////
#
# entry
#
#//////////////////////////////////////////////////////////////////////////////////////
if [ ! -d $prj_dir ];then
mkdir -p $prj_dir
fi
create_index $1
exit 0