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

📄 rltech.texinfo

📁 linux下bash源码
💻 TEXINFO
📖 第 1 页 / 共 5 页
字号:
describes exactly what such functions must do, and provides an example.There are three major functions used to perform completion:@enumerate@itemThe user-interface function @code{rl_complete()}.  This function iscalled with the same arguments as other bindable Readline functions:@var{count} and @var{invoking_key}.It isolates the word to be completed and calls@code{rl_completion_matches()} to generate a list of possible completions.It then either lists the possible completions, inserts the possiblecompletions, or actually performs thecompletion, depending on which behavior is desired.@itemThe internal function @code{rl_completion_matches()} uses anapplication-supplied @dfn{generator} function to generate the list ofpossible matches, and then returns the array of these matches.The caller should place the address of its generator function in@code{rl_completion_entry_function}.@itemThe generator function is called repeatedly from@code{rl_completion_matches()}, returning a string each time.  Thearguments to the generator function are @var{text} and @var{state}.@var{text} is the partial word to be completed.  @var{state} is zero thefirst time the function is called, allowing the generator to performany necessary initialization, and a positive non-zero integer foreach subsequent call.  The generator function returns@code{(char *)NULL} to inform @code{rl_completion_matches()} that there areno more possibilities left.  Usually the generator function computes thelist of possible completions when @var{state} is zero, and returns themone at a time on subsequent calls.  Each string the generator functionreturns as a match must be allocated with @code{malloc()}; Readlinefrees the strings when it has finished with them.@end enumerate@deftypefun int rl_complete (int ignore, int invoking_key)Complete the word at or before point.  You have supplied the functionthat does the initial simple matching selection algorithm (see@code{rl_completion_matches()}).  The default is to do filename completion.@end deftypefun@deftypevar {rl_compentry_func_t *} rl_completion_entry_functionThis is a pointer to the generator function for@code{rl_completion_matches()}.If the value of @code{rl_completion_entry_function} is@code{NULL} then the default filename generatorfunction, @code{rl_filename_completion_function()}, is used.@end deftypevar@node Completion Functions@subsection Completion FunctionsHere is the complete list of callable completion functions present inReadline.@deftypefun int rl_complete_internal (int what_to_do)Complete the word at or before point.  @var{what_to_do} says what to dowith the completion.  A value of @samp{?} means list the possiblecompletions.  @samp{TAB} means do standard completion.  @samp{*} meansinsert all of the possible completions.  @samp{!} means to displayall of the possible completions, if there is more than one, as well asperforming partial completion.@end deftypefun@deftypefun int rl_complete (int ignore, int invoking_key)Complete the word at or before point.  You have supplied the functionthat does the initial simple matching selection algorithm (see@code{rl_completion_matches()} and @code{rl_completion_entry_function}).The default is to do filenamecompletion.  This calls @code{rl_complete_internal()} with anargument depending on @var{invoking_key}.@end deftypefun@deftypefun int rl_possible_completions (int count, int invoking_key)List the possible completions.  See description of @code{rl_complete()}.  This calls @code{rl_complete_internal()} with an argument of@samp{?}.@end deftypefun@deftypefun int rl_insert_completions (int count, int invoking_key)Insert the list of possible completions into the line, deleting thepartially-completed word.  See description of @code{rl_complete()}.This calls @code{rl_complete_internal()} with an argument of @samp{*}.@end deftypefun@deftypefun {char **} rl_completion_matches (const char *text, rl_compentry_func_t *entry_func)Returns an array of strings which is a list of completions for@var{text}.  If there are no completions, returns @code{NULL}.The first entry in the returned array is the substitution for @var{text}.The remaining entries are the possible completions.  The array isterminated with a @code{NULL} pointer.@var{entry_func} is a function of two args, and returns a@code{char *}.  The first argument is @var{text}.  The second is astate argument; it is zero on the first call, and non-zero on subsequentcalls.  @var{entry_func} returns a @code{NULL}  pointer to the callerwhen there are no more matches.@end deftypefun@deftypefun {char *} rl_filename_completion_function (const char *text, int state)A generator function for filename completion in the general case.@var{text} is a partial filename.The Bash source is a useful reference for writing customcompletion functions (the Bash completion functions call this and otherReadline functions).@end deftypefun@deftypefun {char *} rl_username_completion_function (const char *text, int state)A completion generator for usernames.  @var{text} contains a partialusername preceded by a random character (usually @samp{~}).  As with allcompletion generators, @var{state} is zero on the first call and non-zerofor subsequent calls.@end deftypefun@node Completion Variables@subsection Completion Variables@deftypevar {rl_compentry_func_t *} rl_completion_entry_functionA pointer to the generator function for @code{rl_completion_matches()}.@code{NULL} means to use @code{rl_filename_completion_function()}, the defaultfilename completer.@end deftypevar@deftypevar {rl_completion_func_t *} rl_attempted_completion_functionA pointer to an alternative function to create matches.The function is called with @var{text}, @var{start}, and @var{end}.@var{start} and @var{end} are indices in @code{rl_line_buffer} definingthe boundaries of @var{text}, which is a character string.If this function exists and returns @code{NULL}, or if this variable isset to @code{NULL}, then @code{rl_complete()} will call the value of@code{rl_completion_entry_function} to generate matches, otherwise thearray of strings returned will be used.If this function sets the @code{rl_attempted_completion_over}variable to a non-zero value, Readline will not perform its defaultcompletion even if this function returns no matches.@end deftypevar@deftypevar {rl_quote_func_t *} rl_filename_quoting_functionA pointer to a function that will quote a filename in anapplication-specific fashion.  This is called if filename completion is beingattempted and one of the characters in @code{rl_filename_quote_characters}appears in a completed filename.  The function is called with@var{text}, @var{match_type}, and @var{quote_pointer}.  The @var{text}is the filename to be quoted.  The @var{match_type} is either@code{SINGLE_MATCH}, if there is only one completion match, or@code{MULT_MATCH}.  Some functions use this to decide whether or not toinsert a closing quote character.  The @var{quote_pointer} is a pointerto any opening quote character the user typed.  Some functions chooseto reset this character.@end deftypevar@deftypevar {rl_dequote_func_t *} rl_filename_dequoting_functionA pointer to a function that will remove application-specific quotingcharacters from a filename before completion is attempted, so thosecharacters do not interfere with matching the text against names inthe filesystem.  It is called with @var{text}, the text of the wordto be dequoted, and @var{quote_char}, which is the quoting character that delimits the filename (usually @samp{'} or @samp{"}).  If@var{quote_char} is zero, the filename was not in an embedded string.@end deftypevar@deftypevar {rl_linebuf_func_t *} rl_char_is_quoted_pA pointer to a function to call that determines whether or not a specificcharacter in the line buffer is quoted, according to whatever quotingmechanism the program calling Readline uses.  The function is called withtwo arguments: @var{text}, the text of the line, and @var{index}, theindex of the character in the line.  It is used to decide whether acharacter found in @code{rl_completer_word_break_characters} should beused to break words for the completer.@end deftypevar@deftypevar int rl_completion_query_itemsUp to this many items will be displayed in response to apossible-completions call.  After that, we ask the user if she is sureshe wants to see them all.  The default value is 100.@end deftypevar@deftypevar {const char *} rl_basic_word_break_charactersThe basic list of characters that signal a break between words for thecompleter routine.  The default value of this variable is the characterswhich break words for completion in Bash:@code{" \t\n\"\\'`@@$><=;|&@{("}.@end deftypevar@deftypevar {const char *} rl_basic_quote_charactersA list of quote characters which can cause a word break.@end deftypevar@deftypevar {const char *} rl_completer_word_break_charactersThe list of characters that signal a break between words for@code{rl_complete_internal()}.  The default list is the value of@code{rl_basic_word_break_characters}.@end deftypevar@deftypevar {const char *} rl_completer_quote_charactersA list of characters which can be used to quote a substring of the line.Completion occurs on the entire substring, and within the substring@code{rl_completer_word_break_characters} are treated as any other character,unless they also appear within this list.@end deftypevar@deftypevar {const char *} rl_filename_quote_charactersA list of characters that cause a filename to be quoted by the completerwhen they appear in a completed filename.  The default is the null string.@end deftypevar@deftypevar {const char *} rl_special_prefixesThe list of characters that are word break characters, but should beleft in @var{text} when it is passed to the completion function.Programs can use this to help determine what kind of completing to do.For instance, Bash sets this variable to "$@@" so that it can completeshell variables and hostnames.@end deftypevar@deftypevar {int} rl_completion_append_characterWhen a single completion alternative matches at the end of the commandline, this character is appended to the inserted completion text.  Thedefault is a space character (@samp{ }).  Setting this to the nullcharacter (@samp{\0}) prevents anything being appended automatically.This can be changed in custom completion functions toprovide the ``most sensible word separator character'' according toan application-specific command line syntax specification.@end deftypevar@deftypevar int rl_ignore_completion_duplicatesIf non-zero, then duplicates in the matches are removed.The default is 1.@end deftypevar@deftypevar int rl_filename_completion_desiredNon-zero means that the results of the matches are to be treated asfilenames.  This is @emph{always} zero on entry, and can only be changedwithin a completion entry generator function.  If it is set to a non-zerovalue, directory names have a slash appended and Readline attempts toquote completed filenames if they contain any characters in@code{rl_filename_quote_characters} and @code{rl_filename_quoting_desired}is set to a non-zero value.@end deftypevar@deftypevar int rl_filename_quoting_desiredNon-zero means that the results of the matches are to be quoted usingdouble quotes (or an application-specific quoting mechanism) if thecompleted filename contains any characters in@code{rl_filename_quote_chars}.  This is @emph{always} non-zeroon entry, and can only be changed within a completion entry generatorfunction.  The quoting is effected via a call to the function pointed toby @code{rl_filename_quoting_function}.@end deftypevar@deftypevar int rl_attempted_completion_overIf an application-specific completion function assigned to@code{rl_attempted_completion_function} sets this variable to a non-zerovalue, Readline will not perform its default filename completion evenif the application's completion function returns no matches.It should be set only by an application's completion function.@end deftypevar@deftypevar int rl_completion_typeSet to a character describing the type of completion Readline is currentlyattempting; see the description of @code{rl_complete_internal()}(@pxref{Completion Functions}) for the list of characters.@end deftypevar@deftypevar int rl_inhibit_completionIf this variable is non-zero, completion is inhibited.  The completioncharacter will be inserted as any other bound to @code{self-insert}.@end deftypevar@deftypevar {rl_compignore_func_t *} rl_ignore_some_completions_functionThis function, if defined, is called by the completer when real filenamecompletion is done, after all the matching names have been generated.It is passed a @code{NULL} terminated array of matches.The first element (@code{matches[0]}) is themaximal substring common to all matches. This function canre-arrange the list of matches as required, but each element deletedfrom the array must be freed.@end deftypevar@deftypevar {rl_icppfunc_t *} rl_directory_completion_hookThis function, if defined, is allowed to modify the directory portionof filenames Readline completes.  It is called with the address of astring (the current directory name) as an argument, and may modify that string.If the string is replaced with a new string, the old value should be freed.Any modified directory name should have a trailing slash.The modified value will be displayed as part of the completion, replacingthe directory portion of the pathname the user typed.It returns an integer that should be non-zero if the function modifiesits directory argument.It could be used to expand symbolic links or shell variables in pathnames.@end deftypevar@deftypevar {rl_compdisp_func_t *} rl_completion_display_matches_hookIf non-zero, then this is the address of a function to call whencompleting a word would normally display the list of possible matches.This function is called in lieu of Readline displaying the list.It takes three arguments:(@code{char **}@var{matches}, @code{int} @var{num_matches}, @code{int} @var{max_length})where @var{matches} is the array of matching strings,@var{num_matches} is the number of strings in that array, and@var{max_length} is the length of the longest string in that array.Readline provides a convenience function, @code{rl_display_match_list},that takes care of doing the display to Readline's output stream.  Thatfunction may be called from this hook.@end deftypevar@node A Short Completion Example@subsection A Short Completion ExampleHere is a small application demonstrating the use of the GNU Readlinelibrary.  It is called @code{fileman}, and the source code resides in@file{examples/fileman.c}.  This sample application providescompletion of command names, line editing features, and access to thehistory list.@page@smallexample/* fileman.c -- A tiny application which demonstrates how to use the   GNU Readline library.  This application interactively allows users   to manipulate files and their modes. */#include <stdio.h>#include <sys/types.h>#include <sys/file.h>#include <sys/stat.h>#include <sys/errno.h>#include <re

⌨️ 快捷键说明

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