2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Show options.
|
|
|
|
*/
|
|
|
|
|
2013-03-24 09:54:10 +00:00
|
|
|
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2013-03-24 09:54:10 +00:00
|
|
|
enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *,
|
2013-03-25 10:04:04 +00:00
|
|
|
struct options *, int);
|
2013-03-24 09:54:10 +00:00
|
|
|
enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *,
|
2013-03-21 16:17:01 +00:00
|
|
|
const struct options_table_entry *, struct options *);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
const struct cmd_entry cmd_show_options_entry = {
|
|
|
|
"show-options", "show",
|
2013-03-25 10:04:04 +00:00
|
|
|
"gqst:vw", 0, 1,
|
|
|
|
"[-gqsvw] [-t target-session|target-window] [option]",
|
2011-01-04 00:42:46 +00:00
|
|
|
0,
|
|
|
|
cmd_show_options_exec
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2011-01-04 02:03:41 +00:00
|
|
|
const struct cmd_entry cmd_show_window_options_entry = {
|
|
|
|
"show-window-options", "showw",
|
2013-03-21 16:17:01 +00:00
|
|
|
"gvt:", 0, 1,
|
|
|
|
"[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
2011-01-04 02:03:41 +00:00
|
|
|
0,
|
|
|
|
cmd_show_options_exec
|
|
|
|
};
|
|
|
|
|
2012-07-11 07:10:15 +00:00
|
|
|
enum cmd_retval
|
2013-03-24 09:54:10 +00:00
|
|
|
cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2011-01-04 00:42:46 +00:00
|
|
|
struct args *args = self->args;
|
2011-01-01 16:51:21 +00:00
|
|
|
struct session *s;
|
|
|
|
struct winlink *wl;
|
2013-03-21 16:17:01 +00:00
|
|
|
const struct options_table_entry *table;
|
2011-01-01 16:51:21 +00:00
|
|
|
struct options *oo;
|
2013-03-25 10:04:04 +00:00
|
|
|
int quiet;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(self->args, 's')) {
|
2009-12-10 09:16:52 +00:00
|
|
|
oo = &global_options;
|
2011-01-01 16:51:21 +00:00
|
|
|
table = server_options_table;
|
2011-01-04 02:03:41 +00:00
|
|
|
} else if (args_has(self->args, 'w') ||
|
|
|
|
self->entry == &cmd_show_window_options_entry) {
|
2011-01-01 16:51:21 +00:00
|
|
|
table = window_options_table;
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(self->args, 'g'))
|
2009-12-03 17:44:02 +00:00
|
|
|
oo = &global_w_options;
|
|
|
|
else {
|
2013-03-24 09:54:10 +00:00
|
|
|
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
|
2009-12-03 17:44:02 +00:00
|
|
|
if (wl == NULL)
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2009-12-03 17:44:02 +00:00
|
|
|
oo = &wl->window->options;
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-01 16:51:21 +00:00
|
|
|
table = session_options_table;
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(self->args, 'g'))
|
2009-12-03 17:44:02 +00:00
|
|
|
oo = &global_s_options;
|
|
|
|
else {
|
2013-03-24 09:54:10 +00:00
|
|
|
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
2009-12-03 17:44:02 +00:00
|
|
|
if (s == NULL)
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2009-12-03 17:44:02 +00:00
|
|
|
oo = &s->options;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 10:04:04 +00:00
|
|
|
quiet = args_has(self->args, 'q');
|
|
|
|
if (args->argc == 0)
|
2013-03-24 09:54:10 +00:00
|
|
|
return (cmd_show_options_all(self, cmdq, table, oo));
|
2013-03-25 10:04:04 +00:00
|
|
|
else
|
|
|
|
return (cmd_show_options_one(self, cmdq, oo, quiet));
|
2013-03-21 16:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum cmd_retval
|
2013-03-24 09:54:10 +00:00
|
|
|
cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
|
2013-03-25 10:04:04 +00:00
|
|
|
struct options *oo, int quiet)
|
2013-03-21 16:17:01 +00:00
|
|
|
{
|
|
|
|
struct args *args = self->args;
|
2014-04-17 07:43:20 +00:00
|
|
|
const char *name = args->argv[0];
|
2013-03-21 16:17:01 +00:00
|
|
|
const struct options_table_entry *table, *oe;
|
|
|
|
struct options_entry *o;
|
|
|
|
const char *optval;
|
|
|
|
|
2014-04-17 07:43:20 +00:00
|
|
|
retry:
|
|
|
|
if (*name == '@') {
|
|
|
|
if ((o = options_find1(oo, name)) == NULL) {
|
2013-03-25 10:04:04 +00:00
|
|
|
if (quiet)
|
|
|
|
return (CMD_RETURN_NORMAL);
|
2014-04-17 07:43:20 +00:00
|
|
|
cmdq_error(cmdq, "unknown option: %s", name);
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2012-02-25 12:57:42 +00:00
|
|
|
}
|
2013-03-21 16:17:01 +00:00
|
|
|
if (args_has(self->args, 'v'))
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_print(cmdq, "%s", o->str);
|
2013-03-21 16:17:01 +00:00
|
|
|
else
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
|
2013-03-21 16:17:01 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
table = oe = NULL;
|
2014-04-17 07:43:20 +00:00
|
|
|
if (options_table_find(name, &table, &oe) != 0) {
|
|
|
|
cmdq_error(cmdq, "ambiguous option: %s", name);
|
2013-03-21 16:17:01 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
}
|
|
|
|
if (oe == NULL) {
|
2013-03-25 10:04:04 +00:00
|
|
|
if (quiet)
|
|
|
|
return (CMD_RETURN_NORMAL);
|
2014-04-17 07:43:20 +00:00
|
|
|
cmdq_error(cmdq, "unknown option: %s", name);
|
2013-03-21 16:17:01 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
}
|
2014-04-17 07:43:20 +00:00
|
|
|
if (oe->style != NULL) {
|
|
|
|
name = oe->style;
|
|
|
|
goto retry;
|
|
|
|
}
|
2013-03-21 16:17:01 +00:00
|
|
|
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'))
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_print(cmdq, "%s", optval);
|
2013-03-21 16:17:01 +00:00
|
|
|
else
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_print(cmdq, "%s %s", oe->name, optval);
|
2013-03-21 16:17:01 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum cmd_retval
|
2013-03-24 09:54:10 +00:00
|
|
|
cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq,
|
2013-03-21 16:17:01 +00:00
|
|
|
const struct options_table_entry *table, struct options *oo)
|
|
|
|
{
|
|
|
|
const struct options_table_entry *oe;
|
|
|
|
struct options_entry *o;
|
|
|
|
const char *optval;
|
|
|
|
|
|
|
|
RB_FOREACH(o, options_tree, &oo->tree) {
|
|
|
|
if (*o->name == '@') {
|
|
|
|
if (args_has(self->args, 'v'))
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_print(cmdq, "%s", o->str);
|
2013-03-21 16:17:01 +00:00
|
|
|
else
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
|
2012-02-25 12:57:42 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 16:17:01 +00:00
|
|
|
for (oe = table; oe->name != NULL; oe++) {
|
2014-04-17 07:43:20 +00:00
|
|
|
if (oe->style != NULL)
|
|
|
|
continue;
|
2013-03-21 16:17:01 +00:00
|
|
|
if ((o = options_find1(oo, oe->name)) == NULL)
|
|
|
|
continue;
|
|
|
|
optval = options_table_print_entry(oe, o,
|
|
|
|
args_has(self->args, 'v'));
|
|
|
|
if (args_has(self->args, 'v'))
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_print(cmdq, "%s", optval);
|
2013-03-21 16:17:01 +00:00
|
|
|
else
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_print(cmdq, "%s %s", oe->name, optval);
|
2013-03-21 16:17:01 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|