📄 termcap.texinfo
字号:
\input texinfo @c -*-texinfo-*-@setfilename ../info/termcap@settitle The Termcap Library@ifinfoThis file documents the termcap library of the GNU system.Copyright (C) 1988 Free Software Foundation, Inc.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.@ignorePermission is granted to process this file through TeX and print theresults, provided the printed document carries copying permissionnotice identical to this one except for the removal of this paragraph(this paragraph not being relevant to the printed manual).@end ignorePermission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided that the entireresulting derived work is distributed under the terms of a permissionnotice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that this permission notice may be stated in a translation approvedby the Foundation.@end ifinfo@setchapternewpage odd@titlepage@sp 6@center @titlefont{Termcap}@sp 1@center The Termcap Library and Data Base@sp 4@center First Edition@sp 1@center April 1988@sp 5@center Richard M. Stallman@sp 1@center Free Software Foundation@page@vskip 0pt plus 1filllCopyright @copyright{} 1988 Free Software Foundation, Inc.Published by the Free Software Foundation(675 Mass Ave, Cambridge MA 02139).Printed copies are available for $10 each.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided that the entireresulting derived work is distributed under the terms of a permissionnotice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that this permission notice may be stated in a translation approvedby the Foundation.@end titlepage@page@synindex vr fn@node Top, Introduction, (DIR), (DIR)@menu* Introduction::What is termcap? Why this manual?* Library:: The termcap library functions.* Data Base:: What terminal descriptions in @file{/etc/termcap} look like.* Capabilities::Definitions of the individual terminal capabilities: how to write them in descriptions, and how to use their values to do display updating.* Summary:: Brief table of capability names and their meanings.* Var Index:: Index of C functions and variables.* Cap Index:: Index of termcap capabilities.* Index:: Concept index.@end menu@node Introduction, Library, Top, Top@unnumbered Introduction@cindex termcap@dfn{Termcap} is a library and data base that enables programs to usedisplay terminals in a terminal-independent manner. It originated inBerkeley Unix.The termcap data base describes the capabilities of hundreds of differentdisplay terminals in great detail. Some examples of the informationrecorded for a terminal could include how many columns wide it is, whatstring to send to move the cursor to an arbitrary position (including howto encode the row and column numbers), how to scroll the screen up one orseveral lines, and how much padding is needed for such a scrollingoperation.The termcap library is provided for easy access this data base in programsthat want to do terminal-independent character-based display output.This manual describes the GNU version of the termcap library, which hassome extensions over the Unix version. All the extensions are identifiedas such, so this manual also tells you how to use the Unix termcap.The GNU version of the termcap library is available free as source code,for use in free programs, and runs on Unix and VMS systems (at least). Youcan find it in the GNU Emacs distribution in the files @file{termcap.c} and@file{tparam.c}.This manual was written for the GNU project, whose goal is to develop acomplete free operating system upward-compatible with Unix for userprograms. The project is approximately two thirds complete. For moreinformation on the GNU project, including the GNU Emacs editor and themostly-portable optimizing C compiler, send one dollar to@displayFree Software Foundation675 Mass AveCambridge, MA 02139@end display@node Library, Data Base, Introduction, Top@chapter The Termcap LibraryThe termcap library is the application programmer's interface to thetermcap data base. It contains functions for the following purposes:@itemize @bullet@itemFinding the description of the user's terminal type (@code{tgetent}).@itemInterrogating the description for information on various topics(@code{tgetnum}, @code{tgetflag}, @code{tgetstr}).@itemComputing and performing padding (@code{tputs}).@itemEncoding numeric parameters such as cursor positions into theterminal-specific form required for display commands (@code{tparam},@code{tgoto}).@end itemize@menu* Preparation:: Preparing to use the termcap library.* Find:: Finding the description of the terminal being used.* Interrogate:: Interrogating the description for particular capabilities.* Initialize:: Initialization for output using termcap.* Padding:: Outputting padding.* Parameters:: Encoding parameters such as cursor positions.@end menu@node Preparation, Find, Library, Library@section Preparing to Use the Termcap LibraryTo use the termcap library in a program, you need two kinds of preparation:@itemize @bullet@itemThe compiler needs declarations of the functions and variables in thelibrary.On GNU systems, it suffices to include the header file@file{termcap.h} in each source file that uses these functions andvariables.@refillOn Unix systems, there is often no such header file. Then you mustexplictly declare the variables as external. You can do likewise forthe functions, or let them be implicitly declared and cast theirvalues from type @code{int} to the appropriate type.We illustrate the declarations of the individual termcap libraryfunctions with ANSI C prototypes because they show how to pass thearguments. If you are not using the GNU C compiler, you probablycannot use function prototypes, so omit the argument types and namesfrom your declarations.@itemThe linker needs to search the library. Usually either@samp{-ltermcap} or @samp{-ltermlib} as an argument when linking willdo this.@refill@end itemize@node Find, Interrogate, Preparation, Library@section Finding a Terminal Description: @code{tgetent}@findex tgetentAn application program that is going to use termcap must first look up thedescription of the terminal type in use. This is done by calling@code{tgetent}, whose declaration in ANSI Standard C looks like:@exampleint tgetent (char *@var{buffer}, char *@var{termtype});@end example@noindentThis function finds the description and remembers it internally so thatyou can interrogate it about specific terminal capabilities(@pxref{Interrogate}).The argument @var{termtype} is a string which is the name for the type ofterminal to look up. Usually you would obtain this from the environmentvariable @code{TERM} using @code{getenv ("TERM")}.If you are using the GNU version of termcap, you can alternatively ask@code{tgetent} to allocate enough space. Pass a null pointer for@var{buffer}, and @code{tgetent} itself allocates the storage using@code{malloc}. In this case the returned value on success is the addressof the storage, cast to @code{int}. But normally there is no need for youto look at the address. Do not free the storage yourself.@refillWith the Unix version of termcap, you must allocate space for thedescription yourself and pass the address of the space as the argument@var{buffer}. There is no way you can tell how much space is needed, sothe convention is to allocate a buffer 2048 characters long and assume thatis enough. (Formerly the convention was to allocate 1024 characters andassume that was enough. But one day, for one kind of terminal, that wasnot enough.)No matter how the space to store the description has been obtained,termcap records its address internally for use when you later interrogatethe description with @code{tgetnum}, @code{tgetstr} or @code{tgetflag}. Ifthe buffer was allocated by termcap, it will be freed by termcap too if youcall @code{tgetent} again. If the buffer was provided by you, you mustmake sure that its contents remain unchanged for as long as you still planto interrogate the description.@refillThe return value of @code{tgetent} is @minus{}1 if there is some difficultyaccessing the data base of terminal types, 0 if the data base is accessiblebut the specified type is not defined in it, and some other valueotherwise.Here is how you might use the function @code{tgetent}:@example#ifdef unixstatic char term_buffer[2048];#else#define term_buffer 0#endifinit_terminal_data ()@{ char *termtype = getenv ("TERM"); int success; if (termtype == 0) fatal ("Specify a terminal type with `setenv TERM <yourtype>'.\n"); success = tgetent (term_buffer, termtype); if (success < 0) fatal ("Could not access the termcap data base.\n"); if (success == 0) fatal ("Terminal type `%s' is not defined.\n", termtype);@}@end example@noindentHere we assume the function @code{fatal} prints an error message and exits.If the environment variable @code{TERMCAP} is defined, its value is used tooverride the terminal type data base. The function @code{tgetent} checksthe value of @code{TERMCAP} automatically. If the value starts with@samp{/} then it is taken as a file name to use as the data base file,instead of @file{/etc/termcap} which is the standard data base. If thevalue does not start with @samp{/} then it is itself used as the terminaldescription, provided that the terminal type @var{termtype} is among thetypes it claims to apply to. @xref{Data Base}, for information on theformat of a terminal description.@refill@node Interrogate, Initialize, Find, Library@section Interrogating the Terminal DescriptionEach piece of information recorded in a terminal description is called a@dfn{capability}. Each defined terminal capability has a two-letter codename and a specific meaning. For example, the number of columns is named@samp{co}. @xref{Capabilities}, for definitions of all the standardcapability names.Once you have found the proper terminal description with @code{tgetent}(@pxref{Find}), your application program must @dfn{interrogate} it forvarious terminal capabilities. You must specify the two-letter code ofthe capability whose value you seek.Capability values can be numeric, boolean (capability is either present orabsent) or strings. Any particular capability always has the same valuetype; for example, @samp{co} always has a numeric value, while @samp{am}(automatic wrap at margin) is always a flag, and @samp{cm} (cursor motioncommand) always has a string value. The documentation of each capabilitysays which type of value it has.@refillThere are three functions to use to get the value of a capability,depending on the type of value the capability has. Here are theirdeclarations in ANSI C:@findex tgetnum@findex tgetflag@findex tgetstr@exampleint tgetnum (char *@var{name});int tgetflag (char *@var{name});char *tgetstr (char *@var{name}, char **@var{area});@end example@table @code@item tgetnumUse @code{tgetnum} to get a capability value that is numeric. Theargument @var{name} is the two-letter code name of the capability. If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -