From 95f427c34e4db9d7456d2d747e6cd6b54d8badcc Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Sat, 3 Mar 2012 09:16:52 +0000 Subject: [PATCH] Sync OpenBSD patchset 1032: Allow a single option to be specified to show-options to show just that option. --- cmd-set-option.c | 38 +------------------------------------- cmd-show-options.c | 28 ++++++++++++++++++++++------ options-table.c | 33 +++++++++++++++++++++++++++++++++ tmux.1 | 6 ++++-- tmux.h | 3 +++ 5 files changed, 63 insertions(+), 45 deletions(-) diff --git a/cmd-set-option.c b/cmd-set-option.c index 5db70f63..06e7c25e 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -29,9 +29,6 @@ int cmd_set_option_exec(struct cmd *, struct cmd_ctx *); -int cmd_set_option_find(const char *, const struct options_table_entry **, - const struct options_table_entry **); - int cmd_set_option_unset(struct cmd *, struct cmd_ctx *, const struct options_table_entry *, struct options *, const char *); @@ -81,39 +78,6 @@ const struct cmd_entry cmd_set_window_option_entry = { cmd_set_option_exec }; -/* Look for an option in all three tables. */ -int -cmd_set_option_find( - const char *optstr, const struct options_table_entry **table, - const struct options_table_entry **oe) -{ - static const struct options_table_entry *tables[] = { - server_options_table, - window_options_table, - session_options_table - }; - const struct options_table_entry *oe_loop; - u_int i; - - for (i = 0; i < nitems(tables); i++) { - for (oe_loop = tables[i]; oe_loop->name != NULL; oe_loop++) { - if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0) - continue; - - /* If already found, ambiguous. */ - if (*oe != NULL) - return (-1); - *oe = oe_loop; - *table = tables[i]; - - /* Bail now if an exact match. */ - if (strcmp((*oe)->name, optstr) == 0) - break; - } - } - return (0); -} - int cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) { @@ -139,7 +103,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) /* Find the option entry, try each table. */ table = oe = NULL; - if (cmd_set_option_find(optstr, &table, &oe) != 0) { + if (options_table_find(optstr, &table, &oe) != 0) { ctx->error(ctx, "ambiguous option: %s", optstr); return (-1); } diff --git a/cmd-show-options.c b/cmd-show-options.c index 397b0c9c..3abb5643 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -31,8 +31,8 @@ int cmd_show_options_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_show_options_entry = { "show-options", "show", - "gst:w", 0, 0, - "[-gsw] [-t target-session|target-window]", + "gst:w", 0, 1, + "[-gsw] [-t target-session|target-window] [option]", 0, NULL, NULL, @@ -41,8 +41,8 @@ const struct cmd_entry cmd_show_options_entry = { const struct cmd_entry cmd_show_window_options_entry = { "show-window-options", "showw", - "gt:", 0, 0, - "[-g] " CMD_TARGET_WINDOW_USAGE, + "gt:", 0, 1, + "[-g] " CMD_TARGET_WINDOW_USAGE " [option]", 0, NULL, NULL, @@ -86,11 +86,27 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) } } - for (oe = table; oe->name != NULL; oe++) { + if (args->argc != 0) { + table = oe = NULL; + if (options_table_find(args->argv[0], &table, &oe) != 0) { + ctx->error(ctx, "ambiguous option: %s", args->argv[0]); + return (-1); + } + if (oe == NULL) { + ctx->error(ctx, "unknown option: %s", args->argv[0]); + return (-1); + } if ((o = options_find1(oo, oe->name)) == NULL) - continue; + return (0); optval = options_table_print_entry(oe, o); ctx->print(ctx, "%s %s", oe->name, optval); + } else { + for (oe = table; oe->name != NULL; oe++) { + if ((o = options_find1(oo, oe->name)) == NULL) + continue; + optval = options_table_print_entry(oe, o); + ctx->print(ctx, "%s %s", oe->name, optval); + } } return (0); diff --git a/options-table.c b/options-table.c index 8f525161..57896fc5 100644 --- a/options-table.c +++ b/options-table.c @@ -731,3 +731,36 @@ options_table_print_entry( } return (out); } + +/* Find an option. */ +int +options_table_find( + const char *optstr, const struct options_table_entry **table, + const struct options_table_entry **oe) +{ + static const struct options_table_entry *tables[] = { + server_options_table, + window_options_table, + session_options_table + }; + const struct options_table_entry *oe_loop; + u_int i; + + for (i = 0; i < nitems(tables); i++) { + for (oe_loop = tables[i]; oe_loop->name != NULL; oe_loop++) { + if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0) + continue; + + /* If already found, ambiguous. */ + if (*oe != NULL) + return (-1); + *oe = oe_loop; + *table = tables[i]; + + /* Bail now if an exact match. */ + if (strcmp((*oe)->name, optstr) == 0) + break; + } + } + return (0); +} diff --git a/tmux.1 b/tmux.1 index abfee952..252d40bc 100644 --- a/tmux.1 +++ b/tmux.1 @@ -2626,9 +2626,10 @@ The default is off. .It Xo Ic show-options .Op Fl gsw .Op Fl t Ar target-session | Ar target-window +.Op Ar option .Xc .D1 (alias: Ic show ) -Show the window options with +Show the window options (or a single window option if given) with .Fl w (equivalent to .Ic show-window-options ) , @@ -2642,9 +2643,10 @@ is used. .It Xo Ic show-window-options .Op Fl g .Op Fl t Ar target-window +.Op Ar option .Xc .D1 (alias: Ic showw ) -List the window options for +List the window options or a single option for .Ar target-window , or the global window options if .Fl g diff --git a/tmux.h b/tmux.h index b8caee43..7a38777b 100644 --- a/tmux.h +++ b/tmux.h @@ -1415,6 +1415,9 @@ void options_table_populate_tree( const struct options_table_entry *, struct options *); const char *options_table_print_entry( const struct options_table_entry *, struct options_entry *); +int options_table_find( + const char *, const struct options_table_entry **, + const struct options_table_entry **); /* job.c */ extern struct joblist all_jobs;