From e407a0b1fb5f889ca54c59eba7549a9a24b14d34 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 25 Jan 2007 14:14:56 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/Awk.java | 51 ++++- ase/awk/StdAwk.java | 3 +- ase/awk/awk.c | 10 +- ase/awk/awk.h | 8 +- ase/awk/awk_i.h | 3 +- ase/awk/func.c | 10 +- ase/awk/jni.c | 358 +++++++++++++++++++++++++++++++----- ase/awk/jni.h | 15 +- ase/com/Awk.cpp | 16 +- ase/com/Awk.h | 6 +- ase/com/ase.idl | 10 +- ase/test/awk/Awk.java | 7 +- ase/test/awk/AwkApplet.java | 1 + ase/test/awk/awk.c | 6 +- 14 files changed, 425 insertions(+), 79 deletions(-) diff --git a/ase/awk/Awk.java b/ase/awk/Awk.java index 30635dc6..77e4761c 100644 --- a/ase/awk/Awk.java +++ b/ase/awk/Awk.java @@ -1,5 +1,5 @@ /* - * $Id: Awk.java,v 1.21 2007-01-24 14:21:29 bacon Exp $ + * $Id: Awk.java,v 1.22 2007-01-25 14:10:02 bacon Exp $ */ package ase.awk; @@ -22,6 +22,22 @@ public abstract class Awk public static final int DEPTH_REX_BUILD = (1 << 4); public static final int DEPTH_REX_MATCH = (1 << 5); + // options + public static final int OPTION_IMPLICIT = (1 << 0); + public static final int OPTION_EXPLICIT = (1 << 1); + public static final int OPTION_UNIQUEFN = (1 << 2); + public static final int OPTION_SHADING = (1 << 3); + public static final int OPTION_SHIFT = (1 << 4); + public static final int OPTION_IDIV = (1 << 5); + public static final int OPTION_STRCONCAT = (1 << 6); + public static final int OPTION_EXTIO = (1 << 7); + public static final int OPTION_COPROC = (1 << 8); + public static final int OPTION_BLOCKLESS = (1 << 9); + public static final int OPTION_STRBASEONE = (1 << 10); + public static final int OPTION_STRIPSPACES = (1 << 11); + public static final int OPTION_NEXTOFILE = (1 << 12); + public static final int OPTION_CRLF = (1 << 13); + static { /* @@ -53,6 +69,8 @@ public abstract class Awk public Awk () throws Exception { + this.handle = 0; + open (); } @@ -72,6 +90,12 @@ public abstract class Awk private native int getmaxdepth (int id); private native void setmaxdepth (int id, int depth); + private native int getoption (); + private native void setoption (int opt); + + private native boolean getdebug (); + private native void setdebug (boolean debug); + private native void addbfn ( String name, int min_args, int max_args) throws Exception; private native void delbfn (String name) throws Exception; @@ -83,7 +107,8 @@ public abstract class Awk private native Object strtonum ( long runid, String str) throws Exception; - private native String valtostr (long runid, Object obj); + private native String valtostr ( + long runid, Object obj) throws Exception; /* == builtin functions == */ public void addBuiltinFunction ( @@ -209,6 +234,28 @@ public abstract class Awk { setmaxdepth (ids, depth); } + + /* == option == */ + public int getOption () + { + return getoption (); + } + + public void setOption (int opt) + { + setoption (opt); + } + + /* == debug == */ + public boolean getDebug () + { + return getdebug (); + } + + public void setDebug (boolean debug) + { + setdebug (debug); + } /* == source code management == */ protected abstract int openSource (int mode); diff --git a/ase/awk/StdAwk.java b/ase/awk/StdAwk.java index 90337746..23dbcc1a 100644 --- a/ase/awk/StdAwk.java +++ b/ase/awk/StdAwk.java @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.java,v 1.12 2007-01-24 14:21:29 bacon Exp $ + * $Id: StdAwk.java,v 1.13 2007-01-25 14:10:03 bacon Exp $ */ package ase.awk; @@ -801,7 +801,6 @@ public abstract class StdAwk extends Awk return new Long (n); } - /* == utility functions == */ private Process popen (String command) throws IOException { diff --git a/ase/awk/awk.c b/ase/awk/awk.c index 67f832c6..a4bb7fe7 100644 --- a/ase/awk/awk.c +++ b/ase/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.104 2007-01-07 07:30:39 bacon Exp $ + * $Id: awk.c,v 1.105 2007-01-25 14:10:03 bacon Exp $ */ #if defined(__BORLANDC__) @@ -11,7 +11,8 @@ static void __free_afn (void* awk, void* afn); -ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns, int* errnum) +ase_awk_t* ase_awk_open ( + const ase_awk_sysfns_t* sysfns, void* custom_data, int* errnum) { ase_awk_t* awk; @@ -157,6 +158,7 @@ ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns, int* errnum) awk->run.count = 0; awk->run.ptr = ASE_NULL; + awk->custom_data = custom_data; return awk; } @@ -263,3 +265,7 @@ void ase_awk_setoption (ase_awk_t* awk, int opt) awk->option = opt; } +void* ase_awk_getcustomdata (ase_awk_t* awk) +{ + return awk->custom_data; +} diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 3deda297..d5f6fdee 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.184 2007-01-21 13:21:14 bacon Exp $ + * $Id: awk.h,v 1.185 2007-01-25 14:10:03 bacon Exp $ */ #ifndef _ASE_AWK_AWK_H_ @@ -187,7 +187,7 @@ enum ASE_AWK_BLOCKLESS = (1 << 9), /* use 1 as the start index for string operations */ - ASE_AWK_STRIDXONE = (1 << 10), + ASE_AWK_STRBASEONE = (1 << 10), /* strip off leading and trailing spaces when splitting a record * into fields with a regular expression. @@ -401,10 +401,12 @@ enum extern "C" { #endif -ase_awk_t* ase_awk_open (const ase_awk_sysfns_t* sysfns, int* errnum); +ase_awk_t* ase_awk_open ( + const ase_awk_sysfns_t* sysfns, void* custom_data, int* errnum); int ase_awk_close (ase_awk_t* awk); int ase_awk_clear (ase_awk_t* awk); +void* ase_awk_getcustomdata (ase_awk_t* awk); int ase_awk_geterrnum (ase_awk_t* awk); ase_size_t ase_awk_geterrlin (ase_awk_t* awk); const ase_char_t* ase_awk_geterrmsg (ase_awk_t* awk); diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h index 107c17fc..c0d29066 100644 --- a/ase/awk/awk_i.h +++ b/ase/awk/awk_i.h @@ -1,5 +1,5 @@ /* - * $Id: awk_i.h,v 1.97 2007-01-06 15:45:50 bacon Exp $ + * $Id: awk_i.h,v 1.98 2007-01-25 14:10:03 bacon Exp $ */ #ifndef _ASE_AWK_AWKI_H_ @@ -97,6 +97,7 @@ struct ase_awk_tree_t struct ase_awk_t { ase_awk_sysfns_t sysfns; + void* custom_data; /* options */ int option; diff --git a/ase/awk/func.c b/ase/awk/func.c index 6de51ec5..df12334c 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,5 +1,5 @@ /* - * $Id: func.c,v 1.90 2007-01-17 03:45:59 bacon Exp $ + * $Id: func.c,v 1.91 2007-01-25 14:10:03 bacon Exp $ */ #include @@ -411,7 +411,7 @@ static int __bfn_index ( ptr = ase_awk_strxnstr (str0, len0, str1, len1); idx = (ptr == ASE_NULL)? -1: (ase_long_t)(ptr - str0); - if (ase_awk_getoption(run->awk) & ASE_AWK_STRIDXONE) idx = idx + 1; + if (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE) idx = idx + 1; if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0); if (a1->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str1); @@ -513,7 +513,7 @@ static int __bfn_substr ( if (n == 1) lcount = (ase_long_t)rcount; } - if (ase_awk_getoption(run->awk) & ASE_AWK_STRIDXONE) lindex = lindex - 1; + if (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE) lindex = lindex - 1; if (lindex >= len) lindex = len; else if (lindex < 0) lindex = 0; @@ -687,7 +687,7 @@ static int __bfn_split ( ase_awk_refupval (run, *a1_ref); p = str; str_left = str_len; - sta = (ase_awk_getoption(run->awk) & ASE_AWK_STRIDXONE)? 1: 0; + sta = (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE)? 1: 0; num = sta; while (p != ASE_NULL) @@ -1243,7 +1243,7 @@ static int __bfn_match ( if (n == -1) return -1; idx = (n == 0)? -1: (ase_long_t)(mat_ptr - str0); - if (ase_awk_getoption(run->awk) & ASE_AWK_STRIDXONE) idx = idx + 1; + if (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE) idx = idx + 1; a0 = ase_awk_makeintval (run, idx); if (a0 == ASE_NULL) diff --git a/ase/awk/jni.c b/ase/awk/jni.c index 6451230a..451870a3 100644 --- a/ase/awk/jni.c +++ b/ase/awk/jni.c @@ -1,5 +1,5 @@ /* - * $Id: jni.c,v 1.53 2007-01-24 14:21:29 bacon Exp $ + * $Id: jni.c,v 1.54 2007-01-25 14:10:03 bacon Exp $ */ #include @@ -49,10 +49,16 @@ static ase_ssize_t __write_source ( static ase_ssize_t __process_extio ( int cmd, void* arg, ase_char_t* data, ase_size_t count); +typedef struct awk_data_t awk_data_t; typedef struct srcio_data_t srcio_data_t; typedef struct runio_data_t runio_data_t; typedef struct run_data_t run_data_t; +struct awk_data_t +{ + int debug; +}; + struct srcio_data_t { JNIEnv* env; @@ -242,12 +248,19 @@ static void throw_exception ( (*env)->DeleteLocalRef (env, except_obj); } +static jboolean is_debug (ase_awk_t* awk) +{ + awk_data_t* awk_data = (awk_data_t*)ase_awk_getcustomdata (awk); + return awk_data->debug? JNI_TRUE: JNI_FALSE; +} + JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj) { jclass class; jfieldID handle; ase_awk_t* awk; ase_awk_sysfns_t sysfns; + awk_data_t* awk_data; int opt, errnum; memset (&sysfns, 0, sizeof(sysfns)); @@ -277,9 +290,23 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj) sysfns.dprintf = awk_dprintf; sysfns.abort = awk_abort; - awk = ase_awk_open (&sysfns, &errnum); + awk_data = (awk_data_t*)malloc (sizeof(awk_data_t)); + if (awk_data == NULL) + { + throw_exception ( + env, + ase_awk_geterrstr(errnum), + errnum, + 0); + return; + } + + memset (awk_data, 0, sizeof(awk_data_t)); + + awk = ase_awk_open (&sysfns, awk_data, &errnum); if (awk == NULL) { + free (sysfns.custom_data); throw_exception ( env, ase_awk_geterrstr(errnum), @@ -296,6 +323,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj) /* internal error. no handle field * NoSuchFieldError, ExceptionInitializerError, * OutOfMemoryError might occur */ + + ase_awk_close (awk); + free (awk_data); return; } @@ -328,8 +358,10 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj) if (awk != NULL) { /* the handle is not NULL. close it */ + void* tmp = ase_awk_getcustomdata (awk); ase_awk_close (awk); (*env)->SetLongField (env, obj, handle, (jlong)0); + free (tmp); } } @@ -503,22 +535,33 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj) static ase_ssize_t __java_open_source (JNIEnv* env, jobject obj, int mode) { jclass class; + jfieldID handle; jmethodID mid; - jthrowable thrown; jint ret; + ase_awk_t* awk; class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); mid = (*env)->GetMethodID (env, class, "openSource", "(I)I"); (*env)->DeleteLocalRef (env, class); + if (handle == NULL) + { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); + if (mid == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } ret = (*env)->CallIntMethod (env, obj, mid, mode); - thrown = (*env)->ExceptionOccurred (env); - if (thrown) + if ((*env)->ExceptionOccurred (env)) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -529,22 +572,33 @@ static ase_ssize_t __java_open_source (JNIEnv* env, jobject obj, int mode) static ase_ssize_t __java_close_source (JNIEnv* env, jobject obj, int mode) { jclass class; + jfieldID handle; jmethodID mid; - jthrowable thrown; jint ret; + ase_awk_t* awk; class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); mid = (*env)->GetMethodID (env, class, "closeSource", "(I)I"); (*env)->DeleteLocalRef (env, class); + if (handle == NULL) + { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); + if (mid == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } ret = (*env)->CallIntMethod (env, obj, mid, mode); - thrown = (*env)->ExceptionOccurred (env); - if (thrown) + if ((*env)->ExceptionOccurred (env)) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -556,30 +610,43 @@ static ase_ssize_t __java_read_source ( JNIEnv* env, jobject obj, ase_char_t* buf, ase_size_t size) { jclass class; + jfieldID handle; jmethodID mid; jcharArray array; jchar* tmp; jint ret, i; - jthrowable thrown; + ase_awk_t* awk; class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); mid = (*env)->GetMethodID (env, class, "readSource", "([CI)I"); (*env)->DeleteLocalRef (env, class); + if (handle == NULL) + { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); + if (mid == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } array = (*env)->NewCharArray (env, size); if (array == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } ret = (*env)->CallIntMethod (env, obj, mid, array, size); - thrown = (*env)->ExceptionOccurred (env); - if (thrown) + if ((*env)->ExceptionOccurred (env)) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -596,24 +663,37 @@ static ase_ssize_t __java_write_source ( JNIEnv* env, jobject obj, ase_char_t* buf, ase_size_t size) { jclass class; + jfieldID handle; jmethodID mid; jcharArray array; jchar* tmp; jint ret; - jthrowable thrown; ase_size_t i; + ase_awk_t* awk; class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); mid = (*env)->GetMethodID (env, class, "writeSource", "([CI)I"); (*env)->DeleteLocalRef (env, class); - if (mid == NULL) + if (handle == NULL) { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); + + if (mid == NULL) + { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } array = (*env)->NewCharArray (env, size); if (array == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } @@ -622,10 +702,9 @@ static ase_ssize_t __java_write_source ( (*env)->ReleaseCharArrayElements (env, array, tmp, 0); ret = (*env)->CallIntMethod (env, obj, mid, array, size); - thrown = (*env)->ExceptionOccurred (env); - if (thrown) + if ((*env)->ExceptionOccurred (env)) { - if (awk->debug) (*env)->ExceptionDescribe (env); + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -638,31 +717,51 @@ static ase_ssize_t __java_open_extio ( JNIEnv* env, jobject obj, char* meth, ase_awk_extio_t* extio) { jclass class; + jfieldID handle; jmethodID mid; jclass extio_class; jmethodID extio_cons; jobject extio_object; jstring extio_name; jint ret; + ase_awk_t* awk; + /* get the method - meth */ + class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); + mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); + (*env)->DeleteLocalRef (env, class); + + if (handle == NULL) + { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); + + if (mid == NULL) + { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); + return -1; + } + + /* look for extio class */ extio_class = (*env)->FindClass (env, CLASS_EXTIO); - if (extio_class == NULL) return -1; + if (extio_class == NULL) + { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); + return -1; + } /* get the constructor */ extio_cons = (*env)->GetMethodID ( env, extio_class, "", "(Ljava/lang/String;IIJ)V"); if (extio_cons == NULL) { - (*env)->DeleteLocalRef (env, extio_class); - return -1; - } - - /* get the method - meth */ - class = (*env)->GetObjectClass(env, obj); - mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); - (*env)->DeleteLocalRef (env, class); - if (mid == NULL) - { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); (*env)->DeleteLocalRef (env, extio_class); return -1; } @@ -690,6 +789,8 @@ static ase_ssize_t __java_open_extio ( if (extio_name == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); (*env)->DeleteLocalRef (env, extio_class); return -1; } @@ -701,6 +802,8 @@ static ase_ssize_t __java_open_extio ( (*env)->DeleteLocalRef (env, extio_class); if (extio_object == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); (*env)->DeleteLocalRef (env, extio_name); return -1; } @@ -712,6 +815,7 @@ static ase_ssize_t __java_open_extio ( if ((*env)->ExceptionOccurred(env)) { /* clear the exception */ + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -722,10 +826,12 @@ static ase_ssize_t __java_open_extio ( * ret == 0 opened the stream and reached its end * ret == 1 opened the stream. */ extio->handle = (*env)->NewGlobalRef (env, extio_object); - /* TODO: close it... + /* if (extio->handle == NULL) { - close it again... + // TODO: close the stream ... + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); ret = -1; } */ @@ -739,20 +845,33 @@ static ase_ssize_t __java_close_extio ( JNIEnv* env, jobject obj, char* meth, ase_awk_extio_t* extio) { jclass class; + jfieldID handle; jmethodID mid; jint ret; + ase_awk_t* awk; class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); (*env)->DeleteLocalRef (env, class); + + if (handle == NULL) + { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); if (mid == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } ret = (*env)->CallIntMethod (env, obj, mid, extio->handle); if ((*env)->ExceptionOccurred (env)) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -773,30 +892,44 @@ static ase_ssize_t __java_read_extio ( ase_awk_extio_t* extio, ase_char_t* buf, ase_size_t size) { jclass class; + jfieldID handle; jmethodID mid; jcharArray array; jchar* tmp; jint ret, i; - jthrowable thrown; + ase_awk_t* awk; class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I"); (*env)->DeleteLocalRef (env, class); + + if (handle == NULL) + { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); + if (mid == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } array = (*env)->NewCharArray (env, size); if (array == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } ret = (*env)->CallIntMethod (env, obj, mid, extio->handle, array, size); - thrown = (*env)->ExceptionOccurred (env); - if (thrown) + if ((*env)->ExceptionOccurred (env)) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -817,24 +950,37 @@ static ase_ssize_t __java_write_extio ( ase_awk_extio_t* extio, ase_char_t* data, ase_size_t size) { jclass class; + jfieldID handle; jmethodID mid; jcharArray array; jchar* tmp; jint ret; ase_size_t i; - jthrowable thrown; + ase_awk_t* awk; class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I"); (*env)->DeleteLocalRef (env, class); + + if (handle == NULL) + { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); if (mid == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } array = (*env)->NewCharArray (env, size); if (array == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } @@ -843,9 +989,9 @@ static ase_ssize_t __java_write_extio ( (*env)->ReleaseCharArrayElements (env, array, tmp, 0); ret = (*env)->CallIntMethod (env, obj, mid, extio->handle, array, size); - thrown = (*env)->ExceptionOccurred (env); - if (thrown) + if ((*env)->ExceptionOccurred (env)) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -859,21 +1005,32 @@ static ase_ssize_t __java_flush_extio ( JNIEnv* env, jobject obj, char* meth, ase_awk_extio_t* extio) { jclass class; + jfieldID handle; jmethodID mid; jint ret; + ase_awk_t* awk; class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); (*env)->DeleteLocalRef (env, class); + if (handle == NULL) + { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); if (mid == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); return -1; } ret = (*env)->CallIntMethod (env, obj, mid, extio->handle); if ((*env)->ExceptionOccurred (env)) { - if (awk->debug) (*env)->ExceptionDescribe (env); + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -885,21 +1042,31 @@ static ase_ssize_t __java_next_extio ( JNIEnv* env, jobject obj, char* meth, ase_awk_extio_t* extio) { jclass class; + jfieldID handle; jmethodID mid; jint ret; + ase_awk_t* awk; class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); (*env)->DeleteLocalRef (env, class); + if (handle == NULL) + { + (*env)->ExceptionClear (env); + return -1; + } + awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); if (mid == NULL) { + (*env)->ExceptionClear (env); return -1; } ret = (*env)->CallIntMethod (env, obj, mid, extio->handle); if ((*env)->ExceptionOccurred (env)) { - if (awk->debug) (*env)->ExceptionDescribe (env); + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ret = -1; } @@ -1017,9 +1184,11 @@ static int __handle_bfn ( jobject arg, ret; ase_awk_val_t* v; ase_char_t msg_nomem[MSG_SIZE]; + ase_awk_t* awk; run_data = ase_awk_getruncustomdata (run); nargs = ase_awk_getnargs (run); + awk = ase_awk_getrunawk (run); env = run_data->env; obj = run_data->obj; @@ -1032,7 +1201,7 @@ static int __handle_bfn ( if (ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) { ase_size_t i; - jchar* tmp = (jchar*)malloc (ASE_SIZEOF(jchar)*fnl); + jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*fnl); if (tmp == NULL) { ase_awk_setrunerror ( @@ -1048,6 +1217,7 @@ static int __handle_bfn ( if (name == NULL) { + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, msg_nomem); return -1; @@ -1070,7 +1240,8 @@ static int __handle_bfn ( if (method == NULL) { /* if the method is not found, the exception is thrown. - * so clear it to prevent it from being thrown */ + * clear it to prevent it from being thrown */ + if (is_debug(awk)) (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); ase_awk_setrunerrnum (run, ASE_AWK_EBFNUSER); return -1; @@ -1080,9 +1251,8 @@ static int __handle_bfn ( env, nargs, run_data->object_class, NULL); if (args == NULL) { - if ((*env)->ExceptionOccurred (env)) - (*env)->ExceptionClear (env); - + if (is_debug(awk)) (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, msg_nomem); return -1; } @@ -1145,7 +1315,11 @@ static int __handle_bfn ( if (v->type != ASE_AWK_VAL_NIL && arg == NULL) { if ((*env)->ExceptionOccurred (env)) + { + if (is_debug(awk)) + (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); + } (*env)->DeleteLocalRef (env, args); ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, msg_nomem); return -1; @@ -1158,7 +1332,8 @@ static int __handle_bfn ( ret = (*env)->CallObjectMethod (env, obj, method, (jlong)run, args); if ((*env)->ExceptionOccurred (env)) { - if (awk->debug) (*env)->ExceptionDescribe (env); + if (is_debug(ase_awk_getrunawk(run))) + (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); (*env)->DeleteLocalRef (env, args); @@ -1337,6 +1512,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn ( if (ptr == NULL) { (*env)->ExceptionClear (env); + throw_exception ( env, ase_awk_geterrstr(ASE_AWK_ENOMEM), @@ -1497,6 +1673,94 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth ( ase_awk_setmaxdepth (awk, ids, depth); } +JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption ( + JNIEnv* env, jobject obj) +{ + jclass class; + jfieldID handle; + ase_awk_t* awk; + + class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); + (*env)->DeleteLocalRef (env, class); + if (handle == NULL) + { + /* internal error. no handle field + * NoSuchFieldError, ExceptionInitializerError, + * OutOfMemoryError might occur */ + return 0; + } + + awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); + return ase_awk_getoption (awk); +} + +JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption ( + JNIEnv* env, jobject obj, jint options) +{ + jclass class; + jfieldID handle; + ase_awk_t* awk; + + class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); + (*env)->DeleteLocalRef (env, class); + if (handle == NULL) + { + /* internal error. no handle field + * NoSuchFieldError, ExceptionInitializerError, + * OutOfMemoryError might occur */ + return; + } + + awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); + ase_awk_setoption (awk, (int)options); +} + +JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug ( + JNIEnv* env, jobject obj) +{ + jclass class; + jfieldID handle; + ase_awk_t* awk; + + class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); + (*env)->DeleteLocalRef (env, class); + if (handle == NULL) + { + /* internal error. no handle field + * NoSuchFieldError, ExceptionInitializerError, + * OutOfMemoryError might occur */ + return JNI_FALSE; + } + + awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); + return ((awk_data_t*)ase_awk_getcustomdata(awk))->debug? JNI_TRUE: JNI_FALSE; +} + +JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( + JNIEnv* env, jobject obj, jboolean debug) +{ + jclass class; + jfieldID handle; + ase_awk_t* awk; + + class = (*env)->GetObjectClass(env, obj); + handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); + (*env)->DeleteLocalRef (env, class); + if (handle == NULL) + { + /* internal error. no handle field + * NoSuchFieldError, ExceptionInitializerError, + * OutOfMemoryError might occur */ + return; + } + + awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); + ((awk_data_t*)ase_awk_getcustomdata(awk))->debug = debug; +} + JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( JNIEnv* env, jobject obj, jlong runid, jstring name) { @@ -1682,3 +1946,11 @@ JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum ( return ret; } + +JNIEXPORT jstring JNICALL Java_ase_awk_Awk_valtostr ( + JNIEnv* env, jobject obj, jlong runid) +{ + // TODO: ... + return NULL; +} + diff --git a/ase/awk/jni.h b/ase/awk/jni.h index eef6fa76..be25bd14 100644 --- a/ase/awk/jni.h +++ b/ase/awk/jni.h @@ -1,5 +1,5 @@ /* - * $Id: jni.h,v 1.16 2007-01-24 11:54:16 bacon Exp $ + * $Id: jni.h,v 1.17 2007-01-25 14:10:03 bacon Exp $ */ #ifndef _ASE_AWK_JNI_H_ @@ -26,12 +26,25 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth ( JNIEnv* env, jobject obj, jint ids, jint depth); +JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption ( + JNIEnv* env, jobject obj); +JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption ( + JNIEnv* env, jobject obj, jint options); + +JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug ( + JNIEnv* env, jobject obj); +JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( + JNIEnv* env, jobject obj, jboolean debug); + JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( JNIEnv* env, jobject obj, jlong runid, jstring name); JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename ( JNIEnv* env, jobject obj, jlong runid, jstring name); + 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); #ifdef __cplusplus } diff --git a/ase/com/Awk.cpp b/ase/com/Awk.cpp index 654d969c..a15b662e 100644 --- a/ase/com/Awk.cpp +++ b/ase/com/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.21 2007-01-17 14:09:49 bacon Exp $ + * $Id: Awk.cpp,v 1.22 2007-01-25 14:14:55 bacon Exp $ */ #include "stdafx.h" @@ -51,7 +51,7 @@ CAwk::CAwk (): ASE_AWK_SHIFT | ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | - ASE_AWK_STRIDXONE | + ASE_AWK_STRBASEONE | ASE_AWK_STRIPSPACES | ASE_AWK_NEXTOFILE | ASE_AWK_CRLF; @@ -442,7 +442,7 @@ HRESULT CAwk::Parse (int* ret) sysfns.dprintf = awk_dprintf; sysfns.abort = awk_abort; - handle = ase_awk_open (&sysfns, &errnum); + handle = ase_awk_open (&sysfns, NULL, &errnum); if (handle == NULL) { errlin = 0; @@ -976,17 +976,17 @@ STDMETHODIMP CAwk::put_SupportBlockless(BOOL newVal) return S_OK; } -STDMETHODIMP CAwk::get_StringIndexOne(BOOL *pVal) +STDMETHODIMP CAwk::get_StringBaseOne(BOOL *pVal) { if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_STRIDXONE) == 1; + *pVal = (option & ASE_AWK_STRBASEONE) == 1; return S_OK; } -STDMETHODIMP CAwk::put_StringIndexOne(BOOL newVal) +STDMETHODIMP CAwk::put_StringBaseOne(BOOL newVal) { - if (newVal) option = option | ASE_AWK_STRIDXONE; - else option = option & ~ASE_AWK_STRIDXONE; + if (newVal) option = option | ASE_AWK_STRBASEONE; + else option = option & ~ASE_AWK_STRBASEONE; if (handle != NULL) ase_awk_setoption (handle, option); return S_OK; } diff --git a/ase/com/Awk.h b/ase/com/Awk.h index e40532ff..d8d42f1e 100644 --- a/ase/com/Awk.h +++ b/ase/com/Awk.h @@ -1,5 +1,5 @@ /* - * $Id: Awk.h,v 1.14 2007-01-17 14:09:49 bacon Exp $ + * $Id: Awk.h,v 1.15 2007-01-25 14:14:56 bacon Exp $ */ #ifndef _ASE_COM_AWK_H_ @@ -127,8 +127,8 @@ public: STDMETHOD(put_Nextofile)(/*[in]*/ BOOL newVal); STDMETHOD(get_StripSpaces)(/*[out, retval]*/ BOOL *pVal); STDMETHOD(put_StripSpaces)(/*[in]*/ BOOL newVal); - STDMETHOD(get_StringIndexOne)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_StringIndexOne)(/*[in]*/ BOOL newVal); + STDMETHOD(get_StringBaseOne)(/*[out, retval]*/ BOOL *pVal); + STDMETHOD(put_StringBaseOne)(/*[in]*/ BOOL newVal); STDMETHOD(get_SupportBlockless)(/*[out, retval]*/ BOOL *pVal); STDMETHOD(put_SupportBlockless)(/*[in]*/ BOOL newVal); STDMETHOD(get_SupportExtio)(/*[out, retval]*/ BOOL *pVal); diff --git a/ase/com/ase.idl b/ase/com/ase.idl index 7ba2cfba..34050422 100644 --- a/ase/com/ase.idl +++ b/ase/com/ase.idl @@ -1,5 +1,5 @@ /* - * $Id: ase.idl,v 1.15 2007-01-17 14:09:49 bacon Exp $ + * $Id: ase.idl,v 1.16 2007-01-25 14:14:56 bacon Exp $ */ import "oaidl.idl"; @@ -81,10 +81,10 @@ interface IAwk : IDispatch [propput, id(16), helpstring("property SupportBlockless")] HRESULT SupportBlockless([in] BOOL newVal); - [propget, id(17), helpstring("property StringIndexOne")] - HRESULT StringIndexOne([out, retval] BOOL *pVal); - [propput, id(17), helpstring("property StringIndexOne")] - HRESULT StringIndexOne([in] BOOL newVal); + [propget, id(17), helpstring("property StringBaseOne")] + HRESULT StringBaseOne([out, retval] BOOL *pVal); + [propput, id(17), helpstring("property StringBaseOne")] + HRESULT StringBaseOne([in] BOOL newVal); [propget, id(18), helpstring("property StripSpaces")] HRESULT StripSpaces([out, retval] BOOL *pVal); diff --git a/ase/test/awk/Awk.java b/ase/test/awk/Awk.java index 383823d5..f022a9e1 100644 --- a/ase/test/awk/Awk.java +++ b/ase/test/awk/Awk.java @@ -1,5 +1,5 @@ /* - * $Id: Awk.java,v 1.21 2007-01-24 14:21:30 bacon Exp $ + * $Id: Awk.java,v 1.22 2007-01-25 14:14:56 bacon Exp $ */ package ase.test.awk; @@ -88,6 +88,11 @@ public class Awk extends ase.awk.StdAwk { awk = new Awk (); awk.setMaxDepth (Awk.DEPTH_BLOCK_PARSE, 30); + awk.setDebug (true); + //awk.setDebug (false); + + //awk.setOption (awk.getOption() | OPTION_STRBASEONE); + System.out.println ("[" + awk.getOption() + "]"); awk.parse (); awk.run (); diff --git a/ase/test/awk/AwkApplet.java b/ase/test/awk/AwkApplet.java index 3014a65d..45e57df4 100644 --- a/ase/test/awk/AwkApplet.java +++ b/ase/test/awk/AwkApplet.java @@ -4,6 +4,7 @@ import java.applet.*; import java.awt.*; import java.awt.event.*; + public class AwkApplet extends Applet { public void init () diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 289d68b7..3ace7b58 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.152 2007-01-23 14:23:18 bacon Exp $ + * $Id: awk.c,v 1.153 2007-01-25 14:14:56 bacon Exp $ */ #include @@ -797,7 +797,7 @@ static int __main (int argc, ase_char_t* argv[]) ASE_AWK_EXTIO | /*ASE_AWK_COPROC |*/ ASE_AWK_BLOCKLESS | - ASE_AWK_STRIDXONE | + ASE_AWK_STRBASEONE | ASE_AWK_STRIPSPACES | ASE_AWK_NEXTOFILE; @@ -872,7 +872,7 @@ static int __main (int argc, ase_char_t* argv[]) sysfns.custom_data = &sysfns_data; #endif - if ((awk = ase_awk_open(&sysfns, &errnum)) == ASE_NULL) + if ((awk = ase_awk_open(&sysfns, ASE_NULL, &errnum)) == ASE_NULL) { #ifdef _WIN32 HeapDestroy (sysfns_data.heap);