diff --git a/ase/awk/jni.c b/ase/awk/jni.c index 12d9bd6d..6c3bd767 100644 --- a/ase/awk/jni.c +++ b/ase/awk/jni.c @@ -1,5 +1,5 @@ /* - * $Id: jni.c,v 1.57 2007-01-27 02:55:55 bacon Exp $ + * $Id: jni.c,v 1.58 2007-01-28 11:12:29 bacon Exp $ */ #include @@ -1930,9 +1930,163 @@ JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum ( JNIEXPORT jstring JNICALL Java_ase_awk_Awk_valtostr ( - JNIEnv* env, jobject obj, jlong runid) + JNIEnv* env, jobject obj, jlong runid, jobject val) { - // TODO: ... - return NULL; + ase_awk_run_t* run = (ase_awk_run_t*)runid; + run_data_t* run_data; + jstring ret; + ase_awk_val_t* v; + ase_char_t* str; + ase_size_t len; + ase_awk_t* awk; + + awk = ase_awk_getrunawk (run); + + if (val == NULL) + { + ret = (*env)->NewString (env, NULL, 0); + + if (ret == NULL) + { + (*env)->ExceptionClear (env); + + throw_exception ( + env, + ase_awk_geterrstr(ASE_AWK_ENOMEM), + ASE_AWK_ENOMEM, + 0); + } + return ret; + } + + run_data = ase_awk_getruncustomdata (run); + + if ((*env)->IsInstanceOf (env, val, run_data->string_class)) + { + const jchar* ptr; + + len = (*env)->GetStringLength (env, val); + ptr = (*env)->GetStringChars (env, val, JNI_FALSE); + if (ptr == NULL) + { + (*env)->ExceptionClear (env); + + throw_exception ( + env, + ase_awk_geterrstr(ASE_AWK_ENOMEM), + ASE_AWK_ENOMEM, + 0); + + return NULL; + } + + ret = (*env)->NewString (env, ptr, len); + (*env)->ReleaseStringChars (env, ret, ptr); + return ret; + } + + if ((*env)->IsInstanceOf (env, val, run_data->integer_class)) + { + jint jv; + jv = (*env)->CallIntMethod ( + env, val, run_data->integer_value); + v = ase_awk_makeintval (run, jv); + } + else if ((*env)->IsInstanceOf (env, val, run_data->long_class)) + { + jlong jv = (*env)->CallLongMethod ( + env, val, run_data->long_value); + v = ase_awk_makeintval (run, jv); + } + else if ((*env)->IsInstanceOf (env, val, run_data->short_class)) + { + jshort jv = (*env)->CallShortMethod ( + env, val, run_data->short_value); + v = ase_awk_makeintval (run, jv); + } + else if ((*env)->IsInstanceOf (env, val, run_data->float_class)) + { + jfloat jv = (*env)->CallFloatMethod ( + env, val, run_data->float_value); + v = ase_awk_makerealval (run, jv); + } + else if ((*env)->IsInstanceOf (env, val, run_data->double_class)) + { + jdouble jv = (*env)->CallDoubleMethod ( + env, val, run_data->double_value); + v = ase_awk_makerealval (run, jv); + } + else + { + throw_exception ( + env, + ase_awk_geterrstr(ASE_AWK_EVALTYPE), + ASE_AWK_EVALTYPE, + 0); + return NULL; + } + + if (v == NULL) + { + throw_exception ( + env, + ase_awk_geterrstr(ASE_AWK_ENOMEM), + ASE_AWK_ENOMEM, + 0); + return NULL; + } + + ase_awk_refupval (run, v); + str = ase_awk_valtostr (run, v, ASE_AWK_VALTOSTR_CLEAR, NULL, &len); + ase_awk_refdownval (run, v); + + if (str == NULL) + { + + throw_exception ( + env, + ase_awk_geterrstr(ASE_AWK_ENOMEM), + ASE_AWK_ENOMEM, + 0); + return NULL; + } + + if (ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) + { + ase_size_t i; + jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*len); + if (tmp == NULL) + { + ase_awk_free (awk, str); + throw_exception ( + env, + ase_awk_geterrstr(ASE_AWK_ENOMEM), + ASE_AWK_ENOMEM, + 0); + return NULL; + } + + for (i = 0; i < len; i++) tmp[i] = (jchar)str[i]; + ret = (*env)->NewString (env, tmp, len); + free (tmp); + } + else + { + ret = (*env)->NewString (env, str, len); + } + + ase_awk_free (awk, str); + if (ret == NULL) + { + (*env)->ExceptionClear (env); + + throw_exception ( + env, + ase_awk_geterrstr(ASE_AWK_ENOMEM), + ASE_AWK_ENOMEM, + 0); + } + + return ret; } diff --git a/ase/awk/jni.def b/ase/awk/jni.def index 8d1a1825..d15dd6b9 100644 --- a/ase/awk/jni.def +++ b/ase/awk/jni.def @@ -1,13 +1,24 @@ -LIBRARY "aseawk.dll" +LIBRARY "aseawk_jni.dll" EXPORTS Java_ase_awk_Awk_open Java_ase_awk_Awk_close Java_ase_awk_Awk_parse Java_ase_awk_Awk_run + + Java_ase_awk_Awk_getmaxdepth + Java_ase_awk_Awk_setmaxdepth + + Java_ase_awk_Awk_getoption + Java_ase_awk_Awk_setoption + + Java_ase_awk_Awk_getdebug + Java_ase_awk_Awk_setdebug + Java_ase_awk_Awk_addbfn Java_ase_awk_Awk_delbfn Java_ase_awk_Awk_setfilename Java_ase_awk_Awk_setofilename Java_ase_awk_Awk_strtonum + Java_ase_awk_Awk_valtostr diff --git a/ase/awk/jni.h b/ase/awk/jni.h index be25bd14..efdb7651 100644 --- a/ase/awk/jni.h +++ b/ase/awk/jni.h @@ -1,5 +1,5 @@ /* - * $Id: jni.h,v 1.17 2007-01-25 14:10:03 bacon Exp $ + * $Id: jni.h,v 1.18 2007-01-28 11:12:30 bacon Exp $ */ #ifndef _ASE_AWK_JNI_H_ @@ -44,7 +44,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename ( JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum ( JNIEnv* env, jobject obj, jlong runid, jstring str); JNIEXPORT jstring JNICALL Java_ase_awk_Awk_valtostr ( - JNIEnv* env, jobject obj, jlong runid); + JNIEnv* env, jobject obj, jlong runid, jobject val); #ifdef __cplusplus } diff --git a/ase/awk/makefile.msw.cl b/ase/awk/makefile.msw.cl index f1e4bffa..7698ddaf 100644 --- a/ase/awk/makefile.msw.cl +++ b/ase/awk/makefile.msw.cl @@ -10,8 +10,8 @@ JNI_OBJS = $(JNI_SRCS:.c=.obj) JAVA_OBJS = $(JAVA_SRCS:.java=.class) JNI_INC = \ - /I"C:\Program Files\Java\jdk1.5.0_09\include" \ - /I"C:\Program Files\Java\jdk1.5.0_09\include\win32" + /I"$(JAVA_HOME)/include" \ + /I"$(JAVA_HOME)/include\win32" CC = cl LD = link diff --git a/ase/awk/val.c b/ase/awk/val.c index 41eccf80..395dbe3e 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.103 2007-01-16 14:20:42 bacon Exp $ + * $Id: val.c,v 1.104 2007-01-28 11:12:30 bacon Exp $ */ #include @@ -461,10 +461,11 @@ ase_char_t* ase_awk_valtostr ( run, vs->buf, vs->len, opt, buf, len); } -/* TODO: process more value types */ +#ifdef _DEBUG run->awk->sysfns.dprintf ( ASE_T("ERROR: WRONG VALUE TYPE [%d] in ase_awk_valtostr\n"), v->type); +#endif ase_awk_setrunerror (run, ASE_AWK_EVALTYPE, 0, ASE_NULL); return ASE_NULL;