DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

cscope(CP)


cscope -- interactively examine a C program

Syntax

cscope [-bcdelLqTuUV] [-f reffile] [-F symfile] [-i namefile] [-I incdir]
[-num pattern] [-p n] [-P path] [-s dir] [file . . . ]

Description

cscope(CP) is an interactive screen-oriented tool that helps programmers browse through C source code.

By default, cscope examines the C (.c and .h), yacc(CP) (.y), and lex(CP) (.l), source files in the current directory and builds a symbol cross-reference (cscope.out by default). It then uses this table to find references to symbols (including C preprocessor symbols), function declarations, and function calls.

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.

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 prompt generated by the <Ctrl>-E command.

-F symfile
Read symbol reference lines from symfile. (A symbol reference file is created by > and >>, and can also be read using the < command, described under ``Issuing subsequent requests'', below.)

-f reffile
Use reffile as the cross-reference filename instead of the default cscope.out.

-i namefile
Get the list of files (filenames separated by spaces, tabs, or newlines) to browse from namefile. By default, cscope scans the file cscope.files (if it exists and if no source files are given on the command line) to get the list of files. If this option is specified, cscope ignores any files appearing on the command line.

-I incdir
Look in incdir (before looking in INCDIR, the standard place for header files that is 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 above. (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.

-L
Do a single search with line-oriented output when used with the - num option.

-l
Line-oriented interface (see ``Line-Oriented Interface'' below).

-num pattern
Go to input field num (counting from 0 and can be any digit from 0 to 8 inclusive) and find pattern.

-P path
Prepend path to relative filenames 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 not to display the filename at all.

-q
Build an inverted index for quick symbol searching. If you use this option with the -f option, you must use -f on every call to cscope, including when you build the cross-reference file, because it changes the names of the inverted index 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
Do not check file time stamps (assume that no files have changed).

-u
Unconditionally build the cross-reference file (assume that all files have changed).

-V
Print on the first line of the screen the version number of cscope.
The -I, -p, -q, and -T options can also be specified 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 <Tab>, <Return>, <Ctrl>-N, or <Ctrl>-P key repeatedly to move to the desired input field, type the text to search for, and then press the <Return> key.

Issuing subsequent requests

If the search is successful, any of these single-character commands can be used:

1-9
Edit the file referenced by the given line number.

<Space>
Display next lines.

+
Display next set of matching lines.

-
Display previous set of matching lines.

<Ctrl>-E
Edit all lines.

>
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:


<Tab>
Move to next input field.

<Return>
Move to next input field.

<Ctrl>-M, <Ctrl>-N
Move to next input field.

<Ctrl>-P
Move to previous input field.

<Ctrl>-Y
Search with the last text typed.

<Ctrl>-B
Move to previous input field and search pattern.

<Ctrl>-F
Move to next input field and search pattern.

<Ctrl>-C
Toggle ignore/use letter case when searching. (When ignoring letter case, a search for FILE, for example, will match File and file.)

<Ctrl>-R
Rebuild the cross-reference.

!
Start an interactive shell (type <Ctrl>-D to return to cscope).

<Ctrl>-L
Redraw the screen.

?
Display this list of commands.

<Ctrl>-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 prompts for the new text, and then it displays the lines containing the old text. Select the lines to be changed with these single-character commands:

1-9
Mark or unmark the line to be changed.

*
Mark or unmark all displayed lines to be changed.

<Space>
Display next set of lines.

+
Display next set of lines.

-
Display previous set of lines.

a
Mark or unmark all lines to be changed.

<Ctrl>-D
Change the marked lines and exit.

<Esc>
Exit without changing the marked lines.

!
Start an interactive shell (type <Ctrl>-D to return to cscope).

<Ctrl>-L
Redraw the screen.

?
Display this list of commands.

Special keys

If your terminal has arrow keys that work in vi(C), 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 <Tab> key repeatedly. If you have <CLEAR>, <NEXT>, or <PREV> keys they will act as the <Ctrl>-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 prompts 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 will not 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 filename, 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 between ignoring and using letter case when searching. (When ignoring letter case, a search for FILE, for example, 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 <Ctrl>-D or q.

Environment variables


EDITOR
Preferred editor, which defaults to vi(C).

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(C).

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 pathname. If your terminal is not in the standard terminfo directory, see curses(S), terminfo(F), and terminfo(M) for how to make your own terminal description.

TMPDIR
Temporary file directory, which defaults to /var/tmp.

VIEWER
Preferred file display program (such as pg(C)), which overrides EDITOR (see above).

VPATH
An ordered list of directory names, separated by colons. It is used by cscope to search for both source and header files. 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. cscope searches for header files in the following order: if VPATH is set, in directories specified in VPATH, and if VPATH is not set, in the current directory, in directories specified by the -I option (if they exist), and in the standard location for header files (normally /usr/include).

Exit values

Upon successful completion, the exit status of cscope is 0, otherwise the exit status is non-zero.

Warnings

cscope recognizes function definitions of the form:

fname (args) arg_decs { ... }

where:


fname
is the function name, followed by zero or more spaces or tabs (except a newline character).

args
is any string that does not contain a double-quotation (") or a newline, followed by zero or more spaces or tabs.

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. For example, 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 *))
   {
           ...
   }

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 that it is 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.

ncscope.out
Temporary file containing the new cross-reference before it replaces the old cross-reference.

INCDIR
Standard directory for #include files (usually /usr/include).

See also

cc(CP), curses(S), terminfo(F), terminfo(M)

Standards conformance

cscope(CP) is not part of any currently supported standard; it was developed by UNIX System Laboratories, Inc. and is used by permission.
© 2003 Commands for Programming (CP)
SCO OpenServer Release 5.0.7 -- 11 February 2003