version 1.34, 2016/10/16 19:04:05 |
version 1.35, 2017/01/15 20:48:41 |
|
|
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <vis.h> |
|
|
#include "tmux.h" |
#include "tmux.h" |
|
|
|
|
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *); |
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *); |
|
|
static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmdq_item *, |
static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmdq_item *, |
struct options *, int); |
struct options *); |
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *, |
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *, |
struct options *, enum options_table_scope); |
struct options *); |
|
|
const struct cmd_entry cmd_show_options_entry = { |
const struct cmd_entry cmd_show_options_entry = { |
.name = "show-options", |
.name = "show-options", |
|
|
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) |
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
struct session *s = item->state.tflag.s; |
struct cmd_find_state *fs = &item->state.tflag; |
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; |
char *cause; |
const char *target; |
int window; |
|
|
if (args_has(self->args, 's')) { |
window = (self->entry == &cmd_show_window_options_entry); |
oo = global_options; |
scope = options_scope_from_flags(args, window, fs, &oo, &cause); |
scope = OPTIONS_TABLE_SERVER; |
if (scope == OPTIONS_TABLE_NONE) { |
} else if (args_has(self->args, 'w') || |
cmdq_error(item, "%s", cause); |
self->entry == &cmd_show_window_options_entry) { |
free(cause); |
scope = OPTIONS_TABLE_WINDOW; |
return (CMD_RETURN_ERROR); |
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"); |
|
return (CMD_RETURN_ERROR); |
|
} else |
|
oo = wl->window->options; |
|
} else { |
|
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"); |
|
return (CMD_RETURN_ERROR); |
|
} else |
|
oo = s->options; |
|
} |
} |
|
|
quiet = args_has(self->args, 'q'); |
|
if (args->argc == 0) |
if (args->argc == 0) |
return (cmd_show_options_all(self, item, oo, scope)); |
return (cmd_show_options_all(self, item, oo)); |
else |
else |
return (cmd_show_options_one(self, item, oo, quiet)); |
return (cmd_show_options_one(self, item, oo)); |
} |
} |
|
|
|
static void |
|
cmd_show_options_print(struct cmd *self, struct cmdq_item *item, |
|
struct option *o, int idx) |
|
{ |
|
const char *name; |
|
const char *value; |
|
char *tmp, *escaped; |
|
|
|
if (idx != -1) { |
|
xasprintf(&tmp, "%s[%d]", options_name(o), idx); |
|
name = tmp; |
|
} else { |
|
tmp = NULL; |
|
name = options_name(o); |
|
} |
|
|
|
value = options_tostring(o, idx); |
|
if (args_has(self->args, 'v')) |
|
cmdq_print(item, "%s", value); |
|
else if (options_isstring(o)) { |
|
stravis(&escaped, value, VIS_OCTAL|VIS_TAB|VIS_NL|VIS_DQ); |
|
cmdq_print(item, "%s \"%s\"", name, escaped); |
|
free(escaped); |
|
} else |
|
cmdq_print(item, "%s %s", name, value); |
|
|
|
free(tmp); |
|
} |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_show_options_one(struct cmd *self, struct cmdq_item *item, |
cmd_show_options_one(struct cmd *self, struct cmdq_item *item, |
struct options *oo, int quiet) |
struct options *oo) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
const char *name = args->argv[0]; |
struct option *o; |
const struct options_table_entry *oe; |
int idx, ambiguous; |
struct options_entry *o; |
const char *name = args->argv[0]; |
const char *optval; |
|
|
|
retry: |
o = options_match_get(oo, name, &idx, 1, &ambiguous); |
if (*name == '@') { |
if (o == NULL) { |
if ((o = options_find1(oo, name)) == NULL) { |
if (args_has(args, 'q')) |
if (quiet) |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
if (ambiguous) { |
cmdq_error(item, "unknown option: %s", name); |
cmdq_error(item, "ambiguous option: %s", name); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
if (args_has(self->args, 'v')) |
if (options_match_get(oo, name, &idx, 0, &ambiguous) != NULL) |
cmdq_print(item, "%s", o->str); |
|
else |
|
cmdq_print(item, "%s \"%s\"", o->name, o->str); |
|
return (CMD_RETURN_NORMAL); |
|
} |
|
|
|
oe = NULL; |
|
if (options_table_find(name, &oe) != 0) { |
|
cmdq_error(item, "ambiguous option: %s", name); |
|
return (CMD_RETURN_ERROR); |
|
} |
|
if (oe == NULL) { |
|
if (quiet) |
|
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
cmdq_error(item, "unknown option: %s", name); |
cmdq_error(item, "unknown option: %s", name); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
if (oe->style != NULL) { |
cmd_show_options_print(self, item, o, idx); |
name = oe->style; |
|
goto retry; |
|
} |
|
if ((o = options_find1(oo, oe->name)) == NULL) |
|
return (CMD_RETURN_NORMAL); |
|
optval = options_table_print_entry(oe, o, args_has(self->args, 'v')); |
|
if (args_has(self->args, 'v')) |
|
cmdq_print(item, "%s", optval); |
|
else |
|
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 cmdq_item *item, |
cmd_show_options_all(struct cmd *self, struct cmdq_item *item, |
struct options *oo, enum options_table_scope scope) |
struct options *oo) |
{ |
{ |
const struct options_table_entry *oe; |
struct option *o; |
struct options_entry *o; |
const struct options_table_entry *oe; |
const char *optval; |
u_int size, idx; |
int vflag; |
|
|
|
o = options_first(oo); |
o = options_first(oo); |
while (o != NULL) { |
while (o != NULL) { |
if (*o->name == '@') { |
oe = options_table_entry(o); |
if (args_has(self->args, 'v')) |
if (oe != NULL && oe->style != NULL) { |
cmdq_print(item, "%s", o->str); |
o = options_next(o); |
else |
continue; |
cmdq_print(item, "%s \"%s\"", o->name, o->str); |
|
} |
} |
|
if (options_array_size(o, &size) == -1) |
|
cmd_show_options_print(self, item, o, -1); |
|
else { |
|
for (idx = 0; idx < size; idx++) { |
|
if (options_array_get(o, idx) == NULL) |
|
continue; |
|
cmd_show_options_print(self, item, o, idx); |
|
} |
|
} |
o = options_next(o); |
o = options_next(o); |
} |
} |
|
|
vflag = args_has(self->args, 'v'); |
|
for (oe = options_table; oe->name != NULL; oe++) { |
|
if (oe->style != NULL || oe->scope != scope) |
|
continue; |
|
if ((o = options_find1(oo, oe->name)) == NULL) |
|
continue; |
|
optval = options_table_print_entry(oe, o, vflag); |
|
if (vflag) |
|
cmdq_print(item, "%s", optval); |
|
else |
|
cmdq_print(item, "%s %s", oe->name, optval); |
|
} |
|
|
|
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
} |
} |