merge the formfield patch from ooo-build
[ooovba.git] / desktop / win32 / source / extendloaderenvironment.hxx
blob8fd8742181aa0f0efe2f9f2e638307b8df3b55a2
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: extendloaderenvironment.hxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_DESKTOP_WIN32_SOURCE_EXTENDLOADERENVIRONMENT_HXX
32 #define INCLUDED_DESKTOP_WIN32_SOURCE_EXTENDLOADERENVIRONMENT_HXX
34 #include "sal/config.h"
36 #include <cstddef>
38 #include <tchar.h>
40 #define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
41 #define MY_STRING(s) (s), MY_LENGTH(s)
43 namespace desktop_win32 {
45 inline WCHAR * commandLineAppend(
46 WCHAR * buffer, WCHAR const * text, std::size_t length)
48 wcsncpy(buffer, text, length + 1); // trailing null
49 return buffer + length;
52 inline WCHAR * commandLineAppend(WCHAR * buffer, WCHAR const * text) {
53 return commandLineAppend(buffer, text, wcslen(text));
56 inline WCHAR * commandLineAppendEncoded(WCHAR * buffer, WCHAR const * text) {
57 std::size_t n = 0;
58 for (;;) {
59 WCHAR c = *text++;
60 if (c == L'\0') {
61 break;
62 } else if (c == L'$') {
63 buffer = commandLineAppend(buffer, MY_STRING(L"\\$"));
64 n = 0;
65 } else if (c == L'\\') {
66 buffer = commandLineAppend(buffer, MY_STRING(L"\\\\"));
67 n += 2;
68 } else {
69 *buffer++ = c;
70 n = 0;
73 // The command line will continue with a double quote, so double any
74 // preceding backslashes as required by Windows:
75 for (std::size_t i = 0; i < n; ++i) {
76 *buffer++ = L'\\';
78 *buffer = L'\0';
79 return buffer;
82 // Set the PATH environment variable in the current (loader) process, so that a
83 // following CreateProcess has the necessary environment:
85 // @param binPath
86 // Must point to an array of size at least MAX_PATH. Is filled with the null
87 // terminated full path to the "bin" file corresponding to the current
88 // executable.
90 // @param iniDirectory
91 // Must point to an array of size at least MAX_PATH. Is filled with the null
92 // terminated full directory path (ending in "\") to the "ini" file
93 // corresponding to the current executable.
94 void extendLoaderEnvironment(WCHAR * binPath, WCHAR * iniDirectory);
98 #endif