问题描述
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 中没有办法做到这一点,有什么推荐的程序吗?(我目前正在看 uncrustify)
推荐答案
我无法使用 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() + ' ')