From: nicm Date: Fri, 8 May 2015 16:18:04 +0000 (+0000) Subject: Move input parser structs into input.c (removing fairly useless X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=6c01012e1b2514797b55a5c7785e5a5f3e69fa71;p=openbsd Move input parser structs into input.c (removing fairly useless saved_cursor_[xy] formats as a side-effect). --- diff --git a/usr.bin/tmux/cmd-capture-pane.c b/usr.bin/tmux/cmd-capture-pane.c index 957dc47b0ca..14cfabcb934 100644 --- a/usr.bin/tmux/cmd-capture-pane.c +++ b/usr.bin/tmux/cmd-capture-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-capture-pane.c,v 1.31 2015/03/31 17:45:10 nicm Exp $ */ +/* $OpenBSD: cmd-capture-pane.c,v 1.32 2015/05/08 16:18:04 nicm Exp $ */ /* * Copyright (c) 2009 Jonathan Alvarado @@ -57,15 +57,17 @@ char * cmd_capture_pane_pending(struct args *args, struct window_pane *wp, size_t *len) { - char *buf, *line, tmp[5]; - size_t linelen; - u_int i; + struct evbuffer *pending; + char *buf, *line, tmp[5]; + size_t linelen; + u_int i; - if (wp->ictx.since_ground == NULL) + pending = input_pending(wp); + if (pending == NULL) return (xstrdup("")); - line = EVBUFFER_DATA(wp->ictx.since_ground); - linelen = EVBUFFER_LENGTH(wp->ictx.since_ground); + line = EVBUFFER_DATA(pending); + linelen = EVBUFFER_LENGTH(pending); buf = xstrdup(""); if (args_has(args, 'C')) { diff --git a/usr.bin/tmux/cmd-send-keys.c b/usr.bin/tmux/cmd-send-keys.c index 99b574f9d15..fefa6169f72 100644 --- a/usr.bin/tmux/cmd-send-keys.c +++ b/usr.bin/tmux/cmd-send-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-send-keys.c,v 1.19 2015/04/19 21:34:21 nicm Exp $ */ +/* $OpenBSD: cmd-send-keys.c,v 1.20 2015/05/08 16:18:04 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -52,7 +52,6 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq) struct mouse_event *m = &cmdq->item->mouse; struct window_pane *wp; struct session *s; - struct input_ctx *ictx; const u_char *str; int i, key; @@ -78,21 +77,8 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } - if (args_has(args, 'R')) { - ictx = &wp->ictx; - - memcpy(&ictx->cell, &grid_default_cell, sizeof ictx->cell); - memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell); - ictx->old_cx = 0; - ictx->old_cy = 0; - - if (wp->mode == NULL) - screen_write_start(&ictx->ctx, wp, &wp->base); - else - screen_write_start(&ictx->ctx, NULL, &wp->base); - screen_write_reset(&ictx->ctx); - screen_write_stop(&ictx->ctx); - } + if (args_has(args, 'R')) + input_reset(wp); for (i = 0; i < args->argc; i++) { str = args->argv[i]; diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index d3f350d902d..98def9dfe0e 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.64 2015/05/06 08:35:39 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.65 2015/05/08 16:18:04 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -715,8 +715,6 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "cursor_y", "%u", wp->base.cy); format_add(ft, "scroll_region_upper", "%u", wp->base.rupper); format_add(ft, "scroll_region_lower", "%u", wp->base.rlower); - format_add(ft, "saved_cursor_x", "%u", wp->ictx.old_cx); - format_add(ft, "saved_cursor_y", "%u", wp->ictx.old_cy); format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0); format_add(ft, "alternate_saved_x", "%u", wp->saved_cx); diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c index 20a982aa760..2d9f0020f28 100644 --- a/usr.bin/tmux/input.c +++ b/usr.bin/tmux/input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input.c,v 1.73 2015/03/31 17:45:10 nicm Exp $ */ +/* $OpenBSD: input.c,v 1.74 2015/05/08 16:18:04 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -46,6 +46,55 @@ * be passed to the underlying teminal(s). */ +/* Input parser cell. */ +struct input_cell { + struct grid_cell cell; + int set; + int g0set; /* 1 if ACS */ + int g1set; /* 1 if ACS */ +}; + +/* Input parser context. */ +struct input_ctx { + struct window_pane *wp; + struct screen_write_ctx ctx; + + struct input_cell cell; + + struct input_cell old_cell; + u_int old_cx; + u_int old_cy; + + u_char interm_buf[4]; + size_t interm_len; + + u_char param_buf[64]; + size_t param_len; + +#define INPUT_BUF_START 32 +#define INPUT_BUF_LIMIT 1048576 + u_char *input_buf; + size_t input_len; + size_t input_space; + + int param_list[24]; /* -1 not present */ + u_int param_list_len; + + struct utf8_data utf8data; + + int ch; + int flags; +#define INPUT_DISCARD 0x1 + + const struct input_state *state; + + /* + * All input received since we were last in the ground state. Sent to + * control clients on connection. + */ + struct evbuffer *since_ground; +}; + /* Helper functions. */ struct input_transition; int input_split(struct input_ctx *); @@ -706,7 +755,9 @@ input_reset_cell(struct input_ctx *ictx) void input_init(struct window_pane *wp) { - struct input_ctx *ictx = &wp->ictx; + struct input_ctx *ictx; + + ictx = wp->ictx = xcalloc(1, sizeof *ictx); input_reset_cell(ictx); @@ -732,18 +783,46 @@ input_init(struct window_pane *wp) void input_free(struct window_pane *wp) { - if (wp == NULL) - return; + struct input_ctx *ictx = wp->ictx; - free(wp->ictx.input_buf); - evbuffer_free(wp->ictx.since_ground); + free(ictx->input_buf); + evbuffer_free(ictx->since_ground); + + free (ictx); + wp->ictx = NULL; +} + +/* Reset input state and clear screen. */ +void +input_reset(struct window_pane *wp) +{ + struct input_ctx *ictx = wp->ictx; + + memcpy(&ictx->cell, &grid_default_cell, sizeof ictx->cell); + memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell); + ictx->old_cx = 0; + ictx->old_cy = 0; + + if (wp->mode == NULL) + screen_write_start(&ictx->ctx, wp, &wp->base); + else + screen_write_start(&ictx->ctx, NULL, &wp->base); + screen_write_reset(&ictx->ctx); + screen_write_stop(&ictx->ctx); +} + +/* Return pending data. */ +struct evbuffer * +input_pending(struct window_pane *wp) +{ + return (wp->ictx->since_ground); } /* Change input state. */ void input_set_state(struct window_pane *wp, const struct input_transition *itr) { - struct input_ctx *ictx = &wp->ictx; + struct input_ctx *ictx = wp->ictx; if (ictx->state->exit != NULL) ictx->state->exit(ictx); @@ -756,7 +835,7 @@ input_set_state(struct window_pane *wp, const struct input_transition *itr) void input_parse(struct window_pane *wp) { - struct input_ctx *ictx = &wp->ictx; + struct input_ctx *ictx = wp->ictx; const struct input_transition *itr; struct evbuffer *evb = wp->event->input; u_char *buf; diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 7139f384ad5..1b7018bdf93 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.426 2015/05/06 08:35:39 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.427 2015/05/08 16:18:04 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 6 2015 $ +.Dd $Mdocdate: May 8 2015 $ .Dt TMUX 1 .Os .Sh NAME @@ -3318,8 +3318,6 @@ The following variables are available, where appropriate: .It Li "pane_top" Ta "" Ta "Top of pane" .It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane" .It Li "pane_width" Ta "" Ta "Width of pane" -.It Li "saved_cursor_x" Ta "" Ta "Saved cursor X in pane" -.It Li "saved_cursor_y" Ta "" Ta "Saved cursor Y in pane" .It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane" .It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane" .It Li "session_attached" Ta "" Ta "Number of clients session is attached to" diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 798707ebf0b..5e09f9fd719 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.506 2015/05/07 08:08:54 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.507 2015/05/08 16:18:04 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -785,55 +785,6 @@ struct screen_write_ctx { #define screen_hsize(s) ((s)->grid->hsize) #define screen_hlimit(s) ((s)->grid->hlimit) -/* Input parser cell. */ -struct input_cell { - struct grid_cell cell; - int set; - int g0set; /* 1 if ACS */ - int g1set; /* 1 if ACS */ -}; - -/* Input parser context. */ -struct input_ctx { - struct window_pane *wp; - struct screen_write_ctx ctx; - - struct input_cell cell; - - struct input_cell old_cell; - u_int old_cx; - u_int old_cy; - - u_char interm_buf[4]; - size_t interm_len; - - u_char param_buf[64]; - size_t param_len; - -#define INPUT_BUF_START 32 -#define INPUT_BUF_LIMIT 1048576 - u_char *input_buf; - size_t input_len; - size_t input_space; - - int param_list[24]; /* -1 not present */ - u_int param_list_len; - - struct utf8_data utf8data; - - int ch; - int flags; -#define INPUT_DISCARD 0x1 - - const struct input_state *state; - - /* - * All input received since we were last in the ground state. Sent to - * control clients on connection. - */ - struct evbuffer *since_ground; -}; - /* * Window mode. Windows can be in several modes and this is used to call the * right function to handle input and output. @@ -881,6 +832,7 @@ struct window_choose_mode_item { }; /* Child window structure. */ +struct input_ctx; struct window_pane { u_int id; u_int active_point; @@ -920,7 +872,7 @@ struct window_pane { int fd; struct bufferevent *event; - struct input_ctx ictx; + struct input_ctx *ictx; struct grid_cell colgc; @@ -1983,6 +1935,8 @@ void recalculate_sizes(void); /* input.c */ void input_init(struct window_pane *); void input_free(struct window_pane *); +void input_reset(struct window_pane *); +struct evbuffer *input_pending(struct window_pane *); void input_parse(struct window_pane *); /* input-key.c */