Next: , Previous: Divert, Up: Diversions


9.2 出力を逆切替え(undivert)する

切替え先に出力されたテキスト(diverted text)は組み込みマクロ undivertを使って明示的に逆切替え(undivert)することができます。

     undivert(opt number, ...)

このマクロは引数で指定された切替え先を、指定された順に逆切替えして出力します。 引数が与えられなかったときは、すべての切替え先を番号順に逆切替えします。

undivertは展開されると消滅します。

     divert(1)
     This text is diverted.
     divert
     
     This text is not diverted.
     This text is not diverted.
     undivert(1)
     
     This text is diverted.
     

最後にある2つの空行に注目してください。 最後のものはundivert(1)に続く改行によるもので、 前のものはなんとdivert(1)に続く改行によるものです。 切替え先のテキストはしばしばこのような空行で始まります。

切替え先のテキスト(diverted text)は逆切替え(undiverted)されると、 m4によって再走査されずに、 現在の出力(切替え先)に直接コピーされます。 したがってある切替え先(diversion)へ出力中に、 逆切替え(undivert)しても問題ありません。

逆切替えをすると、その切替え先にあるテキストは破棄されるので 切替え先のテキストを取り出せるのは1回だけです。

     divert(1)
     This text is diverted first.
     divert(0)undivert(1)dnl
     
     This text is diverted first.
     undivert(1)
     
     divert(1)
     This text is also diverted but not appended.
     divert(0)undivert(1)dnl
     
     This text is also diverted but not appended.

現在の切替え先(current diversion)を逆切替え(undivert) しようとしても黙殺されます。

GNU m4では名前を指定したファイルを逆切替え(undivert) することができます。数字以外の引数を与えると、その名前をもつファイルの 内容が現在の出力(切替え先)に解釈されずにコピーされます。 これによって組み込みマクロincludeの機能が補完されます(see Include)。 次の例で違いを説明します。ファイルfooの内容は‘bar’だとします。

     define(`bar', `BAR')
     
     undivert(`foo')
     bar
     
     include(`foo')
     BAR