1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include <config_folders.h>
21 #include <rtl/bootstrap.h>
22 #include <rtl/bootstrap.hxx>
23 #include <osl/diagnose.h>
24 #include <osl/process.h>
25 #include <osl/file.hxx>
26 #include <osl/mutex.hxx>
27 #include <osl/profile.hxx>
28 #include <osl/security.hxx>
29 #include <rtl/string.hxx>
30 #include <rtl/ustrbuf.hxx>
31 #include <rtl/ustring.hxx>
32 #include <rtl/byteseq.hxx>
33 #include <sal/log.hxx>
34 #include <o3tl/lru_map.hxx>
35 #include <o3tl/string_view.hxx>
41 #include <string_view>
42 #include <unordered_map>
45 #include <osl/detail/android-bootstrap.h>
49 #include <osl/detail/emscripten-bootstrap.h>
54 #import <Foundation/Foundation.h>
58 using osl::DirectoryItem
;
59 using osl::FileStatus
;
64 struct Bootstrap_Impl
;
66 constexpr std::u16string_view VND_SUN_STAR_PATHNAME
= u
"vnd.sun.star.pathname:";
68 bool isPathnameUrl(std::u16string_view url
)
70 return o3tl::matchIgnoreAsciiCase(url
, VND_SUN_STAR_PATHNAME
);
73 bool resolvePathnameUrl(OUString
* url
)
76 if (!isPathnameUrl(*url
) ||
77 (osl::FileBase::getFileURLFromSystemPath(
78 url
->copy(VND_SUN_STAR_PATHNAME
.size()), *url
) ==
79 osl::FileBase::E_None
))
87 enum class LookupMode
{
88 NORMAL
, URE_BOOTSTRAP
,
89 URE_BOOTSTRAP_EXPANSION
};
91 struct ExpandRequestLink
{
92 ExpandRequestLink
const * next
;
93 Bootstrap_Impl
const * file
;
97 OUString
expandMacros(
98 Bootstrap_Impl
const * file
, std::u16string_view text
, LookupMode mode
,
99 ExpandRequestLink
const * requestStack
);
101 OUString
recursivelyExpandMacros(
102 Bootstrap_Impl
const * file
, std::u16string_view text
, LookupMode mode
,
103 Bootstrap_Impl
const * requestFile
, OUString
const & requestKey
,
104 ExpandRequestLink
const * requestStack
)
106 for (; requestStack
; requestStack
= requestStack
->next
) {
107 if (requestStack
->file
== requestFile
&&
108 requestStack
->key
== requestKey
)
110 return "***RECURSION DETECTED***";
113 ExpandRequestLink link
= { requestStack
, requestFile
, requestKey
};
114 return expandMacros(file
, text
, mode
, &link
);
117 struct rtl_bootstrap_NameValue
122 rtl_bootstrap_NameValue()
124 rtl_bootstrap_NameValue(OUString name
, OUString value
)
125 : sName(std::move( name
)),
126 sValue(std::move( value
))
132 typedef std::vector
<rtl_bootstrap_NameValue
> NameValueVector
;
135 NameValueVector
const & vector
, OUString
const & key
,
139 auto i
= std::find_if(vector
.begin(), vector
.end(),
140 [&key
](const rtl_bootstrap_NameValue
& rNameValue
) { return rNameValue
.sName
== key
; });
141 if (i
!= vector
.end())
151 NameValueVector rtl_bootstrap_set_vector
;
154 static bool getFromCommandLineArgs(
155 OUString
const & key
, OUString
* value
)
159 static NameValueVector nameValueVector
= []()
163 sal_Int32 nArgCount
= osl_getCommandArgCount();
164 for(sal_Int32 i
= 0; i
< nArgCount
; ++ i
)
167 osl_getCommandArg( i
, &pArg
.pData
);
168 if( (pArg
.startsWith("-") || pArg
.startsWith("/") ) &&
169 pArg
.match("env:", 1) )
171 sal_Int32 nIndex
= pArg
.indexOf( '=' );
175 rtl_bootstrap_NameValue nameValue
;
176 nameValue
.sName
= pArg
.copy( 5, nIndex
- 5 );
177 nameValue
.sValue
= pArg
.copy( nIndex
+1 );
179 if( i
== nArgCount
-1 &&
180 nameValue
.sValue
.getLength() &&
181 nameValue
.sValue
[nameValue
.sValue
.getLength()-1] == 13 )
183 // avoid the 13 linefeed for the last argument,
184 // when the executable is started from a script,
185 // that was edited on windows
186 nameValue
.sValue
= nameValue
.sValue
.copy(0,nameValue
.sValue
.getLength()-1);
189 tmp
.push_back( nameValue
);
196 return find(nameValueVector
, key
, value
);
199 static void getExecutableDirectory_Impl(rtl_uString
** ppDirURL
)
202 osl_getExecutableFile(&(fileName
.pData
));
204 sal_Int32 nDirEnd
= fileName
.lastIndexOf('/');
205 OSL_ENSURE(nDirEnd
>= 0, "Cannot locate executable directory");
207 rtl_uString_newFromStr_WithLength(ppDirURL
,fileName
.getStr(),nDirEnd
);
210 static OUString
& getIniFileName_Impl()
212 static OUString aStaticName
= []() {
216 // On iOS hardcode the inifile as "rc" in the .app
217 // directory. Apps are self-contained anyway, there is no
218 // possibility to have several "applications" in the same
219 // installation location with different inifiles.
220 const char *inifile
= [[@
"vnd.sun.star.pathname:" stringByAppendingString
: [[[NSBundle mainBundle
] bundlePath
] stringByAppendingPathComponent
: @
"rc"]] UTF8String
];
221 fileName
= OUString(inifile
, strlen(inifile
), RTL_TEXTENCODING_UTF8
);
222 resolvePathnameUrl(&fileName
);
223 #elif defined ANDROID
224 // Apps are self-contained on Android, too, can as well hardcode
225 // it as "rc" in the "/assets" directory, i.e. inside the app's
226 // .apk (zip) archive as the /assets/rc file.
227 fileName
= OUString("vnd.sun.star.pathname:/assets/rc");
228 resolvePathnameUrl(&fileName
);
229 #elif defined(EMSCRIPTEN)
230 fileName
= OUString("vnd.sun.star.pathname:/instdir/program/sofficerc");
231 resolvePathnameUrl(&fileName
);
233 if (getFromCommandLineArgs("INIFILENAME", &fileName
))
235 resolvePathnameUrl(&fileName
);
239 osl_getExecutableFile(&(fileName
.pData
));
241 // get rid of a potential executable extension
242 OUString progExt
= ".bin";
243 if (fileName
.getLength() > progExt
.getLength()
244 && o3tl::equalsIgnoreAsciiCase(fileName
.subView(fileName
.getLength() - progExt
.getLength()), progExt
))
246 fileName
= fileName
.copy(0, fileName
.getLength() - progExt
.getLength());
250 if (fileName
.getLength() > progExt
.getLength()
251 && o3tl::equalsIgnoreAsciiCase(fileName
.subView(fileName
.getLength() - progExt
.getLength()), progExt
))
253 fileName
= fileName
.copy(0, fileName
.getLength() - progExt
.getLength());
256 // append config file suffix
257 fileName
+= SAL_CONFIGFILE("");
260 // We keep only executables in the MacOS folder, and all
261 // rc files in LIBO_ETC_FOLDER (typically "Resources").
262 sal_Int32 off
= fileName
.lastIndexOf( "/MacOS/" );
264 fileName
= fileName
.replaceAt(off
+ 1, strlen("MacOS"), u
"" LIBO_ETC_FOLDER
);
275 // ensure the given file url has no final slash
277 static void EnsureNoFinalSlash (OUString
& url
)
279 sal_Int32 i
= url
.getLength();
281 if (i
> 0 && url
[i
- 1] == '/')
282 url
= url
.copy(0, i
- 1);
287 struct Bootstrap_Impl
289 sal_Int32 _nRefCount
;
290 Bootstrap_Impl
* _base_ini
;
292 NameValueVector _nameValueVector
;
295 explicit Bootstrap_Impl (OUString
const & rIniName
);
298 static void * operator new (std::size_t n
)
299 { return malloc (sal_uInt32(n
)); }
300 static void operator delete (void * p
, std::size_t)
304 OUString
const & key
, rtl_uString
** value
,
305 rtl_uString
* defaultValue
, LookupMode mode
, bool override
,
306 ExpandRequestLink
const * requestStack
) const;
308 OUString
const & key
, rtl_uString
** value
, LookupMode mode
,
309 ExpandRequestLink
const * requestStack
) const;
310 bool getAmbienceValue(
311 OUString
const & key
, rtl_uString
** value
, LookupMode mode
,
312 ExpandRequestLink
const * requestStack
) const;
314 rtl_uString
** value
, OUString
const & text
, LookupMode mode
,
315 Bootstrap_Impl
const * requestFile
, OUString
const & requestKey
,
316 ExpandRequestLink
const * requestStack
) const;
321 Bootstrap_Impl::Bootstrap_Impl( OUString
const & rIniName
)
323 _base_ini( nullptr ),
326 OUString
base_ini(getIniFileName_Impl());
328 FileStatus
status( osl_FileStatus_Mask_FileURL
);
329 DirectoryItem dirItem
;
330 if (DirectoryItem::get(base_ini
, dirItem
) == DirectoryItem::E_None
&&
331 dirItem
.getFileStatus(status
) == DirectoryItem::E_None
)
333 base_ini
= status
.getFileURL();
334 if (rIniName
!= base_ini
)
336 _base_ini
= static_cast< Bootstrap_Impl
* >(
337 rtl_bootstrap_args_open(base_ini
.pData
));
340 SAL_INFO("sal.bootstrap", "Bootstrap_Impl(): sFile=" << _iniName
);
341 oslFileHandle handle
;
342 if (!_iniName
.isEmpty() &&
343 osl_openFile(_iniName
.pData
, &handle
, osl_File_OpenFlag_Read
) == osl_File_E_None
)
345 rtl::ByteSequence seq
;
347 while (osl_readLine(handle
, reinterpret_cast<sal_Sequence
**>(&seq
)) == osl_File_E_None
)
349 OString
line(reinterpret_cast<const char *>(seq
.getConstArray()), seq
.getLength());
350 sal_Int32 nIndex
= line
.indexOf('=');
353 struct rtl_bootstrap_NameValue nameValue
;
354 nameValue
.sName
= OStringToOUString(o3tl::trim(line
.subView(0,nIndex
)), RTL_TEXTENCODING_ASCII_US
);
355 nameValue
.sValue
= OStringToOUString(o3tl::trim(line
.subView(nIndex
+1)), RTL_TEXTENCODING_UTF8
);
357 SAL_INFO("sal.bootstrap", "pushing: name=" << nameValue
.sName
<< " value=" << nameValue
.sValue
);
359 _nameValueVector
.push_back(nameValue
);
362 osl_closeFile(handle
);
366 SAL_INFO( "sal.bootstrap", "couldn't open file: " << _iniName
);
370 Bootstrap_Impl::~Bootstrap_Impl()
373 rtl_bootstrap_args_close( _base_ini
);
378 Bootstrap_Impl
* get_static_bootstrap_handle()
380 static Bootstrap_Impl
* s_handle
= []() {
381 OUString
iniName(getIniFileName_Impl());
382 Bootstrap_Impl
* that
= static_cast<Bootstrap_Impl
*>(rtl_bootstrap_args_open(iniName
.pData
));
385 that
= new Bootstrap_Impl(iniName
);
394 struct FundamentalIniData
396 rtlBootstrapHandle ini
;
402 (get_static_bootstrap_handle()->getValue(
403 "URE_BOOTSTRAP", &uri
.pData
, nullptr, LookupMode::NORMAL
, false,
405 && resolvePathnameUrl(&uri
))
406 ? rtl_bootstrap_args_open(uri
.pData
) : nullptr;
409 ~FundamentalIniData() { rtl_bootstrap_args_close(ini
); }
411 FundamentalIniData(const FundamentalIniData
&) = delete;
412 FundamentalIniData
& operator=(const FundamentalIniData
&) = delete;
415 FundamentalIniData
& FundamentalIni()
417 static FundamentalIniData SINGLETON
;
423 bool Bootstrap_Impl::getValue(
424 OUString
const & key
, rtl_uString
** value
, rtl_uString
* defaultValue
,
425 LookupMode mode
, bool override
, ExpandRequestLink
const * requestStack
)
428 if (mode
== LookupMode::NORMAL
&& key
== "URE_BOOTSTRAP")
429 mode
= LookupMode::URE_BOOTSTRAP
;
431 if (override
&& getDirectValue(key
, value
, mode
, requestStack
))
437 value
, OUString(RTL_OS
).pData
);
444 value
, OUString(RTL_ARCH
).pData
);
448 if (key
== "_CPPU_ENV")
453 SAL_STRINGIFY(CPPU_ENV
)).
458 #if defined ANDROID || defined EMSCRIPTEN
459 if (key
== "APP_DATA_DIR")
461 const char *app_data_dir
= lo_get_app_data_dir();
463 value
, OUString(app_data_dir
, strlen(app_data_dir
), RTL_TEXTENCODING_UTF8
).pData
);
469 if (key
== "APP_DATA_DIR")
471 const char *app_data_dir
= [[[[NSBundle mainBundle
] bundlePath
] stringByAddingPercentEncodingWithAllowedCharacters
: [NSCharacterSet URLPathAllowedCharacterSet
]] UTF8String
];
473 value
, OUString(app_data_dir
, strlen(app_data_dir
), RTL_TEXTENCODING_UTF8
).pData
);
483 0, std::max
<sal_Int32
>(0, _iniName
.lastIndexOf('/'))).pData
);
487 if (getAmbienceValue(key
, value
, mode
, requestStack
))
490 if (key
== "SYSUSERCONFIG")
493 bool b
= osl::Security().getConfigDir(v
);
494 EnsureNoFinalSlash(v
);
495 rtl_uString_assign(value
, v
.pData
);
499 if (key
== "SYSUSERHOME")
502 bool b
= osl::Security().getHomeDir(v
);
503 EnsureNoFinalSlash(v
);
504 rtl_uString_assign(value
, v
.pData
);
508 if (key
== "SYSBINDIR")
510 getExecutableDirectory_Impl(value
);
514 if (_base_ini
!= nullptr && _base_ini
->getDirectValue(key
, value
, mode
, requestStack
))
517 if (!override
&& getDirectValue(key
, value
, mode
, requestStack
))
520 if (mode
== LookupMode::NORMAL
)
522 FundamentalIniData
const & d
= FundamentalIni();
523 Bootstrap_Impl
const * b
= static_cast<Bootstrap_Impl
const *>(d
.ini
);
524 if (b
!= nullptr && b
!= this && b
->getDirectValue(key
, value
, mode
, requestStack
))
528 if (defaultValue
!= nullptr)
530 rtl_uString_assign(value
, defaultValue
);
534 rtl_uString_new(value
);
538 bool Bootstrap_Impl::getDirectValue(
539 OUString
const & key
, rtl_uString
** value
, LookupMode mode
,
540 ExpandRequestLink
const * requestStack
) const
543 if (find(_nameValueVector
, key
, &v
))
545 expandValue(value
, v
, mode
, this, key
, requestStack
);
552 bool Bootstrap_Impl::getAmbienceValue(
553 OUString
const & key
, rtl_uString
** value
, LookupMode mode
,
554 ExpandRequestLink
const * requestStack
) const
560 osl::MutexGuard
g(osl::Mutex::getGlobalMutex());
561 f
= find(rtl_bootstrap_set_vector
, key
, &v
);
564 if (f
|| getFromCommandLineArgs(key
, &v
) ||
565 osl_getEnvironment(key
.pData
, &v
.pData
) == osl_Process_E_None
)
567 expandValue(value
, v
, mode
, nullptr, key
, requestStack
);
574 void Bootstrap_Impl::expandValue(
575 rtl_uString
** value
, OUString
const & text
, LookupMode mode
,
576 Bootstrap_Impl
const * requestFile
, OUString
const & requestKey
,
577 ExpandRequestLink
const * requestStack
) const
581 (mode
== LookupMode::URE_BOOTSTRAP
&& isPathnameUrl(text
) ?
583 recursivelyExpandMacros(
585 (mode
== LookupMode::URE_BOOTSTRAP
?
586 LookupMode::URE_BOOTSTRAP_EXPANSION
: mode
),
587 requestFile
, requestKey
, requestStack
)).pData
);
592 typedef std::unordered_map
< OUString
, Bootstrap_Impl
* > bootstrap_map_t
;
593 bootstrap_map_t bootstrap_map
;
597 rtlBootstrapHandle SAL_CALL
rtl_bootstrap_args_open(rtl_uString
* pIniName
)
599 static o3tl::lru_map
<OUString
,OUString
> fileUrlLookupCache(16);
601 OUString
originalIniName( pIniName
);
604 osl::ResettableMutexGuard
guard(osl::Mutex::getGlobalMutex());
605 auto cacheIt
= fileUrlLookupCache
.find(originalIniName
);
606 bool foundInCache
= cacheIt
!= fileUrlLookupCache
.end();
608 iniName
= cacheIt
->second
;
614 FileStatus
status(osl_FileStatus_Mask_FileURL
);
615 DirectoryItem dirItem
;
616 if (DirectoryItem::get(originalIniName
, dirItem
) != DirectoryItem::E_None
||
617 dirItem
.getFileStatus(status
) != DirectoryItem::E_None
)
621 iniName
= status
.getFileURL();
626 fileUrlLookupCache
.insert({originalIniName
, iniName
});
627 Bootstrap_Impl
* that
;
628 auto iFind(bootstrap_map
.find(iniName
));
629 if (iFind
== bootstrap_map
.end())
632 that
= new Bootstrap_Impl(iniName
);
634 iFind
= bootstrap_map
.find(iniName
);
635 if (iFind
== bootstrap_map
.end())
638 ::std::pair
< bootstrap_map_t::iterator
, bool > insertion(
639 bootstrap_map
.emplace(iniName
, that
));
640 OSL_ASSERT(insertion
.second
);
644 Bootstrap_Impl
* obsolete
= that
;
645 that
= iFind
->second
;
653 that
= iFind
->second
;
656 return static_cast< rtlBootstrapHandle
>( that
);
659 void SAL_CALL
rtl_bootstrap_args_close(rtlBootstrapHandle handle
) SAL_THROW_EXTERN_C()
664 Bootstrap_Impl
* that
= static_cast< Bootstrap_Impl
* >( handle
);
666 osl::MutexGuard
guard(osl::Mutex::getGlobalMutex());
667 OSL_ASSERT(bootstrap_map
.find(that
->_iniName
)->second
== that
);
670 if (that
->_nRefCount
!= 0)
673 std::size_t const nLeaking
= 8; // only hold up to 8 files statically
674 if (bootstrap_map
.size() > nLeaking
)
676 ::std::size_t erased
= bootstrap_map
.erase( that
->_iniName
);
684 sal_Bool SAL_CALL
rtl_bootstrap_get_from_handle(
685 rtlBootstrapHandle handle
,
687 rtl_uString
** ppValue
,
688 rtl_uString
* pDefault
691 osl::MutexGuard
guard(osl::Mutex::getGlobalMutex());
697 handle
= get_static_bootstrap_handle();
699 found
= static_cast< Bootstrap_Impl
* >(handle
)->getValue(
700 pName
, ppValue
, pDefault
, LookupMode::NORMAL
, false, nullptr );
706 void SAL_CALL
rtl_bootstrap_get_iniName_from_handle (
707 rtlBootstrapHandle handle
,
708 rtl_uString
** ppIniName
716 Bootstrap_Impl
* pImpl
= static_cast<Bootstrap_Impl
*>(handle
);
717 rtl_uString_assign(ppIniName
, pImpl
->_iniName
.pData
);
721 const OUString
& iniName
= getIniFileName_Impl();
722 rtl_uString_assign(ppIniName
, iniName
.pData
);
726 void SAL_CALL
rtl_bootstrap_setIniFileName (
730 osl::MutexGuard
guard(osl::Mutex::getGlobalMutex());
731 OUString
& file
= getIniFileName_Impl();
735 sal_Bool SAL_CALL
rtl_bootstrap_get (
737 rtl_uString
** ppValue
,
738 rtl_uString
* pDefault
741 return rtl_bootstrap_get_from_handle(nullptr, pName
, ppValue
, pDefault
);
744 void SAL_CALL
rtl_bootstrap_set (
749 const OUString
name(pName
);
750 const OUString
value(pValue
);
752 osl::MutexGuard
guard(osl::Mutex::getGlobalMutex());
754 for (auto & item
: rtl_bootstrap_set_vector
)
756 if (item
.sName
== name
)
763 SAL_INFO("sal.bootstrap", "explicitly setting: name=" << name
<< " value=" <<value
);
765 rtl_bootstrap_set_vector
.emplace_back(name
, value
);
768 void SAL_CALL
rtl_bootstrap_expandMacros_from_handle(
769 rtlBootstrapHandle handle
,
770 rtl_uString
** macro
)
773 handle
= get_static_bootstrap_handle();
775 OUString
expanded(expandMacros(static_cast< Bootstrap_Impl
* >(handle
),
776 OUString::unacquired(macro
),
777 LookupMode::NORMAL
, nullptr));
778 rtl_uString_assign(macro
, expanded
.pData
);
781 void SAL_CALL
rtl_bootstrap_expandMacros(rtl_uString
** macro
)
783 rtl_bootstrap_expandMacros_from_handle(nullptr, macro
);
786 void rtl_bootstrap_encode(rtl_uString
const * value
, rtl_uString
** encoded
)
789 OUStringBuffer
b(value
->length
+5);
790 for (sal_Int32 i
= 0; i
< value
->length
; ++i
)
792 sal_Unicode c
= value
->buffer
[i
];
793 if (c
== '$' || c
== '\\')
799 rtl_uString_assign(encoded
, b
.makeStringAndClear().pData
);
804 int hex(sal_Unicode c
)
807 c
>= '0' && c
<= '9' ? c
- '0' :
808 c
>= 'A' && c
<= 'F' ? c
- 'A' + 10 :
809 c
>= 'a' && c
<= 'f' ? c
- 'a' + 10 : -1;
812 sal_Unicode
read(std::u16string_view text
, std::size_t * pos
, bool * escaped
)
814 OSL_ASSERT(pos
&& *pos
< text
.length() && escaped
);
815 sal_Unicode c
= text
[(*pos
)++];
819 if (*pos
< text
.length() - 4 && text
[*pos
] == 'u' &&
820 ((n1
= hex(text
[*pos
+ 1])) >= 0) &&
821 ((n2
= hex(text
[*pos
+ 2])) >= 0) &&
822 ((n3
= hex(text
[*pos
+ 3])) >= 0) &&
823 ((n4
= hex(text
[*pos
+ 4])) >= 0))
827 return static_cast< sal_Unicode
>(
828 (n1
<< 12) | (n2
<< 8) | (n3
<< 4) | n4
);
831 if (*pos
< text
.length())
834 return text
[(*pos
)++];
843 Bootstrap_Impl
const * file
, LookupMode mode
, bool override
,
844 OUString
const & key
, ExpandRequestLink
const * requestStack
)
847 (file
== nullptr ? get_static_bootstrap_handle() : file
)->getValue(
848 key
, &v
.pData
, nullptr, mode
, override
, requestStack
);
852 OUString
expandMacros(
853 Bootstrap_Impl
const * file
, std::u16string_view text
, LookupMode mode
,
854 ExpandRequestLink
const * requestStack
)
856 SAL_INFO("sal.bootstrap", "expandMacros called with: " << OUString(text
));
857 OUStringBuffer
buf(2048);
859 for (std::size_t i
= 0; i
< text
.length();)
862 sal_Unicode c
= read(text
, &i
, &escaped
);
863 if (escaped
|| c
!= '$')
869 if (i
< text
.length() && text
[i
] == '{')
873 sal_Int32 nesting
= 0;
877 while (i
< text
.length())
880 c
= read(text
, &i
, &escaped
);
892 seg
[n
++] = text
.substr(p
, j
- p
);
901 if (nesting
== 0 && n
< 2)
903 seg
[n
++] = text
.substr(p
, j
- p
);
911 for (int j
= 0; j
< n
; ++j
)
913 seg
[j
] = expandMacros(file
, seg
[j
], mode
, requestStack
);
916 if (n
== 3 && seg
[0] != ".override" && seg
[1].isEmpty())
918 // For backward compatibility, treat ${file::key} the
919 // same as just ${file:key}:
926 buf
.append(lookup(file
, mode
, false, seg
[0], requestStack
));
930 rtl::Bootstrap
b(seg
[0]);
931 Bootstrap_Impl
* f
= static_cast< Bootstrap_Impl
* >(b
.getHandle());
932 buf
.append(lookup(f
, mode
, false, seg
[1], requestStack
));
934 else if (n
== 3 && seg
[0] == ".override")
936 rtl::Bootstrap
b(seg
[1]);
937 Bootstrap_Impl
* f
= static_cast< Bootstrap_Impl
* >(b
.getHandle());
938 buf
.append(lookup(f
, mode
, f
!= nullptr, seg
[2], requestStack
));
942 // Going through osl::Profile, this code erroneously
943 // does not recursively expand macros in the resulting
944 // replacement text (and if it did, it would fail to
945 // detect cycles that pass through here):
948 osl::Profile(seg
[0]).readString(
950 seg
[1], RTL_TEXTENCODING_UTF8
),
952 seg
[2], RTL_TEXTENCODING_UTF8
),
954 RTL_TEXTENCODING_UTF8
));
959 OUStringBuffer
kbuf(sal_Int32(text
.length()));
960 for (; i
< text
.length();)
963 c
= read(text
, &j
, &escaped
);
965 (c
== ' ' || c
== '$' || c
== '-' || c
== '/' ||
966 c
== ';' || c
== '\\'))
977 file
, mode
, false, kbuf
.makeStringAndClear(),
983 OUString
result(buf
.makeStringAndClear());
984 SAL_INFO("sal.bootstrap", "expandMacros result: " << result
);
991 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */