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

📄 rltech.texinfo

📁 UNIX下SH的实现源码
💻 TEXINFO
📖 第 1 页 / 共 5 页
字号:
@code{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.  When the generator function returns@code{(char *)NULL} this signals @code{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{completion_matches ()}).  The default is to do filename completion.@end deftypefun@deftypevar {Function *} rl_completion_entry_functionThis is a pointer to the generator function for @code{completion_matches()}.  If the value of @code{rl_completion_entry_function} is@code{(Function *)NULL} then the default filename generator function,@code{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{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 **} completion_matches (char *text, CPFunction *entry_func)Returns an array of @code{(char *)} which is a list of completions for@var{text}.  If there are no completions, returns @code{(char **)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 *} filename_completion_function (char *text, int state)A generator function for filename completion in the general case.  Notethat completion in Bash is a little different because of allthe pathnames that must be followed when looking up completions for acommand.  The Bash source is a useful reference for writing customcompletion functions.@end deftypefun@deftypefun {char *} username_completion_function (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 {Function *} rl_completion_entry_functionA pointer to the generator function for @code{completion_matches ()}.@code{NULL} means to use @code{filename_completion_function ()}, the defaultfilename completer.@end deftypevar@deftypevar {CPPFunction *} 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} sayingwhat the boundaries of @var{text} are.  If this function exists andreturns @code{NULL}, or if this variable is set 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.@end deftypevar@deftypevar {CPFunction *} rl_filename_quoting_functionA pointer to a function that will quote a filename in an application-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 {CPFunction *} 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 {Function *} 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 {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, i.e.,@code{" \t\n\"\\'`@@$><=;|&@{("}.@end deftypevar@deftypevar {char *} rl_basic_quote_charactersList of quote characters which can cause a word break.@end deftypevar@deftypevar {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 {char *} rl_completer_quote_charactersList 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 {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 {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 disallow duplicates in the matches.  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 embedded word breakcharacters.@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_inhibit_completionIf this variable is non-zero, completion is inhibit<ed.  The completioncharacter will be inserted as any other bound to @code{self-insert}.@end deftypevar@deftypevar {Function *} 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 {Function *} 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.  It could be usedto expand symbolic links or shell variables in pathnames.@end deftypevar@deftypevar {VFunction *} 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 <readline/readline.h>#include <readline/history.h>extern char *getwd ();extern char *xmalloc ();/* The names of functions that actually do the manipulation. */int com_list (), com_view (), com_rename (), com_stat (), com_pwd ();int com_delete (), com_help (), com_cd (), com_quit ();/* A structure which contains information on the commands this program   can understand. */typedef struct @{  char *name;			/* User printable name of the function. */  Function *func;		/* Function to call to do the job. */  char *doc;			/* Documentation for this function.  */@} COMMAND;COMMAND commands[] = @{  @{ "cd", com_cd, "Change to directory DIR" @},  @{ "delete", com_delete, "Delete FILE" @},  @{ "help", com_help, "Display this text" @},  @{ "?", com_help, "Synonym for `help'" @},  @{ "list", com_list, "List files in DIR" @},  @{ "ls", com_list, "Synonym for `list'" @},  @{ "pwd", com_pwd, "Print the current working directory" @},  @{ "quit", com_quit, "Quit using Fileman" @},  @{ "rename", com_rename, "Rename FILE to NEWNAME" @},  @{ "stat", com_stat, "Print out statistics on FILE" @},  @{ "view", com_view, "View the contents of FILE" @},  @{ (char *)NULL, (Function *)NULL, (char *)NULL @}@};/* Forward declarations. */char *stripwhite ();COMMAND *find_command ();/* The name of this program, as taken from argv[0]. */char *progname;/* When non-zero, this global means the user is done using this program. */int done;char *dupstr (s)     int s;@{  char *r;  r = xmalloc (strlen (s) + 1);  strcpy (r, s);  return (r);@}main (argc, argv)     int argc;     char **argv;@{  char *line, *s;  progname = argv[0];  initialize_readline ();	/* Bind our completer. */  /* Loop reading and executing lines until the user quits. */  for ( ; done == 0; )    @{      line = readline ("FileMan: ");      if (!line)

⌨️ 快捷键说明

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