2009-07-09 20:14:18 +02:00
|
|
|
/* $Id: cmd.c,v 1.100 2009-07-09 18:14:18 nicm Exp $ */
|
2007-10-03 12:18:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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>
|
2008-06-03 20:13:54 +02:00
|
|
|
#include <sys/time.h>
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2008-06-05 23:25:00 +02:00
|
|
|
#include <stdlib.h>
|
2007-10-03 13:26:34 +02:00
|
|
|
#include <string.h>
|
2008-06-02 20:08:17 +02:00
|
|
|
#include <unistd.h>
|
2007-10-03 12:18:32 +02:00
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
const struct cmd_entry *cmd_table[] = {
|
2007-10-04 13:52:03 +02:00
|
|
|
&cmd_attach_session_entry,
|
2007-10-04 11:30:53 +02:00
|
|
|
&cmd_bind_key_entry,
|
2009-03-07 10:29:54 +01:00
|
|
|
&cmd_break_pane_entry,
|
2009-01-15 20:27:31 +01:00
|
|
|
&cmd_choose_session_entry,
|
|
|
|
&cmd_choose_window_entry,
|
2009-05-14 18:56:23 +02:00
|
|
|
&cmd_clear_history_entry,
|
2009-01-10 20:35:40 +01:00
|
|
|
&cmd_clock_mode_entry,
|
2008-06-19 22:45:21 +02:00
|
|
|
&cmd_command_prompt_entry,
|
2009-04-27 15:21:16 +02:00
|
|
|
&cmd_confirm_before_entry,
|
2009-02-03 18:21:19 +01:00
|
|
|
&cmd_copy_buffer_entry,
|
2007-11-22 19:09:43 +01:00
|
|
|
&cmd_copy_mode_entry,
|
2008-06-20 19:31:48 +02:00
|
|
|
&cmd_delete_buffer_entry,
|
2007-11-16 22:12:31 +01:00
|
|
|
&cmd_detach_client_entry,
|
2009-01-14 20:41:15 +01:00
|
|
|
&cmd_down_pane_entry,
|
2009-01-18 18:20:52 +01:00
|
|
|
&cmd_find_window_entry,
|
2007-10-25 19:44:25 +02:00
|
|
|
&cmd_has_session_entry,
|
2009-07-09 20:14:18 +02:00
|
|
|
&cmd_if_shell_entry,
|
2009-01-13 07:50:10 +01:00
|
|
|
&cmd_kill_pane_entry,
|
2008-06-03 07:10:38 +02:00
|
|
|
&cmd_kill_server_entry,
|
2007-11-12 15:21:41 +01:00
|
|
|
&cmd_kill_session_entry,
|
2007-10-19 13:10:35 +02:00
|
|
|
&cmd_kill_window_entry,
|
2007-10-04 11:30:53 +02:00
|
|
|
&cmd_last_window_entry,
|
2007-10-26 15:03:59 +02:00
|
|
|
&cmd_link_window_entry,
|
2008-06-20 19:31:48 +02:00
|
|
|
&cmd_list_buffers_entry,
|
2007-10-23 11:36:19 +02:00
|
|
|
&cmd_list_clients_entry,
|
2008-06-24 00:24:16 +02:00
|
|
|
&cmd_list_commands_entry,
|
2007-10-04 11:30:53 +02:00
|
|
|
&cmd_list_keys_entry,
|
2007-10-03 23:31:07 +02:00
|
|
|
&cmd_list_sessions_entry,
|
2007-10-04 13:23:17 +02:00
|
|
|
&cmd_list_windows_entry,
|
2009-01-25 20:00:10 +01:00
|
|
|
&cmd_load_buffer_entry,
|
2009-01-11 01:48:42 +01:00
|
|
|
&cmd_lock_server_entry,
|
2008-06-25 22:33:20 +02:00
|
|
|
&cmd_move_window_entry,
|
2007-10-03 23:31:07 +02:00
|
|
|
&cmd_new_session_entry,
|
2007-10-04 01:32:26 +02:00
|
|
|
&cmd_new_window_entry,
|
2009-04-01 20:21:42 +02:00
|
|
|
&cmd_next_layout_entry,
|
2007-10-04 11:30:53 +02:00
|
|
|
&cmd_next_window_entry,
|
2007-11-23 18:52:54 +01:00
|
|
|
&cmd_paste_buffer_entry,
|
2009-04-30 23:17:06 +02:00
|
|
|
&cmd_previous_layout_entry,
|
2007-10-04 11:30:53 +02:00
|
|
|
&cmd_previous_window_entry,
|
2007-11-16 22:12:31 +01:00
|
|
|
&cmd_refresh_client_entry,
|
2007-11-09 12:02:01 +01:00
|
|
|
&cmd_rename_session_entry,
|
2007-10-04 12:39:07 +02:00
|
|
|
&cmd_rename_window_entry,
|
2009-04-30 08:01:24 +02:00
|
|
|
&cmd_resize_pane_entry,
|
2009-05-04 19:58:27 +02:00
|
|
|
&cmd_respawn_window_entry,
|
2009-04-03 19:21:46 +02:00
|
|
|
&cmd_rotate_window_entry,
|
2009-01-12 00:14:57 +01:00
|
|
|
&cmd_save_buffer_entry,
|
2007-11-21 14:11:41 +01:00
|
|
|
&cmd_scroll_mode_entry,
|
2009-05-16 13:48:47 +02:00
|
|
|
&cmd_select_layout_entry,
|
2009-01-14 20:56:55 +01:00
|
|
|
&cmd_select_pane_entry,
|
2008-06-25 22:43:14 +02:00
|
|
|
&cmd_select_prompt_entry,
|
2007-10-04 12:54:21 +02:00
|
|
|
&cmd_select_window_entry,
|
2008-06-01 22:20:25 +02:00
|
|
|
&cmd_send_keys_entry,
|
2007-10-12 15:03:58 +02:00
|
|
|
&cmd_send_prefix_entry,
|
2009-01-10 02:30:38 +01:00
|
|
|
&cmd_server_info_entry,
|
2008-06-20 10:36:20 +02:00
|
|
|
&cmd_set_buffer_entry,
|
2007-12-06 10:46:23 +01:00
|
|
|
&cmd_set_option_entry,
|
2009-01-11 01:48:42 +01:00
|
|
|
&cmd_set_password_entry,
|
2008-06-15 10:01:54 +02:00
|
|
|
&cmd_set_window_option_entry,
|
2008-06-20 10:36:20 +02:00
|
|
|
&cmd_show_buffer_entry,
|
2008-06-15 10:01:54 +02:00
|
|
|
&cmd_show_options_entry,
|
2008-06-16 08:10:02 +02:00
|
|
|
&cmd_show_window_options_entry,
|
2008-12-15 22:21:56 +01:00
|
|
|
&cmd_source_file_entry,
|
2009-01-12 00:31:46 +01:00
|
|
|
&cmd_split_window_entry,
|
2008-06-02 23:08:36 +02:00
|
|
|
&cmd_start_server_entry,
|
2009-01-18 13:09:42 +01:00
|
|
|
&cmd_suspend_client_entry,
|
2009-04-03 01:28:16 +02:00
|
|
|
&cmd_swap_pane_entry,
|
2007-10-30 12:10:33 +01:00
|
|
|
&cmd_swap_window_entry,
|
2007-11-16 22:31:03 +01:00
|
|
|
&cmd_switch_client_entry,
|
2007-10-04 11:30:53 +02:00
|
|
|
&cmd_unbind_key_entry,
|
2007-10-26 18:57:32 +02:00
|
|
|
&cmd_unlink_window_entry,
|
2009-01-14 20:41:15 +01:00
|
|
|
&cmd_up_pane_entry,
|
2007-10-03 23:31:07 +02:00
|
|
|
NULL
|
2007-10-03 13:26:34 +02:00
|
|
|
};
|
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
struct cmd *
|
|
|
|
cmd_parse(int argc, char **argv, char **cause)
|
2007-10-03 13:26:34 +02:00
|
|
|
{
|
2007-10-05 00:04:01 +02:00
|
|
|
const struct cmd_entry **entryp, *entry;
|
2007-10-03 23:31:07 +02:00
|
|
|
struct cmd *cmd;
|
2007-11-16 14:23:59 +01:00
|
|
|
char s[BUFSIZ];
|
2009-07-08 20:01:55 +02:00
|
|
|
int opt, ambiguous = 0;
|
2007-10-03 23:31:07 +02:00
|
|
|
|
|
|
|
*cause = NULL;
|
2009-06-25 17:56:39 +02:00
|
|
|
if (argc == 0) {
|
|
|
|
xasprintf(cause, "no command");
|
2007-10-03 23:31:07 +02:00
|
|
|
return (NULL);
|
2009-06-25 17:56:39 +02:00
|
|
|
}
|
2007-10-03 23:31:07 +02:00
|
|
|
|
|
|
|
entry = NULL;
|
2007-10-05 00:04:01 +02:00
|
|
|
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
2007-12-06 10:46:23 +01:00
|
|
|
if ((*entryp)->alias != NULL &&
|
2007-10-12 15:51:44 +02:00
|
|
|
strcmp((*entryp)->alias, argv[0]) == 0) {
|
2009-07-08 20:01:55 +02:00
|
|
|
ambiguous = 0;
|
2007-10-05 00:04:01 +02:00
|
|
|
entry = *entryp;
|
2007-10-03 13:26:34 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-10-03 23:31:07 +02:00
|
|
|
|
2007-10-05 00:04:01 +02:00
|
|
|
if (strncmp((*entryp)->name, argv[0], strlen(argv[0])) != 0)
|
2007-10-03 23:31:07 +02:00
|
|
|
continue;
|
2007-11-16 14:23:59 +01:00
|
|
|
if (entry != NULL)
|
2009-07-08 20:01:55 +02:00
|
|
|
ambiguous = 1;
|
2007-10-05 00:04:01 +02:00
|
|
|
entry = *entryp;
|
2008-07-19 12:07:50 +02:00
|
|
|
|
|
|
|
/* Bail now if an exact match. */
|
|
|
|
if (strcmp(entry->name, argv[0]) == 0)
|
|
|
|
break;
|
2007-10-03 13:26:34 +02:00
|
|
|
}
|
2009-07-08 20:01:55 +02:00
|
|
|
if (ambiguous)
|
|
|
|
goto ambiguous;
|
2007-10-03 23:31:07 +02:00
|
|
|
if (entry == NULL) {
|
|
|
|
xasprintf(cause, "unknown command: %s", argv[0]);
|
|
|
|
return (NULL);
|
2007-10-03 14:34:16 +02:00
|
|
|
}
|
2009-01-10 02:51:22 +01:00
|
|
|
|
2008-12-10 21:25:42 +01:00
|
|
|
optreset = 1;
|
2007-10-03 23:31:07 +02:00
|
|
|
optind = 1;
|
|
|
|
if (entry->parse == NULL) {
|
2008-12-10 21:25:42 +01:00
|
|
|
while ((opt = getopt(argc, argv, "")) != -1) {
|
2007-10-03 23:31:07 +02:00
|
|
|
switch (opt) {
|
|
|
|
default:
|
|
|
|
goto usage;
|
|
|
|
}
|
2007-10-03 13:26:34 +02:00
|
|
|
}
|
2007-10-03 23:31:07 +02:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
if (argc != 0)
|
|
|
|
goto usage;
|
2007-10-03 13:26:34 +02:00
|
|
|
}
|
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
cmd = xmalloc(sizeof *cmd);
|
|
|
|
cmd->entry = entry;
|
2008-06-16 09:01:41 +02:00
|
|
|
cmd->data = NULL;
|
2007-10-03 23:31:07 +02:00
|
|
|
if (entry->parse != NULL) {
|
2008-06-05 18:35:32 +02:00
|
|
|
if (entry->parse(cmd, argc, argv, cause) != 0) {
|
2007-10-03 23:31:07 +02:00
|
|
|
xfree(cmd);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (cmd);
|
2007-10-03 13:26:34 +02:00
|
|
|
|
2007-11-16 14:23:59 +01:00
|
|
|
ambiguous:
|
|
|
|
*s = '\0';
|
|
|
|
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
|
|
|
if (strncmp((*entryp)->name, argv[0], strlen(argv[0])) != 0)
|
|
|
|
continue;
|
|
|
|
if (strlcat(s, (*entryp)->name, sizeof s) >= sizeof s)
|
|
|
|
break;
|
|
|
|
if (strlcat(s, ", ", sizeof s) >= sizeof s)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s[strlen(s) - 2] = '\0';
|
|
|
|
xasprintf(cause, "ambiguous command: %s, could be: %s", argv[0], s);
|
|
|
|
return (NULL);
|
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
usage:
|
2008-06-02 23:08:36 +02:00
|
|
|
xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
|
2007-10-03 23:31:07 +02:00
|
|
|
return (NULL);
|
2007-10-03 13:26:34 +02:00
|
|
|
}
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2009-01-19 19:23:40 +01:00
|
|
|
int
|
2007-10-03 23:31:07 +02:00
|
|
|
cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx)
|
2007-10-03 12:18:32 +02:00
|
|
|
{
|
2009-01-11 01:48:42 +01:00
|
|
|
if (server_locked) {
|
|
|
|
ctx->error(ctx, "server is locked");
|
2009-01-19 19:23:40 +01:00
|
|
|
return (-1);
|
2009-01-11 01:48:42 +01:00
|
|
|
}
|
2009-01-19 19:23:40 +01:00
|
|
|
return (cmd->entry->exec(cmd, ctx));
|
2007-10-03 12:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-10-03 23:31:07 +02:00
|
|
|
cmd_send(struct cmd *cmd, struct buffer *b)
|
2007-10-03 12:18:32 +02:00
|
|
|
{
|
2007-10-05 00:04:01 +02:00
|
|
|
const struct cmd_entry **entryp;
|
|
|
|
u_int n;
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2007-10-05 00:04:01 +02:00
|
|
|
n = 0;
|
|
|
|
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
|
|
|
if (*entryp == cmd->entry)
|
|
|
|
break;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
if (*entryp == NULL)
|
|
|
|
fatalx("command not found");
|
|
|
|
|
|
|
|
buffer_write(b, &n, sizeof n);
|
|
|
|
|
|
|
|
if (cmd->entry->send != NULL)
|
2008-06-05 18:35:32 +02:00
|
|
|
cmd->entry->send(cmd, b);
|
2007-10-03 12:18:32 +02:00
|
|
|
}
|
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
struct cmd *
|
|
|
|
cmd_recv(struct buffer *b)
|
2007-10-03 12:18:32 +02:00
|
|
|
{
|
2007-10-05 00:04:01 +02:00
|
|
|
const struct cmd_entry **entryp;
|
2007-10-03 23:31:07 +02:00
|
|
|
struct cmd *cmd;
|
2007-10-05 00:04:01 +02:00
|
|
|
u_int m, n;
|
2007-10-03 23:31:07 +02:00
|
|
|
|
2007-10-05 00:04:01 +02:00
|
|
|
buffer_read(b, &m, sizeof m);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-10-05 00:04:01 +02:00
|
|
|
n = 0;
|
|
|
|
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
|
|
|
if (n == m)
|
2007-10-03 23:31:07 +02:00
|
|
|
break;
|
2007-10-05 00:04:01 +02:00
|
|
|
n++;
|
2007-10-03 23:31:07 +02:00
|
|
|
}
|
2007-10-05 00:04:01 +02:00
|
|
|
if (*entryp == NULL)
|
|
|
|
fatalx("command not found");
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
cmd = xmalloc(sizeof *cmd);
|
2007-10-05 00:04:01 +02:00
|
|
|
cmd->entry = *entryp;
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
if (cmd->entry->recv != NULL)
|
2008-06-05 18:35:32 +02:00
|
|
|
cmd->entry->recv(cmd, b);
|
2007-10-03 23:31:07 +02:00
|
|
|
return (cmd);
|
2007-10-03 12:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-10-03 23:31:07 +02:00
|
|
|
cmd_free(struct cmd *cmd)
|
2007-10-03 12:18:32 +02:00
|
|
|
{
|
2007-10-04 11:30:53 +02:00
|
|
|
if (cmd->data != NULL && cmd->entry->free != NULL)
|
2008-06-05 18:35:32 +02:00
|
|
|
cmd->entry->free(cmd);
|
2007-10-03 23:31:07 +02:00
|
|
|
xfree(cmd);
|
2007-10-03 12:18:32 +02:00
|
|
|
}
|
|
|
|
|
2009-01-18 15:40:48 +01:00
|
|
|
size_t
|
|
|
|
cmd_print(struct cmd *cmd, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
if (cmd->entry->print == NULL) {
|
|
|
|
return (xsnprintf(buf, len, "%s", cmd->entry->name));
|
|
|
|
}
|
|
|
|
return (cmd->entry->print(cmd, buf, len));
|
|
|
|
}
|
|
|
|
|
2007-10-03 12:18:32 +02:00
|
|
|
void
|
2007-10-03 23:31:07 +02:00
|
|
|
cmd_send_string(struct buffer *b, const char *s)
|
2007-10-03 12:18:32 +02:00
|
|
|
{
|
2007-10-03 23:31:07 +02:00
|
|
|
size_t n;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
if (s == NULL) {
|
|
|
|
n = 0;
|
|
|
|
buffer_write(b, &n, sizeof n);
|
|
|
|
return;
|
|
|
|
}
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
n = strlen(s) + 1;
|
|
|
|
buffer_write(b, &n, sizeof n);
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
buffer_write(b, s, n);
|
2007-10-03 12:18:32 +02:00
|
|
|
}
|
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
char *
|
|
|
|
cmd_recv_string(struct buffer *b)
|
2007-10-03 12:18:32 +02:00
|
|
|
{
|
2007-10-03 23:31:07 +02:00
|
|
|
char *s;
|
|
|
|
size_t n;
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
buffer_read(b, &n, sizeof n);
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
if (n == 0)
|
|
|
|
return (NULL);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
s = xmalloc(n);
|
|
|
|
buffer_read(b, s, n);
|
|
|
|
s[n - 1] = '\0';
|
2007-10-03 12:18:32 +02:00
|
|
|
|
2007-10-03 23:31:07 +02:00
|
|
|
return (s);
|
2007-10-03 12:18:32 +02:00
|
|
|
}
|
2008-06-02 20:08:17 +02:00
|
|
|
|
2008-06-03 18:55:09 +02:00
|
|
|
struct session *
|
2008-06-05 23:25:00 +02:00
|
|
|
cmd_current_session(struct cmd_ctx *ctx)
|
2008-06-03 18:55:09 +02:00
|
|
|
{
|
2008-06-02 20:08:17 +02:00
|
|
|
struct msg_command_data *data = ctx->msgdata;
|
2008-08-28 19:45:30 +02:00
|
|
|
struct timeval *tv;
|
2008-06-05 23:25:00 +02:00
|
|
|
struct session *s, *newest = NULL;
|
|
|
|
u_int i;
|
2008-06-02 20:08:17 +02:00
|
|
|
|
|
|
|
if (ctx->cursession != NULL)
|
|
|
|
return (ctx->cursession);
|
|
|
|
|
|
|
|
if (data != NULL && data->pid != -1) {
|
|
|
|
if (data->pid != getpid()) {
|
2008-07-01 22:35:16 +02:00
|
|
|
ctx->error(ctx, "wrong server: %ld", (long) data->pid);
|
2008-06-02 20:08:17 +02:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (data->idx > ARRAY_LENGTH(&sessions)) {
|
|
|
|
ctx->error(ctx, "index out of range: %d", data->idx);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if ((s = ARRAY_ITEM(&sessions, data->idx)) == NULL) {
|
|
|
|
ctx->error(ctx, "session doesn't exist: %u", data->idx);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return (s);
|
|
|
|
}
|
2008-06-19 00:21:51 +02:00
|
|
|
|
2008-08-28 19:45:30 +02:00
|
|
|
tv = NULL;
|
2008-06-02 20:08:17 +02:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
2008-06-19 00:21:51 +02:00
|
|
|
s = ARRAY_ITEM(&sessions, i);
|
2008-08-28 19:45:30 +02:00
|
|
|
if (s != NULL && (tv == NULL || timercmp(&s->tv, tv, >))) {
|
2008-06-03 18:55:09 +02:00
|
|
|
newest = ARRAY_ITEM(&sessions, i);
|
2008-08-28 19:45:30 +02:00
|
|
|
tv = &s->tv;
|
2008-06-02 20:08:17 +02:00
|
|
|
}
|
|
|
|
}
|
2008-06-03 18:55:09 +02:00
|
|
|
return (newest);
|
2008-06-02 20:08:17 +02:00
|
|
|
}
|
|
|
|
|
2008-06-05 23:25:00 +02:00
|
|
|
struct client *
|
|
|
|
cmd_find_client(struct cmd_ctx *ctx, const char *arg)
|
|
|
|
{
|
|
|
|
struct client *c;
|
2008-06-19 00:21:51 +02:00
|
|
|
|
2008-06-27 19:10:01 +02:00
|
|
|
if (arg == NULL)
|
2008-06-05 23:25:00 +02:00
|
|
|
c = ctx->curclient;
|
2008-06-27 19:10:01 +02:00
|
|
|
else {
|
|
|
|
if ((c = arg_parse_client(arg)) == NULL) {
|
|
|
|
if (arg != NULL)
|
|
|
|
ctx->error(ctx, "client not found: %s", arg);
|
|
|
|
else
|
|
|
|
ctx->error(ctx, "no client found");
|
|
|
|
}
|
2008-06-17 00:03:27 +02:00
|
|
|
}
|
2008-06-05 23:25:00 +02:00
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct session *
|
|
|
|
cmd_find_session(struct cmd_ctx *ctx, const char *arg)
|
|
|
|
{
|
|
|
|
struct session *s;
|
|
|
|
|
2008-06-27 19:10:01 +02:00
|
|
|
if (arg == NULL)
|
2008-06-05 23:25:00 +02:00
|
|
|
s = cmd_current_session(ctx);
|
2008-06-27 19:10:01 +02:00
|
|
|
else {
|
|
|
|
if ((s = arg_parse_session(arg)) == NULL) {
|
|
|
|
if (arg != NULL)
|
|
|
|
ctx->error(ctx, "session not found: %s", arg);
|
|
|
|
else
|
|
|
|
ctx->error(ctx, "no session found");
|
|
|
|
}
|
2008-06-17 00:03:27 +02:00
|
|
|
}
|
2008-06-05 23:25:00 +02:00
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
2008-06-03 18:55:09 +02:00
|
|
|
struct winlink *
|
2008-06-05 23:25:00 +02:00
|
|
|
cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
|
2008-06-02 20:08:17 +02:00
|
|
|
{
|
2008-06-05 23:25:00 +02:00
|
|
|
struct session *s;
|
|
|
|
struct winlink *wl;
|
|
|
|
int idx;
|
2008-06-02 20:08:17 +02:00
|
|
|
|
2008-06-05 23:25:00 +02:00
|
|
|
wl = NULL;
|
|
|
|
if (arg_parse_window(arg, &s, &idx) != 0) {
|
|
|
|
ctx->error(ctx, "bad window: %s", arg);
|
2008-06-02 20:08:17 +02:00
|
|
|
return (NULL);
|
2008-06-05 23:25:00 +02:00
|
|
|
}
|
|
|
|
if (s == NULL)
|
|
|
|
s = ctx->cursession;
|
|
|
|
if (s == NULL)
|
|
|
|
s = cmd_current_session(ctx);
|
2008-06-06 00:59:38 +02:00
|
|
|
if (s == NULL)
|
|
|
|
return (NULL);
|
2008-06-03 18:55:09 +02:00
|
|
|
if (sp != NULL)
|
|
|
|
*sp = s;
|
2008-06-06 00:59:38 +02:00
|
|
|
|
|
|
|
if (idx == -1)
|
|
|
|
wl = s->curw;
|
|
|
|
else
|
|
|
|
wl = winlink_find_by_index(&s->windows, idx);
|
2008-06-05 23:25:00 +02:00
|
|
|
if (wl == NULL)
|
|
|
|
ctx->error(ctx, "window not found: %s:%d", s->name, idx);
|
2008-06-03 18:55:09 +02:00
|
|
|
return (wl);
|
2008-06-02 20:08:17 +02:00
|
|
|
}
|