1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Remove uni_tbl from struct unicode_data.

Instead of maintaining a single sparse table mapping Unicode to the
currently selected code page, we now maintain a collection of such
tables mapping Unicode to any code page we've so far found a need to
work with, and we add code pages to that list as necessary, and never
throw them away (since there are a limited number of them).

This means that the wc_to_mb family of functions are effectively
stateless: they no longer depend on a 'struct unicode_data'
corresponding to the current terminal settings. So I've removed that
parameter from all of them.

This fills in the missing piece of yesterday's commit a216d86106:
now wc_to_mb too should be able to handle internally-implemented
character sets, by hastily making their reverse mapping table if it
doesn't already have it.

(That was only a _latent_ bug, because the only use of wc_to_mb in the
cross-platform or Windows code _did_ want to convert to the currently
selected code page, so the old strategy worked in that case. But there
was no protection against an unworkable use of it being added later.)
This commit is contained in:
Simon Tatham
2022-06-01 08:35:12 +01:00
parent 8a907510dd
commit 5a28658a6d
9 changed files with 130 additions and 53 deletions

View File

@ -61,8 +61,7 @@ int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
}
int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
char *mbstr, int mblen, const char *defchr,
struct unicode_data *ucsdata)
char *mbstr, int mblen, const char *defchr)
{
if (codepage == DEFAULT_CODEPAGE) {
char output[MB_LEN_MAX];

View File

@ -600,7 +600,7 @@ static bool x11font_has_glyph(unifont *font, wchar_t glyph)
*/
char sbstring[2];
int sblen = wc_to_mb(xfont->real_charset, 0, &glyph, 1,
sbstring, 2, "", NULL);
sbstring, 2, "");
if (sblen == 0 || !sbstring[0])
return false; /* not even in the charset */
@ -956,7 +956,7 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
*/
char *sbstring = snewn(len+1, char);
int sblen = wc_to_mb(xfont->real_charset, 0, string, len,
sbstring, len+1, ".", NULL);
sbstring, len+1, ".");
x11font_really_draw_text(x11font_drawfuncs + index + 0, ctx,
&xfont->fonts[sfid], xfont->disp, x, y,
sbstring, sblen, shadowoffset,
@ -1644,8 +1644,7 @@ static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font,
* string to UTF-8.
*/
utfstring = snewn(len*6+1, char); /* UTF-8 has max 6 bytes/char */
utflen = wc_to_mb(CS_UTF8, 0, string, len,
utfstring, len*6+1, ".", NULL);
utflen = wc_to_mb(CS_UTF8, 0, string, len, utfstring, len*6+1, ".");
utfptr = utfstring;
while (utflen > 0) {

View File

@ -3056,8 +3056,7 @@ static void gtkwin_clip_write(
state->pasteout_data_len = len*6;
state->pasteout_data_len = wc_to_mb(inst->ucsdata.line_codepage, 0,
data, len, state->pasteout_data,
state->pasteout_data_len,
NULL, NULL);
state->pasteout_data_len, NULL);
if (state->pasteout_data_len == 0) {
sfree(state->pasteout_data);
state->pasteout_data = NULL;