other versions
other sections
INDENT(1L) | INDENT(1L) |
名前¶
indent - 空白の挿入や削除を行い、C 言語プログラムの見栄えを変える。書式¶
indent [options] [input-files]説明¶
この man ページはファイル indent.texinfo から生成した。 これは indent バージョン 2.2.9 用の「The indent Manual」の 2.2.9 版 (2002 年 11 月 10 日版) である。オプション¶
- -bad, --blank-lines-after-declarations
- 宣言の後に必ず空行を置く。
- -bap, --blank-lines-after-procedures
- 手続き本体の後に必ず空行を置く。
- -bbb, --blank-lines-before-block-comments
- ブロックコメントの前に必ず空行を置く。
- -bbo, --break-before-boolean-operator
- 長い行をブーリアン演算子の前で折り返す。
- -bc, --blank-lines-after-commas
- 宣言中のコンマの後に必ず改行を置く。
- -bl, --braces-after-if-line
- ブレースは if
等の次の行に置く。
- -blin, --brace-indentn
- ブレースを n
個のスペースでインデント付けする。
- -bls, --braces-after-struct-decl-line
- ブレースは struct
宣言行の次の行に置く。
- -br, --braces-on-if-line
- ブレースは if
等がある行に置く。
- -brs, --braces-on-struct-decl-line
- ブレースは struct
宣言行がある行に置く。
- -bs, --Bill-Shannon, --blank-before-sizeof
- sizeof
とその引き数の間に空白を置く。
- -cn, --comment-indentationn
- コメントをコードの右のカラム
n に置く。
- -cbin, --case-brace-indentationn
- case
ラベルの後に、ブレースを
n
個の空白でインデント付けする。
- -cdn, --declaration-comment-columnn
- コメントを宣言の右のカラム
n に置く。
- -cdb, --comment-delimiters-on-blank-lines
- 空行にコメント区切り文字を置く。
- -cdw, --cuddle-do-while
- do {} while; の while
とその前の `}´
を並べる。
- -ce, --cuddle-else
- else とその前の `}´
を並べる。
- -cin, --continuation-indentationn
- 前の行から継続している場合には、n
個の空白でインデントする。
- -clin, --case-indentationn
- case ラベルを N
個の空白でインデントする。
- -cpn, --else-endif-columnn
- #else 文と #endif
文の右のカラム n
にコメントを置く。
- -cs, --space-after-cast
- キャスト演算子の後に空白を置く。
- -dn, --line-comments-indentationn
- コードの右でないコメントは空白
n
個でインデントするように設定する。
- -bfda, --break-function-decl-args
- (関数)
宣言の全ての引き数の後で折り返す。
- -bfde, --break-function-decl-args
- (関数)
宣言の全ての引き数の前で折り返す。
- -din, --declaration-indentationn
- 変数をカラム n
に置く。
- -fc1, --format-first-column-comments
- 最初のカラムから始まるコメントを整形する。
- -fca, --format-all-comments
- コメントの整形を全てを無効にしない。
- -gnu, --gnu-style
- GNU
コーディングスタイルを使用する。これはデフォルトの動作である。
- -hnl, --honour-newlines
- 入力ファイルで改行が入っている位置で
長い行を折り返すようにする。
- -in, --indent-leveln
- インデントのレベルを空白
n 個に設定する。
- -ipn, --parameter-indentationn
- 古い形式の関数定義のパラメータ型を空白
n
個でインデントする。
- -kr, --k-and-r-style
- Kernighan & Ritchie
コーディングスタイルを使用する。
- -ln, --line-lengthn
- コメントでない行の最大の長さを
n に設定する。
- -lcn, --comment-line-lengthn
- コメントを整形する最大の長さを
n に設定する。
- -lp, --continue-at-parentheses
- 前の行に続く行を括弧の位置に揃える。
- -lps, --leave-preprocessor-space
- `#´
とプリプロセッサディレクティブの間の空白を残す。
- -nbad, --no-blank-lines-after-declarations
- 宣言の後に空行を置かない。
- -nbap, --no-blank-lines-after-procedures
- 手続き本体の後に空行を置かない。
- -nbbo, --break-after-boolean-operator
- ブーリアン演算子の前で長い行を折り返さない。
- -nbc, --no-blank-lines-after-commas
- 宣言中のコンマの後に改行を置かない。
- -nbfda, --dont-break-function-decl-args
- 関数宣言の各引き数を別々の行に置かない。
- -ncdb, --no-comment-delimiters-on-blank-lines
- 空行にコメント区切り文字を置かない。
- -ncdw, --dont-cuddle-do-while
- do {} while; の } と while
を同じ行に並べない。
- -nce, --dont-cuddle-else
- } と else
を同じ行に並べない。
- -ncs, --no-space-after-casts
- キャスト演算子の後に空白を置かない。
- -nfc1, --dont-format-first-column-comments
- 最初のカラムから始まるコメントを通常のように整形しない。
- -nfca, --dont-format-comments
- どのようなコメントも整形しない。
- -nhnl, --ignore-newlines
- 入力ファイルで改行が入っている位置で
長い行を折り返さないようにする。
- -nip, --no-parameter-indentation
- パラメータのインデント幅を
0 にする。
- -nlp, --dont-line-up-parentheses
- 括弧の位置を揃えない。
- -npcs, --no-space-after-function-call-names
- 関数呼び出し内部の関数の後に空白を置かない。
- -nprs, --no-space-after-parentheses
- ´(´ の後と ´)´
の前に空白を置かない。
- -npsl, --dont-break-procedure-type
- 手続きの型を名前と同じ行に置く。
- -nsaf, --no-space-after-for
- for
の後に空白を置かない。
- -nsai, --no-space-after-if
- if
の後に空白を置かない。
- -nsaw, --no-space-after-while
- while
の後に空白を置かない。
- -nsc, --dont-star-comments
- `*´
文字をコメントの左に置かない。
- -nsob, --leave-optional-blank-lines
- 余計な空行を削除しない。
- -nss, --dont-space-special-semicolon
- 特定の文の後のセミコロンの前に空白を置かない。
`-ss´ を無効にする。
- -nut, --no-tabs
- タブではなく空白を使う。
- -nv, --no-verbosity
- 詳細表示モードを無効にする。
- -orig, --original
- オリジナルの Berkeley
コーディングスタイルを使用する。
- -npro, --ignore-profile
- `.indent.pro´
ファイルを読み込まない。
- -pcs, --space-after-procedure-calls
- 呼び出される手続きの名前と
`('
の間に空白を挿入する。
- -pin, --paren-indentationn
- 文が不完全な場合に使われる 開括弧 ´(´ ごとの追加のインデントを指定する。 「 文」セクションを参照すること。
- -pmt, --preserve-mtime
- 出力ファイルのアクセス時刻と修正時刻を保存する。 「 その他のオプション」セクションを参照すること。
- -prs, --space-after-parentheses
- ´(´ の後と ´)´
の前に空白を置く。
- -psl, --procnames-start-lines
- 手続きの型を名前と同じ行に置く。
- -saf, --space-after-for
- for
の後にスペースを置く。
- -sai, --space-after-if
- if
の後にスペースを置く。
- -saw, --space-after-while
- while
の後にスペースを置く。
- -sbin, --struct-brace-indentationn
- stract, union, enum
のブレースを n
個の空白でインデントする。
- -sc, --start-left-side-of-comments
- `*´
文字をコメントの左に置く。
- -sob, --swallow-optional-blank-lines
- 余計な空行を取り除く。
- -ss, --space-special-semicolon
- 1 行で記述した
for 文と while
文において、
セミコロンの前に空白を置く。
- -st, --standard-output
- 標準出力に書き出す。
- -T
- 型名の名前を
indent に指定する。
- -tsn, --tab-sizen
- タブの幅を空白
n 個に設定する。
- -ut, --use-tabs
- タブを使う。これがデフォルトである。
- -v, --verbose
- 詳細表示モードを有効にする。
- -version
- indent
のバージョン番号を表示する。
indent の起動¶
バージョン 1.3 からは、 indent コマンドの書式は 以下のようになっている:indent [ options] [input-files] indent [ options] [single-input-file] [-o output-file]
indent slithy_toves.c -o slithy_toves.out indent -st slithy_toves.c > slithy_toves.out cat slithy_toves.c | indent -o slithy_toves.out
indent -br test/metabolism.c -l85
indent --braces-on-if-line --line-length185 test/metabolism.c indent +braces-on-if-line +line-length185 test/metabolism.c
バックアップファイル¶
バージョン 1.3 からは、GNU indent は GNU 形式、 すなわち GNU Emacs と同様の方法でバックアップファイルを作成する。 つまり、 単純なバックアップファイルと 番号付きのバックアップファイルをどちらも作成できる。一般的なスタイル¶
C 言語には一般的なスタイルがいくつかある。 例えば、GNU スタイル、Kernighan & Ritchie スタイル、 オリジナルの Berkeley スタイル等である。 スタイルは バックグラウンドオプション 1 つを使って選択することができる。 このオプションは、他のオプション全ての値を指定する。 ただし、明示的に指定したオプションは、 暗黙的に指定されたオプションよりも必ず優先される。-nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2 -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai -saw -nsc -nsob
-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs -nprs -npsl -saf -sai -saw -nsc -nsob -nss
-nbad -nbap -bbo -bc -br -brs -c33 -cd33 -cdb -ce -ci4 -cli0 -cp33 -di16 -fc1 -fca -hnl -i4 -ip4 -l75 -lp -npcs -nprs -psl -saf -sai -saw -sc -nsob -nss -ts8
空行¶
各種プログラミングスタイルごとに、空白は異なる場所に置かれる。 indentには、特定の場所に空白行を挿入・削除するための オプションがたくさんある。--blank-lines-after-declarations¶
`-bad´ オプションを指定すると、宣言ブロックの後に必ず空行が置かれる。 `-nbad´ オプションを指定すると、このような空行は追加されない。char *foo; char *bar; /* このコメントは宣言のブロックを分けている */ int baz;
char *foo; char *bar; /* このコメントは宣言のブロックを分けている */ int baz;
char *foo; char *bar; /* このコメントは宣言のブロックを分けている */ int baz;
--blank-lines-after-procedures¶
`-bap´ オプションを指定すると、それぞれの宣言本体の後に必ず空行が置かれる。int foo () { puts("Hi"); } /* この手続き bar には意味はない */ char * bar () { puts("Hello"); }
int foo () { puts ("Hi"); } /* この手続き bar には意味はない */ char * bar () { puts ("Hello"); }
int foo () { puts ("Hi"); } /* この手続き bar には意味はない */ char * bar () { puts ("Hello"); }
コメント¶
indent は C と C++ のコメントを整形する。 C のコメントは `/*´ で始まって `*/´ で終り、 改行文字を含んでもよい。 C++ のコメントは区切り文字 `//´ で始まり改行で終る。/********************** * 箱の中のコメント!! * **********************/ /* * 別な種類のコメントには、 * 別な形式を使う。 */
/* Loving hug */
/* * Loving hug */
文¶
`-br´ または `-bl´ オプションは、ブレースをどのように整形するかを指定する。if (x > 0) { x--; }
if (x > 0) { x--; }
if (x > 0) { x--; }
if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); }
if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); }
do { x--; } while (x);
do { x--; } while (x);
switch (i) { case 0: break; case 1: { ++i; } default: break; }
switch (i) { case 0: break; case 1: { ++i; } default: break; }
switch (i) { case 0: break; case 1: { ++i; } default: break; }
while ( ( e_code - s_code ) < ( dec_ind - 1 ) ) { set_buf_break ( bb_dec_ind ); *e_code++ = ´ ´; }
宣言¶
デフォルトでは、 indent は `-di´ オプションで指定した カラムで識別子を揃える。 例えば、`-di16´ を指定すると以下のようになる:int foo; char *bar;
int foo; char *bar;
int foo;
int a, b, c;
int a, b, c;
void foo (int arg1, char arg2, int *arg3, long arg4, char arg5);は、`-bfda´ オプションを指定すると次のようになり、
void foo ( int arg1, char arg2, int *arg3, long arg4, char arg5);
void foo ( int arg1, char arg2, int *arg3, long arg4, char arg5 );
typedef unsigned long CODE_ADDR; typedef enum {red, blue, green} COLOR;
struct foo { int x; };
struct foo { int x; };
インデント付け¶
コードを整形する時の問題の 1 つは、 各行をどれだけ左端からインデントさせるかである。 if や for 等の文の先頭部分があると、 インデントの深さは `-i´ オプションで指定した値だけ増える。 例えば、レベルごとに 8 文字分のインデントさせるには `-i8´ を使う。 文が 2 行に折り返されている場合、 2 行目は `-ci´ オプションで指定した追加のスペース分だけインデントされる。 `-ci´ のデフォルト値は 0 である。 しかし、`-lp´ オプションが指定されており、かつ同じ行で閉じられていない 左括弧がある場合、その続きの行が始まる文字は左括弧の直後の位置に揃えられる。 この処理は `[´ および初期化リストに現われる `{´ にも適用される。 例えば、`-nlp -ci3´ が有効になっていると、 行をまたがるコードは以下のようになる:p1 = first_procedure (second_procedure (p2, p3), third_procedure (p4, p5));
p1 = first_procedure (second_procedure (p2, p3), third_procedure (p4, p5));
if ((((i < 2 && k > 0) || p == 0) && q == 1) || n = 0)
if ((((i < 2 && k > 0) || p == 0) && q == 1) || n = 0)
char * create_world (x, y, scale) int x; int y; float scale; { . . . }
#if X #if Y #define Z 1 #else #define Z 0 #endif #endifを次のように整形する。
#if X # if Y # define Z 1 # else # define Z 0 # endif #endif
長い行の折り返し¶
オプション `-l n´ または `--line-length n´ により、 C 言語コードの行の最大長を指定することができる。 ただしコードの後のコメントは含まない。if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´)))))
if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´)))))
if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´)))))
if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´)))))
整形の無効化¶
特別な 制御用コメントをプログラムに埋め込むことにより、 C 言語コードを部分的に整形しないようにすることができる。 プログラムのあるセクションを整形しないようにするためには、 無効化制御用コメント /* *INDENT-OFF* */ だけの行を セクションの直前に置けばよい。 この制御用コメントの後でスキャンされたプログラムテキストは、 有効化コメントだけの行がスキャンされるまで、 入力の通りに変更されず出力される。 有効化制御コメントは /* *INDENT-ON* */ であり、 このコメントと同じ行で後に続くテキストも整形されずに出力される。 有効化制御コメントの後に続く行から整形が再開される。その他のオプション¶
使っている indent のバージョンを知るには、 コマンド indent -version を用いること。 これを用いると、通常の処理は全く行われず、 indent のバージョン番号が表示される。バグ¶
バグは bug-indent@gnu.org に報告してほしい。著作権表示¶
以下の著作権表示は indent プログラムに適用される。 このマニュアルに関する著作権と複製許可については、 `indent.texinfo´ と `indent.info´ の先頭近くと `indent.1´ の末尾近くに記述されている。Copyright (c) 2001 David Ingamells. Copyright (c) 1999 Carlo Wood. Copyright (c) 1995, 1996 Joseph Arceneaux. Copyright (c) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Foundation Copyright (c) 1985 Sun Microsystems, Inc. Copyright (c) 1980 The Regents of the University of California. Copyright (c) 1976 Board of Trustees of the University of Illinois. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley, the University of Illinois, Urbana, and Sun Microsystems, Inc. The name of either University or Sun Microsystems may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS´´ AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
オプションの相互参照キー¶
長い名前についてアルファベット順に並べたオプションのリストを示す。 これを使えば対応する短いオプション名が簡単に分かる。--blank-lines-after-commas -bc --blank-lines-after-declarations -bad --blank-lines-after-procedures -bap --blank-lines-before-block-comments -bbb --braces-after-if-line -bl --brace-indent -bli --braces-after-struct-decl-line -bls --braces-on-if-line -br --braces-on-struct-decl-line -brs --break-after-boolean-operator -nbbo --break-before-boolean-operator -bbo --break-function-decl-args -bfda --break-function-decl-args-end -bfde --case-indentation -cli n --case-brace-indentation -cbi n --comment-delimiters-on-blank-lines -cdb --comment-indentation -c n --continuation-indentation -ci n --continue-at-parentheses -lp --cuddle-do-while -cdw --cuddle-else -ce --declaration-comment-column -cd n --declaration-indentation -di n --dont-break-function-decl-args -nbfda --dont-break-function-decl-args-end -nbfde --dont-break-procedure-type -npsl --dont-cuddle-do-while -ncdw --dont-cuddle-else -nce --dont-format-comments -nfca --dont-format-first-column-comments -nfc1 --dont-line-up-parentheses -nlp --dont-space-special-semicolon -nss --dont-star-comments -nsc --else-endif-column -cp n --format-all-comments -fca --format-first-column-comments -fc1 --gnu-style -gnu --honour-newlines -hnl --ignore-newlines -nhnl --ignore-profile -npro --indent-level -i n --k-and-r-style -kr --leave-optional-blank-lines -nsob --leave-preprocessor-space -lps --line-comments-indentation -d n --line-length -l n --no-blank-lines-after-commas -nbc --no-blank-lines-after-declarations -nbad --no-blank-lines-after-procedures -nbap --no-blank-lines-before-block-comments -nbbb --no-comment-delimiters-on-blank-lines -ncdb --no-space-after-casts -ncs --no-parameter-indentation -nip --no-space-after-for -nsaf --no-space-after-function-call-names -npcs --no-space-after-if -nsai --no-space-after-parentheses -nprs --no-space-after-while -nsaw --no-tabs -nut --no-verbosity -nv --original -orig --parameter-indentation -ip n --paren-indentation -pi n --preserve-mtime -pmt --procnames-start-lines -psl --space-after-cast -cs --space-after-for -saf --space-after-if -sai --space-after-parentheses -prs --space-after-procedure-calls -pcs --space-after-while -saw --space-special-semicolon -ss --standard-output -st --start-left-side-of-comments -sc --struct-brace-indentation -sbi n --swallow-optional-blank-lines -sob --tab-size -ts n --use-tabs -ut --verbose -v
返り値¶
不明。ファイル¶
$HOME/.indent.pro indent のデフォルトのオプションを設定する