- Creating cscope database
- Creating ctags database
- Update cscope or ctags databse if they exist
- Clean cscope and ctags database
Usage under shell after the script is included
- run
run_cscope_ctags
to create database - run
clean_cscope_ctags
to clean database - run
run_cscope_ctags
while database exists to update database
Following are steps for using the script, enjoy it.
I. Install related tools
sudo apt-get install cscope
sudo apt-get install ctags
vim ~/.bashrc
append following script for establishing cscope and ctags databse# # Including cscope ctags script # source $HOME/path/you/place/run_cscope_ctags.sh
vim run_cscope_ctags.sh
paste following code in the script#!/bin/bash tags_update="n" tags_create="n" cscope_update="n" cscope_create="n" function make_ctags() { ctags_option="-R \ --exclude=.git \ --exclude=out \ --c++-kinds=+p \ --fields=+iaS \ --extra=+q ." ctags_option2="-R \ --exclude=.git \ --exclude=out \ --extra=+q ." if [ $1 == "update" ]; then ctags -o newtags $ctags_option2 rm -f tags mv newtags tags elif [ $1 == "create" ]; then ctags $ctags_option2 else echo Error: wrong ctags option, check the code exit 1 fi } function make_cscope() { find `pwd` -path ./out -prune \ -o -name "*.aidl" -exec echo \"{}\" \;\ -o -name "*.asm" -exec echo \"{}\" \;\ -o -name "*.s" -exec echo \"{}\" \;\ -o -name "*.S" -exec echo \"{}\" \;\ -o -name "*.h" -exec echo \"{}\" \;\ -o -name "*.c" -exec echo \"{}\" \;\ -o -name "*.cpp" -exec echo \"{}\" \;\ -o -name "*.cc" -exec echo \"{}\" \;\ -o -name "*.java" -exec echo \"{}\" \;\ -o -name "*.xml" -exec echo \"{}\" \;\ -o -name "*.dtsi" -exec echo \"{}\" \;\ -o -name "*.dts" -exec echo \"{}\" \;\ -o -name "*.rc" -exec echo \"{}\" \;\ -o -name "*.mk" -exec echo \"{}\" \;\ -o -name "*.sh" -exec echo \"{}\" \;\ -o -name "*.kl" -exec echo \"{}\" \;\ > cscope.files if [ $1 == "update" ]; then cscope -bkq -i cscope.files -f newcscope.out rm -f cscope.out cscope.out.in cscope.out.po mv newcscope.out cscope.out mv newcscope.out.in cscope.out.in mv newcscope.out.po cscope.out.po elif [ $1 == "create" ]; then cscope -bkq -i cscope.files -f cscope.out else echo Error: wrong cscope option, check the code exit 1 fi return 0 } # # Check ctags # function check_ctags() { if [ -f "tags" ]; then read -p "tags file exists, update it? (y/n) " tags_update if [ $tags_update = "y" ] || [ $tags_update = "Y" ]; then echo "tags is to update" elif [ $tags_update = 'n' ] || [ $tags_update = 'N' ]; then echo "tags not updated" else echo "wrong option, quit" exit 1 fi else read -p "tags does not exist, create new tags? (y/n) " tags_create fi } # # Check cscope # function check_cscope() { if [ -f "cscope.out" ]; then read -p "cscope.out exists, update it? (y/n) " cscope_update if [ $cscope_update = "y" ] || [ $cscope_update = "Y" ]; then echo "cscope files is to update" elif [ $cscope_update = 'n' ] || [ $cscope_update = 'N' ]; then echo "cscope files not updated" else echo "wrong option, quit" exit 1 fi else read -p "cscope.out does not exist, create new cscope.out? (y/n) " cscope_create fi } # # Create ctags and cscope # function create_ctags_cscope() { if [ $tags_create = "y" ] || [ $tags_create = "Y" ]; then echo "creating tags file" make_ctags "create"; echo "tags created" fi if [ $cscope_create = "y" ] || [ $cscope_create = "Y" ]; then echo "creating cscope.out" make_cscope "create"; echo "cscope.out created" fi } # # Update ctags and cscope # function update_ctags_cscope() { if [ $tags_update = "y" ] || [ $tags_update = "Y" ]; then echo "updating tags file" make_ctags "update"; echo "tags updated" fi if [ $cscope_update = "y" ] || [ $cscope_update = "Y" ]; then echo "updating cscope files" make_cscope "update"; echo "cscope.out updated" fi } # # Clean current database # function clean_ctags_cscope() { rm -f cscope.* ncscope.* tags } # # Main function # function run_cscope_ctags() { check_ctags; check_cscope; create_ctags_cscope; update_ctags_cscope; }
http://stackoverflow.com/questions/1932396/c-source-tagging
沒有留言:
張貼留言