enum cmd_retval cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct session *s; struct winlink *wl; const struct options_table_entry *table; struct options *oo; int quiet; if (args_has(self->args, 's')) { oo = global_options; table = server_options_table; } else if (args_has(self->args, 'w') || self->entry == &cmd_show_window_options_entry) { table = window_options_table; if (args_has(self->args, 'g')) oo = global_w_options; else { wl = cmd_find_window(cmdq, args_get(args, 't'), NULL); if (wl == NULL) return (CMD_RETURN_ERROR); oo = wl->window->options; } } else { table = session_options_table; if (args_has(self->args, 'g')) oo = global_s_options; else { s = cmd_find_session(cmdq, args_get(args, 't'), 0); if (s == NULL) return (CMD_RETURN_ERROR); oo = s->options; } } quiet = args_has(self->args, 'q'); if (args->argc == 0) return (cmd_show_options_all(self, cmdq, table, oo)); else return (cmd_show_options_one(self, cmdq, oo, quiet)); }
static enum cmd_retval cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct cmd_find_state *fs = &item->target; struct client *c = cmd_find_client(item, NULL, 1); struct session *s = item->target.s; struct winlink *wl = item->target.wl; struct options *oo; enum options_table_scope scope; char *argument, *name = NULL, *cause; const char *target; int window, idx, ambiguous; struct options_entry *o; window = (self->entry == &cmd_show_window_options_entry); if (args->argc == 0) { scope = options_scope_from_flags(args, window, fs, &oo, &cause); return (cmd_show_options_all(self, item, oo)); } argument = format_single(item, args->argv[0], c, s, wl, NULL); name = options_match(argument, &idx, &ambiguous); if (name == NULL) { if (args_has(args, 'q')) goto fail; if (ambiguous) cmdq_error(item, "ambiguous option: %s", argument); else cmdq_error(item, "invalid option: %s", argument); goto fail; } if (*name == '@') scope = options_scope_from_flags(args, window, fs, &oo, &cause); else { 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 { scope = OPTIONS_TABLE_NONE; xasprintf(&cause, "unknown option: %s", argument); } if (scope == OPTIONS_TABLE_SERVER) oo = global_options; else if (scope == OPTIONS_TABLE_SESSION) { if (args_has(self->args, 'g')) oo = global_s_options; else if (s == NULL) { target = args_get(args, 't'); if (target != NULL) { cmdq_error(item, "no such session: %s", target); } else cmdq_error(item, "no current session"); goto fail; } else oo = s->options; } else if (scope == OPTIONS_TABLE_WINDOW) { if (args_has(self->args, 'g')) oo = global_w_options; else if (wl == NULL) { target = args_get(args, 't'); if (target != NULL) { cmdq_error(item, "no such window: %s", target); } else cmdq_error(item, "no current window"); goto fail; } else oo = wl->window->options; } } if (scope == OPTIONS_TABLE_NONE) { if (args_has(args, 'q')) goto fail; cmdq_error(item, "%s", cause); free(cause); goto fail; } o = options_get_only(oo, name); if (o != NULL) cmd_show_options_print(self, item, o, idx); free(name); free(argument); return (CMD_RETURN_NORMAL); fail: free(name); free(argument); return (CMD_RETURN_ERROR); }