![](/img/trans.png)
[英]uncrustify: how to combine arguments of multiline C function call on to a single line?
[英]Uncrustify Collapse Multiline Function Call
我有看起来像这样的函数调用(没有明显的原因):
func
(
a,
b,
c
)
有没有办法让 uncrustify 将函数折叠成一行? 我已经试了两天不断断续续...
我让它适用于函数声明,但我不让它适用于函数调用。
当我们在做的时候,我也有看起来像这样的函数:
func
(
a, // (IN) the A
b, // (IN) something b
c // (OUT) the resulting value
)
有没有办法在不破坏代码的情况下处理这种情况? 由于 uncrustify 保留评论,我认为这是不可能的。 使用函数声明,它会将其折叠到第一个注释。
阅读文档,我想出了这个:
# Add or remove newline between a function name and the opening '('
nl_func_paren = remove # ignore/add/remove/force
# Add or remove newline between a function name and the opening '(' in the definition
nl_func_def_paren = remove # ignore/add/remove/force
# Add or remove newline after '(' in a function declaration
nl_func_decl_start = remove # ignore/add/remove/force
# Add or remove newline after '(' in a function definition
nl_func_def_start = remove # ignore/add/remove/force
# Add or remove newline after each ',' in a function declaration
nl_func_decl_args = remove # ignore/add/remove/force
# Add or remove newline after each ',' in a function definition
nl_func_def_args = remove # ignore/add/remove/force
# Add or remove newline before the ')' in a function declaration
nl_func_decl_end = remove # ignore/add/remove/force
# Add or remove newline before the ')' in a function definition
nl_func_def_end = remove # ignore/add/remove/force
不过,正如您所料,评论有点毁了它。 有一个选项来改变单行注释( //
)成块注释( /* ... */
),虽然,这应该更容易让你手动加入线(例如在VIM v%J
)
# Whether to change cpp-comments into c-comments
cmt_cpp_to_c = true # false/true
我用原型、声明和调用测试了它:
通话不受影响。 另请注意以下相关选项:
# Whether to fully split long function protos/calls at commas
ls_func_split_full = false # false/true
经过一些 LOOONG 研究,我得出的结论是,uncrustify 不能这样做。 对于我的海豚,我一起编写了一个小的 perl 脚本:
$filename = $ARGV[0];
{
open(FILE, "<", $filename) or die "Cant open $filename for reading\n";
local $/ = undef;
$lines = <FILE>;
close(FILE);
}
# squash comments in function calls and declarations
$lines =~ s/,[ \t]*\/\/[^\n\r]*/,/gm;
# squash last comment in function calls and declarations
$lines =~ s/[ \t]*\/\/[^\n\r]*\r\n[ \t]*\)/\)/gm;
# squash newlines at the start of a function call or declaration
$lines =~ s/\([ \t]*\r\n[ \t]*/\(/gm;
# squash newlines in function calls and declarations
$lines =~ s/,[ \t]*\r\n[ \t]*/, /gm;
# squash the last newline in a function call or declaration
$lines =~ s/[ \t]*\r\n[ \t]*\)/\)/gm;
{
open(FILE, ">", $filename) or die "Cant open $filename for writing\n";
print FILE $lines;
close(FILE);
}
我会研究是否可以构建一个补丁,将该功能集成到 uncustify 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.