summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-11-13 19:53:28 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-11-13 19:53:28 +0000
commit76ef8770cd983e7ece581fbcfb3a7ad5e115aae5 (patch)
tree0b0d7847f179c9963b58488f8c1724e64176266e
parentdafa0f022c573513f949c7c66ae83d063fa9a2ab (diff)
Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.
-rw-r--r--cmd-attach-session.c6
-rw-r--r--cmd-bind-key.c2
-rw-r--r--cmd-break-pane.c4
-rw-r--r--cmd-choose-client.c2
-rw-r--r--cmd-choose-session.c2
-rw-r--r--cmd-choose-window.c2
-rw-r--r--cmd-clear-history.c2
-rw-r--r--cmd-clock-mode.c2
-rw-r--r--cmd-command-prompt.c2
-rw-r--r--cmd-confirm-before.c2
-rw-r--r--cmd-copy-buffer.c2
-rw-r--r--cmd-copy-mode.c6
-rw-r--r--cmd-delete-buffer.c2
-rw-r--r--cmd-detach-client.c2
-rw-r--r--cmd-display-message.c2
-rw-r--r--cmd-display-panes.c2
-rw-r--r--cmd-down-pane.c2
-rw-r--r--cmd-find-window.c2
-rw-r--r--cmd-generic.c88
-rw-r--r--cmd-has-session.c2
-rw-r--r--cmd-if-shell.c2
-rw-r--r--cmd-kill-pane.c4
-rw-r--r--cmd-kill-server.c2
-rw-r--r--cmd-kill-session.c2
-rw-r--r--cmd-kill-window.c2
-rw-r--r--cmd-last-window.c2
-rw-r--r--cmd-link-window.c6
-rw-r--r--cmd-list-buffers.c2
-rw-r--r--cmd-list-clients.c2
-rw-r--r--cmd-list-commands.c2
-rw-r--r--cmd-list-keys.c2
-rw-r--r--cmd-list-panes.c2
-rw-r--r--cmd-list-sessions.c2
-rw-r--r--cmd-list-windows.c2
-rw-r--r--cmd-load-buffer.c2
-rw-r--r--cmd-lock-client.c2
-rw-r--r--cmd-lock-server.c2
-rw-r--r--cmd-lock-session.c2
-rw-r--r--cmd-move-window.c6
-rw-r--r--cmd-new-session.c2
-rw-r--r--cmd-new-window.c2
-rw-r--r--cmd-next-layout.c2
-rw-r--r--cmd-next-window.c6
-rw-r--r--cmd-paste-buffer.c6
-rw-r--r--cmd-pipe-pane.c4
-rw-r--r--cmd-previous-layout.c2
-rw-r--r--cmd-previous-window.c6
-rw-r--r--cmd-refresh-client.c2
-rw-r--r--cmd-rename-session.c2
-rw-r--r--cmd-rename-window.c2
-rw-r--r--cmd-resize-pane.c34
-rw-r--r--cmd-respawn-window.c4
-rw-r--r--cmd-rotate-window.c6
-rw-r--r--cmd-run-shell.c2
-rw-r--r--cmd-save-buffer.c4
-rw-r--r--cmd-select-layout.c2
-rw-r--r--cmd-select-pane.c2
-rw-r--r--cmd-select-prompt.c2
-rw-r--r--cmd-select-window.c2
-rw-r--r--cmd-send-keys.c2
-rw-r--r--cmd-send-prefix.c2
-rw-r--r--cmd-server-info.c2
-rw-r--r--cmd-set-buffer.c2
-rw-r--r--cmd-set-environment.c8
-rw-r--r--cmd-set-option.c10
-rw-r--r--cmd-set-window-option.c10
-rw-r--r--cmd-show-buffer.c2
-rw-r--r--cmd-show-environment.c4
-rw-r--r--cmd-show-options.c4
-rw-r--r--cmd-show-window-options.c4
-rw-r--r--cmd-source-file.c2
-rw-r--r--cmd-split-window.c2
-rw-r--r--cmd-start-server.c2
-rw-r--r--cmd-suspend-client.c2
-rw-r--r--cmd-swap-pane.c13
-rw-r--r--cmd-swap-window.c4
-rw-r--r--cmd-switch-client.c2
-rw-r--r--cmd-unbind-key.c2
-rw-r--r--cmd-unlink-window.c4
-rw-r--r--cmd-up-pane.c2
-rw-r--r--tmux.h7
81 files changed, 185 insertions, 185 deletions
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index 59c2b479..be7adb3f 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -29,7 +29,7 @@ int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_attach_session_entry = {
"attach-session", "attach",
"[-d] " CMD_TARGET_SESSION_USAGE,
- CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, CMD_CHFLAG('d'),
+ CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, "d",
cmd_target_init,
cmd_target_parse,
cmd_attach_session_exec,
@@ -58,7 +58,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
return (0);
if (ctx->cmdclient == NULL) {
- if (data->chflags & CMD_CHFLAG('d')) {
+ if (cmd_check_flag(data->chflags, 'd')) {
/*
* Can't use server_write_session in case attaching to
* the same session as currently attached to.
@@ -89,7 +89,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
}
- if (data->chflags & CMD_CHFLAG('d'))
+ if (cmd_check_flag(data->chflags, 'd'))
server_write_session(s, MSG_DETACH, NULL, 0);
ctx->cmdclient->session = s;
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index 041f558d..eba5125b 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -46,7 +46,7 @@ struct cmd_bind_key_data {
const struct cmd_entry cmd_bind_key_entry = {
"bind-key", "bind",
"[-cnr] [-t key-table] key command [arguments]",
- 0, 0,
+ 0, "",
NULL,
cmd_bind_key_parse,
cmd_bind_key_exec,
diff --git a/cmd-break-pane.c b/cmd-break-pane.c
index 58a93de2..d465f602 100644
--- a/cmd-break-pane.c
+++ b/cmd-break-pane.c
@@ -31,7 +31,7 @@ int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_break_pane_entry = {
"break-pane", "breakp",
CMD_TARGET_PANE_USAGE " [-d]",
- 0, CMD_CHFLAG('d'),
+ 0, "d",
cmd_target_init,
cmd_target_parse,
cmd_break_pane_exec,
@@ -74,7 +74,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
base_idx = options_get_number(&s->options, "base-index");
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
- if (!(data->chflags & CMD_CHFLAG('d')))
+ if (!cmd_check_flag(data->chflags, 'd'))
session_select(s, wl->idx);
server_redraw_session(s);
diff --git a/cmd-choose-client.c b/cmd-choose-client.c
index 0aa66622..cd5ab9ea 100644
--- a/cmd-choose-client.c
+++ b/cmd-choose-client.c
@@ -34,7 +34,7 @@ void cmd_choose_client_free(void *);
const struct cmd_entry cmd_choose_client_entry = {
"choose-client", NULL,
CMD_TARGET_WINDOW_USAGE " [template]",
- CMD_ARG01, 0,
+ CMD_ARG01, "",
cmd_target_init,
cmd_target_parse,
cmd_choose_client_exec,
diff --git a/cmd-choose-session.c b/cmd-choose-session.c
index b9c7c258..23228105 100644
--- a/cmd-choose-session.c
+++ b/cmd-choose-session.c
@@ -34,7 +34,7 @@ void cmd_choose_session_free(void *);
const struct cmd_entry cmd_choose_session_entry = {
"choose-session", NULL,
CMD_TARGET_WINDOW_USAGE " [template]",
- CMD_ARG01, 0,
+ CMD_ARG01, "",
cmd_target_init,
cmd_target_parse,
cmd_choose_session_exec,
diff --git a/cmd-choose-window.c b/cmd-choose-window.c
index 9d6cd932..a1540f1d 100644
--- a/cmd-choose-window.c
+++ b/cmd-choose-window.c
@@ -34,7 +34,7 @@ void cmd_choose_window_free(void *);
const struct cmd_entry cmd_choose_window_entry = {
"choose-window", NULL,
CMD_TARGET_WINDOW_USAGE " [template]",
- CMD_ARG01, 0,
+ CMD_ARG01, "",
cmd_target_init,
cmd_target_parse,
cmd_choose_window_exec,
diff --git a/cmd-clear-history.c b/cmd-clear-history.c
index a9271346..9241485a 100644
--- a/cmd-clear-history.c
+++ b/cmd-clear-history.c
@@ -29,7 +29,7 @@ int cmd_clear_history_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_clear_history_entry = {
"clear-history", "clearhist",
CMD_TARGET_PANE_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_clear_history_exec,
diff --git a/cmd-clock-mode.c b/cmd-clock-mode.c
index b1f135a6..4df934f7 100644
--- a/cmd-clock-mode.c
+++ b/cmd-clock-mode.c
@@ -29,7 +29,7 @@ int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_clock_mode_entry = {
"clock-mode", NULL,
CMD_TARGET_PANE_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_clock_mode_exec,
diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c
index bcbde064..e3774256 100644
--- a/cmd-command-prompt.c
+++ b/cmd-command-prompt.c
@@ -39,7 +39,7 @@ void cmd_command_prompt_cfree(void *);
const struct cmd_entry cmd_command_prompt_entry = {
"command-prompt", NULL,
CMD_TARGET_CLIENT_USAGE " [-p prompts] [template]",
- 0, 0,
+ 0, "",
cmd_command_prompt_init,
cmd_command_prompt_parse,
cmd_command_prompt_exec,
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c
index d0a2196a..cdde81ac 100644
--- a/cmd-confirm-before.c
+++ b/cmd-confirm-before.c
@@ -34,7 +34,7 @@ void cmd_confirm_before_free(void *);
const struct cmd_entry cmd_confirm_before_entry = {
"confirm-before", "confirm",
CMD_TARGET_CLIENT_USAGE " command",
- CMD_ARG1, 0,
+ CMD_ARG1, "",
cmd_confirm_before_init,
cmd_target_parse,
cmd_confirm_before_exec,
diff --git a/cmd-copy-buffer.c b/cmd-copy-buffer.c
index 98166c4b..3a6a441e 100644
--- a/cmd-copy-buffer.c
+++ b/cmd-copy-buffer.c
@@ -43,7 +43,7 @@ struct cmd_copy_buffer_data {
const struct cmd_entry cmd_copy_buffer_entry = {
"copy-buffer", "copyb",
"[-a src-index] [-b dst-index] [-s src-session] [-t dst-session]",
- 0, 0,
+ 0, "",
cmd_copy_buffer_init,
cmd_copy_buffer_parse,
cmd_copy_buffer_exec,
diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c
index fda19efb..48cdd656 100644
--- a/cmd-copy-mode.c
+++ b/cmd-copy-mode.c
@@ -30,7 +30,7 @@ int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_copy_mode_entry = {
"copy-mode", NULL,
"[-u] " CMD_TARGET_PANE_USAGE,
- 0, CMD_CHFLAG('u'),
+ 0, "u",
cmd_copy_mode_init,
cmd_target_parse,
cmd_copy_mode_exec,
@@ -48,7 +48,7 @@ cmd_copy_mode_init(struct cmd *self, int key)
switch (key) {
case KEYC_PPAGE:
- data->chflags |= CMD_CHFLAG('u');
+ cmd_set_flag(&data->chflags, 'u');
break;
}
}
@@ -63,7 +63,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
window_pane_set_mode(wp, &window_copy_mode);
- if (wp->mode == &window_copy_mode && data->chflags & CMD_CHFLAG('u'))
+ if (wp->mode == &window_copy_mode && cmd_check_flag(data->chflags, 'u'))
window_copy_pageup(wp);
return (0);
diff --git a/cmd-delete-buffer.c b/cmd-delete-buffer.c
index b193438c..1a5b6d82 100644
--- a/cmd-delete-buffer.c
+++ b/cmd-delete-buffer.c
@@ -31,7 +31,7 @@ int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_delete_buffer_entry = {
"delete-buffer", "deleteb",
CMD_BUFFER_SESSION_USAGE,
- 0, 0,
+ 0, "",
cmd_buffer_init,
cmd_buffer_parse,
cmd_delete_buffer_exec,
diff --git a/cmd-detach-client.c b/cmd-detach-client.c
index dd480226..4903281f 100644
--- a/cmd-detach-client.c
+++ b/cmd-detach-client.c
@@ -29,7 +29,7 @@ int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_detach_client_entry = {
"detach-client", "detach",
CMD_TARGET_CLIENT_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_detach_client_exec,
diff --git a/cmd-display-message.c b/cmd-display-message.c
index 71421ea2..1ff5718b 100644
--- a/cmd-display-message.c
+++ b/cmd-display-message.c
@@ -31,7 +31,7 @@ int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_display_message_entry = {
"display-message", "display",
CMD_TARGET_CLIENT_USAGE " [message]",
- CMD_ARG01, 0,
+ CMD_ARG01, "",
cmd_target_init,
cmd_target_parse,
cmd_display_message_exec,
diff --git a/cmd-display-panes.c b/cmd-display-panes.c
index 141e3436..42ecbb9b 100644
--- a/cmd-display-panes.c
+++ b/cmd-display-panes.c
@@ -29,7 +29,7 @@ int cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_display_panes_entry = {
"display-panes", "displayp",
CMD_TARGET_CLIENT_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_display_panes_exec,
diff --git a/cmd-down-pane.c b/cmd-down-pane.c
index 242c6ac3..a0f771eb 100644
--- a/cmd-down-pane.c
+++ b/cmd-down-pane.c
@@ -29,7 +29,7 @@ int cmd_down_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_down_pane_entry = {
"down-pane", "downp",
CMD_TARGET_WINDOW_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_down_pane_exec,
diff --git a/cmd-find-window.c b/cmd-find-window.c
index 0a1c38da..49e29337 100644
--- a/cmd-find-window.c
+++ b/cmd-find-window.c
@@ -34,7 +34,7 @@ void cmd_find_window_callback(void *, int);
const struct cmd_entry cmd_find_window_entry = {
"find-window", "findw",
CMD_TARGET_WINDOW_USAGE " match-string",
- CMD_ARG1, 0,
+ CMD_ARG1, "",
cmd_target_init,
cmd_target_parse,
cmd_find_window_exec,
diff --git a/cmd-generic.c b/cmd-generic.c
index 89dc2e25..59d9bbb7 100644
--- a/cmd-generic.c
+++ b/cmd-generic.c
@@ -23,8 +23,8 @@
#include "tmux.h"
-int cmd_getopt(int, char **, const char *, uint64_t);
-int cmd_flags(int, uint64_t, uint64_t *);
+int cmd_getopt(int, char **, const char *, const char *);
+int cmd_parse_flags(int, const char *, uint64_t *);
size_t cmd_print_flags(char *, size_t, size_t, uint64_t);
int cmd_fill_argument(int, char **, char **, int, char **);
@@ -36,51 +36,53 @@ cmd_prarg(char *buf, size_t len, const char *prefix, char *arg)
return (xsnprintf(buf, len, "%s%s", prefix, arg));
}
-/* Prepend flags from chflags onto flagstr and call getopt. */
+/* Append two flag strings together and call getopt. */
int
-cmd_getopt(int argc, char **argv, const char *flagstr, uint64_t chflags)
+cmd_getopt(int argc, char **argv, const char *flagstr, const char *chflagstr)
{
- u_char ch;
- char buf[128];
- size_t len, off;
-
- *buf = '\0';
+ char tmp[BUFSIZ];
- len = sizeof buf;
- off = 0;
+ if (strlcpy(tmp, flagstr, sizeof tmp) >= sizeof tmp)
+ fatalx("strlcpy overflow");
+ if (strlcat(tmp, chflagstr, sizeof tmp) >= sizeof tmp)
+ fatalx("strlcat overflow");
+ return (getopt(argc, argv, tmp));
+}
- for (ch = 0; ch < 26; ch++) {
- if (chflags & CMD_CHFLAG('a' + ch))
- off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
- if (chflags & CMD_CHFLAG('A' + ch))
- off += xsnprintf(buf + off, len - off, "%c", 'A' + ch);
- }
-
- strlcat(buf, flagstr, sizeof buf);
+/* Return if flag character is set. */
+int
+cmd_check_flag(uint64_t chflags, int flag)
+{
+ if (flag >= 'A' && flag <= 'Z')
+ flag = 26 + flag - 'A';
+ else if (flag >= 'a' && flag <= 'z')
+ flag = flag - 'a';
+ else
+ return (0);
+ return ((chflags & (1ULL << flag)) != 0);
+}
- return (getopt(argc, argv, buf));
+/* Set flag character. */
+void
+cmd_set_flag(uint64_t *chflags, int flag)
+{
+ if (flag >= 'A' && flag <= 'Z')
+ flag = 26 + flag - 'A';
+ else if (flag >= 'a' && flag <= 'z')
+ flag = flag - 'a';
+ else
+ return;
+ (*chflags) |= (1ULL << flag);
}
-/*
- * If this option is expected (in ichflags), set it in ochflags, otherwise
- * return -1.
- */
+/* If this option is expected, set it in chflags, otherwise return -1. */
int
-cmd_flags(int opt, uint64_t ichflags, uint64_t *ochflags)
+cmd_parse_flags(int opt, const char *chflagstr, uint64_t *chflags)
{
- u_char ch;
-
- for (ch = 0; ch < 26; ch++) {
- if (opt == 'a' + ch && ichflags & CMD_CHFLAG(opt)) {
- (*ochflags) |= CMD_CHFLAG(opt);
- return (0);
- }
- if (opt == 'A' + ch && ichflags & CMD_CHFLAG(opt)) {
- (*ochflags) |= CMD_CHFLAG(opt);
- return (0);
- }
- }
- return (-1);
+ if (strchr(chflagstr, opt) == NULL)
+ return (-1);
+ cmd_set_flag(chflags, opt);
+ return (0);
}
/* Print the flags supported in chflags. */
@@ -95,9 +97,9 @@ cmd_print_flags(char *buf, size_t len, size_t off, uint64_t chflags)
off += xsnprintf(buf + off, len - off, " -");
for (ch = 0; ch < 26; ch++) {
- if (chflags & CMD_CHFLAG('a' + ch))
+ if (cmd_check_flag(chflags, 'a' + ch))
off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
- if (chflags & CMD_CHFLAG('A' + ch))
+ if (cmd_check_flag(chflags, 'A' + ch))
off += xsnprintf(buf + off, len - off, "%c", 'A' + ch);
}
return (off - boff);
@@ -170,7 +172,7 @@ cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause)
data = self->data;
while ((opt = cmd_getopt(argc, argv, "t:", entry->chflags)) != -1) {
- if (cmd_flags(opt, entry->chflags, &data->chflags) == 0)
+ if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
continue;
switch (opt) {
case 't':
@@ -253,7 +255,7 @@ cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause)
data = self->data;
while ((opt = cmd_getopt(argc, argv, "s:t:", entry->chflags)) != -1) {
- if (cmd_flags(opt, entry->chflags, &data->chflags) == 0)
+ if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
continue;
switch (opt) {
case 's':
@@ -345,7 +347,7 @@ cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
data = self->data;
while ((opt = cmd_getopt(argc, argv, "b:t:", entry->chflags)) != -1) {
- if (cmd_flags(opt, entry->chflags, &data->chflags) == 0)
+ if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
continue;
switch (opt) {
case 'b':
diff --git a/cmd-has-session.c b/cmd-has-session.c
index f279a730..00f171b7 100644
--- a/cmd-has-session.c
+++ b/cmd-has-session.c
@@ -29,7 +29,7 @@ int cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_has_session_entry = {
"has-session", "has",
CMD_TARGET_SESSION_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_has_session_exec,
diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index 82da814a..1779486a 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -36,7 +36,7 @@ void cmd_if_shell_free(void *);
const struct cmd_entry cmd_if_shell_entry = {
"if-shell", "if",
"shell-command command",
- CMD_ARG2, 0,
+ CMD_ARG2, "",
cmd_target_init,
cmd_target_parse,
cmd_if_shell_exec,
diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c
index 351ef0c8..c48e4d4e 100644
--- a/