Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1036714
  • 博文数量: 164
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1336
  • 用 户 组: 普通用户
  • 注册时间: 2016-03-11 14:13
个人简介

狂甩酷拽吊炸天

文章分类

全部博文(164)

文章存档

2023年(1)

2022年(3)

2021年(4)

2020年(17)

2019年(37)

2018年(17)

2017年(35)

2016年(50)

分类: Python/Ruby

2020-08-07 19:06:03

原文地址:cscope 脚本及使用 作者:justyezhao

# cscope.sh
 
#!/bin/bash

LNX=$PWD

echo "generate cscope index files..."

cd $LNX
find $LNX                                                                       \
    -path "$LNX/arch/*" ! -path "$LNX/arch/arm*" -prune -o                      \
    -path "$LNX/arch/arm/mach-*" ! -path "$LNX/arch/arm/mach-pxa*"              \
                                 ! -path "$LNX/arch/arm/mach-mmp*"              \
                                 ! -path "$LNX/arch/arm/mach-tegra*" -prune -o  \
    -path "$LNX/arch/arm/plat-*" ! -path "$LNX/arch/arm/plat-pxa*" -prune -o    \
    -path "$LNX/include/asm-*" ! -path "$LNX/include/asm-arm*"                  \
                               ! -path "$LNX/include/asm-generic*" -prune -o    \
    -path "$LNX/tmp*" -prune -o                                                 \
    -path "$LNX/Documentation*" -prune -o                                       \
    -path "$LNX/scripts*" -prune -o                                             \
    -path "$LNX/patches*" -prune -o                                             \
    -path "$LNX/drivers/*" ! -path "$LNX/drivers/base*"                         \
                           ! -path "$LNX/drivers/char*"                         \
                           ! -path "$LNX/drivers/usb*"                          \
                           ! -path "$LNX/drivers/regulator*"                    \
                           ! -path "$LNX/drivers/mmc*"                          \
                           ! -path "$LNX/drivers/i2c*"                          \
                           ! -path "$LNX/drivers/power*"                        \
                           ! -path "$LNX/drivers/mspm_dyn*"                     \
                           ! -path "$LNX/drivers/gpio*"                         \
                           ! -path "$LNX/drivers/video*"                        \
                           ! -path "$LNX/drivers/tty*"                          \
                           ! -path "$LNX/drivers/serial*"                       \
                           ! -path "$LNX/drivers/rtc*"                          \
                           ! -path "$LNX/drivers/switch*"                       \
                           ! -path "$LNX/drivers/cpufreq*"                      \
                           ! -path "$LNX/drivers/cpuidle*"                      \
                           ! -path "$LNX/drivers/mfd*" -prune -o                \
    -name "*.[chxsS]" -print > $LNX/cscope.files

cscope -b -q -k
注释:
    find 命令是在当前代码树目录下搜索出目标文件,即将会被编译到的目录及文件,把这些文件及文件名存放到cscope.files文件中。
    -path 要搜索的目录名字符串。
    ! 表示取反。
    -prune 表示目录集合取反。
    -o 表示“or”与的意思,还有 -a 表示“and”或的意思。
    -name 表示搜索的文件类型,可用正则表达式过滤。
 
    -path "$LNX/arch/*" ! -path "$LNX/arch/arm*" -prune -o
    这一句没有括号,运算规则从前往后。-path "$LNX/arch/*"表示取出"$LNX/arch/*"集合;
    ! -path "$LNX/arch/arm*" 在前面的集合中去除"$LNX/arch/arm*" 后剩下的集合; -prune 把前面以所有集合取反,即只剩下"$LNX/arch/arm*" ;然后-o,与上后面类似的集合单元。
 
补充:
find还可以使用括号运算符,但是前面要加转义"\"
在dir0、dir1及子目录下查找txt后缀文件

find ./ \( -path './dir0*' -o -path './dir1*' \) -a -name *.txt -print

 
cscope:
 
cscope -b -q -k
一般应加上-i cscope.files,但是cscope会默认在cscope.files中的目录中建立索引所以这句可以省略。
-R: 在生成索引文件时,搜索子目录树中的代码
-b: 只生成索引文件,不进入cscope的界面
-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
-k: 在生成索引文件时,不搜索/usr/include目录
-i: 如果保存文件列表的文件名不是cscope.files时,需要加此选项告诉cscope到哪儿去找源文件列表。可以使用“-”,表示由标准输入获得文件列表。
 
在源码根目录下打开任意.c文件,使用如下命令:
    1. Ctrl+]将跳到光标所在变量或函数的定义处 Ctrl+T返回
    2. :cs find s ---- 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
      :cs find g ---- 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
      :cs find d ---- 查找本函数调用的函数
      :cs find c ---- 查找调用本函数的函数
      :cs find t: ---- 查找指定的字符串
      :cs find e ---- 查找egrep模式,相当于egrep功能,但查找速度快多了
      :cs find f ---- 查找并打开文件,类似vim的find功能
      :cs find i ---- 查找包含本文件的文
    3. 2的所以命令也可以且按銉来实现:
      1. Ctrl+\ 再按 s 表示:cs find s命令
      2. 同理实现cs find + g,d,c,t,e,f,i命令
  • 如果需要自动map快捷键,则需要在.vimrc中加入如下脚本代码:

    Download VIM's cscope plugin file: ;

    Save the cscope_maps.vim file into folder: /usr/share/vim/vim73/plugin/ or ~/.vim/plugin;

    而且如果你打开了 set cscopetag 选项,你就不再需要ctags了,原来的ctrl+J就变成和ctags一样的ctrl+],ctrl+t不变,vim -t 也可以用。

    set hlsearch
    set incsearch
    set smartindent
    set autoindent

    let Tlist_Ctags_Cmd = "/usr/bin/ctags --language-force=C"
    let Tlist_Inc_Winwidth = 1
    let Tlist_Exit_OnlyWindow = 1
    let Tlist_File_Fold_Auto_Close = 1
    let Tlist_Process_File_Always = 1
    let Tlist_Enable_Fold_Column = 0
    let Tlist_Show_One_File = 1
    "let tlist_php_settings = 'php;c:class;d:constant;f:function'
    nnoremap :Tlist

    if has("cscope")

        """"""""""""" Standard cscope/vim boilerplate

        " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
        set cscopetag

        " check cscope for definition of a symbol before checking ctags: set to 1
        " if you want the reverse search order.
        set csto=0

        " add any cscope database in current directory
        if filereadable("cscope.out")
            cs add cscope.out
        " else add the database pointed to by environment variable
        elseif $CSCOPE_DB != ""
            cs add $CSCOPE_DB
        endif

        " show msg when any other cscope db added
        set cscopeverbose


        """"""""""""" My cscope/vim key mappings
        "
        " The following maps all invoke one of the following cscope search types:
        "
        "   's'   symbol: find all references to the token under cursor
        "   'g'   global: find global definition(s) of the token under cursor
        "   'c'   calls:  find all calls to the function name under cursor
        "   't'   text:   find all instances of the text under cursor
        "   'e'   egrep:  egrep search for the word under cursor
        "   'f'   file:   open the filename under cursor
        "   'i'   includes: find files that include the filename under cursor
        "   'd'   called: find functions that function under cursor calls
        "
        " Below are three sets of the maps: one set that just jumps to your
        " search result, one that splits the existing vim window horizontally and
        " diplays your search result in the new window, and one that does the same

        " thing, but does a vertical split instead (vim 6 only).
        "
        " I've used CTRL-\ and CTRL-@ as the starting keys for these maps, as it's
        " unlikely that you need their default mappings (CTRL-\'s default use is
        " as part of CTRL-\ CTRL-N typemap, which basically just does the same
        " thing as hitting 'escape': CTRL-@ doesn't seem to have any default use).
        " If you don't like using or CTRL-\, , you can change some or all
        " of these maps to use other keys.  One likely candidate is 'CTRL-_'
        " (which also maps to CTRL-/, which is easier to type).  By default it is
        " used to switch between Hebrew and English keyboard mode.
        "
        " All of the maps involving the macro use '^$': this is so
        " that searches over '#include " return only references to
        " 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
        " files that contain 'time.h' as part of their name).


        " To do the first type of search, hit 'CTRL-\', followed by one of the
        " cscope search types above (s,g,c,t,e,f,i,d).  The result of your cscope
        " search will be displayed in the current window.  You can use CTRL-T to
        " go back to where you were before the search. 
        "

        nmap s :cs find s =expand("")
        nmap g :cs find g =expand("")
        nmap c :cs find c =expand("")
        nmap t :cs find t =expand("")
        nmap e :cs find e =expand("")
        nmap f :cs find f =expand("")
        nmap i :cs find i ^=expand("")$
        nmap d :cs find d =expand("")


        " Using 'CTRL-spacebar' (intepreted as CTRL-@ by vim) then a search type
        " makes the vim window split horizontally, with search result displayed in
        " the new window.
        "
        " (Note: earlier versions of vim may not have the :scs command, but it
        " can be simulated roughly via:
        "    nmap <C-@>s<> :cs find s =expand("")

        nmap <C-@>s<> :scs find s =expand("")
        nmap <
    C-@>g<> :scs find g =expand("")
        nmap <
    C-@>c<> :scs find c =expand("")
        nmap <
    C-@>t<> :scs find t =expand("")
        nmap <
    C-@>e<> :scs find e =expand("")
        nmap <
    C-@>f<> :scs find f =expand("")
        nmap <
    C-@>i<> :scs find i ^=expand("")$
        nmap <
    C-@>d<> :scs find d =expand("")


        " Hitting CTRL-space *twice* before the search type does a vertical
        " split instead of a horizontal one (vim 6 and up only)
        "
        " (Note: you may wish to put a 'set splitright' in your .vimrc
        " if you prefer the new window on the right instead of the left

        nmap <C-@>s<> :vert scs find s =expand("")
        nmap <
    C-@>g<> :vert scs find g =expand("")
        nmap <
    C-@>c<> :vert scs find c =expand("")
        nmap <
    C-@>t<> :vert scs find t =expand("")
        nmap <
    C-@>e<> :vert scs find e =expand("")
        nmap <
    C-@>f<> :vert scs find f =expand("")
        nmap <
    C-@>i<> :vert scs find i ^=expand("")$
        nmap <
    C-@>d<> :vert scs find d =expand("")


        """"""""""""" key map timeouts
        "
        " By default Vim will only wait 1 second for each keystroke in a mapping.
        " You may find that too short with the above typemaps.  If so, you should
        " either turn off mapping timeouts via 'notimeout'.
        "
        "set notimeout
        "
        " Or, you can keep timeouts, by uncommenting the timeoutlen line below,
        " with your own personal favorite value (in milliseconds):
        "
        "set timeoutlen=4000
        "
        " Either way, since mapping timeout settings by default also set the
        " timeouts for multicharacter 'keys codes' (like ), you should also
        " set ttimeout and ttimeoutlen: otherwise, you will experience strange

        " delays as vim waits for a keystroke after you hit ESC (it will be
        " waiting to see if the ESC is actually part of a key code like ).
        "
        "set ttimeout
        "
        " personally, I find a tenth of a second to work well for key code
        " timeouts. If you experience problems and have a slow terminal or network
        " connection, set it higher.  If you don't set ttimeoutlen, the value for
        " timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
        "
        "set ttimeoutlen=100

    endif     

    阅读(34642) | 评论(0) | 转发(0) |
    0

    上一篇:linux find 和grep

    下一篇:linux sed command

    给主人留下些什么吧!~~