summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2021-08-21 08:45:00 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2021-08-21 08:45:00 +0000
commit74ec25b81c3a3e829dff01a606be13a1a2e1daf0 (patch)
treebe89a0f28fdf1ed787bf888bba4fa31246479473 /usr.bin
parent8f793168bad3b38ed711f06a7e5d23b1743e97b0 (diff)
Wrap command argument definitions in their own struct.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/arguments.c11
-rw-r--r--usr.bin/tmux/cmd.c5
-rw-r--r--usr.bin/tmux/tmux.h17
3 files changed, 18 insertions, 15 deletions
diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c
index 6bcbe2dd124..b38b07446e9 100644
--- a/usr.bin/tmux/arguments.c
+++ b/usr.bin/tmux/arguments.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arguments.c,v 1.39 2021/08/20 20:08:30 nicm Exp $ */
+/* $OpenBSD: arguments.c,v 1.40 2021/08/21 08:44:59 nicm Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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);
}
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index 343375c5f48..c255c162386 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.166 2021/08/20 19:50:17 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.167 2021/08/21 08:44:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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;
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index e06d12d13ac..07010cbb6be 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1127 2021/08/20 19:50:17 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1128 2021/08/21 08:44:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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 *);