1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
//
// 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.
use crate::*;
pub static CMD_LOAD_BUFFER_ENTRY: cmd_entry = cmd_entry {
name: "load-buffer",
alias: Some("loadb"),
args: args_parse::new("b:t:w", 1, 1, None),
usage: "[-b buffer-name] [-t target-client] path",
flags: cmd_flag::CMD_AFTERHOOK
.union(cmd_flag::CMD_CLIENT_TFLAG)
.union(cmd_flag::CMD_CLIENT_CANFAIL),
exec: cmd_load_buffer_exec,
source: cmd_entry_flag::zeroed(),
target: cmd_entry_flag::zeroed(),
};
#[repr(C)]
pub struct cmd_load_buffer_data {
pub client: *mut client,
pub item: *mut cmdq_item,
pub name: *mut u8,
}
/// C `vendor/tmux/cmd-load-buffer.c:54`: `static void cmd_load_buffer_done(__unused struct client *c, const char *path, int error, int closed, struct evbuffer *buffer, void *data)`
unsafe fn cmd_load_buffer_done(
_c: *mut client,
path: *mut u8,
error: i32,
closed: i32,
buffer: *mut evbuffer,
data: *mut c_void,
) {
unsafe {
let cdata = data as *mut cmd_load_buffer_data;
let tc = (*cdata).client;
let item = (*cdata).item;
let bdata = EVBUFFER_DATA(buffer);
let bsize = EVBUFFER_LENGTH(buffer);
if closed == 0 {
return;
}
if error != 0 {
cmdq_error!(item, "{}: {}", _s(path), strerror(error));
} else if bsize != 0 {
let copy = xmalloc(bsize).as_ptr();
memcpy_(copy, bdata as _, bsize);
let mut cause = null_mut();
if paste_set(
copy as _,
bsize,
cstr_to_str_((*cdata).name),
&raw mut cause,
) != 0
{
cmdq_error!(item, "{}", _s(cause));
free_(cause);
free_(copy);
} else if !tc.is_null()
&& !(*tc).session.is_null()
&& !(*tc).flags.intersects(client_flag::DEAD)
{
tty_set_selection(&raw mut (*tc).tty, c!(""), copy as _, bsize);
}
if !tc.is_null() {
server_client_unref(tc);
}
}
cmdq_continue(item);
free_((*cdata).name);
free_(cdata);
}
}
/// C `vendor/tmux/cmd-load-buffer.c:91`: `static enum cmd_retval cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)`
unsafe fn cmd_load_buffer_exec(self_: *mut cmd, item: *mut cmdq_item) -> cmd_retval {
unsafe {
let args = cmd_get_args(self_);
let tc = cmdq_get_target_client(item);
let bufname = args_get(args, b'b');
let cdata = xcalloc_::<cmd_load_buffer_data>(1).as_ptr();
(*cdata).item = item;
if !bufname.is_null() {
(*cdata).name = xstrdup(bufname).as_ptr();
}
if args_has(args, 'w') && !tc.is_null() {
(*cdata).client = tc;
(*(*cdata).client).references += 1;
}
let path = format_single_from_target(item, args_string(args, 0));
file_read(
cmdq_get_client(item),
path,
Some(cmd_load_buffer_done),
cdata.cast(),
);
free_(path);
}
cmd_retval::CMD_RETURN_WAIT
}