xref: /aoo41x/main/desktop/win32/source/unoinfo.cxx (revision 2722cedd)
1*2722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2722ceddSAndrew Rist  * distributed with this work for additional information
6*2722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
9*2722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2722ceddSAndrew Rist  *
11*2722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2722ceddSAndrew Rist  *
13*2722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2722ceddSAndrew Rist  * software distributed under the License is distributed on an
15*2722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2722ceddSAndrew Rist  * specific language governing permissions and limitations
18*2722ceddSAndrew Rist  * under the License.
19*2722ceddSAndrew Rist  *
20*2722ceddSAndrew Rist  *************************************************************/
21*2722ceddSAndrew Rist 
22*2722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <cstddef>
25cdf0e10cSrcweir #include <stdio.h>
26cdf0e10cSrcweir #include <stdlib.h>
27cdf0e10cSrcweir #include <wchar.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN
30cdf0e10cSrcweir #if defined _MSC_VER
31cdf0e10cSrcweir #pragma warning(push, 1)
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <windows.h>
34cdf0e10cSrcweir #if defined _MSC_VER
35cdf0e10cSrcweir #pragma warning(pop)
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include "tools/pathutils.hxx"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
41cdf0e10cSrcweir #define MY_STRING(s) (s), MY_LENGTH(s)
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir wchar_t * getBrandPath(wchar_t * path) {
46cdf0e10cSrcweir     DWORD n = GetModuleFileNameW(NULL, path, MAX_PATH);
47cdf0e10cSrcweir     if (n == 0 || n >= MAX_PATH) {
48cdf0e10cSrcweir         exit(EXIT_FAILURE);
49cdf0e10cSrcweir     }
50cdf0e10cSrcweir     return tools::filename(path);
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir void writeNull() {
54cdf0e10cSrcweir     if (fwrite("\0\0", 1, 2, stdout) != 2) {
55cdf0e10cSrcweir         exit(EXIT_FAILURE);
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir void writePath(
60cdf0e10cSrcweir     wchar_t const * frontBegin, wchar_t const * frontEnd,
61cdf0e10cSrcweir     wchar_t const * backBegin, std::size_t backLength)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     wchar_t path[MAX_PATH];
64cdf0e10cSrcweir     wchar_t * end = tools::buildPath(
65cdf0e10cSrcweir         path, frontBegin, frontEnd, backBegin, backLength);
66cdf0e10cSrcweir     if (end == NULL) {
67cdf0e10cSrcweir         exit(EXIT_FAILURE);
68cdf0e10cSrcweir     }
69cdf0e10cSrcweir     std::size_t n = (end - path) * sizeof (wchar_t);
70cdf0e10cSrcweir     if (fwrite(path, 1, n, stdout) != n) {
71cdf0e10cSrcweir         exit(EXIT_FAILURE);
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir #ifdef __MINGW32__
78cdf0e10cSrcweir int main(int argc, char ** argv, char **) {
79cdf0e10cSrcweir     if (argc == 2 && strcmp(argv[1], "c++") == 0) {
80cdf0e10cSrcweir #else
81cdf0e10cSrcweir int wmain(int argc, wchar_t ** argv, wchar_t **) {
82cdf0e10cSrcweir     if (argc == 2 && wcscmp(argv[1], L"c++") == 0) {
83cdf0e10cSrcweir #endif
84cdf0e10cSrcweir         wchar_t path[MAX_PATH];
85cdf0e10cSrcweir         wchar_t * pathEnd = getBrandPath(path);
86cdf0e10cSrcweir         if (tools::buildPath(path, path, pathEnd, MY_STRING(L"..\\basis-link"))
87cdf0e10cSrcweir             == NULL)
88cdf0e10cSrcweir         {
89cdf0e10cSrcweir             exit(EXIT_FAILURE);
90cdf0e10cSrcweir         }
91cdf0e10cSrcweir         pathEnd = tools::resolveLink(path);
92cdf0e10cSrcweir         if (pathEnd == NULL ||
93cdf0e10cSrcweir             (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\ure-link")) ==
94cdf0e10cSrcweir              NULL))
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             exit(EXIT_FAILURE);
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir         pathEnd = tools::resolveLink(path);
99cdf0e10cSrcweir         if (pathEnd == NULL) {
100cdf0e10cSrcweir             exit(EXIT_FAILURE);
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir         writePath(path, pathEnd, MY_STRING(L"\\bin"));
103cdf0e10cSrcweir #ifdef __MINGW32__
104cdf0e10cSrcweir     } else if (argc == 2 && strcmp(argv[1], "java") == 0) {
105cdf0e10cSrcweir #else
106cdf0e10cSrcweir     } else if (argc == 2 && wcscmp(argv[1], L"java") == 0) {
107cdf0e10cSrcweir #endif
108cdf0e10cSrcweir         if (fwrite("1", 1, 1, stdout) != 1) {
109cdf0e10cSrcweir             exit(EXIT_FAILURE);
110cdf0e10cSrcweir         }
111cdf0e10cSrcweir         wchar_t path[MAX_PATH];
112cdf0e10cSrcweir         wchar_t * pathEnd = getBrandPath(path);
113cdf0e10cSrcweir         writePath(path, pathEnd, MY_STRING(L""));
114cdf0e10cSrcweir         if (tools::buildPath(path, path, pathEnd, MY_STRING(L"..\\basis-link"))
115cdf0e10cSrcweir             == NULL)
116cdf0e10cSrcweir         {
117cdf0e10cSrcweir             exit(EXIT_FAILURE);
118cdf0e10cSrcweir         }
119cdf0e10cSrcweir         pathEnd = tools::resolveLink(path);
120cdf0e10cSrcweir         if (pathEnd == NULL) {
121cdf0e10cSrcweir             exit(EXIT_FAILURE);
122cdf0e10cSrcweir         }
123cdf0e10cSrcweir         writeNull();
124cdf0e10cSrcweir         writePath(path, pathEnd, MY_STRING(L"\\program\\classes\\unoil.jar"));
125cdf0e10cSrcweir         if (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\ure-link")) ==
126cdf0e10cSrcweir             NULL)
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir             exit(EXIT_FAILURE);
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir         pathEnd = tools::resolveLink(path);
131cdf0e10cSrcweir         if (pathEnd == NULL) {
132cdf0e10cSrcweir             exit(EXIT_FAILURE);
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir         writeNull();
135cdf0e10cSrcweir         writePath(path, pathEnd, MY_STRING(L"\\java\\ridl.jar"));
136cdf0e10cSrcweir         writeNull();
137cdf0e10cSrcweir         writePath(path, pathEnd, MY_STRING(L"\\java\\jurt.jar"));
138cdf0e10cSrcweir         writeNull();
139cdf0e10cSrcweir         writePath(path, pathEnd, MY_STRING(L"\\java\\juh.jar"));
140cdf0e10cSrcweir     } else {
141cdf0e10cSrcweir         exit(EXIT_FAILURE);
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir     exit(EXIT_SUCCESS);
144cdf0e10cSrcweir }
145