ctags多线C函数原型

时间:2011-07-25 18:02:53

标签: c ctags exuberant-ctags uncrustify

有没有办法让ctags在C中处理多行函数原型?

我已经四处寻找,--fields=+S应该做多线原型,但我无法让它工作:

ctags -x --c-kinds=pf --fields=+S file

文件:

int 
foo(int
    x, int y
    );

ctags只返回:

foo(int

(请注意,还缺少返回类型)

最终我希望获得类似于

的输出
int foo(int x, int y);

int foo(int x, int y

--fields=+S不是正确的方法吗? 我缺少哪些ctags字段? 一般的指针?

如果没有办法在ctags中执行任何推荐的程序? (我目前正在寻找unrustify)

4 个答案:

答案 0 :(得分:1)

我的代码遇到了同样的问题,但我无法对其进行修改。 当我使用--fields = + S参数时,它似乎工作,因为我在标记文件中得到一个额外的行。 signature:part包含函数的所有参数。

CopyToTX26 D:\ BiseL \ My Dropbox \ Work \ 0_BSW \ PKG_CMD \ Memory.c / ^ void CopyToTX26(uint16 memory_ID,uint32 ** pt_data_address,uint32 nb_recover,$ /;“f signature :( uint16 memory_ID,uint32 * * pt_data_address,uint32 nb_recover,uint32 * nb_copied,uint32 max_length)

答案 1 :(得分:0)

我无法找到任何ctags,所以我写了一个python脚本来重新安排我的文件,以便ctags可以捕获原型。

注意:我的代码有注释,因此大部分注意事项都要删除它们(否则它们会妨碍ctags)。

按此顺序进行操作:

# concat to one line
file_str = ''
for line in read_from.readlines():
    file_str += line

# remove all /* */ comments
file_str = re.sub('/\*(.|[\r\n])*?\*/', '', file_str)

# remove '//' comments
file_str = re.sub('//.*', '', file_str)

# split on '\n'
file_as_list = file_str.splitlines(True)

# strip everything
for index in range(len(file_as_list)):
    file_as_list[index] = file_as_list[index].strip()

# add in newlines where appropriate
for line in file_as_list:
    # if the line ends in ';' or '}'
    if line.endswith(';') or line.endswith('}'):
        # append a newline to the stripped line
        write_to.write(line.strip() + '\n')
    else:
        # append a space to the stripped line
        write_to.write(line.strip() + ' ')

答案 2 :(得分:0)

--_ xformat选项可以帮助您。

[jet@localhost ~]$ cat /tmp/foo.h
int 
foo(int
    x, int y
    );
[jet@localhost ~]$ ~/var/ctags/ctags -x --c-kinds=pf --_xformat="%-16N %4n %-16F %C %S" /tmp/foo.h
foo                 2 /tmp/foo.h       foo(int (int x,int y)

答案 3 :(得分:-1)

您可以使用简单的过滤器删除不需要的换行符,例如

 tr '\n' ' '  | sed 's/\([{};]\)/\1\n/g'