ctags 多行 C 函数原型

发布于 2024-11-26 01:50:39 字数 566 浏览 1 评论 0原文

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

我已经搜索过, --fields=+S 应该做多行原型,但我无法让它工作:

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

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没有办法做到这一点,有什么推荐的程序吗? (我目前正在研究 uncrustify)

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

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

file:

int 
foo(int
    x, int y
    );

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

or

int foo(int x, int y

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

音栖息无 2024-12-03 01:50:39

我的代码也有同样的问题,但我无法修改它。
当我使用 --fields=+S 参数时,它似乎有效,因为我在标记文件中获得了额外的行。签名:部分包含函数的所有参数。

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 签名:( uint16 memory_ID, uint32 ** pt_data_address, uint32 nb_recover,uint32 * nb_copied,uint32 max_length )

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. The signature: part contains all the parameters of the function.

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 )

烟雨凡馨 2024-12-03 01:50:39

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

--_xformat option may help you.

[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)
泼猴你往哪里跑 2024-12-03 01:50:39

我找不到 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() + ' ')

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.

Note: my code had comments and so much of this takes care with removing them (otherwise they would get in the way of 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() + ' ')
凝望流年 2024-12-03 01:50:39

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

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

You can remove unneeded line breaks with a simple filter, e.g.

 tr '\n' ' '  | sed 's/\([{};]\)/\1\n/g'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文