diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-08-20 17:53:55 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-08-20 17:53:55 +0000 |
commit | 7945ba1cb9346b88267a4022df6945ee52e11e44 (patch) | |
tree | ec6b4eae16bb780fe1744d751007907b5dbc996f /usr.bin | |
parent | a1e05a9c0cbadc20fc2e9fcf1b48de3baf5cab0a (diff) |
Add a way to create an empty arguments set.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/arguments.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-find-window.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
3 files changed, 18 insertions, 7 deletions
diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c index 45ecaaacbaa..53649afe1ac 100644 --- a/usr.bin/tmux/arguments.c +++ b/usr.bin/tmux/arguments.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arguments.c,v 1.35 2020/06/12 07:10:43 nicm Exp $ */ +/* $OpenBSD: arguments.c,v 1.36 2021/08/20 17:53:54 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -64,6 +64,17 @@ args_find(struct args *args, u_char flag) return (RB_FIND(args_tree, &args->tree, &entry)); } +/* Create an empty arguments set. */ +struct args * +args_create(void) +{ + struct args *args; + + args = xcalloc(1, sizeof *args); + RB_INIT(&args->tree); + return (args); +} + /* Parse an argv and argc into a new argument set. */ struct args * args_parse(const char *template, int argc, char **argv) @@ -71,12 +82,11 @@ args_parse(const char *template, int argc, char **argv) struct args *args; int opt; - args = xcalloc(1, sizeof *args); - optreset = 1; optind = 1; optarg = NULL; + args = args_create(); while ((opt = getopt(argc, argv, template)) != -1) { if (opt < 0) continue; diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c index 1ba7d608c62..274bc2cfe90 100644 --- a/usr.bin/tmux/cmd-find-window.c +++ b/usr.bin/tmux/cmd-find-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-find-window.c,v 1.50 2020/05/29 13:42:13 nicm Exp $ */ +/* $OpenBSD: cmd-find-window.c,v 1.51 2021/08/20 17:53:54 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -48,7 +48,7 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) struct cmd_find_state *target = cmdq_get_target(item); struct window_pane *wp = target->wp; const char *s = args->argv[0], *suffix = ""; - char *filter, *argv = { NULL }; + char *filter; int C, N, T; C = args_has(args, 'C'); @@ -91,7 +91,7 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) else xasprintf(&filter, "#{m%s:*%s*,#{pane_title}}", suffix, s); - new_args = args_parse("", 1, &argv); + new_args = args_create(); if (args_has(args, 'Z')) args_set(new_args, 'Z', NULL); args_set(new_args, 'f', filter); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 6646bb5dacd..6fdc52ef6fc 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1123 2021/08/13 23:05:40 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1124 2021/08/20 17:53:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -2182,6 +2182,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 **); void args_free(struct args *); char *args_print(struct args *); |