INDENT(1L) INDENT(1L) 名前 indent - 空白の挿入や削除を行い、C 言語プログラムの見栄えを変える。 書式 indent [options] [input-files] indent [options] [single-input-file] [-o output-file] indent --version 説明 この man ページはファイル indent.texinfo から生成した。これは indent バ ージョン 2.2.9 用の「The indent Manual」の 2.2.9 版 (2002 年 11 月 10 日版) である。 indent プログラムを使うとコードを読みやすくすることができる。また、C 言 語のコード記述を、あるスタイルから別のスタイルに変換することもできる。 indent はたくさんある C 言語の文法を理解するが、文法が不完全な部分や 誤 っている部分もできるだけ処理しようとする。 バージョン 1.2 以降では、GNU スタイルのインデントがデフォルトである。 オプション -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´ ファイルを読み込まない。 「indent の起動」セクションを参照すること。 -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 標準出力に書き出す。 「indent の起動」セクションを参照すること。 -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 と異なる。 最初の書式では 1 つ以上の入力ファイルを指定する。 indent は、各ファイル の バックアップコピーを作成してから、オリジナルのファイルをインデント付 けしたものに置き換える。バックアップの作り方については、「バックアッ プ ファイル」セクションを参照すること。 2 番目の書式では入力ファイルを 1 つだけ指定する。この場合、または標準入 力を使う場合には、 `-o´ オプションの後に出力ファイルを指定することが で きる。 indent に標準出力へ出力させるには `-st´ オプションを使う。これが許され るのは、入力ファイルが 1 つだけの場合か、標準入力を使う場合だけである。 入 力 ファイルを指定しなければ入力は標準入力から読み込まれる。また、`-´ というファイル名が指定された場合にも標準入力が読み込まれる。 使用例としては、以下のコマンドはいずれもプログラム `slithy_toves.c´ を 読み込み、インデント付けしたテキストを `slithy_toves.out´ に書き込む: 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 の他のオプションのほとんどは、プログラムをどのように整形するかを 制御するためのものである。バージョン 1.2 からは、indent は各オプショ ン 名として長い名前も認識する。長いオプションの前には `--´ か `+´ が置かれ る。 [POSIX 標準と一貫性を持たせるため、現在は `+´ を `--´ に置き換えよ うとしているところである。] 本 ドキュメントの大部分では、簡潔に表現するために伝統的な短い名前を使っ ている。長いオプション名と短いオプション名のリストは、「オプションの 概 要」を参照すること。 別の使用例を挙げる: indent -br test/metabolism.c -l85 これにより、プログラム `test/metabolism.c´ が `-br´ オプションと `-l85´ オプションを用いてインデント付けされ、その出力が `test/metabolism.c´ に 重ね書きされ、元の `test/metabolism.c´ の内容は `test´ ディレクトリにバ ックアップファイルとして書き込まれる。 この例と同じ指定を長いオプション名を用いて行うと以下のようになる: indent --braces-on-if-line --line-length185 test/metabolism.c indent +braces-on-if-line +line-length185 test/metabolism.c indent を頻繁に同じオプションで使うならば、これらを `.indent.pro´ と い うファイルに書いておくとよい。 indent は 3 つの場所でプロファイルファイ ルを探す。最初に環境変数 INDENT_PROFILE があるかをチェックする。この 環 境 変数がある場合、その値を使用するファイルの名前として解釈する。この環 境変数がない場合、indent はカレントディレクトリの `.indent.pro´ を探 し 、 も し 存 在 す れ ばこれを使う。 indent は最後にホームディレクトリの `.indent.pro´ を探し、もし存在すればこれを使う。この動作は従来のバー ジ ョ ン や 別バージョンの indent と異なる。これらは、両方のディレクトリに `.indent.pro´ ファイルがあれば、両方とも使用する。 `.indent.pro´ の書式は、コマンドラインに指定するのと同じく、空白 (タ ブ 、 ス ペ ー ス 、 改 行) で区切られた単なるオプションのリストである。 `.indent.pro´ のオプションは、 C または C++ のコメントで囲むことがで き る。コメントで囲んだオプションは無視される。 コマンドラインオプションが処理されるのは、 `.indent.pro´ を処理した後で ある。後から指定したオプションは、前に指定した引き数を上書きする。こ れ には例外が 1 つある: 明示的に指定したオプションは暗黙のオプションを必ず 上書きする(「一般的なスタイル」を参照)。 `-npro´ オプションを指定するこ とにより、 indent が `.indent.pro´ ファイルを読み込まないようにすること ができる。 バックアップファイル バージョン 1.3 からは、GNU indent は GNU 形式、すなわち GNU Emacs と 同 様 の方法でバックアップファイルを作成する。つまり、単純なバックアップフ ァイルと番号付きのバックアップファイルをどちらも作成できる。 単純なバックアップファイルの名前は、元のファイル名にサフィックスを追 加 して生成される。このサフィックスのデフォルト値は、 1 文字からなる文字列 `~´ (チルダ)である。したがって、`python.c´ のバックアップフ ァ イ ル は `python.c~´ となる。 環 境変数 SIMPLE_BACKUP_SUFFIX に好きな文字列を設定することにより、デフ ォルト値以外の任意の文字列をサフィックスとして使用できる。 ファイル `momeraths.c´ の番号付きバックアップは、 `momeraths.c.~23~´ の ようになる。ここで、23 はこのファイルのバックアップのバージョンである。 ファイル `src/momeraths.c´ のバックアップを作成するとき、バックアップフ ァイルの名前は `src/momeraths.c.~V~´ のようになる。ここで、V はディレク トリ `src´ に現在ある最も大きいバージョンより 1 大きい数字である。環 境 変 数 VERSION_WIDTH は、必要に応じて左側に 0 を追加することにより、数字 の桁数を制御する。例えばこの変数を "2" に設定すると、バックアップファイ ルの名前は `momeraths.c.~04~´ のようになる。 ど ちらの方法でバックアップファイルを作るかは、環境変数 VERSION_CONTROL で制御する。この文字列が `simple´ ならば、単純なバックアップだけが作 成 さ れる。この値が `numbered´ ならば、番号付きバックアップが作成される。 この値が `numbered-existing´ ならば、インデント付けするファイルの番号付 き のバックアップが既にある場合に、番号付きバックアップが作成される。そ れ以外の場合には、単純なバックアップが作成される。 VERSION_CONTROL が設 定されていなければ、 indent は `numbered-existing´ が指定されているもの として動作する。 別バージョンの indent は、サフィックス `.BAK´ を使ってバックアップフ ァ イルの名前を生成する。この動作は、SIMPLE_BACKUP_SUFFIX に `.BAK´ を設定 することによりエミュレートすることができる。 別バージョンの indent は、現在の GNU indent が行うようにソースファイ ル が あるディレクトリにバックアップを作成するのではなく、カレントディレク トリにバックアップを作成する点にも注意すること。 一般的なスタイル C 言語には一般的なスタイルがいくつかある。 例 え ば 、GNU ス タ イ ル 、Kernighan & Ritchie スタイル、オリジナルの Berkeley スタイル等である 。スタイルはバックグラウンドオプション 1 つを使って選択することができる 。 このオプションは、他のオプション全ての値を指定する。ただし、明示的に 指定したオプションは、暗黙的に指定されたオプションよりも必ず優先され る 。 バージョン 1.2 からは、GNU indent のデフォルトのスタイルは GNU スタイル である。したがって、このフォーマットで出力するために `-gnu´ オプショ ン を 指定する必要はなくなった。ただし、このオプションを指定してもエラーに はならない。 GNU スタイルに対応するオプション設定は以下である: -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 GNU コーディングスタイルは GNU プロジェクトで推奨されている。これは GNU Emacs の C モードが適用しようとするスタイルであり、 GNU Emacs の C で記 述された部分で使われているスタイルである。 (GNU プロジェクトのために プ ロ グ ラ ム を書くことに興味がある方は、「GNU コーディング規約 (The GNU Coding Standards)」を入手されたい。この文書では、メモリの使い方や整数の サイズ等、セマンティックや移植性についても説明されている。) Kernighan & Ritchie スタイルは有名な書籍「プログラミング言語 C (The C Programming Language)」で使われている。これは `-kr´ オプションで有効 と なる。 Kernighan & Ritchie スタイルは、以下のオプションの組合せと同等で ある: -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 Kernighan & Ritchie スタイルでは、コードがある行の右の部分にコメント が 入 れられることはない (コードの右に空白を 1 つだけ入れることもない)。し たがって、このスタイルのカラム数 33 というのは indent が勝手に決めた も のである: オ リジナルの Berkeley 版 indent のスタイルは、 `-orig´ (または長いオプ ション名 `--original´)を指定すれば得られる。このスタイルは、以下の設 定 と同じ意味である: -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に は、特定の場所に空白行を挿入・削除するためのオプションがたくさんある。 `-bad´ オプションを指定すると、 indent は宣言ブロック全ての後に必ず空行 を置く。 `-nbad´ オプションを指定すると、このような空白行は置かれない。 `-bap´ オプションを指定すると、手続き本体全ての後に必ず空行が置かれる。 `-nbap´ オプションを指定すると、このような空行は置かれない。 `-bbb´ オプションを指定すると、箱形コメント全ての前に必ず空行が置かれる (箱形コメントについては「コメント」セクションを参照すること)。 `-nbbb´ オプションを指定すると、このような空行は置かれない。 `-sob´ を指定すると、indent は省略できる空行を飲み込んでしまう (つまり 、入力行に含まれる省略できる空行が出力から全て削除される)。 `-nsob´ を 指定すると、入力行に含まれる空行は出力ファイルにも全てコピーされる。 --blank-lines-after-declarations `-bad´ オプションを指定すると、宣言ブロックの後に必ず空行が置かれる。 `-nbad´ オプションを指定すると、このような空行は追加されない。 例えば、以下の入力を与えると char *foo; char *bar; /* このコメントは宣言のブロックを分けている */ int baz; indent -bad の出力は以下のようになる。 char *foo; char *bar; /* このコメントは宣言のブロックを分けている */ int baz; また、indent -nbad の出力は以下のようになる。 char *foo; char *bar; /* このコメントは宣言のブロックを分けている */ int baz; --blank-lines-after-procedures `-bap´ オプションを指定すると、それぞれの宣言本体の後に必ず空行が置かれ る。 例えば、以下の入力を与えると int foo () { puts("Hi"); } /* この手続き bar には意味はない */ char * bar () { puts("Hello"); } indent -bap の出力は以下となる。 int foo () { puts ("Hi"); } /* この手続き bar には意味はない */ char * bar () { puts ("Hello"); } また、indent -nbap の出力は以下となる。 int foo () { puts ("Hi"); } /* この手続き bar には意味はない */ char * bar () { puts ("Hello"); } 手続き foo の後には空行は追加されない。 コメント indent は C と C++ のコメントを整形する。 C のコメントは `/*´ で始まっ て `*/´ で終り、改行文字を含んでもよい。 C++ のコメントは区 切 り 文 字 `//´ で始まり改行で終る。 indent はコメントの文脈によって別々の扱い方をする。 indent は文・宣言・ プリプロセッサディレクティブが後に続くコメントとどのコードの前にも置 か れ ていないコメントを区別する。どのコードの前にも置かれていないコメント とは、行が開始されるコメントのことである (カラム 1 から始まっている必要 はない)。 さ らに indent は手続きや集合体の外側にあるコメントと内側にあるコメント を区別する。特に手続きの内側で行の最初にあるコメントは、コードが現在 イ ン デントされているカラムにインデントされる。最も左側のカラムから始まる コメントは例外であり、コメントはそのカラムから出力される。 indent は箱形コメントを変更しない。 `*´ や `-´ で四角形や「箱形」に囲ん だ コメントは、他から視覚的に区別したいという一般的な意図があるためであ る。もっと正確に言うと、箱形コメントは次のように定義される。最初の `/*´ の 直後に文字 `*´, `=´, `_´, `-´ が続いているか、コメント開始区切り文字 (`/*´) だけの行があり、以降の行はコメント開始区切り文字の `*´ と同じ カ ラムから `*´ で行が開始される。 箱形コメントの例を示す: /********************** * 箱の中のコメント!! * **********************/ /* * 別な種類のコメントには、 * 別な形式を使う。 */ indent は箱形のコメントをソースファイルの中に見つかった場所に残しておく 。よってコメントのインデント付けは変わらず、その長さもどちらにしても 変 わ らない。別なモードでは、埋め込まれたタブ文字が適切な数の空白に変換さ れるだけである。 `-bbb´ オプションが指定された場合、箱形コメントがコードの前に置かれてい ないときは、箱形コメントの後に空行を置く。 箱 形でないコメントは整形される。これは、行が右端に合うように折り返され 、左側は空白で埋められるという意味である。 1 つの改行文字は空白と同じで あるが、 (1 行に 2 つ以上の改行文字がある) 空行はパラグラフの切れ目とし て解釈される。最初のカラムの後から始まるコメントの整形は、 `-fca´ オ プ シ ョ ンで有効になる。カラム 1 から始まるコメントを整形するには、`-fc1´ を指定する。このような整形は、デフォルトでは無効にされている。 整形する際の右端は、デフォルトでは 78 であるが、 `-lc´ オプションで変更 で きる。指定された右端まででコメントが表示できない場合、コメントの終り まで右端が自動的に拡張される。コメントが整形されない場合、右端の位置 は 守られない。 コ メントで行が開始される場合 (つまり、コメントの左側にプログラムの文字 列がない場合)、コメントがコードのブロック中になければ、そのコメントがあ ったカラムにインデントされる。この場合、(最初のカラムからコメントが開始 されていなければ) そのブロックのインデントされたコードにコメントの左 端 を 揃える。揃える位置は `-d´ オプションで変更可能で、何カラム左へ移動す るかを指定する。指定されない場合は、インデントされない。例え ば 、`-d2´ ではコードから左へ空白 2 個の位置にコメントを置く。デフォルトではコード にコメントの左端を揃える。ただし、コメントが最初のカラムから開始され て い る場合、デフォルトではインデントされない。最初のカラムから始まるコメ ントをコードに左揃えしたい場合は、 `-fc1´ を指定すること。 コードの右側にあるコメントは、デフォルトではカラム 33 にインデントさ れ る。これは次の 3 つのオプションのいずれかで変更できる。 `-c´ はコードの 後のコメントのカラムを指定する。 `-cd´ は宣言の後のコメントのカラムを指 定 する。 `-cp´ はプリプロセッサディレクティブ #else と #endif の後のコ メントのカラムを指定する。 コメントの左側にあるコードが最初のカラムから開始されていない場合、コ ー ド の終りの次のタブストップの位置からコメントカラムが開始される。プリプ ロセッサディレクティブが最初のカラムから開始されていない場合、ディレ ク ティブの終りの 1 カラム後からコメントカラムが開始される。この拡張はこの ような特定のカラムの出力に対してのみ適応される。 `-cdb´ オプションを指定すると、コメント区切り文字を空行に置く。よ っ て /* Loving hug */ のような 1 行のコメントは、以下のように変換される。 /* Loving hug */ `-sc´ オプションを指定すると、複数行コメントの始めに `*´ を置くことがで きる。上記の 1 行のコメントは (`-cdb -sc´ により) 以下のように変換さ れ る。 /* * Loving hug */ 文 `-br´ または `-bl´ オプションは、ブレースをどのように整形するかを指定す る。 `-br´ オプションを指定するとブレースは以下のように整形される: if (x > 0) { x--; } `-bl´ オプションを指定するとブレースは以下のように整形される: if (x > 0) { x--; } `-bl´ オプションを使う場合には `-bli´ オプションも使うとよい。このオ プ シ ョンはブレースのインデント付けに使う空白の数を指定する。 `-bli2´ (デ フォルト値)を指定すると、先に示した結果となる。 `-bli0´ を指定した場 合 の結果は以下である: if (x > 0) { x--; } `-br´ オプションを使う場合には、多分 `-ce´ も使いたくなるだろう。このオ プションは if-then-else 構文の else を直前の `}´ に隣に置く 。 例 え ば `-br -ce´ を指定すると、出力は以下のようになる: if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); } 同じコードで `-br -nce´ を指定すると以下のようになる: if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); } こ れにより do-while ループの while は直前の `}´ と同じ行に置かれる。例 えば `-cdw´ により以下のような出力が得られる。 do { x--; } while (x); 同じコードで `-ncdw´ を指定すると以下のようになる: do { x--; } while (x); `-cli´ オプションは、case 構文のラベルを switch 文から右にインデント す る際に空白をいくつ入れるかを指定する。 デフォルトでは以下のようなコードが得られる。 switch (i) { case 0: break; case 1: { ++i; } default: break; } `-cli2´ を使うと以下のようになる。 switch (i) { case 0: break; case 1: { ++i; } default: break; } case 文の後のブレースのインデントは、 `-cbin´ オプションで制御できる。 例えば `-cli2 -cbi0´ を使うと次のような結果になる。 switch (i) { case 0: break; case 1: { ++i; } default: break; } セミコロンが for または while 文と同じ行にある場合に `-ss´ を指定すると 、 空白がセミコロンの前に置かれる。これによりセミコロンが強調され、 for や while 文の本体が空の文であることがはっきりする。 `-nss´ を指定すると 、この機能は無効になる。 `-pcs´ オプションを指定すると、呼び出される手続きの名前と `(´ の間に空 白が置かれる (例えば、puts ("Hi"); となる。また、`-npcs´ オプションを指 定している場合には puts("Hi");) となる。) `-cs´ オプションを指定すると、 indent はキャスト演算子の後に空白を置く 。 `-bs´ オプションを指定すると、キーワード sizeof とその引き数の間に必 ず 空 白が置かれる。バージョンによっては、この機能は `Bill_Shannon´ オプシ ョンとして知られている。 `-saf´ オプションは for とその後の括弧の間に空白を入れる。これがデフ ォ ルトである。 `-sai´ オプションは if とその後の括弧の間に空白を入れる。これがデフォル トである。 `-saw´ オプションは while とその後の括弧の間に空白を入れる。これがデ フ ォルトである。 `-prs´ オプションは全ての括弧とその間にあるものの間に空白を置く。例えば `-prs´ を使うと以下のようなコードになる。 while ( ( e_code - s_code ) < ( dec_ind - 1 ) ) { set_buf_break ( bb_dec_ind ); *e_code++ = ´ ´; } 宣言 デフォルトでは、indent は `-di´ オプションで指定したカラムで識別子を 揃 える。例えば、`-di16´ を指定すると以下のようになる: int foo; char *bar; `-di´ オプションに小さい値 (1 や 2 など) を使うと、置くことが可能な最初 の場所に識別子を置くことができる。例を以下に示す: int foo; char *bar; この場合でも、`-di´ オプションに指定した値は型指定と異なる行に置いた 変 数には影響を与える。例えば、`-di2´ を指定すると以下のようになる: int foo; `-bc´ オプションを指定すると、宣言中のコンマの後に改行が置かれる。例を 以下に示す: int a, b, c; 同じコードで `-nbc´ オプションを指定した場合は以下のようになる: int a, b, c; `-bfda´ オプションを指定すると、関数宣言の引き数のコンマの後で改行を 入 れる。引き数は関数宣言より 1 段深くインデントされる。これは引き数のリス トが長い場合に特に役立つ。 `-bfde´ オプションを指定すると、関数宣言の閉 括 弧の前に改行を入れる。 2 つのオプションとも ´n´ を設定した -nbdfa と -nbdfe がデフォルトになる。 例えば、 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); 更に `-bfde´ オプションを指定すると次のようになる。 void foo ( int arg1, char arg2, int *arg3, long arg4, char arg5 ); `-psl´ オプションを指定すると、定義される手続きの型は手続きの名前の前の 行に置かれる。このスタイルは、etags プログラムや Emacs の c-mode の一部 の機能を正しく動作させるために必要である。 プログラム中で typedef で定義された型の名前を全て、 `-T´ オプションを使 っ て indent に教えなければならない。 `-T´ は複数個指定することができ、 指定された全ての名前を使うことができる。例えば、プログラムに typedef unsigned long CODE_ADDR; typedef enum {red, blue, green} COLOR; という記述がある場合には、オプション `-T CODE_ADDR -T COLOR´ を使うこと になるだろう。 `-brs´ や `-bls´ オプションは struct 宣言のブレースをどのように整形する かを指定する。 `-brs´ オプションはブレースを次のように整形する。 struct foo { int x; }; `-bls´ オプションはブレースを次のように整形する。 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)); `-lp´ を有効にすると、コードはいくらか見やすくなる: p1 = first_procedure (second_procedure (p2, p3), third_procedure (p4, p5)); 文 が 2 つ以上の括弧の組 (...) にわかれている場合、追加された括弧の組ご とに 1 段深くインデントされる。 if ((((i < 2 && k > 0) || p == 0) && q == 1) || n = 0) オプション `-ipN´ は、括弧ごとの追加オフセットを設定するのに使う。例 え ば `-ip0´ は上記のコードを次のように整形する。 if ((((i < 2 && k > 0) || p == 0) && q == 1) || n = 0) indent はタブが入力と出力のストリームの両方で一定の間隔で置かれることを 想定している。この間隔はデフォルトでは 8 カラム幅であるが、 (バージョン 1.2 からは) `-ts´ オプションで変更することができる。タブは複数個の空白 と同じ意味である。 古い形式の関数定義における型宣言のインデント付けは、 `-ip´ パラメータで 制 御することができる。これは、型宣言では空白何個分のインデントを行うか を指定する数値パラメータである。例えばデフォルトの `-ip5´ では、定義 は 以下のように整形される: char * create_world (x, y, scale) int x; int y; float scale; { . . . } 他 のバージョンの indent との互換性のためにオプション `-nip´ が用意され ている。これは `-ip0´ と同じである。 ANSI C ではプリプロセッサコマンドラインの文字 `#´ とコマンド名の間に 空 白 を入れることが許可されている。デフォルトでは indent はこの空白を削除 するが、 `-lps´ オプションを指定することで indent にこの空白を変更し な いように指示できる。オプション `-ppi´ は `-nlps´ と `-lps´ を上書きす る。 このオプションにより、プリプロセッサ条件文を指定された空白数でインデ ン トできる。例えばオプション `-ppi 3´ は #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 長い行の折り返し オ プション `-ln´ または `--line-lengthn´ により、 C 言語コードの行の最 大長を指定することができる。ただしコードの後のコメントは含まない。 指定された行の長さより長い場合、 GNU indent は行を論理的な位置で折り 返 す。これはバージョン 2.1 の新機能であるが、まだそれほど賢くはなく柔軟で もない。 どこで行を折り返すかを決定するアルゴリズムに干渉するためのオプション が 、現在のところ 2 つある。 `-bbo´ オプションを指定すると、GNU indent は長い行をブーリアン演算子 && と || の前で折り返す。 `-nbbo´ オプションを指定すると、GNU indent は 長 い行をブーリアン演算子の前で折り返さない。例えば、(`--line-length60´ と `--ignore-newlines´と一緒に) デフォルトのオプション `-bbo´ を指定するこ とにより、コードは以下のようになる。 if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´))))) オプション `-nbbo´ を使うと、次のようになる。 if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´))))) し かしデフォルトの `-hnl´ では、入力ファイルにおける改行を重視して、そ こで改行するように可能な限りの優先度を与える。例えば入力ファイルが以 下 のような場合、 if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´))))) オ プ シ ョ ン `-hnl´ または `--honour-newlines´ を上述の `-nbbo´ と `--line-length60´ と一緒に使うと、前の例で示したような出力ではなく、 入 力ファイルのコードで改行されている位置でなるべく折り返される。 if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´))))) こ の オ プションの背景となる考え方は、既に折り返されている長すぎる行は GNU indent で変更しないというものである。しかし本当に汚いコードは、少な く とも 1 回は `--ignore-newlines´ オプションを付けて indent に通してお くべきである。 整形の無効化 特別な制御用コメントをプログラムに埋め込むことにより、 C 言語コードを部 分 的に整形しないようにすることができる。プログラムのあるセクションを整 形しないようにするためには、無効化制御用コメント /* *INDENT-OFF* */ だ け の行をセクションの直前に置けばよい。この制御用コメントの後でスキャン されたプログラムテキストは、有効化コメントだけの行がスキャンされるま で 、入力の通りに変更されず出力される。有効化制御コメントは /* *INDENT-ON* */ であり、このコメントと同じ行で後に続くテキストも整形されずに出力され る。有効化制御コメントの後に続く行から整形が再開される。 も っと正確に言うと、indent は C 言語コメントの終了区切り文字 (*/) を検 証せず、その行の空白は存在が意識されない。 これらの制御コメントは、 C++ の書式、つまり // *INDENT-OFF* と // *INDENT-ON* でも機能する。 indent の内部状態は整形しないセクションでも変更されない、という点に注意 すべきである。よって、例えば関数の途中で整形を無効にして関数の終りま で 無 効にし続けた場合、変な結果になる。したがって、コードを整形しないこと を選択する場合は、モジュールにしておくのがよい。 歴史的な注意点: 以前のバージョンの indent では *INDENT** で始まるエラー メ ッセージを生成するものがあった。これらのバージョンの indent は、この ようなエラーメッセージで始まる入力テキスト行を無視するように書かれて い た。私はこの閉鎖的な機能を GNU indent から削除した。 その他のオプション 使っている indent のバージョンを知るには、コマンド indent -version を用 いること。これを用いると、通常の処理は全く行われず、 indent のバージ ョ ン番号が表示される。 `-v´ オプションを用いると、詳細表示モードを有効にすることができる。詳細 表示モードでは、indent は 1 つの行を出力で複数行にする時には報告を行 い 、実行終了時にサイズに関する情報を出力する。 `-pmt´ オプションを指定すると、indent は出力ファイルのアクセス時刻と修 正時刻を保存する。このオプションを使うと、全てのソースファイルとヘッ ダ ファイルに indent を実行しても、make はターゲットを再構築しない。このオ プションは POSIX utime(2) 関数があるオペレーティングシステムでのみ利 用 可能である。 バグ バグは bug-indent@gnu.org に報告してほしい。 同じプロファイルで 1 つのファイルに indent を 2 回実行した場合、 2 回目 はファイルを全く変更しないべきである。 indent の現在の設計では、それ は 保証できず、詳細にはテストされていない。 indent が C を理解しない。このため、行を結合できない場合もある。指定さ れたプロファイル (`.indent.pro´) で indent を実行した結果のファイルを入 力として使った場合でも、 indent を通したファイルが非可逆になる。 C++ に対して indent を動作させることを試みたが、とても簡単なものでない 限り、 C++ のソースに対しては良い結果が得られない。 出力ファイルにコメントを書き出している場合、 indent は 指 定 さ れ た `--line-length´ オプションを参照しない。そのため、たびたびコメントがか なり右に置かれる。コメントが末尾にある折り返された行を indent が結合 し な いようにするため、コメントが折り返しの最初の行から始まっていることを 確認すること。 /* *INDENT-OFF* */ によって indent が無効にされている場合、 indent は行 数やコメント数を数えない (`-v´ オプションを参照)。 /*UPPERCASE*/ という形式のコメントは、コメントとして扱われないが、次の 行と結合する識別子として扱われる。この動作によって、コードの最初に埋 め 込まれない限り、このタイプのコメントを無用なものにしてしまう。 著作権表示 以 下の著作権表示は 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 -clin --case-brace-indentation -cbin --comment-delimiters-on-blank-lines -cdb --comment-indentation -cn --continuation-indentation -cin --continue-at-parentheses -lp --cuddle-do-while -cdw --cuddle-else -ce --declaration-comment-column -cdn --declaration-indentation -din --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 -cpn --format-all-comments -fca --format-first-column-comments -fc1 --gnu-style -gnu --honour-newlines -hnl --ignore-newlines -nhnl --ignore-profile -npro --indent-level -in --k-and-r-style -kr --leave-optional-blank-lines -nsob --leave-preprocessor-space -lps --line-comments-indentation -dn --line-length -ln --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 -ipn --paren-indentation -pin --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 -sbin --swallow-optional-blank-lines -sob --tab-size -tsn --use-tabs -ut --verbose -v 返り値 不明。 ファイル $HOME/.indent.pro indent のデフォルトのオプションを設定する 著者 Carlo Wood Joseph Arceneaux Jim Kingdon David Ingamells 履歴 UCB の "indent" プログラムが起源である。 著作権 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Founda- tion, Inc. Copyright (C) 1995, 1996 Joseph Arceneaux. Copyright (C) 1999 Carlo Wood. Copyright (C) 2001 David Ingamells. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. INDENT(1L)
INDENT(1L) INDENT(1L) NAME indent - changes the appearance of a C program by inserting or deleting whitespace. SYNOPSIS indent [options] [input-files] indent [options] [single-input-file] [-o output-file] indent --version DESCRIPTION This man page is generated from the file indent.texinfo. This is Edi- tion of "The indent Manual", for Indent Version , last updated . The indent program can be used to make code easier to read. It can also convert from one style of writing C to another. indent understands a substantial amount about the syntax of C, but it also attempts to cope with incomplete and misformed syntax. In version 1.2 and more recent versions, the GNU style of indenting is the default. OPTIONS -bad, --blank-lines-after-declarations Force blank lines after the declarations. See BLANK LINES. -bap, --blank-lines-after-procedures Force blank lines after procedure bodies. See BLANK LINES. -bbb, --blank-lines-before-block-comments Force blank lines before block comments. See BLANK LINES. -bbo, --break-before-boolean-operator Prefer to break long lines before boolean operators. See BREAKING LONG LINES. -bc, --blank-lines-after-commas Force newline after comma in declaration. See DECLARATIONS. -bl, --braces-after-if-line Put braces on line after if, etc. See STATEMENTS. -blf, --braces-after-func-def-line Put braces on line following function definition line. See DECLARATIONS. -blin, --brace-indentn Indent braces n spaces. See STATEMENTS. -bls, --braces-after-struct-decl-line Put braces on the line after struct declaration lines. See DECLARATIONS. -br, --braces-on-if-line Put braces on line with if, etc. See STATEMENTS. -brf, --braces-on-func-def-line Put braces on function definition line. See DECLARATIONS. -brs, --braces-on-struct-decl-line Put braces on struct declaration line. See DECLARATIONS. -bs, --Bill-Shannon, --blank-before-sizeof Put a space between sizeof and its argument. See STATEMENTS. -cn, --comment-indentationn Put comments to the right of code in column n. See COMMENTS. -cbin, --case-brace-indentationn Indent braces after a case label N spaces. See STATEMENTS. -cdn, --declaration-comment-columnn Put comments to the right of the declarations in column n. See COMMENTS. -cdb, --comment-delimiters-on-blank-lines Put comment delimiters on blank lines. See COMMENTS. -cdw, --cuddle-do-while Cuddle while of do {} while; and preceding `}´. See COMMENTS. -ce, --cuddle-else Cuddle else and preceding `}´. See COMMENTS. -cin, --continuation-indentationn Continuation indent of n spaces. See STATEMENTS. -clin, --case-indentationn Case label indent of n spaces. See STATEMENTS. -cpn, --else-endif-columnn Put comments to the right of #else and #endif statements in column n. See COMMENTS. -cs, --space-after-cast Put a space after a cast operator. See STATEMENTS. -dn, --line-comments-indentationn Set indentation of comments not to the right of code to n spaces. See COMMENTS. -bfda, --break-function-decl-args Break the line before all arguments in a declaration. See DECLARATIONS. -bfde, --break-function-decl-args Break the line after the last argument in a declaration. See DECLARATIONS. -djn, --left-justify-declarations If -cd 0 is used then comments after declarations are left justi- fied behind the declaration. See DECLARATIONS. -din, --declaration-indentationn Put variables in column n. See DECLARATIONS. -fc1, --format-first-column-comments Format comments in the first column. See COMMENTS. -fca, --format-all-comments Do not disable all formatting of comments. See COMMENTS. -gnu, --gnu-style Use GNU coding style. This is the default. See COMMON STYLES. -hnl, --honour-newlines Prefer to break long lines at the position of newlines in the input. See BREAKING LONG LINES. -in, --indent-leveln Set indentation level to n spaces. See INDENTATION. -iln, --indent-labeln Set offset for labels to column n. See INDENTATION. -ipn, --parameter-indentationn Indent parameter types in old-style function definitions by n spaces. See INDENTATION. -kr, --k-and-r-style Use Kernighan & Ritchie coding style. See COMMON STYLES. -ln, --line-lengthn Set maximum line length for non-comment lines to n. See BREAKING LONG LINES. -lcn, --comment-line-lengthn Set maximum line length for comment formatting to n. See COMMENTS. -linux, --linux-style Use Linux coding style. See COMMON STYLES. -lp, --continue-at-parentheses Line up continued lines at parentheses. See INDENTATION. -lps, --leave-preprocessor-space Leave space between `#´ and preprocessor directive. See INDENTATION. -nlps, --remove-preprocessor-space Remove space between `#´ and preprocessor directive. See INDENTATION. -nbad, --no-blank-lines-after-declarations Do not force blank lines after declarations. See BLANK LINES. -nbap, --no-blank-lines-after-procedures Do not force blank lines after procedure bodies. See BLANK LINES. -nbbo, --break-after-boolean-operator Do not prefer to break long lines before boolean operators. See BREAKING LONG LINES. -nbc, --no-blank-lines-after-commas Do not force newlines after commas in declarations. See DECLARATIONS. -nbfda, --dont-break-function-decl-args Don´t put each argument in a function declaration on a separate line. See DECLARATIONS. -ncdb, --no-comment-delimiters-on-blank-lines Do not put comment delimiters on blank lines. See COMMENTS. -ncdw, --dont-cuddle-do-while Do not cuddle } and the while of a do {} while;. See STATEMENTS. -nce, --dont-cuddle-else Do not cuddle } and else. See STATEMENTS. -ncs, --no-space-after-casts Do not put a space after cast operators. See STATEMENTS. -ndjn, --dont-left-justify-declarations Comments after declarations are treated the same as comments after other statements. See DECLARATIONS. -nfc1, --dont-format-first-column-comments Do not format comments in the first column as normal. See COMMENTS. -nfca, --dont-format-comments Do not format any comments. See COMMENTS. -nhnl, --ignore-newlines Do not prefer to break long lines at the position of newlines in the input. See BREAKING LONG LINES. -nip, --no-parameter-indentation Zero width indentation for parameters. See INDENTATION. -nlp, --dont-line-up-parentheses Do not line up parentheses. See STATEMENTS. -npcs, --no-space-after-function-call-names Do not put space after the function in function calls. See STATEMENTS. -nprs, --no-space-after-parentheses Do not put a space after every ´(´ and before every ´)´. See STATEMENTS. -npsl, --dont-break-procedure-type Put the type of a procedure on the same line as its name. See DECLARATIONS. -nsaf, --no-space-after-for Do not put a space after every for. See STATEMENTS. -nsai, --no-space-after-if Do not put a space after every if. See STATEMENTS. -nsaw, --no-space-after-while Do not put a space after every while. See STATEMENTS. -nsc, --dont-star-comments Do not put the `*´ character at the left of comments. See COMMENTS. -nsob, --leave-optional-blank-lines Do not swallow optional blank lines. See BLANK LINES. -nss, --dont-space-special-semicolon Do not force a space before the semicolon after certain statements. Disables `-ss´. See STATEMENTS. -nut, --no-tabs Use spaces instead of tabs. See INDENTATION. -nv, --no-verbosity Disable verbose mode. See MISCELLANEOUS OPTIONS. -orig, --original Use the original Berkeley coding style. See COMMON STYLES. -npro, --ignore-profile Do not read `.indent.pro´ files. See INVOKING INDENT. -pcs, --space-after-procedure-calls Insert a space between the name of the procedure being called and the `(´. See STATEMENTS. -pin, --paren-indentationn Specify the extra indentation per open parentheses ´(´ when a statement is broken.See STATEMENTS. -pmt, --preserve-mtime Preserve access and modification times on output files.See MISCEL- LANEOUS OPTIONS. -ppin, --preprocessor-indentationn Specify the indentation for preprocessor conditional statements.See INDENTATION. -prs, --space-after-parentheses Put a space after every ´(´ and before every ´)´. See STATEMENTS. -psl, --procnames-start-lines Put the type of a procedure on the line before its name. See DECLARATIONS. -saf, --space-after-for Put a space after each for. See STATEMENTS. -sai, --space-after-if Put a space after each if. See STATEMENTS. -saw, --space-after-while Put a space after each while. See STATEMENTS. -sbin, --struct-brace-indentationn Indent braces of a struct, union or enum N spaces. See STATEMENTS. -sc, --start-left-side-of-comments Put the `*´ character at the left of comments. See COMMENTS. -sob, --swallow-optional-blank-lines Swallow optional blank lines. See BLANK LINES. -ss, --space-special-semicolon On one-line for and while statements, force a blank before the semicolon. See STATEMENTS. -st, --standard-output Write to standard output. See INVOKING INDENT. -T Tell indent the name of typenames. See DECLARATIONS. -tsn, --tab-sizen Set tab size to n spaces. See INDENTATION. -ut, --use-tabs Use tabs. This is the default. See INDENTATION. -v, --verbose Enable verbose mode. See MISCELLANEOUS OPTIONS. -version Output the version number of indent. See MISCELLANEOUS OPTIONS. INVOKING INDENT As of version 1.3, the format of the indent command is: indent [options] [input-files] indent [options] [single-input-file] [-o output-file] This format is different from earlier versions and other versions of indent. In the first form, one or more input files are specified. indent makes a backup copy of each file, and the original file is replaced with its indented version. See BACKUP FILES, for an explanation of how backups are made. In the second form, only one input file is specified. In this case, or when the standard input is used, you may specify an output file after the `-o´ option. To cause indent to write to standard output, use the `-st´ option. This is only allowed when there is only one input file, or when the standard input is used. If no input files are named, the standard input is read for input. Also, if a filename named `-´ is specified, then the standard input is read. As an example, each of the following commands will input the program `slithy_toves.c´ and write its indented text to `slithy_toves.out´: 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 Most other options to indent control how programs are formatted. As of version 1.2, indent also recognizes a long name for each option name. Long options are prefixed by either `--´ or `+´. [ `+´ is being super- seded by `--´ to maintain consistency with the POSIX standard.] In most of this document, the traditional, short names are used for the sake of brevity. See OPTION SUMMARY, for a list of options, including both long and short names. Here is another example: indent -br test/metabolism.c -l85 This will indent the program `test/metabolism.c´ using the `-br´ and `-l85´ options, write the output back to `test/metabolism.c´, and write the original contents of `test/metabolism.c´ to a backup file in the directory `test´. Equivalent invocations using long option names for this example would be: indent --braces-on-if-line --line-length185 test/metabolism.c indent +braces-on-if-line +line-length185 test/metabolism.c If you find that you often use indent with the same options, you may put those options into a file named `.indent.pro´. indent will look for a profile file in three places. First it will check the environment variable INDENT_PROFILE. If that exists its value is expected to name the file that is to be used. If the environment variable does not exist, indent looks for `.indent.pro´ in the current directory and use that if found. Finally indent will search your home directory for `.indent.pro´ and use that file if it is found. This behaviour is different from that of other versions of indent, which load both files if they both exist. The format of `.indent.pro´ is simply a list of options, just as they would appear on the command line, separated by white space (tabs, spaces, and newlines). Options in `.indent.pro´ may be surrounded by C or C++ comments, in which case they are ignored. Command line switches are handled after processing `.indent.pro´. Options specified later override arguments specified earlier, with one exception: Explicitly specified options always override background options (See COMMON STYLES). You can prevent indent from reading an `.indent.pro´ file by specifying the `-npro´ option. BACKUP FILES As of version 1.3, GNU indent makes GNU-style backup files, the same way GNU Emacs does. This means that either simple or numbered backup filenames may be made. Simple backup file names are generated by appending a suffix to the original file name. The default for this suffix is the one-character string `~´ (tilde). Thus, the backup file for `python.c´ would be `python.c~´. Instead of the default, you may specify any string as a suffix by set- ting the environment variable SIMPLE_BACKUP_SUFFIX to your preferred suffix. Numbered backup versions of a file `momeraths.c´ look like `momeraths.c.~23~´, where 23 is the version of this particular backup. When making a numbered backup of the file `src/momeraths.c´, the backup file will be named `src/momeraths.c.~V~´, where V is one greater than the highest version currently existing in the directory `src´. The environment variable VERSION_WIDTH controls the number of digits, using left zero padding when necessary. For instance, setting this variable to "2" will lead to the backup file being named `momeraths.c.~04~´. The type of backup file made is controlled by the value of the environ- ment variable VERSION_CONTROL. If it is the string `simple´, then only simple backups will be made. If its value is the string `numbered´, then numbered backups will be made. If its value is `numbered-exist- ing´, then numbered backups will be made if there already exist num- bered backups for the file being indented; otherwise, a simple backup is made. If VERSION_CONTROL is not set, then indent assumes the behaviour of `numbered-existing´. Other versions of indent use the suffix `.BAK´ in naming backup files. This behaviour can be emulated by setting SIMPLE_BACKUP_SUFFIX to `.BAK´. Note also that other versions of indent make backups in the current directory, rather than in the directory of the source file as GNU indent now does. COMMON STYLES There are several common styles of C code, including the GNU style, the Kernighan & Ritchie style, and the original Berkeley style. A style may be selected with a single background option, which specifies a set of values for all other options. However, explicitly specified options always override options implied by a background option. As of version 1.2, the default style of GNU indent is the GNU style. Thus, it is no longer necessary to specify the option `-gnu´ to obtain this format, although doing so will not cause an error. Option set- tings which correspond to the GNU style are: -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 The GNU coding style is that preferred by the GNU project. It is the style that the GNU Emacs C mode encourages and which is used in the C portions of GNU Emacs. (People interested in writing programs for Project GNU should get a copy of "The GNU Coding Standards", which also covers semantic and portability issues such as memory usage, the size of integers, etc.) The Kernighan & Ritchie style is used throughout their well-known book "The C Programming Language". It is enabled with the `-kr´ option. The Kernighan & Ritchie style corresponds to the following set of options: -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 Kernighan & Ritchie style does not put comments to the right of code in the same column at all times (nor does it use only one space to the right of the code), so for this style indent has arbitrarily chosen column 33. The style of the original Berkeley indent may be obtained by specifying `-orig´ (or by specifying `--original´, using the long option name). This style is equivalent to the following settings: -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 The Linux style is used in the linux kernel code and drivers. Code gen- erally has to follow the Linux coding style to be accepted. This style is equivalent to the following settings: -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1 BLANK LINES Various programming styles use blank lines in different places. indent has a number of options to insert or delete blank lines in specific places. The `-bad´ option causes indent to force a blank line after every block of declarations. The `-nbad´ option causes indent not to force such blank lines. The `-bap´ option forces a blank line after every procedure body. The `-nbap´ option forces no such blank line. The `-bbb´ option forces a blank line before every boxed comment (See COMMENTS.) The `-nbbb´ option does not force such blank lines. The `-sob´ option causes indent to swallow optional blank lines (that is, any optional blank lines present in the input will be removed from the output). If the `-nsob´ is specified, any blank lines present in the input file will be copied to the output file. --blank-lines-after-declarations The `-bad´ option forces a blank line after every block of declara- tions. The `-nbad´ option does not add any such blank lines. For example, given the input char *foo; char *bar; /* This separates blocks of declarations. */ int baz; indent -bad produces char *foo; char *bar; /* This separates blocks of declarations. */ int baz; and indent -nbad produces char *foo; char *bar; /* This separates blocks of declarations. */ int baz; --blank-lines-after-procedures The `-bap´ option forces a blank line after every procedure body. For example, given the input int foo () { puts("Hi"); } /* The procedure bar is even less interesting. */ char * bar () { puts("Hello"); } indent -bap produces int foo () { puts ("Hi"); } /* The procedure bar is even less interesting. */ char * bar () { puts ("Hello"); } and indent -nbap produces int foo () { puts ("Hi"); } /* The procedure bar is even less interesting. */ char * bar () { puts ("Hello"); } No blank line will be added after the procedure foo. COMMENTS indent formats both C and C++ comments. C comments are begun with `/*´, terminated with `*/´ and may contain newline characters. C++ comments begin with the delimiter `//´ and end at the newline. indent handles comments differently depending upon their context. indent attempts to distinguish between comments which follow state- ments, comments which follow declarations, comments following prepro- cessor directives, and comments which are not preceded by code of any sort, i.e., they begin the text of the line (although not necessarily in column 1). indent further distinguishes between comments found outside of proce- dures and aggregates, and those found within them. In particular, com- ments beginning a line found within a procedure will be indented to the column at which code is currently indented. The exception to this is a comment beginning in the leftmost column; such a comment is output at that column. indent attempts to leave boxed comments unmodified. The general idea of such a comment is that it is enclosed in a rectangle or ``box´´ of stars or dashes to visually set it apart. More precisely, boxed com- ments are defined as those in which the initial `/*´ is followed imme- diately by the character `*´, `=´, `_´, or `-´, or those in which the beginning comment delimiter (`/*´) is on a line by itself, and the fol- lowing line begins with a `*´ in the same column as the star of the opening delimiter. Examples of boxed comments are: /********************** * Comment in a box!! * **********************/ /* * A different kind of scent, * for a different kind of comment. */ indent attempts to leave boxed comments exactly as they are found in the source file. Thus the indentation of the comment is unchanged, and its length is not checked in any way. The only alteration made is that an embedded tab character may be converted into the appropriate number of spaces. If the `-bbb´ option is specified, all such boxed comments will be pre- ceded by a blank line, unless such a comment is preceded by code. Comments which are not boxed comments may be formatted, which means that the line is broken to fit within a right margin and left-filled with whitespace. Single newlines are equivalent to a space, but blank lines (two or more newlines in a row) are taken to mean a paragraph break. Formatting of comments which begin after the first column is enabled with the `-fca´ option. To format those beginning in column one, specify `-fc1´. Such formatting is disabled by default. The right margin for formatting defaults to 78, but may be changed with the `-lc´ option. If the margin specified does not allow the comment to be printed, the margin will be automatically extended for the dura- tion of that comment. The margin is not respected if the comment is not being formatted. If the comment begins a line (i.e., there is no program text to its left), it will be indented to the column it was found in unless the comment is within a block of code. In that case, such a comment will be aligned with the indented code of that block (unless the comment began in the first column). This alignment may be affected by the `-d´ option, which specifies an amount by which such comments are moved to the left, or unindented. For example, `-d2´ places comments two spaces to the left of code. By default, comments are aligned with code, unless they begin in the first column, in which case they are left there by default --- to get them aligned with the code, specify `-fc1´. Comments to the right of code will appear by default in column 33. This may be changed with one of three options. `-c´ will specify the column for comments following code, `-cd´ specifies the column for com- ments following declarations, and `-cp´ specifies the column for com- ments following preprocessor directives #else and #endif. `-dj´ together with `-cd0´ can be used to suppress alignment of comments to the right of declarations, causing the comment to follow one tabstop from the end of the declaration. Normally `-cd0´ causes `-c´ to become effective. If the code to the left of the comment exceeds the beginning column, the comment column will be extended to the next tabstop column past the end of the code, or in the case of preprocessor directives, to one space past the end of the directive. This extension lasts only for the output of that particular comment. The `-cdb´ option places the comment delimiters on blank lines. Thus, a single line comment like /* Loving hug */ can be transformed into: /* Loving hug */ Stars can be placed at the beginning of multi-line comments with the `-sc´ option. Thus, the single-line comment above can be transformed (with `-cdb -sc´) into: /* * Loving hug */ STATEMENTS The `-br´ or `-bl´ option specifies how to format braces. The `-br´ option formats statement braces like this: if (x > 0) { x--; } The `-bl´ option formats them like this: if (x > 0) { x--; } If you use the `-bl´ option, you may also want to specify the `-bli´ option. This option specifies the number of spaces by which braces are indented. `-bli2´, the default, gives the result shown above. `-bli0´ results in the following: if (x > 0) { x--; } If you are using the `-br´ option, you probably want to also use the `-ce´ option. This causes the else in an if-then-else construct to cuddle up to the immediately preceding `}´. For example, with `-br -ce´ you get the following: if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); } With `-br -nce´ that code would appear as if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); } This causes the while in a do-while loop to cuddle up to the immedi- ately preceding `}´. For example, with `-cdw´ you get the following: do { x--; } while (x); With `-ncdw´ that code would appear as do { x--; } while (x); The `-cli´ option specifies the number of spaces that case labels should be indented to the right of the containing switch statement. The default gives code like: switch (i) { case 0: break; case 1: { ++i; } default: break; } Using the `-cli2´ that would become: switch (i) { case 0: break; case 1: { ++i; } default: break; } The indentation of the braces below a case statement can be controlled with the `-cbin´ option. For example, using `-cli2 -cbi0´ results in: switch (i) { case 0: break; case 1: { ++i; } default: break; } If a semicolon is on the same line as a for or while statement, the `-ss´ option will cause a space to be placed before the semicolon. This emphasizes the semicolon, making it clear that the body of the for or while statement is an empty statement. `-nss´ disables this fea- ture. The `-pcs´ option causes a space to be placed between the name of the procedure being called and the `(´ (for example, puts ("Hi");. The `-npcs´ option would give puts("Hi");). If the `-cs´ option is specified, indent puts a space after a cast operator. The `-bs´ option ensures that there is a space between the keyword sizeof and its argument. In some versions, this is known as the `Bill_Shannon´ option. The `-saf´ option forces a space between a for and the following paren- thesis. This is the default. The `-sai´ option forces a space between a if and the following paren- thesis. This is the default. The `-saw´ option forces a space between a while and the following parenthesis. This is the default. The `-prs´ option causes all parentheses to be separated with a space from whatever is between them. For example, using `-prs´ results in code like: while ( ( e_code - s_code ) < ( dec_ind - 1 ) ) { set_buf_break ( bb_dec_ind ); *e_code++ = ´ ´; } DECLARATIONS By default indent will line up identifiers, in the column specified by the `-di´ option. For example, `-di16´ makes things look like: int foo; char *bar; Using a small value (such as one or two) for the `-di´ option can be used to cause the identifiers to be placed in the first available posi- tion; for example: int foo; char *bar; The value given to the `-di´ option will still affect variables which are put on separate lines from their types, for example `-di2´ will lead to: int foo; If the `-bc´ option is specified, a newline is forced after each comma in a declaration. For example, int a, b, c; With the `-nbc´ option this would look like int a, b, c; The `-bfda´ option causes a newline to be forced after the comma sepa- rating the arguments of a function declaration. The arguments will appear at one indention level deeper than the function declaration. This is particularly helpful for functions with long argument lists. The option `-bfde´ causes a newline to be forced before the closing bracket of the function declaration. For both options the ´n´ setting is the default: -nbdfa and -nbdfe. For example, void foo (int arg1, char arg2, int *arg3, long arg4, char arg5); With the `-bfda´ option this would look like void foo ( int arg1, char arg2, int *arg3, long arg4, char arg5); With, in addition, the `-bfde´ option this would look like void foo ( int arg1, char arg2, int *arg3, long arg4, char arg5 ); The `-psl´ option causes the type of a procedure being defined to be placed on the line before the name of the procedure. This style is required for the etags program to work correctly, as well as some of the c-mode functions of Emacs. You must use the `-T´ option to tell indent the name of all the type- names in your program that are defined by typedef. `-T´ can be speci- fied more than once, and all names specified are used. For example, if your program contains typedef unsigned long CODE_ADDR; typedef enum {red, blue, green} COLOR; you would use the options `-T CODE_ADDR -T COLOR´. The `-brs´ or `-bls´ option specifies how to format braces in struct declarations. The `-brs´ option formats braces like this: struct foo { int x; }; The `-bls´ option formats them like this: struct foo { int x; }; Similarly to the structure brace `-brs´ and `-bls´ options, the function brace options `-brf´ or `-blf´ specify how to format the braces in function definitions. The `-brf´ option formats braces like this: int one(void) { return 1; }; The `-blf´ option formats them like this: int one(void) { return 1; }; INDENTATION One issue in the formatting of code is how far each line should be indented from the left margin. When the beginning of a statement such as if or for is encountered, the indentation level is increased by the value specified by the `-i´ option. For example, use `-i8´ to specify an eight character indentation for each level. When a statement is broken across two lines, the second line is indented by a number of additional spaces specified by the `-ci´ option. `-ci´ defaults to 0. However, if the `-lp´ option is specified, and a line has a left paren- thesis which is not closed on that line, then continuation lines will be lined up to start at the character position just after the left parenthesis. This processing also applies to `[´ and applies to `{´ when it occurs in initialization lists. For example, a piece of con- tinued code might look like this with `-nlp -ci3´ in effect: p1 = first_procedure (second_procedure (p2, p3), third_procedure (p4, p5)); With `-lp´ in effect the code looks somewhat clearer: p1 = first_procedure (second_procedure (p2, p3), third_procedure (p4, p5)); When a statement is broken in between two or more paren pairs (...), each extra pair causes the indentation level extra indentation: if ((((i < 2 && k > 0) || p == 0) && q == 1) || n = 0) The option `-ipN´ can be used to set the extra offset per paren. For instance, `-ip0´ would format the above as: if ((((i < 2 && k > 0) || p == 0) && q == 1) || n = 0) indent assumes that tabs are placed at regular intervals of both input and output character streams. These intervals are by default 8 columns wide, but (as of version 1.2) may be changed by the `-ts´ option. Tabs are treated as the equivalent number of spaces. The indentation of type declarations in old-style function definitions is controlled by the `-ip´ parameter. This is a numeric parameter specifying how many spaces to indent type declarations. For example, the default `-ip5´ makes definitions look like this: char * create_world (x, y, scale) int x; int y; float scale; { . . . } For compatibility with other versions of indent, the option `-nip´ is provided, which is equivalent to `-ip0´. ANSI C allows white space to be placed on preprocessor command lines between the character `#´ and the command name. By default, indent removes this space, but specifying the `-lps´ option directs indent to leave this space unmodified. The option `-ppi´ overrides `-nlps´ and `-lps´. This option can be used to request that preprocessor conditional state- ments can be indented by to given number of spaces, for example with the option `-ppi 3´ #if X #if Y #define Z 1 #else #define Z 0 #endif #endif becomes #if X # if Y # define Z 1 # else # define Z 0 # endif #endif This option sets the offset at which a label (except case labels) will be positioned. If it is set to zero or a positive number, this indi- cates how far from the left margin to indent a label. If it is set to a negative number, this indicates how far back from the current indent level to place the label. The default setting is -2 which matches the behaviour of earlier versions of indent. Note that this parameter does not affect the placing of case labels; see the `-cli´ parameter for that. For example with the option `-il 1´ group function() { if (do_stuff1() == ERROR) goto cleanup1; if (do_stuff2() == ERROR) goto cleanup2; return SUCCESS; cleanup2: do_cleanup2(); cleanup1: do_cleanup1(); return ERROR; } becomes group function() { if (do_stuff1() == ERROR) goto cleanup1; if (do_stuff2() == ERROR) goto cleanup2; return SUCCESS; cleanup2: do_cleanup2(); cleanup1: do_cleanup1(); return ERROR; } BREAKING LONG LINES With the option `-ln´, or `--line-lengthn´, it is possible to specify the maximum length of a line of C code, not including possible comments that follow it. When lines become longer than the specified line length, GNU indent tries to break the line at a logical place. This is new as of version 2.1 however and not very intelligent or flexible yet. Currently there are two options that allow one to interfere with the algorithm that determines where to break a line. The `-bbo´ option causes GNU indent to prefer to break long lines before the boolean operators && and ||. The `-nbbo´ option causes GNU indent not have that preference. For example, the default option `-bbo´ (together with `--line-length60´ and `--ignore-newlines´) makes code look like this: if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´))))) Using the option `-nbbo´ will make it look like this: if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´))))) The default `-hnl´, however, honours newlines in the input file by giv- ing them the highest possible priority to break lines at. For example, when the input file looks like this: if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´))))) then using the option `-hnl´, or `--honour-newlines´, together with the previously mentioned `-nbbo´ and `--line-length60´, will cause the out- put not to be what is given in the last example but instead will prefer to break at the positions where the code was broken in the input file: if (mask && ((mask[0] == ´\0´) || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´))))) The idea behind this option is that lines which are too long, but are already broken up, will not be touched by GNU indent. Really messy code should be run through indent at least once using the `--ignore- newlines´ option though. DISABLING FORMATTING Formatting of C code may be disabled for portions of a program by embedding special control comments in the program. To turn off format- ting for a section of a program, place the disabling control comment /* *INDENT-OFF* */ on a line by itself just before that section. Program text scanned after this control comment is output precisely as input with no modifications until the corresponding enabling comment is scanned on a line by itself. The disabling control comment is /* *INDENT-ON* */, and any text following the comment on the line is also output unformatted. Formatting begins again with the input line fol- lowing the enabling control comment. More precisely, indent does not attempt to verify the closing delimiter (*/) for these C comments, and any whitespace on the line is totally transparent. These control comments also function in their C++ formats, namely // *INDENT-OFF* and // *INDENT-ON*. It should be noted that the internal state of indent remains unchanged over the course of the unformatted section. Thus, for example, turning off formatting in the middle of a function and continuing it after the end of the function may lead to bizarre results. It is therefore wise to be somewhat modular in selecting code to be left unformatted. As a historical note, some earlier versions of indent produced error messages beginning with *INDENT**. These versions of indent were writ- ten to ignore any input text lines which began with such error mes- sages. I have removed this incestuous feature from GNU indent. MISCELLANEOUS OPTIONS To find out what version of indent you have, use the command indent -version. This will report the version number of indent, without doing any of the normal processing. The `-v´ option can be used to turn on verbose mode. When in verbose mode, indent reports when it splits one line of input into two more more lines of output, and gives some size statistics at completion. The `-pmt´ option causes indent to preserve the access and modification times on the output files. Using this option has the advantage that running indent on all source and header files in a project won´t cause make to rebuild all targets. This option is only available on Operat- ing Systems that have the POSIX utime(2) function. BUGS Please report any bugs to bug-indent@gnu.org. When indent is run twice on a file, with the same profile, it should never change that file the second time. With the current design of indent, this can not be guaranteed, and it has not been extensively tested. indent does not understand C. In some cases this leads to the inability to join lines. The result is that running a file through indent is irreversible, even if the used input file was the result of running indent with a given profile (`.indent.pro´). While an attempt was made to get indent working for C++, it will not do a good job on any C++ source except the very simplest. indent does not look at the given `--line-length´ option when writing comments to the output file. This results often in comments being put far to the right. In order to prohibit indent from joining a broken line that has a comment at the end, make sure that the comments start on the first line of the break. indent does not count lines and comments (see the `-v´ option) when indent is turned off with /* *INDENT-OFF* */. Comments of the form /*UPPERCASE*/ are not treated as comment but as an identifier, causing them to be joined with the next line. This renders comments of this type useless, unless they are embedded in the code to begin with. COPYRIGHT The following copyright notice applies to the indent program. The copyright and copying permissions for this manual appear near the beginning of `indent.texinfo´ and `indent.info´, and near the end of `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. Options´ Cross Key Here is a list of options alphabetized by long option, to help you find the corresponding short option. --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 --braces-after-func-def-line -blf --brace-indent -bli --braces-after-struct-decl-line -bls --braces-on-if-line -br --braces-on-func-def-line -brf --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 -clin --case-brace-indentation -cbin --comment-delimiters-on-blank-lines -cdb --comment-indentation -cn --continuation-indentation -cin --continue-at-parentheses -lp --cuddle-do-while -cdw --cuddle-else -ce --declaration-comment-column -cdn --declaration-indentation -din --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-left-justify-declarations -ndj --dont-space-special-semicolon -nss --dont-star-comments -nsc --else-endif-column -cpn --format-all-comments -fca --format-first-column-comments -fc1 --gnu-style -gnu --honour-newlines -hnl --ignore-newlines -nhnl --ignore-profile -npro --indent-label -iln --indent-level -in --k-and-r-style -kr --leave-optional-blank-lines -nsob --leave-preprocessor-space -lps --left-justify-declarations -dj --line-comments-indentation -dn --line-length -ln --linux-style -linux --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 -ipn --paren-indentation -pin --preserve-mtime -pmt --preprocessor-indentation -ppin --procnames-start-lines -psl --remove-preprocessor-space -nlps --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 -sbin --swallow-optional-blank-lines -sob --tab-size -tsn --use-tabs -ut --verbose -v RETURN VALUE Unknown FILES $HOME/.indent.pro holds default options for indent. AUTHORS Carlo Wood Joseph Arceneaux Jim Kingdon David Ingamells HISTORY Derived from the UCB program "indent". COPYING Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Founda- tion, Inc. Copyright (C) 1995, 1996 Joseph Arceneaux. Copyright (C) 1999 Carlo Wood. Copyright (C) 2001 David Ingamells. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. INDENT(1L)
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa