CSCOPE 安裝和使用方法總結

1, cscope安裝

        解壓:

        第一步:bzip2 -d  gcc-4.1.0.tar.bz2 
        ---上面解壓完以後執行下面的命令。

        第二步:tar -xvf gcc-4.1.0.tar 或 tar -xvf *.tar
        解完以後會出現多一個文件夾 gcc-4.1.0  php


   2. 軟件安裝: 
         1. ./configure --with-flex  (注:若是平臺是Linux,最好帶上 --with-flex選項)
         2. make  (注:我沒有遇到錯誤)
         3. make install (注: 直接安裝好了)

2,cscope配置

   1. 修改vim配置文件vimrc.你能夠修改/etc/vimrc使用全部用戶都使用本配置文件,固然你還能夠修改~/.vimrc
         1. 下載配置文件:cscope_map.vim  
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CSCOPE settings for vim           
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" This file contains some boilerplate settings for vim's cscope interface,
" plus some keyboard mappings that I've found useful.
"
" USAGE: 
" -- vim 6:     Stick this file in your ~/.vim/plugin directory (or in a
"               'plugin' directory in some other directory that is in your
"               'runtimepath'.
"
" -- vim 5:     Stick this file somewhere and 'source cscope.vim' it from
"               your ~/.vimrc file (or cut and paste it into your .vimrc).
"
" NOTE: 
" These key maps use multiple keystrokes (2 or 3 keys).  If you find that vim
" keeps timing you out before you can complete them, try changing your timeout
" settings, as explained below.
"
" Happy cscoping,
"
" Jason Duell       jduell@alumni.princeton.edu     2002/3/7
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


" This tests to see if vim was configured with the '--enable-cscope' option
" when it was compiled.  If it wasn't, time to recompile vim... 
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 'CTRL-@' 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 <cfile> macro use '^<cfile>$': this is so
    " that searches over '#include <time.h>" 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 <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>	
    nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>	


    " 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 <C-W><C-S> :cs find s <C-R>=expand("<cword>")<CR><CR>	

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


    " 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-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>	
    nmap <C-@><C-@>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>	
    nmap <C-@><C-@>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>


    """"""""""""" 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 <F1>), 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 <F1>).
    "
    "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
         2. 把cscope_map.vim裏從 if has("cscope")  到 endif裏邊的內容複製到/etc/vimrc裏邊去
         3. 裏邊的命令意思請看下邊文章

3,cscope使用

   1. 創建cscope使用的索引文件
         1. 在你須要瀏覽源碼的根目錄下(如你想用cscope看linux源碼)使用下面命令:
                * #: cscope -Rbkq<回車>
         2. R 表示把全部子目錄裏的文件也創建索引
         3. b 表示cscope不啓動自帶的用戶界面,而僅僅創建符號數據庫
         4. q生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
         5. k在生成索引文件時,不搜索/usr/include目錄
   2. 在源碼根目錄下打開任意.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命令
   3. cscope_map.vim說明:
         1. 有英文註釋的我就不說明了,我就說一下里邊的鍵map映射
         2. 如: nmap <C-\\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
               1. nmap 表示在vim的普通模式下,即相對於:編輯模塊和可視模式,如下是幾種模式
                     1.         :map            普通,可視模式及操做符等待模式
                                :vmap           可視模式
                                :omap           操做符等待模式
                                :map!           插入和命令行模式
                                :imap           插入模式
                                :cmap           命令行模式
               2. <C-\\>表示:Ctrl+\\
               3. s表示輸入(即按:s)s
               4. : 表示輸入\':\'
               5. 「cs find s"表示輸入"cs find s"也便是要輸入的命令
               6. <C-R>=expand("cword")整體是爲了獲得:光標下的變量或函數。cword 表示:cursor word, 相似的還有:cfile表示光標所在處的文件名吧
               7. <CR><CR>就是回車吧,不太清楚
相關文章
相關標籤/搜索