有没有办法说服 GNU 缩进打破长注释并将其更改为多行注释?像这样的东西:
// Very long comment, longer than 80 characters. Just imagine that.
对此:
/*
* Very long comment, longer than 80 characters. Just
* imagine that.
*/
我知道格式化第二个可以简单地通过“-cdb -sc”来完成,但我不知道如何确保换行符和注释类型更改。有可能吗?
答案1
sed -i '\_//_{s_//_/* _g;s_$_ */_g}' file.c
indent -fc1 -fca -sc -cdb file.c
sed -i 's/\/\*\(.*\)\*\/$/\/\/\1/' file.c
做了你要求的事情,但我会很谨慎,因为它可能会错过一些边缘情况
输入:
// Lorem ipsum dolor sit amet, apeirian constituam interpretaris no his, soluta salutandi persequeris vel ne, facete impedit contentiones te eam. Ut utamur habemus qualisque usu
#include <stdio.h>
int main () // damn
{
puts ("hello world" /* sheeet */); } /* oh shit */
输出:
/*
* Lorem ipsum dolor sit amet, apeirian constituam interpretaris no his,
* soluta salutandi persequeris vel ne, facete impedit contentiones te eam.
* Ut utamur habemus qualisque usu
*/
#include <stdio.h>
int
main () // damn
{
puts ("hello world" /* sheeet */ );
} // oh shit
答案2
我让它工作,出于某种原因它需要-fc1
和-fca
选项:
indent -fc1 -fca j.c
或者,您可以使用伯克利风格:
indent -orig j.c
输入:
// Lorem ipsum dolor sit amet, apeirian constituam interpretaris no his, soluta salutandi persequeris vel ne, facete impedit contentiones te eam. Ut utamur habemus qualisque usu
#include <stdio.h>
int main(){puts("hello world");}
输出:
// Lorem ipsum dolor sit amet, apeirian constituam interpretaris no his,
// soluta salutandi persequeris vel ne, facete impedit contentiones te eam.
// Ut utamur habemus qualisque usu
#include <stdio.h>
int
main ()
{
puts ("hello world");
}