diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2019-07-29 10:51:30 +0100 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2019-07-29 10:51:30 +0100 |
commit | da552eb73b80bab3c0a28dfb9ae2c75fa6d4bdaf (patch) | |
tree | cf9c86c3218659faf46e606a1e38bc6ebb570dcd /options.c | |
parent | 5a501a8ae27c2d0128870caa48c5708e97528567 (diff) | |
parent | b90a9fcd13f4434aed0fe1785d619aa668bbc77d (diff) | |
download | rtmux-da552eb73b80bab3c0a28dfb9ae2c75fa6d4bdaf.tar.gz rtmux-da552eb73b80bab3c0a28dfb9ae2c75fa6d4bdaf.tar.bz2 rtmux-da552eb73b80bab3c0a28dfb9ae2c75fa6d4bdaf.zip |
Merge branch 'master' into 3.0-rc
Diffstat (limited to 'options.c')
-rw-r--r-- | options.c | 105 |
1 files changed, 97 insertions, 8 deletions
@@ -100,7 +100,7 @@ options_parent_table_entry(struct options *oo, const char *s) if (oo->parent == NULL) fatalx("no parent options for %s", s); - o = options_get_only(oo->parent, s); + o = options_get(oo->parent, s); if (o == NULL) fatalx("%s not in parent options", s); return (o->tableentry); @@ -178,6 +178,12 @@ options_free(struct options *oo) free(oo); } +void +options_set_parent(struct options *oo, struct options *parent) +{ + oo->parent = parent; +} + struct options_entry * options_first(struct options *oo) { @@ -365,7 +371,8 @@ options_array_set(struct options_entry *o, u_int idx, const char *value, pr = cmd_parse_from_string(value, NULL); switch (pr->status) { case CMD_PARSE_EMPTY: - *cause = xstrdup("empty command"); + if (cause != NULL) + *cause = xstrdup("empty command"); return (-1); case CMD_PARSE_ERROR: if (cause != NULL) @@ -544,7 +551,7 @@ options_parse_get(struct options *oo, const char *s, int *idx, int only) } char * -options_match(const char *s, int *idx, int* ambiguous) +options_match(const char *s, int *idx, int *ambiguous) { const struct options_table_entry *oe, *found; char *name; @@ -724,20 +731,102 @@ options_set_style(struct options *oo, const char *name, int append, return (o); } -enum options_table_scope +int +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; + struct window_pane *wp = fs->wp; + const char *target = args_get(args, 't'); + const struct options_table_entry *oe; + int scope = OPTIONS_TABLE_NONE; + + if (*name == '@') + return (options_scope_from_flags(args, window, fs, oo, cause)); + + for (oe = options_table; oe->name != NULL; oe++) { + if (strcmp(oe->name, name) == 0) + break; + } + if (oe->name == NULL) { + xasprintf(cause, "unknown option: %s", name); + return (OPTIONS_TABLE_NONE); + } + switch (oe->scope) { + case OPTIONS_TABLE_SERVER: + *oo = global_options; + scope = OPTIONS_TABLE_SERVER; + break; + case OPTIONS_TABLE_SESSION: + if (args_has(args, 'g')) { + *oo = global_s_options; + scope = OPTIONS_TABLE_SESSION; + } else if (s == NULL && target != NULL) + xasprintf(cause, "no such session: %s", target); + else if (s == NULL) + xasprintf(cause, "no current session"); + else { + *oo = s->options; + scope = OPTIONS_TABLE_SESSION; + } + break; + case OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE: + if (args_has(args, 'p')) { + if (wp == NULL && target != NULL) + xasprintf(cause, "no such pane: %s", target); + else if (wp == NULL) + xasprintf(cause, "no current pane"); + else { + *oo = wp->options; + scope = OPTIONS_TABLE_PANE; + } + break; + } + /* FALLTHROUGH */ + case OPTIONS_TABLE_WINDOW: + if (args_has(args, 'g')) { + *oo = global_w_options; + scope = OPTIONS_TABLE_WINDOW; + } else if (wl == NULL && target != NULL) + xasprintf(cause, "no such window: %s", target); + else if (wl == NULL) + xasprintf(cause, "no current window"); + else { + *oo = wl->window->options; + scope = OPTIONS_TABLE_WINDOW; + } + break; + } + return (scope); +} + +int 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'); + struct session *s = fs->s; + struct winlink *wl = fs->wl; + struct window_pane *wp = fs->wp; + const char *target = args_get(args, 't'); if (args_has(args, 's')) { *oo = global_options; return (OPTIONS_TABLE_SERVER); } - if (window || args_has(args, 'w')) { + if (args_has(args, 'p')) { + if (wp == NULL) { + if (target != NULL) + xasprintf(cause, "no such pane: %s", target); + else + xasprintf(cause, "no current pane"); + return (OPTIONS_TABLE_NONE); + } + *oo = wp->options; + return (OPTIONS_TABLE_PANE); + } else if (window || args_has(args, 'w')) { if (args_has(args, 'g')) { *oo = global_w_options; return (OPTIONS_TABLE_WINDOW); |