Re: [PATCH] tools: Pass opaque data in vshCompleter and introduce autoCompleteOpaque

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06.09.2016 14:04, Nishith Shah wrote:
> 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 <nishithshah.2211@xxxxxxxxx>
> ---
>  tools/vsh.c | 10 +++++++++-
>  tools/vsh.h |  2 +-
>  2 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/vsh.c b/tools/vsh.c
> index 3157922..3cc03ec 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,8 @@ vshReadlineInit(vshControl *ctl)
>      char *histsize_env = NULL;
>      const char *histsize_str = NULL;
>  
> +    /* Opaque data for autocomplete callbacks and connections to libvirtd */
> +    autoCompleteOpaque = ctl;

I'd put a empty space here so that it creates a visual barrier before
next comment starts.

>      /* 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 7f43055..e53910f 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
> 

ACKed and pushed.

Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]