summaryrefslogtreecommitdiffstats
path: root/options.c
diff options
context:
space:
mode:
authornicm <nicm>2019-06-20 07:41:29 +0000
committernicm <nicm>2019-06-20 07:41:29 +0000
commitc1ede507d954b98a73c40665e7aee6fe5f0c5bce (patch)
tree279281ff205a0a31e27d7e6a9796aa522eb7123a /options.c
parentcd1fc42df6d1bacac4f617e031c279ba31bc0632 (diff)
Add a helper function to work out option table from name.
Diffstat (limited to 'options.c')
-rw-r--r--options.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/options.c b/options.c
index 619c27ed..3bce6041 100644
--- a/options.c
+++ b/options.c
@@ -726,12 +726,62 @@ options_set_style(struct options *oo, const char *name, int append,
}
enum options_table_scope
+options_scope_from_name(struct args *args, int window,
+ const char *name, struct cmd_find_state *fs, struct options **oo,
+ char **cause)
+{
+ struct session *s = fs->s;
+ struct winlink *wl = fs->wl;
+ const char *target = args_get(args, 't');
+ enum options_table_scope scope;
+
+ if (*name == '@')
+ return (options_scope_from_flags(args, window, fs, oo, cause));
+
+ if (options_get_only(global_options, name) != NULL)
+ scope = OPTIONS_TABLE_SERVER;
+ else if (options_get_only(global_s_options, name) != NULL)
+ scope = OPTIONS_TABLE_SESSION;
+ else if (options_get_only(global_w_options, name) != NULL)
+ scope = OPTIONS_TABLE_WINDOW;
+ else {
+ xasprintf(cause, "unknown option: %s", name);
+ return (OPTIONS_TABLE_NONE);
+ }
+
+ if (scope == OPTIONS_TABLE_SERVER)
+ *oo = global_options;
+ else if (scope == OPTIONS_TABLE_SESSION) {
+ if (args_has(args, 'g'))
+ *oo = global_s_options;
+ else if (s == NULL) {
+ if (target != NULL)
+ xasprintf(cause, "no such session: %s", target);
+ else
+ xasprintf(cause, "no current session");
+ } else
+ *oo = s->options;
+ } else if (scope == OPTIONS_TABLE_WINDOW) {
+ if (args_has(args, 'g'))
+ *oo = global_w_options;
+ else if (wl == NULL) {
+ if (target != NULL)
+ xasprintf(cause, "no such window: %s", target);
+ else
+ xasprintf(cause, "no current window");
+ } else
+ *oo = wl->window->options;
+ }
+ return (scope);
+}
+
+enum options_table_scope
options_scope_from_flags(struct args *args, int window,
struct cmd_find_state *fs, struct options **oo, char **cause)
{
struct session *s = fs->s;
struct winlink *wl = fs->wl;
- const char *target= args_get(args, 't');
+ const char *target = args_get(args, 't');
if (args_has(args, 's')) {
*oo = global_options;