[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 2

termdef Subroutine

Purpose

Queries terminal characteristics.

Library

Standard C Library (libc.a)

Syntax


char *termdef ( FileDescriptor Characteristic)
int FileDescriptor;
char Characteristic;

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:

Parameters

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:
  1. 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.
  2. 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.
  3. 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:
  1. 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.
  2. 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.
  3. 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:
  1. The termdef subroutine attempts to use the value of the TERM environment variable.
  2. If the TERM environment variable is not set, the termdef subroutine returns a pointer to string set to "dumb".

Examples

  1. To display the terminal type of the standard input device, enter:

    printf("%s\n", termdef(0, 't'));
  2. 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.

Related Information

The setupterm (setupterm Subroutine) subroutine.

The stty command.

The Input and Output Handling Programmer's Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]