⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 termcap.texi

📁 linux下bash的源码
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
@example@var{parm} -= 2 * (@var{parm} % 16);@end example@end table@node Using Parameters,  , Encode Parameters, Parameters@subsection Sending Display Commands with ParametersThe termcap library functions @code{tparam} and @code{tgoto} serve as theanalog of @code{printf} for terminal string parameters.  The newer function@code{tparam} is a GNU extension, more general but missing from Unixtermcap.  The original parameter-encoding function is @code{tgoto}, whichis preferable for cursor motion.@menu* tparam::      The general case, for GNU termcap only.* tgoto::       The special case of cursor motion.@end menu@node tparam, tgoto,  , Using Parameters@subsubsection @code{tparam}@findex tparamThe function @code{tparam} can encode display commands with any number ofparameters and allows you to specify the buffer space.  It is the preferredfunction for encoding parameters for all but the @samp{cm} capability.  ItsANSI C declaration is as follows:@smallexamplechar *tparam (char *@var{ctlstring}, char *@var{buffer}, int @var{size}, int @var{parm1},...)@end smallexampleThe arguments are a control string @var{ctlstring} (the value of a terminalcapability, presumably), an output buffer @var{buffer} and @var{size}, andany number of integer parameters to be encoded.  The effect of@code{tparam} is to copy the control string into the buffer, encodingparameters according to the @samp{%} sequences in the control string.You describe the output buffer by its address, @var{buffer}, and its sizein bytes, @var{size}.  If the buffer is not big enough for the data to bestored in it, @code{tparam} calls @code{malloc} to get a larger buffer.  Ineither case, @code{tparam} returns the address of the buffer it ultimatelyuses.  If the value equals @var{buffer}, your original buffer was used.Otherwise, a new buffer was allocated, and you must free it after you aredone with printing the results.  If you pass zero for @var{size} and@var{buffer}, @code{tparam} always allocates the space with @code{malloc}.All capabilities that require parameters also have the ability to specifypadding, so you should use @code{tputs} to output the string produced by@code{tparam}.  @xref{Padding}.  Here is an example.@example@{char *buf;char buffer[40];buf = tparam (command, buffer, 40, parm);tputs (buf, 1, fputchar);if (buf != buffer)free (buf);@}@end exampleIf a parameter whose value is zero is encoded with @samp{%.}-styleencoding, the result is a null character, which will confuse @code{tputs}.This would be a serious problem, but luckily @samp{%.} encoding is usedonly by a few old models of terminal, and only for the @samp{cm}capability.  To solve the problem, use @code{tgoto} rather than@code{tparam} to encode the @samp{cm} capability.@refill@node tgoto,  , tparam, Using Parameters@subsubsection @code{tgoto}@findex tgotoThe special case of cursor motion is handled by @code{tgoto}.  Thereare two reasons why you might choose to use @code{tgoto}:@itemize @bullet@itemFor Unix compatibility, because Unix termcap does not have @code{tparam}.@itemFor the @samp{cm} capability, since @code{tgoto} has a special featureto avoid problems with null characters, tabs and newlines on certain oldterminal types that use @samp{%.} encoding for that capability.@end itemizeHere is how @code{tgoto} might be declared in ANSI C:@examplechar *tgoto (char *@var{cstring}, int @var{hpos}, int @var{vpos})@end exampleThere are three arguments, the terminal description's @samp{cm} string andthe two cursor position numbers; @code{tgoto} computes the parametrizedstring in an internal static buffer and returns the address of that buffer.The next time you use @code{tgoto} the same buffer will be reused.@vindex UP@vindex BCParameters encoded with @samp{%.} encoding can generate null characters,tabs or newlines.  These might cause trouble: the null character because@code{tputs} would think that was the end of the string, the tab becausethe kernel or other software might expand it into spaces, and the newlinebecaue the kernel might add a carriage-return, or padding charactersnormally used for a newline.  To prevent such problems, @code{tgoto} iscareful to avoid these characters.  Here is how this works: if the targetcursor position value is such as to cause a problem (that is to say, zero,nine or ten), @code{tgoto} increments it by one, then compensates byappending a string to move the cursor back or up one position.The compensation strings to use for moving back or up are found in globalvariables named @code{BC} and @code{UP}.  These are actual external Cvariables with upper case names; they are declared @code{char *}.  It is upto you to store suitable values in them, normally obtained from the@samp{le} and @samp{up} terminal capabilities in the terminal descriptionwith @code{tgetstr}.  Alternatively, if these two variables are both zero,the feature of avoiding nulls, tabs and newlines is turned off.It is safe to use @code{tgoto} for commands other than @samp{cm} only ifyou have stored zero in @code{BC} and @code{UP}.Note that @code{tgoto} reverses the order of its operands: the horizontalposition comes before the vertical position in the arguments to@code{tgoto}, even though the vertical position comes before the horizontalin the parameters of the @samp{cm} string.  If you use @code{tgoto} with acommand such as @samp{AL} that takes one parameter, you must pass theparameter to @code{tgoto} as the ``vertical position''.@refill@node Data Base, Capabilities, Library, Top@chapter The Format of the Data BaseThe termcap data base of terminal descriptions is stored in the file@file{/etc/termcap}.  It contains terminal descriptions, blank lines, andcomments.A terminal description starts with one or more names for the terminal type.The information in the description is a series of @dfn{capability names}and values.  The capability names have standard meanings(@pxref{Capabilities}) and their values describe the terminal.@menu* Format::      Overall format of a terminal description.* Capability Format::  Format of capabilities within a description.* Naming::      Naming conventions for terminal types.* Inheriting::  Inheriting part of a description froma related terminal type.* Changing::    When changes in the data base take effect.@end menu@node Format, Capability Format,  , Data Base@section Terminal Description Format@cindex description formatAside from comments (lines starting with @samp{#}, which are ignored), eachnonblank line in the termcap data base is a terminal description.A terminal description is nominally a single line, but it can be splitinto multiple lines by inserting the two characters @samp{\ newline}.This sequence is ignored wherever it appears in a description.The preferred way to split the description is between capabilities: insertthe four characters @samp{: \ newline tab} immediately before any colon.This allows each sub-line to start with some indentation.  This worksbecause, after the @samp{\ newline} are ignored, the result is @samp{: tab:}; the first colon ends the preceding capability and the second colonstarts the next capability.  If you split with @samp{\ newline} alone, youmay not add any indentation after them.Here is a real example of a terminal description:@exampledw|vt52|DEC vt52:\        :cr=^M:do=^J:nl=^J:bl=^G:\        :le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:\        :cm=\EY%+ %+ :co#80:li#24:\        :nd=\EC:ta=^I:pt:sr=\EI:up=\EA:\        :ku=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H:@end exampleEach terminal description begins with several names for the terminal type.The names are separated by @samp{|} characters, and a colon ends the lastname.  The first name should be two characters long; it exists only for thesake of very old Unix systems and is never used in modern systems.  Thelast name should be a fully verbose name such as ``DEC vt52'' or ``AnnArbor Ambassador with 48 lines''.  The other names should include whateverthe user ought to be able to specify to get this terminal type, such as@samp{vt52} or @samp{aaa-48}.  @xref{Naming}, for information on how tochoose terminal type names.After the terminal type names come the terminal capabilities, separated bycolons and with a colon after the last one.  Each capability has atwo-letter name, such as @samp{cm} for ``cursor motion string'' or @samp{li}for ``number of display lines''.@node Capability Format, Naming, Format, Data Base@section Writing the CapabilitiesThere are three kinds of capabilities: flags, numbers, and strings.  Eachkind has its own way of being written in the description.  Each definedcapability has by convention a particular kind of value; for example,@samp{li} always has a numeric value and @samp{cm} always a string value.A flag capability is thought of as having a boolean value: the value istrue if the capability is present, false if not.  When the capability ispresent, just write its name between two colons.A numeric capability has a value which is a nonnegative number.  Write thecapability name, a @samp{#}, and the number, between two colons.  Forexample, @samp{@dots{}:li#48:@dots{}} is how you specify the @samp{li}capability for 48 lines.@refillA string-valued capability has a value which is a sequence of characters.Usually these are the characters used to perform some display operation.Write the capability name, a @samp{=}, and the characters of the value,between two colons.  For example, @samp{@dots{}:cm=\E[%i%d;%dH:@dots{}} ishow the cursor motion command for a standard ANSI terminal would bespecified.@refillSpecial characters in the string value can be expressed using@samp{\}-escape sequences as in C; in addition, @samp{\E} stands for@key{ESC}.  @samp{^} is also a kind of escape character; @samp{^} followedby @var{char} stands for the control-equivalent of @var{char}.  Thus,@samp{^a} stands for the character control-a, just like @samp{\001}.@samp{\} and @samp{^} themselves can be represented as @samp{\\} and@samp{\^}.@refillTo include a colon in the string, you must write @samp{\072}.  You mightask, ``Why can't @samp{\:} be used to represent a colon?''  The reason isthat the interrogation functions do not count slashes while looking for acapability.  Even if @samp{:ce=ab\:cd:} were interpreted as giving the@samp{ce} capability the value @samp{ab:cd}, it would also appear to define@samp{cd} as a flag.The string value will often contain digits at the front to specify padding(@pxref{Padding}) and/or @samp{%}-sequences within to specify how to encodeparameters (@pxref{Parameters}).  Although these things are not to beoutput literally to the terminal, they are considered part of the value ofthe capability.  They are special only when the string value is processedby @code{tputs}, @code{tparam} or @code{tgoto}.  By contrast, @samp{\} and@samp{^} are considered part of the syntax for specifying the charactersin the string.Let's look at the VT52 example again:@exampledw|vt52|DEC vt52:\        :cr=^M:do=^J:nl=^J:bl=^G:\        :le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:\        :cm=\EY%+ %+ :co#80:li#24:\             :nd=\EC:ta=^I:pt:sr=\EI:up=\EA:\        :ku=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H:@end exampleHere we see the numeric-valued capabilities @samp{co} and @samp{li}, theflags @samp{bs} and @samp{pt}, and many string-valued capabilities.  Mostof the strings start with @key{ESC} represented as @samp{\E}.  The restcontain control characters represented using @samp{^}.  The meanings of theindividual capabilities are defined elsewhere (@pxref{Capabilities}).@node Naming, Inheriting, Capability Format, Data Base@section Terminal Type Name Conventions@cindex names of terminal typesThere are conventions for choosing names of terminal types.  For one thing,all letters should be in lower case.  The terminal type for a terminal inits most usual or most fundamental mode of operation should not have ahyphen in it.If the same terminal has other modes of operation which requiredifferent terminal descriptions, these variant descriptions are givennames made by adding suffixes with hyphens.  Such alternate descriptionsare used for two reasons:@itemize @bullet@itemWhen the terminal has a switch that changes its behavior.  Since thecomputer cannot tell how the switch is set, the user must tell thecomputer by choosing the appropriate terminal type name.@cindex wrappingFor example, the VT-100 has a setup flag that controls whether thecursor wraps at the right margin.  If this flag is set to ``wrap'',you must use the terminal type @samp{vt100-am}.  Otherwise you mustuse @samp{vt100-nam}.  Plain @samp{vt100} is defined as a synonym foreither @samp{vt100-am} or @samp{vt100-nam} depending on thepreferences of the local site.@refillThe standard suffix @samp{-am} stands for ``automatic margins''.@itemTo give the user a choice in how to use the terminal.  This is donewhen the terminal has a switch that the computer normally controls.@cindex screen sizeFor example, the Ann Arbor Ambassador can be configured with manyscreen sizes ranging from 20 to 60 lines.  Fewer lines make biggercharacters but more lines let you see more of what you are editing.As a result, users have different preferences.  Therefore, termcapprovides terminal types for many screen sizes.  If you choose type@samp{aaa-30}, the terminal will be configured to use 30 lines; if youchoose @samp{aaa-48}, 48 lines will be used, and so on.@end itemizeHere is a list of standard suffixes and their conventional meanings:@table @samp@item -wShort for ``wide''.  This is a mode that gives the terminal morecolumns than usual.  This is normally a user option.@item -am``Automatic margins''.  This is an alternate description for use when

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -