mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Wrap command argument definitions in their own struct.
This commit is contained in:
parent
d589be6c65
commit
d371764d02
@ -79,7 +79,7 @@ args_create(void)
|
||||
|
||||
/* Parse an argv and argc into a new argument set. */
|
||||
struct args *
|
||||
args_parse(const char *template, int argc, char **argv, int lower, int upper)
|
||||
args_parse(const struct args_parse *parse, int argc, char **argv)
|
||||
{
|
||||
struct args *args;
|
||||
int opt;
|
||||
@ -89,10 +89,10 @@ args_parse(const char *template, int argc, char **argv, int lower, int upper)
|
||||
optarg = NULL;
|
||||
|
||||
args = args_create();
|
||||
while ((opt = getopt(argc, argv, template)) != -1) {
|
||||
while ((opt = getopt(argc, argv, parse->template)) != -1) {
|
||||
if (opt < 0)
|
||||
continue;
|
||||
if (opt == '?' || strchr(template, opt) == NULL) {
|
||||
if (opt == '?' || strchr(parse->template, opt) == NULL) {
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
@ -105,7 +105,8 @@ args_parse(const char *template, int argc, char **argv, int lower, int upper)
|
||||
args->argc = argc;
|
||||
args->argv = cmd_copy_argv(argc, argv);
|
||||
|
||||
if ((lower != -1 && argc < lower) || (upper != -1 && argc > upper)) {
|
||||
if ((parse->lower != -1 && argc < parse->lower) ||
|
||||
(parse->upper != -1 && argc > parse->upper)) {
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
|
3
cmd.c
3
cmd.c
@ -518,8 +518,7 @@ cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
return (NULL);
|
||||
cmd_log_argv(argc, argv, "%s: %s", __func__, entry->name);
|
||||
|
||||
args = args_parse(entry->args.template, argc, argv, entry->args.lower,
|
||||
entry->args.upper);
|
||||
args = args_parse(&entry->args, argc, argv);
|
||||
if (args == NULL)
|
||||
goto usage;
|
||||
|
||||
|
15
tmux.h
15
tmux.h
@ -1365,6 +1365,13 @@ struct args_value {
|
||||
struct args_entry;
|
||||
RB_HEAD(args_tree, args_entry);
|
||||
|
||||
/* Arguments parsing state. */
|
||||
struct args_parse {
|
||||
const char *template;
|
||||
int lower;
|
||||
int upper;
|
||||
};
|
||||
|
||||
/* Command find structures. */
|
||||
enum cmd_find_type {
|
||||
CMD_FIND_PANE,
|
||||
@ -1453,11 +1460,7 @@ struct cmd_entry {
|
||||
const char *name;
|
||||
const char *alias;
|
||||
|
||||
struct {
|
||||
const char *template;
|
||||
int lower;
|
||||
int upper;
|
||||
} args;
|
||||
struct args_parse args;
|
||||
const char *usage;
|
||||
|
||||
struct cmd_entry_flag source;
|
||||
@ -2183,7 +2186,7 @@ int tty_keys_next(struct tty *);
|
||||
/* arguments.c */
|
||||
void args_set(struct args *, u_char, const char *);
|
||||
struct args *args_create(void);
|
||||
struct args *args_parse(const char *, int, char **, int, int);
|
||||
struct args *args_parse(const struct args_parse *, int, char **);
|
||||
void args_vector(struct args *, int *, char ***);
|
||||
void args_free(struct args *);
|
||||
char *args_print(struct args *);
|
||||
|
Loading…
Reference in New Issue
Block a user