to be global. Move to paste.c.
-/* $OpenBSD: cmd-capture-pane.c,v 1.25 2013/10/10 12:00:18 nicm Exp $ */
+/* $OpenBSD: cmd-capture-pane.c,v 1.26 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
} else {
limit = options_get_number(&global_options, "buffer-limit");
if (!args_has(args, 'b')) {
- paste_add(&global_buffers, buf, len, limit);
+ paste_add(buf, len, limit);
return (CMD_RETURN_NORMAL);
}
return (CMD_RETURN_ERROR);
}
- if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
+ if (paste_replace(buffer, buf, len) != 0) {
cmdq_error(cmdq, "no buffer %d", buffer);
free(buf);
return (CMD_RETURN_ERROR);
-/* $OpenBSD: cmd-choose-buffer.c,v 1.16 2014/04/02 18:12:18 nicm Exp $ */
+/* $OpenBSD: cmd-choose-buffer.c,v 1.17 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
return (CMD_RETURN_ERROR);
utf8flag = options_get_number(&wl->window->options, "utf8");
- if (paste_get_top(&global_buffers) == NULL)
+ if (paste_get_top() == NULL)
return (CMD_RETURN_NORMAL);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
action = xstrdup("paste-buffer -b '%%'");
idx = 0;
- while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
+ while ((pb = paste_walk_stack(&idx)) != NULL) {
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
cdata->idx = idx - 1;
-/* $OpenBSD: cmd-delete-buffer.c,v 1.10 2013/10/10 12:00:19 nicm Exp $ */
+/* $OpenBSD: cmd-delete-buffer.c,v 1.11 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
int buffer;
if (!args_has(args, 'b')) {
- paste_free_top(&global_buffers);
+ paste_free_top();
return (CMD_RETURN_NORMAL);
}
return (CMD_RETURN_ERROR);
}
- if (paste_free_index(&global_buffers, buffer) != 0) {
+ if (paste_free_index(buffer) != 0) {
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
-/* $OpenBSD: cmd-list-buffers.c,v 1.19 2014/04/02 18:12:18 nicm Exp $ */
+/* $OpenBSD: cmd-list-buffers.c,v 1.20 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
template = LIST_BUFFERS_TEMPLATE;
idx = 0;
- while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
+ while ((pb = paste_walk_stack(&idx)) != NULL) {
ft = format_create();
format_add(ft, "line", "%u", idx - 1);
format_paste_buffer(ft, pb, 0);
-/* $OpenBSD: cmd-load-buffer.c,v 1.27 2014/02/17 23:07:03 nicm Exp $ */
+/* $OpenBSD: cmd-load-buffer.c,v 1.28 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
limit = options_get_number(&global_options, "buffer-limit");
if (buffer == -1) {
- paste_add(&global_buffers, pdata, psize, limit);
+ paste_add(pdata, psize, limit);
return (CMD_RETURN_NORMAL);
}
- if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
+ if (paste_replace(buffer, pdata, psize) != 0) {
cmdq_error(cmdq, "no buffer %d", buffer);
free(pdata);
return (CMD_RETURN_ERROR);
limit = options_get_number(&global_options, "buffer-limit");
if (*buffer == -1)
- paste_add(&global_buffers, pdata, psize, limit);
- else if (paste_replace(&global_buffers, *buffer, pdata, psize) != 0) {
+ paste_add(pdata, psize, limit);
+ else if (paste_replace(*buffer, pdata, psize) != 0) {
/* No context so can't use server_client_msg_error. */
evbuffer_add_printf(c->stderr_data, "no buffer %d\n", *buffer);
server_push_stderr(c);
-/* $OpenBSD: cmd-paste-buffer.c,v 1.23 2013/10/10 12:00:21 nicm Exp $ */
+/* $OpenBSD: cmd-paste-buffer.c,v 1.24 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
}
if (buffer == -1)
- pb = paste_get_top(&global_buffers);
+ pb = paste_get_top();
else {
- pb = paste_get_index(&global_buffers, buffer);
+ pb = paste_get_index(buffer);
if (pb == NULL) {
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
/* Delete the buffer if -d. */
if (args_has(args, 'd')) {
if (buffer == -1)
- paste_free_top(&global_buffers);
+ paste_free_top();
else
- paste_free_index(&global_buffers, buffer);
+ paste_free_index(buffer);
}
return (CMD_RETURN_NORMAL);
-/* $OpenBSD: cmd-save-buffer.c,v 1.23 2014/04/16 23:05:38 nicm Exp $ */
+/* $OpenBSD: cmd-save-buffer.c,v 1.24 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
FILE *f;
if (!args_has(args, 'b')) {
- if ((pb = paste_get_top(&global_buffers)) == NULL) {
+ if ((pb = paste_get_top()) == NULL) {
cmdq_error(cmdq, "no buffers");
return (CMD_RETURN_ERROR);
}
return (CMD_RETURN_ERROR);
}
- pb = paste_get_index(&global_buffers, buffer);
+ pb = paste_get_index(buffer);
if (pb == NULL) {
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
-/* $OpenBSD: cmd-set-buffer.c,v 1.16 2014/03/31 21:43:55 nicm Exp $ */
+/* $OpenBSD: cmd-set-buffer.c,v 1.17 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
free(cause);
return (CMD_RETURN_ERROR);
}
- pb = paste_get_index(&global_buffers, buffer);
+ pb = paste_get_index(buffer);
if (pb == NULL) {
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
} else if (args_has(args, 'a')) {
- pb = paste_get_top(&global_buffers);
+ pb = paste_get_top();
if (pb != NULL)
buffer = 0;
}
psize += newsize;
if (buffer == -1)
- paste_add(&global_buffers, pdata, psize, limit);
+ paste_add(pdata, psize, limit);
else
- paste_replace(&global_buffers, buffer, pdata, psize);
+ paste_replace(buffer, pdata, psize);
return (CMD_RETURN_NORMAL);
}
-/* $OpenBSD: input-keys.c,v 1.35 2014/04/03 08:15:17 nicm Exp $ */
+/* $OpenBSD: input-keys.c,v 1.36 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
if (m->button == 1 && (m->event & MOUSE_EVENT_CLICK) &&
options_get_number(&wp->window->options, "mode-mouse") == 1) {
- pb = paste_get_top(&global_buffers);
+ pb = paste_get_top();
if (pb != NULL) {
paste_send_pane(pb, wp, "\r",
wp->screen->mode & MODE_BRACKETPASTE);
-/* $OpenBSD: paste.c,v 1.17 2014/04/02 18:12:18 nicm Exp $ */
+/* $OpenBSD: paste.c,v 1.18 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
* string!
*/
+ARRAY_DECL(, struct paste_buffer *) paste_buffers = ARRAY_INITIALIZER;
+
/* Return each item of the stack in turn. */
struct paste_buffer *
-paste_walk_stack(struct paste_stack *ps, u_int *idx)
+paste_walk_stack(u_int *idx)
{
struct paste_buffer *pb;
- pb = paste_get_index(ps, *idx);
+ pb = paste_get_index(*idx);
(*idx)++;
return (pb);
}
/* Get the top item on the stack. */
struct paste_buffer *
-paste_get_top(struct paste_stack *ps)
+paste_get_top(void)
{
- if (ARRAY_LENGTH(ps) == 0)
+ if (ARRAY_LENGTH(&paste_buffers) == 0)
return (NULL);
- return (ARRAY_FIRST(ps));
+ return (ARRAY_FIRST(&paste_buffers));
}
/* Get an item by its index. */
struct paste_buffer *
-paste_get_index(struct paste_stack *ps, u_int idx)
+paste_get_index(u_int idx)
{
- if (idx >= ARRAY_LENGTH(ps))
+ if (idx >= ARRAY_LENGTH(&paste_buffers))
return (NULL);
- return (ARRAY_ITEM(ps, idx));
+ return (ARRAY_ITEM(&paste_buffers, idx));
}
/* Free the top item on the stack. */
int
-paste_free_top(struct paste_stack *ps)
+paste_free_top(void)
{
struct paste_buffer *pb;
- if (ARRAY_LENGTH(ps) == 0)
+ if (ARRAY_LENGTH(&paste_buffers) == 0)
return (-1);
- pb = ARRAY_FIRST(ps);
- ARRAY_REMOVE(ps, 0);
+ pb = ARRAY_FIRST(&paste_buffers);
+ ARRAY_REMOVE(&paste_buffers, 0);
free(pb->data);
free(pb);
/* Free an item by index. */
int
-paste_free_index(struct paste_stack *ps, u_int idx)
+paste_free_index(u_int idx)
{
struct paste_buffer *pb;
- if (idx >= ARRAY_LENGTH(ps))
+ if (idx >= ARRAY_LENGTH(&paste_buffers))
return (-1);
- pb = ARRAY_ITEM(ps, idx);
- ARRAY_REMOVE(ps, idx);
+ pb = ARRAY_ITEM(&paste_buffers, idx);
+ ARRAY_REMOVE(&paste_buffers, idx);
free(pb->data);
free(pb);
* that the caller is responsible for allocating data.
*/
void
-paste_add(struct paste_stack *ps, char *data, size_t size, u_int limit)
+paste_add(char *data, size_t size, u_int limit)
{
struct paste_buffer *pb;
if (size == 0)
return;
- while (ARRAY_LENGTH(ps) >= limit) {
- pb = ARRAY_LAST(ps);
+ while (ARRAY_LENGTH(&paste_buffers) >= limit) {
+ pb = ARRAY_LAST(&paste_buffers);
free(pb->data);
free(pb);
- ARRAY_TRUNC(ps, 1);
+ ARRAY_TRUNC(&paste_buffers, 1);
}
pb = xmalloc(sizeof *pb);
- ARRAY_INSERT(ps, 0, pb);
+ ARRAY_INSERT(&paste_buffers, 0, pb);
pb->data = data;
pb->size = size;
* allocating data.
*/
int
-paste_replace(struct paste_stack *ps, u_int idx, char *data, size_t size)
+paste_replace(u_int idx, char *data, size_t size)
{
struct paste_buffer *pb;
return (0);
}
- if (idx >= ARRAY_LENGTH(ps))
+ if (idx >= ARRAY_LENGTH(&paste_buffers))
return (-1);
- pb = ARRAY_ITEM(ps, idx);
+ pb = ARRAY_ITEM(&paste_buffers, idx);
free(pb->data);
pb->data = data;
-/* $OpenBSD: server.c,v 1.112 2014/04/17 14:45:49 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.113 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
struct event server_ev_accept;
struct event server_ev_second;
-struct paste_stack global_buffers;
-
int server_create_socket(void);
void server_loop(void);
int server_should_shutdown(void);
RB_INIT(&sessions);
RB_INIT(&dead_sessions);
TAILQ_INIT(&session_groups);
- ARRAY_INIT(&global_buffers);
mode_key_init_trees();
key_bindings_init();
utf8_build();
-/* $OpenBSD: status.c,v 1.113 2014/04/17 07:36:45 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.114 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
c->flags |= CLIENT_STATUS;
break;
case MODEKEYEDIT_PASTE:
- if ((pb = paste_get_top(&global_buffers)) == NULL)
+ if ((pb = paste_get_top()) == NULL)
break;
for (n = 0; n < pb->size; n++) {
ch = (u_char) pb->data[n];
-/* $OpenBSD: tmux.h,v 1.456 2014/04/17 15:37:55 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.457 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
char *data;
size_t size;
};
-ARRAY_DECL(paste_stack, struct paste_buffer *);
/* Environment variable. */
struct environ_entry {
int tty_keys_next(struct tty *);
/* paste.c */
-struct paste_buffer *paste_walk_stack(struct paste_stack *, u_int *);
-struct paste_buffer *paste_get_top(struct paste_stack *);
-struct paste_buffer *paste_get_index(struct paste_stack *, u_int);
-int paste_free_top(struct paste_stack *);
-int paste_free_index(struct paste_stack *, u_int);
-void paste_add(struct paste_stack *, char *, size_t, u_int);
-int paste_replace(struct paste_stack *, u_int, char *, size_t);
+struct paste_buffer *paste_walk_stack(u_int *);
+struct paste_buffer *paste_get_top(void);
+struct paste_buffer *paste_get_index(u_int);
+int paste_free_top(void);
+int paste_free_index(u_int);
+void paste_add(char *, size_t, u_int);
+int paste_replace(u_int, char *, size_t);
char *paste_make_sample(struct paste_buffer *, int);
void paste_send_pane(struct paste_buffer *, struct window_pane *,
const char *, int);
/* server.c */
extern struct clients clients;
extern struct clients dead_clients;
-extern struct paste_stack global_buffers;
int server_start(int, char *);
void server_update_socket(void);
void server_add_accept(int);
-/* $OpenBSD: window-copy.c,v 1.106 2014/04/17 14:45:49 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.107 2014/04/24 09:14:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*data->inputstr = '\0';
break;
case MODEKEYEDIT_PASTE:
- if ((pb = paste_get_top(&global_buffers)) == NULL)
+ if ((pb = paste_get_top()) == NULL)
break;
for (n = 0; n < pb->size; n++) {
ch = (u_char) pb->data[n];
if (idx == -1) {
limit = options_get_number(&global_options, "buffer-limit");
- paste_add(&global_buffers, buf, len, limit);
- } else if (paste_replace(&global_buffers, idx, buf, len) != 0)
+ paste_add(buf, len, limit);
+ } else if (paste_replace(idx, buf, len) != 0)
free(buf);
}
if (idx == -1)
idx = 0;
- if (idx == 0 && paste_get_top(&global_buffers) == NULL) {
+ if (idx == 0 && paste_get_top() == NULL) {
limit = options_get_number(&global_options, "buffer-limit");
- paste_add(&global_buffers, buf, len, limit);
+ paste_add(buf, len, limit);
return;
}
- pb = paste_get_index(&global_buffers, idx);
+ pb = paste_get_index(idx);
if (pb != NULL) {
buf = xrealloc(buf, 1, len + pb->size);
memmove(buf + pb->size, buf, len);
len += pb->size;
}
- if (paste_replace(&global_buffers, idx, buf, len) != 0)
+ if (paste_replace(idx, buf, len) != 0)
free(buf);
}