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