【问题标题】:cscope for files which are symlinkscscope 用于符号链接的文件
【发布时间】:2015-04-08 15:16:46
【问题描述】:

我有一个包含多个文件的源目录。其中一些是指向其他文件的符号链接。

我创建了一个 cscope.files 文件。但是当我执行 cscope 时。它抱怨符号链接的文件:

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

我认为这不是很好,但也许正确的方法是更改​​“查找”脚本,只写符号链接的目标?

【问题讨论】:

  • 该文件是符号链接还是符号链接的目标?符号链接的目标是否存在?
  • 这是符号链接。不是目标。目标存在。

标签: linux bash vim symlink cscope


【解决方案1】:

目前我正在使用:

# 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

但这似乎是一个糟糕的解决方案。还在寻找更好的

【讨论】:

  • 它不适用于作为符号链接的文件(如果您想从输出中删除它们以避免警告)。
【解决方案2】:

我认为您可以使用该命令在您搜索的文件夹中查找所有真实路径

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

例如,如果我想在 cscope.files 中添加开发文件夹和 linux 内核头文件,我将使用以下命令:

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

希望答案对你有所帮助。

【讨论】:

    【解决方案3】:

    例如,如果您想将 / 作为 cscope 的路径,并希望 cscope 搜索扩展名为 .c/.h/.x/.s/.S 的文件,您可以将 find 命令指定为:

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

    这将包括常规文件,包括符号链接的目标。

    【讨论】:

      【解决方案4】:

      我只是执行以下操作以避免符号链接,并在 cscope.files 中获取绝对路径。使用绝对路径,当 cscope 与 vim 编辑器集成时,您可以从沙箱中的任何目录进行搜索

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

      注意:如果您在 find 中省略 -print,它不会将符号链接路径放在您的 cscope.files 中,而只会将解析的路径。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-02
        • 1970-01-01
        • 2021-01-15
        相关资源
        最近更新 更多