[BACK]Return to cmd-command-prompt.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/cmd-command-prompt.c between version 1.38 and 1.39

version 1.38, 2016/10/16 19:04:05 version 1.39, 2017/01/06 11:57:03
Line 32 
Line 32 
 static enum cmd_retval  cmd_command_prompt_exec(struct cmd *,  static enum cmd_retval  cmd_command_prompt_exec(struct cmd *,
                             struct cmdq_item *);                              struct cmdq_item *);
   
 static int      cmd_command_prompt_callback(void *, const char *);  static int      cmd_command_prompt_callback(void *, const char *, int);
 static void     cmd_command_prompt_free(void *);  static void     cmd_command_prompt_free(void *);
   
 const struct cmd_entry cmd_command_prompt_entry = {  const struct cmd_entry cmd_command_prompt_entry = {
         .name = "command-prompt",          .name = "command-prompt",
         .alias = NULL,          .alias = NULL,
   
         .args = { "1I:Np:t:", 0, 1 },          .args = { "1iI:Np:t:", 0, 1 },
         .usage = "[-1N] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "          .usage = "[-1Ni] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
                  "[template]",                   "[template]",
   
         .tflag = CMD_CLIENT,          .tflag = CMD_CLIENT,
Line 51 
Line 51 
   
 struct cmd_command_prompt_cdata {  struct cmd_command_prompt_cdata {
         struct client   *c;          struct client   *c;
           int              flags;
   
         char            *inputs;          char            *inputs;
         char            *next_input;          char            *next_input;
         char            *next_prompt;  
         char            *prompts;          char            *prompts;
           char            *next_prompt;
   
         char            *template;          char            *template;
         int              idx;          int              idx;
 };  };
Line 73 
Line 77 
         if (c->prompt_string != NULL)          if (c->prompt_string != NULL)
                 return (CMD_RETURN_NORMAL);                  return (CMD_RETURN_NORMAL);
   
         cdata = xmalloc(sizeof *cdata);          cdata = xcalloc(1, sizeof *cdata);
         cdata->c = c;          cdata->c = c;
         cdata->idx = 1;  
         cdata->inputs = NULL;          cdata->inputs = NULL;
         cdata->next_input = NULL;          cdata->next_input = NULL;
         cdata->next_prompt = NULL;  
         cdata->prompts = NULL;          cdata->prompts = NULL;
           cdata->next_prompt = NULL;
   
         cdata->template = NULL;          cdata->template = NULL;
           cdata->idx = 1;
   
         if (args->argc != 0)          if (args->argc != 0)
                 cdata->template = xstrdup(args->argv[0]);                  cdata->template = xstrdup(args->argv[0]);
Line 112 
Line 119 
   
         flags = 0;          flags = 0;
         if (args_has(args, '1'))          if (args_has(args, '1'))
                 flags |= PROMPT_SINGLE;                  cdata->flags |= PROMPT_SINGLE;
         else if (args_has(args, 'N'))          else if (args_has(args, 'N'))
                 flags |= PROMPT_NUMERIC;                  cdata->flags |= PROMPT_NUMERIC;
           else if (args_has(args, 'i'))
                   cdata->flags |= PROMPT_INCREMENTAL;
         status_prompt_set(c, prompt, input, cmd_command_prompt_callback,          status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
             cmd_command_prompt_free, cdata, flags);              cmd_command_prompt_free, cdata, cdata->flags);
         free(prompt);          free(prompt);
   
         return (CMD_RETURN_NORMAL);          return (CMD_RETURN_NORMAL);
Line 134 
Line 143 
 }  }
   
 static int  static int
 cmd_command_prompt_callback(void *data, const char *s)  cmd_command_prompt_callback(void *data, const char *s, int done)
 {  {
         struct cmd_command_prompt_cdata *cdata = data;          struct cmd_command_prompt_cdata *cdata = data;
         struct client                   *c = cdata->c;          struct client                   *c = cdata->c;
Line 145 
Line 154 
   
         if (s == NULL)          if (s == NULL)
                 return (0);                  return (0);
           if (done && (cdata->flags & PROMPT_INCREMENTAL))
                   return (0);
   
         new_template = cmd_template_replace(cdata->template, s, cdata->idx);          new_template = cmd_template_replace(cdata->template, s, cdata->idx);
         free(cdata->template);          if (done) {
         cdata->template = new_template;                  free(cdata->template);
                   cdata->template = new_template;
           }
   
         /*          /*
          * Check if there are more prompts; if so, get its respective input           * Check if there are more prompts; if so, get its respective input
          * and update the prompt data.           * and update the prompt data.
          */           */
         if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {          if (done && (ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
                 xasprintf(&prompt, "%s ", ptr);                  xasprintf(&prompt, "%s ", ptr);
                 input = strsep(&cdata->next_input, ",");                  input = strsep(&cdata->next_input, ",");
                 status_prompt_update(c, prompt, input);                  status_prompt_update(c, prompt, input);
Line 178 
Line 191 
         if (new_item != NULL)          if (new_item != NULL)
                 cmdq_append(c, new_item);                  cmdq_append(c, new_item);
   
           if (!done)
                   free(new_template);
         if (c->prompt_callbackfn != (void *)&cmd_command_prompt_callback)          if (c->prompt_callbackfn != (void *)&cmd_command_prompt_callback)
                 return (1);                  return (1);
         return (0);          return (0);

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39