From d4413bd2bbee00fa4a058e6c3a58c11d5596cd3d Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 5 Apr 2003 16:36:11 +0000 Subject: [PATCH] Fixed the printing and charset combo boxes in Unix PuTTY. (The former by simply removing it; the latter by adding an enumeration function to libcharset.) This has had slight `const' repercussions on cp_name() and cp_enumerate() which might break the Mac build. git-svn-id: svn://svn.tartarus.org/sgt/putty@3064 cda61777-01e9-0310-a592-d414129be87e --- Recipe | 2 +- charset/charset.h | 8 ++++++++ config.c | 2 +- putty.h | 4 ++-- unicode.c | 4 ++-- unix/ptermm.c | 21 --------------------- unix/uxputty.c | 27 --------------------------- unix/uxucs.c | 30 +++++++++++++++++++++++++++--- 8 files changed, 41 insertions(+), 57 deletions(-) diff --git a/Recipe b/Recipe index 6bb4fa10..71eeb152 100644 --- a/Recipe +++ b/Recipe @@ -124,7 +124,7 @@ MACMISC = misc version macstore settings tree234 macnet mtcpnet otnet proxy + macmisc macabout # Character set library, for use in pterm. -CHARSET = sbcsdat slookup sbcs utf8 toucs fromucs xenc mimeenc macenc +CHARSET = sbcsdat slookup sbcs utf8 toucs fromucs xenc mimeenc macenc localenc # Standard libraries, and the same with WinSocks 1 and 2. LIBS = advapi32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib diff --git a/charset/charset.h b/charset/charset.h index 7dd038bb..0a2e9190 100644 --- a/charset/charset.h +++ b/charset/charset.h @@ -137,6 +137,14 @@ const char *charset_to_mimeenc(int charset); int charset_from_mimeenc(const char *name); /* + * Convert our own encoding names to and from our charset + * identifiers. + */ +const char *charset_to_localenc(int charset); +int charset_from_localenc(const char *name); +int charset_localenc_nth(int n); + +/* * Convert Mac OS script/region/font to our charset identifiers. */ int charset_from_macenc(int script, int region, int sysvers, diff --git a/config.c b/config.c index 54880318..239247db 100644 --- a/config.c +++ b/config.c @@ -162,7 +162,7 @@ static void codepage_handler(union control *ctrl, void *dlg, Config *cfg = (Config *)data; if (event == EVENT_REFRESH) { int i; - char *cp; + const char *cp; dlg_update_start(ctrl, dlg); strcpy(cfg->line_codepage, cp_name(decode_codepage(cfg->line_codepage))); diff --git a/putty.h b/putty.h index 76bfe002..f985ad27 100644 --- a/putty.h +++ b/putty.h @@ -728,8 +728,8 @@ int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen, wchar_t xlat_uskbd2cyrllic(int ch); int check_compose(int first, int second); int decode_codepage(char *cp_name); -char *cp_enumerate (int index); -char *cp_name(int codepage); +const char *cp_enumerate (int index); +const char *cp_name(int codepage); void get_unitab(int codepage, wchar_t * unitab, int ftype); /* diff --git a/unicode.c b/unicode.c index 02427336..c68017ae 100644 --- a/unicode.c +++ b/unicode.c @@ -1094,7 +1094,7 @@ int decode_codepage(char *cp_name) return codepage; } -char *cp_name(int codepage) +const char *cp_name(int codepage) { const struct cp_list_item *cpi, *cpno; static char buf[32]; @@ -1134,7 +1134,7 @@ char *cp_name(int codepage) * Return the nth code page in the list, for use in the GUI * configurer. */ -char *cp_enumerate(int index) +const char *cp_enumerate(int index) { if (index < 0 || index >= lenof(cp_list)) return NULL; diff --git a/unix/ptermm.c b/unix/ptermm.c index 58b42b61..6cdeffc5 100644 --- a/unix/ptermm.c +++ b/unix/ptermm.c @@ -9,27 +9,6 @@ const char *const appname = "pterm"; -/* - * Another bunch of temporary stub functions. These ones will want - * removing by means of implementing them properly: libcharset - * should invent its own sensible format for codepage names and a - * means of enumerating them, and printer_enum needs to be dealt - * with somehow or other too. - */ - -char *cp_name(int codepage) -{ - return ""; -} -char *cp_enumerate(int index) -{ - return NULL; -} -int decode_codepage(char *cp_name) -{ - return -2; -} - Backend *select_backend(Config *cfg) { return &pty_backend; diff --git a/unix/uxputty.c b/unix/uxputty.c index 18f1b6b0..53ee0d83 100644 --- a/unix/uxputty.c +++ b/unix/uxputty.c @@ -14,12 +14,6 @@ /* * TODO: * - * - libcharset enumeration. - * - * - fix the printer enum (I think the sensible thing is simply to - * have uxcfg.c remove the drop-down list completely, since you - * can't sensibly provide an enumerated list of lpr commands!). - * * - Remainder of the context menu: * * - Event Log (this means we must implement the Event Log; not @@ -73,27 +67,6 @@ void cleanup_exit(int code) exit(code); } -/* - * Another bunch of temporary stub functions. These ones will want - * removing by means of implementing them properly: libcharset - * should invent its own sensible format for codepage names and a - * means of enumerating them, and printer_enum needs to be dealt - * with somehow or other too. - */ - -char *cp_name(int codepage) -{ - return ""; -} -char *cp_enumerate(int index) -{ - return NULL; -} -int decode_codepage(char *cp_name) -{ - return -2; -} - const char *const appname = "PuTTY"; Backend *select_backend(Config *cfg) diff --git a/unix/uxucs.c b/unix/uxucs.c index 8731239f..f3d6a89a 100644 --- a/unix/uxucs.c +++ b/unix/uxucs.c @@ -8,6 +8,7 @@ #include #include "putty.h" +#include "charset.h" #include "terminal.h" #include "misc.h" @@ -122,9 +123,7 @@ int init_ucs(struct unicode_data *ucsdata, * line_codepage should be decoded from the specification in * cfg. */ - ucsdata->line_codepage = charset_from_mimeenc(linecharset); - if (ucsdata->line_codepage == CS_NONE) - ucsdata->line_codepage = charset_from_xenc(linecharset); + ucsdata->line_codepage = decode_codepage(linecharset); /* * If line_codepage is _still_ CS_NONE, we assume we're using @@ -218,3 +217,28 @@ int init_ucs(struct unicode_data *ucsdata, return ret; } + +const char *cp_name(int codepage) +{ + if (codepage == CS_NONE) + return "Use font encoding"; + return charset_to_localenc(codepage); +} + +const char *cp_enumerate(int index) +{ + int charset; + if (index == 0) + return "Use font encoding"; + charset = charset_localenc_nth(index-1); + if (charset == CS_NONE) + return NULL; + return charset_to_localenc(charset); +} + +int decode_codepage(char *cp_name) +{ + if (!*cp_name) + return CS_NONE; /* use font encoding */ + return charset_from_localenc(cp_name); +} -- 2.11.0