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

Diff for /src/usr.bin/tmux/cmd.c between version 1.48 and 1.49

version 1.48, 2010/12/30 23:16:18 version 1.49, 2011/01/04 00:42:47
Line 167 
Line 167 
 }  }
   
 char **  char **
 cmd_copy_argv(int argc, char **argv)  cmd_copy_argv(int argc, char *const *argv)
 {  {
         char    **new_argv;          char    **new_argv;
         int       i;          int       i;
Line 201 
Line 201 
 {  {
         const struct cmd_entry **entryp, *entry;          const struct cmd_entry **entryp, *entry;
         struct cmd              *cmd;          struct cmd              *cmd;
           struct args             *args;
         char                     s[BUFSIZ];          char                     s[BUFSIZ];
         int                      opt, ambiguous = 0;          int                      ambiguous = 0;
   
         *cause = NULL;          *cause = NULL;
         if (argc == 0) {          if (argc == 0) {
Line 236 
Line 237 
                 return (NULL);                  return (NULL);
         }          }
   
         optreset = 1;          args = args_parse(entry->args_template, argc, argv);
         optind = 1;          if (args == NULL)
         if (entry->parse == NULL) {                  goto usage;
                 while ((opt = getopt(argc, argv, "")) != -1) {          if (entry->args_lower != -1 && args->argc < entry->args_lower)
                         switch (opt) {                  goto usage;
                         default:          if (entry->args_upper != -1 && args->argc > entry->args_upper)
                                 goto usage;                  goto usage;
                         }          if (entry->check != NULL && entry->check(args) != 0)
                 }                  goto usage;
                 argc -= optind;  
                 argv += optind;  
                 if (argc != 0)  
                         goto usage;  
         }  
   
         cmd = xmalloc(sizeof *cmd);          cmd = xmalloc(sizeof *cmd);
         cmd->entry = entry;          cmd->entry = entry;
         cmd->data = NULL;          cmd->args = args;
         if (entry->parse != NULL) {  
                 if (entry->parse(cmd, argc, argv, cause) != 0) {  
                         xfree(cmd);  
                         return (NULL);  
                 }  
         }  
         return (cmd);          return (cmd);
   
 ambiguous:  ambiguous:
Line 277 
Line 267 
         return (NULL);          return (NULL);
   
 usage:  usage:
           if (args != NULL)
                   args_free(args);
         xasprintf(cause, "usage: %s %s", entry->name, entry->usage);          xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
         return (NULL);          return (NULL);
 }  }
Line 290 
Line 282 
 void  void
 cmd_free(struct cmd *cmd)  cmd_free(struct cmd *cmd)
 {  {
         if (cmd->data != NULL && cmd->entry->free != NULL)          if (cmd->args != NULL)
                 cmd->entry->free(cmd);                  args_free(cmd->args);
         xfree(cmd);          xfree(cmd);
 }  }
   
 size_t  size_t
 cmd_print(struct cmd *cmd, char *buf, size_t len)  cmd_print(struct cmd *cmd, char *buf, size_t len)
 {  {
         if (cmd->entry->print == NULL)          size_t  off, used;
                 return (xsnprintf(buf, len, "%s", cmd->entry->name));  
         return (cmd->entry->print(cmd, buf, len));          off = xsnprintf(buf, len, "%s ", cmd->entry->name);
           if (off < len) {
                   used = args_print(cmd->args, buf + off, len - off);
                   if (used == 0)
                           buf[off - 1] = '\0';
                   else {
                           off += used;
                           buf[off] = '\0';
                   }
           }
           return (off);
 }  }
   
 /*  /*

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.49