CTAGS多行的C函数原型 [英] ctags multi-line C function prototypes

查看:316
本文介绍了CTAGS多行的C函数原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法为的ctags处理用C多行函数原型?

Is there a way for ctags to handle multiline function prototypes in C?

我已搜索周围和 - 栏= + S 是应该做的多行原型,但我不能得到它的工作:

I've searched around and the --fields=+S is supposed to do multiline prototypes, but I can't get it to work:

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

文件:

int 
foo(int
    x, int y
    );

的ctags只返回:

ctags only returns:

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);

int foo(int x, int y

- 栏= + S 不是正确的方法是什么?
是否有我错过了的ctags领域的一部分?
一般来说任何指针?

is --fields=+S not the correct way? Are there part of the ctags fields that I am missing? Any pointers in general?

如果没有办法做到这一点在CTAGS,任何建议的程序? (目前我看uncrustify)

If there is not a way to do it in ctags, any recommended programs? (I'm currently looking at uncrustify)

推荐答案

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

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.

请注意:我的code有评论和这么多的这种照顾与删除它们(否则他们将得到的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).

手法以此顺序完成:

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

这篇关于CTAGS多行的C函数原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆