简体   繁体   English

ctags多线C函数原型

[英]ctags multi-line C function prototypes

Is there a way for ctags to handle multiline function prototypes in C? 有没有办法让ctags在C中处理多行函数原型?

I've searched around and the --fields=+S is supposed to do multiline prototypes, but I can't get it to work: 我已经四处搜索了--fields=+S应该做多线原型,但我不能让它工作:

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

file: 文件:

int 
foo(int
    x, int y
    );

ctags only returns: ctags只返回:

foo(int

(Note that the return type is also missing) (注意,返回类型也缺失)

Ultimately I would like to get an output similar to 最终我想获得类似的输出

int foo(int x, int y);

or 要么

int foo(int x, int y

is --fields=+S not the correct way? --fields=+S不是正确的方法? Are there part of the ctags fields that I am missing? 我缺少哪些ctags字段? Any pointers in general? 一般的指针?

If there is not a way to do it in ctags, any recommended programs? 如果没有办法在ctags中做任何推荐的程序? (I'm currently looking at uncrustify) (我目前正在寻找unrustify)

I had the same issue with my code but I couldn't modify it. 我的代码遇到了同样的问题但我无法修改它。 When I use the --fields=+S parameter, it seem to work because I get an additional line in the tag file. 当我使用--fields = + S参数时,它似乎工作,因为我在标记文件中得到一个额外的行。 The signature: part contains all the parameters of the function. 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 ) 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)

--_xformat option may help you. --_ 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)

I was unable to find anything with ctags so I wrote a python script to re-arrange my file so that ctags could capture the prototypes. 我无法找到任何ctags,所以我编写了一个python脚本来重新安排我的文件,以便ctags可以捕获原型。

Note: my code had comments and so much of this takes care with removing them (otherwise they would get in the way of ctags). 注意:我的代码有注释,因此大部分都需要删除它们(否则它们会妨碍ctags)。

Manipulations were done in this order: 操作按此顺序进行:

# 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() + ' ')

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM