[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.9 and 1.10

version 1.9, 2009/08/23 16:45:00 version 1.10, 2009/08/25 12:18:51
Line 35 
Line 35 
   
 int      cmd_command_prompt_callback(void *, const char *);  int      cmd_command_prompt_callback(void *, const char *);
 void     cmd_command_prompt_cfree(void *);  void     cmd_command_prompt_cfree(void *);
 char    *cmd_command_prompt_replace(char *, const char *, int);  
   
 const struct cmd_entry cmd_command_prompt_entry = {  const struct cmd_entry cmd_command_prompt_entry = {
         "command-prompt", NULL,          "command-prompt", NULL,
Line 216 
Line 215 
         if (s == NULL)          if (s == NULL)
                 return (0);                  return (0);
   
         newtempl = cmd_command_prompt_replace(cdata->template, s, cdata->idx);          newtempl = cmd_template_replace(cdata->template, s, cdata->idx);
         xfree(cdata->template);          xfree(cdata->template);
         cdata->template = newtempl;          cdata->template = newtempl;
   
Line 264 
Line 263 
         if (cdata->template != NULL)          if (cdata->template != NULL)
                 xfree(cdata->template);                  xfree(cdata->template);
         xfree(cdata);          xfree(cdata);
 }  
   
 char *  
 cmd_command_prompt_replace(char *template, const char *s, int idx)  
 {  
         char     ch;  
         char    *buf, *ptr;  
         int      replaced;  
         size_t   len;  
   
         if (strstr(template, "%") == NULL)  
                 return (xstrdup(template));  
   
         buf = xmalloc(1);  
         *buf = '\0';  
         len = 0;  
         replaced = 0;  
   
         ptr = template;  
         while (*ptr != '\0') {  
                 switch (ch = *ptr++) {  
                 case '%':  
                         if (*ptr < '1' || *ptr > '9' || *ptr - '0' != idx) {  
                                 if (*ptr != '%' || replaced)  
                                         break;  
                                 replaced = 1;  
                         }  
                         ptr++;  
   
                         len += strlen(s);  
                         buf = xrealloc(buf, 1, len + 1);  
                         strlcat(buf, s, len + 1);  
                         continue;  
                 }  
                 buf = xrealloc(buf, 1, len + 2);  
                 buf[len++] = ch;  
                 buf[len] = '\0';  
         }  
   
         return (buf);  
 }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10