xref: /aoo41x/main/desktop/win32/source/unoinfo.cxx (revision c79a0cc3)
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 
getBrandPath(wchar_t * path)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 
writeNull()53cdf0e10cSrcweir void writeNull() {
54cdf0e10cSrcweir     if (fwrite("\0\0", 1, 2, stdout) != 2) {
55cdf0e10cSrcweir         exit(EXIT_FAILURE);
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
writePath(wchar_t const * frontBegin,wchar_t const * frontEnd,wchar_t const * backBegin,std::size_t backLength)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*c79a0cc3SHerbert Dürr     size_t nWideLen = wcslen(path);
70*c79a0cc3SHerbert Dürr     fwrite( path, sizeof(wchar_t), nWideLen, stdout);
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #ifdef __MINGW32__
main(int argc,char ** argv,char **)76cdf0e10cSrcweir int main(int argc, char ** argv, char **) {
77cdf0e10cSrcweir     if (argc == 2 && strcmp(argv[1], "c++") == 0) {
78cdf0e10cSrcweir #else
79cdf0e10cSrcweir int wmain(int argc, wchar_t ** argv, wchar_t **) {
80cdf0e10cSrcweir     if (argc == 2 && wcscmp(argv[1], L"c++") == 0) {
81cdf0e10cSrcweir #endif
82cdf0e10cSrcweir         wchar_t path[MAX_PATH];
83cdf0e10cSrcweir         wchar_t * pathEnd = getBrandPath(path);
84a96a8d21SJürgen Schmidt 
85cdf0e10cSrcweir         if (pathEnd == NULL) {
86cdf0e10cSrcweir             exit(EXIT_FAILURE);
87cdf0e10cSrcweir         }
88a96a8d21SJürgen Schmidt 
89a96a8d21SJürgen Schmidt         writePath(path, pathEnd, MY_STRING(L""));
90cdf0e10cSrcweir #ifdef __MINGW32__
91cdf0e10cSrcweir     } else if (argc == 2 && strcmp(argv[1], "java") == 0) {
92cdf0e10cSrcweir #else
93cdf0e10cSrcweir     } else if (argc == 2 && wcscmp(argv[1], L"java") == 0) {
94cdf0e10cSrcweir #endif
95cdf0e10cSrcweir         if (fwrite("1", 1, 1, stdout) != 1) {
96cdf0e10cSrcweir             exit(EXIT_FAILURE);
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir         wchar_t path[MAX_PATH];
99cdf0e10cSrcweir         wchar_t * pathEnd = getBrandPath(path);
100cdf0e10cSrcweir         writePath(path, pathEnd, MY_STRING(L""));
101cdf0e10cSrcweir         if (pathEnd == NULL) {
102cdf0e10cSrcweir             exit(EXIT_FAILURE);
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir         writeNull();
105a96a8d21SJürgen Schmidt         writePath(path, pathEnd, MY_STRING(L"classes\\unoil.jar"));
106cdf0e10cSrcweir         writeNull();
107*c79a0cc3SHerbert Dürr         writePath(path, pathEnd, MY_STRING(L"classes\\ridl.jar"));
108cdf0e10cSrcweir         writeNull();
109a96a8d21SJürgen Schmidt         writePath(path, pathEnd, MY_STRING(L"classes\\jurt.jar"));
110cdf0e10cSrcweir         writeNull();
111a96a8d21SJürgen Schmidt         writePath(path, pathEnd, MY_STRING(L"classes\\juh.jar"));
112cdf0e10cSrcweir     } else {
113cdf0e10cSrcweir         exit(EXIT_FAILURE);
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir     exit(EXIT_SUCCESS);
116cdf0e10cSrcweir }
117