[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.37 and 1.38

version 1.37, 2021/08/20 18:59:53 version 1.38, 2021/08/20 19:50:16
Line 38 
Line 38 
         RB_ENTRY(args_entry)     entry;          RB_ENTRY(args_entry)     entry;
 };  };
   
   struct args {
           struct args_tree          tree;
           int                       argc;
           char                    **argv;
   };
   
 static struct args_entry        *args_find(struct args *, u_char);  static struct args_entry        *args_find(struct args *, u_char);
   
 static int      args_cmp(struct args_entry *, struct args_entry *);  static int      args_cmp(struct args_entry *, struct args_entry *);
Line 73 
Line 79 
   
 /* Parse an argv and argc into a new argument set. */  /* Parse an argv and argc into a new argument set. */
 struct args *  struct args *
 args_parse(const char *template, int argc, char **argv)  args_parse(const char *template, int argc, char **argv, int lower, int upper)
 {  {
         struct args     *args;          struct args     *args;
         int              opt;          int              opt;
Line 99 
Line 105 
         args->argc = argc;          args->argc = argc;
         args->argv = cmd_copy_argv(argc, argv);          args->argv = cmd_copy_argv(argc, argv);
   
           if ((lower != -1 && argc < lower) || (upper != -1 && argc > upper)) {
                   args_free(args);
                   return (NULL);
           }
         return (args);          return (args);
 }  }
   
Line 126 
Line 136 
         free(args);          free(args);
 }  }
   
   /* Convert arguments to vector. */
   void
   args_vector(struct args *args, int *argc, char ***argv)
   {
           *argc = args->argc;
           *argv = cmd_copy_argv(args->argc, args->argv);
   }
   
 /* 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 145 
Line 163 
         free(s);          free(s);
 }  }
   
 /* Add value to string. */  
 static void  
 args_print_add_value(char **buf, size_t *len, struct args_entry *entry,  
     struct args_value *value)  
 {  
         char    *escaped;  
   
         if (**buf != '\0')  
                 args_print_add(buf, len, " -%c ", entry->flag);  
         else  
                 args_print_add(buf, len, "-%c ", entry->flag);  
   
         escaped = args_escape(value->value);  
         args_print_add(buf, len, "%s", escaped);  
         free(escaped);  
 }  
   
 /* Add argument to string. */  /* Add argument to string. */
 static void  static void
 args_print_add_argument(char **buf, size_t *len, const char *argument)  args_print_add_argument(char **buf, size_t *len, const char *argument)
Line 203 
Line 204 
   
         /* Then the flags with arguments. */          /* Then the flags with arguments. */
         RB_FOREACH(entry, args_tree, &args->tree) {          RB_FOREACH(entry, args_tree, &args->tree) {
                 TAILQ_FOREACH(value, &entry->values, entry)                  TAILQ_FOREACH(value, &entry->values, entry) {
                         args_print_add_value(&buf, &len, entry, value);                          if (*buf != '\0')
                                   args_print_add(&buf, &len, " -%c", entry->flag);
                           else
                                   args_print_add(&buf, &len, "-%c", entry->flag);
                           args_print_add_argument(&buf, &len, value->value);
                   }
         }          }
   
         /* And finally the argument vector. */          /* And finally the argument vector. */
Line 328 
Line 334 
         if (*entry == NULL)          if (*entry == NULL)
                 return (0);                  return (0);
         return ((*entry)->flag);          return ((*entry)->flag);
   }
   
   /* Get argument count. */
   u_int
   args_count(struct args *args)
   {
           return (args->argc);
   }
   
   /* Return argument as string. */
   const char *
   args_string(struct args *args, u_int idx)
   {
           if (idx >= (u_int)args->argc)
                   return (NULL);
           return (args->argv[idx]);
 }  }
   
 /* Get first value in argument. */  /* Get first value in argument. */

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