xref: /aoo41x/main/desktop/win32/source/unoinfo.cxx (revision a96a8d21)
12722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52722ceddSAndrew Rist  * distributed with this work for additional information
62722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
92722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
102722ceddSAndrew Rist  *
112722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122722ceddSAndrew Rist  *
132722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142722ceddSAndrew Rist  * software distributed under the License is distributed on an
152722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
172722ceddSAndrew Rist  * specific language governing permissions and limitations
182722ceddSAndrew Rist  * under the License.
192722ceddSAndrew Rist  *
202722ceddSAndrew Rist  *************************************************************/
212722ceddSAndrew Rist 
222722ceddSAndrew 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     }
69*a96a8d21SJürgen Schmidt     fprintf(stdout, "%S", path);
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir #ifdef __MINGW32__
75cdf0e10cSrcweir int main(int argc, char ** argv, char **) {
76cdf0e10cSrcweir     if (argc == 2 && strcmp(argv[1], "c++") == 0) {
77cdf0e10cSrcweir #else
78cdf0e10cSrcweir int wmain(int argc, wchar_t ** argv, wchar_t **) {
79cdf0e10cSrcweir     if (argc == 2 && wcscmp(argv[1], L"c++") == 0) {
80cdf0e10cSrcweir #endif
81cdf0e10cSrcweir         wchar_t path[MAX_PATH];
82cdf0e10cSrcweir         wchar_t * pathEnd = getBrandPath(path);
83*a96a8d21SJürgen Schmidt 
84cdf0e10cSrcweir         if (pathEnd == NULL) {
85cdf0e10cSrcweir             exit(EXIT_FAILURE);
86cdf0e10cSrcweir         }
87*a96a8d21SJürgen Schmidt 
88*a96a8d21SJürgen Schmidt         writePath(path, pathEnd, MY_STRING(L""));
89cdf0e10cSrcweir #ifdef __MINGW32__
90cdf0e10cSrcweir     } else if (argc == 2 && strcmp(argv[1], "java") == 0) {
91cdf0e10cSrcweir #else
92cdf0e10cSrcweir     } else if (argc == 2 && wcscmp(argv[1], L"java") == 0) {
93cdf0e10cSrcweir #endif
94cdf0e10cSrcweir         if (fwrite("1", 1, 1, stdout) != 1) {
95cdf0e10cSrcweir             exit(EXIT_FAILURE);
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir         wchar_t path[MAX_PATH];
98cdf0e10cSrcweir         wchar_t * pathEnd = getBrandPath(path);
99cdf0e10cSrcweir         writePath(path, pathEnd, MY_STRING(L""));
100cdf0e10cSrcweir         if (pathEnd == NULL) {
101cdf0e10cSrcweir             exit(EXIT_FAILURE);
102cdf0e10cSrcweir         }
103cdf0e10cSrcweir         writeNull();
104*a96a8d21SJürgen Schmidt         writePath(path, pathEnd, MY_STRING(L"classes\\unoil.jar"));
105cdf0e10cSrcweir         writeNull();
106*a96a8d21SJürgen Schmidt         writePath(path, pathEnd, MY_STRING(L"\classes\\ridl.jar"));
107cdf0e10cSrcweir         writeNull();
108*a96a8d21SJürgen Schmidt         writePath(path, pathEnd, MY_STRING(L"classes\\jurt.jar"));
109cdf0e10cSrcweir         writeNull();
110*a96a8d21SJürgen Schmidt         writePath(path, pathEnd, MY_STRING(L"classes\\juh.jar"));
111cdf0e10cSrcweir     } else {
112cdf0e10cSrcweir         exit(EXIT_FAILURE);
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir     exit(EXIT_SUCCESS);
115cdf0e10cSrcweir }
116