View | Details | Raw Unified | Return to issue 69373
Collapse All | Expand All

(-)sal/osl/unx/makefile.mk (+4 lines)
Lines 110-115 Link Here
110
			$(OBJ)$/file_stat.obj
110
			$(OBJ)$/file_stat.obj
111
#.ENDIF
111
#.ENDIF
112
112
113
.IF "$(OS)"=="MACOSX"
114
SLOFILES += $(SLO)$/osxlocale.obj
115
.ENDIF
116
113
.IF "$(OS)"=="SOLARIS" || "$(OS)"=="FREEBSD" || "$(OS)"=="NETBSD" || "$(OS)$(CPU)"=="LINUXS"
117
.IF "$(OS)"=="SOLARIS" || "$(OS)"=="FREEBSD" || "$(OS)"=="NETBSD" || "$(OS)$(CPU)"=="LINUXS"
114
SLOFILES += $(SLO)$/backtrace.obj
118
SLOFILES += $(SLO)$/backtrace.obj
115
OBJFILES += $(OBJ)$/backtrace.obj
119
OBJFILES += $(OBJ)$/backtrace.obj
(-)sal/osl/unx/nlsupport.c (-21 / +11 lines)
Lines 841-846 Link Here
841
#include <CoreFoundation/CoreFoundation.h>
841
#include <CoreFoundation/CoreFoundation.h>
842
#include <postmac.h>
842
#include <postmac.h>
843
#include <sal/config.h>
843
#include <sal/config.h>
844
#include <dlfcn.h>
844
845
845
/* OS X locale discovery function from dylib */
846
/* OS X locale discovery function from dylib */
846
int (*pGetOSXLocale)( char *, sal_uInt32 );
847
int (*pGetOSXLocale)( char *, sal_uInt32 );
Lines 869-903 Link Here
869
        {
870
        {
870
            /* Load the locale discovery library if we are running on OS X */
871
            /* Load the locale discovery library if we are running on OS X */
871
872
872
            const sal_Char   *aLocaleLibName            = "libsalsystools" SAL_DLLEXTENSION;
873
            const sal_Char   *aGetOSXLocaleFunctionName = "macosx_getLocale";
873
            const sal_Char   *aGetOSXLocaleFunctionName = "macosx_getLocale";
874
            oslModule         pLocaleLib;
875
            void             *pFunc;
874
            void             *pFunc;
876
            int               err;
875
            int               err;
877
	
876
	
878
            pLocaleLib = osl_psz_loadModule( aLocaleLibName, SAL_LOADMODULE_DEFAULT );
877
            /* Grab a pointer to the locale function and call it */
879
            if( pLocaleLib )
878
            pFunc = dlsym( RTLD_DEFAULT, aGetOSXLocaleFunctionName );
879
            if( pFunc )
880
            {
880
            {
881
                /* Grab a pointer to the locale function and call it */
881
                pGetOSXLocale = ( int(*)(char *, sal_uInt32) )( pFunc );
882
                pFunc = osl_psz_getSymbol( pLocaleLib, aGetOSXLocaleFunctionName );
882
                locale = (char *)malloc( 20 );
883
                if( pFunc )
883
                if ( locale )
884
                {
884
                    err = (*pGetOSXLocale)( locale, 20 );
885
                    pGetOSXLocale = ( int(*)(char *, sal_uInt32) )( pFunc );
886
                    locale = (char *)malloc( 20 );
887
                    if ( locale )
888
                        err = (*pGetOSXLocale)( locale, 20 );
889
                    else
890
                        fprintf( stderr, "nlsupport.c:  locale allocation returned NULL!\n" );
891
                }
892
                else
885
                else
893
                    fprintf( stderr, "Could not load the OS X locale discovery function! (%s)\n", aGetOSXLocaleFunctionName );
886
                    fprintf( stderr, "nlsupport.c:  locale allocation returned NULL!\n" );
894
            }
887
            }
895
            else
888
            else
896
                fprintf( stderr, "Could not load the OS X locale discovery library! (%s)\n", aLocaleLibName );
889
                fprintf( stderr, "Could not load the OS X locale discovery function! (%s)\n", aGetOSXLocaleFunctionName );
897
890
        }
898
            /* Let go of the module, we don't need it anymore */
899
            osl_unloadModule( pLocaleLib );
900
         }
901
    }
891
    }
902
892
903
    /* handle the case where OS specific method of finding locale fails */
893
    /* handle the case where OS specific method of finding locale fails */
(-)sal/osl/unx/osxlocale.cxx (+132 lines)
Line 0 Link Here
1
/*************************************************************************
2
 *
3
 *  OpenOffice.org - a multi-platform office productivity suite
4
 *
5
 *  $RCSfile: osxlocale.cxx,v $
6
 *
7
 *  $Revision: 1.4 $
8
 *
9
 *  last change: $Author: obo $ $Date: 2006/09/17 09:06:24 $
10
 *
11
 *  The Contents of this file are made available subject to
12
 *  the terms of GNU Lesser General Public License Version 2.1.
13
 *
14
 *
15
 *    GNU Lesser General Public License Version 2.1
16
 *    =============================================
17
 *    Copyright 2005 by Sun Microsystems, Inc.
18
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
19
 *
20
 *    This library is free software; you can redistribute it and/or
21
 *    modify it under the terms of the GNU Lesser General Public
22
 *    License version 2.1, as published by the Free Software Foundation.
23
 *
24
 *    This library is distributed in the hope that it will be useful,
25
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27
 *    Lesser General Public License for more details.
28
 *
29
 *    You should have received a copy of the GNU Lesser General Public
30
 *    License along with this library; if not, write to the Free Software
31
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32
 *    MA  02111-1307  USA
33
 *
34
 ************************************************************************/
35
36
// MARKER(update_precomp.py): autogen include statement, do not remove
37
#include "precompiled_sal.hxx"
38
39
#include <sal/types.h>
40
#include <assert.h>
41
42
#include <premac.h>
43
#include <CoreServices/CoreServices.h>
44
#include <CoreFoundation/CoreFoundation.h>
45
#include <postmac.h>
46
47
namespace /* private */
48
{
49
	template <typename T>
50
	class CFGuard
51
	{
52
	public:
53
		explicit CFGuard(T& rT) : rT_(rT) {}
54
		~CFGuard() { if (rT_) CFRelease(rT_); }
55
	private:
56
		T& rT_;
57
	};
58
		
59
	typedef CFGuard<CFArrayRef> CFArrayGuard;
60
	typedef CFGuard<CFStringRef> CFStringGuard;
61
	typedef CFGuard<CFPropertyListRef> CFPropertyListGuard;
62
	
63
	/** Get the current process locale from system 
64
	*/
65
	CFStringRef getProcessLocale()
66
	{
67
		CFPropertyListRef pref = CFPreferencesCopyAppValue(CFSTR("AppleLocale"), kCFPreferencesCurrentApplication);
68
		CFPropertyListGuard proplGuard(pref);
69
		
70
		if (pref == NULL) // return fallback value 'en_US'
71
			 return CFStringCreateWithCString(kCFAllocatorDefault, "en_US", kCFStringEncodingASCII);
72
		
73
		CFStringRef sref = (CFGetTypeID(pref) == CFArrayGetTypeID()) ? (CFStringRef)CFArrayGetValueAtIndex((CFArrayRef)pref, 0) : (CFStringRef)pref;
74
		
75
		// NOTE: this API is only available with Mac OS X >=10.3. We need to use it because
76
		// Apple used non-ISO values on systems <10.2 like "German" for instance but didn't
77
		// upgrade those values during upgrade to newer Mac OS X versions. See also #i54337#
78
		return CFLocaleCreateCanonicalLocaleIdentifierFromString(kCFAllocatorDefault, sref);	
79
	}	
80
} // namespace private
81
	
82
/** Grab current locale from system.
83
*/
84
extern "C" int macosx_getLocale(char *locale, sal_uInt32 bufferLen)
85
{	
86
	CFStringRef sref = getProcessLocale();
87
	CFStringGuard sGuard(sref);
88
	
89
	assert(sref != NULL && "osxlocale.cxx: getProcessLocale must return a non-NULL value");
90
	
91
	// split the string into substrings; the first two (if there are two) substrings 
92
	// are language and country
93
	CFArrayRef subs = CFStringCreateArrayBySeparatingStrings(NULL, sref, CFSTR("_"));	
94
	CFArrayGuard arrGuard(subs);
95
		
96
	CFStringRef lang = (CFStringRef)CFArrayGetValueAtIndex(subs, 0);
97
	CFStringGetCString(lang, locale, bufferLen, kCFStringEncodingASCII);
98
		
99
	// country also available? Assumption: if the array contains more than one
100
	// value the second value is always the country!
101
	if (CFArrayGetCount(subs) > 1)
102
	{
103
		strlcat(locale, "_", bufferLen - strlen(locale));
104
			
105
		CFStringRef country = (CFStringRef)CFArrayGetValueAtIndex(subs, 1);
106
		CFStringGetCString(country, locale + strlen(locale), bufferLen - strlen(locale), kCFStringEncodingASCII);			
107
	}	    
108
    // Append 'UTF-8' to the locale because the Mac OS X file
109
    // system interface is UTF-8 based and sal tries to determine
110
    // the file system locale from the locale information 
111
	strlcat(locale, ".UTF-8", bufferLen - strlen(locale));							
112
		
113
	return noErr;
114
}
115
116
117
118
/*
119
 * macxp_OSXConvertCFEncodingToIANACharSetName
120
 *
121
 * Convert a CoreFoundation text encoding to an IANA charset name.
122
 */
123
extern "C" int macxp_OSXConvertCFEncodingToIANACharSetName( char *buffer, unsigned int bufferLen, CFStringEncoding cfEncoding )
124
{
125
	CFStringRef	sCFEncodingName;
126
127
	sCFEncodingName = CFStringConvertEncodingToIANACharSetName( cfEncoding );
128
	CFStringGetCString( sCFEncodingName, buffer, bufferLen, cfEncoding );
129
130
	return( noErr );
131
}
132
(-)sal/prj/build.lst (-1 lines)
Lines 3-9 Link Here
3
sa	sal\inc									nmake	-	all	sa_inc NULL
3
sa	sal\inc									nmake	-	all	sa_inc NULL
4
sa	sal\typesconfig							nmake	-	u	sa_tc sa_inc NULL
4
sa	sal\typesconfig							nmake	-	u	sa_tc sa_inc NULL
5
sa	sal\cpprt								nmake	-	u	sa_cpprt sa_util sa_inc NULL
5
sa	sal\cpprt								nmake	-	u	sa_cpprt sa_util sa_inc NULL
6
sa	sal\systools\macxp_extras\x11osx		nmake	-	u	sa_mxpext_x11osx sa_tc.u sa_inc NULL
7
sa	sal\rtl\source							nmake	-	all	sa_rtl sa_tc.u sa_inc NULL
6
sa	sal\rtl\source							nmake	-	all	sa_rtl sa_tc.u sa_inc NULL
8
sa	sal\textenc								nmake	-	all	sa_textenc sa_tc.u sa_inc NULL
7
sa	sal\textenc								nmake	-	all	sa_textenc sa_tc.u sa_inc NULL
9
sa	sal\systools\win32\uwinapi				nmake	-	n	sa_uwinapi sa_inc NULL
8
sa	sal\systools\win32\uwinapi				nmake	-	n	sa_uwinapi sa_inc NULL
(-)sal/systools/macxp_extras/x11osx/makefile.mk (-73 lines)
Lines 1-73 Link Here
1
#*************************************************************************
2
#
3
#   OpenOffice.org - a multi-platform office productivity suite
4
#
5
#   $RCSfile: makefile.mk,v $
6
#
7
#   $Revision: 1.4 $
8
#
9
#   last change: $Author: vg $ $Date: 2006/04/06 11:54:20 $
10
#
11
#   The Contents of this file are made available subject to
12
#   the terms of GNU Lesser General Public License Version 2.1.
13
#
14
#
15
#     GNU Lesser General Public License Version 2.1
16
#     =============================================
17
#     Copyright 2005 by Sun Microsystems, Inc.
18
#     901 San Antonio Road, Palo Alto, CA 94303, USA
19
#
20
#     This library is free software; you can redistribute it and/or
21
#     modify it under the terms of the GNU Lesser General Public
22
#     License version 2.1, as published by the Free Software Foundation.
23
#
24
#     This library is distributed in the hope that it will be useful,
25
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
26
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27
#     Lesser General Public License for more details.
28
#
29
#     You should have received a copy of the GNU Lesser General Public
30
#     License along with this library; if not, write to the Free Software
31
#     Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32
#     MA  02111-1307  USA
33
#
34
#*************************************************************************
35
36
PRJ=..$/..$/..
37
PRJINC=..$/..$/..
38
PRJNAME=sal
39
TARGET=salsystools
40
41
# --- Settings ----------------------------------
42
.INCLUDE : settings.mk
43
.INCLUDE :  $(PRJ)$/version.mk
44
45
.IF "$(OS)"!="MACOSX"
46
47
dummy:
48
	@echo "Nothing to build for OS $(OS)"
49
50
.ELSE		# "$(OS)"!="MACOSX"
51
52
# --- Files -------------------------------------
53
54
SLOFILES=\
55
	$(SLO)$/osxlocale.obj
56
57
# --- Library -----------------------------------
58
59
SHL1TARGET=$(TARGET)
60
SHL1OBJS=$(SLOFILES)
61
NOSHAREDSTATICLIB=TRUE
62
NOCREATESTATICLIB=TRUE
63
SHL1STDLIBS=\
64
	-framework CoreServices
65
	
66
SHL1DEPN=
67
68
.ENDIF		# "$(OS)"!="MACOSX"
69
70
# --- Targets ----------------------------------
71
72
.INCLUDE : target.mk
73
(-)sal/systools/macxp_extras/x11osx/osxlocale.cxx (-132 lines)
Lines 1-132 Link Here
1
/*************************************************************************
2
 *
3
 *  OpenOffice.org - a multi-platform office productivity suite
4
 *
5
 *  $RCSfile: osxlocale.cxx,v $
6
 *
7
 *  $Revision: 1.4 $
8
 *
9
 *  last change: $Author: obo $ $Date: 2006/09/17 09:06:24 $
10
 *
11
 *  The Contents of this file are made available subject to
12
 *  the terms of GNU Lesser General Public License Version 2.1.
13
 *
14
 *
15
 *    GNU Lesser General Public License Version 2.1
16
 *    =============================================
17
 *    Copyright 2005 by Sun Microsystems, Inc.
18
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
19
 *
20
 *    This library is free software; you can redistribute it and/or
21
 *    modify it under the terms of the GNU Lesser General Public
22
 *    License version 2.1, as published by the Free Software Foundation.
23
 *
24
 *    This library is distributed in the hope that it will be useful,
25
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27
 *    Lesser General Public License for more details.
28
 *
29
 *    You should have received a copy of the GNU Lesser General Public
30
 *    License along with this library; if not, write to the Free Software
31
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32
 *    MA  02111-1307  USA
33
 *
34
 ************************************************************************/
35
36
// MARKER(update_precomp.py): autogen include statement, do not remove
37
#include "precompiled_sal.hxx"
38
39
#include <sal/types.h>
40
#include <assert.h>
41
42
#include <premac.h>
43
#include <CoreServices/CoreServices.h>
44
#include <CoreFoundation/CoreFoundation.h>
45
#include <postmac.h>
46
47
namespace /* private */
48
{
49
	template <typename T>
50
	class CFGuard
51
	{
52
	public:
53
		explicit CFGuard(T& rT) : rT_(rT) {}
54
		~CFGuard() { if (rT_) CFRelease(rT_); }
55
	private:
56
		T& rT_;
57
	};
58
		
59
	typedef CFGuard<CFArrayRef> CFArrayGuard;
60
	typedef CFGuard<CFStringRef> CFStringGuard;
61
	typedef CFGuard<CFPropertyListRef> CFPropertyListGuard;
62
	
63
	/** Get the current process locale from system 
64
	*/
65
	CFStringRef getProcessLocale()
66
	{
67
		CFPropertyListRef pref = CFPreferencesCopyAppValue(CFSTR("AppleLocale"), kCFPreferencesCurrentApplication);
68
		CFPropertyListGuard proplGuard(pref);
69
		
70
		if (pref == NULL) // return fallback value 'en_US'
71
			 return CFStringCreateWithCString(kCFAllocatorDefault, "en_US", kCFStringEncodingASCII);
72
		
73
		CFStringRef sref = (CFGetTypeID(pref) == CFArrayGetTypeID()) ? (CFStringRef)CFArrayGetValueAtIndex((CFArrayRef)pref, 0) : (CFStringRef)pref;
74
		
75
		// NOTE: this API is only available with Mac OS X >=10.3. We need to use it because
76
		// Apple used non-ISO values on systems <10.2 like "German" for instance but didn't
77
		// upgrade those values during upgrade to newer Mac OS X versions. See also #i54337#
78
		return CFLocaleCreateCanonicalLocaleIdentifierFromString(kCFAllocatorDefault, sref);	
79
	}	
80
} // namespace private
81
	
82
/** Grab current locale from system.
83
*/
84
extern "C" int macosx_getLocale(char *locale, sal_uInt32 bufferLen)
85
{	
86
	CFStringRef sref = getProcessLocale();
87
	CFStringGuard sGuard(sref);
88
	
89
	assert(sref != NULL && "osxlocale.cxx: getProcessLocale must return a non-NULL value");
90
	
91
	// split the string into substrings; the first two (if there are two) substrings 
92
	// are language and country
93
	CFArrayRef subs = CFStringCreateArrayBySeparatingStrings(NULL, sref, CFSTR("_"));	
94
	CFArrayGuard arrGuard(subs);
95
		
96
	CFStringRef lang = (CFStringRef)CFArrayGetValueAtIndex(subs, 0);
97
	CFStringGetCString(lang, locale, bufferLen, kCFStringEncodingASCII);
98
		
99
	// country also available? Assumption: if the array contains more than one
100
	// value the second value is always the country!
101
	if (CFArrayGetCount(subs) > 1)
102
	{
103
		strlcat(locale, "_", bufferLen - strlen(locale));
104
			
105
		CFStringRef country = (CFStringRef)CFArrayGetValueAtIndex(subs, 1);
106
		CFStringGetCString(country, locale + strlen(locale), bufferLen - strlen(locale), kCFStringEncodingASCII);			
107
	}	    
108
    // Append 'UTF-8' to the locale because the Mac OS X file
109
    // system interface is UTF-8 based and sal tries to determine
110
    // the file system locale from the locale information 
111
	strlcat(locale, ".UTF-8", bufferLen - strlen(locale));							
112
		
113
	return noErr;
114
}
115
116
117
118
/*
119
 * macxp_OSXConvertCFEncodingToIANACharSetName
120
 *
121
 * Convert a CoreFoundation text encoding to an IANA charset name.
122
 */
123
extern "C" int macxp_OSXConvertCFEncodingToIANACharSetName( char *buffer, unsigned int bufferLen, CFStringEncoding cfEncoding )
124
{
125
	CFStringRef	sCFEncodingName;
126
127
	sCFEncodingName = CFStringConvertEncodingToIANACharSetName( cfEncoding );
128
	CFStringGetCString( sCFEncodingName, buffer, bufferLen, cfEncoding );
129
130
	return( noErr );
131
}
132

Return to issue 69373