12.07.2015 Views

spec - Local Sector 7 web page

spec - Local Sector 7 web page

spec - Local Sector 7 web page

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Controlling Output Tothe Printer and Data Files<strong>spec</strong>’s output facility is unusual. Output files and devices, including the screen, areturned on or off for output. The output of each printing command, whether generatedby a user command or internally,issent to all the turned-on devices.open("filename") opens a file or device to append output. The current contents ofexisting files are never erased. The on("filename") function turns on printing tothe file or device and opens the file if open() was not previously called. Theoff("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 filepointers. The name "tty" is <strong>spec</strong>ial 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. Alog file is used for debugging purposes andis any file that begins with log . Output to all on files and devices is automaticallycopied to a log file.To get the status of all open files, type:13.FOURC> on()‘tty’ has output ON.‘/usr/alan/default.dat’ has output OFF.‘/dev/null’ has output OFF.14.FOURC>If you change <strong>spec</strong>’s current directory, you can reference open files either by thename with which the files were opened or by the correct path name relative to thenew 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 controllingoutput to these devices, where ont is defined as on("tty") ,etc. Typical usage isond; offt; printf("#S %d\n", ++SCAN_N); offd; ontOften, printing commands are placed between onp and offp to direct the output bothto the screen and the printer. For instance,1.FOURC> onp; p "This is also being printed on the printer."; offpThis is also being printed on the printer.2.FOURC>Formatted printing is available using the printf() and fprintf() functions. TheINTERIM WORK-IN-PROGRESS (8/16/01) NOT FOR GENERAL DISTRIBUTION USER MANUAL AND TUTORIALS 17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!