void ArrayAppend(int A1[], int A2[]){
	if(A1 == NULL || A2 = NULL)
		return;
	int length_A1 = getArrayLen(A1);
	int length_A2 = getArrayLen(A2);

	int indexOfA1 = length_A1 - 1;
	int indexOfA2 = length_A2 -1;
	int indexOfNew = length_A1 + length_A2 - 1;

	while(indexOfA1 > 0 && indexOfA2 > 0 && indexOfA1 < indexOfNew ){
		if(A1[indexOfA1] >= A2[indexOfA2]){
			A1[indexOfNew --] = A1[indexOfA1--];
			A1[indexOfNew --] = A1[indexOfA2--];
		}
		else{
			A1[indexOfNew--] = A2[indexOfA2--];
			A1[indexOfNew--] = A1[indexOfA1--];
		}
	}
}
Пример #2
0
/*
 * Class:     quake_jni_Natives
 * Method:    QuakeMain
 * Signature: ([Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_quake_jni_Natives_QuakeMain
  (JNIEnv * env, jclass cls, jobjectArray jargv)
{
	(*env)->GetJavaVM(env, &g_VM);

	// Extract char ** args from Java array
	jsize clen =  getArrayLen(env, jargv);

	char * args[(int)clen];

	int i;
	jstring jrow;
	for (i = 0; i < clen; i++)
	{
	    jrow = (jstring)(*env)->GetObjectArrayElement(env, jargv, i);
	    const char *row  = (*env)->GetStringUTFChars(env, jrow, 0);

	    args[i] = malloc( strlen(row) + 1);
	    strcpy (args[i], row);
		
		jni_printf("Q2Main[%d]=%s", i, args[i]);
		
	    // free java string jrow
	    (*env)->ReleaseStringUTFChars(env, jrow, row);
	}

	if ( ! Init_JNI(env) ) {
		return 0;
	}
	
	// Invoke Quake's main sub. This will loop forever
	// Program args come from Java
	main (clen, args);

	return 1;
}
Пример #3
0
int lib_main(int argc, char **argv);

const int getArrayLen(JNIEnv *env, jobjectArray jarray);

void jni_printf(char *format, ...);

static JavaVM *g_VM;

static jclass jNativesCls;

JNIEXPORT jint JNICALL Java_jni_Natives_LibMain
    (JNIEnv *env, jclass class, jobjectArray jargv){
        (*env)->GetJavaVM(env, &g_VM);

        jsize clen = getArrayLen(env, jargv);

        char *args[(int)clen];

        jstring jrow; int i;
        for( i = 0; i < clen; i++){
            jrow = (jstring)(*env)->GetObjectArrayElement(env, jargv, i);
            const char *row = (*env)->GetStringUTFChars(env, jrow, 0);

            args[i] = malloc(strlen(row) +1);
            strcpy(args[i], row);

            jni_printf("Main argvs[%d] = %s", i, args[i]);

            (*env)->ReleaseStringUTFChars(env, jrow, row);
        }