1CSCOPE(1)                   General Commands Manual                  CSCOPE(1)
2
3
4

NAME

6       cscope - interactively examine a C program
7

SYNOPSIS

9       cscope  [-bCcdehkLlqRTUuVv] [-Fsymfile] [-freffile] [-Iincdir] [-iname‐
10       file] [-0123456789pattern] [-pn] [-sdir] [files]
11

DESCRIPTION

13       cscope is an interactive, screen-oriented tool that allows the user  to
14       browse through C source files for specified elements of code.
15
16       By  default, cscope examines the C (.c and .h), lex (.l), and yacc (.y)
17       source files in the current directory.  cscope may also be invoked  for
18       source files named on the command line. In either case, cscope searches
19       the standard directories for #include files that it does  not  find  in
20       the  current  directory.   cscope uses a symbol cross-reference, called
21       cscope.out by default, to locate  functions,  function  calls,  macros,
22       variables, and preprocessor symbols in the files.
23
24       cscope  builds  the symbol cross-reference the first time it is used on
25       the source files for the program being browsed. On a subsequent invoca‐
26       tion,  cscope  rebuilds  the  cross-reference only if a source file has
27       changed or the list of source files is different. When the cross-refer‐
28       ence  is  rebuilt, the data for the unchanged files are copied from the
29       old cross-reference, which makes rebuilding  faster  than  the  initial
30       build.
31

OPTIONS

33       Some  command line arguments can only occur as the only argument in the
34       execution of cscope.  They cause the program to  just  print  out  some
35       output and exit immediately:
36
37       -h     View the long usage help display.
38
39       -V     Print on the first line of screen the version number of cscope.
40
41       --help Same as -h
42
43       --version
44              Same as -V
45
46
47       The following options can appear in any combination:
48
49       -b     Build the cross-reference only.
50
51       -C     Ignore letter case when searching.
52
53       -c     Use  only ASCII characters in the cross-reference file, that is,
54              do not compress the data.
55
56       -d     Do not update the cross-reference.
57
58       -e     Suppress the <Ctrl>-e command prompt between files.
59
60       -Fsymfile
61              Read symbol reference lines from symfile.  (A  symbol  reference
62              file  is  created  by > and >>, and can also be read using the <
63              command,  described  under  ``Issuing   Subsequent   Requests'',
64              below.)
65
66       -freffile
67              Use  reffile  as  the  cross-reference  file name instead of the
68              default "cscope.out".
69
70       -Iincdir
71              Look in incdir (before looking in $INCDIR,  the  standard  place
72              for  header files, normally /usr/include) for any #include files
73              whose names do not begin with ``/'' and that are  not  specified
74              on  the  command  line or in namefile below. (The #include files
75              may be specified with either double quotes or  angle  brackets.)
76              The  incdir  directory  is  searched  in addition to the current
77              directory (which is searched first) and the standard list (which
78              is  searched  last).  If more than one occurrence of -I appears,
79              the directories are searched in the order  they  appear  on  the
80              command line.
81
82       -inamefile
83              Browse  through all source files whose names are listed in name‐
84              file (file  names  separated  by  spaces,  tabs,  or  new-lines)
85              instead   of  the  default  name  list  file,  which  is  called
86              cscope.files. If this option is specified,  cscope  ignores  any
87              file  names appearing on the command line. The argument namefile
88              can be set to ``-'' to accept a list of files from the  standard
89              input.   Filenames  in the namefile that contain whitespace have
90              to be enclosed in "double quotes".   Inside  such  quoted  file‐
91              names,  any  double-quote  and  backslash  characters have to be
92              escaped by backslashes.
93
94       -k     ``Kernel Mode'', turns off the use of the  default  include  dir
95              (usually  /usr/include) when building the database, since kernel
96              source trees generally do not use it.
97
98       -L     Do a single search with line-oriented output when used with  the
99              -num pattern option.
100
101       -l     Line-oriented interface (see ``Line-Oriented Interface'' below).
102
103       -[0-9]pattern
104              Go to input field num (counting from 0) and find pattern.
105
106       -Ppath Prepend  path to relative file names in a pre-built cross-refer‐
107              ence file so you do not have to change to  the  directory  where
108              the  cross-reference  file  was built. This option is only valid
109              with the -d option.
110
111       -pn    Display the last n file path components instead of  the  default
112              (1). Use 0 not to display the file name at all.
113
114       -q     Enable  fast  symbol  lookup  via an inverted index. This option
115              causes  cscope  to  create   2   more   files   (default   names
116              ``cscope.in.out'' and ``cscope.po.out'') in addition to the nor‐
117              mal database. This allows a faster symbol search algorithm  that
118              provides   noticeably   faster   lookup  performance  for  large
119              projects.
120
121       -R     Recurse subdirectories during search for source files.
122
123       -sdir  Look in dir for additional source files. This option is  ignored
124              if source files are given on the command line.
125
126       -T     Use  only the first eight characters to match against C symbols.
127              A regular expression containing special characters other than  a
128              period  (.)  will  not match any symbol if its minimum length is
129              greater than eight characters.
130
131       -U     Check file time stamps. This option will update the  time  stamp
132              on the database even if no files have changed.
133
134       -u     Unconditionally  build the cross-reference file (assume that all
135              files have changed).
136
137       -v     Be more verbose in line-oriented mode.  Output progress  updates
138              during database building and searches.
139
140       files  A list of file names to operate on.
141
142       The  -I, -c, -k, -p, -q, and -T options can also be in the cscope.files
143       file.
144
145   Requesting the initial search
146       After the cross-reference is ready, cscope will display this menu:
147
148       Find this C symbol:
149       Find this function definition:
150       Find functions called by this function:
151       Find functions calling this function:
152       Find this text string:
153       Change this text string:
154       Find this egrep pattern:
155       Find this file:
156       Find files #including this file:
157
158       Press the <Up> or <Down> keys repeatedly to move to the  desired  input
159       field, type the text to search for, and then press the <Return> key.
160
161   Issuing subsequent requests
162       If the search is successful, any of these single-character commands can
163       be used:
164
165       0-9a-zA-Z
166              Edit the file referenced by the given line number.
167
168       <Space>
169              Display next set of matching lines.
170
171       <Tab>  Alternate between the menu and the list of matching lines
172
173       <Up>   Move to the previous menu item (if the cursor is in the menu) or
174              move  to  the  previous  matching  line (if the cursor is in the
175              matching line list.)
176
177       <Down> Move to the next menu item (if the cursor is  in  the  menu)  or
178              move to the next matching line (if the cursor is in the matching
179              line list.)
180
181       +      Display next set of matching lines.
182
183       -      Display previous set of matching lines.
184
185       ^e     Edit displayed files in order.
186
187       >      Write the displayed list of lines to a file.
188
189       >>     Append the displayed list of lines to a file.
190
191       <      Read lines from a file that is in symbol reference format  (cre‐
192              ated by > or >>), just like the -F option.
193
194       ^      Filter all lines through a shell command and display the result‐
195              ing lines, replacing the lines that were already there.
196
197       |      Pipe all lines to a  shell  command  and  display  them  without
198              changing them.
199
200       At any time these single-character commands can also be used:
201
202       <Return>
203              Move to next input field.
204
205       ^n     Move to next input field.
206
207       ^p     Move to previous input field.
208
209       ^y     Search with the last text typed.
210
211       ^b     Move to previous input field and search pattern.
212
213       ^f     Move to next input field and search pattern.
214
215       ^c     Toggle  ignore/use  letter  case  when searching. (When ignoring
216              letter  case,  search  for  ``FILE''  will  match  ``File''  and
217              ``file''.)
218
219       ^r     Rebuild the cross-reference.
220
221       !      Start an interactive shell (type ^d to return to cscope).
222
223       ^l     Redraw the screen.
224
225       ?      Give help information about cscope commands.
226
227       ^d     Exit cscope.
228
229       NOTE: If the first character of the text to be searched for matches one
230       of the above commands, escape it by typing a (backslash) first.
231
232       Substituting new text for old text
233
234       After the text to be changed has been typed, cscope will prompt for the
235       new  text,  and then it will display the lines containing the old text.
236       Select the lines to be changed with these single-character commands:
237
238       0-9a-zA-Z
239              Mark or unmark the line to be changed.
240
241       *      Mark or unmark all displayed lines to be changed.
242
243       <Space>
244              Display next set of lines.
245
246       +      Display next set of lines.
247
248       -      Display previous set of lines.
249
250       a      Mark or unmark all lines to be changed.
251
252       ^d     Change the marked lines and exit.
253
254       <Esc>  Exit without changing the marked lines.
255
256       !      Start an interactive shell (type ^d to return to cscope).
257
258       ^l     Redraw the screen.
259
260       ?      Give help information about cscope commands.
261
262       Special keys
263              If your terminal has arrow keys that work in  vi,  you  can  use
264              them to move around the input fields. The up-arrow key is useful
265              to move to the previous input field instead of using  the  <Tab>
266              key repeatedly. If you have <CLEAR>, <NEXT>, or <PREV> keys they
267              will act as the ^l, +, and - commands, respectively.
268
269   Line-Oriented interface
270       The -l option lets you use cscope  where  a  screen-oriented  interface
271       would not be useful, for example, from another screen-oriented program.
272
273       cscope  will prompt with >> when it is ready for an input line starting
274       with the field number (counting from 0)  immediately  followed  by  the
275       search pattern, for example, ``lmain'' finds the definition of the main
276       function.
277
278       If you just want a single search, instead of the -l option use  the  -L
279       and -num pattern options, and you won't get the >> prompt.
280
281       For -l, cscope outputs the number of reference lines cscope: 2 lines
282
283       For  each reference found, cscope outputs a line consisting of the file
284       name, function name, line number, and line text, separated  by  spaces,
285       for example, main.c main 161 main(argc, argv)
286
287       Note  that  the  editor  is  not  called to display a single reference,
288       unlike the screen-oriented interface.
289
290       You can use the c command to toggle ignore/use letter case when search‐
291       ing.  (When  ignoring  letter  case,  search  for  ``FILE''  will match
292       ``File'' and ``file''.)
293
294       You can use the r command to rebuild the database.
295
296       cscope will quit when it detects end-of-file, or when the first charac‐
297       ter of an input line is ``^d'' or ``q''.
298

ENVIRONMENT VARIABLES

300       CSCOPE_EDITOR
301              Overrides  the EDITOR and VIEWER variables. Use this if you wish
302              to use a different editor with cscope  than  that  specified  by
303              your EDITOR/VIEWER variables.
304
305       CSCOPE_LINEFLAG
306              Format  of  the  line  number  flag for your editor. By default,
307              cscope invokes your editor via the  equivalent  of  ``editor  +N
308              file'',  where  ``N''  is the line number that the editor should
309              jump to. This format is used by both emacs and vi. If your  edi‐
310              tor needs something different, specify it in this variable, with
311              ``%s'' as a placeholder for the line number.  Ex: if your editor
312              needs  to be invoked as ``editor -#103 file'' to go to line 103,
313              set this variable to ``-#%s''.
314
315       CSCOPE_LINEFLAG_AFTER_FILE
316              Set this variable to ``yes'' if your editor needs to be  invoked
317              with  the line number option after the filename to be edited. To
318              continue the example from CSCOPE_LINEFLAG, above: if your editor
319              needs  to  see  ``editor  file  -#number'', set this environment
320              variable. Users of most standard editors (vi, emacs) do not need
321              to set this variable.
322
323       EDITOR Preferred editor, which defaults to vi.
324
325       HOME   Home directory, which is automatically set at login.
326
327       INCLUDEDIRS
328              Colon-separated  list  of  directories  to  search  for #include
329              files.
330
331       SHELL  Preferred shell, which defaults to sh.
332
333       SOURCEDIRS
334              Colon-separated list of directories  to  search  for  additional
335              source files.
336
337       TERM   Terminal type, which must be a screen terminal.
338
339       TERMINFO
340              Terminal  information directory full path name. If your terminal
341              is not in the standard terminfo directory, see curses  and  ter‐
342              minfo for how to make your own terminal description.
343
344       TMPDIR Temporary file directory, which defaults to /var/tmp.
345
346       VIEWER Preferred  file  display program (such as less), which overrides
347              EDITOR (see above).
348
349       VPATH  A colon-separated list of directories, each  of  which  has  the
350              same  directory  structure  below  it.  If  VPATH is set, cscope
351              searches for source files in the directories specified; if it is
352              not set, cscope searches only in the current directory.
353

FILES

355       cscope.files
356              Default files containing -I, -p, -q, and -T options and the list
357              of source files (overridden by the -i option).
358
359       cscope.out
360              Symbol cross-reference file (overridden by the -f option), which
361              is put in the home directory if it cannot be created in the cur‐
362              rent directory.
363
364       cscope.in.out
365       cscope.po.out
366              Default files containing the inverted index used for quick  sym‐
367              bol  searching  (-q  option). If you use the -f option to rename
368              the cross-reference file (so it's not cscope.out), the names for
369              these inverted index files will be created by adding
370               .in and .po to the name you supply with -f. For example, if you
371              indicated -f xyz, then these files would  be  named  xyz.in  and
372              xyz.po.
373
374       INCDIR Standard directory for #include files (usually /usr/include).
375

Notices

377       cscope recognizes function definitions of the form:
378       fname blank ( args ) white arg_decs white {
379
380       where: fname is the function name
381
382       blank  is  zero  or  more  spaces,  tabs, vtabs, form feeds or carriage
383              returns, not including newlines
384
385       args   is any string that does not contain a ``"'' or a newline
386
387       white  is zero or  more  spaces,  tabs,  vtabs,  form  feeds,  carriage
388              returns or newlines
389
390       arg_decs
391              are  zero  or  more  argument declarations (arg_decs may include
392              comments and white space)
393
394       It is not necessary for a function declaration to start at  the  begin‐
395       ning  of  a line. The return type may precede the function name; cscope
396       will still recognize the declaration. Function definitions that deviate
397       from this form will not be recognized by cscope.
398
399       The  ``Function''  column of the search output for the menu option Find
400       functions called by this function: input field will  only  display  the
401       first function called in the line, that is, for this function
402
403        e()
404        {
405                return (f() + g());
406        }
407
408       the display would be
409
410          Functions called by this function: e
411          File Function Line
412          a.c f 3 return(f() + g());
413
414       Occasionally,  a  function  definition  or  call  may not be recognized
415       because of braces inside #if statements. Similarly, the use of a  vari‐
416       able may be incorrectly recognized as a definition.
417
418       A  typedef  name preceding a preprocessor statement will be incorrectly
419       recognized as a global definition, for example,
420
421        LDFILE  *
422        #if AR16WR
423
424       Preprocessor statements can also prevent the recognition  of  a  global
425       definition, for example,
426
427        char flag
428        #ifdef ALLOCATE_STORAGE
429             = -1
430        #endif
431        ;
432
433       A function declaration inside a function is incorrectly recognized as a
434       function call, for example,
435
436        f()
437        {
438                void g();
439        }
440
441       is incorrectly recognized as a call to g.
442
443       cscope recognizes C++ classes by looking for  the  class  keyword,  but
444       doesn't  recognize  that a struct is also a class, so it doesn't recog‐
445       nize inline member function definitions in a structure. It also doesn't
446       expect  the class keyword in a typedef , so it incorrectly recognizes X
447       as a definition in
448
449        typedef class X  *  Y;
450
451       It also doesn't recognize operator function definitions
452
453        Bool Feature::operator==(const Feature & other)
454        {
455          ...
456        }
457
458       Nor does it recognize function  definitions  with  a  function  pointer
459       argument
460
461        ParseTable::Recognize(int startState, char *pattern,
462          int finishState, void (*FinalAction)(char *))
463        {
464          ...
465        }
466
467
468
469The Santa Cruz Operation         January 2007                        CSCOPE(1)
Impressum