Purpose
Queries
terminal characteristics.
Library
Standard
C Library (libc.a)
Description
The termdef subroutine
returns a pointer to a null-terminated, static character string that
contains the value of a characteristic defined for the terminal specified
by the FileDescriptor parameter.
Asynchronous
Terminal Support
Shell profiles usually
set the TERM environment variable each time you log in. The stty command allows you to change the
lines and columns (by using the lines and cols options).
This is preferred over changing the LINES and COLUMNS environment
variables, since the termdef subroutine examines the environment
variables last. You consider setting LINES and COLUMNS environment
variables if:
- You
are using an asynchronous
terminal and want to override the lines and cols setting
in the terminfo database
- Your asynchronous terminal
has an unusual number of lines or columns and you are running an application
that uses the termdef subroutine but not an application which
uses the terminfo database (for example, curses).
This
is because the curses initialization subroutine, setupterm (setupterm Subroutine), calls the termdef subroutine
to determine the number of lines and columns on the display. If the termdef subroutine
cannot supply this information, the setupterm subroutine uses
the values in the terminfo database.
Parameters
Item |
Description |
FileDescriptor |
Specifies
an open file descriptor. |
Characteristic |
Specifies the characteristic that is to be queried. The following
values can be specified: - c
- Causes the termdef subroutine to query for the number
of "columns" for the terminal. This is determined by performing the
following actions:
- It requests a copy
of the terminal's winsize structure
by issuing the TIOCGWINSZ ioctl. If ws_col is
not 0, the ws_col value is used.
- If
the TIOCGWINSZ ioctl is unsuccessful
or if ws_col is 0, the termdef subroutine attempts to
use the value of the COLUMNS environment variable.
- If the COLUMNS environment variable
is not set, the termdef subroutine returns a pointer to a null
string.
- l
- Causes the termdef subroutine to query for the number
of "lines" (or rows) for the terminal. This is determined by performing
the following actions:
- It requests a
copy of the terminal's winsize structure
by issuing the TIOCGWINSZ ioctl. If ws_row is
not 0, the ws_row value is used.
- If
the TIOCGWINSZ ioctl is unsuccessful
or if ws_row is 0, the termdef subroutine attempts to
use the value of the LINES environment variable.
- If the LINES environment variable is
not set, the termdef subroutine returns a pointer to a null
string.
- Characters
other than c or l
- Cause the termdef subroutine
to query for the "terminal
type" of the terminal. This is determined by performing the following
actions:
- The termdef subroutine
attempts to
use the value of the TERM environment variable.
- If the TERM environment variable is
not set, the termdef subroutine returns a pointer to string
set to "dumb".
|
Examples
- To display the terminal
type of the standard input device, enter:
printf("%s\n", termdef(0, 't'));
- To display the current
lines and columns of the standard output device, enter:
printf("lines\tcolumns\n%s\t%s\n", termdef(2, 'l'),
termdef(2, 'c'));
Note: If the termdef subroutine
is unable to determine a value for lines or columns, it returns pointers
to null strings.