mirror of
https://github.com/tmux/tmux.git
synced 2025-01-05 23: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. */
|
/* Parse an argv and argc into a new argument set. */
|
||||||
struct args *
|
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;
|
struct args *args;
|
||||||
int opt;
|
int opt;
|
||||||
@ -89,10 +89,10 @@ args_parse(const char *template, int argc, char **argv, int lower, int upper)
|
|||||||
optarg = NULL;
|
optarg = NULL;
|
||||||
|
|
||||||
args = args_create();
|
args = args_create();
|
||||||
while ((opt = getopt(argc, argv, template)) != -1) {
|
while ((opt = getopt(argc, argv, parse->template)) != -1) {
|
||||||
if (opt < 0)
|
if (opt < 0)
|
||||||
continue;
|
continue;
|
||||||
if (opt == '?' || strchr(template, opt) == NULL) {
|
if (opt == '?' || strchr(parse->template, opt) == NULL) {
|
||||||
args_free(args);
|
args_free(args);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -105,7 +105,8 @@ args_parse(const char *template, int argc, char **argv, int lower, int upper)
|
|||||||
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)) {
|
if ((parse->lower != -1 && argc < parse->lower) ||
|
||||||
|
(parse->upper != -1 && argc > parse->upper)) {
|
||||||
args_free(args);
|
args_free(args);
|
||||||
return (NULL);
|
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);
|
return (NULL);
|
||||||
cmd_log_argv(argc, argv, "%s: %s", __func__, entry->name);
|
cmd_log_argv(argc, argv, "%s: %s", __func__, entry->name);
|
||||||
|
|
||||||
args = args_parse(entry->args.template, argc, argv, entry->args.lower,
|
args = args_parse(&entry->args, argc, argv);
|
||||||
entry->args.upper);
|
|
||||||
if (args == NULL)
|
if (args == NULL)
|
||||||
goto usage;
|
goto usage;
|
||||||
|
|
||||||
|
15
tmux.h
15
tmux.h
@ -1365,6 +1365,13 @@ struct args_value {
|
|||||||
struct args_entry;
|
struct args_entry;
|
||||||
RB_HEAD(args_tree, args_entry);
|
RB_HEAD(args_tree, args_entry);
|
||||||
|
|
||||||
|
/* Arguments parsing state. */
|
||||||
|
struct args_parse {
|
||||||
|
const char *template;
|
||||||
|
int lower;
|
||||||
|
int upper;
|
||||||
|
};
|
||||||
|
|
||||||
/* Command find structures. */
|
/* Command find structures. */
|
||||||
enum cmd_find_type {
|
enum cmd_find_type {
|
||||||
CMD_FIND_PANE,
|
CMD_FIND_PANE,
|
||||||
@ -1453,11 +1460,7 @@ struct cmd_entry {
|
|||||||
const char *name;
|
const char *name;
|
||||||
const char *alias;
|
const char *alias;
|
||||||
|
|
||||||
struct {
|
struct args_parse args;
|
||||||
const char *template;
|
|
||||||
int lower;
|
|
||||||
int upper;
|
|
||||||
} args;
|
|
||||||
const char *usage;
|
const char *usage;
|
||||||
|
|
||||||
struct cmd_entry_flag source;
|
struct cmd_entry_flag source;
|
||||||
@ -2183,7 +2186,7 @@ int tty_keys_next(struct tty *);
|
|||||||
/* arguments.c */
|
/* arguments.c */
|
||||||
void args_set(struct args *, u_char, const char *);
|
void args_set(struct args *, u_char, const char *);
|
||||||
struct args *args_create(void);
|
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_vector(struct args *, int *, char ***);
|
||||||
void args_free(struct args *);
|
void args_free(struct args *);
|
||||||
char *args_print(struct args *);
|
char *args_print(struct args *);
|
||||||
|
Loading…
Reference in New Issue
Block a user