From: Nishith Shah Date: Tue, 6 Sep 2016 12:04:37 +0000 (+0000) Subject: tools: Pass opaque data in vshCompleter and introduce autoCompleteOpaque X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=cbbaa17faf2e8dd92455d69daaa05178be4dce05;p=libvirt.git tools: Pass opaque data in vshCompleter and introduce autoCompleteOpaque This patch changes the signature of vshCompleters, allowing to pass along some data that we might want to along with the completers; for example, we might want to pass the autocomplete vshControl along with the completer, in case the completer requires a connection to libvirtd. Signed-off-by: Nishith Shah Signed-off-by: Michal Privoznik --- diff --git a/tools/vsh.c b/tools/vsh.c index 31579228b0..be6a073f56 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -64,6 +64,11 @@ # define SA_SIGINFO 0 #endif +#ifdef WITH_READLINE +/* For autocompletion */ +void *autoCompleteOpaque; +#endif + /* NOTE: It would be much nicer to have these two as part of vshControl * structure, unfortunately readline doesn't support passing opaque data * and only relies on static data accessible from the user-side callback @@ -2808,7 +2813,8 @@ vshReadlineParse(const char *text, int state) res = vshReadlineOptionsGenerator(sanitized_text, state, cmd); } else if (non_bool_opt_exists && data_complete && opt->completer) { if (!completed_list) - completed_list = opt->completer(opt->completer_flags); + completed_list = opt->completer(autoCompleteOpaque, + opt->completer_flags); if (completed_list) { while ((completed_name = completed_list[completed_list_index])) { completed_list_index++; @@ -2858,6 +2864,9 @@ vshReadlineInit(vshControl *ctl) char *histsize_env = NULL; const char *histsize_str = NULL; + /* Opaque data for autocomplete callbacks. */ + autoCompleteOpaque = ctl; + /* Allow conditional parsing of the ~/.inputrc file. * Work around ancient readline 4.1 (hello Mac OS X), * which declared it as 'char *' instead of 'const char *'. diff --git a/tools/vsh.h b/tools/vsh.h index 7f430552e2..e53910f9af 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -123,7 +123,7 @@ typedef struct _vshCmdOpt vshCmdOpt; typedef struct _vshCmdOptDef vshCmdOptDef; typedef struct _vshControl vshControl; -typedef char **(*vshCompleter)(unsigned int flags); +typedef char **(*vshCompleter)(void *opaque, unsigned int flags); /* * vshCmdInfo -- name/value pair for information about command