GNU indentを使ってみた

わざとらしく次のようなファイル(hello.c)を用意します。

#include<stdio.h>

int




main(


void


) {


printf("hello, world\n");


  return 
             0

;
}


$ indent -st hello.c

すると

#include<stdio.h>

int
main (void)
{


  printf ("hello, world\n");


  return 0;
}

が標準出力されます(-stが無ければ上書き)。(-kr)でK&Rスタイルにもできますが、hello.cから直でやる(indent -kr -st hello.c)と

#include<stdio.h>

int



 main(void


    )
{


    printf("hello, world\n");


    return 0;
}

なんかかっこ悪いですね。じゃあってことで、"indent -st hello.c | indent -kr"してみます。

#include<stdio.h>

int main(void)
{


    printf("hello, world\n");


    return 0;
}

あ、これなら良いですね。