Termcap
Encyclopedia
Termcap is a software library and database
Database
A database is an organized collection of data for one or more purposes, usually in digital form. The data are typically organized to model relevant aspects of reality , in a way that supports processes requiring this information...

 used on Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 computers. It enables programs to use display computer terminal
Computer terminal
A computer terminal is an electronic or electromechanical hardware device that is used for entering data into, and displaying data from, a computer or a computing system...

s in a device-independent manner, which greatly simplifies the process of writing portable text mode
Text mode
Text mode is a kind of computer display mode in which the content of the screen is internally represented in terms of characters rather than individual pixels. Typically, the screen consists of a uniform rectangular grid of character cells, each of which contains one of the characters of a...

 applications. Bill Joy
Bill Joy
William Nelson Joy , commonly known as Bill Joy, is an American computer scientist. Joy co-founded Sun Microsystems in 1982 along with Vinod Khosla, Scott McNealy and Andy Bechtolsheim, and served as chief scientist at the company until 2003...

 wrote the first termcap library for the Berkeley Unix operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

; it has since been ported to most Unix and Unix-like environments. Joy's design was reportedly influenced by the design of the terminal data store in the earlier Incompatible Timesharing System
Incompatible Timesharing System
ITS, the Incompatible Timesharing System , was an early, revolutionary, and influential time-sharing operating system from MIT; it was developed principally by the Artificial Intelligence Laboratory at MIT, with some help from Project MAC.In addition to being technically influential ITS, the...

.

A termcap database can describe the capabilities of hundreds of different display terminals.
This allows external programs to be able to have character-based display output, independent of the type of terminal. On-screen text editors such as vi
Vi
vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by the Single Unix Specification and POSIX.The original code for vi...

 and emacs
Emacs
Emacs is a class of text editors, usually characterized by their extensibility. GNU Emacs has over 1,000 commands. It also allows the user to combine these commands into macros to automate work.Development began in the mid-1970s and continues actively...

 are examples of programs that may use termcap. Other programs are listed in the Termcap category.

Examples of what the database describes:
  • how many columns wide it is
  • what string to send to move the cursor to an arbitrary position (including how to encode the row and column numbers)
  • how to scroll the screen up one or several lines
  • how much padding is needed for such a scrolling operation.

Indices

Each description must contain the canonical
Canonical
Canonical is an adjective derived from canon. Canon comes from the greek word κανών kanon, "rule" or "measuring stick" , and is used in various meanings....

 name of the terminal. It may also contain one or more aliases for the name of the terminal. The canonical name or aliases are the keys by which the library searches the termcap database.

Data values

The description contains one or more capabilities, which have conventional names. The capabilities are typed: boolean, numeric and string. The termcap library has no predetermined type for each capability name. It determines the types of each capability by the syntax:
  • string capabilities have an "=" between the capability name and its value,
  • numeric capabilities have a "#" between the capability name and its value, and
  • boolean capabilities have no associated value (they are always true if specified).


Applications which use termcap do expect specific types for the commonly used capabilities, and obtain the values of capabilities from the termcap database using library calls that return successfully only when the database contents matches the assumed type.

Hierarchy

Termcap descriptions can be constructed by including the contents of one description in another, suppressing capabilities from the included description or overriding or adding capabilities. No matter what storage model
Storage model
A storage model is a model that captures key physical aspects of data structure in a data store.On the other hand, a data model is a model that captures key logical aspects of data structure in a database....

 is used, the termcap library constructs the terminal description from the requested description, including, suppressing or overriding at the time of the request.

Storage model

Termcap data is stored as text, making it simple to modify.
The text can be retrieved by the termcap library from files or environment variables.

Environment variable

The TERMCAP environment variable
Environment variable
Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.They can be said in some sense to create the operating environment in which a process runs...

 may contain a termcap database. It is most often used to store a single termcap description, set by a terminal emulator to provide the terminal's characteristics to the shell and dependent programs.

Flat file

The original (and most common) implementation of the termcap library retrieves data from a flat text file. Searching a large termcap file, e.g., 500Kb, can be slow. To aid performance, a utility such as reorder is used to put the most frequently used entries near the beginning of the file.

Hashed database

Newer implementations of termcap store the terminal description in a hashed database (e.g., something like Berkeley DB
Berkeley DB
Berkeley DB is a computer software library that provides a high-performance embedded database for key/value data. Berkeley DB is a programmatic software library written in C with API bindings for C++, PHP, Java, Perl, Python, Ruby, Tcl, Smalltalk, and most other programming languages...

 version 1.85). These store two types of records: aliases which point to the canonical entry, and the canonical entry itself. The text of the termcap entry is stored literally.

Limitations and extensions

The original termcap implementation was designed to use little memory:
  • the first name is two characters, to fit in 16 bits
  • capability names are two characters
  • descriptions are limited to 1023 characters.
  • only one description can be included, and must be at the end.


Newer implementations of the termcap interface generally do not require the two-character name at the beginning of the entry.

Capability names are still two characters in all implementations.

The tgetent function used to read the terminal description uses a buffer whose size must be large enough for the data, and is assumed to be 1024 characters. Newer implementations of the termcap interface may relax this constraint by allowing a null pointer in place of the fixed buffer, or by hiding the data which would not fit, e.g., via the ZZ capability in NetBSD
NetBSD
NetBSD is a freely available open source version of the Berkeley Software Distribution Unix operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed. The NetBSD project is primarily focused on high quality design,...

 termcap. The terminfo library interface also emulates the termcap interface, and does not actually use the fixed-size buffer.

The terminfo library's emulation of termcap allows multiple descriptions to be included without restricting the position. A few other newer implementations of the termcap library may also provide this ability, though it is not well documented.

External links

  • Current termcap data
  • Termcap/Terminfo Resources Page at Eric S. Raymond
    Eric S. Raymond
    Eric Steven Raymond , often referred to as ESR, is an American computer programmer, author and open source software advocate. After the 1997 publication of The Cathedral and the Bazaar, Raymond was for a number of years frequently quoted as an unofficial spokesman for the open source movement...

    's website
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK