1 /*
2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27 /*
28 * Converts a single string command line to the traditional argc, argv.
29 * There are rules which govern the breaking of the arguments, and
30 * these rules are embodied in the regression tests below, and duplicated
31 * in the jdk regression tests.
32 */
33
34 #include <assert.h>
35
36 #ifndef IDE_STANDALONE
37 #include "java.h"
38 #include "jli_util.h"
39 #else /* IDE_STANDALONE */
40 // The defines we need for stand alone testing
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <Windows.h>
44 #define JNI_TRUE TRUE
45 #define JNI_FALSE FALSE
46 #define JLI_MemRealloc realloc
47 #define JLI_StringDup _strdup
48 #define JLI_MemFree free
49 #define jboolean boolean
50 typedef struct {
51 char* arg;
52 boolean has_wildcard;
53 } StdArg ;
54 #endif
55 static StdArg *stdargs;
56 static int stdargc;
57
171 } else {
172 dest += copyCh(ch, dest);
173 }
174 slashes = 0;
175 }
176
177 if (!done) {
178 prev = ch;
179 src += charLength;
180 }
181 }
182 if (prev == L'\\') {
183 for (i = 0; i < slashes; i++) {
184 dest += copyCh(prev, dest);
185 }
186 }
187 *dest = 0;
188 return done ? src : NULL;
189 }
190
191 int JLI_GetStdArgc() {
192 return stdargc;
193 }
194
195 StdArg* JLI_GetStdArgs() {
196 return stdargs;
197 }
198
199 void JLI_CmdToArgs(char* cmdline) {
200 int nargs = 0;
201 StdArg* argv = NULL;
202 jboolean wildcard = JNI_FALSE;
203 char* src = cmdline, *arg = NULL;
204 JLI_List argsInFile;
205 size_t i, cnt;
206
207 JLI_List envArgs = JLI_List_new(1);
208 if (JLI_AddArgsFromEnvVar(envArgs, JDK_JAVA_OPTIONS)) {
209 // JLI_SetTraceLauncher is not called yet
210 // Show _JAVA_OPTIONS content along with JDK_JAVA_OPTIONS to aid diagnosis
211 if (getenv(JLDEBUG_ENV_ENTRY)) {
212 char *tmp = getenv("_JAVA_OPTIONS");
213 if (NULL != tmp) {
214 JLI_ReportMessage(ARG_INFO_ENVVAR, "_JAVA_OPTIONS", tmp);
215 }
216 }
217 }
218 cnt = envArgs->size + 1;
219 argv = JLI_MemAlloc(cnt * sizeof(StdArg));
|
1 /*
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27 /*
28 * Converts a single string command line to the traditional argc, argv.
29 * There are rules which govern the breaking of the arguments, and
30 * these rules are embodied in the regression tests below, and duplicated
31 * in the jdk regression tests.
32 */
33
34 #include <assert.h>
35
36 #ifndef IDE_STANDALONE
37 #include "java.h"
38 #include "jni.h"
39 #include "jli_util.h"
40 #else /* IDE_STANDALONE */
41 // The defines we need for stand alone testing
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <Windows.h>
45 #define JNI_TRUE TRUE
46 #define JNI_FALSE FALSE
47 #define JLI_MemRealloc realloc
48 #define JLI_StringDup _strdup
49 #define JLI_MemFree free
50 #define jboolean boolean
51 typedef struct {
52 char* arg;
53 boolean has_wildcard;
54 } StdArg ;
55 #endif
56 static StdArg *stdargs;
57 static int stdargc;
58
172 } else {
173 dest += copyCh(ch, dest);
174 }
175 slashes = 0;
176 }
177
178 if (!done) {
179 prev = ch;
180 src += charLength;
181 }
182 }
183 if (prev == L'\\') {
184 for (i = 0; i < slashes; i++) {
185 dest += copyCh(prev, dest);
186 }
187 }
188 *dest = 0;
189 return done ? src : NULL;
190 }
191
192 JNIEXPORT int JNICALL
193 JLI_GetStdArgc() {
194 return stdargc;
195 }
196
197 JNIEXPORT StdArg* JNICALL
198 JLI_GetStdArgs() {
199 return stdargs;
200 }
201
202 JNIEXPORT void JNICALL
203 JLI_CmdToArgs(char* cmdline) {
204 int nargs = 0;
205 StdArg* argv = NULL;
206 jboolean wildcard = JNI_FALSE;
207 char* src = cmdline, *arg = NULL;
208 JLI_List argsInFile;
209 size_t i, cnt;
210
211 JLI_List envArgs = JLI_List_new(1);
212 if (JLI_AddArgsFromEnvVar(envArgs, JDK_JAVA_OPTIONS)) {
213 // JLI_SetTraceLauncher is not called yet
214 // Show _JAVA_OPTIONS content along with JDK_JAVA_OPTIONS to aid diagnosis
215 if (getenv(JLDEBUG_ENV_ENTRY)) {
216 char *tmp = getenv("_JAVA_OPTIONS");
217 if (NULL != tmp) {
218 JLI_ReportMessage(ARG_INFO_ENVVAR, "_JAVA_OPTIONS", tmp);
219 }
220 }
221 }
222 cnt = envArgs->size + 1;
223 argv = JLI_MemAlloc(cnt * sizeof(StdArg));
|