Recovered from cvs revision 2007-10-19 03:50:00

This commit is contained in:
hyung-hwan 2007-10-19 14:05:00 +00:00
parent 060d42d19b
commit 3b74f61b7f
7 changed files with 238 additions and 279 deletions

View File

@ -1,36 +1,38 @@
/* /*
* $Id: Argument.java,v 1.2 2007/10/17 14:38:28 bacon Exp $ * $Id: Argument.java,v 1.3 2007/10/18 14:51:04 bacon Exp $
*/ */
package ase.awk; package ase.awk;
public class Argument public class Argument
{ {
protected Context ctx; protected long runid;
protected long value; protected long valid;
Argument (Context ctx) Argument (long runid, long valid)
{ {
this.ctx = ctx; this.runid = runid;
this.valid = valid;
} }
long getIntValue () long getIntValue ()
{ {
return getintval (ctx.getId(), value); return getintval (this.runid, this.valid);
} }
double getRealValue () double getRealValue ()
{ {
return 0.0; return getrealval (this.runid, this.valid);
} }
String getStringValue () String getStringValue () throws Exception
{ {
return null; return getstrval (this.runid, this.valid);
} }
Argument getIndexed (String idx) Argument getIndexed (String idx)
{ {
// TODO:..
return null; return null;
} }
@ -41,5 +43,5 @@ public class Argument
protected native long getintval (long runid, long valid); protected native long getintval (long runid, long valid);
protected native double getrealval (long runid, long valid); protected native double getrealval (long runid, long valid);
protected native String getstrval (long runid, long valid); protected native String getstrval (long runid, long valid) throws Exception;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.java,v 1.23 2007/10/17 14:38:28 bacon Exp $ * $Id: Awk.java,v 1.25 2007/10/18 14:51:04 bacon Exp $
* *
* {License} * {License}
*/ */
@ -62,49 +62,75 @@ public abstract class Awk
/* == just in case == */ /* == just in case == */
protected void finalize () throws Throwable protected void finalize () throws Throwable
{ {
if (this.awkid != 0) close (); close ();
super.finalize (); super.finalize ();
} }
/* == native methods == */ public void close ()
private native void open () throws Exception; {
public native void close (); if (this.awkid != 0)
public native void parse () throws Exception; {
public native void run (String main, String[] args) throws Exception; close (this.awkid);
public native void stop (); this.awkid = 0;
private native int getmaxdepth (int id); }
private native void setmaxdepth (int id, int depth); }
private native int getoption ();
private native void setoption (int opt); public void parse () throws Exception
private native boolean getdebug (); {
private native void setdebug (boolean debug); parse (this.awkid);
private native void setword (String ow, String nw); }
private native void addfunc (String name, int min_args, int max_args) throws Exception;
private native void delfunc (String name) throws Exception; public void run (String main, String[] args) throws Exception
native void setfilename (long runid, String name) throws Exception; {
native void setofilename (long runid, String name) throws Exception; run (this.awkid, main, args);
private native Object strtonum (long runid, String str) throws Exception; }
private native String valtostr (long runid, Object obj) throws Exception;
protected native String strftime (String fmt, long sec);
protected native String strfgmtime (String fmt, long sec);
protected native int system (String cmd);
/* == simpler run methods == */
public void run (String main) throws Exception public void run (String main) throws Exception
{ {
run (main, null); run (this.awkid, main, null);
} }
public void run (String[] args) throws Exception public void run (String[] args) throws Exception
{ {
run (null, args); run (this.awkid, null, args);
} }
public void run () throws Exception public void run () throws Exception
{ {
run (null, null); run (this.awkid, null, null);
} }
public void stop () throws Exception
{
stop (this.awkid);
}
/* == native methods == */
private native void open () throws Exception;
protected native void close (long awkid);
protected native void parse (long awkid) throws Exception;
protected native void run (long awkid, String main, String[] args) throws Exception;
protected native void stop (long awkid) throws Exception;
protected native int getmaxdepth (long awkid, int id) throws Exception;
protected native void setmaxdepth (long awkid, int id, int depth) throws Exception;
protected native int getoption (long awkid) throws Exception;
protected native void setoption (long awkid, int opt) throws Exception;
protected native boolean getdebug (long awkid) throws Exception;
protected native void setdebug (long awkid, boolean debug) throws Exception;
protected native void setword (long awkid, String ow, String nw) throws Exception;
protected native void addfunc (String name, int min_args, int max_args) throws Exception;
protected native void delfunc (String name) throws Exception;
native void setfilename (long runid, String name) throws Exception;
native void setofilename (long runid, String name) throws Exception;
protected native Object strtonum (long runid, String str) throws Exception;
protected native String valtostr (long runid, Object obj) throws Exception;
protected native String strftime (String fmt, long sec);
protected native String strfgmtime (String fmt, long sec);
protected native int system (String cmd);
/* == intrinsic functions == */ /* == intrinsic functions == */
public void addFunction (String name, int min_args, int max_args) throws Exception public void addFunction (String name, int min_args, int max_args) throws Exception
{ {
@ -236,51 +262,52 @@ public abstract class Awk
} }
/* == depth limiting == */ /* == depth limiting == */
public int getMaxDepth (int id) public int getMaxDepth (int id) throws Exception
{ {
return getmaxdepth (id); return getmaxdepth (this.awkid, id);
} }
public void setMaxDepth (int ids, int depth) public void setMaxDepth (int ids, int depth) throws Exception
{ {
setmaxdepth (ids, depth); setmaxdepth (this.awkid, ids, depth);
} }
/* == option == */ /* == option == */
public int getOption () public int getOption () throws Exception
{ {
return getoption (); return getoption (this.awkid);
} }
public void setOption (int opt) public void setOption (int opt) throws Exception
{ {
setoption (opt); setoption (this.awkid, opt);
} }
/* == debug == */ /* == debug == */
public boolean getDebug () public boolean getDebug () throws Exception
{ {
return getdebug (); return getdebug (this.awkid);
} }
public void setDebug (boolean debug) public void setDebug (boolean debug) throws Exception
{ {
setdebug (debug); setdebug (this.awkid, debug);
} }
public void setWord (String ow, String nw) /* == word replacement == */
public void setWord (String ow, String nw) throws Exception
{ {
setword (ow, nw); setword (this.awkid, ow, nw);
} }
public void unsetWord (String ow) public void unsetWord (String ow) throws Exception
{ {
setword (ow, null); setword (this.awkid, ow, null);
} }
public void unsetAllWords () public void unsetAllWords () throws Exception
{ {
setword (null, null); setword (this.awkid, null, null);
} }
/* == source code management == */ /* == source code management == */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: StdAwk.java,v 1.15 2007/10/15 16:10:10 bacon Exp $ * $Id: StdAwk.java,v 1.16 2007/10/18 14:51:04 bacon Exp $
* *
* {License} * {License}
*/ */
@ -333,8 +333,12 @@ public abstract class StdAwk extends Awk
/* == arithmetic built-in functions */ /* == arithmetic built-in functions */
public Object sin (Context ctx, String name, Object[] args) throws Exception public Object sin (Context ctx, String name, Object[] args) throws Exception
{ {
/*
double x = builtinFunctionArgumentToDouble (ctx, args[0]); double x = builtinFunctionArgumentToDouble (ctx, args[0]);
return new Double (Math.sin(x)); return new Double (Math.sin(x));
*/
Argument x = (Argument)args[0];
return new Double (Math.sin(x.getIntValue()));
} }
public Object cos (Context ctx, String name, Object[] args) throws Exception public Object cos (Context ctx, String name, Object[] args) throws Exception

View File

@ -1,5 +1,5 @@
/* /*
* $Id: jni.c,v 1.27 2007/10/17 14:38:28 bacon Exp $ * $Id: jni.c,v 1.29 2007/10/18 14:51:04 bacon Exp $
* *
* {License} * {License}
*/ */
@ -39,6 +39,7 @@
#define CLASS_EXCEPTION "ase/awk/Exception" #define CLASS_EXCEPTION "ase/awk/Exception"
#define CLASS_EXTIO "ase/awk/Extio" #define CLASS_EXTIO "ase/awk/Extio"
#define CLASS_CONTEXT "ase/awk/Context" #define CLASS_CONTEXT "ase/awk/Context"
#define CLASS_ARGUMENT "ase/awk/Argument"
#define FIELD_AWKID "awkid" #define FIELD_AWKID "awkid"
#define FIELD_RUNID "runid" #define FIELD_RUNID "runid"
@ -102,6 +103,7 @@ struct run_data_t
jclass double_class; jclass double_class;
jclass object_class; jclass object_class;
jclass context_class; jclass context_class;
jclass argument_class;
jmethodID integer_init; jmethodID integer_init;
jmethodID long_init; jmethodID long_init;
@ -109,6 +111,7 @@ struct run_data_t
jmethodID float_init; jmethodID float_init;
jmethodID double_init; jmethodID double_init;
jmethodID context_init; jmethodID context_init;
jmethodID argument_init;
jmethodID integer_value; jmethodID integer_value;
jmethodID long_value; jmethodID long_value;
@ -488,45 +491,33 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
#endif #endif
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj) JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj, jlong awkid)
{ {
jclass class;
jfieldID awkid;
ase_awk_t* awk; ase_awk_t* awk;
awk_data_t* tmp;
awk = (ase_awk_t*)awkid;
/* don't like to throw an exception for close.
* i find doing so very irritating, especially when it
* should be called in an exception handler */
if (awk == NULL) return;
#if defined(_WIN32) && defined(_DEBUG) #if defined(_WIN32) && defined(_DEBUG)
OutputDebugStringW (L"<<<CLOSING AWK>>>\n"); OutputDebugStringW (L"<<<CLOSING AWK>>>\n");
#endif #endif
class = (*env)->GetObjectClass(env, obj); tmp = (awk_data_t*)ase_awk_getcustomdata (awk);
awkid = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
(*env)->DeleteLocalRef (env, class);
if (awkid == NULL)
{
/* internal error. no awkid field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
return;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, awkid);
if (awk != NULL)
{
/* the awkid is not NULL. close it */
awk_data_t* tmp = (awk_data_t*)ase_awk_getcustomdata (awk);
#if defined(_WIN32) && defined(__DMC__) #if defined(_WIN32) && defined(__DMC__)
HANDLE heap = tmp->heap; HANDLE heap = tmp->heap;
#endif #endif
ase_awk_close (awk); ase_awk_close (awk);
(*env)->SetLongField (env, obj, awkid, (jlong)0);
#if defined(_WIN32) && defined(__DMC__) #if defined(_WIN32) && defined(__DMC__)
awk_free (heap, tmp); awk_free (heap, tmp);
HeapDestroy (heap); HeapDestroy (heap);
#else #else
awk_free (NULL, tmp); awk_free (NULL, tmp);
#endif #endif
}
#if defined(_WIN32) && defined(_DEBUG) #if defined(_WIN32) && defined(_DEBUG)
OutputDebugStringW (L"<<<CLOSED AWK>>>\n"); OutputDebugStringW (L"<<<CLOSED AWK>>>\n");
@ -534,30 +525,38 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj)
_CrtDumpMemoryLeaks (); _CrtDumpMemoryLeaks ();
#endif #endif
#endif #endif
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj) #define EXCEPTION_ON_NULL_AWK(awk) \
{ if (awk == NULL) \
jclass class; { \
jfieldID handle; throw_exception ( \
env, \
ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOPER), \
ASE_AWK_ENOPER, \
0); \
return; \
}
#define EXCEPTION_ON_NULL_AWK_RETURNING(awk,ret) \
if (awk == NULL) \
{ \
throw_exception ( \
env, \
ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOPER), \
ASE_AWK_ENOPER, \
0); \
return ret; \
}
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj, jlong awkid)
{
ase_awk_t* awk; ase_awk_t* awk;
ase_awk_srcios_t srcios; ase_awk_srcios_t srcios;
srcio_data_t srcio_data; srcio_data_t srcio_data;
class = (*env)->GetObjectClass (env, obj); awk = (ase_awk_t*) awkid;
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J"); EXCEPTION_ON_NULL_AWK (awk);
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
return;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
srcio_data.env = env; srcio_data.env = env;
srcio_data.obj = obj; srcio_data.obj = obj;
@ -587,6 +586,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj)
(*env)->DeleteLocalRef (env, run_data.string_class); \ (*env)->DeleteLocalRef (env, run_data.string_class); \
(*env)->DeleteLocalRef (env, run_data.object_class); \ (*env)->DeleteLocalRef (env, run_data.object_class); \
(*env)->DeleteLocalRef (env, run_data.context_class); \ (*env)->DeleteLocalRef (env, run_data.context_class); \
(*env)->DeleteLocalRef (env, run_data.argument_class); \
if (run_data.context_object != NULL) \ if (run_data.context_object != NULL) \
(*env)->DeleteLocalRef (env, run_data.context_object); \ (*env)->DeleteLocalRef (env, run_data.context_object); \
} while (0) } while (0)
@ -651,35 +651,21 @@ static void on_run_end (ase_awk_run_t* run, int errnum, void* custom)
(*env)->SetLongField (env, run_data->context_object, runid, (jlong)0); (*env)->SetLongField (env, run_data->context_object, runid, (jlong)0);
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jstring mfn, jobjectArray args) JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jlong awkid, jstring mfn, jobjectArray args)
{ {
jclass class;
jfieldID handle;
ase_awk_t* awk; ase_awk_t* awk;
ase_awk_runcbs_t runcbs; ase_awk_runcbs_t runcbs;
ase_awk_runios_t runios; ase_awk_runios_t runios;
runio_data_t runio_data; runio_data_t runio_data;
run_data_t run_data; run_data_t run_data;
ase_char_t* mmm; ase_char_t* mmm;
ase_awk_runarg_t* runarg = NULL;
ase_size_t len, i; ase_size_t len, i;
const jchar* ptr; const jchar* ptr;
ase_awk_runarg_t* runarg = NULL; awk = (ase_awk_t*) awkid;
EXCEPTION_ON_NULL_AWK (awk);
class = (*env)->GetObjectClass (env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
(*env)->DeleteLocalRef (env, class);
if (handle == 0)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
return;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
run_data.env = env; run_data.env = env;
run_data.obj = obj; run_data.obj = obj;
@ -693,6 +679,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jstring m
run_data.double_class = (*env)->FindClass (env, "java/lang/Double"); run_data.double_class = (*env)->FindClass (env, "java/lang/Double");
run_data.object_class = (*env)->FindClass (env, "java/lang/Object"); run_data.object_class = (*env)->FindClass (env, "java/lang/Object");
run_data.context_class = (*env)->FindClass (env, CLASS_CONTEXT); run_data.context_class = (*env)->FindClass (env, CLASS_CONTEXT);
run_data.argument_class = (*env)->FindClass (env, CLASS_ARGUMENT);
ASE_ASSERT (run_data.string_class != NULL); ASE_ASSERT (run_data.string_class != NULL);
ASE_ASSERT (run_data.integer_class != NULL); ASE_ASSERT (run_data.integer_class != NULL);
@ -702,6 +689,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jstring m
ASE_ASSERT (run_data.double_class != NULL); ASE_ASSERT (run_data.double_class != NULL);
ASE_ASSERT (run_data.object_class != NULL); ASE_ASSERT (run_data.object_class != NULL);
ASE_ASSERT (run_data.context_class != NULL); ASE_ASSERT (run_data.context_class != NULL);
ASE_ASSERT (run_data.argument_class != NULL);
run_data.integer_init = (*env)->GetMethodID ( run_data.integer_init = (*env)->GetMethodID (
env, run_data.integer_class, "<init>", "(I)V"); env, run_data.integer_class, "<init>", "(I)V");
@ -715,6 +703,8 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jstring m
env, run_data.double_class, "<init>", "(D)V"); env, run_data.double_class, "<init>", "(D)V");
run_data.context_init = (*env)->GetMethodID ( run_data.context_init = (*env)->GetMethodID (
env, run_data.context_class, "<init>", "(Lase/awk/Awk;)V"); env, run_data.context_class, "<init>", "(Lase/awk/Awk;)V");
run_data.argument_init = (*env)->GetMethodID (
env, run_data.argument_class, "<init>", "(JJ)V");
ASE_ASSERT (run_data.integer_init != NULL); ASE_ASSERT (run_data.integer_init != NULL);
ASE_ASSERT (run_data.long_init != NULL); ASE_ASSERT (run_data.long_init != NULL);
@ -722,6 +712,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jstring m
ASE_ASSERT (run_data.float_init != NULL); ASE_ASSERT (run_data.float_init != NULL);
ASE_ASSERT (run_data.double_init != NULL); ASE_ASSERT (run_data.double_init != NULL);
ASE_ASSERT (run_data.context_init != NULL); ASE_ASSERT (run_data.context_init != NULL);
ASE_ASSERT (run_data.argument_init != NULL);
run_data.integer_value = (*env)->GetMethodID ( run_data.integer_value = (*env)->GetMethodID (
env, run_data.integer_class, "intValue", "()I"); env, run_data.integer_class, "intValue", "()I");
@ -955,25 +946,11 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jstring m
DELETE_CLASS_REFS (env, run_data); DELETE_CLASS_REFS (env, run_data);
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_stop (JNIEnv* env, jobject obj) JNIEXPORT void JNICALL Java_ase_awk_Awk_stop (JNIEnv* env, jobject obj, jlong awkid)
{ {
jclass class; ase_awk_t* awk = (ase_awk_t*)awkid;
jfieldID handle; EXCEPTION_ON_NULL_AWK (awk);
ase_awk_t* awk; ase_awk_stopall (awk);
class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
return;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
if (awk != NULL) ase_awk_stopall (awk);
} }
static ase_ssize_t java_open_source (JNIEnv* env, jobject obj, int mode) static ase_ssize_t java_open_source (JNIEnv* env, jobject obj, int mode)
@ -1718,6 +1695,11 @@ static int handle_bfn (
{ {
v = ase_awk_getarg (run, i); v = ase_awk_getarg (run, i);
arg = (*env)->NewObject (env,
run_data->argument_class,
run_data->argument_init, (jlong)run, (jlong)v);
#if 0
arg = NULL; arg = NULL;
if (v->type == ASE_AWK_VAL_INT) if (v->type == ASE_AWK_VAL_INT)
@ -1768,8 +1750,9 @@ static int handle_bfn (
env, (jchar*)((ase_awk_val_str_t*)v)->buf, len); env, (jchar*)((ase_awk_val_str_t*)v)->buf, len);
} }
} }
#endif
if (v->type != ASE_AWK_VAL_NIL && arg == NULL) if (/*v->type != ASE_AWK_VAL_NIL && */arg == NULL)
{ {
if ((*env)->ExceptionOccurred (env)) if ((*env)->ExceptionOccurred (env))
{ {
@ -2099,155 +2082,60 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_delfunc (
} }
} }
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth ( JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth (JNIEnv* env, jobject obj, jlong awkid, jint id)
JNIEnv* env, jobject obj, jint id)
{ {
jclass class; ase_awk_t* awk = (ase_awk_t*)awkid;
jfieldID handle; EXCEPTION_ON_NULL_AWK_RETURNING (awk, 0);
ase_awk_t* awk;
class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
(*env)->DeleteLocalRef (env, class);
if (handle == NULL) return 0; /* should never happen */
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
return (jint)ase_awk_getmaxdepth (awk, id); return (jint)ase_awk_getmaxdepth (awk, id);
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth (JNIEnv* env, jobject obj, jlong awkid, jint ids, jint depth)
JNIEnv* env, jobject obj, jint ids, jint depth)
{ {
jclass class; ase_awk_t* awk = (ase_awk_t*)awkid;
jfieldID handle; EXCEPTION_ON_NULL_AWK (awk);
ase_awk_t* awk;
class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
return;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
ase_awk_setmaxdepth (awk, ids, depth); ase_awk_setmaxdepth (awk, ids, depth);
} }
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption ( JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption (JNIEnv* env, jobject obj, jlong awkid)
JNIEnv* env, jobject obj)
{ {
jclass class; ase_awk_t* awk = (ase_awk_t*)awkid;
jfieldID handle; EXCEPTION_ON_NULL_AWK_RETURNING (awk, 0);
ase_awk_t* awk;
class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
return 0;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
return ase_awk_getoption (awk); return ase_awk_getoption (awk);
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption (JNIEnv* env, jobject obj, jlong awkid, jint options)
JNIEnv* env, jobject obj, jint options)
{ {
jclass class; ase_awk_t* awk = (ase_awk_t*)awkid;
jfieldID handle; EXCEPTION_ON_NULL_AWK (awk);
ase_awk_t* awk;
class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
return;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
ase_awk_setoption (awk, (int)options); ase_awk_setoption (awk, (int)options);
} }
JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug ( JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug (JNIEnv* env, jobject obj, jlong awkid)
JNIEnv* env, jobject obj)
{ {
jclass class; ase_awk_t* awk = (ase_awk_t*)awkid;
jfieldID handle; EXCEPTION_ON_NULL_AWK_RETURNING (awk, JNI_FALSE);
ase_awk_t* awk;
class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
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; return ((awk_data_t*)ase_awk_getcustomdata(awk))->debug? JNI_TRUE: JNI_FALSE;
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug (
JNIEnv* env, jobject obj, jboolean debug) JNIEnv* env, jobject obj, jlong awkid, jboolean debug)
{ {
jclass class; ase_awk_t* awk = (ase_awk_t*)awkid;
jfieldID handle; EXCEPTION_ON_NULL_AWK (awk);
ase_awk_t* awk;
class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
return;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
((awk_data_t*)ase_awk_getcustomdata(awk))->debug = debug; ((awk_data_t*)ase_awk_getcustomdata(awk))->debug = debug;
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_setword ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setword (
JNIEnv* env, jobject obj, jstring ow, jstring nw) JNIEnv* env, jobject obj, jlong awkid, jstring ow, jstring nw)
{ {
jclass class;
jfieldID handle;
ase_awk_t* awk; ase_awk_t* awk;
const jchar* op = NULL, * np = NULL; const jchar* op = NULL, * np = NULL;
jsize ol = 0, nl = 0; jsize ol = 0, nl = 0;
ase_char_t* ox, * nx; ase_char_t* ox, * nx;
jint r; jint r;
class = (*env)->GetObjectClass(env, obj); awk = (ase_awk_t*) awkid;
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J"); EXCEPTION_ON_NULL_AWK (awk);
(*env)->DeleteLocalRef (env, class);
if (handle == NULL)
{
/* internal error. no handle field
* NoSuchFieldError, ExceptionInitializerError,
* OutOfMemoryError might have occurred */
return;
}
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
if (ow != NULL) if (ow != NULL)
{ {
@ -2941,20 +2829,51 @@ JNIEXPORT jdouble JNICALL Java_ase_awk_Argument_getrealval (JNIEnv* env, jobject
JNIEXPORT jstring JNICALL Java_ase_awk_Argument_getstrval (JNIEnv* env, jobject obj, long runid, long valid) JNIEXPORT jstring JNICALL Java_ase_awk_Argument_getstrval (JNIEnv* env, jobject obj, long runid, long valid)
{ {
int n; ase_awk_run_t* run = (ase_awk_run_t*)runid;
ase_awk_val_t* val = (ase_awk_val_t*)valid;
ase_awk_t* awk = ase_awk_getrunawk (run);
ase_char_t* str; ase_char_t* str;
ase_size_t len; ase_size_t len;
jstring ret; jstring ret = NULL;
str = ase_awk_valtostr ( str = ase_awk_valtostr (
(ase_awk_run_t*)runid, (ase_awk_val_t*)valid, run, val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len);
ASE_AWK_VALTOSTR_CLEAR, ASE_NULL,&len); if (str == ASE_NULL) goto no_mem;
if (str == ASE_NULL) return ASE_NULL;
// TODO: convert string properly.... if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
ret = (*env)->NewString (env, (jchar*)str, len); {
ase_awk_free (ase_awk_getrunawk((ase_awk_run_t*)runid), str); jchar* tmp;
ase_size_t i;
tmp = (jchar*) ase_awk_malloc (awk, ASE_SIZEOF(jchar)*len);
if (tmp == NULL)
{
ase_awk_free (awk, str);
goto no_mem;
}
for (i = 0; i < len; i++) tmp[i] = (jchar)str[i];
ret = (*env)->NewString (env, tmp, len);
ase_awk_free (awk, tmp);
}
else
{
ret = (*env)->NewString (env, (jchar*)str, len);
}
ase_awk_free (awk, str);
if (ret == NULL)
{
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env);
no_mem:
throw_exception (
env,
ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
}
// TODO: clear exception if any...
return ret; return ret;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: jni.h,v 1.7 2007/10/17 14:38:28 bacon Exp $ * $Id: jni.h,v 1.8 2007/10/18 11:14:48 bacon Exp $
* *
* {License} * {License}
*/ */
@ -18,11 +18,11 @@ extern "C" {
#endif #endif
JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj); JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj); JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj); JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_run ( JNIEXPORT void JNICALL Java_ase_awk_Awk_run (
JNIEnv* env, jobject obj, jstring mfn, jobjectArray args); JNIEnv* env, jobject obj, jlong awkid, jstring mfn, jobjectArray args);
JNIEXPORT void JNICALL Java_ase_awk_Awk_stop (JNIEnv* env, jobject obj); JNIEXPORT void JNICALL Java_ase_awk_Awk_stop (JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_addfunc ( JNIEXPORT void JNICALL Java_ase_awk_Awk_addfunc (
JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args); JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args);
@ -30,22 +30,22 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_delfunc (
JNIEnv* env, jobject obj, jstring name); JNIEnv* env, jobject obj, jstring name);
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth ( JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth (
JNIEnv* env, jobject obj, jint id); JNIEnv* env, jobject obj, jlong awkid, jint id);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth (
JNIEnv* env, jobject obj, jint ids, jint depth); JNIEnv* env, jobject obj, jlong awkid, jint ids, jint depth);
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption ( JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption (
JNIEnv* env, jobject obj); JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption (
JNIEnv* env, jobject obj, jint options); JNIEnv* env, jobject obj, jlong awkid, jint options);
JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug ( JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug (
JNIEnv* env, jobject obj); JNIEnv* env, jobject obj, jlong awkid);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug (
JNIEnv* env, jobject obj, jboolean debug); JNIEnv* env, jobject obj, jlong awkid, jboolean debug);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setword ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setword (
JNIEnv* env, jobject obj, jstring ow, jstring nw); JNIEnv* env, jobject obj, jlong awkid, jstring ow, jstring nw);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename (
JNIEnv* env, jobject obj, jlong runid, jstring name); JNIEnv* env, jobject obj, jlong runid, jstring name);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: AseAwk.java,v 1.12 2007/10/15 16:10:10 bacon Exp $ * $Id: AseAwk.java,v 1.13 2007/10/18 14:51:04 bacon Exp $
*/ */
import java.awt.*; import java.awt.*;
@ -223,7 +223,8 @@ public class AseAwk extends StdAwk
String ow = arg.substring (0, idx); String ow = arg.substring (0, idx);
String nw = arg.substring (idx+1); String nw = arg.substring (idx+1);
awk.setWord (ow, nw); try { awk.setWord (ow, nw); }
catch (Exception e) {/* don't care */}
mode = 0; mode = 0;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: AseAwkPanel.java,v 1.4 2007/10/15 16:10:10 bacon Exp $ * $Id: AseAwkPanel.java,v 1.5 2007/10/18 14:51:04 bacon Exp $
*/ */
import java.awt.*; import java.awt.*;
@ -399,10 +399,16 @@ public class AseAwkPanel extends Panel
awk.parse (); awk.parse ();
awk.run (); awk.run ();
} }
catch (ase.awk.Exception e) catch (ase.awk.Exception e)
{ {
showMessage ("An exception occurred - " + e.getMessage()); int line = e.getLine();
if (line <= 0)
showMessage ("An exception occurred - " + e.getMessage());
else
showMessage ("An exception occurred - " + e.getMessage() + " at line " + line);
return; return;
} }
finally finally