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