From 45b03419fdfe37ed526e33606ab76a879261bcb0 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 7 Feb 2021 19:59:20 +0000 Subject: [PATCH] Remove TermWin's is_utf8 method. All implementations of it work by checking the line_codepage field in the ucsdata structure that the terminal itself already has a pointer to. Therefore, it's a totally unnecessary query function: the terminal can check the same thing directly by inspecting that structure! (In fact, it already _does_ do that, for the purpose of actually deciding how to decode terminal output data. It only uses this query function at all for the auxiliary purpose of inventing useful tty modes to pass to the backend.) --- fuzzterm.c | 2 -- putty.h | 3 --- terminal.c | 2 +- unix/gtkwin.c | 9 +-------- windows/window.c | 7 ------- 5 files changed, 2 insertions(+), 21 deletions(-) diff --git a/fuzzterm.c b/fuzzterm.c index cfb80a63..c1fc2b3c 100644 --- a/fuzzterm.c +++ b/fuzzterm.c @@ -99,7 +99,6 @@ static void fuzz_palette_reset(TermWin *tw) {} static void fuzz_get_pos(TermWin *tw, int *x, int *y) { *x = *y = 0; } static void fuzz_get_pixels(TermWin *tw, int *x, int *y) { *x = *y = 0; } static const char *fuzz_get_title(TermWin *tw, bool icon) { return "moo"; } -static bool fuzz_is_utf8(TermWin *tw) { return true; } static const TermWinVtable fuzz_termwin_vt = { .setup_draw_ctx = fuzz_setup_draw_ctx, @@ -129,7 +128,6 @@ static const TermWinVtable fuzz_termwin_vt = { .get_pos = fuzz_get_pos, .get_pixels = fuzz_get_pixels, .get_title = fuzz_get_title, - .is_utf8 = fuzz_is_utf8, }; void ldisc_send(Ldisc *ldisc, const void *buf, int len, bool interactive) {} diff --git a/putty.h b/putty.h index 8e8c5236..44aea084 100644 --- a/putty.h +++ b/putty.h @@ -1150,7 +1150,6 @@ struct TermWinVtable { void (*get_pos)(TermWin *, int *x, int *y); void (*get_pixels)(TermWin *, int *x, int *y); const char *(*get_title)(TermWin *, bool icon); - bool (*is_utf8)(TermWin *); }; static inline bool win_setup_draw_ctx(TermWin *win) @@ -1213,8 +1212,6 @@ static inline void win_get_pixels(TermWin *win, int *x, int *y) { win->vt->get_pixels(win, x, y); } static inline const char *win_get_title(TermWin *win, bool icon) { return win->vt->get_title(win, icon); } -static inline bool win_is_utf8(TermWin *win) -{ return win->vt->is_utf8(win); } /* * Global functions not specific to a connection instance. diff --git a/terminal.c b/terminal.c index d025a448..46d9bd16 100644 --- a/terminal.c +++ b/terminal.c @@ -7138,7 +7138,7 @@ char *term_get_ttymode(Terminal *term, const char *mode) if (strcmp(mode, "ERASE") == 0) { val = term->bksp_is_delete ? "^?" : "^H"; } else if (strcmp(mode, "IUTF8") == 0) { - val = win_is_utf8(term->win) ? "yes" : "no"; + val = (term->ucsdata->line_codepage == CP_UTF8) ? "yes" : "no"; } /* FIXME: perhaps we should set ONLCR based on lfhascr as well? */ /* FIXME: or ECHO and friends based on local echo state? */ diff --git a/unix/gtkwin.c b/unix/gtkwin.c index b2196107..abc53fed 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -348,7 +348,7 @@ static int gtk_seat_get_userpass_input(Seat *seat, prompts_t *p, static bool gtk_seat_is_utf8(Seat *seat) { GtkFrontend *inst = container_of(seat, GtkFrontend, seat); - return win_is_utf8(&inst->termwin); + return inst->ucsdata.line_codepage == CS_UTF8; } static bool gtk_seat_get_window_pixel_size(Seat *seat, int *w, int *h) @@ -4251,12 +4251,6 @@ static bool gtk_seat_get_windowid(Seat *seat, long *id) } #endif -static bool gtkwin_is_utf8(TermWin *tw) -{ - GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); - return inst->ucsdata.line_codepage == CS_UTF8; -} - char *setup_fonts_ucs(GtkFrontend *inst) { bool shadowbold = conf_get_bool(inst->conf, CONF_shadowbold); @@ -5197,7 +5191,6 @@ static const TermWinVtable gtk_termwin_vt = { .get_pos = gtkwin_get_pos, .get_pixels = gtkwin_get_pixels, .get_title = gtkwin_get_title, - .is_utf8 = gtkwin_is_utf8, }; void new_session_window(Conf *conf, const char *geometry_string) diff --git a/windows/window.c b/windows/window.c index cae0172d..e3c810ef 100644 --- a/windows/window.c +++ b/windows/window.c @@ -254,7 +254,6 @@ static void wintw_palette_reset(TermWin *); static void wintw_get_pos(TermWin *, int *x, int *y); static void wintw_get_pixels(TermWin *, int *x, int *y); static const char *wintw_get_title(TermWin *, bool icon); -static bool wintw_is_utf8(TermWin *); static const TermWinVtable windows_termwin_vt = { .setup_draw_ctx = wintw_setup_draw_ctx, @@ -284,7 +283,6 @@ static const TermWinVtable windows_termwin_vt = { .get_pos = wintw_get_pos, .get_pixels = wintw_get_pixels, .get_title = wintw_get_title, - .is_utf8 = wintw_is_utf8, }; static TermWin wintw[1]; @@ -300,11 +298,6 @@ static bool is_utf8(void) return ucsdata.line_codepage == CP_UTF8; } -static bool wintw_is_utf8(TermWin *tw) -{ - return is_utf8(); -} - static bool win_seat_is_utf8(Seat *seat) { return is_utf8();