2.4.2.1. - Controlling Output Files
With this group of functions, the names
"tty"
and
"/dev/tty"
,
when used for
filename
,
are special and refers to the user's terminal.
The names
"null"
and
"/dev/null"
are also special and when used as as an output device,
result in no output.
The name
"pipe"
is also special, but only when spec is invoked with the -p
flag, where it refers to the special data
stream from spec to a front-end
program.
open()
-
Lists all open files, including their directories,
and indicates which files are currently turned on
for output.
Returns zero.
open(filename)
-
Makes
filename
, which is a string constant or expression, available for output. Files are opened to append. Returns zero for success, -1 if the file can not be opened or if there are too many open files. If thespec_par()
"check_file_name"
option is on, and iffilename
contains any of the characters()[]{}|$\'\`*?;!&<>\\@
, spec will print an error message and the function will return an error, unless the file already exists. close(filename)
-
Closes
filename
and removes it from the table of files available for output. Returns zero for success, -1 if the file wasn't open. Files should be closed before modifying them with editors. on()
-
Lists all open files and indicates which ones are currently turned on
for output.
on(filename)
-
Turns on
filename
for output. All messages, except for some error and debugging messages, but including allprint
andprintf()
output, are sent to all turned-on devices. Iffilename
has not been made available for output with theopen()
function, it will be opened. Returns zero for success, -1 if the file can't be opened or if there are too many open files. off(filename)
-
Turns off output
to
filename
, but keeps it in the list of files available for output. If this was the last turned-on file or device,tty
is turned back on automatically. Returns zero for success, -1 if the file wasn't open.
spec remembers the directory the files are in when they are first opened. If the user changes spec's current directory, open files may be referenced either by the name with which the files were opened or by the correct path name relative to the current directory. If an open file disappears from the file system (for example, if a user removes the file using a subshell), the next time the file is written to, spec prints a warning message and creates a new instance of the file.
Files should be closed before attempting to edit them outside of spec.
Errors during parsing or execution of commands, or typing a
^C
turns off all open files except
log
files (see next section).