www.delorie.com/gnu/docs/m4/m4_41.html   search  
Buy GNU books!

GNU macro processor

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.5 Saving input

It is possible to `save' some text until the end of the normal input has been seen. Text can be saved, to be read again by m4 when the normal input has been exhausted. This feature is normally used to initiate cleanup actions before normal exit, e.g., deleting temporary files.

To save input text, use the builtin m4wrap:

m4wrap(string, ...)
which stores string and the rest of the arguments in a safe place, to be reread when end of input is reached.

define(`cleanup', `This is the `cleanup' actions.
This is the first and last normal input line.
=>This is the first and last normal input line.
=>This is the cleanup actions.

The saved input is only reread when the end of normal input is seen, and not if m4exit is used to exit m4.

It is safe to call m4wrap from saved text, but then the order in which the saved text is reread is undefined. If m4wrap is not used recursively, the saved pieces of text are reread in the opposite order in which they were saved (LIFO--last in, first out).

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003