static int sel_charset_button (WButton * button, int action) { int new_dcp; (void) button; (void) action; new_dcp = select_charset (-1, -1, new_display_codepage, TRUE); if (new_dcp != SELECT_CHARSET_CANCEL) { const char *cpname; char buf[BUF_TINY]; new_display_codepage = new_dcp; cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ? _("Other 8 bit") : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; if (cpname != NULL) utf8_display = str_isutf8 (cpname); /* avoid strange bug with label repainting */ g_snprintf (buf, sizeof (buf), "%-27s", cpname); label_set_text (cplabel, buf); } return 0; }
static int sel_charset_button (WButton * button, int action) { int new_dcp; (void) action; new_dcp = select_charset (-1, -1, new_display_codepage, TRUE); if (new_dcp != SELECT_CHARSET_CANCEL) { const char *cpname; new_display_codepage = new_dcp; cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ? _("Other 8 bit") : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; if (cpname != NULL) mc_global.utf8_display = str_isutf8 (cpname); else cpname = _("7-bit ASCII"); /* FIXME */ button_set_text (button, cpname); dlg_redraw (WIDGET (button)->owner); } return 0; }
static int sel_charset_button (int action) { const char *cpname; char buf[64]; new_display_codepage = select_charset (new_display_codepage, 1); cpname = (new_display_codepage < 0) ? _("Other 8 bit") : codepages[new_display_codepage].name; /* avoid strange bug with label repainting */ g_snprintf (buf, sizeof (buf), "%-27s", cpname); label_set_text (cplabel, buf); return 0; }
gboolean do_select_codepage (void) { const char *errmsg = NULL; int r; r = select_charset (-1, -1, source_codepage, FALSE); if (r == SELECT_CHARSET_CANCEL) return FALSE; source_codepage = r; errmsg = init_translation_table (r == SELECT_CHARSET_NO_TRANSLATE ? display_codepage : source_codepage, display_codepage); if (errmsg != NULL) message (D_ERROR, MSG_ERROR, "%s", errmsg); return (errmsg == NULL); }
void msg_init(char * const *argv) { char *p; SVX_ASSERT(argv); /* Point to argv[0] itself so we report a more helpful error if the * code to work out the clean appname generates a signal */ appname_copy = argv[0]; #if OS_UNIX /* use name as-is on Unix - programs run from path get name as supplied */ appname_copy = osstrdup(argv[0]); #else /* use the lower-cased leafname on other platforms */ p = leaf_from_fnm(argv[0]); appname_copy = p; while (*p) { *p = tolower(*p); ++p; } #endif /* shortcut --version so you can check the version number even when the * correct message file can't be found... */ if (argv[1] && strcmp(argv[1], "--version") == 0) { cmdline_version(); exit(0); } if (argv[0]) { exe_pth = path_from_fnm(argv[0]); #ifdef MACOSX_BUNDLE /* If we're being built into a bundle, always look relative to * the path to the binary. */ #ifdef AVEN /* Aven is packaged as an application, so we must look inside there. */ pth_cfg_files = use_path(exe_pth, "../Resources"); #else pth_cfg_files = use_path(exe_pth, "share/survex"); #endif #elif OS_UNIX && defined DATADIR && defined PACKAGE bool free_pth = fFalse; char *pth = getenv("srcdir"); if (!pth || !pth[0]) { pth = path_from_fnm(argv[0]); free_pth = fTrue; } if (pth[0]) { struct stat buf; #if OS_UNIX_MACOSX /* On MacOS X the programs may be installed anywhere, with the * share directory and the binaries in the same directory. */ p = use_path(pth, "share/survex/en.msg"); if (lstat(p, &buf) == 0 && S_ISREG(buf.st_mode)) { pth_cfg_files = use_path(pth, "share/survex"); goto macosx_got_msg; } osfree(p); /* The cavern which aven runs is a hardlinked copy alongside * the aven binary. */ p = use_path(pth, "../Resources/en.msg"); if (lstat(p, &buf) == 0 && S_ISREG(buf.st_mode)) { pth_cfg_files = use_path(pth, "../Resources"); goto macosx_got_msg; } osfree(p); #endif /* If we're run with an explicit path, check if "../lib/en.msg" * from the program's path exists, and if so look there for * support files - this allows us to test binaries in the build * tree easily. */ p = use_path(pth, "../lib/en.msg"); if (lstat(p, &buf) == 0) { #ifdef S_ISREG /* POSIX way */ if (S_ISREG(buf.st_mode)) { pth_cfg_files = use_path(pth, "../lib"); } #else /* BSD way */ if ((buf.st_mode & S_IFMT) == S_IFREG) { pth_cfg_files = use_path(pth, "../lib"); } #endif } #if defined(__GNUC__) && defined(__APPLE_CC__) macosx_got_msg: #endif osfree(p); } if (free_pth) osfree(pth); #elif OS_WIN32 DWORD len = 256; char *buf = NULL, *modname; while (1) { DWORD got; buf = osrealloc(buf, len); got = GetModuleFileName(NULL, buf, len); if (got < len) break; len += len; } modname = buf; /* Strange Win32 nastiness - strip prefix "\\?\" if present */ if (strncmp(modname, "\\\\?\\", 4) == 0) modname += 4; pth_cfg_files = path_from_fnm(modname); osfree(buf); #else /* Get the path to the support files from argv[0] */ pth_cfg_files = path_from_fnm(argv[0]); #endif } msg_lang = getenv("SURVEXLANG"); #ifdef DEBUG fprintf(stderr, "msg_lang = %p (= \"%s\")\n", msg_lang, msg_lang?msg_lang:"(null)"); #endif msg_lang_explicit = fTrue; if (!msg_lang || !*msg_lang) { msg_lang_explicit = fFalse; msg_lang = getenv("LC_ALL"); } if (!msg_lang || !*msg_lang) { msg_lang = getenv("LC_MESSAGES"); if (!msg_lang || !*msg_lang) { msg_lang = getenv("LANG"); /* Something (AutoCAD?) on Microsoft Windows sets LANG to a number. */ if (msg_lang && !isalpha(msg_lang[0])) msg_lang = NULL; } if (!msg_lang || !*msg_lang) { #if OS_WIN32 LCID locid; #endif #ifdef DEFAULTLANG msg_lang = STRING(DEFAULTLANG); #else msg_lang = "en"; #endif #if OS_WIN32 /* GetUserDefaultUILanguage() requires Microsoft Windows 2000 or * newer. For older versions, we use GetUserDefaultLCID(). */ { HMODULE win32 = GetModuleHandle(TEXT("kernel32.dll")); FARPROC f = GetProcAddress(win32, "GetUserDefaultUILanguage"); if (f) { typedef LANGID (WINAPI *func_GetUserDefaultUILanguage)(void); func_GetUserDefaultUILanguage g; g = (func_GetUserDefaultUILanguage)f; locid = g(); } else { locid = GetUserDefaultLCID(); } } if (locid) { WORD langid = LANGIDFROMLCID(locid); switch (PRIMARYLANGID(langid)) { case LANG_BULGARIAN: msg_lang = "bg"; break; /* older mingw compilers don't seem to supply this value */ #ifndef LANG_CATALAN # define LANG_CATALAN 0x03 #endif case LANG_CATALAN: msg_lang = "ca"; break; case LANG_CHINESE: msg_lang = "zh_CN"; break; case LANG_ENGLISH: if (SUBLANGID(langid) == SUBLANG_ENGLISH_US) msg_lang = "en_US"; else msg_lang = "en"; break; case LANG_FRENCH: msg_lang = "fr"; break; case LANG_GERMAN: switch (SUBLANGID(langid)) { case SUBLANG_GERMAN_SWISS: msg_lang = "de_CH"; break; default: msg_lang = "de"; } break; case LANG_GREEK: msg_lang = "el"; break; case LANG_HUNGARIAN: msg_lang = "hu"; break; case LANG_INDONESIAN: msg_lang = "id"; break; case LANG_ITALIAN: msg_lang = "it"; break; case LANG_POLISH: msg_lang = "pl"; break; case LANG_PORTUGUESE: if (SUBLANGID(langid) == SUBLANG_PORTUGUESE_BRAZILIAN) msg_lang = "pt_BR"; else msg_lang = "pt"; break; case LANG_ROMANIAN: msg_lang = "ro"; break; case LANG_RUSSIAN: msg_lang = "ru"; break; case LANG_SLOVAK: msg_lang = "sk"; break; case LANG_SPANISH: msg_lang = "es"; break; } } #endif } } #ifdef DEBUG fprintf(stderr, "msg_lang = %p (= \"%s\")\n", msg_lang, msg_lang?msg_lang:"(null)"); #endif /* On Mandrake LANG defaults to C */ if (strcmp(msg_lang, "C") == 0) msg_lang = "en"; { /* If msg_lang has a country code, snip it out to give msg_lang2. */ size_t b = 0; while (isalpha((unsigned char)msg_lang[b])) { ++b; } if (msg_lang[b] == '_') { char * tmp; size_t e = b + 1; while (isalpha((unsigned char)msg_lang[e])) { ++e; } tmp = osstrdup(msg_lang); memmove(tmp + b, tmp + e, strlen(tmp + e) + 1); msg_lang2 = tmp; } } #ifdef LC_MESSAGES /* try to setlocale() appropriately too */ if (!setlocale(LC_MESSAGES, msg_lang)) { if (msg_lang2) { (void)setlocale(LC_MESSAGES, msg_lang2); } } #endif select_charset(default_charset()); }