From b8ae1f0f33829d37d85254de8cea8182b4c8f628 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 5 Sep 2001 21:01:04 +0000 Subject: [PATCH] Unicode cleanup phase 2: we now reintroduce the ability to enter a numeric code page, and also reinstate the direct-to-font zero translation mode (but now under an actual _name_ rather than blank). Also add CP437 to the list since at least one expatriate DOS user wanted it; also select a sensible ISO or KOI codepage based on the system locale. git-svn-id: svn://svn.tartarus.org/sgt/putty@1230 cda61777-01e9-0310-a592-d414129be87e --- settings.c | 6 ++++- unicode.c | 81 +++++++++++++++++++++++++++++++++++++++++--------------------- winctrls.c | 7 +++--- windlg.c | 18 ++++++++------ winstuff.h | 2 +- 5 files changed, 74 insertions(+), 40 deletions(-) diff --git a/settings.c b/settings.c index 989eedd3..9db6fe26 100644 --- a/settings.c +++ b/settings.c @@ -457,7 +457,11 @@ void load_settings(char *section, int do_host, Config * cfg) cfg->wordness[j] = atoi(q); } } - gpps(sesskey, "LineCodePage", "ISO-8859-1:1987", cfg->line_codepage, + /* + * The empty default for LineCodePage will be converted later + * into a plausible default for the locale. + */ + gpps(sesskey, "LineCodePage", "", cfg->line_codepage, sizeof(cfg->line_codepage)); gppi(sesskey, "ScrollBar", 1, &cfg->scrollbar); gppi(sesskey, "ScrollOnKey", 0, &cfg->scroll_on_key); diff --git a/unicode.c b/unicode.c index 954015ff..45ca745f 100644 --- a/unicode.c +++ b/unicode.c @@ -233,36 +233,14 @@ static struct cp_list_item cp_list[] = { {"Win1257 (Baltic)", 1257}, {"Win1258 (Vietnamese)", 1258}, - /* All below here are aliases - First the windows ones. */ - {"Central European (Win1250)", 1250}, - {"Cyrillic (Win1251)", 1251}, - {"Western (Win1252)", 1252}, - {"Greek (Win1253)", 1253}, - {"Turkish (Win1254)", 1254}, - {"Hebrew (Win1255)", 1255}, - {"Arabic (Win1256)", 1256}, - {"Baltic (Win1257)", 1257}, - {"Vietnamese (Win1258)", 1258}, - - {"ROMAN8", 0, 96, roman8}, - {"R8", 0, 96, roman8}, - - /* Note this is Latin ->> */ - {"LATIN0", 0, 96, iso_8859_15}, - {"L0", 0, 96, iso_8859_15}, + {"Win1258 (Vietnamese)", 1258}, + {"CP437", 437}, {"CP819", 28591}, {"CP878", 20866}, - {"L1", 28591}, - {"L2", 28592}, - {"L3", 28593}, - {"L4", 28594}, - {"L5", 28599}, - {"LATIN1", 28591}, - {"LATIN2", 28592}, - {"LATIN3", 28593}, - {"LATIN4", 28594}, - {"LATIN5", 28599}, + + {"Use font encoding", -1}, + {0, 0} }; @@ -884,6 +862,49 @@ int decode_codepage(char *cp_name) int codepage = -1; CPINFO cpinfo; + if (!*cp_name) { + /* + * Here we select a plausible default code page based on + * the locale the user is in. We wish to select an ISO code + * page or appropriate local default _rather_ than go with + * the Win125* series, because it's more important to have + * CSI and friends enabled by default than the ghastly + * Windows extra quote characters, and because it's more + * likely the user is connecting to a remote server that + * does something Unixy or VMSy and hence standards- + * compliant than that they're connecting back to a Windows + * box using horrible nonstandard charsets. + * + * Accordingly, Robert de Bath suggests a method for + * picking a default character set that runs as follows: + * first call GetACP to get the system's ANSI code page + * identifier, and translate as follows: + * + * 1250 -> ISO 8859-2 + * 1251 -> KOI8-U + * 1252 -> ISO 8859-1 + * 1253 -> ISO 8859-7 + * 1254 -> ISO 8859-9 + * 1255 -> ISO 8859-8 + * 1256 -> ISO 8859-6 + * 1257 -> ISO 8859-4 + * + * and for anything else, choose direct-to-font. + */ + int cp = GetACP(); + switch (cp) { + case 1250: cp_name = "ISO-8859-2"; break; + case 1251: cp_name = "KOI8-U"; break; + case 1252: cp_name = "ISO-8859-1"; break; + case 1253: cp_name = "ISO-8859-7"; break; + case 1254: cp_name = "ISO-8859-9"; break; + case 1255: cp_name = "ISO-8859-8"; break; + case 1256: cp_name = "ISO-8859-6"; break; + case 1257: cp_name = "ISO-8859-4"; break; + /* default: leave it blank, which will select -1, direct->font */ + } + } + if (cp_name && *cp_name) for (cpi = cp_list; cpi->name; cpi++) { s = cp_name; @@ -947,6 +968,12 @@ char *cp_name(int codepage) { struct cp_list_item *cpi, *cpno; static char buf[32]; + + if (codepage == -1) { + sprintf(buf, "Use font encoding"); + return buf; + } + if (codepage > 0 && codepage < 65536) sprintf(buf, "CP%03d", codepage); else diff --git a/winctrls.c b/winctrls.c index de4812c7..72550d0e 100644 --- a/winctrls.c +++ b/winctrls.c @@ -153,10 +153,9 @@ void multiedit(struct ctlpos *cp, ...) } /* - * A static line, followed by a full-width drop-down list (ie a - * non-editing combo box). + * A static line, followed by a full-width combo box. */ -void dropdownlist(struct ctlpos *cp, char *text, int staticid, int listid) +void combobox(struct ctlpos *cp, char *text, int staticid, int listid) { RECT r; @@ -170,7 +169,7 @@ void dropdownlist(struct ctlpos *cp, char *text, int staticid, int listid) r.bottom = COMBOHEIGHT * 10; doctl(cp, r, "COMBOBOX", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | - CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", listid); + CBS_DROPDOWN | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", listid); cp->ypos += STATICHEIGHT + GAPWITHIN + COMBOHEIGHT + GAPBETWEEN; } diff --git a/windlg.c b/windlg.c index d89331a4..46b02b5b 100644 --- a/windlg.c +++ b/windlg.c @@ -784,15 +784,13 @@ static void init_dlg_ctrls(HWND hwnd, int keepsess) { int i; char *cp; - int index = 0; + strcpy(cfg.line_codepage, cp_name(decode_codepage(cfg.line_codepage))); SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_RESETCONTENT, 0, 0); for (i = 0; (cp = cp_enumerate(i)) != NULL; i++) { SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_ADDSTRING, 0, (LPARAM) cp); - if (!strcmp(cp, cfg.line_codepage)) - index = i; } - SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_SETCURSEL, index, 0); + SetDlgItemText(hwnd, IDC_CODEPAGE, cfg.line_codepage); } CheckRadioButton(hwnd, IDC_VTXWINDOWS, IDC_VTUNICODE, @@ -1104,9 +1102,8 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) endbox(&cp); beginbox(&cp, "Character set translation on received data", IDC_BOX_TRANSLATION2); - dropdownlist(&cp, - "Received data assumed to be in which character set:", - IDC_CODEPAGESTATIC, IDC_CODEPAGE); + combobox(&cp, "Received data assumed to be in which character set:", + IDC_CODEPAGESTATIC, IDC_CODEPAGE); endbox(&cp); } @@ -2458,6 +2455,13 @@ static int GenericMainDlgProc(HWND hwnd, UINT msg, CB_GETCURSEL, 0, 0); SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_GETLBTEXT, index, (LPARAM)cfg.line_codepage); + } else if (HIWORD(wParam) == CBN_EDITCHANGE) { + GetDlgItemText(hwnd, IDC_CODEPAGE, cfg.line_codepage, + sizeof(cfg.line_codepage) - 1); + } else if (HIWORD(wParam) == CBN_KILLFOCUS) { + strcpy(cfg.line_codepage, + cp_name(decode_codepage(cfg.line_codepage))); + SetDlgItemText(hwnd, IDC_CODEPAGE, cfg.line_codepage); } break; case IDC_VTXWINDOWS: diff --git a/winstuff.h b/winstuff.h index a8d696bd..ccb246bd 100644 --- a/winstuff.h +++ b/winstuff.h @@ -59,7 +59,7 @@ void static2btn(struct ctlpos *cp, char *stext, int sid, char *btext1, int bid1, char *btext2, int bid2); void staticedit(struct ctlpos *cp, char *stext, int sid, int eid, int percentedit); -void dropdownlist(struct ctlpos *cp, char *text, int staticid, int listid); +void combobox(struct ctlpos *cp, char *text, int staticid, int listid); void staticpassedit(struct ctlpos *cp, char *stext, int sid, int eid, int percentedit); void bigeditctrl(struct ctlpos *cp, char *stext, -- 2.11.0