From f3f534a3a0361ed11d0fc455f9a42ba82e6aa471 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 12 Mar 2019 18:26:57 +0000 Subject: [PATCH] Tidy up a lot of &ictx->ctx by using a local variable. --- input.c | 149 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 79 insertions(+), 70 deletions(-) diff --git a/input.c b/input.c index 73bd099b..0503c52a 100644 --- a/input.c +++ b/input.c @@ -801,16 +801,17 @@ void input_reset(struct window_pane *wp, int clear) { struct input_ctx *ictx = wp->ictx; + struct screen_write_ctx *sctx = &ictx->ctx; input_reset_cell(ictx); if (clear) { if (TAILQ_EMPTY(&wp->modes)) - screen_write_start(&ictx->ctx, wp, &wp->base); + screen_write_start(sctx, wp, &wp->base); else - screen_write_start(&ictx->ctx, NULL, &wp->base); - screen_write_reset(&ictx->ctx); - screen_write_stop(&ictx->ctx); + screen_write_start(sctx, NULL, &wp->base); + screen_write_reset(sctx); + screen_write_stop(sctx); } input_clear(ictx); @@ -846,6 +847,7 @@ void input_parse(struct window_pane *wp) { struct input_ctx *ictx = wp->ictx; + struct screen_write_ctx *sctx = &ictx->ctx; const struct input_transition *itr; struct evbuffer *evb = wp->event->input; u_char *buf; @@ -862,9 +864,9 @@ input_parse(struct window_pane *wp) * update the tty. */ if (TAILQ_EMPTY(&wp->modes)) - screen_write_start(&ictx->ctx, wp, &wp->base); + screen_write_start(sctx, wp, &wp->base); else - screen_write_start(&ictx->ctx, NULL, &wp->base); + screen_write_start(sctx, NULL, &wp->base); ictx->wp = wp; buf = EVBUFFER_DATA(evb); @@ -900,7 +902,7 @@ input_parse(struct window_pane *wp) * be the minority. */ if (itr->handler != input_print) - screen_write_collect_end(&ictx->ctx); + screen_write_collect_end(sctx); /* * Execute the handler, if any. Don't switch state if it @@ -919,7 +921,7 @@ input_parse(struct window_pane *wp) } /* Close the screen. */ - screen_write_stop(&ictx->ctx); + screen_write_stop(sctx); evbuffer_drain(evb, len); } @@ -1048,7 +1050,8 @@ input_ground(struct input_ctx *ictx) static int input_print(struct input_ctx *ictx) { - int set; + struct screen_write_ctx *sctx = &ictx->ctx; + int set; ictx->utf8started = 0; /* can't be valid UTF-8 */ @@ -1059,7 +1062,7 @@ input_print(struct input_ctx *ictx) ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET; utf8_set(&ictx->cell.cell.data, ictx->ch); - screen_write_collect_add(&ictx->ctx, &ictx->cell.cell); + screen_write_collect_add(sctx, &ictx->cell.cell); ictx->last = ictx->ch; ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET; @@ -1533,17 +1536,18 @@ input_csi_dispatch(struct input_ctx *ictx) static void input_csi_dispatch_rm(struct input_ctx *ictx) { - u_int i; + struct screen_write_ctx *sctx = &ictx->ctx; + u_int i; for (i = 0; i < ictx->param_list_len; i++) { switch (input_get(ictx, i, 0, -1)) { case -1: break; case 4: /* IRM */ - screen_write_mode_clear(&ictx->ctx, MODE_INSERT); + screen_write_mode_clear(sctx, MODE_INSERT); break; case 34: - screen_write_mode_set(&ictx->ctx, MODE_BLINKING); + screen_write_mode_set(sctx, MODE_BLINKING); break; default: log_debug("%s: unknown '%c'", __func__, ictx->ch); @@ -1556,6 +1560,7 @@ input_csi_dispatch_rm(struct input_ctx *ictx) static void input_csi_dispatch_rm_private(struct input_ctx *ictx) { + struct screen_write_ctx *sctx = &ictx->ctx; struct window_pane *wp = ictx->wp; u_int i; @@ -1564,40 +1569,39 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx) case -1: break; case 1: /* DECCKM */ - screen_write_mode_clear(&ictx->ctx, MODE_KCURSOR); + screen_write_mode_clear(sctx, MODE_KCURSOR); break; case 3: /* DECCOLM */ - screen_write_cursormove(&ictx->ctx, 0, 0); - screen_write_clearscreen(&ictx->ctx, - ictx->cell.cell.bg); + screen_write_cursormove(sctx, 0, 0); + screen_write_clearscreen(sctx, ictx->cell.cell.bg); break; case 6: /* DECOM */ - screen_write_mode_clear(&ictx->ctx, MODE_ORIGIN); - screen_write_cursormove(&ictx->ctx, 0, 0); + screen_write_mode_clear(sctx, MODE_ORIGIN); + screen_write_cursormove(sctx, 0, 0); break; case 7: /* DECAWM */ - screen_write_mode_clear(&ictx->ctx, MODE_WRAP); + screen_write_mode_clear(sctx, MODE_WRAP); break; case 12: - screen_write_mode_clear(&ictx->ctx, MODE_BLINKING); + screen_write_mode_clear(sctx, MODE_BLINKING); break; case 25: /* TCEM */ - screen_write_mode_clear(&ictx->ctx, MODE_CURSOR); + screen_write_mode_clear(sctx, MODE_CURSOR); break; case 1000: case 1001: case 1002: case 1003: - screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES); + screen_write_mode_clear(sctx, ALL_MOUSE_MODES); break; case 1004: - screen_write_mode_clear(&ictx->ctx, MODE_FOCUSON); + screen_write_mode_clear(sctx, MODE_FOCUSON); break; case 1005: - screen_write_mode_clear(&ictx->ctx, MODE_MOUSE_UTF8); + screen_write_mode_clear(sctx, MODE_MOUSE_UTF8); break; case 1006: - screen_write_mode_clear(&ictx->ctx, MODE_MOUSE_SGR); + screen_write_mode_clear(sctx, MODE_MOUSE_SGR); break; case 47: case 1047: @@ -1607,7 +1611,7 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx) window_pane_alternate_off(wp, &ictx->cell.cell, 1); break; case 2004: - screen_write_mode_clear(&ictx->ctx, MODE_BRACKETPASTE); + screen_write_mode_clear(sctx, MODE_BRACKETPASTE); break; default: log_debug("%s: unknown '%c'", __func__, ictx->ch); @@ -1620,17 +1624,18 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx) static void input_csi_dispatch_sm(struct input_ctx *ictx) { - u_int i; + struct screen_write_ctx *sctx = &ictx->ctx; + u_int i; for (i = 0; i < ictx->param_list_len; i++) { switch (input_get(ictx, i, 0, -1)) { case -1: break; case 4: /* IRM */ - screen_write_mode_set(&ictx->ctx, MODE_INSERT); + screen_write_mode_set(sctx, MODE_INSERT); break; case 34: - screen_write_mode_clear(&ictx->ctx, MODE_BLINKING); + screen_write_mode_clear(sctx, MODE_BLINKING); break; default: log_debug("%s: unknown '%c'", __func__, ictx->ch); @@ -1643,6 +1648,7 @@ input_csi_dispatch_sm(struct input_ctx *ictx) static void input_csi_dispatch_sm_private(struct input_ctx *ictx) { + struct screen_write_ctx *sctx = &ictx->ctx; struct window_pane *wp = ictx->wp; u_int i; @@ -1651,49 +1657,48 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx) case -1: break; case 1: /* DECCKM */ - screen_write_mode_set(&ictx->ctx, MODE_KCURSOR); + screen_write_mode_set(sctx, MODE_KCURSOR); break; case 3: /* DECCOLM */ - screen_write_cursormove(&ictx->ctx, 0, 0); - screen_write_clearscreen(&ictx->ctx, - ictx->cell.cell.bg); + screen_write_cursormove(sctx, 0, 0); + screen_write_clearscreen(sctx, ictx->cell.cell.bg); break; case 6: /* DECOM */ - screen_write_mode_set(&ictx->ctx, MODE_ORIGIN); - screen_write_cursormove(&ictx->ctx, 0, 0); + screen_write_mode_set(sctx, MODE_ORIGIN); + screen_write_cursormove(sctx, 0, 0); break; case 7: /* DECAWM */ - screen_write_mode_set(&ictx->ctx, MODE_WRAP); + screen_write_mode_set(sctx, MODE_WRAP); break; case 12: - screen_write_mode_set(&ictx->ctx, MODE_BLINKING); + screen_write_mode_set(sctx, MODE_BLINKING); break; case 25: /* TCEM */ - screen_write_mode_set(&ictx->ctx, MODE_CURSOR); + screen_write_mode_set(sctx, MODE_CURSOR); break; case 1000: - screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES); - screen_write_mode_set(&ictx->ctx, MODE_MOUSE_STANDARD); + screen_write_mode_clear(sctx, ALL_MOUSE_MODES); + screen_write_mode_set(sctx, MODE_MOUSE_STANDARD); break; case 1002: - screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES); - screen_write_mode_set(&ictx->ctx, MODE_MOUSE_BUTTON); + screen_write_mode_clear(sctx, ALL_MOUSE_MODES); + screen_write_mode_set(sctx, MODE_MOUSE_BUTTON); break; case 1003: - screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES); - screen_write_mode_set(&ictx->ctx, MODE_MOUSE_ALL); + screen_write_mode_clear(sctx, ALL_MOUSE_MODES); + screen_write_mode_set(sctx, MODE_MOUSE_ALL); break; case 1004: - if (ictx->ctx.s->mode & MODE_FOCUSON) + if (sctx->s->mode & MODE_FOCUSON) break; - screen_write_mode_set(&ictx->ctx, MODE_FOCUSON); + screen_write_mode_set(sctx, MODE_FOCUSON); wp->flags |= PANE_FOCUSPUSH; /* force update */ break; case 1005: - screen_write_mode_set(&ictx->ctx, MODE_MOUSE_UTF8); + screen_write_mode_set(sctx, MODE_MOUSE_UTF8); break; case 1006: - screen_write_mode_set(&ictx->ctx, MODE_MOUSE_SGR); + screen_write_mode_set(sctx, MODE_MOUSE_SGR); break; case 47: case 1047: @@ -1703,7 +1708,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx) window_pane_alternate_on(wp, &ictx->cell.cell, 1); break; case 2004: - screen_write_mode_set(&ictx->ctx, MODE_BRACKETPASTE); + screen_write_mode_set(sctx, MODE_BRACKETPASTE); break; default: log_debug("%s: unknown '%c'", __func__, ictx->ch); @@ -1716,6 +1721,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx) static void input_csi_dispatch_winops(struct input_ctx *ictx) { + struct screen_write_ctx *sctx = &ictx->ctx; struct window_pane *wp = ictx->wp; int n, m; @@ -1755,7 +1761,7 @@ input_csi_dispatch_winops(struct input_ctx *ictx) return; case 0: case 2: - screen_push_title(ictx->ctx.s); + screen_push_title(sctx->s); break; } break; @@ -1766,7 +1772,7 @@ input_csi_dispatch_winops(struct input_ctx *ictx) return; case 0: case 2: - screen_pop_title(ictx->ctx.s); + screen_pop_title(sctx->s); server_status_window(ictx->wp->window); break; } @@ -2089,20 +2095,19 @@ input_enter_dcs(struct input_ctx *ictx) static int input_dcs_dispatch(struct input_ctx *ictx) { - const char prefix[] = "tmux;"; - const u_int prefix_len = (sizeof prefix) - 1; + struct screen_write_ctx *sctx = &ictx->ctx; + u_char *buf = ictx->input_buf; + size_t len = ictx->input_len; + const char prefix[] = "tmux;"; + const u_int prefixlen = (sizeof prefix) - 1; if (ictx->flags & INPUT_DISCARD) return (0); - log_debug("%s: \"%s\"", __func__, ictx->input_buf); + log_debug("%s: \"%s\"", __func__, buf); - /* Check for tmux prefix. */ - if (ictx->input_len >= prefix_len && - strncmp(ictx->input_buf, prefix, prefix_len) == 0) { - screen_write_rawstring(&ictx->ctx, - ictx->input_buf + prefix_len, ictx->input_len - prefix_len); - } + if (len >= prefixlen && strncmp(buf, prefix, prefixlen) == 0) + screen_write_rawstring(sctx, buf + prefixlen, len - prefixlen); return (0); } @@ -2122,8 +2127,9 @@ input_enter_osc(struct input_ctx *ictx) static void input_exit_osc(struct input_ctx *ictx) { - u_char *p = ictx->input_buf; - u_int option; + struct screen_write_ctx *sctx = &ictx->ctx; + u_char *p = ictx->input_buf; + u_int option; if (ictx->flags & INPUT_DISCARD) return; @@ -2143,7 +2149,7 @@ input_exit_osc(struct input_ctx *ictx) case 0: case 2: if (utf8_isvalid(p)) { - screen_set_title(ictx->ctx.s, p); + screen_set_title(sctx->s, p); server_status_window(ictx->wp->window); } break; @@ -2158,7 +2164,7 @@ input_exit_osc(struct input_ctx *ictx) break; case 12: if (utf8_isvalid(p) && *p != '?') /* ? is colour request */ - screen_set_cursor_colour(ictx->ctx.s, p); + screen_set_cursor_colour(sctx->s, p); break; case 52: input_osc_52(ictx, p); @@ -2168,7 +2174,7 @@ input_exit_osc(struct input_ctx *ictx) break; case 112: if (*p == '\0') /* no arguments allowed */ - screen_set_cursor_colour(ictx->ctx.s, ""); + screen_set_cursor_colour(sctx->s, ""); break; default: log_debug("%s: unknown '%u'", __func__, option); @@ -2191,13 +2197,15 @@ input_enter_apc(struct input_ctx *ictx) static void input_exit_apc(struct input_ctx *ictx) { + struct screen_write_ctx *sctx = &ictx->ctx; + if (ictx->flags & INPUT_DISCARD) return; log_debug("%s: \"%s\"", __func__, ictx->input_buf); if (!utf8_isvalid(ictx->input_buf)) return; - screen_set_title(ictx->ctx.s, ictx->input_buf); + screen_set_title(sctx->s, ictx->input_buf); server_status_window(ictx->wp->window); } @@ -2233,6 +2241,7 @@ input_exit_rename(struct input_ctx *ictx) static int input_top_bit_set(struct input_ctx *ictx) { + struct screen_write_ctx *sctx = &ictx->ctx; struct utf8_data *ud = &ictx->utf8data; ictx->last = -1; @@ -2259,7 +2268,7 @@ input_top_bit_set(struct input_ctx *ictx) (int)ud->size, ud->data, ud->width); utf8_copy(&ictx->cell.cell.data, ud); - screen_write_collect_add(&ictx->ctx, &ictx->cell.cell); + screen_write_collect_add(sctx, &ictx->cell.cell); return (0); } @@ -2270,7 +2279,7 @@ input_osc_4(struct input_ctx *ictx, const char *p) { struct window_pane *wp = ictx->wp; char *copy, *s, *next = NULL; - long idx; + long idx; u_int r, g, b; copy = s = xstrdup(p); @@ -2410,7 +2419,7 @@ input_osc_104(struct input_ctx *ictx, const char *p) { struct window_pane *wp = ictx->wp; char *copy, *s; - long idx; + long idx; if (*p == '\0') { window_pane_reset_palette(wp);