1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-28 17:27:08 -05:00

dup_mb_to_wc, dup_wc_to_mb: remove the 'flags' parameter.

This parameter was undocumented, and Windows-specific: its semantics
date from before PuTTY was cross-platform, and are "Pass this flags
parameter straight through to the Win32 API's conversion functions".
So in Windows platform code you can pass flags like MB_USEGLYPHCHARS,
but in cross-platform code, you dare not pass anything nonzero at all
because the Unix frontend won't recognise it (or, likely, even
compile).

I've kept the flag for now in the underlying mb_to_wc / wc_to_mb
functions. Partly that's because there's one place in the Windows code
where the parameter _is_ used; mostly, it's because I'm about to
replace those functions anyway, so there's no point in editing all the
call sites twice.
This commit is contained in:
Simon Tatham 2024-09-24 08:46:39 +01:00
parent ed621590b0
commit c4c4d2c5cb
10 changed files with 31 additions and 32 deletions

8
misc.h
View File

@ -71,12 +71,12 @@ void strbuf_finalise_agent_query(strbuf *buf);
/* String-to-Unicode converters that auto-allocate the destination and
* work around the rather deficient interface of mb_to_wc. */
wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string,
wchar_t *dup_mb_to_wc_c(int codepage, const char *string,
size_t len, size_t *outlen_p);
wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string);
char *dup_wc_to_mb_c(int codepage, int flags, const wchar_t *string,
wchar_t *dup_mb_to_wc(int codepage, const char *string);
char *dup_wc_to_mb_c(int codepage, const wchar_t *string,
size_t len, const char *defchr, size_t *outlen_p);
char *dup_wc_to_mb(int codepage, int flags, const wchar_t *string,
char *dup_wc_to_mb(int codepage, const wchar_t *string,
const char *defchr);
static inline int toint(unsigned u)

View File

@ -3440,7 +3440,7 @@ static void gtkwin_set_title(TermWin *tw, const char *title, int codepage)
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
sfree(inst->wintitle);
if (codepage != CP_UTF8) {
wchar_t *title_w = dup_mb_to_wc(codepage, 0, title);
wchar_t *title_w = dup_mb_to_wc(codepage, title);
inst->wintitle = encode_wide_string_as_utf8(title_w);
sfree(title_w);
} else {
@ -3454,7 +3454,7 @@ static void gtkwin_set_icon_title(TermWin *tw, const char *title, int codepage)
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
sfree(inst->icontitle);
if (codepage != CP_UTF8) {
wchar_t *title_w = dup_mb_to_wc(codepage, 0, title);
wchar_t *title_w = dup_mb_to_wc(codepage, title);
inst->icontitle = encode_wide_string_as_utf8(title_w);
sfree(title_w);
} else {

View File

@ -9,14 +9,14 @@
#include "putty.h"
#include "misc.h"
wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string,
wchar_t *dup_mb_to_wc_c(int codepage, const char *string,
size_t inlen, size_t *outlen_p)
{
assert(inlen <= INT_MAX);
size_t mult;
for (mult = 1 ;; mult++) {
wchar_t *ret = snewn(mult*inlen + 2, wchar_t);
size_t outlen = mb_to_wc(codepage, flags, string, inlen, ret,
size_t outlen = mb_to_wc(codepage, 0, string, inlen, ret,
mult*inlen + 1);
if (outlen < mult*inlen+1) {
if (outlen_p)
@ -28,7 +28,7 @@ wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string,
}
}
wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string)
wchar_t *dup_mb_to_wc(int codepage, const char *string)
{
return dup_mb_to_wc_c(codepage, flags, string, strlen(string), NULL);
return dup_mb_to_wc_c(codepage, string, strlen(string), NULL);
}

View File

@ -11,7 +11,7 @@
#include "putty.h"
#include "misc.h"
char *dup_wc_to_mb_c(int codepage, int flags, const wchar_t *string,
char *dup_wc_to_mb_c(int codepage, const wchar_t *string,
size_t inlen, const char *defchr, size_t *outlen_p)
{
assert(inlen <= INT_MAX);
@ -20,7 +20,7 @@ char *dup_wc_to_mb_c(int codepage, int flags, const wchar_t *string,
char *out = snewn(outsize, char);
while (true) {
size_t outlen = wc_to_mb(codepage, flags, string, inlen, out, outsize,
size_t outlen = wc_to_mb(codepage, 0, string, inlen, out, outsize,
defchr);
/* We can only be sure we've consumed the whole input if the
* output is not within a multibyte-character-length of the
@ -36,9 +36,8 @@ char *dup_wc_to_mb_c(int codepage, int flags, const wchar_t *string,
}
}
char *dup_wc_to_mb(int codepage, int flags, const wchar_t *string,
char *dup_wc_to_mb(int codepage, const wchar_t *string,
const char *defchr)
{
return dup_wc_to_mb_c(codepage, flags, string, wcslen(string),
defchr, NULL);
return dup_wc_to_mb_c(codepage, string, wcslen(string), defchr, NULL);
}

View File

@ -148,7 +148,7 @@ static void console_write(BinarySink *bs, const void *data, size_t len)
* Convert the UTF-8 input into a wide string.
*/
size_t wlen;
wchar_t *wide = dup_mb_to_wc_c(CP_UTF8, 0, data, len, &wlen);
wchar_t *wide = dup_mb_to_wc_c(CP_UTF8, data, len, &wlen);
if (conio->hout_is_console) {
/*
* To write UTF-8 to a console, use WriteConsoleW on the
@ -168,7 +168,7 @@ static void console_write(BinarySink *bs, const void *data, size_t len)
* what else can you do?
*/
size_t clen;
char *sys_cp = dup_wc_to_mb_c(CP_ACP, 0, wide, wlen, "?", &clen);
char *sys_cp = dup_wc_to_mb_c(CP_ACP, wide, wlen, "?", &clen);
size_t pos = 0;
DWORD nwritten;

View File

@ -2012,7 +2012,7 @@ bool winctrl_handle_command(struct dlgparam *dp, UINT msg,
of.nMaxFile = lenof(filename);
of.lpstrFileTitle = NULL;
of.lpstrTitle = title_to_free = dup_mb_to_wc(
DEFAULT_CODEPAGE, 0, ctrl->fileselect.title);
DEFAULT_CODEPAGE, ctrl->fileselect.title);
of.Flags = 0;
if (request_file_w(NULL, &of, false,
ctrl->fileselect.for_writing)) {

View File

@ -144,7 +144,7 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf)
if (p_AddDllDirectory) {
/* Add MIT Kerberos' path to the DLL search path,
* it loads its own DLLs further down the road */
wchar_t *dllPath = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, bindir);
wchar_t *dllPath = dup_mb_to_wc(DEFAULT_CODEPAGE, bindir);
p_AddDllDirectory(dllPath);
sfree(dllPath);
}

View File

@ -10,7 +10,7 @@ Filename *filename_from_str(const char *str)
{
Filename *fn = snew(Filename);
fn->cpath = dupstr(str);
fn->wpath = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, fn->cpath);
fn->wpath = dup_mb_to_wc(DEFAULT_CODEPAGE, fn->cpath);
fn->utf8path = encode_wide_string_as_utf8(fn->wpath);
return fn;
}
@ -19,7 +19,7 @@ Filename *filename_from_wstr(const wchar_t *str)
{
Filename *fn = snew(Filename);
fn->wpath = dupwcs(str);
fn->cpath = dup_wc_to_mb(DEFAULT_CODEPAGE, 0, fn->wpath, "?");
fn->cpath = dup_wc_to_mb(DEFAULT_CODEPAGE, fn->wpath, "?");
fn->utf8path = encode_wide_string_as_utf8(fn->wpath);
return fn;
}
@ -29,7 +29,7 @@ Filename *filename_from_utf8(const char *ustr)
Filename *fn = snew(Filename);
fn->utf8path = dupstr(ustr);
fn->wpath = decode_utf8_to_wide_string(fn->utf8path);
fn->cpath = dup_wc_to_mb(DEFAULT_CODEPAGE, 0, fn->wpath, "?");
fn->cpath = dup_wc_to_mb(DEFAULT_CODEPAGE, fn->wpath, "?");
return fn;
}
@ -86,7 +86,7 @@ char filename_char_sanitise(char c)
FILE *f_open(const Filename *fn, const char *mode, bool isprivate)
{
wchar_t *wmode = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, mode);
wchar_t *wmode = dup_mb_to_wc(DEFAULT_CODEPAGE, mode);
return _wfopen(fn->wpath, wmode);
sfree(wmode);
}

View File

@ -50,8 +50,8 @@ int message_box(HWND owner, LPCTSTR text, LPCTSTR caption, DWORD style,
wtext = decode_utf8_to_wide_string(text);
wcaption = decode_utf8_to_wide_string(caption);
} else {
wtext = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, text);
wcaption = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, caption);
wtext = dup_mb_to_wc(DEFAULT_CODEPAGE, text);
wcaption = dup_mb_to_wc(DEFAULT_CODEPAGE, caption);
}
mbox.lpszText = wtext;
mbox.lpszCaption = wcaption;

View File

@ -390,7 +390,7 @@ static void sw_SetWindowText(HWND hwnd, wchar_t *text)
if (unicode_window) {
SetWindowTextW(hwnd, text);
} else {
char *mb = dup_wc_to_mb(DEFAULT_CODEPAGE, 0, text, "?");
char *mb = dup_wc_to_mb(DEFAULT_CODEPAGE, text, "?");
SetWindowTextA(hwnd, mb);
sfree(mb);
}
@ -417,7 +417,7 @@ wchar_t *terminal_window_class_w(void)
{
static wchar_t *classname = NULL;
if (!classname)
classname = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, appname);
classname = dup_mb_to_wc(DEFAULT_CODEPAGE, appname);
if (!hprev) {
WNDCLASSW wndclassw;
SETUP_WNDCLASS(wndclassw, classname);
@ -549,9 +549,9 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
bool resize_forbidden = false;
if (vt && vt->flags & BACKEND_RESIZE_FORBIDDEN)
resize_forbidden = true;
wchar_t *uappname = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, appname);
wgs->window_name = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, appname);
wgs->icon_name = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, appname);
wchar_t *uappname = dup_mb_to_wc(DEFAULT_CODEPAGE, appname);
wgs->window_name = dup_mb_to_wc(DEFAULT_CODEPAGE, appname);
wgs->icon_name = dup_mb_to_wc(DEFAULT_CODEPAGE, appname);
if (!conf_get_bool(wgs->conf, CONF_scrollbar))
winmode &= ~(WS_VSCROLL);
if (conf_get_int(wgs->conf, CONF_resize_action) == RESIZE_DISABLED ||
@ -4826,7 +4826,7 @@ static int TranslateKey(WinGuiSeat *wgs, UINT message, WPARAM wParam,
static void wintw_set_title(TermWin *tw, const char *title, int codepage)
{
WinGuiSeat *wgs = container_of(tw, WinGuiSeat, termwin);
wchar_t *new_window_name = dup_mb_to_wc(codepage, 0, title);
wchar_t *new_window_name = dup_mb_to_wc(codepage, title);
if (!wcscmp(new_window_name, wgs->window_name)) {
sfree(new_window_name);
return;
@ -4841,7 +4841,7 @@ static void wintw_set_title(TermWin *tw, const char *title, int codepage)
static void wintw_set_icon_title(TermWin *tw, const char *title, int codepage)
{
WinGuiSeat *wgs = container_of(tw, WinGuiSeat, termwin);
wchar_t *new_icon_name = dup_mb_to_wc(codepage, 0, title);
wchar_t *new_icon_name = dup_mb_to_wc(codepage, title);
if (!wcscmp(new_icon_name, wgs->icon_name)) {
sfree(new_icon_name);
return;