用ctags为linux系统头文件生成systags

#!/bin/bash
# Program:
#   This program is used to generate system ctags for vim editor and auto add path for vim
#History:
# 2012/12/6     Kom     First release

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/~/bin
export PATH

# The ctags result will be store at /home/$(USER)/.vim/systags
systagsdirpath="/home/${USER}/.vim/"
systagspath="${systagsdirpath}systags"
#echo ${systagsdirpath}
#echo ${systagspath}

# detect specific directory is exist
# return:
#   0: exist
#   1: doesn't exist
#   2: parameters number error
function isdirexist()
{
    if [ $# -eq 0 ] || [ $# -gt 1 ]; then
        return 2
    fi
    if [ -d $1 ]; then
        return 0
    else
        return 1
    fi
}

#detect specific file is exist
#return:
#   0: exist
#   1: doesn't exist
#   2: parameters number error
function isfileexist()
{
    if [ $# -eq 0 ] || [ $# -gt 1 ]; then
        return 2
    fi
    if [ -e $1 ]; then
        return 0
    else
        return 1
    fi
}

# if the dir to store systags doesn't exist, create it
isdirexist ${systagsdirpath}
if [ $? == 1 ]; then
    echo -n "'"${systagsdirpath}"' doesn't exist, now create ... "
    mkdir ${systagsdirpath}
    isdirexist ${systagsdirpath}
    if [ $? == 0 ]; then
        echo "success."
    else
        echo "FAILED."
        return 1
    fi
else
    echo "'"${systagsdirpath}"' already exist."
fi

# if the systags file already exist, delete it
isfileexist ${systagspath}
if [ $? == 1 ]; then
    echo "'"${systagspath}"' doesn't exist."
else
    echo -n "'"${systagspath}"' already exist, now delete is ... "
    rm -fr ${systagspath}
    isfileexist ${systagspath}
    if [ $? == 1 ]; then
        echo "success."
    else
        echo "FAILED."
        return 1
    fi
fi

# now, generate tags file
echo -n "Now, generate system ctags for vim editor ... "
ctags -I __THROW -I __attribute__ -I __attribute_pure__ -I __nonnull --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p --c++-kinds=+p --fields=+iaS --extra=+q -R -f ${systagspath} /usr/include /usr/local/include
#ctags -I __THROW -I __attribute__ -I __attribute_pure__ -I __nonnull --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p --c++-kinds=+p --fields=+iaS --extra=+q -f ${systagspath} /usr/include/* /usr/include/sys/* /usr/include/bits/* /usr/include/netinet/* /usr/include/arpa/* /usr/include/mysql/*

echo "success."

# now, add it to the vim
echo -n "Now, add it to the vim ... "
echo "set tags+=${systagspath}" >> /home/${USER}/.vimrc
echo "success."

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值