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

📄 termcap.texinfo

📁 早期freebsd实现
💻 TEXINFO
📖 第 1 页 / 共 5 页
字号:
the capability is present, @code{tgetnum} returns the numeric value(which is nonnegative).  If the capability is not mentioned in theterminal description, @code{tgetnum} returns @minus{}1.@item tgetflagUse @code{tgetflag} to get a boolean value.  If the capability@var{name} is present in the terminal description, @code{tgetflag}returns 1; otherwise, it returns 0.@item tgetstrUse @code{tgetstr} to get a string value.  It returns a pointer to astring which is the capability value, or a null pointer if thecapability is not present in the terminal description.There are two ways @code{tgetstr} can find space to store the string value:@itemize @bullet@itemYou can ask @code{tgetstr} to allocate the space.  Pass a nullpointer for the argument @var{area}, and @code{tgetstr} will use@code{malloc} to allocate storage big enough for the value.Termcap will never free this storage or refer to it again; youshould free it when you are finished with it.This method is more robust, since there is no need to guess howmuch space is needed.  But it is supported only by the GNUtermcap library.@itemYou can provide the space.  Provide for the argument @var{area} theaddress of a pointer variable of type @code{char *}.  Before calling@code{tgetstr}, initialize the variable to point at available space.Then @code{tgetstr} will store the string value in that space and willincrement the pointer variable to point after the space that has beenused.  You can use the same pointer variable for many calls to@code{tgetstr}.There is no way to determine how much space is needed for a singlestring, and no way for you to prevent or handle overflow of the areayou have provided.  However, you can be sure that the total size ofall the string values you will obtain from the terminal description isno greater than the size of the description (unless you get the samecapability twice).  You can determine that size with @code{strlen} onthe buffer you provided to @code{tgetent}.  See below for an example.Providing the space yourself is the only method supported by the Unixversion of termcap.@end itemize@end tableNote that you do not have to specify a terminal type or terminaldescription for the interrogation functions.  They automatically use thedescription found by the most recent call to @code{tgetent}.Here is an example of interrogating a terminal description for variouscapabilities, with conditionals to select between the Unix and GNU methodsof providing buffer space.@examplechar *tgetstr ();char *cl_string, *cm_string;int height;int width;int auto_wrap;char PC;   /* For tputs.  */char *BC;  /* For tgoto.  */char *UP;interrogate_terminal ()@{#ifdef UNIX  /* Here we assume that an explicit term_buffer     was provided to tgetent.  */  char *buffer    = (char *) malloc (strlen (term_buffer));#define BUFFADDR &buffer#else#define BUFFADDR 0#endif  char *temp;  /* Extract information we will use.  */  cl_string = tgetstr ("cl", BUFFADDR);  cm_string = tgetstr ("cm", BUFFADDR);  auto_wrap = tgetflag ("am");  height = tgetnum ("li");  width = tgetnum ("co");  /* Extract information that termcap functions use.  */  temp = tgetstr ("pc", BUFFADDR);  PC = temp ? *temp : 0;  BC = tgetstr ("le", BUFFADDR);  UP = tgetstr ("up", BUFFADDR);@}@end example@noindent@xref{Padding}, for information on the variable @code{PC}.  @xref{UsingParameters}, for information on @code{UP} and @code{BC}.@node Initialize, Padding, Interrogate, Library@section Initialization for Use of Termcap@cindex terminal flags (kernel)Before starting to output commands to a terminal using termcap,an application program should do two things:@itemize @bullet@itemInitialize various global variables which termcap library outputfunctions refer to.  These include @code{PC} and @code{ospeed} forpadding (@pxref{Output Padding}) and @code{UP} and @code{BC} forcursor motion (@pxref{tgoto}).@refill@itemTell the kernel to turn off alteration and padding of horizontal-tabcharacters sent to the terminal.@end itemizeTo turn off output processing in Berkeley Unix you would use @code{ioctl}with code @code{TIOCLSET} to set the bit named @code{LLITOUT}, and clearthe bits @code{ANYDELAY} using @code{TIOCSETN}.  In POSIX or System V, youmust clear the bit named @code{OPOST}.  Refer to the system documentationfor details.@refillIf you do not set the terminal flags properly, some older terminals willnot work.  This is because their commands may contain the characters thatnormally signify newline, carriage return and horizontal tab---characterswhich the kernel thinks it ought to modify before output.When you change the kernel's terminal flags, you must arrange to restorethem to their normal state when your program exits.  This implies that theprogram must catch fatal signals such as @code{SIGQUIT} and @code{SIGINT}and restore the old terminal flags before actually terminating.Modern terminals' commands do not use these special characters, so if youdo not care about problems with old terminals, you can leave the kernel'sterminal flags unaltered.@node Padding, Parameters, Initialize, Library@section Padding@cindex padding@dfn{Padding} means outputting null characters following a terminal displaycommand that takes a long time to execute.  The terminal description sayswhich commands require padding and how much; the function @code{tputs},described below, outputs a terminal command while extracting from it thepadding information, and then outputs the padding that is necessary.@menu* Why Pad::          Explanation of padding.* Describe Padding:: The data base says how much padding a terminal needs.* Output Padding::   Using @code{tputs} to output the needed padding.@end menu@node Why Pad, Describe Padding, Padding, Padding@subsection Why Pad, and HowMost types of terminal have commands that take longer to execute than theydo to send over a high-speed line.  For example, clearing the screen maytake 20msec once the entire command is received.  During that time, on a9600 bps line, the terminal could receive about 20 additional outputcharacters while still busy clearing the screen.  Every terminal has acertain amount of buffering capacity to remember output characters thatcannot be processed yet, but too many slow commands in a row can cause thebuffer to fill up.  Then any additional output that cannot be processedimmediately will be lost.To avoid this problem, we normally follow each display command with enoughuseless charaters (usually null characters) to fill up the time that thedisplay command needs to execute.  This does the job if the terminal throwsaway null characters without using up space in the buffer (which mostterminals do).  If enough padding is used, no output can ever be lost.  Theright amount of padding avoids loss of output without slowing downoperation, since the time used to transmit padding is time that nothingelse could be done.The number of padding characters needed for an operation depends on theline speed.  In fact, it is proportional to the line speed.  A 9600 baudline transmits about one character per msec, so the clear screen command inthe example above would need about 20 characters of padding.  At 1200 baud,however, only about 3 characters of padding are needed to fill up 20msec.@node Describe Padding, Output Padding, Why Pad, Padding@subsection Specifying Padding in a Terminal DescriptionIn the terminal description, the amount of padding required by each displaycommand is recorded as a sequence of digits at the front of the command.These digits specify the padding time in msec.  They can be followedoptionally by a decimal point and one more digit, which is a number oftenths of msec.Sometimes the padding needed by a command depends on the cursor position.For example, the time taken by an ``insert line'' command is usuallyproportional to the number of lines that need to be moved down or cleared.An asterisk (@samp{*}) following the padding time says that the timeshould be multiplied by the number of screen lines affected by the command.@example:al=1.3*\E[L:@end example@noindentis used to describe the ``insert line'' command for a certain terminal.The padding required is 1.3 msec per line affected.  The command itself is@samp{@key{ESC} [ L}.The padding time specified in this way tells @code{tputs} how many padcharacters to output.  @xref{Output Padding}.Two special capability values affect padding for all commands.  These arethe @samp{pc} and @samp{pb}.  The variable @samp{pc} specifies thecharacter to pad with, and @samp{pb} the speed below which no padding isneeded.  The defaults for these variables, a null character and 0,are correct for most terminals.  @xref{Pad Specs}.@node Output Padding,, Describe Padding, Padding@subsection Performing Padding with @code{tputs}@cindex line speed@findex tputsUse the termcap function @code{tputs} to output a string containing anoptional padding spec of the form described above (@pxref{DescribePadding}).  The function @code{tputs} strips off and decodes the paddingspec, outputs the rest of the string, and then outputs the appropriatepadding.  Here is its declaration in ANSI C:@examplechar PC;short ospeed;int tputs (char *@var{string}, int @var{nlines}, int (*@var{outfun}) ());@end exampleHere @var{string} is the string (including padding spec) to be output;@var{nlines} is the number of lines affected by the operation, which isused to multiply the amount of padding if the padding spec ends with a@samp{*}.  Finally, @var{outfun} is a function (such as @code{fputchar})that is called to output each character.  When actually called,@var{outfun} should expect one argument, a character.@vindex ospeed@vindex PCThe operation of @code{tputs} is controlled by two global variables,@code{ospeed} and @code{PC}.  The value of @code{ospeed} is supposed to bethe terminal output speed, encoded as in the @code{ioctl} system call whichgets the speed information.  This is needed to compute the number ofpadding characters.  The value of @code{PC} is the character used forpadding.You are responsible for storing suitable values into these variables beforeusing @code{tputs}.  The value stored into the @code{PC} variable should betaken from the @samp{pc} capability in the terminal description (@pxref{PadSpecs}).  Store zero in @code{PC} if there is no @samp{pc}capability.@refillThe argument @var{nlines} requires some thought.  Normally, it should bethe number of lines whose contents will be cleared or moved by the command.For cursor motion commands, or commands that do editing within one line,use the value 1.  For most commands that affect multiple lines, such as@samp{al} (insert a line) and @samp{cd} (clear from the cursor to the endof the screen), @var{nlines} should be the screen height minus the currentvertical position (origin 0).  For multiple insert and scroll commands suchas @samp{AL} (insert multiple lines), that same value for @var{nlines} iscorrect; the number of lines being inserted is @i{not} correct.@refillIf a ``scroll window'' feature is used to reduce the number of linesaffected by a command, the value of @var{nlines} should take this intoaccount.  This is because the delay time required depends on how much workthe terminal has to do, and the scroll window feature reduces the work.@xref{Scrolling}.Commands such as @samp{ic} and @samp{dc} (insert or delete characters) areproblematical because the padding needed by these commands is proportionalto the number of characters affected, which is the number of columns fromthe cursor to the end of the line.  It would be nice to have a way tospecify such a dependence, and there is no need for dependence on verticalposition in these commands, so it is an obvious idea to say that for thesecommands @var{nlines} should really be the number of columns affected.However, the definition of termcap clearly says that @var{nlines} is alwaysthe number of lines affected, even in this case, where it is always 1.  Itis not easy to change this rule now, because too many programs and terminaldescriptions have been written to follow it.Because @var{nlines} is always 1 for the @samp{ic} and @samp{dc} strings,there is no reason for them to use @samp{*}, but some of them do.  Theseshould be corrected by deleting the @samp{*}.  If, some day, such entrieshave disappeared, it may be possible to change to a more useful conventionfor the @var{nlines} argument for these operations without breaking anyprograms.@node Parameters,, Padding, Library@section Filling In Parameters@cindex parametersSome terminal control strings require numeric @dfn{parameters}.  Forexample, when you move the cursor, you need to say what horizontal andvertical positions to move it to.  The value of the terminal's @samp{cm}capability, which says how to move the cursor, cannot simply be a string ofcharacters; it must say how to express the cursor position numbers andwhere to put them within the command.The specifications of termcap include conventions as to which string-valuedcapabilities require parameters, how many parameters, and what theparameters mean; for example, it defines the @samp{cm} string to taketwo parameters, the vertical and horizontal positions, with 0,0 being theupper left corner.  These conventions are described where the individualcommands are documented.Termcap also defines a language used within the capability definition for

⌨️ 快捷键说明

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