1.3.3. - Controlling Output To the Printer and Data Files
spec's output facility is unusual. Output files and devices, including the screen, are turned on or off for output. The output of each printing command, whether generated by a user command or internally, is sent to all the turned-on devices.
open("filename")
opens a file or device to
append
output.
The current contents of existing files are never erased.
The
on("filename")
function turns on printing to the file or device
and opens the file if
open()
was not previously called.
The
off("filename")
function ends printing to that file or device, and
close("filename")
closes the file or device and removes
the name from the program's table of file pointers.
The name
"tty"
is special when used as an argument to these functions.
It always refers to your current terminal.
Whenever there is an error or a
^C
interrupt,
all files (except
log
files)
are turned off,
and output to the terminal is turned on.
A
log
file is used for debugging purposes and
is any file that begins with
log
. Output to
all
on
files and devices is automatically copied to a log file.
To get the status of all open files, type:
1.FOURC> on()
`tty' has output ON. `/usr/alan/default.dat' has output OFF. `/dev/null' has output OFF. 2.FOURC>
If you change spec's current directory, you can reference open files either by the name with which the files were opened or by the correct path name relative to the new directory.
The standard macros use three output devices: the screen, a printer and a data file. The
ont
,
offt
,
onp
,
offp
,
ond
and
offd
macros are usually used to simplify controlling output to these devices,
where
ont
is defined as
on("tty")
,
etc.
Typical usage is
ond; offt; printf("#S %d\n", ++SCAN_N); offd; ontOften, printing commands are placed between
onp
and
offp
to direct the output both to the screen and the printer.
For instance,
1.FOURC> onp; p "This is also being printed on the printer."; offp
This is also being printed on the printer. 2.FOURC>
Formatted printing is available using the
printf()
and
fprintf()
functions.
The
format specifications are the same as for the
C-language routine and can be found in the
printf()
write-up in any C reference manual.
1.FOURC> printf("The square root of two is %.12g.\n", sqrt(2))
The square root of two is 1.41421356237. 2.FOURC>