summaryrefslogtreecommitdiff
path: root/tools/source/misc
diff options
context:
space:
mode:
Diffstat (limited to 'tools/source/misc')
-rw-r--r--tools/source/misc/appendunixshellword.cxx76
-rw-r--r--tools/source/misc/extendapplicationenvironment.cxx92
-rw-r--r--tools/source/misc/getprocessworkingdir.cxx64
-rw-r--r--tools/source/misc/makefile.mk47
-rw-r--r--tools/source/misc/pathutils.cxx219
-rw-r--r--tools/source/misc/solarmutex.cxx60
6 files changed, 558 insertions, 0 deletions
diff --git a/tools/source/misc/appendunixshellword.cxx b/tools/source/misc/appendunixshellword.cxx
new file mode 100644
index 000000000000..af2a05b00716
--- /dev/null
+++ b/tools/source/misc/appendunixshellword.cxx
@@ -0,0 +1,76 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_tools.hxx"
+#include "sal/config.h"
+
+#if defined UNX
+
+#include <cstddef>
+
+#include "osl/diagnose.h"
+#include "rtl/strbuf.hxx"
+#include "rtl/string.h"
+#include "rtl/string.hxx"
+#include "sal/types.h"
+#include "tools/appendunixshellword.hxx"
+
+namespace tools {
+
+void appendUnixShellWord(
+ rtl::OStringBuffer * accumulator, rtl::OString const & text)
+{
+ OSL_ASSERT(accumulator != NULL);
+ if (text.getLength() == 0) {
+ accumulator->append(RTL_CONSTASCII_STRINGPARAM("''"));
+ } else {
+ bool quoted = false;
+ for (sal_Int32 i = 0; i < text.getLength(); ++i) {
+ char c = text[i];
+ if (c == '\'') {
+ if (quoted) {
+ accumulator->append('\'');
+ quoted = false;
+ }
+ accumulator->append(RTL_CONSTASCII_STRINGPARAM("\\'"));
+ } else {
+ if (!quoted) {
+ accumulator->append('\'');
+ quoted = true;
+ }
+ accumulator->append(c);
+ }
+ }
+ if (quoted) {
+ accumulator->append('\'');
+ }
+ }
+}
+
+}
+
+#endif
diff --git a/tools/source/misc/extendapplicationenvironment.cxx b/tools/source/misc/extendapplicationenvironment.cxx
new file mode 100644
index 000000000000..440f5a5cb207
--- /dev/null
+++ b/tools/source/misc/extendapplicationenvironment.cxx
@@ -0,0 +1,92 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_tools.hxx"
+#include "sal/config.h"
+
+#include <stdlib.h>
+
+#if defined UNX
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#endif
+
+#include "osl/process.h"
+#include "osl/thread.h"
+#include "rtl/bootstrap.hxx"
+#include "rtl/string.hxx"
+#include "rtl/textcvt.h"
+#include "rtl/ustrbuf.hxx"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+#include "tools/extendapplicationenvironment.hxx"
+
+namespace tools {
+
+void extendApplicationEnvironment() {
+#if defined UNX
+ // Try to set RLIMIT_NOFILE as large as possible (failure is harmless):
+ rlimit l;
+ if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
+ l.rlim_cur = l.rlim_max;
+ setrlimit(RLIMIT_NOFILE, &l);
+ }
+#endif
+
+ // Make sure URE_BOOTSTRAP environment variable is set (failure is fatal):
+ rtl::OUStringBuffer env;
+ rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP"));
+ rtl::OUString uri;
+ if (rtl::Bootstrap::get(envVar, uri))
+ {
+ if (!uri.matchIgnoreAsciiCaseAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pathname:")))
+ {
+ uri = rtl::Bootstrap::encode(uri);
+ }
+ env.append(uri);
+ } else {
+ if (osl_getExecutableFile(&uri.pData) != osl_Process_E_None) {
+ abort();
+ }
+ sal_Int32 i = uri.lastIndexOf('/');
+ if (i >= 0) {
+ uri = uri.copy(0, i + 1);
+ }
+ env.append(rtl::Bootstrap::encode(uri));
+ env.appendAscii(
+ RTL_CONSTASCII_STRINGPARAM(SAL_CONFIGFILE("fundamental")));
+ }
+ rtl::OUString envValue(env.makeStringAndClear());
+ if (osl_setEnvironment(envVar.pData, envValue.pData) != osl_Process_E_None) {
+ abort();
+ }
+}
+
+}
diff --git a/tools/source/misc/getprocessworkingdir.cxx b/tools/source/misc/getprocessworkingdir.cxx
new file mode 100644
index 000000000000..8cad594befca
--- /dev/null
+++ b/tools/source/misc/getprocessworkingdir.cxx
@@ -0,0 +1,64 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_tools.hxx"
+#include "sal/config.h"
+
+#include <cstddef>
+
+#include "osl/diagnose.h"
+#include "osl/file.hxx"
+#include "osl/process.h"
+#include "rtl/bootstrap.hxx"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+#include "tools/getprocessworkingdir.hxx"
+
+namespace tools {
+
+bool getProcessWorkingDir(rtl::OUString * url) {
+ OSL_ASSERT(url != NULL);
+ rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("$OOO_CWD"));
+ rtl::Bootstrap::expandMacros(s);
+ if (s.getLength() == 0) {
+ if (osl_getProcessWorkingDir(&url->pData) == osl_Process_E_None) {
+ return true;
+ }
+ } else if (s[0] == '1') {
+ *url = s.copy(1);
+ return true;
+ } else if (s[0] == '2' &&
+ (osl::FileBase::getFileURLFromSystemPath(s.copy(1), *url) ==
+ osl::FileBase::E_None))
+ {
+ return true;
+ }
+ *url = rtl::OUString();
+ return false;
+}
+
+}
diff --git a/tools/source/misc/makefile.mk b/tools/source/misc/makefile.mk
new file mode 100644
index 000000000000..a426bb4053c3
--- /dev/null
+++ b/tools/source/misc/makefile.mk
@@ -0,0 +1,47 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ = ..$/..
+PRJNAME = tools
+TARGET = misc
+LIBTARGET = NO
+ENABLE_EXCEPTIONS = TRUE
+
+.INCLUDE: settings.mk
+.INCLUDE: $(PRJ)$/util$/makefile.pmk
+
+LIB1TARGET = $(SLB)$/$(TARGET).lib
+LIB1OBJFILES = \
+ $(SLO)$/appendunixshellword.obj \
+ $(SLO)$/extendapplicationenvironment.obj \
+ $(SLO)$/solarmutex.obj \
+ $(SLO)$/getprocessworkingdir.obj
+
+OBJFILES = $(OBJ)$/pathutils.obj
+SLOFILES = $(SLO)$/pathutils.obj $(LIB1OBJFILES) $(SLO)$/solarmutex.obj
+
+.INCLUDE: target.mk
diff --git a/tools/source/misc/pathutils.cxx b/tools/source/misc/pathutils.cxx
new file mode 100644
index 000000000000..397bade136e7
--- /dev/null
+++ b/tools/source/misc/pathutils.cxx
@@ -0,0 +1,219 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_tools.hxx"
+#include "sal/config.h"
+
+#if defined WNT
+
+#include <cstddef>
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include "sal/types.h"
+#include "tools/pathutils.hxx"
+
+namespace tools {
+
+WCHAR * filename(WCHAR * path) {
+ WCHAR * f = path;
+ for (WCHAR * p = path;;) {
+ switch (*p++) {
+ case L'\0':
+ return f;
+ case L'\\':
+ f = p;
+ break;
+ }
+ }
+}
+
+WCHAR * buildPath(
+ WCHAR * path, WCHAR const * frontBegin, WCHAR const * frontEnd,
+ WCHAR const * backBegin, std::size_t backLength)
+{
+ // Remove leading ".." segments in the second path together with matching
+ // segments in the first path that are neither empty nor "." nor ".." nor
+ // end in ":" (which is not foolprove, as it can erroneously erase the start
+ // of a UNC path, but only if the input is bad data):
+ while (backLength >= 2 && backBegin[0] == L'.' && backBegin[1] == L'.' &&
+ (backLength == 2 || backBegin[2] == L'\\'))
+ {
+ if (frontEnd - frontBegin < 2 || frontEnd[-1] != L'\\' ||
+ frontEnd[-2] == L'\\' || frontEnd[-2] == L':' ||
+ (frontEnd[-2] == L'.' &&
+ (frontEnd - frontBegin < 3 || frontEnd[-3] == L'\\' ||
+ (frontEnd[-3] == L'.' &&
+ (frontEnd - frontBegin < 4 || frontEnd[-4] == L'\\')))))
+ {
+ break;
+ }
+ WCHAR const * p = frontEnd - 1;
+ while (p != frontBegin && p[-1] != L'\\') {
+ --p;
+ }
+ if (p == frontBegin) {
+ break;
+ }
+ frontEnd = p;
+ if (backLength == 2) {
+ backBegin += 2;
+ backLength -= 2;
+ } else {
+ backBegin += 3;
+ backLength -= 3;
+ }
+ }
+ if (backLength <
+ static_cast< std::size_t >(MAX_PATH - (frontEnd - frontBegin)))
+ // hopefully std::size_t is large enough
+ {
+ WCHAR * p;
+ if (frontBegin == path) {
+ p = const_cast< WCHAR * >(frontEnd);
+ } else {
+ p = path;
+ while (frontBegin != frontEnd) {
+ *p++ = *frontBegin++;
+ }
+ }
+ for (; backLength > 0; --backLength) {
+ *p++ = *backBegin++;
+ }
+ *p = L'\0';
+ return p;
+ } else {
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return NULL;
+ }
+}
+
+WCHAR * resolveLink(WCHAR * path) {
+ HANDLE h = CreateFileW(
+ path, FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ if (h == INVALID_HANDLE_VALUE) {
+ return NULL;
+ }
+ char p1[MAX_PATH];
+ DWORD n;
+ BOOL ok = ReadFile(h, p1, MAX_PATH, &n, NULL);
+ CloseHandle(h);
+ if (!ok) {
+ return NULL;
+ }
+ WCHAR p2[MAX_PATH];
+ std::size_t n2 = 0;
+ bool colon = false;
+ for (DWORD i = 0; i < n;) {
+ unsigned char c = static_cast< unsigned char >(p1[i++]);
+ switch (c) {
+ case '\0':
+ SetLastError(ERROR_BAD_PATHNAME);
+ return NULL;
+ case '\x0A':
+ case '\x0D':
+ if (n2 == MAX_PATH) {
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return NULL;
+ }
+ p2[n2] = L'\0';
+ break;
+ case ':':
+ colon = true;
+ // fall through
+ default:
+ // Convert from UTF-8 to UTF-16:
+ if (c <= 0x7F) {
+ p2[n2++] = c;
+ } else if (c >= 0xC2 && c <= 0xDF && i < n &&
+ static_cast< unsigned char >(p1[i]) >= 0x80 &&
+ static_cast< unsigned char >(p1[i]) <= 0xBF)
+ {
+ p2[n2++] = ((c & 0x1F) << 6) |
+ (static_cast< unsigned char >(p1[i++]) & 0x3F);
+ } else if (n - i > 1 &&
+ ((c == 0xE0 &&
+ static_cast< unsigned char >(p1[i]) >= 0xA0 &&
+ static_cast< unsigned char >(p1[i]) <= 0xBF) ||
+ ((c >= 0xE1 && c <= 0xEC || c >= 0xEE && c <= 0xEF) &&
+ static_cast< unsigned char >(p1[i]) >= 0x80 &&
+ static_cast< unsigned char >(p1[i]) <= 0xBF) ||
+ (c == 0xED &&
+ static_cast< unsigned char >(p1[i]) >= 0x80 &&
+ static_cast< unsigned char >(p1[i]) <= 0x9F)) &&
+ static_cast< unsigned char >(p1[i + 1]) >= 0x80 &&
+ static_cast< unsigned char >(p1[i + 1]) <= 0xBF)
+ {
+ p2[n2++] = ((c & 0x0F) << 12) |
+ ((static_cast< unsigned char >(p1[i]) & 0x3F) << 6) |
+ (static_cast< unsigned char >(p1[i + 1]) & 0x3F);
+ i += 2;
+ } else if (n - 2 > 1 &&
+ ((c == 0xF0 &&
+ static_cast< unsigned char >(p1[i]) >= 0x90 &&
+ static_cast< unsigned char >(p1[i]) <= 0xBF) ||
+ (c >= 0xF1 && c <= 0xF3 &&
+ static_cast< unsigned char >(p1[i]) >= 0x80 &&
+ static_cast< unsigned char >(p1[i]) <= 0xBF) ||
+ (c == 0xF4 &&
+ static_cast< unsigned char >(p1[i]) >= 0x80 &&
+ static_cast< unsigned char >(p1[i]) <= 0x8F)) &&
+ static_cast< unsigned char >(p1[i + 1]) >= 0x80 &&
+ static_cast< unsigned char >(p1[i + 1]) <= 0xBF &&
+ static_cast< unsigned char >(p1[i + 2]) >= 0x80 &&
+ static_cast< unsigned char >(p1[i + 2]) <= 0xBF)
+ {
+ sal_Int32 u = ((c & 0x07) << 18) |
+ ((static_cast< unsigned char >(p1[i]) & 0x3F) << 12) |
+ ((static_cast< unsigned char >(p1[i + 1]) & 0x3F) << 6) |
+ (static_cast< unsigned char >(p1[i + 2]) & 0x3F);
+ i += 3;
+ p2[n2++] = static_cast< WCHAR >(((u - 0x10000) >> 10) | 0xD800);
+ p2[n2++] = static_cast< WCHAR >(
+ ((u - 0x10000) & 0x3FF) | 0xDC00);
+ } else {
+ SetLastError(ERROR_BAD_PATHNAME);
+ return NULL;
+ }
+ break;
+ }
+ }
+ WCHAR * end;
+ if (colon || p2[0] == L'\\') {
+ // Interpret p2 as an absolute path:
+ end = path;
+ } else {
+ // Interpret p2 as a relative path:
+ end = filename(path);
+ }
+ return buildPath(path, path, end, p2, n2);
+}
+
+}
+
+#endif
diff --git a/tools/source/misc/solarmutex.cxx b/tools/source/misc/solarmutex.cxx
new file mode 100644
index 000000000000..5abdfef5e37f
--- /dev/null
+++ b/tools/source/misc/solarmutex.cxx
@@ -0,0 +1,60 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_tools.hxx"
+#include <tools/solarmutex.hxx>
+
+namespace tools
+{
+ static ::vos::IMutex* pSolarMutex = 0;
+
+ ::vos::IMutex* SolarMutex::GetSolarMutex()
+ {
+ return pSolarMutex;
+ }
+
+ void SolarMutex::SetSolarMutex( ::vos::IMutex* pMutex )
+ {
+ pSolarMutex = pMutex;
+ }
+
+ bool SolarMutex::Acquire()
+ {
+ if ( pSolarMutex )
+ pSolarMutex->acquire();
+ else
+ return false;
+ return true;
+ }
+
+ void SolarMutex::Release()
+ {
+ if ( pSolarMutex )
+ pSolarMutex->release();
+ }
+}