Defer loading of character sets, and some anti-crash checks related to
missing or incomplete LANG env var. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2186 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1935,11 +1935,16 @@ static void wxLoadCharacterSets(void)
|
|||||||
{
|
{
|
||||||
static bool already_loaded = FALSE;
|
static bool already_loaded = FALSE;
|
||||||
|
|
||||||
|
if (already_loaded) return;
|
||||||
|
|
||||||
#if defined(__UNIX__) && wxUSE_UNICODE
|
#if defined(__UNIX__) && wxUSE_UNICODE
|
||||||
// search through files in /usr/share/i18n/charmaps
|
// search through files in /usr/share/i18n/charmaps
|
||||||
for (wxString fname = ::wxFindFirstFile(_T("/usr/share/i18n/charmaps/*"));
|
wxString fname;
|
||||||
|
printf("Commencing load\n");
|
||||||
|
for (fname = ::wxFindFirstFile(_T("/usr/share/i18n/charmaps/*"));
|
||||||
!fname.IsEmpty();
|
!fname.IsEmpty();
|
||||||
fname = ::wxFindNextFile()) {
|
fname = ::wxFindNextFile()) {
|
||||||
|
wxPrintf(_("Loading: %s\n"), fname.c_str());
|
||||||
wxTextFile cmap(fname);
|
wxTextFile cmap(fname);
|
||||||
if (cmap.Open()) {
|
if (cmap.Open()) {
|
||||||
wxCharacterSet *cset = new wxCharacterSet;
|
wxCharacterSet *cset = new wxCharacterSet;
|
||||||
@@ -1948,7 +1953,8 @@ static void wxLoadCharacterSets(void)
|
|||||||
|
|
||||||
wxPrintf(_T("yup, loaded %s\n"),fname.c_str());
|
wxPrintf(_T("yup, loaded %s\n"),fname.c_str());
|
||||||
|
|
||||||
for (wxString line = cmap.GetFirstLine();
|
wxString line;
|
||||||
|
for (line = cmap.GetFirstLine();
|
||||||
!cmap.Eof();
|
!cmap.Eof();
|
||||||
line = cmap.GetNextLine()) {
|
line = cmap.GetNextLine()) {
|
||||||
wxPrintf(_T("line contents: %s\n"),line.c_str());
|
wxPrintf(_T("line contents: %s\n"),line.c_str());
|
||||||
@@ -2002,34 +2008,33 @@ static void wxLoadCharacterSets(void)
|
|||||||
already_loaded = TRUE;
|
already_loaded = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static wxCharacterSet *wxFindCharacterSet(const wxString& charset)
|
static wxCharacterSet *wxFindCharacterSet(const wxChar *charset)
|
||||||
{
|
{
|
||||||
|
wxLoadCharacterSets();
|
||||||
for (size_t n=0; n<wxCharsets.GetCount(); n++)
|
for (size_t n=0; n<wxCharsets.GetCount(); n++)
|
||||||
if (wxCharsets[n].names.Index(charset) != wxNOT_FOUND)
|
if (wxCharsets[n].names.Index(charset) != wxNOT_FOUND)
|
||||||
return &(wxCharsets[n]);
|
return &(wxCharsets[n]);
|
||||||
return (wxCharacterSet *)NULL;
|
return (wxCharacterSet *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
WXDLLEXPORT_DATA(wxCSConv) wxConv_local((const wxChar *)NULL);
|
WXDLLEXPORT_DATA(wxCSConv) wxConv_local((const wxChar *)NULL);
|
||||||
#endif
|
|
||||||
|
|
||||||
wxCSConv::wxCSConv(const wxChar *charset)
|
wxCSConv::wxCSConv(const wxChar *charset)
|
||||||
{
|
{
|
||||||
wxLoadCharacterSets();
|
|
||||||
if (!charset) {
|
if (!charset) {
|
||||||
#ifdef __UNIX__
|
#ifdef __UNIX__
|
||||||
wxChar *lang = wxGetenv(_T("LANG"));
|
wxChar *lang = wxGetenv(_T("LANG"));
|
||||||
wxChar *dot = wxStrchr(lang, _T('.'));
|
wxChar *dot = lang ? wxStrchr(lang, _T('.')) : (wxChar *)NULL;
|
||||||
if (dot) charset = dot+1;
|
if (dot) charset = dot+1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
cset = (wxCharacterSet *) NULL;
|
m_cset = (wxCharacterSet *) NULL;
|
||||||
|
m_deferred = FALSE;
|
||||||
|
if (charset) {
|
||||||
#ifdef __UNIX__
|
#ifdef __UNIX__
|
||||||
// first, convert the character set name to standard form
|
// first, convert the character set name to standard form
|
||||||
wxString codeset;
|
wxString codeset;
|
||||||
if (wxString(charset,3) == _T("ISO")) {
|
if (wxString(charset,3).CmpNoCase(_T("ISO")) == 0) {
|
||||||
// make sure it's represented in the standard form: ISO_8859-1
|
// make sure it's represented in the standard form: ISO_8859-1
|
||||||
codeset = _T("ISO_");
|
codeset = _T("ISO_");
|
||||||
charset += 3;
|
charset += 3;
|
||||||
@@ -2043,20 +2048,33 @@ wxCSConv::wxCSConv(const wxChar *charset)
|
|||||||
}
|
}
|
||||||
codeset << charset;
|
codeset << charset;
|
||||||
codeset.MakeUpper();
|
codeset.MakeUpper();
|
||||||
cset = wxFindCharacterSet(codeset);
|
m_name = wxStrdup(codeset.c_str());
|
||||||
|
m_deferred = TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCSConv::~wxCSConv(void)
|
wxCSConv::~wxCSConv()
|
||||||
{
|
{
|
||||||
|
free(m_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxCSConv::LoadNow()
|
||||||
|
{
|
||||||
|
// wxPrintf(_T("Conversion request\n"));
|
||||||
|
if (m_deferred) {
|
||||||
|
m_cset = wxFindCharacterSet(m_name);
|
||||||
|
m_deferred = FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||||
{
|
{
|
||||||
|
((wxCSConv *)this)->LoadNow(); // discard constness
|
||||||
if (buf) {
|
if (buf) {
|
||||||
if (cset) {
|
if (m_cset) {
|
||||||
for (size_t c=0; c<=n; c++)
|
for (size_t c=0; c<=n; c++)
|
||||||
buf[c] = cset->data[psz[c]];
|
buf[c] = m_cset->data[psz[c]];
|
||||||
} else {
|
} else {
|
||||||
// latin-1 (direct)
|
// latin-1 (direct)
|
||||||
for (size_t c=0; c<=n; c++)
|
for (size_t c=0; c<=n; c++)
|
||||||
@@ -2068,11 +2086,12 @@ size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
|||||||
|
|
||||||
size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||||
{
|
{
|
||||||
|
((wxCSConv *)this)->LoadNow(); // discard constness
|
||||||
if (buf) {
|
if (buf) {
|
||||||
if (cset) {
|
if (m_cset) {
|
||||||
for (size_t c=0; c<=n; c++) {
|
for (size_t c=0; c<=n; c++) {
|
||||||
size_t n;
|
size_t n;
|
||||||
for (n=0; (n<256) && (cset->data[n] != psz[c]); n++);
|
for (n=0; (n<256) && (m_cset->data[n] != psz[c]); n++);
|
||||||
buf[c] = (n>0xff) ? '?' : n;
|
buf[c] = (n>0xff) ? '?' : n;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -743,12 +743,12 @@ void wxEnableTopLevelWindows(bool enable)
|
|||||||
// Yield to other apps/messages and disable user input
|
// Yield to other apps/messages and disable user input
|
||||||
bool wxSafeYield(wxWindow *win)
|
bool wxSafeYield(wxWindow *win)
|
||||||
{
|
{
|
||||||
wxEnableTopLevelWindow(FALSE);
|
wxEnableTopLevelWindows(FALSE);
|
||||||
// always enable ourselves
|
// always enable ourselves
|
||||||
if ( win )
|
if ( win )
|
||||||
win->Enable(TRUE);
|
win->Enable(TRUE);
|
||||||
bool rc = wxYield();
|
bool rc = wxYield();
|
||||||
wxEnableToplevelWindows(TRUE);
|
wxEnableTopLevelWindows(TRUE);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user