Libraries and Packages: The VOS Interface

2.8 Terminal I/O -- tty

The tty interface is a table driven, device independent interface for controlling terminal and printer devices. Devices are described either by environment definitions, or by an entry in the tty database file. The tty database file is the standard Berkeley Unix termcap terminal capability database file (a text file), to which have been added entries for local printer devices. Accessing the Unix termcap file directly without modification is sometimes awkward, but the benefits of accessing a widely used, standard database more than compensate for any clumsiness.

When the cl starts up, the following environment variables are defined to describe the default terminal and printer devices. The user may subsequently change the values of these variables with the set statement or with the stty program.

Table 2.66: TTY Environment Variables.

The variables defining the names of the default terminal and printer devices will normally correspond to the names of device entries in the termcap file. The name of a file containing a single termcap entry for the device may optionally be given; the filename must contain a virtual filename (VFN) or operating system filename (OSFN) directory prefix to be recognized as a filename. The default termcap file is dev$termcap. Terminal initialization files (used to set tab stops) are files of the form dev$tty.tbi, where tty is the last field of the Unix pathname in the if termcap entry. If the first character of the if filename string is not a /, an IRAF VFN should be given.

The value strings for the environment variables ttyncols and ttynlines, defining the screen dimensions, are extracted from the termcap file by the stty program during start-up. The screen dimensions are defined in the environment for two reasons: efficiency, and if a window is used, the logical screen dimensions may be less than the physical screen dimensions. Most applications programs should therefore use envgeti() rather than ttygeti() to get the screen dimensions. ttygeti() returns the physical screen dimensions as given in the termcap file.

Open and Close

Before any tty control sequences can be output, the tty device descriptor must be read from the termcap file into a buffer for efficient access. ttyodes() is used to open the tty descriptor; ttycdes() should be called when done to close the descriptor, returning all buffer space used. If ttyname is terminal or printer, the descriptor for the default terminal or printer is accessed.

Table 2.67: TTY Open and Close Functions.

Low Level Database Access, TTY Control

The ttyget() procedures are used to get capabilities from the database entry. If the named capability is not found, ttygeti() returns zero, ttygetb() returns false, and ttygets() returns the null string. ttysubi() performs argument substitution on a control sequence containing at most two integer arguments (such as a cursor motion control sequence), generating an output sequence suitable for input to ttyputs(). ttyputs() puts the control sequence to the output file, padding as required given the number of affected lines. The baud rate and pad character, used to generate padding, are evaluated at ttyodes() time and are conveyed to ttyputs() in the tty descriptor.

Table 2.68: Low-Level TTY Database Functions.

ttygett() is implemented for int, real, and bool data types.

High-Level Control

Table 2.69: High-Level TTY Functions.

ttyctrl() calls ttygets() and ttyputs() to process and output a control sequence (slightly less efficiently than if the control string is buffered by the user code). ttygoto() moves the cursor to the desired column and line. ttyputline() is like the fio putline(), except that it processes any form feeds, standout mode directives, and other control characters (including tabs) embedded in the text. Lines longer than ttyncols are broken into several output lines. ttyputline() is used by the help, page, type, and lprint utilities to map tabs and standout mode directives for a particular output device. Standout mode is mapped as reverse video on most VDTs, and as underscore on most printers and on overstrike terminals such as the Tektronix 4012.

Table 2.66: - TTY Environment Variables.
Open and Close
Table 2.67: - TTY Open and Close Functions.
Low Level Database Access, TTY Control
Table 2.68: - Low-Level TTY Database Functions.
High-Level Control
Table 2.69: - High-Level TTY Functions.

Generated with CERN WebMaker