Fixed bug #447 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Wed, 04 Jul 2007 07:54:06 +0000
branchSDL-1.2
changeset 3998098ac044cd2f
parent 3997 6a4f3a32c2e6
child 3999 f61a20d195f7
Fixed bug #447

Xlib uses the native locale, not latin1

... the question is... what does the server use? :)
include/SDL_stdinc.h
src/stdlib/SDL_iconv.c
src/video/x11/SDL_x11wm.c
     1.1 --- a/include/SDL_stdinc.h	Wed Jul 04 04:27:47 2007 +0000
     1.2 +++ b/include/SDL_stdinc.h	Wed Jul 04 07:54:06 2007 +0000
     1.3 @@ -584,8 +584,7 @@
     1.4     string that must be freed with SDL_free() or NULL on error.
     1.5  */
     1.6  extern DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft);
     1.7 -#define SDL_iconv_utf8_ascii(S)		SDL_iconv_string("646", "UTF-8", S, SDL_strlen(S)+1)
     1.8 -#define SDL_iconv_utf8_latin1(S)	SDL_iconv_string("8859-1", "UTF-8", S, SDL_strlen(S)+1)
     1.9 +#define SDL_iconv_utf8_locale(S)	SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
    1.10  #define SDL_iconv_utf8_ucs2(S)		(Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
    1.11  #define SDL_iconv_utf8_ucs4(S)		(Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
    1.12  
     2.1 --- a/src/stdlib/SDL_iconv.c	Wed Jul 04 04:27:47 2007 +0000
     2.2 +++ b/src/stdlib/SDL_iconv.c	Wed Jul 04 07:54:06 2007 +0000
     2.3 @@ -772,6 +772,26 @@
     2.4  
     2.5  #endif /* !HAVE_ICONV */
     2.6  
     2.7 +static const char *getlocale()
     2.8 +{
     2.9 +	const char *lang;
    2.10 +
    2.11 +	lang = SDL_getenv("LC_ALL");
    2.12 +	if ( !lang ) {
    2.13 +		lang = SDL_getenv("LC_CTYPE");
    2.14 +	}
    2.15 +	if ( !lang ) {
    2.16 +		lang = SDL_getenv("LC_MESSAGES");
    2.17 +	}
    2.18 +	if ( !lang ) {
    2.19 +		lang = SDL_getenv("LANG");
    2.20 +	}
    2.21 +	if ( !lang || SDL_strcmp(lang, "C") == 0 ) {
    2.22 +		lang = "ASCII";
    2.23 +	}
    2.24 +	return lang;
    2.25 +}
    2.26 +
    2.27  char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
    2.28  {
    2.29  	SDL_iconv_t cd;
    2.30 @@ -781,6 +801,12 @@
    2.31  	size_t outbytesleft;
    2.32  	size_t retCode = 0;
    2.33  
    2.34 +	if ( !fromcode || !*fromcode ) {
    2.35 +		fromcode = getlocale();
    2.36 +	}
    2.37 +	if ( !tocode || !*tocode ) {
    2.38 +		tocode = getlocale();
    2.39 +	}
    2.40  	cd = SDL_iconv_open(tocode, fromcode);
    2.41  	if ( cd == (SDL_iconv_t)-1 ) {
    2.42  		return NULL;
     3.1 --- a/src/video/x11/SDL_x11wm.c	Wed Jul 04 04:27:47 2007 +0000
     3.2 +++ b/src/video/x11/SDL_x11wm.c	Wed Jul 04 07:54:06 2007 +0000
     3.3 @@ -257,13 +257,13 @@
     3.4  #endif
     3.5  
     3.6  	if ( title != NULL ) {
     3.7 -		char *title_latin1 = SDL_iconv_utf8_latin1((char *)title);
     3.8 -		if ( !title_latin1 ) {
     3.9 +		char *title_locale = SDL_iconv_utf8_locale(title);
    3.10 +		if ( !title_locale ) {
    3.11  			SDL_OutOfMemory();
    3.12  			return;
    3.13  		}
    3.14 -		status = XStringListToTextProperty(&title_latin1, 1, &titleprop);
    3.15 -		SDL_free(title_latin1);
    3.16 +		status = XStringListToTextProperty(&title_locale, 1, &titleprop);
    3.17 +		SDL_free(title_locale);
    3.18  		if ( status ) {
    3.19  			XSetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
    3.20  			XFree(titleprop.value);
    3.21 @@ -280,13 +280,13 @@
    3.22  #endif
    3.23  	}
    3.24  	if ( icon != NULL ) {
    3.25 -		char *icon_latin1 = SDL_iconv_utf8_latin1((char *)icon);
    3.26 -		if ( !icon_latin1 ) {
    3.27 +		char *icon_locale = SDL_iconv_utf8_locale(icon);
    3.28 +		if ( !icon_locale ) {
    3.29  			SDL_OutOfMemory();
    3.30  			return;
    3.31  		}
    3.32 -		status = XStringListToTextProperty(&icon_latin1, 1, &iconprop);
    3.33 -		SDL_free(icon_latin1);
    3.34 +		status = XStringListToTextProperty(&icon_locale, 1, &iconprop);
    3.35 +		SDL_free(icon_locale);
    3.36  		if ( status ) {
    3.37  			XSetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
    3.38  			XFree(iconprop.value);