Target Language Compiler | ![]() ![]() |
Output File Control
The structure of the output file control construct is
%openfile string optional-equal-string optional-mode %closefileid
%selectfileid
%openfile
The %openfile
directive opens a file or buffer for writing; the required string variable becomes a variable of type file
. For example,
%openfile x /% Opens and selects x for writing. %/ %openfile out ="
out.h"
/% Opens"
out.h"
for writing. %/
%selectfile
The %selectfile
directive selects the file specified by the variable as the current output stream. All output goes to that file until another file is selected using %selectfile
. For example,
%selectfile x /% Select file x for output. %/
%closefile
The %closefile
directive closes the specified file or buffer, and if this file is the currently selected stream, %closefile
invokes %selectfile
to reselect the last previously selected output stream.
There are two possible cases that %closefile
must handle:
%undef
.%assign x = "" /% Creates an empty string. %/ %openfile x "hello, world" %closefile x /% x ="
hello, world\n"
%/
If desired, you can append to an output file or string by using the optional mode, a
, as in
%openfile "foo.c", "a" %% Opens foo.c for appending.
![]() | Object-Oriented Facility for Generating Target Code | Input File Control | ![]() |