经过一些 LOOONG 研究后,我得出结论,uncrustify 无法做到这一点。对于我的 porposses,我一起编写了一个小的 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 中的补丁。