version 1.33, 2016/10/14 22:14:22 |
version 1.34, 2016/10/16 19:04:05 |
|
|
* Show options. |
* Show options. |
*/ |
*/ |
|
|
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *); |
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *); |
|
|
static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *, |
static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmdq_item *, |
struct options *, int); |
struct options *, int); |
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *, |
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *, |
struct options *, enum options_table_scope); |
struct options *, enum options_table_scope); |
|
|
const struct cmd_entry cmd_show_options_entry = { |
const struct cmd_entry cmd_show_options_entry = { |
|
|
}; |
}; |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) |
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
struct session *s = cmdq->state.tflag.s; |
struct session *s = item->state.tflag.s; |
struct winlink *wl = cmdq->state.tflag.wl; |
struct winlink *wl = item->state.tflag.wl; |
struct options *oo; |
struct options *oo; |
enum options_table_scope scope; |
enum options_table_scope scope; |
int quiet; |
int quiet; |
|
|
else if (wl == NULL) { |
else if (wl == NULL) { |
target = args_get(args, 't'); |
target = args_get(args, 't'); |
if (target != NULL) { |
if (target != NULL) { |
cmdq_error(cmdq, "no such window: %s", target); |
cmdq_error(item, "no such window: %s", target); |
} else |
} else |
cmdq_error(cmdq, "no current window"); |
cmdq_error(item, "no current window"); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} else |
} else |
oo = wl->window->options; |
oo = wl->window->options; |
|
|
else if (s == NULL) { |
else if (s == NULL) { |
target = args_get(args, 't'); |
target = args_get(args, 't'); |
if (target != NULL) { |
if (target != NULL) { |
cmdq_error(cmdq, "no such session: %s", target); |
cmdq_error(item, "no such session: %s", target); |
} else |
} else |
cmdq_error(cmdq, "no current session"); |
cmdq_error(item, "no current session"); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} else |
} else |
oo = s->options; |
oo = s->options; |
|
|
|
|
quiet = args_has(self->args, 'q'); |
quiet = args_has(self->args, 'q'); |
if (args->argc == 0) |
if (args->argc == 0) |
return (cmd_show_options_all(self, cmdq, oo, scope)); |
return (cmd_show_options_all(self, item, oo, scope)); |
else |
else |
return (cmd_show_options_one(self, cmdq, oo, quiet)); |
return (cmd_show_options_one(self, item, oo, quiet)); |
} |
} |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq, |
cmd_show_options_one(struct cmd *self, struct cmdq_item *item, |
struct options *oo, int quiet) |
struct options *oo, int quiet) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
|
|
if ((o = options_find1(oo, name)) == NULL) { |
if ((o = options_find1(oo, name)) == NULL) { |
if (quiet) |
if (quiet) |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
cmdq_error(cmdq, "unknown option: %s", name); |
cmdq_error(item, "unknown option: %s", name); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
if (args_has(self->args, 'v')) |
if (args_has(self->args, 'v')) |
cmdq_print(cmdq, "%s", o->str); |
cmdq_print(item, "%s", o->str); |
else |
else |
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str); |
cmdq_print(item, "%s \"%s\"", o->name, o->str); |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
} |
} |
|
|
oe = NULL; |
oe = NULL; |
if (options_table_find(name, &oe) != 0) { |
if (options_table_find(name, &oe) != 0) { |
cmdq_error(cmdq, "ambiguous option: %s", name); |
cmdq_error(item, "ambiguous option: %s", name); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
if (oe == NULL) { |
if (oe == NULL) { |
if (quiet) |
if (quiet) |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
cmdq_error(cmdq, "unknown option: %s", name); |
cmdq_error(item, "unknown option: %s", name); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
if (oe->style != NULL) { |
if (oe->style != NULL) { |
|
|
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
optval = options_table_print_entry(oe, o, args_has(self->args, 'v')); |
optval = options_table_print_entry(oe, o, args_has(self->args, 'v')); |
if (args_has(self->args, 'v')) |
if (args_has(self->args, 'v')) |
cmdq_print(cmdq, "%s", optval); |
cmdq_print(item, "%s", optval); |
else |
else |
cmdq_print(cmdq, "%s %s", oe->name, optval); |
cmdq_print(item, "%s %s", oe->name, optval); |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
} |
} |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq, struct options *oo, |
cmd_show_options_all(struct cmd *self, struct cmdq_item *item, |
enum options_table_scope scope) |
struct options *oo, enum options_table_scope scope) |
{ |
{ |
const struct options_table_entry *oe; |
const struct options_table_entry *oe; |
struct options_entry *o; |
struct options_entry *o; |
|
|
while (o != NULL) { |
while (o != NULL) { |
if (*o->name == '@') { |
if (*o->name == '@') { |
if (args_has(self->args, 'v')) |
if (args_has(self->args, 'v')) |
cmdq_print(cmdq, "%s", o->str); |
cmdq_print(item, "%s", o->str); |
else |
else |
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str); |
cmdq_print(item, "%s \"%s\"", o->name, o->str); |
} |
} |
o = options_next(o); |
o = options_next(o); |
} |
} |
|
|
continue; |
continue; |
optval = options_table_print_entry(oe, o, vflag); |
optval = options_table_print_entry(oe, o, vflag); |
if (vflag) |
if (vflag) |
cmdq_print(cmdq, "%s", optval); |
cmdq_print(item, "%s", optval); |
else |
else |
cmdq_print(cmdq, "%s %s", oe->name, optval); |
cmdq_print(item, "%s %s", oe->name, optval); |
} |
} |
|
|
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |