xref: /aoo42x/main/desktop/win32/source/unoinfo.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <cstddef>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <wchar.h>
32 
33 #define WIN32_LEAN_AND_MEAN
34 #if defined _MSC_VER
35 #pragma warning(push, 1)
36 #endif
37 #include <windows.h>
38 #if defined _MSC_VER
39 #pragma warning(pop)
40 #endif
41 
42 #include "tools/pathutils.hxx"
43 
44 #define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
45 #define MY_STRING(s) (s), MY_LENGTH(s)
46 
47 namespace {
48 
49 wchar_t * getBrandPath(wchar_t * path) {
50     DWORD n = GetModuleFileNameW(NULL, path, MAX_PATH);
51     if (n == 0 || n >= MAX_PATH) {
52         exit(EXIT_FAILURE);
53     }
54     return tools::filename(path);
55 }
56 
57 void writeNull() {
58     if (fwrite("\0\0", 1, 2, stdout) != 2) {
59         exit(EXIT_FAILURE);
60     }
61 }
62 
63 void writePath(
64     wchar_t const * frontBegin, wchar_t const * frontEnd,
65     wchar_t const * backBegin, std::size_t backLength)
66 {
67     wchar_t path[MAX_PATH];
68     wchar_t * end = tools::buildPath(
69         path, frontBegin, frontEnd, backBegin, backLength);
70     if (end == NULL) {
71         exit(EXIT_FAILURE);
72     }
73     std::size_t n = (end - path) * sizeof (wchar_t);
74     if (fwrite(path, 1, n, stdout) != n) {
75         exit(EXIT_FAILURE);
76     }
77 }
78 
79 }
80 
81 #ifdef __MINGW32__
82 int main(int argc, char ** argv, char **) {
83     if (argc == 2 && strcmp(argv[1], "c++") == 0) {
84 #else
85 int wmain(int argc, wchar_t ** argv, wchar_t **) {
86     if (argc == 2 && wcscmp(argv[1], L"c++") == 0) {
87 #endif
88         wchar_t path[MAX_PATH];
89         wchar_t * pathEnd = getBrandPath(path);
90         if (tools::buildPath(path, path, pathEnd, MY_STRING(L"..\\basis-link"))
91             == NULL)
92         {
93             exit(EXIT_FAILURE);
94         }
95         pathEnd = tools::resolveLink(path);
96         if (pathEnd == NULL ||
97             (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\ure-link")) ==
98              NULL))
99         {
100             exit(EXIT_FAILURE);
101         }
102         pathEnd = tools::resolveLink(path);
103         if (pathEnd == NULL) {
104             exit(EXIT_FAILURE);
105         }
106         writePath(path, pathEnd, MY_STRING(L"\\bin"));
107 #ifdef __MINGW32__
108     } else if (argc == 2 && strcmp(argv[1], "java") == 0) {
109 #else
110     } else if (argc == 2 && wcscmp(argv[1], L"java") == 0) {
111 #endif
112         if (fwrite("1", 1, 1, stdout) != 1) {
113             exit(EXIT_FAILURE);
114         }
115         wchar_t path[MAX_PATH];
116         wchar_t * pathEnd = getBrandPath(path);
117         writePath(path, pathEnd, MY_STRING(L""));
118         if (tools::buildPath(path, path, pathEnd, MY_STRING(L"..\\basis-link"))
119             == NULL)
120         {
121             exit(EXIT_FAILURE);
122         }
123         pathEnd = tools::resolveLink(path);
124         if (pathEnd == NULL) {
125             exit(EXIT_FAILURE);
126         }
127         writeNull();
128         writePath(path, pathEnd, MY_STRING(L"\\program\\classes\\unoil.jar"));
129         if (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\ure-link")) ==
130             NULL)
131         {
132             exit(EXIT_FAILURE);
133         }
134         pathEnd = tools::resolveLink(path);
135         if (pathEnd == NULL) {
136             exit(EXIT_FAILURE);
137         }
138         writeNull();
139         writePath(path, pathEnd, MY_STRING(L"\\java\\ridl.jar"));
140         writeNull();
141         writePath(path, pathEnd, MY_STRING(L"\\java\\jurt.jar"));
142         writeNull();
143         writePath(path, pathEnd, MY_STRING(L"\\java\\juh.jar"));
144     } else {
145         exit(EXIT_FAILURE);
146     }
147     exit(EXIT_SUCCESS);
148 }
149