*** empty log message ***

This commit is contained in:
hyung-hwan 2006-11-28 15:09:53 +00:00
parent 90e1c6e5e1
commit 7dfead7ac3
7 changed files with 177 additions and 153 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: StdAwk.java,v 1.6 2006-11-28 04:38:07 bacon Exp $ * $Id: StdAwk.java,v 1.7 2006-11-28 15:09:53 bacon Exp $
*/ */
package ase.awk; package ase.awk;
@ -23,14 +23,6 @@ public abstract class StdAwk extends Awk
public StdAwk () throws Exception public StdAwk () throws Exception
{ {
super (); super ();
addBuiltinFunction ("xxx", 1, 1);
}
public int xxx ()
{
System.out.println ("xxx....\n");
return 0;
} }
/* == major methods == */ /* == major methods == */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h,v 1.154 2006-11-28 04:30:21 bacon Exp $ * $Id: awk.h,v 1.155 2006-11-28 15:09:53 bacon Exp $
*/ */
#ifndef _ASE_AWK_AWK_H_ #ifndef _ASE_AWK_AWK_H_
@ -109,8 +109,10 @@ struct ase_awk_runios_t
struct ase_awk_runcbs_t struct ase_awk_runcbs_t
{ {
void (*on_start) (ase_awk_t* awk, void* handle, void* arg); void (*on_start) (
void (*on_end) (ase_awk_t* awk, void* handle, int errnum, void* arg); ase_awk_t* awk, void* handle, void* custom_data);
void (*on_end) (
ase_awk_t* awk, void* handle, int errnum, void* custom_data);
void* custom_data; void* custom_data;
}; };
@ -202,6 +204,7 @@ enum
ASE_AWK_ENOERR, /* no error */ ASE_AWK_ENOERR, /* no error */
ASE_AWK_ENOMEM, /* out of memory */ ASE_AWK_ENOMEM, /* out of memory */
ASE_AWK_EINVAL, /* invalid parameter */ ASE_AWK_EINVAL, /* invalid parameter */
ASE_AWK_EEXIST, /* existing data found */
ASE_AWK_ERUNTIME, /* run-time error */ ASE_AWK_ERUNTIME, /* run-time error */
ASE_AWK_ERUNNING, /* there are running instances */ ASE_AWK_ERUNNING, /* there are running instances */
ASE_AWK_ETOOMANYRUNS, /* too many running instances */ ASE_AWK_ETOOMANYRUNS, /* too many running instances */
@ -390,12 +393,10 @@ int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios);
* on_end handler of the callback is triggered with the relevant * on_end handler of the callback is triggered with the relevant
* error number. The third parameter to on_end denotes this error number. * error number. The third parameter to on_end denotes this error number.
*/ */
int ase_awk_run (ase_awk_t* awk, int ase_awk_run (
const ase_char_t* main, ase_awk_t* awk, const ase_char_t* main,
ase_awk_runios_t* runios, ase_awk_runios_t* runios, ase_awk_runcbs_t* runcbs,
ase_awk_runcbs_t* runcbs, ase_awk_runarg_t* runarg, void* custom_data);
ase_awk_runarg_t* runarg,
void* custom_data);
int ase_awk_stop (ase_awk_t* awk, ase_awk_run_t* run); int ase_awk_stop (ase_awk_t* awk, ase_awk_run_t* run);
void ase_awk_stopall (ase_awk_t* awk); void ase_awk_stopall (ase_awk_t* awk);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: err.c,v 1.52 2006-11-27 04:33:22 bacon Exp $ * $Id: err.c,v 1.53 2006-11-28 15:09:53 bacon Exp $
*/ */
#include <ase/awk/awk_i.h> #include <ase/awk/awk_i.h>
@ -16,6 +16,7 @@ const ase_char_t* ase_awk_geterrstr (int errnum)
ASE_T("no error"), ASE_T("no error"),
ASE_T("out of memory"), ASE_T("out of memory"),
ASE_T("invalid parameter"), ASE_T("invalid parameter"),
ASE_T("existing data found"),
ASE_T("general run-time error"), ASE_T("general run-time error"),
ASE_T("one or more running instances"), ASE_T("one or more running instances"),
ASE_T("too many running instances"), ASE_T("too many running instances"),

View File

@ -1,5 +1,5 @@
/* /*
* $Id: func.c,v 1.79 2006-11-28 04:30:21 bacon Exp $ * $Id: func.c,v 1.80 2006-11-28 15:09:53 bacon Exp $
*/ */
#include <ase/awk/awk_i.h> #include <ase/awk/awk_i.h>
@ -49,6 +49,12 @@ void* ase_awk_addbfn (
{ {
ase_awk_bfn_t* p; ase_awk_bfn_t* p;
if (ase_awk_getbfn (awk, name, name_len) != ASE_NULL)
{
awk->errnum = ASE_AWK_EEXIST;
return ASE_NULL;
}
p = (ase_awk_bfn_t*) ASE_AWK_MALLOC (awk, ase_sizeof(ase_awk_bfn_t)); p = (ase_awk_bfn_t*) ASE_AWK_MALLOC (awk, ase_sizeof(ase_awk_bfn_t));
if (p == ASE_NULL) if (p == ASE_NULL)
{ {

View File

@ -1,9 +1,9 @@
/* /*
* $Id: jni.c,v 1.29 2006-11-28 04:30:21 bacon Exp $ * $Id: jni.c,v 1.30 2006-11-28 15:09:53 bacon Exp $
*/ */
#include <ase/awk/jni.h> #include <ase/awk/jni.h>
#include <ase/awk/awk.h> #include <ase/awk/awk_i.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <wctype.h> #include <wctype.h>
@ -25,6 +25,8 @@
#define CLASS_EXTIO "ase/awk/Extio" #define CLASS_EXTIO "ase/awk/Extio"
#define FIELD_HANDLE "handle" #define FIELD_HANDLE "handle"
#define MSG_SIZE 256
enum enum
{ {
SOURCE_READ = 1, SOURCE_READ = 1,
@ -157,8 +159,6 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
ase_awk_syscas_t syscas; ase_awk_syscas_t syscas;
int opt; int opt;
class = (*env)->GetObjectClass(env, obj);
memset (&syscas, 0, sizeof(syscas)); memset (&syscas, 0, sizeof(syscas));
syscas.malloc = __awk_malloc; syscas.malloc = __awk_malloc;
syscas.realloc = __awk_realloc; syscas.realloc = __awk_realloc;
@ -189,21 +189,22 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
awk = ase_awk_open (&syscas); awk = ase_awk_open (&syscas);
if (awk == NULL) if (awk == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
except = (*env)->FindClass (env, CLASS_EXCEPTION); except = (*env)->FindClass (env, CLASS_EXCEPTION);
if (except == NULL) return; if (except == NULL) return;
(*env)->ThrowNew (env, except, "cannot create awk"); (*env)->ThrowNew (env, except, "cannot create awk");
(*env)->DeleteLocalRef (env, except); (*env)->DeleteLocalRef (env, except);
return; return;
} }
class = (*env)->GetObjectClass(env, obj);
fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
if (fid_handle == 0) (*env)->DeleteLocalRef (env, class);
if (fid_handle == NULL)
{ {
/* something wrong. should not happen */ except = (*env)->FindClass (env, CLASS_EXCEPTION);
(*env)->DeleteLocalRef (env, class); if (except == NULL) return;
(*env)->ThrowNew (env, except, "cannot find the handle field");
(*env)->DeleteLocalRef (env, except);
return; return;
} }
@ -214,9 +215,6 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_HASHSIGN | ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_HASHSIGN |
ASE_AWK_NEXTOFILE; ASE_AWK_NEXTOFILE;
ase_awk_setopt (awk, opt); ase_awk_setopt (awk, opt);
(*env)->DeleteLocalRef (env, class);
printf ("__awk(native) done => %u, 0x%X\n", awk, awk);
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj) JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj)
@ -225,37 +223,30 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj)
jfieldID fid_handle; jfieldID fid_handle;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
(*env)->DeleteLocalRef (env, class);
if (fid_handle == NULL) if (fid_handle == NULL)
{ {
/* something wrong. should not happen */ /* something wrong. should not happen */
(*env)->DeleteLocalRef (env, class); /* TODO: should it throw an exception??? */
return; return;
} }
ase_awk_close ((ase_awk_t*)(*env)->GetLongField (env, obj, fid_handle)); ase_awk_close ((ase_awk_t*)(*env)->GetLongField (env, obj, fid_handle));
(*env)->SetLongField (env, obj, fid_handle, (jlong)0); (*env)->SetLongField (env, obj, fid_handle, (jlong)0);
(*env)->DeleteLocalRef (env, class);
printf ("close (native) done\n");
} }
static jint __java_get_max_depth (JNIEnv* env, jobject obj, const char* name) static jint __java_get_max_depth (JNIEnv* env, jobject obj, const char* name)
{ {
jclass class; jclass class;
jmethodID mid; jmethodID mid;
jthrowable thrown; jthrowable thrown;
jint ret; jint ret;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, name, "()I"); mid = (*env)->GetMethodID (env, class, name, "()I");
if (mid == NULL) (*env)->DeleteLocalRef (env, class);
{ if (mid == NULL) return -1;
(*env)->DeleteLocalRef (env, class);
return -1;
}
ret = (*env)->CallIntMethod (env, obj, mid); ret = (*env)->CallIntMethod (env, obj, mid);
thrown = (*env)->ExceptionOccurred (env); thrown = (*env)->ExceptionOccurred (env);
@ -265,14 +256,13 @@ static jint __java_get_max_depth (JNIEnv* env, jobject obj, const char* name)
ret = -1; ret = -1;
} }
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj) JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj)
{ {
jclass class; jclass class;
jfieldID fid; jfieldID fid_handle;
jthrowable except; jthrowable except;
jint depth; jint depth;
@ -281,11 +271,18 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj)
srcio_data_t srcio_data; srcio_data_t srcio_data;
class = (*env)->GetObjectClass (env, obj); class = (*env)->GetObjectClass (env, obj);
fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
(*env)->DeleteLocalRef (env, class);
if (fid_handle == NULL)
{
except = (*env)->FindClass (env, CLASS_EXCEPTION);
if (except == NULL) return;
(*env)->ThrowNew (env, except, "cannot find the handle field");
(*env)->DeleteLocalRef (env, except);
return;
}
fid = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); awk = (ase_awk_t*) (*env)->GetLongField (env, obj, fid_handle);
if (fid == 0) return;
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, fid);
srcio_data.env = env; srcio_data.env = env;
srcio_data.obj = obj; srcio_data.obj = obj;
@ -301,13 +298,13 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj)
if (ase_awk_parse (awk, &srcios) == -1) if (ase_awk_parse (awk, &srcios) == -1)
{ {
char msg[256]; char msg[MSG_SIZE];
int n; int n;
except = (*env)->FindClass (env, CLASS_EXCEPTION); except = (*env)->FindClass (env, CLASS_EXCEPTION);
if (except == NULL) return; if (except == NULL) return;
snprintf (msg, sizeof(msg), "parse error at line %d: %S", n = snprintf (msg, sizeof(msg), "parse error at line %d: %S",
ase_awk_getsrcline(awk), ase_awk_getsrcline(awk),
ase_awk_geterrstr(ase_awk_geterrnum(awk))); ase_awk_geterrstr(ase_awk_geterrnum(awk)));
if (n < 0 || n >= sizeof(msg)) msg[sizeof(msg)-1] = '\0'; if (n < 0 || n >= sizeof(msg)) msg[sizeof(msg)-1] = '\0';
@ -330,11 +327,14 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
run_data_t run_data; run_data_t run_data;
class = (*env)->GetObjectClass (env, obj); class = (*env)->GetObjectClass (env, obj);
fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
(*env)->DeleteLocalRef (env, class);
if (fid_handle == 0) if (fid_handle == 0)
{ {
(*env)->DeleteLocalRef (env, class); except = (*env)->FindClass (env, CLASS_EXCEPTION);
if (except == NULL) return;
(*env)->ThrowNew (env, except, "cannot find the handle field");
(*env)->DeleteLocalRef (env, except);
return; return;
} }
@ -352,12 +352,14 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
runios.console = __process_extio; runios.console = __process_extio;
runios.custom_data = &runio_data; runios.custom_data = &runio_data;
// TODO:
//depth = __java_get_max_depth (env, obj, "getMaxRunDepth"); //depth = __java_get_max_depth (env, obj, "getMaxRunDepth");
// setMaxRunDepth...
if (ase_awk_run (awk, if (ase_awk_run (awk,
ASE_NULL, &runios, ASE_NULL, ASE_NULL, &run_data) == -1) ASE_NULL, &runios, ASE_NULL, ASE_NULL, &run_data) == -1)
{ {
char msg[256]; char msg[MSG_SIZE];
int n; int n;
(*env)->DeleteLocalRef (env, class); (*env)->DeleteLocalRef (env, class);
@ -365,9 +367,10 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
except = (*env)->FindClass (env, CLASS_EXCEPTION); except = (*env)->FindClass (env, CLASS_EXCEPTION);
if (except == NULL) return; /* exception thrown */ if (except == NULL) return; /* exception thrown */
snprintf (msg, sizeof(msg), "%S", n = snprintf (msg, sizeof(msg), "%S",
ase_awk_geterrstr(ase_awk_geterrnum(awk))); ase_awk_geterrstr(ase_awk_geterrnum(awk)));
if (n < 0 || n >= sizeof(msg)) msg[sizeof(msg)-1] = '\0'; if (n < 0 || n >= sizeof(msg)) msg[sizeof(msg)-1] = '\0';
(*env)->ThrowNew (env, except, msg); (*env)->ThrowNew (env, except, msg);
(*env)->DeleteLocalRef (env, except); (*env)->DeleteLocalRef (env, except);
return; return;
@ -384,11 +387,10 @@ static ase_ssize_t __java_open_source (JNIEnv* env, jobject obj, int mode)
jint ret; jint ret;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, "openSource", "(I)I"); mid = (*env)->GetMethodID (env, class, "openSource", "(I)I");
(*env)->DeleteLocalRef (env, class);
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -400,7 +402,6 @@ static ase_ssize_t __java_open_source (JNIEnv* env, jobject obj, int mode)
ret = -1; ret = -1;
} }
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
@ -412,11 +413,10 @@ static ase_ssize_t __java_close_source (JNIEnv* env, jobject obj, int mode)
jint ret; jint ret;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, "closeSource", "(I)I"); mid = (*env)->GetMethodID (env, class, "closeSource", "(I)I");
(*env)->DeleteLocalRef (env, class);
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -428,7 +428,6 @@ static ase_ssize_t __java_close_source (JNIEnv* env, jobject obj, int mode)
ret = -1; ret = -1;
} }
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
@ -443,18 +442,16 @@ static ase_ssize_t __java_read_source (
jthrowable thrown; jthrowable thrown;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, "readSource", "([CI)I"); mid = (*env)->GetMethodID (env, class, "readSource", "([CI)I");
(*env)->DeleteLocalRef (env, class);
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
array = (*env)->NewCharArray (env, size); array = (*env)->NewCharArray (env, size);
if (array == NULL) if (array == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -471,7 +468,6 @@ static ase_ssize_t __java_read_source (
(*env)->ReleaseCharArrayElements (env, array, tmp, 0); (*env)->ReleaseCharArrayElements (env, array, tmp, 0);
(*env)->DeleteLocalRef (env, array); (*env)->DeleteLocalRef (env, array);
(*env)->DeleteLocalRef (env, class);
return i; return i;
} }
@ -486,18 +482,16 @@ static ase_ssize_t __java_write_source (
jthrowable thrown; jthrowable thrown;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, "writeSource", "([CI)I"); mid = (*env)->GetMethodID (env, class, "writeSource", "([CI)I");
(*env)->DeleteLocalRef (env, class);
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
array = (*env)->NewCharArray (env, size); array = (*env)->NewCharArray (env, size);
if (array == NULL) if (array == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -515,7 +509,6 @@ static ase_ssize_t __java_write_source (
} }
(*env)->DeleteLocalRef (env, array); (*env)->DeleteLocalRef (env, array);
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
@ -531,12 +524,9 @@ static ase_ssize_t __java_open_extio (
jstring extio_name; jstring extio_name;
jint ret; jint ret;
class = (*env)->GetObjectClass(env, obj);
extio_class = (*env)->FindClass (env, CLASS_EXTIO); extio_class = (*env)->FindClass (env, CLASS_EXTIO);
if (extio_class == NULL) if (extio_class == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -546,16 +536,16 @@ static ase_ssize_t __java_open_extio (
if (extio_cons == NULL) if (extio_cons == NULL)
{ {
(*env)->DeleteLocalRef (env, extio_class); (*env)->DeleteLocalRef (env, extio_class);
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
/* get the method - meth */ /* get the method - meth */
class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I");
(*env)->DeleteLocalRef (env, class);
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, extio_class); (*env)->DeleteLocalRef (env, extio_class);
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -565,7 +555,6 @@ static ase_ssize_t __java_open_extio (
if (extio_name == NULL) if (extio_name == NULL)
{ {
(*env)->DeleteLocalRef (env, extio_class); (*env)->DeleteLocalRef (env, extio_class);
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -573,14 +562,15 @@ static ase_ssize_t __java_open_extio (
extio_object = (*env)->NewObject ( extio_object = (*env)->NewObject (
env, extio_class, extio_cons, env, extio_class, extio_cons,
extio_name, extio->type & 0xFF, extio->mode, extio->run); extio_name, extio->type & 0xFF, extio->mode, extio->run);
(*env)->DeleteLocalRef (env, extio_class);
if (extio_object == NULL) if (extio_object == NULL)
{ {
(*env)->DeleteLocalRef (env, extio_name); (*env)->DeleteLocalRef (env, extio_name);
(*env)->DeleteLocalRef (env, extio_class);
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
(*env)->DeleteLocalRef (env, extio_name);
/* execute the method */ /* execute the method */
ret = (*env)->CallIntMethod (env, obj, mid, extio_object); ret = (*env)->CallIntMethod (env, obj, mid, extio_object);
thrown = (*env)->ExceptionOccurred (env); thrown = (*env)->ExceptionOccurred (env);
@ -588,7 +578,7 @@ static ase_ssize_t __java_open_extio (
{ {
(*env)->ExceptionDescribe (env); (*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env); (*env)->ExceptionClear (env);
return -1; ret = -1;
} }
if (ret != -1) if (ret != -1)
@ -600,9 +590,6 @@ static ase_ssize_t __java_open_extio (
} }
(*env)->DeleteLocalRef (env, extio_object); (*env)->DeleteLocalRef (env, extio_object);
(*env)->DeleteLocalRef (env, extio_name);
(*env)->DeleteLocalRef (env, extio_class);
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
@ -615,12 +602,10 @@ static ase_ssize_t __java_close_extio (
jint ret; jint ret;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I");
mid = (*env)->GetMethodID ( (*env)->DeleteLocalRef (env, class);
env, class, meth, "(Lase/awk/Extio;)I");
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -641,7 +626,6 @@ static ase_ssize_t __java_close_extio (
extio->handle = NULL; extio->handle = NULL;
} }
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
@ -657,18 +641,16 @@ static ase_ssize_t __java_read_extio (
jthrowable thrown; jthrowable thrown;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I"); mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I");
(*env)->DeleteLocalRef (env, class);
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
array = (*env)->NewCharArray (env, size); array = (*env)->NewCharArray (env, size);
if (array == NULL) if (array == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -688,7 +670,6 @@ static ase_ssize_t __java_read_extio (
} }
(*env)->DeleteLocalRef (env, array); (*env)->DeleteLocalRef (env, array);
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
@ -705,18 +686,16 @@ static ase_ssize_t __java_write_extio (
jthrowable thrown; jthrowable thrown;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I"); mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I");
(*env)->DeleteLocalRef (env, class);
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
array = (*env)->NewCharArray (env, size); array = (*env)->NewCharArray (env, size);
if (array == NULL) if (array == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -733,7 +712,6 @@ static ase_ssize_t __java_write_extio (
} }
(*env)->DeleteLocalRef (env, array); (*env)->DeleteLocalRef (env, array);
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
@ -747,12 +725,10 @@ static ase_ssize_t __java_flush_extio (
jint ret; jint ret;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I");
mid = (*env)->GetMethodID ( (*env)->DeleteLocalRef (env, class);
env, class, meth, "(Lase/awk/Extio;)I");
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -765,7 +741,6 @@ static ase_ssize_t __java_flush_extio (
ret = -1; ret = -1;
} }
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
@ -778,12 +753,10 @@ static ase_ssize_t __java_next_extio (
jint ret; jint ret;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I");
mid = (*env)->GetMethodID ( (*env)->DeleteLocalRef (env, class);
env, class, meth, "(Lase/awk/Extio;)I");
if (mid == NULL) if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class);
return -1; return -1;
} }
@ -796,7 +769,6 @@ static ase_ssize_t __java_next_extio (
ret = -1; ret = -1;
} }
(*env)->DeleteLocalRef (env, class);
return ret; return ret;
} }
@ -926,66 +898,107 @@ static int __handle_bfn (
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
{ {
jclass class; jclass class;
jmethodID mid; jmethodID method;
jstring name;
jthrowable thrown; jthrowable thrown;
char* buf; jstring name;
ase_awk_t* awk; const char* name_utf;
run_data_t* run_data; run_data_t* run_data;
JNIEnv* env; JNIEnv* env;
jobject obj; jobject obj;
jint ret, i, nargs;
jobjectArray args;
jobject arg;
ase_awk_val_t* v;
awk = ase_awk_getrunawk (run);
run_data = ase_awk_getruncustomdata (run); run_data = ase_awk_getruncustomdata (run);
nargs = ase_awk_getnargs (run);
env = run_data->env; env = run_data->env;
obj = run_data->obj; obj = run_data->obj;
buf = ase_awk_malloc (awk, fnl * 5);
if (buf == NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1;
}
name = (*env)->NewString (env, fnm, fnl); name = (*env)->NewString (env, fnm, fnl);
if (name == NULL) if (name == NULL)
{ {
ase_awk_free (awk, buf); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1;
}
name_utf = (*env)->GetStringUTFChars (env, name, JNI_FALSE);
if (name_utf == NULL)
{
(*env)->DeleteLocalRef (env, name);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1; return -1;
} }
(*env)->GetStringUTFRegion (env, name, 0, fnl, buf); class = (*env)->GetObjectClass(env, obj);
thrown = (*env)->ExceptionOccurred (env); method = (*env)->GetMethodID (
if (thrown) env, class, name_utf,
"([Ljava/lang/Object;)Ljava/lang/Object;");
(*env)->DeleteLocalRef (env, class);
(*env)->ReleaseStringUTFChars (env, name, name_utf);
(*env)->DeleteLocalRef (env, name);
if (method == NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOSUCHFN);
return -1;
}
class = (*env)->FindClass (env, "java/lang/Object");
if (class == NULL)
{ {
(*env)->ExceptionClear (env);
ase_awk_free (awk, buf);
ase_awk_setrunerrnum (run, ASE_AWK_EINTERNAL); ase_awk_setrunerrnum (run, ASE_AWK_EINTERNAL);
return -1; return -1;
} }
(*env)->DeleteLocalRef (env, name); args = (*env)->NewObjectArray (env, nargs, class, NULL);
(*env)->DeleteLocalRef (env, class);
class = (*env)->GetObjectClass(env, obj); if (args == NULL)
mid = (*env)->GetMethodID (env, class, buf, "()I");
if (mid == NULL)
{ {
(*env)->DeleteLocalRef (env, class); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1; return -1;
} }
/* /* A LOT OF TODO's HERE */
CreateObjectArray... for (i = 0; i < nargs; i++)
Call the method with this array. {
Delete the array... v = ase_awk_getarg (run, i);
*/
/* if (v->type == ASE_AWK_VAL_NIL)
(*env)->DeleteLocalRef (env, class); {
*/
return 0; }
else if (v->type == ASE_AWK_VAL_INT)
{
}
else if (v->type == ASE_AWK_VAL_REAL)
{
}
else if (v->type == ASE_AWK_VAL_STR)
{
arg = (*env)->NewString (env,
((ase_awk_val_str_t*)v)->buf,
((ase_awk_val_str_t*)v)->len);
}
else
{
/* something wrong ... */
}
(*env)->SetObjectArrayElement (env, args, i, arg);
}
ret = (*env)->CallObjectMethod (env, obj, method, args);
thrown = (*env)->ExceptionOccurred (env);
if (thrown)
{
(*env)->ExceptionClear (env);
(*env)->DeleteLocalRef (env, args);
ase_awk_setrunerrnum (run, ASE_AWK_EINTERNAL);
return -1;
}
(*env)->DeleteLocalRef (env, args);
return ret;
} }
JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn ( JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (
@ -1016,13 +1029,20 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (
if (ase_awk_addbfn (awk, str, len, 0, if (ase_awk_addbfn (awk, str, len, 0,
min_args, max_args, ASE_NULL, __handle_bfn) == ASE_NULL) min_args, max_args, ASE_NULL, __handle_bfn) == ASE_NULL)
{ {
char msg[MSG_SIZE];
int n;
(*env)->ReleaseStringChars (env, name, str); (*env)->ReleaseStringChars (env, name, str);
(*env)->DeleteLocalRef (env, class); (*env)->DeleteLocalRef (env, class);
except = (*env)->FindClass (env, CLASS_EXCEPTION); except = (*env)->FindClass (env, CLASS_EXCEPTION);
if (except == NULL) return; if (except == NULL) return;
(*env)->ThrowNew (env, except, "cannot add the function"); /* TODO: more intuitive message */
n = snprintf (msg, sizeof(msg), "cannot add the function");
if (n < 0 || n >= sizeof(msg)) msg[sizeof(msg)-1] = '\0';
(*env)->ThrowNew (env, except, msg);
(*env)->DeleteLocalRef (env, except); (*env)->DeleteLocalRef (env, except);
return; return;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.java,v 1.14 2006-11-28 04:30:57 bacon Exp $ * $Id: Awk.java,v 1.15 2006-11-28 15:09:03 bacon Exp $
*/ */
package ase.test.awk; package ase.test.awk;
@ -16,13 +16,21 @@ public class Awk extends ase.awk.StdAwk
{ {
super (); super ();
addBuiltinFunction ("sin", 1, 1); try { addBuiltinFunction ("sin", 1, 1); }
catch (ase.awk.Exception e) { System.out.println (">>>>>> CANNOT ADD sin"); }
try { addBuiltinFunction ("xxx", 1, 1); }
catch (ase.awk.Exception e) { System.out.println (">>>>>> CANNOT ADD xxx"); }
} }
public int sin () public Object xxx (Object[] args)
{ {
System.out.println ("BFN_SIN...."); System.out.println ("BFN_XXX");
return 0; return null;
}
public Object sin (Object[] args)
{
System.out.println ("BFN_SIN: " + (String)args[0]);
return args[0];
} }
protected String[] getInputConsoleNames () protected String[] getInputConsoleNames ()

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.130 2006-11-28 04:38:07 bacon Exp $ * $Id: awk.c,v 1.131 2006-11-28 15:09:03 bacon Exp $
*/ */
#include <ase/awk/awk.h> #include <ase/awk/awk.h>
@ -8,6 +8,7 @@
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
#include <math.h> #include <math.h>
#include <assert.h>
#ifdef ASE_CHAR_IS_WCHAR #ifdef ASE_CHAR_IS_WCHAR
#include <wchar.h> #include <wchar.h>
@ -17,26 +18,21 @@
#if defined(_WIN32) #if defined(_WIN32)
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
#include <assert.h>
#define xp_printf _tprintf #define xp_printf _tprintf
#define xp_assert assert
#pragma warning (disable: 4996) #pragma warning (disable: 4996)
#pragma warning (disable: 4296)
#elif defined(__MSDOS__) #elif defined(__MSDOS__)
#include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#define xp_printf printf #define xp_printf printf
#define xp_assert assert
#else #else
#include <xp/bas/stdio.h> #include <xp/bas/stdio.h>
#include <xp/bas/stdlib.h> #include <xp/bas/stdlib.h>
#include <xp/bas/string.h> #include <xp/bas/string.h>
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
#include <xp/bas/sysapi.h> #include <xp/bas/sysapi.h>
#include <xp/bas/assert.h>
#include <xp/bas/locale.h> #include <xp/bas/locale.h>
#endif #endif
@ -507,7 +503,7 @@ static int open_extio_console (ase_awk_extio_t* epa)
/* TODO: OpenConsole in GUI APPLICATION */ /* TODO: OpenConsole in GUI APPLICATION */
/* epa->name is always empty for console */ /* epa->name is always empty for console */
xp_assert (epa->name[0] == ASE_T('\0')); assert (epa->name[0] == ASE_T('\0'));
__awk_dprintf (ASE_T("opening console[%s] of type %x\n"), epa->name, epa->type); __awk_dprintf (ASE_T("opening console[%s] of type %x\n"), epa->name, epa->type);