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