国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
vim+cscope閱讀代碼的利器
來源: ChinaUnix博客  日期: 2008.09.26 13:39 (共有條評論)我要評論
下載地址:http://cscope.sourceforge.net
win32版本下載地址:http://iamphet.nm.ru/cscope/
vim配置文件腳本示例:http://cscope.sourceforge.net/cscope_maps.vim
目前就只能用這個鳥東西了,kscope搞不出來。。。。。
首先在目錄下建立cscope索引文件
find -name '*.c' > cscope.file
cscope -Rbkq
這個命令會生成三個文件:cscope.out, cscope.in.out, cscope.po.out。
其中cscope.out是基本的符號索引,后兩個文件是使用"-q"選項生成的,可以加快cscope的索引速度。
上面所用到的命令參數(shù),含義如下:
-R: 在生成索引文件時,搜索子目錄樹中的代碼
-b: 只生成索引文件,不進入cscope的界面
-k: 在生成索引文件時,不搜索/usr/include目錄
-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
接下來,就可以在vim里讀代碼了。
過在使用過程中,發(fā)現(xiàn)無法找到C++的類、函數(shù)定義、調(diào)用關(guān)系。仔細閱讀了cscope的手冊后發(fā)現(xiàn),原來cscope在產(chǎn)生索引文件時,只搜索類型為
C, lex和yacc的文件(后綴名為.c, .h, .l,
.y),C++的文件根本沒有生成索引。不過按照手冊上的說明,cscope支持c++和Java語言的文件。
于是按照cscope手冊上提供的方法,先產(chǎn)生一個文件列表,然后讓cscope為這個列表中的每個文件都生成索引。
為了方便使用,編寫了下面的腳本來更新cscope和ctags的索引文件:
#!/bin/sh
find . -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.files
cscope -bkq -i cscope.files
ctags -R
這個腳本,首先使用find命令,查找當前目錄及子目錄中所有后綴名為".h", ".c"和".cc"的文件,并把查找結(jié)果重定向到文件cscope.files中。
然后cscope根據(jù)cscope.files中的所有文件,生成符號索引文件。
最后一條命令使用ctags命令,生成一個tags文件,在vim中執(zhí)行":help tags"命令查詢它的用法。它可以和cscope一起使用。
cs help
find 的選項
0或則S:查找本符號
1或則G:查找本定義
2或則D:查找本函數(shù)調(diào)用的函數(shù)
3或則C:查找調(diào)用本函數(shù)的函數(shù)
4或則T:查找本字符串
6或則E:查找本EGREP模式
7或則F:查找本文件
8或則I:查找包含本文件的文件
熱后就可以在vim中使用cscope了,具體使用方法參考
//----------------------------------------------------------------------
  cscope是什么?
  為什么要使用cscope?
  如何使用cscope?
  下載
  安裝
  建立符號數(shù)據(jù)庫
  瀏覽源代碼
  命令行使用說明
  版權(quán)
  參考
  其他
cscope是什么?
†
cscope 是一個 C 語言的瀏覽工具,通過這個工具可以很方便地找到某個函數(shù)或變量的定義位置、被調(diào)用的位置等信息。目前支持 C 和
C++。cscope 自身帶一個基于文本的用戶界面,不過 gvim 提供了cscope接口,因此可以在 gvim 中調(diào)用
cscope,方便快捷地瀏覽源代碼。
為什么要使用cscope?
†
假設(shè)我們在讀一份很大的項目的源代碼。我們也許會需要進行如下操作。
函數(shù) foo() 調(diào)用了函數(shù) bar(),想看看函數(shù) bar() 的內(nèi)容。 想知道 foo() 在什么地方被調(diào)用。 想知道一個結(jié)構(gòu)類型的定義。
雖然在 Linux 下使用 grep 或者在 Windows 下使用文件查找功能也能找到想找的文件,但是效率太低了。有沒有什么更為方便快捷的方法?
這就需要用到cscope。gvim結(jié)合cscope,可以很方便地完成以上的操作,只需簡單地敲幾下鍵盤即可跳轉(zhuǎn)到想去的地方。
如何使用cscope?
†
下載
†
如果你使用的是Linux,那么恭喜你,很可能操作系統(tǒng)已經(jīng)為你提供了cscope工具。使用下面的命令確認它是否存在:
cscope -V
如果cscope工具已經(jīng)安裝,上面的命令將顯示cscope的版本號,類似于下面的結(jié)果:
cscope: version 16.0a
但是如果提示錯誤說找不到cscope命令,說明cscope尚未安裝。你可以到網(wǎng)上去尋找cscope的RPM包。另外,我們可以從
cscope官方網(wǎng)站
上下載到 cscope 的最新源代碼。在Linux下你可以編譯該源代碼生成cscope的可執(zhí)行文件。
如果你是Windows用戶,就沒有這么好的福氣了,因為在Windows下編譯程序并不是很簡單的事情。好在已經(jīng)有人為我們編譯好了Windows版,可以從這里下載到:
http://iamphet.nm.ru/cscope/
。
安裝
†
安裝很簡單,只要將cscope的可執(zhí)行文件放到PATH環(huán)境變量包含的目錄中即可。推薦Windows用戶將上面下載到的
cscope.exe 與 gvim 放在同一個目錄下,如 C:\Program Files\Vim\gvim64
下,然后單擊開始菜單選擇運行,輸入 cmd,啟動命令行提示符程序,執(zhí)行
cscope -V
如果能看到cscope的版本好則說明安裝成功。
另外,為了方便地使用cscope,我們還需要下載cscope的鍵盤映射設(shè)置,這樣就可以在gvim中簡單地通過快捷鍵來使用 cscope,而不必敲復(fù)雜的命令了。鍵盤映射可以從這里下載:
http://cscope.sourceforge.net/cscope_maps.vim
將下載到的 cscope_maps.vim 放在gvim的插件目錄里,如 C:\Program Files\Vim\vimfiles\plugin 中。Linux用戶可以放在 $HOME/.vim/plugin 中。
建立符號數(shù)據(jù)庫
†
我們假設(shè)我們要閱讀的代碼放在 D:\src\myproject 下。然后打開命令行,進入源代碼所在的目錄,為 cscope 建立搜索文件列表。在命令行中執(zhí)行以下命令:
dir /s /b *.c *.h  > cscope.files
如果你的源代碼是C++,則可以將 cpp 等擴展名也加入到上面的命令中。
dir /s /b *.c *.h *cpp *.hpp  > cscope.files
如果是Linux用戶,則可以使用 find 命令實現(xiàn)同樣的功能:
find $(pwd) -name "*.[ch]"
然后執(zhí)行以下命令:
cscope -b
執(zhí)行結(jié)束后你可以在當前目錄下發(fā)現(xiàn) cscope.out 文件,這就是 cscope 建立的符號數(shù)據(jù)庫。
上面這個命令中,-b參數(shù)使得cscope不啟動自帶的用戶界面,而僅僅建立符號數(shù)據(jù)庫。
瀏覽源代碼
†
使用 gvim 打開你的源代碼目錄中任意一個C程序文件。然后在gvim中執(zhí)行如下命令:
:cscope add D:\src\myproject\cscope.out
由于在 gvim 中可以使用命令縮寫,因此上面的命令可以寫成:
:cs a D:\src\myproject\cscope.out
這樣就打開了剛剛建立的符號數(shù)據(jù)庫。通過下面的命令可以檢查數(shù)據(jù)庫連接的存在。
:cscope show
該命令可以縮寫為
:cs s
現(xiàn)在將光標移動到源代碼中的某個函數(shù)名上,依次按下一下組合鍵:
s
稍等片刻之后你會在屏幕下放看到如下的字樣
*1
Cscope tag: display
#   line  filename / context / line
1    342  D:\src\myproject\src\global.h >
void display(void );
2    616  D:\src\myproject\src\command.c >
display();
3    138  D:\src\myproject\src\display.c >
display(void )
4    385  D:\src\myproject\src\main.c >
display();
5    652  D:\src\myproject\src\main.c >
display();
6    663  D:\src\myproject\src\main.c >
display();
Enter nr or choice ( to abort):
這里顯示出的就是整個工程中使用到了 display 這個標識符的位置。此時輸入 4,回車,即可跳轉(zhuǎn)到 main.c 的 385 行調(diào)用
display() 函數(shù)的地方進行瀏覽。瀏覽結(jié)束后按  或者  可以回到跳轉(zhuǎn)前的位置。
然后將光標移動到源代碼某個函數(shù)名上,迅速地依次安下面的組合鍵:
s
其中  按 Ctrl-2 即可輸入。同樣,屏幕上出現(xiàn)了一排結(jié)果,選擇之后你會發(fā)現(xiàn),跳轉(zhuǎn)到的文件將在水平方向的新窗口中打開。
然后將光標移動到源代碼某個函數(shù)名上,迅速地依次安下面的組合鍵:
s
選擇之后你會發(fā)現(xiàn),跳轉(zhuǎn)到的文件將在垂直方向的新窗口中打開。
以上我們簡單介紹了cscope的使用方法,其中我們只用到了一個 s 命令,即跟在  和  后面的 s 鍵。同樣,我們可以使用以下的功能鍵實現(xiàn)不同的跳轉(zhuǎn)功能。
c: 查找該函數(shù)被調(diào)用的位置 d: 查找該函數(shù)調(diào)用了哪些函數(shù) e: 查找指定的正規(guī)表達式 f: 查找指定的文件 g: 查找指定標識符的定義位置 i: 查找該文件在哪些地方被包含 s: 查找指定標識符的使用位置 t: 查找指定的文本字符串
命令行使用說明
†
除了上述通過快捷鍵映射的方式使用cscope之外,也可以直接在gvim命令行中使用cscope。這樣就可以隨意定義查找字符串,而不必局限于源代碼中已有的標識符。命令格式如下:
:cscope find
該命令可以縮寫為
:cs f
一個比較實用的技巧是使用cscope打開文件。使用以下命令即可直接打開名為display.c的文件,而不必先切換到display.c所在的目錄。
:cs f f display.c
cscope也支持正規(guī)表達式。如果記不清某個函數(shù)的名稱,可以用下面的方式來找到該函數(shù)的定義位置。
:cs f g .*SetConfiguration.*
版權(quán)
†
Cscope雖然不是GPL版權(quán),但是Cscope是開放源碼的自由軟件,使用Cscope無須支付任何費用。
參考
†
Cscope官方主頁,
http://cscope.sourceforge.net/
The Vim/Cscope tutorial,
http://cscope.sourceforge.net/cscope_vim_tutorial.html
Cscope on Win32,
http://iamphet.nm.ru/cscope/
Vim中關(guān)于 cscope 的幫助,使用 :help cscope 命令查看
其他
†
本文所需的cscope Win32版以及鍵盤映射配置等,在這里做了備份。萬一文章中提到的URL無法下載時,請使用以下的下載鏈接。
cscope 16.0a Win32版:
cscope-16.0a-win32.7static.zip
鍵盤映射配置:
cscope_maps.zip
//-------------------------------------------------------------------------
FreeBSD的ctags沒有-R選項,迫使我嘗試cscope,感覺比ctags強很多。
安裝:
#cd /usr/ports/devel/cscope
#make install clean
#cd /usr/ports/editors/vim
#make WITH_GTK2=yes WITH_CSCOPE=yes install clean
配置:
.vimrc
" An example for a vimrc file.
"
" Maintainer:   Bram Moolenaar
" Last change:  2002 Sep 19
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"             for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"           for OpenVMS:  sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather then Vi settings (much
" This must be first, because it changes other options as a side effect.
set nocompatible
set autowrite
set nu
set cindent shiftwidth=4
set softtabstop=4
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set autoindent
if has("vms")
set nobackup          " do not keep a backup file, use versions instead
else
set backup            " keep a backup file
endif
set history=50          " keep 50 lines of command line history
set ruler               " show the cursor position all the time
set showcmd             " display incomplete commands
set incsearch           " do incremental searching
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") = line("$") |
\   exe "normal g`\"" |
\ endif
augroup END
else
set autoindent                " always set autoindenting on
endif " has("autocmd")
:colo evening
if has("cscope")
set csprg=/usr/local/bin/cscope
" use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
set cscopetag
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != "
cs add $CSCOPE_DB
endif
set csverb
endif
使用:
在源碼書根目錄
#cscope -Rb
#vim xxx.c
然后就可以方便的ctrl+] ,ctrl + t 跳轉(zhuǎn)來。
//------------------------------------------------------------------
The Vim/Cscope tutorial
Cscope is a very handy tool, but it's even better when you don't ever have to
leave the comfort of your favorite editor (i.e. Vim) to use it.  Fortunately,
Cscope support has been built into Vim.
This tutorial introduces you both to Vim's built-in Cscope support, and to a
set of maps that make searching more convenient.
It is assumed you know the basics of using a vi-style editor, but you don't
need any particular knowledge about Vim (where Vim-specific features--like
multiple windows--are used, a working knowledge of the features is briefly
introduced).  You also don't need to know anything about Cscope: the basics are
introduced as we go along.
In a nutshell, Vim's Cscope support is very similar to Vim's
ctags
features,
in case you've used those.  But since Cscope has more search types than ctags,
there are a few differences.
This is a hands-on tutorial, so open up a shell, and follow these steps:
Get and install Cscope if you don't have it already on your machine.
Ideally, you will also have Vim 6.x, but you can get most of the
functionality with later versions of Vim 5 (vertical splits don't work, but
horizontal splits will work if you modify the maps as described in the
file's comments).
Note: If your version of Vim wasn't compiled with '--enable-cscope',
you will need to reconfigure and recompile Vim with that flag.  Most
Vim binaries that ship with Linux distributions have the Cscope
plugin enabled.
Download the
cscope_maps.vim
file, and
arrange for it to be read by Vim at startup time. If you are using Vim 6.x,
stick the file in your $HOME/.vim/plugin directory (or in any other 'plugin'
subdirectory in your 'runtimepath').  If you are using Vim 5.x, you can
either cut and paste the entire contents of the cscope_maps file into your
$HOME/.vimrc file, or stick a "source cscope_maps.vim" line into your .vimrc
file.
Go into a directory with some C code in it, and enter 'cscope -R'
(the '-R' makes Cscope parse all subdirectories, not just the current
directory).  Since we aren't passing the '-b' flag (which tells Cscope to
just build the database, then exit), you will also find yourself inside
Cscope's curses-based GUI.  Try a couple of searches (hint: you use the
arrow keys to move around between search types, and 'tab' to switch between
the search types and your search results).  Hit the number at the far left
of a search result, and Cscope will open Vim right to that location.
(unless you've set your EDITOR environment variable to something besides
Vim).  Exit Vim, and you'll be right back in the Cscope GUI where you left
off.  Nifty.
Alas, the Cscope interface has one big problem: you need to exit Vim each
time you want to do a new search.  That's where the Vim plugin comes in.
Hit CTRL-D to exit Cscope.
Start up Vim.  If you want, you can start it with a C symbol (ex:
'vim -t main'), and you should hop right to the definition of that symbol
in your code.
Put the cursor over a C symbol that is used in several places in your
program.  Type "CTRL-\ s" (Control-backslash, then just 's') in quick
succession, and you should see a menu at the bottom of your Vim window
showing you all the uses of the symbol in the program.  Select one of them
and hit enter, and you'll jump to that use.  As with ctags, you can hit
"CTRL-t" to jump back to your original location before the search (and you
can nest searches and CTRL-t will unwind them one at a time).
Mnemonic: the '\' key is right next to the ']' key, which is used for
ctags searches.
Try the same search, but this time via "CTRL-spacebar s".  This time,
your Vim window will split in two horizontally , and the Cscope search
result will be put in the new window. [if you've never used multiple Vim
windows before: move between windows via 'CTRL-W w' (or CTRL-W arrow key, or
CTRL-W h/j/k/l for left/up/down/right), close a window via 'CTRL-W c' (or
good old ':q'), make the current window the only one via 'CTRL-W o', split a
window into two via 'CTRL-W s' (or 'CTRL-W v' for a vertical split), open a
file in a new window via ':spl[it] filename']
Mnemonic: there's now a big, spacebar-like bar across the middle of your
screen separating your Vim windows.
Now try the same search via "CTRL-spacebar CTRL-spacebar s" (just
hold down the CTRL key and tap the spacebar twice). If you have trouble
hitting the keys fast enough for this to work, go into the cscope_maps.vim
script and change Vim's timeout settings as described in the comments
[actually, I generally recommend that you turn off Vim's timeouts].  This
time your Vim window will be split vertically (note: this doesn't work with
Vim 5.x, as vertical splits are new with Vim 6.0).
Up to now we've only been using the keystroke maps from
'cscope_maps.vim', which all do a search for the term that happens to be
under your cursor in Vim.  To do Cscope searches the old-fashioned way
(using Vim's built-in Cscope support), enter ":cscope find symbol foo" (or,
more tersely, ":cs f s foo").  To do the horizontal split version, use
":scscope" (or just ":scs") instead (Vim 6.x only).  While it's easier to
use the maps if the word you want to search for is under your cursor, the
command line interface lets you go to any symbol you type in, so you'll
definitely want to use it at times.
So far we've only been doing one kind of search: 's', for 'find all
uses of symbol X'.  Try doing one of Cscope's other searches by using a
different letter:  'g' finds the global definition(s) of a symbol, 'c'
finds all calls to a function, 'f' opens the filename under the cursor
(note: since Cscope by default parses all C header files it finds in
/usr/include, you can open up most standard include files with this).
Those are the ones I use most frequently, but there are others (look in the
cscope_maps.vim file for all of them, and/or read the Cscope man page).
Although Cscope was originally intended only for use with C code,
it's actually a very flexible tool that works well with languages like C++
and Java. You can think of it as a generic 'grep' database,
with the ability to recognize certain additional constructs like function
calls and variable definitions.  By default Cscope only parses C, lex, and
yacc files (.c, .h, .l, .y) in the current directory (and subdirectories, if
you pass the -R flag), and there's currently no way to change that list of
file extensions (yes, we ought to change that).  So instead you have to make
a list of the files that you want to parse, and call it 'cscope.files' (you
can call it anything you want if you invoke 'cscope -i foofile').  An easy
(and very flexible) way to do this is via the trusty Unix 'find' command:
find . -name '*.java' > cscope.files
Now run 'cscope -b' to rebuild the database (the -b just builds the database
without launching the Cscope GUI), and you'll be able to browse all the
symbols in your Java files.  Apparently there are folks out there using
Cscope to browse and edit large volumes of documentation files, which shows
how flexible Cscope's parser is.
For larger projects, you may additionally need to use the -q
flag, and/or use a more sophisticated 'find' command.  See our tutorial on
using Cscope with large projects for more info.
Try setting the $CSCOPE_DB environment variable to point to a Cscope
database you create, so you won't always need to launch Vim in the same
directory as the database. This is particularly useful for projects where
code is split into multiple subdirectories.  Note: for this to work, you
should build the database with absolute pathnames: cd to /, and do
find /my/project/dir -name '*.c' -o -name '*.h' > /foo/cscope.files
Then run Cscope in the same directory as the cscope.files file (or use
'cscope -i /foo/cscope.files'), then set and export the $CSCOPE_DB variable,
pointing it to the cscope.out file that results):
cd /foo
cscope -b
CSCOPE_DB=/foo/cscope.out; export CSCOPE_DB
(The last command above is for Bourne/Korn/Bash shells: I've forgotten how
to export variables in csh-based shells, since I avoid them like the
plague).
You should now be able to run 'vim -t foo' in any directory on your
machine and have Vim jump right to the definition of 'foo'.  I tend to write
little shell scripts (that just define and export CSCOPE_DB) for all my
different projects, which lets me switch between them with a simple 'source
projectA' command.
BUG: in versions of Cscope prior to
15.4, there is a silly bug that may cause Vim to freeze when you do this
unless you call your database something other than the default
'cscope.out': use '-f foo' in your Cscope invocation to name your
database 'foo.out' instead, and you'll be OK.
That's it! Use ":help cscope" (in Vim) and/or "man cscope" (from your
shell) if you've got questions, and to learn the fine points.
//==========================
CSCOPE
NAME
cscope - interactively examine a C program
SYNOPSIS
cscope
[ -bCcdehkLlqRTUuV ]
[-Fsymfile]
[-freffile]
[-Iincdir]
[-inamefile]
[-numpattern]
[-pn]
[-sdir]
DESCRIPTION
cscope
is an interactive, screen-oriented tool that allows the user to
browse through C source files for specified elements of code.
By default,
cscope
examines the C (.c and .h), lex (.l), and yacc (.y)
source files in the current directory.
cscope
may also be invoked for
source files named on the command line. In either case,
cscope
searches the standard directories for #include files that it does not
find in the current directory.
cscope
uses a symbol cross-reference,
cscope.out by default, to locate functions, function calls, macros,
variables, and preprocessor symbols in the files.
cscope
builds the symbol cross-reference the first time it is used on
the source files for the program being browsed. On a subsequent
invocation,
cscope
rebuilds the cross-reference only if a source file
has changed or the list of source files is different. When the
cross-reference is rebuilt, the data for the unchanged files are
copied from the old cross-reference, which makes rebuilding faster
than the initial build.
OPTIONS
The following options can appear in any combination:
-b
Build the cross-reference only.
-C
Ignore letter case when searching.
-c
Use only ASCII characters in the cross-reference file, that is,
do not compress the data.
-d
Do not update the cross-reference.
-e
Suppress the -e command prompt between files.
-F symfile
Read symbol reference lines from symfile. (A symbol reference
file is created by > and >>, and can also be read using the -f reffile
Use reffile as the cross-reference file name instead of the
default cscope.out.
-h
View the long usage help display.
-I incdir
Look in incdir (before looking in INCDIR, the standard place
for header files, normally /usr/include) for any #include files
whose names do not begin with ``/'' and that are not specified
on the command line or in namefile below. (The #include files
may be specified with either double quotes or angle brackets.)
The incdir directory is searched in addition to the current
directory (which is searched first) and the standard list
(which is searched last). If more than one occurrence of -I
appears, the directories are searched in the order they appear
on the command line.
-i namefile
Browse through all source files whose names are listed in namefile
(file names separated by spaces, tabs, or new-lines) instead of the
default (cscope.files). If this option is specified, cscope ignores
any files appearing on the command line. The argument namefile can be
set to ``-'' to accept a list of files from stdio.  Filenames in the
namefile that contain whitespace have to be enclosed in "double
quotes".  Inside such quoted filenames, any double-quote and backslash
characters have to be escaped by backslashes.
-k
``Kernel Mode'', turns off the use of the default include dir
(usually /usr/include) when building the database, since kernel
source trees generally do not use it.
-L
Do a single search with line-oriented output when used with the
-num pattern option.
-l
Line-oriented interface (see ``Line-Oriented Interface''
below).
-num pattern
Go to input field num (counting from 0) and find pattern.
-P path
Prepend path to relative file names in a pre-built
cross-reference file so you do not have to change to the
directory where the cross-reference file was built. This option
is only valid with the -d option.
-p n
Display the last n file path components instead of the default
(1). Use 0 to not display the file name at all.
-q
Enable fast symbol lookup via an inverted index. This option
causes cscope to create 2 more files (default names
``cscope.in.out'' and ``cscope.po.out'') in addition to the normal
database. This allows a faster symbol search algorithm that
provides noticeably faster lookup performance for large projects.
-R
Recurse subdirectories for source files.
-s dir
Look in dir for additional source files. This option is ignored
if source files are given on the command line.
-T
Use only the first eight characters to match against C symbols.
A regular expression containing special characters other than a
period (.) will not match any symbol if its minimum length is
greater than eight characters.
-U
Check file time stamps. This option will update the time stamp
on the database even if no files have changed.
-u
Unconditionally build the cross-reference file (assume that all
files have changed).
-V
Print on the first line of screen the version number of cscope.
The -I, -c, -k, -p, -q, and -T options can also be in the cscope.files file.
Requesting the initial search
After the cross-reference is ready, cscope will display this menu:
Find this C symbol:
Find this function definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:
Press the  or  keys repeatedly to move to the desired input
field, type the text to search for, and then press the  key.
Issuing subsequent requests
If the search is successful, any of these single-character commands
can be used:
0-9a-zA-Z
Edit the file referenced by the given line number.
Display next set of matching lines.
Alternate between the menu and the list of matching lines
Move to the previous menu item (if the cursor is in the menu)
or move to the previous matching line (if the cursor is in the
matching line list.)
Move to the next menu item (if the cursor is in the menu)
or move to the next matching line (if the cursor is in the
matching line list.)
+
Display next set of matching lines.
-
Display previous set of matching lines.
^e
Edit displayed files in order.
>
Write the displayed list of lines to a file.
>>
Append the displayed list of lines to a file.
Read lines from a file that is in symbol reference format
(created by > or >>), just like the -F option.
^
Filter all lines through a shell command and display the
resulting lines, replacing the lines that were already there.
|
Pipe all lines to a shell command and display them without
changing them.
At any time these single-character commands can also be used:
Move to next input field.
^n
Move to next input field.
^p
Move to previous input field.
^y
Search with the last text typed.
^b
Move to previous input field and search pattern.
^f
Move to next input field and search pattern.
^c
Toggle ignore/use letter case when searching. (When ignoring
letter case, search for ``FILE'' will match ``File'' and
``file''.)
^r
Rebuild the cross-reference.
!
Start an interactive shell (type ^d to return to cscope).
^l
Redraw the screen.
Give help information about cscope commands.
^d
Exit cscope.
NOTE: If the first character of the text to be searched for matches
one of the above commands, escape it by typing a  (backslash) first.
Substituting new text for old text
After the text to be changed has been typed, cscope will prompt for
the new text, and then it will display the lines containing the old
text. Select the lines to be changed with these single-character
commands:
0-9a-zA-Z
Mark or unmark the line to be changed.
*
Mark or unmark all displayed lines to be changed.
Display next set of lines.
+
Display next set of lines.
-
Display previous set of lines.
a
Mark or unmark all lines to be changed.
^d
Change the marked lines and exit.
Exit without changing the marked lines.
!
Start an interactive shell (type ^d to return to cscope).
^l
Redraw the screen.
Give help information about cscope commands.
Special keys
If your terminal has arrow keys that work in vi, you can use them
to move around the input fields. The up-arrow key is useful to move to
the previous
input field instead of using the  key repeatedly. If you have
, , or  keys they will act as the ^l, +, and -
commands, respectively.
Line-Oriented interface
The -l option lets you use cscope where a screen-oriented interface
would not be useful, for example, from another screen-oriented
program.
cscope will prompt with >> when it is ready for an input line starting
with the field number (counting from 0) immediately followed by the
search pattern, for example, ``lmain'' finds the definition of the
main function.
If you just want a single search, instead of the -l option use the -L
and -num pattern options, and you won't get the >> prompt.
For -l, cscope outputs the number of reference lines
cscope: 2 lines
For each reference found, cscope outputs a line consisting of the file
name, function name, line number, and line text, separated by spaces,
for example,
main.c main 161 main(argc, argv)
Note that the editor is not called to display a single reference,
unlike the screen-oriented interface.
You can use the c command to toggle ignore/use letter case when
searching. (When ignoring letter case, search for ``FILE'' will match
``File'' and ``file''.)
You can use the r command to rebuild the database.
cscope will quit when it detects end-of-file, or when the first
character of an input line is ``^d'' or ``q''.
ENVIRONMENT VARIABLES
CSCOPE_EDITOR
Overrides the EDITOR and VIEWER variables. Use this if you wish to use
a different editor with cscope than that specified by your
EDITOR/VIEWER variables.
CSCOPE_LINEFLAG
Format of the line number flag for your editor. By default, cscope
invokes your editor via the equivalent of ``editor +N file'', where
``N'' is the line number that the editor should jump to. This format
is used by both emacs and vi. If your editor needs something
different, specify it in this variable, with ``%s'' as a placeholder
for the line number.  Ex: if your editor needs to be invoked as
``editor -#103 file'' to go to line 103, set this variable to
``-#%s''.
CSCOPE_LINEFLAG_AFTER_FILE
Set this variable to ``yes'' if your editor needs to be invoked with
the line number option after the filename to be edited. To continue
the example from CSCOPE_LINEFLAG, above: if your editor needs to see
``editor file -#number'', set this environment variable. Users of most
standard editors (vi, emacs) do not need to set this variable.
EDITOR
Preferred editor, which defaults to vi.
HOME
Home directory, which is automatically set at login.
INCLUDEDIRS
Colon-separated list of directories to search for #include
files.
SHELL
Preferred shell, which defaults to sh.
SOURCEDIRS
Colon-separated list of directories to search for additional
source files.
TERM
Terminal type, which must be a screen terminal.
TERMINFO
Terminal information directory full path name. If your terminal
is not in the standard terminfo directory, see curses
and terminfo for how to make your own terminal description.
TMPDIR
Temporary file directory, which defaults to /var/tmp.
VIEWER
Preferred file display program (such as less), which overrides
EDITOR (see above).
VPATH
A colon-separated list of directories, each of which has the
same directory structure below it. If VPATH is set, cscope
searches for source files in the directories specified; if it
is not set, cscope searches only in the current directory.
FILES
cscope.files
Default files containing -I, -p, -q, and -T options and the
list of source files (overridden by the -i option).
cscope.out
Symbol cross-reference file (overridden by the -f option),
which is put in the home directory if it cannot be created in
the current directory.
cscope.in.out
cscope.po.out
Default files containing the inverted index used for quick
symbol searching (-q option). If you use the -f option to
rename the cross-reference file (so it's not cscope.out), the
names for these inverted index files will be created by adding
.in and .po to the name you supply with -f. For example, if you
indicated -f xyz, then these files would be named xyz.in and
xyz.po.
INCDIR
Standard directory for #include files (usually /usr/include).
Notices
cscope
recognizes function definitions of the form:
fname blank ( args ) white arg_decs white {
where:
fname
is the function name
blank
is zero or more spaces or tabs, not including newlines
args
is any string that does not contain a ``"'' or a newline
white
is zero or more spaces, tabs, or newlines
arg_decs
are zero or more argument declarations (arg_decs may include
comments and white space)
It is not necessary for a function declaration to start at the
beginning of a line. The return type may precede the function name;
cscope will still recognize the declaration. Function definitions that
deviate from this form will not be recognized by cscope.
The ``Function'' column of the search output for the menu option Find
functions called by this function: input field will only display the
first function called in the line, that is, for this function
e()
{
return (f() + g());
}
the display would be
Functions called by this function: e
File Function Line
a.c f 3 return(f() + g());
Occasionally, a function definition or call may not be recognized
because of braces inside #if statements. Similarly, the use of a
variable may be incorrectly recognized as a definition.
A
typedef
name preceding a preprocessor statement will be incorrectly
recognized as a global definition, for example,
LDFILE  *
#if AR16WR
Preprocessor statements can also prevent the recognition of a global
definition, for example,
char flag
#ifdef ALLOCATE_STORAGE
= -1
#endif
;
A function declaration inside a function is incorrectly recognized as
a function call, for example,
f()
{
void g();
}
is incorrectly recognized as a call to g.
cscope
recognizes C++ classes by looking for the class keyword, but
doesn't recognize that a struct is also a class, so it doesn't
recognize inline member function definitions in a structure. It also
doesn't expect the class keyword in a
typedef
, so it incorrectly
recognizes X as a definition in
typedef class X  *  Y;
It also doesn't recognize operator function definitions
Bool Feature::operator==(const Feature & other)
{
...
}
Nor does it recognize function definitions with a function pointer
argument
ParseTable::Recognize(int startState, char *pattern,
int finishState, void (*FinalAction)(char *))
{
...
}
//-----------------------------------------------------------------------------------------------------------
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/6889/showart_1226165.html
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Cscope在emacs中的配置與使用
如何將VIM配置成適用C語言的IDE
linux系統(tǒng)下用vim+ctags+cscope查看源碼
在你的 VSCode 里深夜放煙火
vim強大的g命令
VIM技巧之分隔窗口
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服