Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ cscope(1) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

curses(3X)

terminfo(4)

cscope(1)                                                         cscope(1)

NAME
     cscope - interactively examine a C program

SYNOPSIS
     cscope [option...] file...

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, lex, and yacc source files in the
     current directory. cscope may also be invoked for source files named
     in 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 table, cscope.out by
     default, to locate functions, function calls, macros, variables, and
     preprocessor symbols in the files.

     cscope builds the symbol cross-reference table the first time it is
     used on the source files for the program being browsed. On a subse-
     quent invocation, cscope rebuilds the cross-reference table only if a
     source file has changed or the list of source files is different. When
     the cross-reference table is rebuilt, the data for the unchanged files
     are copied from the old cross-reference table, which makes rebuilding
     faster than the initial build.

OPTIONS
     -b   Build the cross-references only.

     -C   Ignore letter case when searching.

     -c   Use only ASCII characters in the cross-reference table, that is,
          do not compress the data.

     -d   Do not update the cross-reference table

     -e   Suppress the command prompt between files.

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

     -I incdir
          Before looking in INCDIR, the directory for header files (nor-
          mally /usr/include), a search should be made in incdir for any
          #include files whose names do not begin with / and that are not
          specified on the command line or in namefile (see 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 and the standard directories. If the option
          -I appears more than once, the directories are searched in the
          order they appear on the command line.



Page 1                       Reliant UNIX 5.44                Printed 11/98

cscope(1)                                                         cscope(1)

     -i namefile
          Browse through all source files whose names are listed in
          namefile instead of the default file cscope.files. Filenames are
          separated by spaces, tabs, or new-lines. If this option is speci-
          fied, cscope ignores any files appearing on the command line.

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

     -l   Line-oriented interface (see section entitled "Line-oriented
          interface").

     -num pattern
          Go to input field num and find pattern. Counting starts from 0.

     -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 to not display the filename at all.

     -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. It is assumed that no files have
          changed.

     -u   Unconditionally build the cross-reference file. It is assumed
          that all files have changed.

     -V   Print on the first line of screen the version number of cscope.

     The -I, -p, and -T options can also be in the cscope.files file.












Page 2                       Reliant UNIX 5.44                Printed 11/98

cscope(1)                                                         cscope(1)

   Requesting the initial search

     After the cross-reference table is ready, cscope will display this
     menu:

        Find this C symbol:
        Find this global 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 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 key combinations can be
     used:

     1-9       Edit the line referenced by the number which was input
     SPACE     Output the next lines found
     +         Output the next lines found
     ^v        Output the next lines found
     -         Output the next files found
     ^e        Edit all the files output, in order
     >         Append list of lines to a file
     |         Pass all the displayed lines to a shell command























Page 3                       Reliant UNIX 5.44                Printed 11/98

cscope(1)                                                         cscope(1)

     The following key combinations can be used to control the cscope menu
     and to execute other commands:

     TAB       Next input field
     RETURN    Next input field
     ^n        Next input field
     ^p        Previous input field
     ^y        Search for last text input
     ^b        Next input field and search pattern
     ^f        Next input field and search pattern
     ^c        Take uppercase/lowercase into account in searching
     ^r        Recreate cross reference table
     !         Start an interactive shell (input ^d to return to cscope)
     ^l        Redraw the screen
     ?         Output help information about cscope commands
     ^d        Exit cscope

     If the first character of the text to be searched for matches one of
     the specified key combinations, type a \ before this character.

   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 the following keys:

     1-9       Select a line
     *         Select a line
     SPACE     Output next line
     +         Output next line
     -         Output previous line
     a         Select all lines
     ^d        Amend and exit from selected lines
     ESCAPE    Exit from edit mode without altering the marked lines

   Special keys

     If your terminal has arrow keys that work in vi(1), you can use them
     to move around between the input fields. The up-arrow key is useful to
     move to the previous input field instead of using the TAB key repeat-
     edly. If you have CLEAR, NEXT, or PREV 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, e.g., from another screen-oriented program.

     cscope prompts with >> and then expects input of a field number
     (counting from 0), immediately followed by the search pattern. For
     example, lmain will find the definition of the main function.



Page 4                       Reliant UNIX 5.44                Printed 11/98

cscope(1)                                                         cscope(1)

     If you only want the file to be searched once, you should use the -L
     and -num pattern options.

     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, e.g.,

          main.c main 161 main(argc, argv)

     Note that the editor is not called to display a single reference,
     unlike the screen-oriented interface.

     cscope will quit when it detects end-of-file, or when the first char-
     acter of an input line is ^d or q.

   Environment variables

     EDITOR
          The preferred editor

     INCLUDEDIRS
          Colon-separated list of directories to search for #include files.

     HOME Home directory, which is automatically set at login.

     SHELL
          Preferred shell, which defaults to sh(1).

     SOURCEDIRS
          Colon-separated list of directories to search for additional
          source files.

     TERM Terminal type, which must be a screen terminal.

     TERMINFO
          Full pathname of terminal information directory. If your terminal
          type is not in the standard terminfo directory, see curses(3X)
          and terminfo(4) for how to make your own terminal description.

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

     VIEWER
          Selects the file display program (such as pg(1)). This has prior-
          ity over EDITOR.





Page 5                       Reliant UNIX 5.44                Printed 11/98

cscope(1)                                                         cscope(1)

     VPATH
          A colon-separated list of directories, each of which has the same
          directory structure.

          If VPATH is set, cscope searches for source files in the direc-
          tories specified; if it is not set, cscope searches only in the
          current directory.

NOTES
     cscope recognizes function definitions of the form:

          fname blank ( args ) white argdecs 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 ", a ( or ) or a
                 newline

     white       is zero or more spaces, tabs, or newlines

     argdecs    are zero or more argument declarations which may include
                 comments and white space

     It is not necessary for a function declaration to start at the begin-
     ning of a line. The return type may precede the function name; cscope
     will still recognize the declaration. Function definitions that devi-
     ate 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: will only display the first func-
     tion called in the line. That is, for the following function



















Page 6                       Reliant UNIX 5.44                Printed 11/98

cscope(1)                                                         cscope(1)

        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 vari-
     able may be incorrectly recognized as a definition.

     A typedef name preceding a preprocessor statement will be incorrectly
     recognized as a global definition, e.g.,

        LDFILE *
        #if AR16WR

     Preprocessor statements can also prevent the recognition of a global
     definition, e.g.,

        char flag
        #ifdef ALLOCATESTORAGE
              = -1
        #endif
        ;

     A function declaration inside a function is incorrectly recognized as
     a function call, e.g., the following function declaration will be
     incorrectly recognized as a call to g():

        f()
        {
           void 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 recog-
     nize 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;







Page 7                       Reliant UNIX 5.44                Printed 11/98

cscope(1)                                                         cscope(1)

     It also doesn't recognize operator function definitions

        Bool Feature::operator==(const Feature & other)
        {
              ...
        }

FILES
     cscope.files
          Default file containing -I, -p and -T options and the list of
          sourcefiles; another choice can be made using the -i option.

     cscope.out
          Symbol cross-reference table, which is put in the home directory
          if it cannot be created in the current directory.

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

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

SEE ALSO
     curses(3X), terminfo(4).

     The "cscope" chapter in the "Guide to Tools for Programming in C".



























Page 8                       Reliant UNIX 5.44                Printed 11/98

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026