From edce3fb9da091f94960b5207d83de9fa7ac60f0c Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 18 Feb 2023 14:10:01 +0000 Subject: [PATCH] Add platform-independent Unicode setup function. Similarly to the one I just added for FontSpec: in a cross-platform main source file, you don't really want to mess about with per-platform ifdefs just to initialise a 'struct unicode_data' from a Conf. But until now, you had to, because init_ucs had a different prototype on Windows and Unix. I plan to use this in future test programs. But an immediate positive effect is that it removes the only platform-dependent call from fuzzterm.c. So now that could be built on Windows too, given only an appropriate cmake stanza. (Not that I have much idea if it's useful to fuzz the terminal separately on multiple platforms, but it's nice to know that it's possible if anyone does need to.) --- putty.h | 5 +++++ test/fuzzterm.c | 4 +--- unix/unicode.c | 7 +++++++ windows/unicode.c | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/putty.h b/putty.h index 6132327f..f51ce449 100644 --- a/putty.h +++ b/putty.h @@ -286,6 +286,11 @@ struct unicode_data { #define LGTYP_PACKETS 3 /* logmode: SSH data packets */ #define LGTYP_SSHRAW 4 /* logmode: SSH raw data */ +/* Platform-generic function to set up a struct unicode_data. This is + * only likely to be useful to test programs; real clients will want + * to use the more flexible per-platform setup functions. */ +void init_ucs_generic(Conf *conf, struct unicode_data *ucsdata); + /* * Enumeration of 'special commands' that can be sent during a * session, separately from the byte stream of ordinary session data. diff --git a/test/fuzzterm.c b/test/fuzzterm.c index ae838651..291ded6c 100644 --- a/test/fuzzterm.c +++ b/test/fuzzterm.c @@ -21,9 +21,7 @@ int main(int argc, char **argv) conf = conf_new(); do_defaults(NULL, conf); - init_ucs(&ucsdata, conf_get_str(conf, CONF_line_codepage), - conf_get_bool(conf, CONF_utf8_override), - CS_NONE, conf_get_int(conf, CONF_vtmode)); + init_ucs_generic(conf, &ucsdata); term = term_init(conf, &ucsdata, &termwin); term_size(term, 24, 80, 10000); diff --git a/unix/unicode.c b/unix/unicode.c index a98c8d3b..7be64a53 100644 --- a/unix/unicode.c +++ b/unix/unicode.c @@ -243,6 +243,13 @@ bool init_ucs(struct unicode_data *ucsdata, char *linecharset, return ret; } +void init_ucs_generic(Conf *conf, struct unicode_data *ucsdata) +{ + init_ucs(ucsdata, conf_get_str(conf, CONF_line_codepage), + conf_get_bool(conf, CONF_utf8_override), + CS_NONE, conf_get_int(conf, CONF_vtmode)); +} + const char *cp_name(int codepage) { if (codepage == CS_NONE) diff --git a/windows/unicode.c b/windows/unicode.c index 4b18ef56..26ffcb6f 100644 --- a/windows/unicode.c +++ b/windows/unicode.c @@ -689,6 +689,11 @@ void init_ucs(Conf *conf, struct unicode_data *ucsdata) } } +void init_ucs_generic(Conf *conf, struct unicode_data *ucsdata) +{ + init_ucs(conf, ucsdata); +} + static void link_font(WCHAR *line_tbl, WCHAR *font_tbl, WCHAR attr) { int font_index, line_index, i;