summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-choose-buffer.c6
-rw-r--r--usr.bin/tmux/cmd-paste-buffer.c4
-rw-r--r--usr.bin/tmux/cmd-save-buffer.c23
-rw-r--r--usr.bin/tmux/cmd-set-buffer.c41
-rw-r--r--usr.bin/tmux/format.c8
-rw-r--r--usr.bin/tmux/paste.c36
-rw-r--r--usr.bin/tmux/status.c18
-rw-r--r--usr.bin/tmux/tmux.h44
-rw-r--r--usr.bin/tmux/window-copy.c34
9 files changed, 117 insertions, 97 deletions
diff --git a/usr.bin/tmux/cmd-choose-buffer.c b/usr.bin/tmux/cmd-choose-buffer.c
index 30424d7ca4b..386f68a8e97 100644
--- a/usr.bin/tmux/cmd-choose-buffer.c
+++ b/usr.bin/tmux/cmd-choose-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-choose-buffer.c,v 1.22 2015/04/27 16:25:57 nicm Exp $ */
+/* $OpenBSD: cmd-choose-buffer.c,v 1.23 2015/08/29 09:25:00 nicm Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -65,7 +65,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
utf8flag = options_get_number(&wl->window->options, "utf8");
- if (paste_get_top() == NULL)
+ if (paste_get_top(NULL) == NULL)
return (CMD_RETURN_NORMAL);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
@@ -85,7 +85,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
cdata->ft_template = xstrdup(template);
format_defaults_paste_buffer(cdata->ft, pb, utf8flag);
- xasprintf(&action_data, "%s", pb->name);
+ xasprintf(&action_data, "%s", paste_buffer_name(pb));
cdata->command = cmd_template_replace(action, action_data, 1);
free(action_data);
diff --git a/usr.bin/tmux/cmd-paste-buffer.c b/usr.bin/tmux/cmd-paste-buffer.c
index aa09f906262..3c6b17d8017 100644
--- a/usr.bin/tmux/cmd-paste-buffer.c
+++ b/usr.bin/tmux/cmd-paste-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-paste-buffer.c,v 1.27 2014/11/05 23:25:02 nicm Exp $ */
+/* $OpenBSD: cmd-paste-buffer.c,v 1.28 2015/08/29 09:25:00 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -58,7 +58,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
bufname = args_get(args, 'b');
if (bufname == NULL)
- pb = paste_get_top();
+ pb = paste_get_top(NULL);
else {
pb = paste_get_name(bufname);
if (pb == NULL) {
diff --git a/usr.bin/tmux/cmd-save-buffer.c b/usr.bin/tmux/cmd-save-buffer.c
index c760537e5bf..06e5f31c5ea 100644
--- a/usr.bin/tmux/cmd-save-buffer.c
+++ b/usr.bin/tmux/cmd-save-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-save-buffer.c,v 1.28 2015/04/27 16:25:57 nicm Exp $ */
+/* $OpenBSD: cmd-save-buffer.c,v 1.29 2015/08/29 09:25:00 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -57,14 +57,14 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
struct client *c = cmdq->client;
struct session *s;
struct paste_buffer *pb;
- const char *path, *bufname;
+ const char *path, *bufname, *bufdata;
char *start, *end, *msg;
- size_t size, used, msglen;
+ size_t size, used, msglen, bufsize;
int cwd, fd;
FILE *f;
if (!args_has(args, 'b')) {
- if ((pb = paste_get_top()) == NULL) {
+ if ((pb = paste_get_top(NULL)) == NULL) {
cmdq_error(cmdq, "no buffers");
return (CMD_RETURN_ERROR);
}
@@ -76,6 +76,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
}
+ bufdata = paste_buffer_data(pb, &bufsize);
if (self->entry == &cmd_show_buffer_entry)
path = "-";
@@ -114,7 +115,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
return (CMD_RETURN_ERROR);
}
- if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
+ if (fwrite(bufdata, 1, bufsize, f) != bufsize) {
cmdq_error(cmdq, "%s: fwrite error", path);
fclose(f);
return (CMD_RETURN_ERROR);
@@ -124,25 +125,25 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
do_stdout:
- evbuffer_add(c->stdout_data, pb->data, pb->size);
+ evbuffer_add(c->stdout_data, bufdata, bufsize);
server_push_stdout(c);
return (CMD_RETURN_NORMAL);
do_print:
- if (pb->size > (INT_MAX / 4) - 1) {
+ if (bufsize > (INT_MAX / 4) - 1) {
cmdq_error(cmdq, "buffer too big");
return (CMD_RETURN_ERROR);
}
msg = NULL;
used = 0;
- while (used != pb->size) {
- start = pb->data + used;
- end = memchr(start, '\n', pb->size - used);
+ while (used != bufsize) {
+ start = bufdata + used;
+ end = memchr(start, '\n', bufsize - used);
if (end != NULL)
size = end - start;
else
- size = pb->size - used;
+ size = bufsize - used;
msglen = size * 4 + 1;
msg = xrealloc(msg, msglen);
diff --git a/usr.bin/tmux/cmd-set-buffer.c b/usr.bin/tmux/cmd-set-buffer.c
index 9c825042034..8c89ae7b44c 100644
--- a/usr.bin/tmux/cmd-set-buffer.c
+++ b/usr.bin/tmux/cmd-set-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-buffer.c,v 1.20 2014/10/20 22:29:25 nicm Exp $ */
+/* $OpenBSD: cmd-set-buffer.c,v 1.21 2015/08/29 09:25:00 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -42,9 +42,9 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct paste_buffer *pb;
- char *pdata, *cause;
- const char *bufname;
- size_t psize, newsize;
+ char *bufdata, *cause;
+ const char *bufname, *olddata;
+ size_t bufsize, newsize;
bufname = NULL;
@@ -58,12 +58,11 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
bufname = args_get(args, 'b');
if (bufname == NULL) {
- pb = paste_get_top();
+ pb = paste_get_top(&bufname);
if (pb == NULL) {
cmdq_error(cmdq, "no buffer");
return (CMD_RETURN_ERROR);
}
- bufname = pb->name;
}
if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) {
@@ -79,37 +78,33 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
cmdq_error(cmdq, "no data specified");
return (CMD_RETURN_ERROR);
}
-
- psize = 0;
- pdata = NULL;
-
pb = NULL;
+ bufsize = 0;
+ bufdata = NULL;
+
if ((newsize = strlen(args->argv[0])) == 0)
return (CMD_RETURN_NORMAL);
if (args_has(args, 'b')) {
bufname = args_get(args, 'b');
pb = paste_get_name(bufname);
- } else if (args_has(args, 'a')) {
- pb = paste_get_top();
- if (pb != NULL)
- bufname = pb->name;
- }
+ } else if (args_has(args, 'a'))
+ pb = paste_get_top(&bufname);
if (args_has(args, 'a') && pb != NULL) {
- psize = pb->size;
- pdata = xmalloc(psize);
- memcpy(pdata, pb->data, psize);
+ olddata = paste_buffer_data(pb, &bufsize);
+ bufdata = xmalloc(bufsize);
+ memcpy(bufdata, olddata, bufsize);
}
- pdata = xrealloc(pdata, psize + newsize);
- memcpy(pdata + psize, args->argv[0], newsize);
- psize += newsize;
+ bufdata = xrealloc(bufdata, bufsize + newsize);
+ memcpy(bufdata + bufsize, args->argv[0], newsize);
+ bufsize += newsize;
- if (paste_set(pdata, psize, bufname, &cause) != 0) {
+ if (paste_set(bufdata, bufsize, bufname, &cause) != 0) {
cmdq_error(cmdq, "%s", cause);
- free(pdata);
+ free(bufdata);
free(cause);
return (CMD_RETURN_ERROR);
}
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index efd36f1bd04..fab5bca4c65 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.80 2015/08/28 17:01:42 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.81 2015/08/29 09:25:00 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1074,10 +1074,12 @@ void
format_defaults_paste_buffer(struct format_tree *ft, struct paste_buffer *pb,
int utf8flag)
{
+ size_t bufsize;
char *s;
- format_add(ft, "buffer_size", "%zu", pb->size);
- format_add(ft, "buffer_name", "%s", pb->name);
+ paste_buffer_data(pb, &bufsize);
+ format_add(ft, "buffer_size", "%zu", bufsize);
+ format_add(ft, "buffer_name", "%s", paste_buffer_name(pb));
s = paste_make_sample(pb, utf8flag);
format_add(ft, "buffer_sample", "%s", s);
diff --git a/usr.bin/tmux/paste.c b/usr.bin/tmux/paste.c
index 2cf1678f3ef..62e6b10eed6 100644
--- a/usr.bin/tmux/paste.c
+++ b/usr.bin/tmux/paste.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: paste.c,v 1.27 2015/04/07 13:06:22 nicm Exp $ */
+/* $OpenBSD: paste.c,v 1.28 2015/08/29 09:25:00 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -30,6 +30,18 @@
* string!
*/
+struct paste_buffer {
+ char *data;
+ size_t size;
+
+ char *name;
+ int automatic;
+ u_int order;
+
+ RB_ENTRY(paste_buffer) name_entry;
+ RB_ENTRY(paste_buffer) time_entry;
+};
+
u_int paste_next_index;
u_int paste_next_order;
u_int paste_num_automatic;
@@ -60,6 +72,22 @@ paste_cmp_times(const struct paste_buffer *a, const struct paste_buffer *b)
return (0);
}
+/* Get paste buffer name. */
+const char *
+paste_buffer_name(struct paste_buffer *pb)
+{
+ return (pb->name);
+}
+
+/* Get paste buffer data. */
+const char *
+paste_buffer_data(struct paste_buffer *pb, size_t *size)
+{
+ if (size != NULL)
+ *size = pb->size;
+ return (pb->data);
+}
+
/* Walk paste buffers by name. */
struct paste_buffer *
paste_walk(struct paste_buffer *pb)
@@ -71,13 +99,15 @@ paste_walk(struct paste_buffer *pb)
/* Get the most recent automatic buffer. */
struct paste_buffer *
-paste_get_top(void)
+paste_get_top(const char **name)
{
struct paste_buffer *pb;
pb = RB_MIN(paste_time_tree, &paste_by_time);
if (pb == NULL)
return (NULL);
+ if (name != NULL)
+ *name = pb->name;
return (pb);
}
@@ -87,7 +117,7 @@ paste_free_top(void)
{
struct paste_buffer *pb;
- pb = paste_get_top();
+ pb = paste_get_top(NULL);
if (pb == NULL)
return (-1);
return (paste_free_name(pb->name));
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c
index 950e6f8e67d..4d18ad4037e 100644
--- a/usr.bin/tmux/status.c
+++ b/usr.bin/tmux/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.133 2015/08/28 12:16:28 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.134 2015/08/29 09:25:00 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -815,10 +815,9 @@ status_prompt_key(struct client *c, int key)
struct options *oo = &sess->options;
struct paste_buffer *pb;
char *s, *first, *last, word[64], swapc;
- const char *histstr;
- const char *wsep = NULL;
+ const char *histstr, *bufdata, *wsep = NULL;
u_char ch;
- size_t size, n, off, idx;
+ size_t size, n, off, idx, bufsize;
size = strlen(c->prompt_buffer);
switch (mode_key_lookup(&c->prompt_mdata, key, NULL)) {
@@ -1067,24 +1066,25 @@ status_prompt_key(struct client *c, int key)
c->flags |= CLIENT_STATUS;
break;
case MODEKEYEDIT_PASTE:
- if ((pb = paste_get_top()) == NULL)
+ if ((pb = paste_get_top(NULL)) == NULL)
break;
- for (n = 0; n < pb->size; n++) {
- ch = (u_char) pb->data[n];
+ bufdata = paste_buffer_data(pb, &bufsize);
+ for (n = 0; n < bufsize; n++) {
+ ch = (u_char)bufdata[n];
if (ch < 32 || ch == 127)
break;
}
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);
+ memcpy(c->prompt_buffer + c->prompt_index, bufdata, n);
c->prompt_index += n;
c->prompt_buffer[c->prompt_index] = '\0';
} else {
memmove(c->prompt_buffer + c->prompt_index + n,
c->prompt_buffer + c->prompt_index,
size + 1 - c->prompt_index);
- memcpy(c->prompt_buffer + c->prompt_index, pb->data, n);
+ memcpy(c->prompt_buffer + c->prompt_index, bufdata, n);
c->prompt_index += n;
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index dd8721ae185..83b44192730 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.541 2015/08/29 08:30:54 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.542 2015/08/29 09:25:00 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -957,19 +957,6 @@ struct layout_cell {
TAILQ_ENTRY(layout_cell) entry;
};
-/* Paste buffer. */
-struct paste_buffer {
- char *data;
- size_t size;
-
- char *name;
- int automatic;
- u_int order;
-
- RB_ENTRY(paste_buffer) name_entry;
- RB_ENTRY(paste_buffer) time_entry;
-};
-
/* Environment variable. */
struct environ_entry {
char *name;
@@ -1452,6 +1439,22 @@ void cfg_add_cause(const char *, ...);
void cfg_print_causes(struct cmd_q *);
void cfg_show_causes(struct session *);
+/* paste.c */
+struct paste_buffer;
+const char *paste_buffer_name(struct paste_buffer *);
+const char *paste_buffer_data(struct paste_buffer *, size_t *);
+struct paste_buffer *paste_walk(struct paste_buffer *);
+struct paste_buffer *paste_get_top(const char **);
+struct paste_buffer *paste_get_name(const char *);
+int paste_free_top(void);
+int paste_free_name(const char *);
+void paste_add(char *, size_t);
+int paste_rename(const char *, const char *, char **);
+int paste_set(char *, size_t, const char *, char **);
+char *paste_make_sample(struct paste_buffer *, int);
+void paste_send_pane(struct paste_buffer *, struct window_pane *,
+ const char *, int);
+
/* format.c */
struct format_tree;
struct format_tree *format_create(void);
@@ -1636,19 +1639,6 @@ void tty_keys_build(struct tty *);
void tty_keys_free(struct tty *);
int tty_keys_next(struct tty *);
-/* paste.c */
-struct paste_buffer *paste_walk(struct paste_buffer *);
-struct paste_buffer *paste_get_top(void);
-struct paste_buffer *paste_get_name(const char *);
-int paste_free_top(void);
-int paste_free_name(const char *);
-void paste_add(char *, size_t);
-int paste_rename(const char *, const char *, char **);
-int paste_set(char *, size_t, const char *, char **);
-char *paste_make_sample(struct paste_buffer *, int);
-void paste_send_pane(struct paste_buffer *, struct window_pane *,
- const char *, int);
-
/* arguments.c */
int args_cmp(struct args_entry *, struct args_entry *);
RB_PROTOTYPE(args_tree, args_entry, entry, args_cmp);
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 7695ce1ca07..3fae9aa2cf9 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.131 2015/08/28 12:25:42 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.132 2015/08/29 09:25:00 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -782,7 +782,8 @@ window_copy_key_input(struct window_pane *wp, int key)
{
struct window_copy_mode_data *data = wp->modedata;
struct screen *s = &data->screen;
- size_t inputlen, n;
+ const char *bufdata;
+ size_t inputlen, n, bufsize;
int np;
struct paste_buffer *pb;
u_char ch;
@@ -800,17 +801,18 @@ window_copy_key_input(struct window_pane *wp, int key)
*data->inputstr = '\0';
break;
case MODEKEYEDIT_PASTE:
- if ((pb = paste_get_top()) == NULL)
+ if ((pb = paste_get_top(NULL)) == NULL)
break;
- for (n = 0; n < pb->size; n++) {
- ch = (u_char) pb->data[n];
+ bufdata = paste_buffer_data(pb, &bufsize);
+ for (n = 0; n < bufsize; n++) {
+ ch = (u_char)bufdata[n];
if (ch < 32 || ch == 127)
break;
}
inputlen = strlen(data->inputstr);
data->inputstr = xrealloc(data->inputstr, inputlen + n + 1);
- memcpy(data->inputstr + inputlen, pb->data, n);
+ memcpy(data->inputstr + inputlen, bufdata, n);
data->inputstr[inputlen + n] = '\0';
break;
case MODEKEYEDIT_ENTER:
@@ -1491,7 +1493,8 @@ window_copy_append_selection(struct window_pane *wp, const char *bufname)
{
char *buf;
struct paste_buffer *pb;
- size_t len;
+ const char *bufdata;
+ size_t len, bufsize;
struct screen_write_ctx ctx;
buf = window_copy_get_selection(wp, &len);
@@ -1504,17 +1507,16 @@ window_copy_append_selection(struct window_pane *wp, const char *bufname)
screen_write_stop(&ctx);
}
- if (bufname == NULL || *bufname == '\0') {
- pb = paste_get_top();
- if (pb != NULL)
- bufname = pb->name;
- } else
+ if (bufname == NULL || *bufname == '\0')
+ pb = paste_get_top(&bufname);
+ else
pb = paste_get_name(bufname);
if (pb != NULL) {
- buf = xrealloc(buf, len + pb->size);
- memmove(buf + pb->size, buf, len);
- memcpy(buf, pb->data, pb->size);
- len += pb->size;
+ bufdata = paste_buffer_data(pb, &bufsize);
+ buf = xrealloc(buf, len + bufsize);
+ memmove(buf + bufsize, buf, len);
+ memcpy(buf, bufdata, bufsize);
+ len += bufsize;
}
if (paste_set(buf, len, bufname, NULL) != 0)
free(buf);