CSCOPE(1)
π CSCOPE(1) β like, the General Commands Manual entry, bestie π
okay so first things first: this is the manual page for cscope, section 1 of the General Commands Manual. buckle up, she's a whole icon β¨
πΈ NAME πΈ
cscope β interactively examine a C program π«Ά
β¨ SYNOPSIS β¨
cscope [-bCcdehkLlqRTUuVvX] [-Fsymfile] [-freffile] [-Iincdir]
[-inamefile] [-0123456789pattern] [-pn] [-sdir] [files]
π DESCRIPTION π
cscope is an interactive, screen-oriented tool that lets you browse through C source files looking for specified elements of code. she's giving very much "search engine but for your codebase" energy π
By default, cscope examines the C (.c and .h), lex (.l), and yacc (.y) source files in the current directory. but like β cscope may also be invoked for source files named on the command line, so you're not stuck with just what's right there. in either case, cscope searches the standard directories for #include files that it doesn't find in the current directory. no cap, she goes looking π
cscope uses a symbol cross-reference, called cscope.out by default, to locate functions, function calls, macros, variables, and preprocessor symbols in the files. it's literally the main character of the whole operation π
cscope builds the symbol cross-reference the first time it's 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. the way that it doesn't just redo everything for no reason?? we stan an efficient queen π
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. lowkey genius, ngl β
πΈ OPTIONS πΈ (the flag buffet, bestie)
Okay so some command line arguments are absolute divas β they can only occur as the only argument in the execution of cscope. They cause the program to just print out some output and exit immediately:
-hβ View the long usage help display.-Vβ Print on the first line of screen the version number ofcscope.--helpβ Same as-h.--versionβ Same as-V.
The following options can appear in any combination β mix and match, no cap:
-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<Ctrl>-ecommand prompt between files.-Fsymfileβ Read symbol reference lines fromsymfile. (A symbol reference file is created by>and>>, and can also be read using the<command, described under ``Issuing Subsequent Requests'', below.)-freffileβ Usereffileas the cross-reference file name instead of the default"cscope.out".-Iincdirβ Look inincdir(before looking in$INCDIR, the standard place for header files, normally/usr/include) for any#includefiles whose names do not begin with/and that are not specified on the command line or innamefilebelow. (The#includefiles may be specified with either double quotes or angle brackets.) Theincdirdirectory 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-Iappears, the directories are searched in the order they appear on the command line.-inamefileβ Browse through all source files whose names are listed innamefile(file names separated by spaces, tabs, or new-lines) instead of the default name list file, which is calledcscope.files. If this option is specified, cscope ignores any file names appearing on the command line. The argumentnamefilecan be set to-to accept a list of files from the standard input. Filenames in thenamefilethat 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-numpattern option.-lβ Line-oriented interface (see ``Line-Oriented Interface'' below).-[0-9]patternβ Go to input field num (counting from 0) and find pattern.-Ppathβ Prependpathto 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-doption.-pnβ Display the last n file path components instead of the default (1). Use 0 not to 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 namescscope.in.out'' andcscope.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 during search for source files.-sdirβ Look indirfor 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β Be more verbose in line-oriented mode. Output progress updates during database building and searches.-Xβ Remove the cscope reference file and inverted indexes when exiting.filesβ A list of file names to operate on.
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:
Find assignments to this symbol:
Press the <Up> or <Down> keys repeatedly to move to the desired input field, type the text to search for, and then press the <Return> key. Very demure, very mindful navigation. π
π 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.<Space>β Display next set of matching lines.<Tab>β Alternate between the menu and the list of matching lines.<Up>β 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.)<Down>β 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-Foption.^β 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:
<Return>β 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 forFILEwill matchFileandfile.)^rβ Rebuild the cross-reference.!β Start an interactive shell (type^dto 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. Do not let the command characters catch you lacking. π
π 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.<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.^dβ Change the marked lines and exit.<Esc>β Exit without changing the marked lines.!β Start an interactive shell (type^dto 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 <Tab> key repeatedly. If you have <CLEAR>, <NEXT>, or <PREV> keys they will act as the ^l, +, and - commands, respectively. Keyboard shortcuts are giving main character energy. β¨
π 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. No pop-up editor jumpscare, we love that for us. π«Ά
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. Exit gracefully, bestie. β
π ENVIRONMENT VARIABLES π
These are the environment variables cscope actually peeks at, bestie β every single one matters, no skipping π
CSCOPE_EDITORβ overrides theEDITORandVIEWERvariables. Use this if you want a different editor withcscopethan the one yourEDITOR/VIEWERvariables say.CSCOPE_LINEFLAGβ the format of the line number flag for your editor. By default,cscopeinvokes your editor via the equivalent ofeditor +N file, whereNis the line number the editor should jump to. This format is used by bothemacsandvi. If your editor needs something different, put it in this variable, with%sas the placeholder for the line number. Example: if your editor needs to be invoked aseditor -#103 fileto go to line 103, set this variable to-#%s.CSCOPE_LINEFLAG_AFTER_FILEβ set this variable toyesif your editor needs to be invoked with the line number option after the filename to be edited. Continuing the example fromCSCOPE_LINEFLAGabove: if your editor needs to seeeditor 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 tovi.HOMEβ home directory, which is automatically set at login.INCLUDEDIRSβ colon-separated list of directories to search for#includefiles.SHELLβ preferred shell, which defaults tosh.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 standardterminfodirectory, seecursesandterminfofor how to make your own terminal description.TMPDIRβ temporary file directory, which defaults to/var/tmp.VIEWERβ preferred file display program (such asless), which overridesEDITOR(see above).VPATHβ a colon-separated list of directories, each of which has the same directory structure below it. IfVPATHis set,cscopesearches for source files in the directories specified; if it is not set,cscopesearches only in the current directory.
π FILES π
These are the files cscope is obsessed with π
cscope.filesβ default files containing-I,-p,-q, and-Toptions and the list of source files (overridden by the-ioption).cscope.outβ symbol cross-reference file (overridden by the-foption), 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 (-qoption). If you use the-foption to rename the cross-reference file (so itβs notcscope.out), the names for these inverted index files will be created by adding.inand.poto the name you supply with-f. For example, if you indicated-f xyz, then these files would be namedxyz.inandxyz.po.INCDIRβ standard directory for#includefiles (usually/usr/include).
π Notices π
OK so this is the part where cscope gets a little picky β it recognizes function definitions shaped exactly like this:
fname blank ( args ) white arg_decs white {
where:
fnameβ the function name.blankβ zero or more spaces, tabs, vtabs, form feeds or carriage returns, not including newlines.argsβ any string that does not contain a"or a newline.whiteβ zero or more spaces, tabs, vtabs, form feeds, carriage returns or newlines.arg_decsβ zero or more argument declarations (arg_decsmay 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 *))
{
...
}
Thatβs the whole page, bestie π β this iconic little manual page is CSCOPE(1) from The Santa Cruz Operation, dated January 2007 πβ¨
π¦ where this page comes from
- arch rolling: cscope 15.9-3 Β· BSD
- nixos 26.05: cscope 15.9
- nixpkgs unstable: cscope 15.9
- opensuse-leap 16.0: cscope 15.9-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: cscope 15.9-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: cscope 15.9-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: cscope 15.9-160000.2.2 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms