merge the formfield patch from ooo-build
[ooovba.git] / desktop / source / deployment / misc / dp_platform.cxx
bloba61fd6c4aff1ed0eaf7948de1f8eecd9d7638a29
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dp_platform.cxx,v $
11 * $Revision: 1.2.86.2 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_desktop.hxx"
35 #include "dp_misc.h"
36 #include "dp_platform.hxx"
37 #include "rtl/ustring.hxx"
38 #include "rtl/ustrbuf.hxx"
39 #include "rtl/instance.hxx"
40 #include "rtl/bootstrap.hxx"
42 #define PLATFORM_ALL "all"
43 #define PLATFORM_WIN_X86 "windows_x86"
44 #define PLATFORM_LINUX_X86 "linux_x86"
45 #define PLATFORM_LINUX_X86_64 "linux_x86_64"
46 #define PLATFORM_LINUX_SPARC "linux_sparc"
47 #define PLATFORM_LINUX_POWERPC "linux_powerpc"
48 #define PLATFORM_LINUX_POWERPC64 "linux_powerpc64"
49 #define PLATFORM_LINUX_ARM_EABI "linux_arm_eabi"
50 #define PLATFORM_LINUX_ARM_OABI "linux_arm_oabi"
51 #define PLATFORM_LINUX_MIPS_EL "linux_mips_el"
52 #define PLATFORM_LINUX_MIPS_EB "linux_mips_eb"
53 #define PLATFORM_LINUX_IA64 "linux_ia64"
54 #define PLATFORM_LINUX_S390 "linux_s390"
55 #define PLATFORM_LINUX_S390x "linux_s390x"
59 #define PLATFORM_SOLARIS_SPARC "solaris_sparc"
60 #define PLATFORM_SOLARIS_SPARC64 "solaris_sparc64"
61 #define PLATFORM_SOLARIS_X86 "solaris_x86"
62 #define PLATFORM_FREEBSD_X86 "freebsd_x86"
63 #define PLATFORM_FREEBSD_X86_64 "freebsd_x86_64"
64 #define PLATFORM_MACOSX_X86 "macosx_x86"
65 #define PLATFORM_MACOSX_PPC "macosx_powerpc"
66 #define PLATFORM_OS2_X86 "os2_x86"
76 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
77 using ::rtl::OUString;
78 namespace css = ::com::sun::star;
80 namespace dp_misc
82 namespace
84 struct StrOperatingSystem :
85 public rtl::StaticWithInit<const OUString, StrOperatingSystem> {
86 const OUString operator () () {
87 OUString os( RTL_CONSTASCII_USTRINGPARAM("$_OS") );
88 ::rtl::Bootstrap::expandMacros( os );
89 return os;
93 struct StrCPU :
94 public rtl::StaticWithInit<const OUString, StrCPU> {
95 const OUString operator () () {
96 OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
97 ::rtl::Bootstrap::expandMacros( arch );
98 return arch;
103 struct StrPlatform : public rtl::StaticWithInit<
104 const OUString, StrPlatform> {
105 const OUString operator () () {
106 ::rtl::OUStringBuffer buf;
107 buf.append( StrOperatingSystem::get() );
108 buf.append( static_cast<sal_Unicode>('_') );
109 OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
110 ::rtl::Bootstrap::expandMacros( arch );
111 buf.append( arch );
112 return buf.makeStringAndClear();
116 bool checkOSandCPU(OUString const & os, OUString const & cpu)
118 return os.equals(StrOperatingSystem::get())
119 && cpu.equals(StrCPU::get());
122 bool isValidPlatform(OUString const & token )
124 bool ret = false;
125 if (token.equals(OUSTR(PLATFORM_ALL)))
126 ret = true;
127 else if (token.equals(OUSTR(PLATFORM_WIN_X86)))
128 ret = checkOSandCPU(OUSTR("Windows"), OUSTR("x86"));
129 else if (token.equals(OUSTR(PLATFORM_LINUX_X86)))
130 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("x86"));
131 else if (token.equals(OUSTR(PLATFORM_LINUX_X86_64)))
132 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("X86_64"));
133 else if (token.equals(OUSTR(PLATFORM_LINUX_SPARC)))
134 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("SPARC"));
135 else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC)))
136 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC"));
137 else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC64)))
138 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC_64"));
139 else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_EABI)))
140 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_EABI"));
141 else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_OABI)))
142 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_OABI"));
143 else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EL)))
144 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EL"));
145 else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EB)))
146 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EB"));
147 else if (token.equals(OUSTR(PLATFORM_LINUX_IA64)))
148 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("IA64"));
149 else if (token.equals(OUSTR(PLATFORM_LINUX_S390)))
150 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390"));
151 else if (token.equals(OUSTR(PLATFORM_LINUX_S390x)))
152 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390x"));
153 else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC)))
154 ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC"));
155 else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC64)))
156 ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC64"));
157 else if (token.equals(OUSTR(PLATFORM_SOLARIS_X86)))
158 ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("x86"));
159 else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86)))
160 ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("x86"));
161 else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86_64)))
162 ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("X86_64"));
163 else if (token.equals(OUSTR(PLATFORM_MACOSX_X86)))
164 ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("x86"));
165 else if (token.equals(OUSTR(PLATFORM_MACOSX_PPC)))
166 ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("PowerPC"));
167 else if (token.equals(OUSTR(PLATFORM_OS2_X86)))
168 ret = checkOSandCPU(OUSTR("OS2"), OUSTR("x86"));
169 else
171 OSL_ENSURE(0, "Extension Manager: The extension supports an unknown platform. "
172 "Check the platform element in the descripion.xml");
173 ret = false;
175 return ret;
178 } // anon namespace
179 //=============================================================================
181 OUString const & getPlatformString()
183 return StrPlatform::get();
186 bool platform_fits( OUString const & platform_string )
188 sal_Int32 index = 0;
189 for (;;)
191 const OUString token(
192 platform_string.getToken( 0, ',', index ).trim() );
193 // check if this platform:
194 if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
195 (token.indexOf( '_' ) < 0 && /* check OS part only */
196 token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
198 return true;
200 if (index < 0)
201 break;
203 return false;
206 bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
208 bool ret = false;
209 for (sal_Int32 i = 0; i < platformStrings.getLength(); i++)
211 if (isValidPlatform(platformStrings[i]))
213 ret = true;
214 break;
217 return ret;