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

Diff for /src/usr.bin/tmux/arguments.c between version 1.47 and 1.48

version 1.47, 2021/08/25 08:51:55 version 1.48, 2021/08/27 17:25:55
Line 166 
Line 166 
                         }                          }
                         argument = *++found;                          argument = *++found;
                         if (argument != ':') {                          if (argument != ':') {
                                 log_debug("%s: add -%c", __func__, flag);                                  log_debug("%s: -%c", __func__, flag);
                                 args_set(args, flag, NULL);                                  args_set(args, flag, NULL);
                                 continue;                                  continue;
                         }                          }
Line 192 
Line 192 
                                 args_copy_value(new, &values[i++]);                                  args_copy_value(new, &values[i++]);
                         }                          }
                         s = args_value_as_string(new);                          s = args_value_as_string(new);
                         log_debug("%s: add -%c = %s", __func__, flag, s);                          log_debug("%s: -%c = %s", __func__, flag, s);
                         args_set(args, flag, new);                          args_set(args, flag, new);
                         break;                          break;
                 }                  }
Line 203 
Line 203 
                         value = &values[i];                          value = &values[i];
   
                         s = args_value_as_string(value);                          s = args_value_as_string(value);
                         log_debug("%s: %u = %s", __func__, i, s);                          log_debug("%s: %u = %s (type %d)", __func__, i, s,
                               value->type);
   
                         if (parse->cb != NULL) {                          if (parse->cb != NULL) {
                                 type = parse->cb(args, args->count, cause);                                  type = parse->cb(args, args->count, cause);
Line 265 
Line 266 
         return (args);          return (args);
 }  }
   
   /* Copy and expand a value. */
   static void
   args_copy_copy_value(struct args_value *to, struct args_value *from, int argc,
       char **argv)
   {
           char    *s, *expanded;
           int      i;
   
           to->type = from->type;
           switch (from->type) {
           case ARGS_NONE:
                   break;
           case ARGS_STRING:
                   expanded = xstrdup(from->string);
                   for (i = 0; i < argc; i++) {
                           s = cmd_template_replace(expanded, argv[i], i + 1);
                           free(expanded);
                           expanded = s;
                   }
                   to->string = expanded;
                   break;
           case ARGS_COMMANDS:
                   to->cmdlist = cmd_list_copy(from->cmdlist, argc, argv);
                   break;
           }
   }
   
   /* Copy an arguments set. */
   struct args *
   args_copy(struct args *args, int argc, char **argv)
   {
           struct args             *new_args;
           struct args_entry       *entry;
           struct args_value       *value, *new_value;
           u_int                    i;
   
           new_args = args_create();
           RB_FOREACH(entry, args_tree, &args->tree) {
                   if (entry->count == 1) {
                           args_set(new_args, entry->flag, NULL);
                           continue;
                   }
                   TAILQ_FOREACH(value, &entry->values, entry) {
                           new_value = xcalloc(1, sizeof *new_value);
                           args_copy_copy_value(new_value, value, argc, argv);
                           args_set(new_args, entry->flag, new_value);
                   }
           }
           new_args->count = args->count;
           new_args->values = xcalloc(args->count, sizeof *new_args->values);
           for (i = 0; i < args->count; i++) {
                   new_value = &new_args->values[i];
                   args_copy_copy_value(new_value, &args->values[i], argc, argv);
           }
           return (new_args);
   }
   
 /* Free a value. */  /* Free a value. */
 void  void
 args_free_value(struct args_value *value)  args_free_value(struct args_value *value)
Line 282 
Line 340 
         free(value->cached);          free(value->cached);
 }  }
   
   /* Free values. */
   void
   args_free_values(struct args_value *values, u_int count)
   {
           u_int   i;
   
           for (i = 0; i < count; i++)
                   args_free_value(&values[i]);
   }
   
 /* Free an arguments set. */  /* Free an arguments set. */
 void  void
 args_free(struct args *args)  args_free(struct args *args)
Line 290 
Line 358 
         struct args_entry       *entry1;          struct args_entry       *entry1;
         struct args_value       *value;          struct args_value       *value;
         struct args_value       *value1;          struct args_value       *value1;
         u_int                    i;  
   
         for (i = 0; i < args->count; i++)          args_free_values(args->values, args->count);
                 args_free_value(&args->values[i]);  
         free(args->values);          free(args->values);
   
         RB_FOREACH_SAFE(entry, args_tree, &args->tree, entry1) {          RB_FOREACH_SAFE(entry, args_tree, &args->tree, entry1) {
Line 311 
Line 377 
   
 /* Convert arguments to vector. */  /* Convert arguments to vector. */
 void  void
 args_vector(struct args *args, int *argc, char ***argv)  args_to_vector(struct args *args, int *argc, char ***argv)
 {  {
         char    *s;          char    *s;
         u_int    i;          u_int    i;
Line 335 
Line 401 
         }          }
 }  }
   
   /* Convert arguments from vector. */
   struct args_value *
   args_from_vector(int argc, char **argv)
   {
           struct args_value       *values;
           int                      i;
   
           values = xcalloc(argc, sizeof *values);
           for (i = 0; i < argc; i++) {
                   values[i].type = ARGS_STRING;
                   values[i].string = xstrdup(argv[i]);
           }
           return (values);
   }
   
 /* Add to string. */  /* Add to string. */
 static void printflike(3, 4)  static void printflike(3, 4)
 args_print_add(char **buf, size_t *len, const char *fmt, ...)  args_print_add(char **buf, size_t *len, const char *fmt, ...)
Line 424 
Line 505 
 char *  char *
 args_escape(const char *s)  args_escape(const char *s)
 {  {
         static const char        dquoted[] = " #';${}";          static const char        dquoted[] = " #';${}%";
         static const char        squoted[] = " \"";          static const char        squoted[] = " \"";
         char                    *escaped, *result;          char                    *escaped, *result;
         int                      flags, quotes = 0;          int                      flags, quotes = 0;
Line 538 
Line 619 
         return (args->count);          return (args->count);
 }  }
   
   /* Get argument values. */
   struct args_value *
   args_values(struct args *args)
   {
           return (args->values);
   }
   
 /* Get argument value. */  /* Get argument value. */
 struct args_value *  struct args_value *
 args_value(struct args *args, u_int idx)  args_value(struct args *args, u_int idx)
Line 570 
Line 658 
                 cmdq_error(item, "%s", error);                  cmdq_error(item, "%s", error);
                 free(error);                  free(error);
         }          }
        else          else
                cmdlist->references++;                  cmdlist->references++;
         args_make_commands_free(state);          args_make_commands_free(state);
         return (cmdlist);          return (cmdlist);
 }  }
Line 631 
Line 719 
         char                    *cmd, *new_cmd;          char                    *cmd, *new_cmd;
         int                      i;          int                      i;
   
         if (state->cmdlist != NULL)          if (state->cmdlist != NULL) {
                 return (state->cmdlist);                  if (argc == 0)
                           return (state->cmdlist);
                   return (cmd_list_copy(state->cmdlist, argc, argv));
           }
   
         cmd = xstrdup(state->cmd);          cmd = xstrdup(state->cmd);
         for (i = 0; i < argc; i++) {          for (i = 0; i < argc; i++) {

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