src/java.base/windows/native/libjli/java_md.c
Print this page
*** 988,997 ****
--- 988,1017 ----
ProcessPlatformOption(const char *arg)
{
return JNI_FALSE;
}
+ int
+ filterArgs(StdArg *stdargs, const int nargc, StdArg **pargv) {
+ StdArg* argv = NULL;
+ int nargs = 0;
+ int i;
+
+ /* Copy the non-vm args */
+ for (i = 0; i < nargc ; i++) {
+ const char *arg = stdargs[i].arg;
+ if (arg[0] != '-' || arg[1] != 'J') {
+ argv = (StdArg*) JLI_MemRealloc(argv, (nargs+1) * sizeof(StdArg));
+ argv[nargs].arg = JLI_StringDup(arg);
+ argv[nargs].has_wildcard = stdargs[i].has_wildcard;
+ nargs++;
+ }
+ }
+ *pargv = argv;
+ return nargs;
+ }
+
/*
* At this point we have the arguments to the application, and we need to
* check with original stdargs in order to compare which of these truly
* needs expansion. cmdtoargs will specify this if it finds a bare
* (unquoted) argument containing a glob character(s) ie. * or ?
*** 1003,1034 ****
size_t tlen;
jobjectArray outArray, inArray;
char *ostart, *astart, **nargv;
jboolean needs_expansion = JNI_FALSE;
jmethodID mid;
! int stdargc;
StdArg *stdargs;
jclass cls = GetLauncherHelperClass(env);
NULL_CHECK0(cls);
if (argc == 0) {
return NewPlatformStringArray(env, strv, argc);
}
// the holy grail we need to compare with.
stdargs = JLI_GetStdArgs();
stdargc = JLI_GetStdArgc();
// sanity check, this should never happen
if (argc > stdargc) {
JLI_TraceLauncher("Warning: app args is larger than the original, %d %d\n", argc, stdargc);
JLI_TraceLauncher("passing arguments as-is.\n");
return NewPlatformStringArray(env, strv, argc);
}
// sanity check, match the args we have, to the holy grail
! idx = stdargc - argc;
! ostart = stdargs[idx].arg;
astart = strv[0];
// sanity check, ensure that the first argument of the arrays are the same
if (JLI_StrCmp(ostart, astart) != 0) {
// some thing is amiss the args don't match
JLI_TraceLauncher("Warning: app args parsing error\n");
--- 1023,1057 ----
size_t tlen;
jobjectArray outArray, inArray;
char *ostart, *astart, **nargv;
jboolean needs_expansion = JNI_FALSE;
jmethodID mid;
! int filteredargc, stdargc;
StdArg *stdargs;
+ StdArg *filteredargs;
jclass cls = GetLauncherHelperClass(env);
NULL_CHECK0(cls);
if (argc == 0) {
return NewPlatformStringArray(env, strv, argc);
}
// the holy grail we need to compare with.
stdargs = JLI_GetStdArgs();
stdargc = JLI_GetStdArgc();
+ filteredargc = filterArgs(stdargs, stdargc, &filteredargs);
+
// sanity check, this should never happen
if (argc > stdargc) {
JLI_TraceLauncher("Warning: app args is larger than the original, %d %d\n", argc, stdargc);
JLI_TraceLauncher("passing arguments as-is.\n");
return NewPlatformStringArray(env, strv, argc);
}
// sanity check, match the args we have, to the holy grail
! idx = filteredargc - argc;
! ostart = filteredargs[idx].arg;
astart = strv[0];
// sanity check, ensure that the first argument of the arrays are the same
if (JLI_StrCmp(ostart, astart) != 0) {
// some thing is amiss the args don't match
JLI_TraceLauncher("Warning: app args parsing error\n");
*** 1037,1048 ****
}
// make a copy of the args which will be expanded in java if required.
nargv = (char **)JLI_MemAlloc(argc * sizeof(char*));
for (i = 0, j = idx; i < argc; i++, j++) {
! jboolean arg_expand = (JLI_StrCmp(stdargs[j].arg, strv[i]) == 0)
! ? stdargs[j].has_wildcard
: JNI_FALSE;
if (needs_expansion == JNI_FALSE)
needs_expansion = arg_expand;
// indicator char + String + NULL terminator, the java method will strip
--- 1060,1071 ----
}
// make a copy of the args which will be expanded in java if required.
nargv = (char **)JLI_MemAlloc(argc * sizeof(char*));
for (i = 0, j = idx; i < argc; i++, j++) {
! jboolean arg_expand = (JLI_StrCmp(filteredargs[j].arg, strv[i]) == 0)
! ? filteredargs[j].has_wildcard
: JNI_FALSE;
if (needs_expansion == JNI_FALSE)
needs_expansion = arg_expand;
// indicator char + String + NULL terminator, the java method will strip
*** 1075,1081 ****
--- 1098,1105 ----
outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray);
for (i = 0; i < argc; i++) {
JLI_MemFree(nargv[i]);
}
JLI_MemFree(nargv);
+ JLI_MemFree(filteredargs);
return outArray;
}