merge the formfield patch from ooo-build
[ooovba.git] / desktop / win32 / source / unoinfo.cxx
blobd4458212c3c30be83c41424b48b19b6b89a609ea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoinfo.cxx,v $
10 * $Revision: 1.4 $
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 #include <cstddef>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <wchar.h>
36 #define WIN32_LEAN_AND_MEAN
37 #if defined _MSC_VER
38 #pragma warning(push, 1)
39 #endif
40 #include <windows.h>
41 #if defined _MSC_VER
42 #pragma warning(pop)
43 #endif
45 #include "tools/pathutils.hxx"
47 #define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
48 #define MY_STRING(s) (s), MY_LENGTH(s)
50 namespace {
52 wchar_t * getBrandPath(wchar_t * path) {
53 DWORD n = GetModuleFileNameW(NULL, path, MAX_PATH);
54 if (n == 0 || n >= MAX_PATH) {
55 exit(EXIT_FAILURE);
57 return tools::filename(path);
60 void writeNull() {
61 if (fwrite("\0\0", 1, 2, stdout) != 2) {
62 exit(EXIT_FAILURE);
66 void writePath(
67 wchar_t const * frontBegin, wchar_t const * frontEnd,
68 wchar_t const * backBegin, std::size_t backLength)
70 wchar_t path[MAX_PATH];
71 wchar_t * end = tools::buildPath(
72 path, frontBegin, frontEnd, backBegin, backLength);
73 if (end == NULL) {
74 exit(EXIT_FAILURE);
76 std::size_t n = (end - path) * sizeof (wchar_t);
77 if (fwrite(path, 1, n, stdout) != n) {
78 exit(EXIT_FAILURE);
84 #ifdef __MINGW32__
85 int main(int argc, char ** argv, char **) {
86 if (argc == 2 && strcmp(argv[1], "c++") == 0) {
87 #else
88 int wmain(int argc, wchar_t ** argv, wchar_t **) {
89 if (argc == 2 && wcscmp(argv[1], L"c++") == 0) {
90 #endif
91 wchar_t path[MAX_PATH];
92 wchar_t * pathEnd = getBrandPath(path);
93 if (tools::buildPath(path, path, pathEnd, MY_STRING(L"..\\basis-link"))
94 == NULL)
96 exit(EXIT_FAILURE);
98 pathEnd = tools::resolveLink(path);
99 if (pathEnd == NULL ||
100 (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\ure-link")) ==
101 NULL))
103 exit(EXIT_FAILURE);
105 pathEnd = tools::resolveLink(path);
106 if (pathEnd == NULL) {
107 exit(EXIT_FAILURE);
109 writePath(path, pathEnd, MY_STRING(L"\\bin"));
110 #ifdef __MINGW32__
111 } else if (argc == 2 && strcmp(argv[1], "java") == 0) {
112 #else
113 } else if (argc == 2 && wcscmp(argv[1], L"java") == 0) {
114 #endif
115 if (fwrite("1", 1, 1, stdout) != 1) {
116 exit(EXIT_FAILURE);
118 wchar_t path[MAX_PATH];
119 wchar_t * pathEnd = getBrandPath(path);
120 writePath(path, pathEnd, MY_STRING(L""));
121 if (tools::buildPath(path, path, pathEnd, MY_STRING(L"..\\basis-link"))
122 == NULL)
124 exit(EXIT_FAILURE);
126 pathEnd = tools::resolveLink(path);
127 if (pathEnd == NULL) {
128 exit(EXIT_FAILURE);
130 writeNull();
131 writePath(path, pathEnd, MY_STRING(L"\\program\\classes\\unoil.jar"));
132 if (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\ure-link")) ==
133 NULL)
135 exit(EXIT_FAILURE);
137 pathEnd = tools::resolveLink(path);
138 if (pathEnd == NULL) {
139 exit(EXIT_FAILURE);
141 writeNull();
142 writePath(path, pathEnd, MY_STRING(L"\\java\\ridl.jar"));
143 writeNull();
144 writePath(path, pathEnd, MY_STRING(L"\\java\\jurt.jar"));
145 writeNull();
146 writePath(path, pathEnd, MY_STRING(L"\\java\\juh.jar"));
147 } else {
148 exit(EXIT_FAILURE);
150 exit(EXIT_SUCCESS);