Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "dp_misc.h"
31 : : #include "dp_platform.hxx"
32 : : #include "rtl/ustring.hxx"
33 : : #include "rtl/ustrbuf.hxx"
34 : : #include "rtl/instance.hxx"
35 : : #include "rtl/bootstrap.hxx"
36 : :
37 : : #define PLATFORM_ALL "all"
38 : : #define PLATFORM_WIN_X86 "windows_x86"
39 : : #define PLATFORM_WIN_X86_64 "windows_x86_64"
40 : : #define PLATFORM_LINUX_X86 "linux_x86"
41 : : #define PLATFORM_LINUX_X86_64 "linux_x86_64"
42 : : #define PLATFORM_KFREEBSD_X86 "kfreebsd_x86"
43 : : #define PLATFORM_KFREEBSD_X86_64 "kfreebsd_x86_64"
44 : : #define PLATFORM_LINUX_SPARC "linux_sparc"
45 : : #define PLATFORM_LINUX_POWERPC "linux_powerpc"
46 : : #define PLATFORM_LINUX_POWERPC64 "linux_powerpc64"
47 : : #define PLATFORM_LINUX_ARM_EABI "linux_arm_eabi"
48 : : #define PLATFORM_LINUX_ARM_OABI "linux_arm_oabi"
49 : : #define PLATFORM_LINUX_MIPS_EL "linux_mips_el"
50 : : #define PLATFORM_LINUX_MIPS_EB "linux_mips_eb"
51 : : #define PLATFORM_LINUX_IA64 "linux_ia64"
52 : : #define PLATFORM_LINUX_M68K "linux_m68k"
53 : : #define PLATFORM_LINUX_S390 "linux_s390"
54 : : #define PLATFORM_LINUX_S390x "linux_s390x"
55 : : #define PLATFORM_LINUX_HPPA "linux_hppa"
56 : : #define PLATFORM_LINUX_ALPHA "linux_alpha"
57 : :
58 : :
59 : :
60 : : #define PLATFORM_SOLARIS_SPARC "solaris_sparc"
61 : : #define PLATFORM_SOLARIS_SPARC64 "solaris_sparc64"
62 : : #define PLATFORM_SOLARIS_X86 "solaris_x86"
63 : : #define PLATFORM_FREEBSD_X86 "freebsd_x86"
64 : : #define PLATFORM_FREEBSD_X86_64 "freebsd_x86_64"
65 : : #define PLATFORM_NETBSD_X86 "netbsd_x86"
66 : : #define PLATFORM_NETBSD_X86_64 "netbsd_x86_64"
67 : : #define PLATFORM_MACOSX_X86 "macosx_x86"
68 : : #define PLATFORM_MACOSX_PPC "macosx_powerpc"
69 : : #define PLATFORM_OPENBSD_X86 "openbsd_x86"
70 : : #define PLATFORM_OPENBSD_X86_64 "openbsd_x86_64"
71 : : #define PLATFORM_DRAGONFLY_X86 "dragonfly_x86"
72 : : #define PLATFORM_DRAGONFLY_X86_64 "dragonfly_x86_64"
73 : :
74 : :
75 : : #define PLATFORM_AIX_POWERPC "aix_powerpc"
76 : :
77 : :
78 : :
79 : :
80 : :
81 : :
82 : :
83 : : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
84 : : using ::rtl::OUString;
85 : : namespace css = ::com::sun::star;
86 : :
87 : : namespace dp_misc
88 : : {
89 : : namespace
90 : : {
91 : : struct StrOperatingSystem :
92 : : public rtl::StaticWithInit<OUString, StrOperatingSystem> {
93 : 124 : const OUString operator () () {
94 : 124 : OUString os( RTL_CONSTASCII_USTRINGPARAM("$_OS") );
95 : 124 : ::rtl::Bootstrap::expandMacros( os );
96 : 124 : return os;
97 : : }
98 : : };
99 : :
100 : : struct StrCPU :
101 : : public rtl::StaticWithInit<OUString, StrCPU> {
102 : 124 : const OUString operator () () {
103 : 124 : OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
104 : 124 : ::rtl::Bootstrap::expandMacros( arch );
105 : 124 : return arch;
106 : : }
107 : : };
108 : :
109 : :
110 : : struct StrPlatform : public rtl::StaticWithInit<
111 : : OUString, StrPlatform> {
112 : 124 : const OUString operator () () {
113 : 124 : ::rtl::OUStringBuffer buf;
114 [ + - ][ + - ]: 124 : buf.append( StrOperatingSystem::get() );
115 [ + - ]: 124 : buf.append( static_cast<sal_Unicode>('_') );
116 [ + - ][ + - ]: 124 : buf.append( StrCPU::get() );
117 [ + - ]: 124 : return buf.makeStringAndClear();
118 : : }
119 : : };
120 : :
121 : 186 : bool checkOSandCPU(OUString const & os, OUString const & cpu)
122 : : {
123 : 186 : return os.equals(StrOperatingSystem::get())
124 [ + - ][ + - ]: 186 : && cpu.equals(StrCPU::get());
125 : : }
126 : :
127 : 496 : bool isValidPlatform(OUString const & token )
128 : : {
129 : 496 : bool ret = false;
130 [ + + ]: 496 : if (token.equals(OUSTR(PLATFORM_ALL)))
131 : 310 : ret = true;
132 [ - + ]: 186 : else if (token.equals(OUSTR(PLATFORM_WIN_X86)))
133 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Windows"), OUSTR("x86"));
134 [ - + ]: 186 : else if (token.equals(OUSTR(PLATFORM_WIN_X86_64)))
135 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Windows"), OUSTR("x86_64"));
136 [ + - ]: 186 : else if (token.equals(OUSTR(PLATFORM_LINUX_X86)))
137 [ + - ][ + - ]: 186 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("x86"));
138 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_X86_64)))
139 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("X86_64"));
140 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86)))
141 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("x86"));
142 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86_64)))
143 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("X86_64"));
144 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_SPARC)))
145 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("SPARC"));
146 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC)))
147 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC"));
148 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC64)))
149 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC_64"));
150 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_EABI)))
151 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_EABI"));
152 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_OABI)))
153 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_OABI"));
154 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EL)))
155 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EL"));
156 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EB)))
157 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EB"));
158 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_IA64)))
159 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("IA64"));
160 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_M68K)))
161 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("M68K"));
162 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_S390)))
163 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390"));
164 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_S390x)))
165 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390x"));
166 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_HPPA)))
167 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("HPPA"));
168 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_ALPHA)))
169 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ALPHA"));
170 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC)))
171 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC"));
172 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC64)))
173 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC64"));
174 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_SOLARIS_X86)))
175 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("x86"));
176 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86)))
177 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("x86"));
178 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86_64)))
179 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("X86_64"));
180 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_NETBSD_X86)))
181 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("NetBSD"), OUSTR("x86"));
182 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_NETBSD_X86_64)))
183 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("NetBSD"), OUSTR("X86_64"));
184 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_MACOSX_X86)))
185 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("x86"));
186 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_MACOSX_PPC)))
187 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("PowerPC"));
188 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_AIX_POWERPC)))
189 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("AIX"), OUSTR("PowerPC"));
190 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_OPENBSD_X86)))
191 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("OpenBSD"), OUSTR("x86"));
192 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_OPENBSD_X86_64)))
193 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("OpenBSD"), OUSTR("X86_64"));
194 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_DRAGONFLY_X86)))
195 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("DragonFly"), OUSTR("x86"));
196 [ # # ]: 0 : else if (token.equals(OUSTR(PLATFORM_DRAGONFLY_X86_64)))
197 [ # # ][ # # ]: 0 : ret = checkOSandCPU(OUSTR("DragonFly"), OUSTR("X86_64"));
198 : : else
199 : : {
200 : : OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
201 : : "Check the platform element in the description.xml");
202 : 0 : ret = false;
203 : : }
204 : 496 : return ret;
205 : : }
206 : :
207 : : } // anon namespace
208 : : //=============================================================================
209 : :
210 : 1134 : OUString const & getPlatformString()
211 : : {
212 : 1134 : return StrPlatform::get();
213 : : }
214 : :
215 : 744 : bool platform_fits( OUString const & platform_string )
216 : : {
217 : 744 : sal_Int32 index = 0;
218 : 744 : for (;;)
219 : : {
220 : : const OUString token(
221 : 744 : platform_string.getToken( 0, ',', index ).trim() );
222 : : // check if this platform:
223 [ - + # # : 744 : if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
# # ][ + - ]
[ + - ]
224 : 0 : (token.indexOf( '_' ) < 0 && /* check OS part only */
225 [ # # ]: 0 : token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
226 : : {
227 : 744 : return true;
228 : : }
229 [ # # ]: 0 : if (index < 0)
230 : : break;
231 [ - + - ]: 744 : }
232 : 744 : return false;
233 : : }
234 : :
235 : 496 : bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
236 : : {
237 : 496 : bool ret = false;
238 [ + - ]: 496 : for (sal_Int32 i = 0; i < platformStrings.getLength(); i++)
239 : : {
240 [ + - ]: 496 : if (isValidPlatform(platformStrings[i]))
241 : : {
242 : 496 : ret = true;
243 : 496 : break;
244 : : }
245 : : }
246 : 496 : return ret;
247 : : }
248 : :
249 : : }
250 : :
251 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|