|
|
The purpose of cscope is to build a database containing information about functions, function calls, macros, and variables. cscope allows you to look at functions and examine the lines of code around those functions. In the testcase.c example, all the functions are contained in the one file. If, however, functions that are called from testcase.c were located in other files (excluding system library functions), cscope would allow you to look directly at those functions without exiting cscope. While using cscope on testcase.c might not be extremely helpful, it may still be of interest.
To examine the functions within testcase.c, run cscope as follows:
cscope testcase.cTo move the cursor to a menu option, press the <Return> key. To examine the function main, move the cursor to "List functions called by this function:", enter main, and press <Return>:
cscope Press the ? key for helpThe display lists the three functions called by main: gets, GetWords and PrintWords. Displayed along with the function names is the source code line that contains the function.
List references to this C symbol: Edit this function or #define: List functions called by this function: main List functions calling this function: List lines containing this text string: Change this text string: List file names containing this text string:
Functions called by this function: mainBy examining the GetWords function, we can move deeper into the code:File Function Line 1 testcase.c gets 85 while(gets(buf) != (char *)NULL) { 2 testcase.c GetWords 86 WordCount = GetWords(buf); 3 testcase.c PrintWords 87 PrintWords(WordCount, match); }
List references to this C symbol: Edit this function or #define: List functions called by this function: GetWords List functions calling this function: List lines containing this text string: Change this text string: List file names containing this text string:
Functions called by this function: GetWordsIn analyzing the results, we see that GetWords calls three functions displayed with their line numbers in the source code.File Function Line 1 testcase.c strlen 45 int end = strlen(buf); 2 testcase.c isspace 55 if (!isspace(*cp)) { 3 testcase.c isspace 61 if (isspace(*cp)) {
List references to this C symbol: Edit this function or #define: List functions called by this function: List functions calling this function: List lines containing this text string: Change this text string: List file names containing this text string:
Using cscope is particularly helpful when examining a large or complex program that has many files that span several directories. For more information, see ``C programmer's productivity tools'' and cscope(CP).