How to use cscope for a project with .c, .cpp and .h files?

I am working on a project that requires an understanding of llvm compiler source code. To view the llvm source code, I tried using cscope with the following command in the source root directory:

cscope -R *

But that will not work. Since basically there are .cpp and .h files, but some .c files are also there. So now I have no clue how to make cscope work? Can anybody help?

+6
source share
5 answers

You can use the following commands to perform the required task from the root directory of the llvm source tree:

touch tags.lst find | grep "\.c$" >> tags.lst find | grep "\.cpp$" >> tags.lst find | grep "\.h$" >> tags.lst cscope -i tags.lst 

It will create a cscope.out file that will be used with cscope to view the code. Hope this helps!

+9
source

A convenient way to list all C++ files in a project is to use ack : the grep-like command optimized for the source Search for code (in some distributions, for example Ubuntu, the tool is called ack-grep ). You can run it as follows:

 ack -f --cpp > cscope.files 

The output is the paths to all .cpp , .h , .cc .hpp

+6
source

To cover our large code base, I have a script that looks a bit like this for creating cscope indexes. The reason I'm switching to / is because I have full paths to the source files that make things a little smoother.

 cd / find -L /home/adrianc/code -name "*.c" -o -name "*.cc" -o -name "*.h" > /home/adrianc/code/cscope.files cd /home/adrianc/code /usr/local/bin/cscope -b -icscope.files -q -u 

Also worth checking out is http://cscope.sourceforge.net/cscope_vim_tutorial.html

+2
source

Just because it's still the most popular record. However, stdin thingy can be added or not, but this makes it elegant:

 find -regex '.*\.\(c\|h\|cpp\|cxx\|hh\|hpp\|hxx\)$' | cscope -i- -b -q 
0
source

I have the following in my .bashrc that simplifies the job. Run cscope_build() to create the database and cscope to run the cscope tool.

 # Use vim to edit files export CSCOPE_EDITOR=`which vim` # Generate cscope database function cscope_build() { # Generate a list of all source files starting from the current directory # The -o means logical or find . -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" > cscope.files # -q build fast but larger database # -R search symbols recursively # -b build the database only, don't fire cscope # -i file that contains list of file paths to be processed # This will generate a few cscope.* files cscope -q -R -b -i cscope.files # Temporary files, remove them # rm -f cscope.files cscope.in.out cscope.po.out echo "The cscope database is generated" } # -d don't build database, use kscope_generate explicitly alias cscope="cscope -d" 
0
source

Source: https://habr.com/ru/post/922646/


All Articles