-/* $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>
/* 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;
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);
}
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);
}
-/* $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>
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;
-/* $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>
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,
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;
/* 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 *);