aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2014-10-21 07:11:44 +0100
committerThomas Adam <thomas@xteddy.org>2014-10-21 07:11:44 +0100
commit562af864bd8ab06c416075b5742ce3bbcf6d0610 (patch)
tree2c3900dd6b284aa52441c3fde9dfdf8383d87b54
parentb6aef2490f086f3404f439308bb1746ec5134e9a (diff)
parent0a1a88d63caf3a0e8b4440686e73e1f0f690e03c (diff)
downloadrtmux-562af864bd8ab06c416075b5742ce3bbcf6d0610.tar.gz
rtmux-562af864bd8ab06c416075b5742ce3bbcf6d0610.tar.bz2
rtmux-562af864bd8ab06c416075b5742ce3bbcf6d0610.zip
Merge branch 'obsd-master'
Conflicts: Makefile cmd-list-commands.c cmd-suspend-client.c job.c tmux.h xmalloc.c
-rw-r--r--Makefile.am3
-rw-r--r--arguments.c1
-rw-r--r--array.h4
-rw-r--r--client.c13
-rw-r--r--cmd-attach-session.c1
-rw-r--r--cmd-bind-key.c1
-rw-r--r--cmd-break-pane.c3
-rw-r--r--cmd-capture-pane.c3
-rw-r--r--cmd-choose-buffer.c4
-rw-r--r--cmd-choose-client.c7
-rw-r--r--cmd-choose-tree.c12
-rw-r--r--cmd-clear-history.c1
-rw-r--r--cmd-clock-mode.c1
-rw-r--r--cmd-command-prompt.c30
-rw-r--r--cmd-confirm-before.c22
-rw-r--r--cmd-copy-mode.c10
-rw-r--r--cmd-delete-buffer.c1
-rw-r--r--cmd-detach-client.c18
-rw-r--r--cmd-display-message.c6
-rw-r--r--cmd-display-panes.c1
-rw-r--r--cmd-find-window.c6
-rw-r--r--cmd-has-session.c1
-rw-r--r--cmd-if-shell.c1
-rw-r--r--cmd-join-pane.c17
-rw-r--r--cmd-kill-pane.c1
-rw-r--r--cmd-kill-server.c2
-rw-r--r--cmd-kill-session.c1
-rw-r--r--cmd-kill-window.c1
-rw-r--r--cmd-link-window.c1
-rw-r--r--cmd-list-buffers.c4
-rw-r--r--cmd-list-clients.c6
-rw-r--r--cmd-list-commands.c54
-rw-r--r--cmd-list-keys.c33
-rw-r--r--cmd-list-panes.c1
-rw-r--r--cmd-list-sessions.c9
-rw-r--r--cmd-list-windows.c17
-rw-r--r--cmd-load-buffer.c1
-rw-r--r--cmd-lock-server.c3
-rw-r--r--cmd-move-window.c1
-rw-r--r--cmd-new-session.c17
-rw-r--r--cmd-new-window.c3
-rw-r--r--cmd-paste-buffer.c1
-rw-r--r--cmd-pipe-pane.c1
-rw-r--r--cmd-queue.c4
-rw-r--r--cmd-refresh-client.c1
-rw-r--r--cmd-rename-session.c1
-rw-r--r--cmd-rename-window.c1
-rw-r--r--cmd-resize-pane.c48
-rw-r--r--cmd-respawn-pane.c1
-rw-r--r--cmd-respawn-window.c1
-rw-r--r--cmd-rotate-window.c10
-rw-r--r--cmd-run-shell.c1
-rw-r--r--cmd-save-buffer.c4
-rw-r--r--cmd-select-layout.c29
-rw-r--r--cmd-select-pane.c19
-rw-r--r--cmd-select-window.c19
-rw-r--r--cmd-send-keys.c2
-rw-r--r--cmd-set-buffer.c3
-rw-r--r--cmd-set-environment.c1
-rw-r--r--cmd-set-option.c2
-rw-r--r--cmd-show-environment.c1
-rw-r--r--cmd-show-messages.c2
-rw-r--r--cmd-show-options.c2
-rw-r--r--cmd-source-file.c1
-rw-r--r--cmd-split-window.c12
-rw-r--r--cmd-string.c19
-rw-r--r--cmd-suspend-client.c55
-rw-r--r--cmd-swap-pane.c12
-rw-r--r--cmd-swap-window.c1
-rw-r--r--cmd-switch-client.c19
-rw-r--r--cmd-unbind-key.c1
-rw-r--r--cmd-unlink-window.c1
-rw-r--r--cmd-wait-for.c1
-rw-r--r--cmd.c99
-rw-r--r--control.c2
-rw-r--r--format.c9
-rw-r--r--grid.c15
-rw-r--r--input.c4
-rw-r--r--job.c1
-rw-r--r--key-bindings.c180
-rw-r--r--log.c6
-rw-r--r--options.c2
-rw-r--r--osdep-cygwin.c2
-rw-r--r--osdep-linux.c3
-rw-r--r--paste.c2
-rw-r--r--screen-write.c28
-rw-r--r--screen.c10
-rw-r--r--server-client.c1
-rw-r--r--server-fn.c2
-rw-r--r--signal.c2
-rw-r--r--status.c15
-rw-r--r--style.c2
-rw-r--r--tmux.117
-rw-r--r--tmux.c7
-rw-r--r--tmux.h126
-rw-r--r--tty-acs.c2
-rw-r--r--utf8.c8
-rw-r--r--window-choose.c2
-rw-r--r--window-copy.c18
-rw-r--r--xmalloc.c26
100 files changed, 432 insertions, 757 deletions
diff --git a/Makefile.am b/Makefile.am
index 04107abd..81ef1b25 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -82,7 +82,6 @@ dist_tmux_SOURCES = \
cmd-display-message.c \
cmd-display-panes.c \
cmd-find-window.c \
- cmd-has-session.c \
cmd-if-shell.c \
cmd-join-pane.c \
cmd-kill-pane.c \
@@ -92,7 +91,6 @@ dist_tmux_SOURCES = \
cmd-link-window.c \
cmd-list-buffers.c \
cmd-list-clients.c \
- cmd-list-commands.c \
cmd-list-keys.c \
cmd-list-panes.c \
cmd-list-sessions.c \
@@ -128,7 +126,6 @@ dist_tmux_SOURCES = \
cmd-source-file.c \
cmd-split-window.c \
cmd-string.c \
- cmd-suspend-client.c \
cmd-swap-pane.c \
cmd-swap-window.c \
cmd-switch-client.c \
diff --git a/arguments.c b/arguments.c
index fd656b14..98a4a06c 100644
--- a/arguments.c
+++ b/arguments.c
@@ -18,6 +18,7 @@
#include <sys/types.h>
+#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
diff --git a/array.h b/array.h
index 11e963bc..2c70c310 100644
--- a/array.h
+++ b/array.h
@@ -39,10 +39,10 @@
fatalx("size too big"); \
if ((a)->space == 0) { \
(a)->space = ARRAY_INITIALSPACE(a); \
- (a)->list = xrealloc((a)->list, 1, (a)->space); \
+ (a)->list = xrealloc((a)->list, (a)->space); \
} \
while ((a)->space <= ((a)->num + (n)) * ARRAY_ITEMSIZE(a)) { \
- (a)->list = xrealloc((a)->list, 2, (a)->space); \
+ (a)->list = xreallocarray((a)->list, 2, (a)->space); \
(a)->space *= 2; \
} \
} while (0)
diff --git a/client.c b/client.c
index 6ab53e4f..48cce926 100644
--- a/client.c
+++ b/client.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <event.h>
#include <fcntl.h>
+#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -437,15 +438,11 @@ client_signal(int sig, unused short events, unused void *data)
struct sigaction sigact;
int status;
- if (!client_attached) {
- switch (sig) {
- case SIGCHLD:
- waitpid(WAIT_ANY, &status, WNOHANG);
- break;
- case SIGTERM:
+ if (sig == SIGCHLD)
+ waitpid(WAIT_ANY, &status, WNOHANG);
+ else if (!client_attached) {
+ if (sig == SIGTERM)
event_loopexit(NULL);
- break;
- }
} else {
switch (sig) {
case SIGHUP:
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index 17c932e6..c2bede2e 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -37,7 +37,6 @@ const struct cmd_entry cmd_attach_session_entry = {
"c:drt:", 0, 0,
"[-dr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
CMD_CANTNEST|CMD_STARTSERVER,
- NULL,
cmd_attach_session_exec
};
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index 7e7975f7..8ac2b001 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -36,7 +36,6 @@ const struct cmd_entry cmd_bind_key_entry = {
"cnrt:", 1, -1,
"[-cnr] [-t mode-table] key command [arguments]",
0,
- NULL,
cmd_bind_key_exec
};
diff --git a/cmd-break-pane.c b/cmd-break-pane.c
index fe7891e9..9a4b5cb6 100644
--- a/cmd-break-pane.c
+++ b/cmd-break-pane.c
@@ -26,6 +26,8 @@
* Break pane off into a window.
*/
+#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
+
enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_break_pane_entry = {
@@ -33,7 +35,6 @@ const struct cmd_entry cmd_break_pane_entry = {
"dPF:t:", 0, 0,
"[-dP] [-F format] " CMD_TARGET_PANE_USAGE,
0,
- NULL,
cmd_break_pane_exec
};
diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c
index 0efe1cd0..776737e1 100644
--- a/cmd-capture-pane.c
+++ b/cmd-capture-pane.c
@@ -41,14 +41,13 @@ const struct cmd_entry cmd_capture_pane_entry = {
"[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] [-S start-line]"
CMD_TARGET_PANE_USAGE,
0,
- NULL,
cmd_capture_pane_exec
};
char *
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
{
- buf = xrealloc(buf, 1, *len + linelen + 1);
+ buf = xrealloc(buf, *len + linelen + 1);
memcpy(buf + *len, line, linelen);
*len += linelen;
return (buf);
diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c
index 6b146fad..2bc3db64 100644
--- a/cmd-choose-buffer.c
+++ b/cmd-choose-buffer.c
@@ -27,6 +27,9 @@
* Enter choice mode to choose a buffer.
*/
+#define CHOOSE_BUFFER_TEMPLATE \
+ "#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}"
+
enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_choose_buffer_entry = {
@@ -34,7 +37,6 @@ const struct cmd_entry cmd_choose_buffer_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
- NULL,
cmd_choose_buffer_exec
};
diff --git a/cmd-choose-client.c b/cmd-choose-client.c
index 93671987..827e08d6 100644
--- a/cmd-choose-client.c
+++ b/cmd-choose-client.c
@@ -27,6 +27,12 @@
* Enter choice mode to choose a client.
*/
+#define CHOOSE_CLIENT_TEMPLATE \
+ "#{client_tty}: #{session_name} " \
+ "[#{client_width}x#{client_height} #{client_termname}]" \
+ "#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
+ "(last used #{client_activity_string})"
+
enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_q *);
void cmd_choose_client_callback(struct window_choose_data *);
@@ -36,7 +42,6 @@ const struct cmd_entry cmd_choose_client_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
- NULL,
cmd_choose_client_exec
};
diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c
index be3bd69a..9349d765 100644
--- a/cmd-choose-tree.c
+++ b/cmd-choose-tree.c
@@ -32,6 +32,15 @@
* Enter choice mode to choose a session and/or window.
*/
+#define CHOOSE_TREE_SESSION_TEMPLATE \
+ "#{session_name}: #{session_windows} windows" \
+ "#{?session_grouped, (group ,}" \
+ "#{session_group}#{?session_grouped,),}" \
+ "#{?session_attached, (attached),}"
+#define CHOOSE_TREE_WINDOW_TEMPLATE \
+ "#{window_index}: #{window_name}#{window_flags} " \
+ "\"#{pane_title}\""
+
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_choose_tree_entry = {
@@ -40,7 +49,6 @@ const struct cmd_entry cmd_choose_tree_entry = {
"[-suw] [-b session-template] [-c window template] [-S format] " \
"[-W format] " CMD_TARGET_WINDOW_USAGE,
0,
- NULL,
cmd_choose_tree_exec
};
@@ -49,7 +57,6 @@ const struct cmd_entry cmd_choose_session_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
- NULL,
cmd_choose_tree_exec
};
@@ -58,7 +65,6 @@ const struct cmd_entry cmd_choose_window_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
0,
- NULL,
cmd_choose_tree_exec
};
diff --git a/cmd-clear-history.c b/cmd-clear-history.c
index cce3ea18..225a174f 100644
--- a/cmd-clear-history.c
+++ b/cmd-clear-history.c
@@ -31,7 +31,6 @@ const struct cmd_entry cmd_clear_history_entry = {
"t:", 0, 0,
CMD_TARGET_PANE_USAGE,
0,
- NULL,
cmd_clear_history_exec
};
diff --git a/cmd-clock-mode.c b/cmd-clock-mode.c
index 50e4ab8b..35bc14da 100644
--- a/cmd-clock-mode.c
+++ b/cmd-clock-mode.c
@@ -31,7 +31,6 @@ const struct cmd_entry cmd_clock_mode_entry = {
"t:", 0, 0,
CMD_TARGET_PANE_USAGE,
0,
- NULL,
cmd_clock_mode_exec
};
diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c
index 759d578b..1f43169d 100644
--- a/cmd-command-prompt.c
+++ b/cmd-command-prompt.c
@@ -29,7 +29,6 @@
* Prompt for command in client.
*/
-void cmd_command_prompt_key_binding(struct cmd *, int);
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *);
int cmd_command_prompt_callback(void *, const char *);
@@ -40,7 +39,6 @@ const struct cmd_entry cmd_command_prompt_entry = {
"I:p:t:", 0, 1,
"[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " [template]",
0,
- cmd_command_prompt_key_binding,
cmd_command_prompt_exec
};
@@ -54,34 +52,6 @@ struct cmd_command_prompt_cdata {
int idx;
};
-void
-cmd_command_prompt_key_binding(struct cmd *self, int key)
-{
- switch (key) {
- case '$':
- self->args = args_create(1, "rename-session '%%'");
- args_set(self->args, 'I', "#S");
- break;
- case ',':
- self->args = args_create(1, "rename-window '%%'");
- args_set(self->args, 'I', "#W");
- break;
- case '.':
- self->args = args_create(1, "move-window -t '%%'");
- break;
- case 'f':
- self->args = args_create(1, "find-window '%%'");
- break;
- case '\'':
- self->args = args_create(1, "select-window -t ':%%'");
- args_set(self->args, 'p', "index");
- break;
- default:
- self->args = args_create(0);
- break;
- }
-}
-
enum cmd_retval
cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c
index 9266721f..4b8d0421 100644
--- a/cmd-confirm-before.c
+++ b/cmd-confirm-before.c
@@ -16,6 +16,8 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
+
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@@ -26,7 +28,6 @@
* Asks for confirmation before executing a command.
*/
-void cmd_confirm_before_key_binding(struct cmd *, int);
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *);
int cmd_confirm_before_callback(void *, const char *);
@@ -37,7 +38,6 @@ const struct cmd_entry cmd_confirm_before_entry = {
"p:t:", 1, 1,
"[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
0,
- cmd_confirm_before_key_binding,
cmd_confirm_before_exec
};
@@ -46,24 +46,6 @@ struct cmd_confirm_before_data {
struct client *client;
};
-void
-cmd_confirm_before_key_binding(struct cmd *self, int key)
-{
- switch (key) {
- case '&':
- self->args = args_create(1, "kill-window");
- args_set(self->args, 'p', "kill-window #W? (y/n)");
- break;
- case 'x':
- self->args = args_create(1, "kill-pane");
- args_set(self->args, 'p', "kill-pane #P? (y/n)");
- break;
- default:
- self->args = args_create(0);
- break;
- }
-}
-
enum cmd_retval
cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c
index f11c7aff..52b98896 100644
--- a/cmd-copy-mode.c
+++ b/cmd-copy-mode.c
@@ -24,7 +24,6 @@
* Enter copy mode.
*/
-void cmd_copy_mode_key_binding(struct cmd *, int);
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_copy_mode_entry = {
@@ -32,18 +31,9 @@ const struct cmd_entry cmd_copy_mode_entry = {
"t:u", 0, 0,
"[-u] " CMD_TARGET_PANE_USAGE,
0,
- cmd_copy_mode_key_binding,
cmd_copy_mode_exec
};
-void
-cmd_copy_mode_key_binding(struct cmd *self, int key)
-{
- self->args = args_create(0);
- if (key == KEYC_PPAGE)
- args_set(self->args, 'u', NULL);
-}
-
enum cmd_retval
cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-delete-buffer.c b/cmd-delete-buffer.c
index 9957de66..d22d09b1 100644
--- a/cmd-delete-buffer.c
+++ b/cmd-delete-buffer.c
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_delete_buffer_entry = {
"b:", 0, 0,
CMD_BUFFER_USAGE,
0,
- NULL,
cmd_delete_buffer_exec
};
diff --git a/cmd-detach-client.c b/cmd-detach-client.c
index fe4b2397..c5a73517 100644
--- a/cmd-detach-client.c
+++ b/cmd-detach-client.c
@@ -33,7 +33,14 @@ const struct cmd_entry cmd_detach_client_entry = {
"as:t:P", 0, 0,
"[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
CMD_READONLY,
- NULL,
+ cmd_detach_client_exec
+};
+
+const struct cmd_entry cmd_suspend_client_entry = {
+ "suspend-client", "suspendc",
+ "t:", 0, 0,
+ CMD_TARGET_CLIENT_USAGE,
+ 0,
cmd_detach_client_exec
};
@@ -46,6 +53,15 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
enum msgtype msgtype;
u_int i;
+ if (self->entry == &cmd_suspend_client_entry) {
+ if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
+ tty_stop_tty(&c->tty);
+ c->flags |= CLIENT_SUSPENDED;
+ server_write_client(c, MSG_SUSPEND, NULL, 0);
+ return (CMD_RETURN_NORMAL);
+ }
+
if (args_has(args, 'P'))
msgtype = MSG_DETACHKILL;
else
diff --git a/cmd-display-message.c b/cmd-display-message.c
index 78752f86..da73fba6 100644
--- a/cmd-display-message.c
+++ b/cmd-display-message.c
@@ -27,6 +27,11 @@
* Displays a message in the status line.
*/
+#define DISPLAY_MESSAGE_TEMPLATE \
+ "[#{session_name}] #{window_index}:" \
+ "#{window_name}, current pane #{pane_index} " \
+ "- (%H:%M %d-%b-%y)"
+
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_display_message_entry = {
@@ -35,7 +40,6 @@ const struct cmd_entry cmd_display_message_entry = {
"[-p] [-c target-client] [-F format] " CMD_TARGET_PANE_USAGE
" [message]",
0,
- NULL,
cmd_display_message_exec
};
diff --git a/cmd-display-panes.c b/cmd-display-panes.c
index c137feef..12551d35 100644
--- a/cmd-display-panes.c
+++ b/cmd-display-panes.c
@@ -31,7 +31,6 @@ const struct cmd_entry cmd_display_panes_entry = {
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
- NULL,
cmd_display_panes_exec
};
diff --git a/cmd-find-window.c b/cmd-find-window.c
index 39a279b5..7a32a7af 100644
--- a/cmd-find-window.c
+++ b/cmd-find-window.c
@@ -28,6 +28,11 @@
* Find window containing text.
*/
+#define FIND_WINDOW_TEMPLATE \
+ "#{window_index}: #{window_name} " \
+ "[#{window_width}x#{window_height}] " \
+ "(#{window_panes} panes) #{window_find_matches}"
+
enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_q *);
void cmd_find_window_callback(struct window_choose_data *);
@@ -47,7 +52,6 @@ const struct cmd_entry cmd_find_window_entry = {
"F:CNt:T", 1, 4,
"[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
0,
- NULL,
cmd_find_window_exec
};
diff --git a/cmd-has-session.c b/cmd-has-session.c
index 38a92f61..8dcd2d49 100644
--- a/cmd-has-session.c
+++ b/cmd-has-session.c
@@ -31,7 +31,6 @@ const struct cmd_entry cmd_has_session_entry = {
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
- NULL,
cmd_has_session_exec
};
diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index 9b6dcf30..233fcee5 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -40,7 +40,6 @@ const struct cmd_entry cmd_if_shell_entry = {
"bt:", 2, 3,
"[-b] " CMD_TARGET_PANE_USAGE " shell-command command [command]",
0,
- NULL,
cmd_if_shell_exec
};
diff --git a/cmd-join-pane.c b/cmd-join-pane.c
index 000fdba9..32cdb31a 100644
--- a/cmd-join-pane.c
+++ b/cmd-join-pane.c
@@ -28,7 +28,6 @@
* Join or move a pane into another (like split/swap/kill).
*/
-void cmd_join_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *);
enum cmd_retval join_pane(struct cmd *, struct cmd_q *, int);
@@ -38,7 +37,6 @@ const struct cmd_entry cmd_join_pane_entry = {
"bdhvp:l:s:t:", 0, 0,
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
0,
- cmd_join_pane_key_binding,
cmd_join_pane_exec
};
@@ -47,24 +45,9 @@ const struct cmd_entry cmd_move_pane_entry = {
"bdhvp:l:s:t:", 0, 0,
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
0,
- NULL,
cmd_join_pane_exec
};
-void
-cmd_join_pane_key_binding(struct cmd *self, int key)
-{
- switch (key) {
- case '%':
- self->args = args_create(0);
- args_set(self->args, 'h', NULL);
- break;
- default:
- self->args = args_create(0);
- break;
- }
-}
-
enum cmd_retval
cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c
index bf486eb3..f6ee4417 100644
--- a/cmd-kill-pane.c
+++ b/cmd-kill-pane.c
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_kill_pane_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_PANE_USAGE,
0,
- NULL,
cmd_kill_pane_exec
};
diff --git a/cmd-kill-server.c b/cmd-kill-server.c
index 03016869..dca4198b 100644
--- a/cmd-kill-server.c
+++ b/cmd-kill-server.c
@@ -34,7 +34,6 @@ const struct cmd_entry cmd_kill_server_entry = {
"", 0, 0,
"",
0,
- NULL,
cmd_kill_server_exec
};
@@ -43,7 +42,6 @@ const struct cmd_entry cmd_start_server_entry = {
"", 0, 0,
"",
CMD_STARTSERVER,
- NULL,
cmd_kill_server_exec
};
diff --git a/cmd-kill-session.c b/cmd-kill-session.c
index 54b0c31b..030276e2 100644
--- a/cmd-kill-session.c
+++ b/cmd-kill-session.c
@@ -34,7 +34,6 @@ const struct cmd_entry cmd_kill_session_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_SESSION_USAGE,
0,
- NULL,
cmd_kill_session_exec
};
diff --git a/cmd-kill-window.c b/cmd-kill-window.c
index ca8fe3d6..fc1c33eb 100644
--- a/cmd-kill-window.c
+++ b/cmd-kill-window.c
@@ -31,7 +31,6 @@ const struct cmd_entry cmd_kill_window_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_WINDOW_USAGE,
0,
- NULL,
cmd_kill_window_exec
};
diff --git a/cmd-link-window.c b/cmd-link-window.c
index d94eb38a..ebfdf5dc 100644
--- a/cmd-link-window.c
+++ b/cmd-link-window.c
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_link_window_entry = {
"dks:t:", 0, 0,
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
0,
- NULL,
cmd_link_window_exec
};
diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c
index c5a6e322..c10c09dc 100644
--- a/cmd-list-buffers.c
+++ b/cmd-list-buffers.c
@@ -27,6 +27,9 @@
* List paste buffers.
*/
+#define LIST_BUFFERS_TEMPLATE \
+ "#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\""
+
enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_buffers_entry = {
@@ -34,7 +37,6 @@ const struct cmd_entry cmd_list_buffers_entry = {
"F:", 0, 0,
"[-F format]",
0,
- NULL,
cmd_list_buffers_exec
};
diff --git a/cmd-list-clients.c b/cmd-list-clients.c
index 904ec005..ccd89e18 100644
--- a/cmd-list-clients.c
+++ b/cmd-list-clients.c
@@ -28,6 +28,11 @@
* List all clients.
*/
+#define LIST_CLIENTS_TEMPLATE \
+ "#{client_tty}: #{session_name} " \
+ "[#{client_width}x#{client_height} #{client_termname}]" \
+ "#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"
+
enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_clients_entry = {
@@ -35,7 +40,6 @@ const struct cmd_entry cmd_list_clients_entry = {
"F:t:", 0, 0,
"[-F format] " CMD_TARGET_SESSION_USAGE,
CMD_READONLY,
- NULL,
cmd_list_clients_exec
};
diff --git a/cmd-list-commands.c b/cmd-list-commands.c
deleted file mode 100644
index 06e48378..00000000
--- a/cmd-list-commands.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/* $Id$ */
-
-/*
- * 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 "tmux.h"
-
-/*
- * List all commands with usages.
- */
-
-enum cmd_retval cmd_list_commands_exec(struct cmd *, struct cmd_q *);
-
-const struct cmd_entry cmd_list_commands_entry = {
- "list-commands", "lscm",
- "", 0, 0,
- "",
- 0,
- NULL,
- cmd_list_commands_exec
-};
-
-enum cmd_retval
-cmd_list_commands_exec(unused struct cmd *self, struct cmd_q *cmdq)
-{
- const struct cmd_entry **entryp;
-
- for (entryp = cmd_table; *entryp != NULL; entryp++) {
- if ((*entryp)->alias != NULL) {
- cmdq_print(cmdq, "%s (%s) %s", (*entryp)->name,
- (*entryp)->alias, (*entryp)->usage);
- } else {
- cmdq_print(cmdq, "%s %s", (*entryp)->name,
- (*entryp)->usage);
- }
- }
-
- return (CMD_RETURN_NORMAL);
-}
diff --git a/cmd-list-keys.c b/cmd-list-keys.c
index 615c5ce1..d609036b 100644
--- a/cmd-list-keys.c
+++ b/cmd-list-keys.c
@@ -27,14 +27,23 @@
*/
enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *);
+
enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *);
+enum cmd_retval cmd_list_keys_commands(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_keys_entry = {
"list-keys", "lsk",
"t:", 0, 0,
"[-t key-table]",
0,
- NULL,
+ cmd_list_keys_exec
+};
+
+const struct cmd_entry cmd_list_commands_entry = {
+ "list-commands", "lscm",
+ "", 0, 0,
+ "",
+ 0,
cmd_list_keys_exec
};
@@ -48,6 +57,9 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
size_t used;
int width, keywidth;
+ if (self->entry == &cmd_list_commands_entry)
+ return (cmd_list_keys_commands(self, cmdq));
+
if (args_has(args, 't'))
return (cmd_list_keys_table(self, cmdq));
@@ -148,3 +160,22 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
}
+
+enum cmd_retval
+cmd_list_keys_commands(unused struct cmd *self, struct cmd_q *cmdq)
+{
+ const struct cmd_entry **entryp;
+ const struct cmd_entry *entry;
+
+ for (entryp = cmd_table; *entryp != NULL; entryp++) {
+ entry = *entryp;
+ if (entry->alias == NULL) {
+ cmdq_print(cmdq, "%s %s", entry->name, entry->usage);
+ continue;
+ }
+ cmdq_print(cmdq, "%s (%s) %s", entry->name, entry->alias,
+ entry->usage);
+ }
+
+ return (CMD_RETURN_NORMAL);
+}
diff --git a/cmd-list-panes.c b/cmd-list-panes.c
index c989eba1..b3d9bd9e 100644
--- a/cmd-list-panes.c
+++ b/cmd-list-panes.c
@@ -40,7 +40,6 @@ const struct cmd_entry cmd_list_panes_entry = {
"asF:t:", 0, 0,
"[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
0,
- NULL,
cmd_list_panes_exec
};
diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c
index a3613c87..4969eab0 100644
--- a/cmd-list-sessions.c
+++ b/cmd-list-sessions.c
@@ -28,6 +28,14 @@
* List all sessions.
*/
+#define LIST_SESSIONS_TEMPLATE \
+ "#{session_name}: #{session_windows} windows " \
+ "(created #{session_created_string}) " \
+ "[#{session_width}x#{session_height}]" \
+ "#{?session_grouped, (group ,}" \
+ "#{session_group}#{?session_grouped,),}" \
+ "#{?session_attached, (attached),}"
+
enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_sessions_entry = {
@@ -35,7 +43,6 @@ const struct cmd_entry cmd_list_sessions_entry = {
"F:", 0, 0,
"[-F format]",
0,
- NULL,
cmd_list_sessions_exec
};
diff --git a/cmd-list-windows.c b/cmd-list-windows.c
index ce122f45..223c6b2b 100644
--- a/cmd-list-windows.c
+++ b/cmd-list-windows.c
@@ -27,18 +27,29 @@
* List windows on given session.
*/
+#define LIST_WINDOWS_TEMPLATE \
+ "#{window_index}: #{window_name}#{window_flags} " \
+ "(#{window_panes} panes) " \
+ "[#{window_width}x#{window_height}] " \
+ "[layout #{window_layout}] #{window_id}" \
+ "#{?window_active, (active),}";
+#define LIST_WINDOWS_WITH_SESSION_TEMPLATE \
+ "#{session_name}:" \
+ "#{window_index}: #{window_name}#{window_flags} " \
+ "(#{window_panes} panes) " \
+ "[#{window_width}x#{window_height}] "
+
enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_q *);
void cmd_list_windows_server(struct cmd *, struct cmd_q *);
-void cmd_list_windows_session(
- struct cmd *, struct session *, struct cmd_q *, int);
+void cmd_list_windows_session(struct cmd *, struct session *,
+ struct cmd_q *, int);
const struct cmd_entry cmd_list_windows_entry = {
"list-windows", "lsw",
"F:at:", 0, 0,
"[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
0,
- NULL,
cmd_list_windows_exec
};
diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c
index d6df1f60..81d198e0 100644
--- a/cmd-load-buffer.c
+++ b/cmd-load-buffer.c
@@ -39,7 +39,6 @@ const struct cmd_entry cmd_load_buffer_entry = {
"b:", 1, 1,
CMD_BUFFER_USAGE " path",
0,
- NULL,
cmd_load_buffer_exec
};
diff --git a/cmd-lock-server.c b/cmd-lock-server.c
index 5e0f6e0f..a341f5e6 100644
--- a/cmd-lock-server.c
+++ b/cmd-lock-server.c
@@ -31,7 +31,6 @@ const struct cmd_entry cmd_lock_server_entry = {
"", 0, 0,
"",
0,
- NULL,
cmd_lock_server_exec
};
@@ -40,7 +39,6 @@ const struct cmd_entry cmd_lock_session_entry = {
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
- NULL,
cmd_lock_server_exec
};
@@ -49,7 +47,6 @@ const struct cmd_entry cmd_lock_client_entry = {
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
- NULL,
cmd_lock_server_exec
};
diff --git a/cmd-move-window.c b/cmd-move-window.c
index 21606755..7867dca8 100644
--- a/cmd-move-window.c
+++ b/cmd-move-window.c
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_move_window_entry = {
"dkrs:t:", 0, 0,
"[-dkr] " CMD_SRCDST_WINDOW_USAGE,
0,
- NULL,
cmd_move_window_exec
};
diff --git a/cmd-new-session.c b/cmd-new-session.c
index b36de70a..5823e5e1 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -31,6 +31,8 @@
* Create a new session and attach to the current terminal unless -d is given.
*/
+#define NEW_SESSION_TEMPLATE "#{session_name}:"
+
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_session_entry = {
@@ -40,7 +42,14 @@ const struct cmd_entry cmd_new_session_entry = {
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
"[-y height] [command]",
CMD_STARTSERVER|CMD_CANTNEST,
- NULL,
+ cmd_new_session_exec
+};
+
+const struct cmd_entry cmd_has_session_entry = {
+ "has-session", "has",
+ "t:", 0, 0,
+ CMD_TARGET_SESSION_USAGE,
+ 0,
cmd_new_session_exec
};
@@ -62,6 +71,12 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
struct format_tree *ft;
struct environ_entry *envent;
+ if (self->entry == &cmd_has_session_entry) {
+ if (cmd_find_session(cmdq, args_get(args, 't'), 0) == NULL)
+ return (CMD_RETURN_ERROR);
+ return (CMD_RETURN_NORMAL);
+ }
+
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) {
cmdq_error(cmdq, "command or window name given with target");
return (CMD_RETURN_ERROR);
diff --git a/cmd-new-window.c b/cmd-new-window.c
index efbcbbf1..ed1ce0e5 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -30,6 +30,8 @@
* Create a new window.
*/
+#define NEW_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
+
enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_window_entry = {
@@ -38,7 +40,6 @@ const struct cmd_entry cmd_new_window_entry = {
"[-adkP] [-c start-directory] [-F format] [-n window-name] "
CMD_TARGET_WINDOW_USAGE " [command]",
0,
- NULL,
cmd_new_window_exec
};
diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c
index f6c9d0ad..1d9ceb12 100644
--- a/cmd-paste-buffer.c
+++ b/cmd-paste-buffer.c
@@ -37,7 +37,6 @@ const struct cmd_entry cmd_paste_buffer_entry = {
"db:prs:t:", 0, 0,
"[-dpr] [-s separator] " CMD_BUFFER_USAGE " " CMD_TARGET_PANE_USAGE,
0,
- NULL,
cmd_paste_buffer_exec
};
diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c
index 611ad8cf..9451938e 100644
--- a/cmd-pipe-pane.c
+++ b/cmd-pipe-pane.c
@@ -40,7 +40,6 @@ const struct cmd_entry cmd_pipe_pane_entry = {
"ot:", 0, 1,
"[-o] " CMD_TARGET_PANE_USAGE " [command]",
0,
- NULL,
cmd_pipe_pane_exec
};
diff --git a/cmd-queue.c b/cmd-queue.c
index ca9d16e2..270ad771 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -57,7 +57,7 @@ cmdq_free(struct cmd_q *cmdq)
}
/* Show message from command. */
-void printflike2
+void
cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
@@ -87,7 +87,7 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
}
/* Show error from command. */
-void printflike2
+void
cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c
index 45804fbe..edb2c6c1 100644
--- a/cmd-refresh-client.c
+++ b/cmd-refresh-client.c
@@ -31,7 +31,6 @@ const struct cmd_entry cmd_refresh_client_entry = {
"C:St:", 0, 0,
"[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
0,
- NULL,
cmd_refresh_client_exec
};
diff --git a/cmd-rename-session.c b/cmd-rename-session.c
index 4c8ae122..5d4b61ae 100644
--- a/cmd-rename-session.c
+++ b/cmd-rename-session.c
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_rename_session_entry = {
"t:", 1, 1,
CMD_TARGET_SESSION_USAGE " new-name",
0,
- NULL,
cmd_rename_session_exec
};
diff --git a/cmd-rename-window.c b/cmd-rename-window.c
index f647abb3..f77fa062 100644
--- a/cmd-rename-window.c
+++ b/cmd-rename-window.c
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_rename_window_entry = {
"t:", 1, 1,
CMD_TARGET_WINDOW_USAGE " new-name",
0,
- NULL,
cmd_rename_window_exec
};
diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c
index d31f8868..c3075edd 100644
--- a/cmd-resize-pane.c
+++ b/cmd-resize-pane.c
@@ -26,7 +26,6 @@
* Increase or decrease pane size.
*/
-void cmd_resize_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_resize_pane_entry = {
@@ -34,56 +33,9 @@ const struct cmd_entry cmd_resize_pane_entry = {
"DLRt:Ux:y:Z", 0, 1,
"[-DLRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]",
0,
- cmd_resize_pane_key_binding,
cmd_resize_pane_exec
};
-void
-cmd_resize_pane_key_binding(struct cmd *self, int key)
-{
- switch (key) {
- case KEYC_UP | KEYC_CTRL:
- self->args = args_create(0);
- args_set(self->args, 'U', NULL);
- break;
- case KEYC_DOWN | KEYC_CTRL:
- self->args = args_create(0);
- args_set(self->args, 'D', NULL);
- break;
- case KEYC_LEFT | KEYC_CTRL:
- self->args = args_create(0);
- args_set(self->args, 'L', NULL);
- break;
- case KEYC_RIGHT | KEYC_CTRL:
- self->args = args_create(0);
- args_set(self->args, 'R', NULL);
- break;
- case KEYC_UP | KEYC_ESCAPE:
- self->args = args_create(1, "5");
- args_set(self->args, 'U', NULL);
- break;
- case KEYC_DOWN | KEYC_ESCAPE:
- self->args = args_create(1, "5");
- args_set(self->args, 'D', NULL);
- break;
- case KEYC_LEFT | KEYC_ESCAPE:
- self->args = args_create(1, "5");
- args_set(self->args, 'L', NULL);
- break;
- case KEYC_RIGHT | KEYC_ESCAPE:
- self->args = args_create(1, "5");
- args_set(self->args, 'R', NULL);
- break;
- case 'z':
- self->args = args_create(0);
- args_set(self->args, 'Z', NULL);
- break;
- default:
- self->args = args_create(0);
- break;
- }
-}
-
enum cmd_retval
cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c
index f951685c..72080410 100644
--- a/cmd-respawn-pane.c
+++ b/cmd-respawn-pane.c
@@ -35,7 +35,6 @@ const struct cmd_entry cmd_respawn_pane_entry = {
"kt:", 0, -1,
"[-k] " CMD_TARGET_PANE_USAGE " [command]",
0,
- NULL,
cmd_respawn_pane_exec
};
diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c
index 307560bb..5ad8297b 100644
--- a/cmd-respawn-window.c
+++ b/cmd-respawn-window.c
@@ -34,7 +34,6 @@ const struct cmd_entry cmd_respawn_window_entry = {
"kt:", 0, -1,
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
0,
- NULL,
cmd_respawn_window_exec
};
diff --git a/cmd-rotate-window.c b/cmd-rotate-window.c
index 9f4cc751..6e44e767 100644
--- a/cmd-rotate-window.c
+++ b/cmd-rotate-window.c
@@ -24,7 +24,6 @@
* Rotate the panes in a window.
*/
-void cmd_rotate_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_rotate_window_entry = {
@@ -32,18 +31,9 @@ const struct cmd_entry cmd_rotate_window_entry = {
"Dt:U", 0, 0,
"[-DU] " CMD_TARGET_WINDOW_USAGE,
0,
- cmd_rotate_window_key_binding,
cmd_rotate_window_exec
};
-void
-cmd_rotate_window_key_binding(struct cmd *self, int key)
-{
- self->args = args_create(0);
- if (key == ('o' | KEYC_ESCAPE))
- args_set(self->args, 'D', NULL);
-}
-
enum cmd_retval
cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-run-shell.c b/cmd-run-shell.c
index a91968d0..d67ea34b 100644
--- a/cmd-run-shell.c
+++ b/cmd-run-shell.c
@@ -40,7 +40,6 @@ const struct cmd_entry cmd_run_shell_entry = {
"bt:", 1, 1,
"[-b] " CMD_TARGET_PANE_USAGE " shell-command",
0,
- NULL,
cmd_run_shell_exec
};
diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c
index 8dd52c96..2fd0e82a 100644
--- a/cmd-save-buffer.c
+++ b/cmd-save-buffer.c
@@ -38,7 +38,6 @@ const struct cmd_entry cmd_save_buffer_entry = {
"ab:", 1, 1,
"[-a] " CMD_BUFFER_USAGE " path",
0,
- NULL,
cmd_save_buffer_exec
};
@@ -47,7 +46,6 @@ const struct cmd_entry cmd_show_buffer_entry = {
"b:", 0, 0,
CMD_BUFFER_USAGE,
0,
- NULL,
cmd_save_buffer_exec
};
@@ -146,7 +144,7 @@ do_print:
size = pb->size - used;
msglen = size * 4 + 1;
- msg = xrealloc(msg, 1, msglen);
+ msg = xrealloc(msg, msglen);
strvisx(msg, start, size, VIS_OCTAL|VIS_TAB);
cmdq_print(cmdq, "%s", msg);
diff --git a/cmd-select-layout.c b/cmd-select-layout.c
index 37cd22c2..c3d2cab9 100644
--- a/cmd-select-layout.c
+++ b/cmd-select-layout.c
@@ -24,7 +24,6 @@
* Switch window to selected layout.
*/
-void cmd_select_layout_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_layout_entry = {
@@ -32,7 +31,6 @@ const struct cmd_entry cmd_select_layout_entry = {
"npt:", 0, 1,
"[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
0,
- cmd_select_layout_key_binding,
cmd_select_layout_exec
};
@@ -41,7 +39,6 @@ const struct cmd_entry cmd_next_layout_entry = {
"t:", 0, 0,
CMD_TARGET_WINDOW_USAGE,
0,
- NULL,
cmd_select_layout_exec
};
@@ -50,35 +47,9 @@ const struct cmd_entry cmd_previous_layout_entry = {
"t:", 0, 0,
CMD_TARGET_WINDOW_USAGE,
0,
- NULL,
cmd_select_layout_exec
};
-void
-cmd_select_layout_key_binding(struct cmd *self, int key)
-{
- switch (key) {
- case '1' | KEYC_ESCAPE:
- self->args = args_create(1, "even-horizontal");
- break;
- case '2' | KEYC_ESCAPE:
- self->args = args_create(1, "even-vertical");
- break;
- case '3' | KEYC_ESCAPE:
- self->args = args_create(1, "main-horizontal");
- break;
- case '4' | KEYC_ESCAPE:
- self->args = args_create(1, "main-vertical");
- break;
- case '5' | KEYC_ESCAPE:
- self->args = args_create(1, "tiled");
- break;
- default:
- self->args = args_create(0);
- break;
- }
-}
-
enum cmd_retval
cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-select-pane.c b/cmd-select-pane.c
index 639adf52..00324b99 100644
--- a/cmd-select-pane.c
+++ b/cmd-select-pane.c
@@ -24,7 +24,6 @@
* Select pane.
*/
-void cmd_select_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_pane_entry = {
@@ -32,7 +31,6 @@ const struct cmd_entry cmd_select_pane_entry = {
"DdeLlRt:U", 0, 0,
"[-DdeLlRU] " CMD_TARGET_PANE_USAGE,
0,
- cmd_select_pane_key_binding,
cmd_select_pane_exec
};
@@ -41,26 +39,9 @@ const struct cmd_entry cmd_last_pane_entry = {
"det:", 0, 0,
"[-de] " CMD_TARGET_WINDOW_USAGE,
0,
- NULL,
cmd_select_pane_exec
};
-void
-cmd_select_pane_key_binding(struct cmd *self, int key)
-{
- self->args = args_create(0);
- if (key == KEYC_UP)
- args_set(self->args, 'U', NULL);
- if (key == KEYC_DOWN)
- args_set(self->args, 'D', NULL);
- if (key == KEYC_LEFT)
- args_set(self->args, 'L', NULL);
- if (key == KEYC_RIGHT)
- args_set(self->args, 'R', NULL);
- if (key == 'o')
- args_set(self->args, 't', ":.+");
-}
-
enum cmd_retval
cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-select-window.c b/cmd-select-window.c
index 73196200..0e11c23d 100644
--- a/cmd-select-window.c
+++ b/cmd-select-window.c
@@ -26,7 +26,6 @@
* Select window by index.
*/
-void cmd_select_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_window_entry = {
@@ -34,7 +33,6 @@ const struct cmd_entry cmd_select_window_entry = {
"lnpTt:", 0, 0,
"[-lnpT] " CMD_TARGET_WINDOW_USAGE,
0,
- cmd_select_window_key_binding,
cmd_select_window_exec
};
@@ -43,7 +41,6 @@ const struct cmd_entry cmd_next_window_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_SESSION_USAGE,
0,
- cmd_select_window_key_binding,
cmd_select_window_exec
};
@@ -52,7 +49,6 @@ const struct cmd_entry cmd_previous_window_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_SESSION_USAGE,
0,
- cmd_select_window_key_binding,
cmd_select_window_exec
};
@@ -61,24 +57,9 @@ const struct cmd_entry cmd_last_window_entry = {
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
- NULL,
cmd_select_window_exec
};
-void
-cmd_select_window_key_binding(struct cmd *self, int key)
-{
- char tmp[16];
-
- self->args = args_create(0);
- if (key >= '0' && key <= '9') {
- xsnprintf(tmp, sizeof tmp, ":%d", key - '0');
- args_set(self->args, 't', tmp);
- }
- if (key == ('n' | KEYC_ESCAPE) || key == ('p' | KEYC_ESCAPE))
- args_set(self->args, 'a', NULL);
-}
-
enum cmd_retval
cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-send-keys.c b/cmd-send-keys.c
index 50cb70e2..aecfc66f 100644
--- a/cmd-send-keys.c
+++ b/cmd-send-keys.c
@@ -34,7 +34,6 @@ const struct cmd_entry cmd_send_keys_entry = {
"lRt:", 0, -1,
"[-lR] " CMD_TARGET_PANE_USAGE " key ...",
0,
- NULL,
cmd_send_keys_exec
};
@@ -43,7 +42,6 @@ const struct cmd_entry cmd_send_prefix_entry = {
"2t:", 0, 0,
"[-2] " CMD_TARGET_PANE_USAGE,
0,
- NULL,
cmd_send_keys_exec
};
diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c
index 82922279..37d3763e 100644
--- a/cmd-set-buffer.c
+++ b/cmd-set-buffer.c
@@ -34,7 +34,6 @@ const struct cmd_entry cmd_set_buffer_entry = {
"ab:n:", 0, 1,
"[-a] " CMD_BUFFER_USAGE " [-n new-buffer-name] data",
0,
- NULL,
cmd_set_buffer_exec
};
@@ -104,7 +103,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
memcpy(pdata, pb->data, psize);
}
- pdata = xrealloc(pdata, 1, psize + newsize);
+ pdata = xrealloc(pdata, psize + newsize);
memcpy(pdata + psize, args->argv[0], newsize);
psize += newsize;
diff --git a/cmd-set-environment.c b/cmd-set-environment.c
index 8d067c35..b51969fc 100644
--- a/cmd-set-environment.c
+++ b/cmd-set-environment.c
@@ -34,7 +34,6 @@ const struct cmd_entry cmd_set_environment_entry = {
"grt:u", 1, 2,
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
0,
- NULL,
cmd_set_environment_exec
};
diff --git a/cmd-set-option.c b/cmd-set-option.c
index 22432b7d..c75f99c5 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -69,7 +69,6 @@ const struct cmd_entry cmd_set_option_entry = {
"agoqst:uw", 1, 2,
"[-agosquw] [-t target-session|target-window] option [value]",
0,
- NULL,
cmd_set_option_exec
};
@@ -78,7 +77,6 @@ const struct cmd_entry cmd_set_window_option_entry = {
"agoqt:u", 1, 2,
"[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
0,
- NULL,
cmd_set_option_exec
};
diff --git a/cmd-show-environment.c b/cmd-show-environment.c
index 2238929e..d1b86545 100644
--- a/cmd-show-environment.c
+++ b/cmd-show-environment.c
@@ -34,7 +34,6 @@ const struct cmd_entry cmd_show_environment_entry = {
"gt:", 0, 1,
"[-g] " CMD_TARGET_SESSION_USAGE " [name]",
0,
- NULL,
cmd_show_environment_exec
};
diff --git a/cmd-show-messages.c b/cmd-show-messages.c
index 551966ed..fa843b6e 100644
--- a/cmd-show-messages.c
+++ b/cmd-show-messages.c
@@ -35,7 +35,6 @@ const struct cmd_entry cmd_show_messages_entry = {
"IJTt:", 0, 0,
"[-IJT] " CMD_TARGET_CLIENT_USAGE,
0,
- NULL,
cmd_show_messages_exec
};
@@ -44,7 +43,6 @@ const struct cmd_entry cmd_server_info_entry = {
"", 0, 0,
"",
0,
- NULL,
cmd_show_messages_exec
};
diff --git a/cmd-show-options.c b/cmd-show-options.c
index bf3cfef5..093072f5 100644
--- a/cmd-show-options.c
+++ b/cmd-show-options.c
@@ -39,7 +39,6 @@ const struct cmd_entry cmd_show_options_entry = {
"gqst:vw", 0, 1,
"[-gqsvw] [-t target-session|target-window] [option]",
0,
- NULL,
cmd_show_options_exec
};
@@ -48,7 +47,6 @@ const struct cmd_entry cmd_show_window_options_entry = {
"gvt:", 0, 1,
"[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
0,
- NULL,
cmd_show_options_exec
};
diff --git a/cmd-source-file.c b/cmd-source-file.c
index eb7e1490..33e9cca2 100644
--- a/cmd-source-file.c
+++ b/cmd-source-file.c
@@ -36,7 +36,6 @@ const struct cmd_entry cmd_source_file_entry = {
"", 1, 1,
"path",
0,
- NULL,
cmd_source_file_exec
};
diff --git a/cmd-split-window.c b/cmd-split-window.c
index f086a4ce..6e50aa0b 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -30,7 +30,8 @@
* Split a window (add a new pane).
*/
-void cmd_split_window_key_binding(struct cmd *, int);
+#define SPLIT_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
+
enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_split_window_entry = {
@@ -39,18 +40,9 @@ const struct cmd_entry cmd_split_window_entry = {
"[-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] "
CMD_TARGET_PANE_USAGE " [command]",
0,
- cmd_split_window_key_binding,
cmd_split_window_exec
};
-void
-cmd_split_window_key_binding(struct cmd *self, int key)
-{
- self->args = args_create(0);
- if (key == '%')
- args_set(self->args, 'h', NULL);
-}
-
enum cmd_retval
cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-string.c b/cmd-string.c
index e793ea02..fd483070 100644
--- a/cmd-string.c
+++ b/cmd-string.c
@@ -107,10 +107,11 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
case ' ':
case '\t':
if (buf != NULL) {
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len] = '\0';
- argv = xrealloc(argv, argc + 1, sizeof *argv);
+ argv = xreallocarray(argv, argc + 1,
+ sizeof *argv);
argv[argc++] = buf;
buf = NULL;
@@ -151,7 +152,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
if (len >= SIZE_MAX - 2)
goto error;
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len++] = ch;
break;
}
@@ -179,7 +180,7 @@ cmd_string_copy(char **dst, char *src, size_t *len)
srclen = strlen(src);
- *dst = xrealloc(*dst, 1, *len + srclen + 1);
+ *dst = xrealloc(*dst, *len + srclen + 1);
strlcpy(*dst + *len, src, srclen + 1);
*len += srclen;
@@ -231,11 +232,11 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
if (len >= SIZE_MAX - 2)
goto error;
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len++] = ch;
}
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len] = '\0';
return (buf);
@@ -278,7 +279,7 @@ cmd_string_variable(const char *s, size_t *p)
return (t);
}
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len++] = ch;
for (;;) {
@@ -288,7 +289,7 @@ cmd_string_variable(const char *s, size_t *p)
else {
if (len >= SIZE_MAX - 3)
goto error;
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len++] = ch;
}
}
@@ -299,7 +300,7 @@ cmd_string_variable(const char *s, size_t *p)
if (ch != EOF && fch != '{')
cmd_string_ungetc(p); /* ch */
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len] = '\0';
envent = environ_find(&global_environ, buf);
diff --git a/cmd-suspend-client.c b/cmd-suspend-client.c
deleted file mode 100644
index e0e375fc..00000000
--- a/cmd-suspend-client.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* $Id$ */
-
-/*
- * Copyright (c) 2009 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"
-
-/*
- * Suspend client with SIGTSTP.
- */
-
-enum cmd_retval cmd_suspend_client_exec(struct cmd *, struct cmd_q *);
-
-const struct cmd_entry cmd_suspend_client_entry = {
- "suspend-client", "suspendc",
- "t:", 0, 0,
- CMD_TARGET_CLIENT_USAGE,
- 0,
- NULL,
- cmd_suspend_client_exec
-};
-
-enum cmd_retval
-cmd_suspend_client_exec(struct cmd *self, struct cmd_q *cmdq)
-{
- struct args *args = self->args;
- struct client *c;
-
- if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
- return (CMD_RETURN_ERROR);
-
- tty_stop_tty(&c->tty);
- c->flags |= CLIENT_SUSPENDED;
- server_write_client(c, MSG_SUSPEND, NULL, 0);
-
- return (CMD_RETURN_NORMAL);
-}
diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c
index b8ff7690..0e3cecb4 100644
--- a/cmd-swap-pane.c
+++ b/cmd-swap-pane.c
@@ -26,7 +26,6 @@
* Swap two panes.
*/
-void cmd_swap_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_swap_pane_entry = {
@@ -34,20 +33,9 @@ const struct cmd_entry cmd_swap_pane_entry = {
"dDs:t:U", 0, 0,
"[-dDU] " CMD_SRCDST_PANE_USAGE,
0,
- cmd_swap_pane_key_binding,
cmd_swap_pane_exec
};
-void
-cmd_swap_pane_key_binding(struct cmd *self, int key)
-{
- self->args = args_create(0);
- if (key == '{')
- args_set(self->args, 'U', NULL);
- else if (key == '}')
- args_set(self->args, 'D', NULL);
-}
-
enum cmd_retval
cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-swap-window.c b/cmd-swap-window.c
index 1591d403..c507ad5a 100644
--- a/cmd-swap-window.c
+++ b/cmd-swap-window.c
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_swap_window_entry = {
"ds:t:", 0, 0,
"[-d] " CMD_SRCDST_WINDOW_USAGE,
0,
- NULL,
cmd_swap_window_exec
};
diff --git a/cmd-switch-client.c b/cmd-switch-client.c
index 9e7967cd..e808fc7f 100644
--- a/cmd-switch-client.c
+++ b/cmd-switch-client.c
@@ -27,7 +27,6 @@
* Switch client to a different session.
*/
-void cmd_switch_client_key_binding(struct cmd *, int);
enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_switch_client_entry = {
@@ -35,27 +34,9 @@ const struct cmd_entry cmd_switch_client_entry = {
"lc:npt:r", 0, 0,
"[-lnpr] [-c target-client] [-t target-session]",
CMD_READONLY,
- cmd_switch_client_key_binding,
cmd_switch_client_exec
};
-void
-cmd_switch_client_key_binding(struct cmd *self, int key)
-{
- self->args = args_create(0);
- switch (key) {
- case '(':
- args_set(self->args, 'p', NULL);
- break;
- case ')':
- args_set(self->args, 'n', NULL);
- break;
- case 'L':
- args_set(self->args, 'l', NULL);
- break;
- }
-}
-
enum cmd_retval
cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c
index 494404c1..72d9fd75 100644
--- a/cmd-unbind-key.c
+++ b/cmd-unbind-key.c
@@ -34,7 +34,6 @@ const struct cmd_entry cmd_unbind_key_entry = {
"acnt:", 0, 1,
"[-acn] [-t mode-table] key",
0,
- NULL,
cmd_unbind_key_exec
};
diff --git a/cmd-unlink-window.c b/cmd-unlink-window.c
index ec69b91f..3c4390ad 100644
--- a/cmd-unlink-window.c
+++ b/cmd-unlink-window.c
@@ -31,7 +31,6 @@ const struct cmd_entry cmd_unlink_window_entry = {
"kt:", 0, 0,
"[-k] " CMD_TARGET_WINDOW_USAGE,
0,
- NULL,
cmd_unlink_window_exec
};
diff --git a/cmd-wait-for.c b/cmd-wait-for.c
index 1deb2da9..607ac84a 100644
--- a/cmd-wait-for.c
+++ b/cmd-wait-for.c
@@ -35,7 +35,6 @@ const struct cmd_entry cmd_wait_for_entry = {
"LSU", 1, 1,
"[-L|-S|-U] channel",
0,
- NULL,
cmd_wait_for_exec
};
diff --git a/cmd.c b/cmd.c
index f5165a5f..a8275f88 100644
--- a/cmd.c
+++ b/cmd.c
@@ -120,7 +120,7 @@ struct session *cmd_choose_session_list(struct sessionslist *);
struct session *cmd_choose_session(int);
struct client *cmd_choose_client(struct clients *);
struct client *cmd_lookup_client(const char *);
-struct session *cmd_lookup_session(const char *, int *);
+struct session *cmd_lookup_session(struct cmd_q *, const char *, int *);
struct session *cmd_lookup_session_id(const char *);
struct winlink *cmd_lookup_window(struct session *, const char *, int *);
int cmd_lookup_index(struct session *, const char *, int *);
@@ -221,7 +221,7 @@ cmd_stringify_argv(int argc, char **argv)
for (i = 0; i < argc; i++) {
len += strlen(argv[i]) + 1;
- buf = xrealloc(buf, 1, len);
+ buf = xrealloc(buf, len);
if (i == 0)
*buf = '\0';
@@ -584,9 +584,11 @@ cmd_lookup_session_id(const char *arg)
/* Lookup a session by name. If no session is found, NULL is returned. */
struct session *
-cmd_lookup_session(const char *name, int *ambiguous)
+cmd_lookup_session(struct cmd_q *cmdq, const char *name, int *ambiguous)
{
- struct session *s, *sfound;
+ struct session *s, *sfound;
+ struct window *w;
+ struct window_pane *wp;
*ambiguous = 0;
@@ -594,6 +596,12 @@ cmd_lookup_session(const char *name, int *ambiguous)
if ((s = cmd_lookup_session_id(name)) != NULL)
return (s);
+ /* Try as pane or window id. */
+ if ((wp = cmd_lookup_paneid(name)) != NULL)
+ return (cmd_window_session(cmdq, wp->window, NULL));
+ if ((w = cmd_lookup_windowid(name)) != NULL)
+ return (cmd_window_session(cmdq, w, NULL));
+
/*
* Look for matches. First look for exact matches - session names must
* be unique so an exact match can't be ambigious and can just be
@@ -629,16 +637,30 @@ cmd_lookup_session(const char *name, int *ambiguous)
struct winlink *
cmd_lookup_window(struct session *s, const char *name, int *ambiguous)
{
- struct winlink *wl, *wlfound;
- const char *errstr;
- u_int idx;
+ struct winlink *wl, *wlfound;
+ struct window *w;
+ struct window_pane *wp;
+ const char *errstr;
+ u_int idx;
*ambiguous = 0;
- /* Try as a window id. */
+ /* Try as pane or window id. */
if ((wl = cmd_lookup_winlink_windowid(s, name)) != NULL)
return (wl);
+ /* Lookup as pane or window id. */
+ if ((wp = cmd_lookup_paneid(name)) != NULL) {
+ wl = winlink_find_by_window(&s->windows, wp->window);
+ if (wl != NULL)
+ return (wl);
+ }
+ if ((w = cmd_lookup_windowid(name)) != NULL) {
+ wl = winlink_find_by_window(&s->windows, w);
+ if (wl != NULL)
+ return (wl);
+ }
+
/* First see if this is a valid window index in this session. */
idx = strtonum(name, 0, INT_MAX, &errstr);
if (errstr == NULL) {
@@ -785,13 +807,11 @@ cmd_window_session(struct cmd_q *cmdq, struct window *w, struct winlink **wlp)
struct session *
cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached)
{
- struct session *s;
- struct window_pane *wp;
- struct window *w;
- struct client *c;
- char *tmparg;
- size_t arglen;
- int ambiguous;
+ struct session *s;
+ struct client *c;
+ char *tmparg;
+ size_t arglen;
+ int ambiguous;
/* A NULL argument means the current session. */
if (arg == NULL) {
@@ -800,12 +820,6 @@ cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached)
return (s);
}
- /* Lookup as pane id or window id. */
- if ((wp = cmd_lookup_paneid(arg)) != NULL)
- return (cmd_window_session(cmdq, wp->window, NULL));
- if ((w = cmd_lookup_windowid(arg)) != NULL)
- return (cmd_window_session(cmdq, w, NULL));
-
/* Trim a single trailing colon if any. */
tmparg = xstrdup(arg);
arglen = strlen(tmparg);
@@ -821,7 +835,7 @@ cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached)
}
/* Find the session, if any. */
- s = cmd_lookup_session(tmparg, &ambiguous);
+ s = cmd_lookup_session(cmdq, tmparg, &ambiguous);
/* If it doesn't, try to match it as a client. */
if (s == NULL && (c = cmd_lookup_client(tmparg)) != NULL)
@@ -843,12 +857,11 @@ cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached)
struct winlink *
cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp)
{
- struct session *s;
- struct winlink *wl;
- struct window_pane *wp;
- const char *winptr;
- char *sessptr = NULL;
- int ambiguous = 0;
+ struct session *s;
+ struct winlink *wl;
+ const char *winptr;
+ char *sessptr = NULL;
+ int ambiguous = 0;
/*
* Find the current session. There must always be a current session, if
@@ -866,14 +879,6 @@ cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp)
return (s->curw);
}
- /* Lookup as pane id. */
- if ((wp = cmd_lookup_paneid(arg)) != NULL) {
- s = cmd_window_session(cmdq, wp->window, &wl);
- if (sp != NULL)
- *sp = s;
- return (wl);
- }
-
/* Time to look at the argument. If it is empty, that is an error. */
if (*arg == '\0')
goto not_found;
@@ -888,7 +893,7 @@ cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp)
/* Try to lookup the session if present. */
if (*sessptr != '\0') {
- if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL)
+ if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL)
goto no_session;
}
if (sp != NULL)
@@ -939,7 +944,8 @@ no_colon:
lookup_session:
if (ambiguous)
goto not_found;
- if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
+ if (*arg != '\0' &&
+ (s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL)
goto no_session;
if (sp != NULL)
@@ -1029,7 +1035,7 @@ cmd_find_index(struct cmd_q *cmdq, const char *arg, struct session **sp)
/* Try to lookup the session if present. */
if (sessptr != NULL && *sessptr != '\0') {
- if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL)
+ if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL)
goto no_session;
}
if (sp != NULL)
@@ -1077,7 +1083,8 @@ no_colon:
lookup_session:
if (ambiguous)
goto not_found;
- if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
+ if (*arg != '\0' &&
+ (s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL)
goto no_session;
if (sp != NULL)
@@ -1191,7 +1198,13 @@ cmd_find_pane(struct cmd_q *cmdq,
*wpp = wl->window->active;
else if (paneptr[0] == '+' || paneptr[0] == '-')
*wpp = cmd_find_pane_offset(paneptr, wl);
- else {
+ else if (paneptr[0] == '!' && paneptr[1] == '\0') {
+ if (wl->window->last == NULL) {
+ cmdq_error(cmdq, "no last pane");
+ goto error;
+ }
+ *wpp = wl->window->last;
+ } else {
idx = strtonum(paneptr, 0, INT_MAX, &errstr);
if (errstr != NULL)
goto lookup_string;
@@ -1288,11 +1301,11 @@ cmd_template_replace(const char *template, const char *s, int idx)
ptr++;
len += strlen(s);
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
strlcat(buf, s, len + 1);
continue;
}
- buf = xrealloc(buf, 1, len + 2);
+ buf = xrealloc(buf, len + 2);
buf[len++] = ch;
buf[len] = '\0';
}
diff --git a/control.c b/control.c
index 52fdb524..b0a031f7 100644
--- a/control.c
+++ b/control.c
@@ -27,7 +27,7 @@
#include "tmux.h"
/* Write a line. */
-void printflike2
+void
control_write(struct client *c, const char *fmt, ...)
{
va_list ap;
diff --git a/format.c b/format.c
index baf23ec1..105212a3 100644
--- a/format.c
+++ b/format.c
@@ -17,6 +17,7 @@
*/
#include <sys/types.h>
+#include <sys/param.h>
#include <ctype.h>
#include <errno.h>
@@ -267,7 +268,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
/* Expand the buffer and copy in the value. */
while (*len - *off < valuelen + 1) {
- *buf = xrealloc(*buf, 2, *len);
+ *buf = xreallocarray(*buf, 2, *len);
*len *= 2;
}
memcpy(*buf + *off, value, valuelen);
@@ -298,7 +299,7 @@ format_expand(struct format_tree *ft, const char *fmt)
while (*fmt != '\0') {
if (*fmt != '#') {
while (len - off < 2) {
- buf = xrealloc(buf, 2, len);
+ buf = xreallocarray(buf, 2, len);
len *= 2;
}
buf[off++] = *fmt++;
@@ -326,7 +327,7 @@ format_expand(struct format_tree *ft, const char *fmt)
continue;
case '#':
while (len - off < 2) {
- buf = xrealloc(buf, 2, len);
+ buf = xreallocarray(buf, 2, len);
len *= 2;
}
buf[off++] = '#';
@@ -339,7 +340,7 @@ format_expand(struct format_tree *ft, const char *fmt)
s = format_lower[ch - 'a'];
if (s == NULL) {
while (len - off < 3) {
- buf = xrealloc(buf, 2, len);
+ buf = xreallocarray(buf, 2, len);
len *= 2;
}
buf[off++] = '#';
diff --git a/grid.c b/grid.c
index 6b8cfcb7..521fb9fd 100644
--- a/grid.c
+++ b/grid.c
@@ -172,7 +172,8 @@ grid_scroll_history(struct grid *gd)
u_int yy;
yy = gd->hsize + gd->sy;
- gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
+ gd->linedata = xreallocarray(gd->linedata, yy + 1,
+ sizeof *gd->linedata);
memset(&gd->linedata[yy], 0, sizeof gd->linedata[yy]);
gd->hsize++;
@@ -187,7 +188,8 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower)
/* Create a space for a new line. */
yy = gd->hsize + gd->sy;
- gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
+ gd->linedata = xreallocarray(gd->linedata, yy + 1,
+ sizeof *gd->linedata);
/* Move the entire screen down to free a space for this line. */
gl_history = &gd->linedata[gd->hsize];
@@ -221,7 +223,7 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx)
if (sx <= gl->cellsize)
return;
- gl->celldata = xrealloc(gl->celldata, sx, sizeof *gl->celldata);
+ gl->celldata = xreallocarray(gl->celldata, sx, sizeof *gl->celldata);
for (xx = gl->cellsize; xx < sx; xx++)
grid_put_cell(gd, xx, py, &grid_default_cell);
gl->cellsize = sx;
@@ -610,7 +612,7 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
}
while (len < off + size + codelen + 1) {
- buf = xrealloc(buf, 2, len);
+ buf = xreallocarray(buf, 2, len);
len *= 2;
}
@@ -685,7 +687,7 @@ grid_reflow_join(struct grid *dst, u_int *py, struct grid_line *src_gl,
nx = ox + to_copy;
/* Resize the destination line. */
- dst_gl->celldata = xrealloc(dst_gl->celldata, nx,
+ dst_gl->celldata = xreallocarray(dst_gl->celldata, nx,
sizeof *dst_gl->celldata);
dst_gl->cellsize = nx;
@@ -724,7 +726,8 @@ grid_reflow_split(struct grid *dst, u_int *py, struct grid_line *src_gl,
to_copy = src_gl->cellsize;
/* Expand destination line. */
- dst_gl->celldata = xmalloc(to_copy * sizeof *dst_gl->celldata);
+ dst_gl->celldata = xreallocarray(NULL, to_copy,
+ sizeof *dst_gl->celldata);
dst_gl->cellsize = to_copy;
dst_gl->flags |= GRID_LINE_WRAPPED;
diff --git a/input.c b/input.c
index 06e940aa..12459675 100644
--- a/input.c
+++ b/input.c
@@ -909,7 +909,7 @@ input_ground(struct input_ctx *ictx)
if (ictx->input_space > INPUT_BUF_START) {
ictx->input_space = INPUT_BUF_START;
- ictx->input_buf = xrealloc(ictx->input_buf, 1, INPUT_BUF_START);
+ ictx->input_buf = xrealloc(ictx->input_buf, INPUT_BUF_START);
}
}
@@ -974,7 +974,7 @@ input_input(struct input_ctx *ictx)
ictx->flags |= INPUT_DISCARD;
return (0);
}
- ictx->input_buf = xrealloc(ictx->input_buf, 1, available);
+ ictx->input_buf = xrealloc(ictx->input_buf, available);
ictx->input_space = available;
}
ictx->input_buf[ictx->input_len++] = ictx->ch;
diff --git a/job.c b/job.c
index 47f25d01..d01472b0 100644
--- a/job.c
+++ b/job.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <signal.h>
#include "tmux.h"
diff --git a/key-bindings.c b/key-bindings.c
index 58be0c6f..0413e2be 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -84,107 +84,99 @@ key_bindings_remove(int key)
void
key_bindings_init(void)
{
- static const struct {
- int key;
- int can_repeat;
- const struct cmd_entry *entry;
- } table[] = {
- { ' ', 0, &cmd_next_layout_entry },
- { '!', 0, &cmd_break_pane_entry },
- { '"', 0, &cmd_split_window_entry },
- { '#', 0, &cmd_list_buffers_entry },
- { '$', 0, &cmd_command_prompt_entry },
- { '%', 0, &cmd_split_window_entry },
- { '&', 0, &cmd_confirm_before_entry },
- { '(', 0, &cmd_switch_client_entry },
- { ')', 0, &cmd_switch_client_entry },
- { ',', 0, &cmd_command_prompt_entry },
- { '-', 0, &cmd_delete_buffer_entry },
- { '.', 0, &cmd_command_prompt_entry },
- { '0', 0, &cmd_select_window_entry },
- { '1', 0, &cmd_select_window_entry },
- { '2', 0, &cmd_select_window_entry },
- { '3', 0, &cmd_select_window_entry },
- { '4', 0, &cmd_select_window_entry },
- { '5', 0, &cmd_select_window_entry },
- { '6', 0, &cmd_select_window_entry },
- { '7', 0, &cmd_select_window_entry },
- { '8', 0, &cmd_select_window_entry },
- { '9', 0, &cmd_select_window_entry },
- { ':', 0, &cmd_command_prompt_entry },
- { ';', 0, &cmd_last_pane_entry },
- { '=', 0, &cmd_choose_buffer_entry },
- { '?', 0, &cmd_list_keys_entry },
- { 'D', 0, &cmd_choose_client_entry },
- { 'L', 0, &cmd_switch_client_entry },
- { '[', 0, &cmd_copy_mode_entry },
- { '\'', 0, &cmd_command_prompt_entry },
- { '\002', /* C-b */ 0, &cmd_send_prefix_entry },
- { '\017', /* C-o */ 0, &cmd_rotate_window_entry },
- { '\032', /* C-z */ 0, &cmd_suspend_client_entry },
- { ']', 0, &cmd_paste_buffer_entry },
- { 'c', 0, &cmd_new_window_entry },
- { 'd', 0, &cmd_detach_client_entry },
- { 'f', 0, &cmd_command_prompt_entry },
- { 'i', 0, &cmd_display_message_entry },
- { 'l', 0, &cmd_last_window_entry },
- { 'n', 0, &cmd_next_window_entry },
- { 'o', 0, &cmd_select_pane_entry },
- { 'p', 0, &cmd_previous_window_entry },
- { 'q', 0, &cmd_display_panes_entry },
- { 'r', 0, &cmd_refresh_client_entry },
- { 's', 0, &cmd_choose_tree_entry },
- { 't', 0, &cmd_clock_mode_entry },
- { 'w', 0, &cmd_choose_window_entry },
- { 'x', 0, &cmd_confirm_before_entry },
- { 'z', 0, &cmd_resize_pane_entry },
- { '{', 0, &cmd_swap_pane_entry },
- { '}', 0, &cmd_swap_pane_entry },
- { '~', 0, &cmd_show_messages_entry },
- { '1' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
- { '2' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
- { '3' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
- { '4' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
- { '5' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
- { KEYC_PPAGE, 0, &cmd_copy_mode_entry },
- { 'n' | KEYC_ESCAPE, 0, &cmd_next_window_entry },
- { 'o' | KEYC_ESCAPE, 0, &cmd_rotate_window_entry },
- { 'p' | KEYC_ESCAPE, 0, &cmd_previous_window_entry },
- { KEYC_UP, 1, &cmd_select_pane_entry },
- { KEYC_DOWN, 1, &cmd_select_pane_entry },
- { KEYC_LEFT, 1, &cmd_select_pane_entry },
- { KEYC_RIGHT, 1, &cmd_select_pane_entry },
- { KEYC_UP | KEYC_ESCAPE, 1, &cmd_resize_pane_entry },
- { KEYC_DOWN | KEYC_ESCAPE, 1, &cmd_resize_pane_entry },
- { KEYC_LEFT | KEYC_ESCAPE, 1, &cmd_resize_pane_entry },
- { KEYC_RIGHT | KEYC_ESCAPE, 1, &cmd_resize_pane_entry },
- { KEYC_UP | KEYC_CTRL, 1, &cmd_resize_pane_entry },
- { KEYC_DOWN | KEYC_CTRL, 1, &cmd_resize_pane_entry },
- { KEYC_LEFT | KEYC_CTRL, 1, &cmd_resize_pane_entry },
- { KEYC_RIGHT | KEYC_CTRL, 1, &cmd_resize_pane_entry },
+ static const char* defaults[] = {
+ "bind C-b send-prefix",
+ "bind C-o rotate-window",
+ "bind C-z suspend-client",
+ "bind Space next-layout",
+ "bind ! break-pane",
+ "bind '\"' split-window",
+ "bind '#' list-buffers",
+ "bind '$' command-prompt -I'#S' \"rename-session '%%'\"",
+ "bind % split-window -h",
+ "bind & confirm-before -p\"kill-window #W? (y/n)\" kill-window",
+ "bind \"'\" command-prompt -pindex \"select-window -t ':%%'\"",
+ "bind ( switch-client -p",
+ "bind ) switch-client -n",
+ "bind , command-prompt -I'#W' \"rename-window '%%'\"",
+ "bind - delete-buffer",
+ "bind . command-prompt \"move-window -t '%%'\"",
+ "bind 0 select-window -t:0",
+ "bind 1 select-window -t:1",
+ "bind 2 select-window -t:2",
+ "bind 3 select-window -t:3",
+ "bind 4 select-window -t:4",
+ "bind 5 select-window -t:5",
+ "bind 6 select-window -t:6",
+ "bind 7 select-window -t:7",
+ "bind 8 select-window -t:8",
+ "bind 9 select-window -t:9",
+ "bind : command-prompt",
+ "bind \\; last-pane",
+ "bind = choose-buffer",
+ "bind ? list-keys",
+ "bind D choose-client",
+ "bind L switch-client -l",
+ "bind [ copy-mode",
+ "bind ] paste-buffer",
+ "bind c new-window",
+ "bind d detach-client",
+ "bind f command-prompt \"find-window '%%'\"",
+ "bind i display-message",
+ "bind l last-window",
+ "bind n next-window",
+ "bind o select-pane -t:.+",
+ "bind p previous-window",
+ "bind q display-panes",
+ "bind r refresh-client",
+ "bind s choose-tree",
+ "bind t clock-mode",
+ "bind w choose-window",
+ "bind x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
+ "bind z resize-pane -Z",
+ "bind { swap-pane -U",
+ "bind } swap-pane -D",
+ "bind '~' show-messages",
+ "bind PPage copy-mode -u",
+ "bind -r Up select-pane -U",
+ "bind -r Down select-pane -D",
+ "bind -r Left select-pane -L",
+ "bind -r Right select-pane -R",
+ "bind M-1 select-layout even-horizontal",
+ "bind M-2 select-layout even-vertical",
+ "bind M-3 select-layout main-horizontal",
+ "bind M-4 select-layout main-vertical",
+ "bind M-5 select-layout tiled",
+ "bind M-n next-window -a",
+ "bind M-o rotate-window -D",
+ "bind M-p previous-window -a",
+ "bind -r M-Up resize-pane -U 5",
+ "bind -r M-Down resize-pane -D 5",
+ "bind -r M-Left resize-pane -L 5",
+ "bind -r M-Right resize-pane -R 5",
+ "bind -r C-Up resize-pane -U",
+ "bind -r C-Down resize-pane -D",
+ "bind -r C-Left resize-pane -L",
+ "bind -r C-Right resize-pane -R",
};
u_int i;
- struct cmd *cmd;
struct cmd_list *cmdlist;
+ char* cause;
+ int error;
+ struct cmd_q *cmdq;
RB_INIT(&key_bindings);
- for (i = 0; i < nitems(table); i++) {
- cmdlist = xcalloc(1, sizeof *cmdlist);
- cmdlist->references = 1;
- TAILQ_INIT(&cmdlist->list);
-
- cmd = xcalloc(1, sizeof *cmd);
- cmd->entry = table[i].entry;
- if (cmd->entry->key_binding != NULL)
- cmd->entry->key_binding(cmd, table[i].key);
- else
- cmd->args = args_create(0);
- TAILQ_INSERT_HEAD(&cmdlist->list, cmd, qentry);
-
- key_bindings_add(
- table[i].key | KEYC_PREFIX, table[i].can_repeat, cmdlist);
+ cmdq = cmdq_new (NULL);
+ for (i = 0; i < nitems(defaults); i++) {
+ error = cmd_string_parse(defaults[i], &cmdlist,
+ "<default-keys>", i, &cause);
+ if (error != 0)
+ fatalx("bad default key");
+ cmdq_run (cmdq, cmdlist);
+ cmd_list_free (cmdlist);
}
+ cmdq_free (cmdq);
}
void
diff --git a/log.c b/log.c
index 5c2889c7..6abbf435 100644
--- a/log.c
+++ b/log.c
@@ -81,7 +81,7 @@ log_vwrite(const char *msg, va_list ap)
}
/* Log a debug message. */
-void printflike1
+void
log_debug(const char *msg, ...)
{
va_list ap;
@@ -92,7 +92,7 @@ log_debug(const char *msg, ...)
}
/* Log a critical error with error string and die. */
-__dead void printflike1
+__dead void
log_fatal(const char *msg, ...)
{
char *fmt;
@@ -106,7 +106,7 @@ log_fatal(const char *msg, ...)
}
/* Log a critical error and die. */
-__dead void printflike1
+__dead void
log_fatalx(const char *msg, ...)
{
char *fmt;
diff --git a/options.c b/options.c
index 8bec8e5c..67885c60 100644
--- a/options.c
+++ b/options.c
@@ -99,7 +99,7 @@ options_remove(struct options *oo, const char *name)
free(o);
}
-struct options_entry *printflike3
+struct options_entry *
options_set_string(struct options *oo, const char *name, const char *fmt, ...)
{
struct options_entry *o;
diff --git a/osdep-cygwin.c b/osdep-cygwin.c
index 01d2d0c2..f28df376 100644
--- a/osdep-cygwin.c
+++ b/osdep-cygwin.c
@@ -50,7 +50,7 @@ osdep_get_name(int fd, unused char *tty)
while ((ch = fgetc(f)) != EOF) {
if (ch == '\0')
break;
- buf = xrealloc(buf, 1, len + 2);
+ buf = xrealloc(buf, len + 2);
buf[len++] = ch;
}
if (buf != NULL)
diff --git a/osdep-linux.c b/osdep-linux.c
index 46aea68e..1850d51b 100644
--- a/osdep-linux.c
+++ b/osdep-linux.c
@@ -18,6 +18,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/param.h>
#include <event.h>
#include <stdio.h>
@@ -50,7 +51,7 @@ osdep_get_name(int fd, unused char *tty)
while ((ch = fgetc(f)) != EOF) {
if (ch == '\0')
break;
- buf = xrealloc(buf, 1, len + 2);
+ buf = xrealloc(buf, len + 2);
buf[len++] = ch;
}
if (buf != NULL)
diff --git a/paste.c b/paste.c
index 4af8cccf..ce1f27d3 100644
--- a/paste.c
+++ b/paste.c
@@ -278,7 +278,7 @@ paste_make_sample(struct paste_buffer *pb, int utf8flag)
len = pb->size;
if (len > width)
len = width;
- buf = xmalloc(len * 4 + 4);
+ buf = xreallocarray(NULL, len, 4 + 4);
if (utf8flag)
used = utf8_strvis(buf, pb->data, len, flags);
diff --git a/screen-write.c b/screen-write.c
index 325fb9a4..b3555b61 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -25,13 +25,13 @@
void screen_write_initctx(struct screen_write_ctx *, struct tty_ctx *, int);
void screen_write_overwrite(struct screen_write_ctx *, u_int);
-int screen_write_combine(
- struct screen_write_ctx *, const struct utf8_data *);
+int screen_write_combine(struct screen_write_ctx *,
+ const struct utf8_data *);
/* Initialise writing with a window. */
void
-screen_write_start(
- struct screen_write_ctx *ctx, struct window_pane *wp, struct screen *s)
+screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp,
+ struct screen *s)
{
ctx->wp = wp;
if (wp != NULL && s == NULL)
@@ -73,7 +73,7 @@ screen_write_putc(struct screen_write_ctx *ctx, struct grid_cell *gc,
}
/* Calculate string length, with embedded formatting. */
-size_t printflike2
+size_t
screen_write_cstrlen(int utf8flag, const char *fmt, ...)
{
va_list ap;
@@ -108,7 +108,7 @@ screen_write_cstrlen(int utf8flag, const char *fmt, ...)
}
/* Calculate string length. */
-size_t printflike2
+size_t
screen_write_strlen(int utf8flag, const char *fmt, ...)
{
va_list ap;
@@ -145,9 +145,9 @@ screen_write_strlen(int utf8flag, const char *fmt, ...)
}
/* Write simple string (no UTF-8 or maximum length). */
-void printflike3
-screen_write_puts(
- struct screen_write_ctx *ctx, struct grid_cell *gc, const char *fmt, ...)
+void
+screen_write_puts(struct screen_write_ctx *ctx, struct grid_cell *gc,
+ const char *fmt, ...)
{
va_list ap;
@@ -157,9 +157,9 @@ screen_write_puts(
}
/* Write string with length limit (-1 for unlimited). */
-void printflike5
-screen_write_nputs(struct screen_write_ctx *ctx,
- ssize_t maxlen, struct grid_cell *gc, int utf8flag, const char *fmt, ...)
+void
+screen_write_nputs(struct screen_write_ctx *ctx, ssize_t maxlen,
+ struct grid_cell *gc, int utf8flag, const char *fmt, ...)
{
va_list ap;
@@ -221,7 +221,7 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
}
/* Write string, similar to nputs, but with embedded formatting (#[]). */
-void printflike5
+void
screen_write_cnputs(struct screen_write_ctx *ctx,
ssize_t maxlen, struct grid_cell *gc, int utf8flag, const char *fmt, ...)
{
@@ -990,6 +990,8 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
memcpy(&tmp_gc, &s->sel.cell, sizeof tmp_gc);
grid_cell_get(gc, &ud);
grid_cell_set(&tmp_gc, &ud);
+ tmp_gc.attr = tmp_gc.attr & ~GRID_ATTR_CHARSET;
+ tmp_gc.attr |= gc->attr & GRID_ATTR_CHARSET;
tmp_gc.flags = gc->flags & ~(GRID_FLAG_FG256|GRID_FLAG_BG256);
tmp_gc.flags |= s->sel.cell.flags &
(GRID_FLAG_FG256|GRID_FLAG_BG256);
diff --git a/screen.c b/screen.c
index 014e4f31..c498ed55 100644
--- a/screen.c
+++ b/screen.c
@@ -32,12 +32,12 @@ void screen_resize_y(struct screen *, u_int);
void
screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit)
{
- char hn[MAXHOSTNAMELEN];
+ char host[HOST_NAME_MAX];
s->grid = grid_create(sx, sy, hlimit);
- if (gethostname(hn, MAXHOSTNAMELEN) == 0)
- s->title = xstrdup(hn);
+ if (gethostname(host, HOST_NAME_MAX) == 0)
+ s->title = xstrdup(host);
else
s->title = xstrdup("");
@@ -216,8 +216,8 @@ screen_resize_y(struct screen *s, u_int sy)
}
/* Resize line arrays. */
- gd->linedata = xrealloc(
- gd->linedata, gd->hsize + sy, sizeof *gd->linedata);
+ gd->linedata = xreallocarray(gd->linedata, gd->hsize + sy,
+ sizeof *gd->linedata);
/* Size increasing. */
if (sy > oldy) {
diff --git a/server-client.c b/server-client.c
index d1e3e829..1942926b 100644
--- a/server-client.c
+++ b/server-client.c
@@ -328,6 +328,7 @@ server_client_check_mouse(struct client *c, struct window_pane *wp)
if (options_get_number(oo, "mouse-select-pane") &&
(m->event == MOUSE_EVENT_DOWN || m->event == MOUSE_EVENT_WHEEL)) {
window_set_active_at(wp->window, m->x, m->y);
+ server_status_window(wp->window);
server_redraw_window_borders(wp->window);
wp = wp->window->active; /* may have changed */
}
diff --git a/server-fn.c b/server-fn.c
index e0859f70..7db8668b 100644
--- a/server-fn.c
+++ b/server-fn.c
@@ -31,7 +31,7 @@ void server_callback_identify(int, short, void *);
void
server_fill_environ(struct session *s, struct environ *env)
{
- char var[MAXPATHLEN], *term;
+ char var[PATH_MAX], *term;
u_int idx;
long pid;
diff --git a/signal.c b/signal.c
index 56333522..d24de7d2 100644
--- a/signal.c
+++ b/signal.c
@@ -17,6 +17,8 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
+
#include <string.h>
#include <signal.h>
diff --git a/status.c b/status.c
index deb1b60d..19b0ec88 100644
--- a/status.c
+++ b/status.c
@@ -121,12 +121,17 @@ status_set_window_at(struct client *c, u_int x)
{
struct session *s = c->session;
struct winlink *wl;
+ struct options *oo;
+ size_t len;
x += c->wlmouse;
RB_FOREACH(wl, winlinks, &s->windows) {
+ oo = &wl->window->options;
+
+ len = strlen(options_get_string(oo, "window-status-separator"));
if (x < wl->status_width && session_select(s, wl->idx) == 0)
server_redraw_session(s);
- x -= wl->status_width + 1;
+ x -= wl->status_width + len;
}
}
@@ -646,7 +651,7 @@ status_print(
}
/* Set a status line message. */
-void printflike2
+void
status_message_set(struct client *c, const char *fmt, ...)
{
struct timeval tv;
@@ -987,7 +992,7 @@ status_prompt_key(struct client *c, int key)
/* Insert the new word. */
size += strlen(s);
off = first - c->prompt_buffer;
- c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + 1);
+ c->prompt_buffer = xrealloc(c->prompt_buffer, size + 1);
first = c->prompt_buffer + off;
memmove(first + strlen(s), first, n);
memcpy(first, s, strlen(s));
@@ -1165,7 +1170,7 @@ status_prompt_key(struct client *c, int key)
break;
}
- c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + n + 1);
+ c->prompt_buffer = xrealloc(c->prompt_buffer, size + n + 1);
if (c->prompt_index == size) {
memcpy(c->prompt_buffer + c->prompt_index, pb->data, n);
c->prompt_index += n;
@@ -1205,7 +1210,7 @@ status_prompt_key(struct client *c, int key)
case MODEKEY_OTHER:
if ((key & 0xff00) != 0 || key < 32 || key == 127)
break;
- c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + 2);
+ c->prompt_buffer = xrealloc(c->prompt_buffer, size + 2);
if (c->prompt_index == size) {
c->prompt_buffer[c->prompt_index++] = key;
diff --git a/style.c b/style.c
index 2a049fb6..6df2ed04 100644
--- a/style.c
+++ b/style.c
@@ -17,6 +17,8 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
+
#include <string.h>
#include "tmux.h"
diff --git a/tmux.1 b/tmux.1
index 8afc3c5e..273bcdc6 100644
--- a/tmux.1
+++ b/tmux.1
@@ -439,10 +439,11 @@ first attempts to use the argument as a pane index; if that fails, it is looked
up as for
.Ar target-window .
A
-.Ql +
-or
+.Ql + ,
.Ql -
-indicate the next or previous pane index, respectively.
+or
+.Ql \&!
+indicate the next, previous or last pane.
One of the strings
.Em top ,
.Em bottom ,
@@ -1859,7 +1860,7 @@ In addition, the following special key names are accepted:
.Em Escape ,
.Em F1
to
-.Em F20 ,
+.Em F12 ,
.Em Home ,
.Em IC
(Insert),
@@ -3652,7 +3653,7 @@ to change the cursor colour from inside
$ printf '\e033]12;red\e033\e\e'
.Ed
.It Em \&Ss , Se
-Change the cursor style.
+Set or reset the cursor style.
If set, a sequence such as this may be used
to change the cursor to an underline:
.Bd -literal -offset indent
@@ -3660,10 +3661,8 @@ $ printf '\e033[4 q'
.Ed
.Pp
If
-.Em Csr
-is set, it will be used to reset the cursor style instead
-of
-.Em Cs .
+.Em Se
+is not set, \&Ss with argument 0 will be used to reset the cursor style instead.
.It Em \&Ms
This sequence can be used by
.Nm
diff --git a/tmux.c b/tmux.c
index 631e8502..7669d120 100644
--- a/tmux.c
+++ b/tmux.c
@@ -22,6 +22,7 @@
#include <errno.h>
#include <event.h>
#include <fcntl.h>
+#include <getopt.h>
#include <locale.h>
#include <pwd.h>
#include <stdlib.h>
@@ -45,7 +46,7 @@ char *cfg_file;
char *shell_cmd;
int debug_level;
time_t start_time;
-char socket_path[MAXPATHLEN];
+char socket_path[PATH_MAX];
int login_shell;
char *environ_path;
@@ -127,7 +128,7 @@ areshell(const char *shell)
char *
makesocketpath(const char *label)
{
- char base[MAXPATHLEN], realbase[MAXPATHLEN], *path, *s;
+ char base[PATH_MAX], realbase[PATH_MAX], *path, *s;
struct stat sb;
u_int uid;
@@ -205,7 +206,7 @@ int
main(int argc, char **argv)
{
struct passwd *pw;
- char *s, *path, *label, **var, tmp[MAXPATHLEN];
+ char *s, *path, *label, **var, tmp[PATH_MAX];
char in[256];
const char *home;
long long pid;
diff --git a/tmux.h b/tmux.h
index 5ffc07cd..f35c4e56 100644
--- a/tmux.h
+++ b/tmux.h
@@ -21,13 +21,11 @@
#define PROTOCOL_VERSION 8
-#include <sys/param.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <event.h>
#include <limits.h>
-#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <termios.h>
@@ -69,89 +67,13 @@ extern char **environ;
#define unused __attribute__ ((unused))
/* Attribute to make gcc check printf-like arguments. */
-#define printflike1 __attribute__ ((format (printf, 1, 2)))
-#define printflike2 __attribute__ ((format (printf, 2, 3)))
-#define printflike3 __attribute__ ((format (printf, 3, 4)))
-#define printflike4 __attribute__ ((format (printf, 4, 5)))
-#define printflike5 __attribute__ ((format (printf, 5, 6)))
+#define printflike(a, b) __attribute__ ((format (printf, a, b)))
/* Number of items in array. */
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
#endif
-/* Default template for choose-buffer. */
-#define CHOOSE_BUFFER_TEMPLATE \
- "#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}"
-
-/* Default template for choose-client. */
-#define CHOOSE_CLIENT_TEMPLATE \
- "#{client_tty}: #{session_name} " \
- "[#{client_width}x#{client_height} #{client_termname}]" \
- "#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
- "(last used #{client_activity_string})"
-
-/* Default templates for choose-tree. */
-#define CHOOSE_TREE_SESSION_TEMPLATE \
- "#{session_name}: #{session_windows} windows" \
- "#{?session_grouped, (group ,}" \
- "#{session_group}#{?session_grouped,),}" \
- "#{?session_attached, (attached),}"
-#define CHOOSE_TREE_WINDOW_TEMPLATE \
- "#{window_index}: #{window_name}#{window_flags} " \
- "\"#{pane_title}\""
-
-/* Default template for display-message. */
-#define DISPLAY_MESSAGE_TEMPLATE \
- "[#{session_name}] #{window_index}:" \
- "#{window_name}, current pane #{pane_index} " \
- "- (%H:%M %d-%b-%y)"
-
-/* Default template for find-window. */
-#define FIND_WINDOW_TEMPLATE \
- "#{window_index}: #{window_name} " \
- "[#{window_width}x#{window_height}] " \
- "(#{window_panes} panes) #{window_find_matches}"
-
-/* Default template for list-buffers. */
-#define LIST_BUFFERS_TEMPLATE \
- "#{buffer_name}: #{buffer_size} bytes: " \
- "\"#{buffer_sample}\""
-
-/* Default template for list-clients. */
-#define LIST_CLIENTS_TEMPLATE \
- "#{client_tty}: #{session_name} " \
- "[#{client_width}x#{client_height} #{client_termname}]" \
- "#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"
-
-/* Default template for list-sessions. */
-#define LIST_SESSIONS_TEMPLATE \
- "#{session_name}: #{session_windows} windows " \
- "(created #{session_created_string}) " \
- "[#{session_width}x#{session_height}]" \
- "#{?session_grouped, (group ,}" \
- "#{session_group}#{?session_grouped,),}" \
- "#{?session_attached, (attached),}"
-
-/* Default templates for list-windows. */
-#define LIST_WINDOWS_TEMPLATE \
- "#{window_index}: #{window_name}#{window_flags} " \
- "(#{window_panes} panes) " \
- "[#{window_width}x#{window_height}] " \
- "[layout #{window_layout}] #{window_id}" \
- "#{?window_active, (active),}";
-#define LIST_WINDOWS_WITH_SESSION_TEMPLATE \
- "#{session_name}:" \
- "#{window_index}: #{window_name}#{window_flags} " \
- "(#{window_panes} panes) " \
- "[#{window_width}x#{window_height}] "
-
-/* Default templates for break-pane, new-window and split-window. */
-#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
-#define NEW_SESSION_TEMPLATE "#{session_name}:"
-#define NEW_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE
-#define SPLIT_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE
-
/* Bell option values. */
#define BELL_NONE 0
#define BELL_ANY 1
@@ -1489,7 +1411,6 @@ struct cmd_entry {
#define CMD_READONLY 0x4
int flags;
- void (*key_binding)(struct cmd *, int);
enum cmd_retval (*exec)(struct cmd *, struct cmd_q *);
};
@@ -1563,7 +1484,7 @@ extern char *cfg_file;
extern char *shell_cmd;
extern int debug_level;
extern time_t start_time;
-extern char socket_path[MAXPATHLEN];
+extern char socket_path[PATH_MAX];
extern int login_shell;
extern char *environ_path;
void logfile(const char *);
@@ -1588,8 +1509,8 @@ int format_cmp(struct format_entry *, struct format_entry *);
RB_PROTOTYPE(format_tree, format_entry, entry, format_cmp);
struct format_tree *format_create(void);
void format_free(struct format_tree *);
-void printflike3 format_add(struct format_tree *, const char *, const char *,
- ...);
+void printflike(3, 4) format_add(struct format_tree *, const char *,
+ const char *, ...);
const char *format_find(struct format_tree *, const char *);
char *format_expand(struct format_tree *, const char *);
void format_session(struct format_tree *, struct session *);
@@ -1642,7 +1563,7 @@ void options_free(struct options *);
struct options_entry *options_find1(struct options *, const char *);
struct options_entry *options_find(struct options *, const char *);
void options_remove(struct options *, const char *);
-struct options_entry *printflike3 options_set_string(struct options *,
+struct options_entry *printflike(3, 4) options_set_string(struct options *,
const char *, const char *, ...);
char *options_get_string(struct options *, const char *);
struct options_entry *options_set_number(struct options *, const char *,
@@ -1909,8 +1830,8 @@ size_t cmd_list_print(struct cmd_list *, char *, size_t);
/* cmd-queue.c */
struct cmd_q *cmdq_new(struct client *);
int cmdq_free(struct cmd_q *);
-void printflike2 cmdq_print(struct cmd_q *, const char *, ...);
-void printflike2 cmdq_error(struct cmd_q *, const char *, ...);
+void printflike(2, 3) cmdq_print(struct cmd_q *, const char *, ...);
+void printflike(2, 3) cmdq_error(struct cmd_q *, const char *, ...);
int cmdq_guard(struct cmd_q *, const char *, int);
void cmdq_run(struct cmd_q *, struct cmd_list *);
void cmdq_append(struct cmd_q *, struct cmd_list *);
@@ -2005,9 +1926,9 @@ void status_free_jobs(struct status_out_tree *);
void status_update_jobs(struct client *);
void status_set_window_at(struct client *, u_int);
int status_redraw(struct client *);
-char *status_replace(struct client *, struct session *,
- struct winlink *, struct window_pane *, const char *, time_t, int);
-void printflike2 status_message_set(struct client *, const char *, ...);
+char *status_replace(struct client *, struct session *, struct winlink *,
+ struct window_pane *, const char *, time_t, int);
+void printflike(2, 3) status_message_set(struct client *, const char *, ...);
void status_message_clear(struct client *);
int status_message_redraw(struct client *);
void status_prompt_set(struct client *, const char *, const char *,
@@ -2097,13 +2018,13 @@ void screen_write_start(
struct screen_write_ctx *, struct window_pane *, struct screen *);
void screen_write_stop(struct screen_write_ctx *);
void screen_write_reset(struct screen_write_ctx *);
-size_t printflike2 screen_write_cstrlen(int, const char *, ...);
-void printflike5 screen_write_cnputs(struct screen_write_ctx *,
+size_t printflike(2, 3) screen_write_cstrlen(int, const char *, ...);
+void printflike(5, 6) screen_write_cnputs(struct screen_write_ctx *,
ssize_t, struct grid_cell *, int, const char *, ...);
-size_t printflike2 screen_write_strlen(int, const char *, ...);
-void printflike3 screen_write_puts(struct screen_write_ctx *,
+size_t printflike(2, 3) screen_write_strlen(int, const char *, ...);
+void printflike(3, 4) screen_write_puts(struct screen_write_ctx *,
struct grid_cell *, const char *, ...);
-void printflike5 screen_write_nputs(struct screen_write_ctx *,
+void printflike(5, 6) screen_write_nputs(struct screen_write_ctx *,
ssize_t, struct grid_cell *, int, const char *, ...);
void screen_write_vnputs(struct screen_write_ctx *,
ssize_t, struct grid_cell *, int, const char *, va_list);
@@ -2287,7 +2208,7 @@ extern const char window_clock_table[14][5][5];
extern const struct window_mode window_copy_mode;
void window_copy_init_from_pane(struct window_pane *);
void window_copy_init_for_output(struct window_pane *);
-void printflike2 window_copy_add(struct window_pane *, const char *, ...);
+void printflike(2, 3) window_copy_add(struct window_pane *, const char *, ...);
void window_copy_vadd(struct window_pane *, const char *, va_list);
void window_copy_pageup(struct window_pane *);
@@ -2326,7 +2247,7 @@ void clear_signals(int);
/* control.c */
void control_callback(struct client *, int, void *);
-void printflike2 control_write(struct client *, const char *, ...);
+void printflike(2, 3) control_write(struct client *, const char *, ...);
void control_write_buffer(struct client *, struct evbuffer *);
/* control-notify.c */
@@ -2399,18 +2320,19 @@ struct event_base *osdep_event_init(void);
/* log.c */
void log_open(const char *);
void log_close(void);
-void printflike1 log_debug(const char *, ...);
-__dead void printflike1 log_fatal(const char *, ...);
-__dead void printflike1 log_fatalx(const char *, ...);
+void printflike(1, 2) log_debug(const char *, ...);
+__dead void printflike(1, 2) log_fatal(const char *, ...);
+__dead void printflike(1, 2) log_fatalx(const char *, ...);
/* xmalloc.c */
char *xstrdup(const char *);
void *xcalloc(size_t, size_t);
void *xmalloc(size_t);
-void *xrealloc(void *, size_t, size_t);
-int printflike2 xasprintf(char **, const char *, ...);
+void *xrealloc(void *, size_t);
+void *xreallocarray(void *, size_t, size_t);
+int printflike(2, 3) xasprintf(char **, const char *, ...);
int xvasprintf(char **, const char *, va_list);
-int printflike3 xsnprintf(char *, size_t, const char *, ...);
+int printflike(3, 4) xsnprintf(char *, size_t, const char *, ...);
int xvsnprintf(char *, size_t, const char *, va_list);
/* style.c */
diff --git a/tty-acs.c b/tty-acs.c
index ae84f0d4..140ad4d6 100644
--- a/tty-acs.c
+++ b/tty-acs.c
@@ -81,7 +81,7 @@ tty_acs_get(struct tty *tty, u_char ch)
struct tty_acs_entry *entry;
/* If not a UTF-8 terminal, use the ACS set. */
- if (!(tty->flags & TTY_UTF8)) {
+ if (tty != NULL && !(tty->flags & TTY_UTF8)) {
if (tty->term->acs[ch][0] == '\0')
return (NULL);
return (&tty->term->acs[ch][0]);
diff --git a/utf8.c b/utf8.c
index 4b2560c4..58475405 100644
--- a/utf8.c
+++ b/utf8.c
@@ -420,7 +420,7 @@ utf8_fromcstr(const char *src)
n = 0;
while (*src != '\0') {
- dst = xrealloc(dst, n + 1, sizeof *dst);
+ dst = xreallocarray(dst, n + 1, sizeof *dst);
if (utf8_open(&dst[n], *src)) {
more = 1;
while (*++src != '\0' && more)
@@ -437,7 +437,7 @@ utf8_fromcstr(const char *src)
n++;
}
- dst = xrealloc(dst, n + 1, sizeof *dst);
+ dst = xreallocarray(dst, n + 1, sizeof *dst);
dst[n].size = 0;
return (dst);
}
@@ -453,12 +453,12 @@ utf8_tocstr(struct utf8_data *src)
n = 0;
for(; src->size != 0; src++) {
- dst = xrealloc(dst, n + src->size, 1);
+ dst = xreallocarray(dst, n + src->size, 1);
memcpy(dst + n, src->data, src->size);
n += src->size;
}
- dst = xrealloc(dst, n + 1, 1);
+ dst = xreallocarray(dst, n + 1, 1);
dst[n] = '\0';
return (dst);
}
diff --git a/window-choose.c b/window-choose.c
index 23e77b32..2bceaa41 100644
--- a/window-choose.c
+++ b/window-choose.c
@@ -317,7 +317,7 @@ window_choose_prompt_input(enum window_choose_input_type input_type,
data->input_prompt = prompt;
input_len = strlen(data->input_str) + 2;
- data->input_str = xrealloc(data->input_str, 1, input_len);
+ data->input_str = xrealloc(data->input_str, input_len);
data->input_str[input_len - 2] = key;
data->input_str[input_len - 1] = '\0';
diff --git a/window-copy.c b/window-copy.c
index 3ac994d3..542c28ac 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -794,7 +794,7 @@ window_copy_key_input(struct window_pane *wp, int key)
}
inputlen = strlen(data->inputstr);
- data->inputstr = xrealloc(data->inputstr, 1, inputlen + n + 1);
+ data->inputstr = xrealloc(data->inputstr, inputlen + n + 1);
memcpy(data->inputstr + inputlen, pb->data, n);
data->inputstr[inputlen + n] = '\0';
break;
@@ -840,7 +840,7 @@ window_copy_key_input(struct window_pane *wp, int key)
break;
inputlen = strlen(data->inputstr) + 2;
- data->inputstr = xrealloc(data->inputstr, 1, inputlen);
+ data->inputstr = xrealloc(data->inputstr, inputlen);
data->inputstr[inputlen - 2] = key;
data->inputstr[inputlen - 1] = '\0';
break;
@@ -1533,7 +1533,7 @@ window_copy_append_selection(struct window_pane *wp, const char *bufname)
} else
pb = paste_get_name(bufname);
if (pb != NULL) {
- buf = xrealloc(buf, 1, len + pb->size);
+ buf = xrealloc(buf, len + pb->size);
memmove(buf + pb->size, buf, len);
memcpy(buf, pb->data, pb->size);
len += pb->size;
@@ -1552,6 +1552,7 @@ window_copy_copy_line(struct window_pane *wp,
struct grid_line *gl;
struct utf8_data ud;
u_int i, xx, wrapped = 0;
+ const char *s;
if (sx > ex)
return;
@@ -1580,8 +1581,15 @@ window_copy_copy_line(struct window_pane *wp,
if (gc->flags & GRID_FLAG_PADDING)
continue;
grid_cell_get(gc, &ud);
+ if (ud.size == 1 && (gc->attr & GRID_ATTR_CHARSET)) {
+ s = tty_acs_get(NULL, ud.data[0]);
+ if (s != NULL && strlen(s) <= sizeof ud.data) {
+ ud.size = strlen(s);
+ memcpy (ud.data, s, ud.size);
+ }
+ }
- *buf = xrealloc(*buf, 1, (*off) + ud.size);
+ *buf = xrealloc(*buf, (*off) + ud.size);
memcpy(*buf + *off, ud.data, ud.size);
*off += ud.size;
}
@@ -1589,7 +1597,7 @@ window_copy_copy_line(struct window_pane *wp,
/* Only add a newline if the line wasn't wrapped. */
if (!wrapped || ex != xx) {
- *buf = xrealloc(*buf, 1, (*off) + 1);
+ *buf = xrealloc(*buf, (*off) + 1);
(*buf)[(*off)++] = '\n';
}
}
diff --git a/xmalloc.c b/xmalloc.c
index df583e55..4c24d0d8 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -16,10 +16,9 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/param.h>
+#include <sys/types.h>
-#include <errno.h>
-#include <libgen.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -67,7 +66,20 @@ xmalloc(size_t size)
}
void *
-xrealloc(void *oldptr, size_t nmemb, size_t size)
+xrealloc(void *oldptr, size_t newsize)
+{
+ void *newptr;
+
+ if (newsize == 0)
+ fatalx("zero size");
+ if ((newptr = realloc(oldptr, newsize)) == NULL)
+ fatal("xrealloc failed");
+
+ return (newptr);
+}
+
+void *
+xreallocarray(void *oldptr, size_t nmemb, size_t size)
{
size_t newsize = nmemb * size;
void *newptr;
@@ -77,12 +89,12 @@ xrealloc(void *oldptr, size_t nmemb, size_t size)
if (SIZE_MAX / nmemb < size)
fatalx("nmemb * size > SIZE_MAX");
if ((newptr = realloc(oldptr, newsize)) == NULL)
- fatal("xrealloc failed");
+ fatal("xreallocarray failed");
return (newptr);
}
-int printflike2
+int
xasprintf(char **ret, const char *fmt, ...)
{
va_list ap;
@@ -107,7 +119,7 @@ xvasprintf(char **ret, const char *fmt, va_list ap)
return (i);
}
-int printflike3
+int
xsnprintf(char *buf, size_t len, const char *fmt, ...)
{
va_list ap;