7

I have a source directory with several files. Some of them are symlinks to other files.

I created a cscope.files file. But when I execute cscope. It complains for the files that are symlinks:

cscope: cannot find file /home/bla/source/file.cc

I think it's not very good, but maybe the correct way to go is to change the "find" script, to just write the destination of the symlink instead?

user972014
  • 3,296
  • 6
  • 49
  • 89

6 Answers6

6

Currently I'm using:

# Write only the files which are NOT symlinks
find `pwd` \( \( -iname "*.c" -o -iname "*.cc" -o -iname "*.h" \) -and \( -not -type l \) \) -print > cscope.files
# Add the target of the symlink for all files matching the right extension, and are symlinks
find `pwd` \( \( -iname "*.c" -o -iname "*.cc" -o -iname "*.h" \) -and -type l \) -printf "%l\n"  >> cscope.files

But this seems like a terrible solution. Still looking for a better one

user972014
  • 3,296
  • 6
  • 49
  • 89
  • It doesn't work with files being symlinks (in case you would like to remove them from the output to avoid warnings). – 0andriy Oct 08 '19 at 14:51
  • 2 problem 1. -type l will match all symlinks, not just files. so -type l -xtype f would be better. 2. the symlink won't work if it is a relative symlink. so using readlink -f or realpath is better. – John Kearney Dec 04 '22 at 08:20
3

I think you can use the command to find all real paths in a folder that you searched

find -L [your searched folder] -name [your searched pattern] -exec realpath {} \; >> cscope.files

For example, if I would like to add developed folder and linux kernel header to cscope.files, I will the these commands:

find -L `pwd` -iname "*.c" -o -iname "*.h" > cscope.files
find -L /usr/src/linux-headers-3.19.0-15-generic/ -iname '*.h' -exec realpath {} \; >> cscope.files

I hope the answer can help you.

Iverson Hsieh
  • 181
  • 1
  • 10
3

For example if you want to give / as your path for cscope, and want cscope to search files with extensions .c/.h/.x/.s/.S you can give the find command as:

find / -type f -name "*.[chxsS]" -print -exec readlink -f {} \;> cscope.files

This will include regular files, including targets of symbolic links.

MuhammadI
  • 31
  • 3
1

I just do the following to avoid symbolic links, as well get the absolute path in the cscope.files. With absolute path you can search from any directory in your sandbox when cscope is integrated with the vim editor

find /"path-to-your-sandbox" -path .git -prune -o -name "*.[ch]"  -exec readlink -f {} \; > cscope.files

Note: if you omit -print from the find it does not put the symbolic link path in your cscope.files only the resolved path.

Kallol
  • 11
  • 3
0

Better in a bash script:

#!/bin/bash
#
# find_cscope_files.sh

extension_list=(c cpp cxx cc h hpp hxx hh)
for x in "${extension_list[@]}"; do
    find . -name "*.$x" -print -exec readlink -f {} \;
done
Robin Hsu
  • 174
  • 1
  • 9
0

For reference for others I'm currently using.

find "$(pwd)" \( -name "*.[chCS]" -o -name "*.[ch][ci]" -o -name "*.[ch]pp" -o -name "*.[ch]++" -o -name "*.[ch]xx" ) -not \( -ipath "*unittest*" -or -ipath "*regress*" \) \( \( -type l -xtype f -exec readlink -f {} \; \) -o \( -type f -print \) \) >cscope.files
cscope -q -R -b -i cscope.files
John Kearney
  • 322
  • 3
  • 9