src/windows/bin/java_md.c
jobjectArray
CreateApplicationArgs(JNIEnv *env, char **strv, int argc)
{
    int i, j, idx, 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");
        JLI_TraceLauncher("passing arguments as-is\n");
        return NewPlatformStringArray(env, strv, argc);
    }

    // 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
        // out the first character, the indicator character, so no matter what
        // we add the indicator
        tlen = 1 + JLI_StrLen(strv[i]) + 1;
        nargv[i] = (char *) JLI_MemAlloc(tlen);
        if (JLI_Snprintf(nargv[i], tlen, "%c%s", arg_expand ? 'T' : 'F',
                         strv[i]) < 0) {
            return NULL;
        }
        JLI_TraceLauncher("%s\n", nargv[i]);
    }

    if (!needs_expansion) {
        // clean up any allocated memory and return back the old arguments
        for (i = 0 ; i < argc ; i++) {
            JLI_MemFree(nargv[i]);
        }
        JLI_MemFree(nargv);
        return NewPlatformStringArray(env, strv, argc);
    }
    NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
                                                "expandArgs",
                                                "([Ljava/lang/String;)[Ljava/lang/String;"));

    // expand the arguments that require expansion, the java method will strip
    // out the indicator character.
    inArray = NewPlatformStringArray(env, nargv, argc);
    outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray);
    for (i = 0; i < argc; i++) {
        JLI_MemFree(nargv[i]);
    }
    JLI_MemFree(nargv);
    return outArray;
}
/*
 * 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 ?
 */
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.
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 .
jobjectArray
CreateApplicationArgs(JNIEnv *env, char **strv, int argc)
{
    int i, j, idx, 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);
    }
    stdargs = JLI_GetStdArgs();
    stdargc = JLI_GetStdArgc();
    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);
    }
    idx = stdargc - argc;
    ostart = stdargs[idx].arg;
    astart = strv[0];
    if (JLI_StrCmp(ostart, astart) != 0) {
        JLI_TraceLauncher("Warning: app args parsing error\n");
        JLI_TraceLauncher("passing arguments as-is\n");
        return NewPlatformStringArray(env, strv, argc);
    }
    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;
        tlen = 1 + JLI_StrLen(strv[i]) + 1;
        nargv[i] = (char *) JLI_MemAlloc(tlen);
        if (JLI_Snprintf(nargv[i], tlen, "%c%s", arg_expand ? 'T' : 'F',
                         strv[i]) < 0) {
            return NULL;
        }
        JLI_TraceLauncher("%s\n", nargv[i]);
    }
    if (!needs_expansion) {
        for (i = 0 ; i < argc ; i++) {
            JLI_MemFree(nargv[i]);
        }
        JLI_MemFree(nargv);
        return NewPlatformStringArray(env, strv, argc);
    }
    NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
                                                "expandArgs",
                                                "([Ljava/lang/String;)[Ljava/lang/String;"));
    inArray = NewPlatformStringArray(env, nargv, argc);
    outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray);
    for (i = 0; i < argc; i++) {
        JLI_MemFree(nargv[i]);
    }
    JLI_MemFree(nargv);
    return outArray;
}
jobjectArray CreateApplicationArgs ( JNIEnv * env , char * * strv , int argc ) { int i , j , idx , 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 ) ; } stdargs = JLI_GetStdArgs ( ) ; stdargc = JLI_GetStdArgc ( ) ; if ( argc > stdargc ) { JLI_TraceLauncher ( " \n " , argc , stdargc ) ; JLI_TraceLauncher ( " \n " ) ; return NewPlatformStringArray ( env , strv , argc ) ; } idx = stdargc - argc ; ostart = stdargs [ idx ] . arg ; astart = strv [ 0 ] ; if ( JLI_StrCmp ( ostart , astart ) != 0 ) { JLI_TraceLauncher ( " \n " ) ; JLI_TraceLauncher ( " \n " ) ; return NewPlatformStringArray ( env , strv , argc ) ; } 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 ; tlen = 1 + JLI_StrLen ( strv [ i ] ) + 1 ; nargv [ i ] = ( char * ) JLI_MemAlloc ( tlen ) ; if ( JLI_Snprintf ( nargv [ i ] , tlen , " " , arg_expand ? ' ' : ' ' , strv [ i ] ) < 0 ) { return NULL ; } JLI_TraceLauncher ( " \n " , nargv [ i ] ) ; } if ( ! needs_expansion ) { for ( i = 0 ; i < argc ; i ++ ) { JLI_MemFree ( nargv [ i ] ) ; } JLI_MemFree ( nargv ) ; return NewPlatformStringArray ( env , strv , argc ) ; } NULL_CHECK0 ( mid = ( * env ) -> GetStaticMethodID ( env , cls , " " , " " ) ) ; inArray = NewPlatformStringArray ( env , nargv , argc ) ; outArray = ( * env ) -> CallStaticObjectMethod ( env , cls , mid , inArray ) ; for ( i = 0 ; i < argc ; i ++ ) { JLI_MemFree ( nargv [ i ] ) ; } JLI_MemFree ( nargv ) ; return outArray ; }
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.
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 .
// the holy grail we need to compare with. // sanity check, this should never happen // sanity check, match the args we have, to the holy grail // sanity check, ensure that the first argument of the arrays are the same // some thing is amiss the args don't match // make a copy of the args which will be expanded in java if required. // indicator char + String + NULL terminator, the java method will strip // out the first character, the indicator character, so no matter what // we add the indicator // clean up any allocated memory and return back the old arguments // expand the arguments that require expansion, the java method will strip // out the indicator character.