*** empty log message ***
This commit is contained in:
parent
e7d6a32428
commit
cae441539b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.java,v 1.13 2006-11-27 15:10:34 bacon Exp $
|
* $Id: Awk.java,v 1.14 2006-11-29 14:52:06 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ase.awk;
|
package ase.awk;
|
||||||
@ -45,8 +45,8 @@ public abstract class Awk
|
|||||||
public native void parse () throws Exception;
|
public native void parse () throws Exception;
|
||||||
public native void run () throws Exception;
|
public native void run () throws Exception;
|
||||||
|
|
||||||
private native void addbfn (String name, int min_args, int max_args);
|
private native int addbfn (String name, int min_args, int max_args);
|
||||||
//private native int delbfn (String name);
|
private native int delbfn (String name);
|
||||||
|
|
||||||
private native int setfilename (long run_id, String name);
|
private native int setfilename (long run_id, String name);
|
||||||
private native int setofilename (long run_id, String name);
|
private native int setofilename (long run_id, String name);
|
||||||
@ -55,7 +55,20 @@ public abstract class Awk
|
|||||||
public void addBuiltinFunction (
|
public void addBuiltinFunction (
|
||||||
String name, int min_args, int max_args) throws Exception
|
String name, int min_args, int max_args) throws Exception
|
||||||
{
|
{
|
||||||
addbfn (name, min_args, max_args);
|
if (addbfn (name, min_args, max_args) == -1)
|
||||||
|
{
|
||||||
|
throw new Exception (
|
||||||
|
"cannot add the built-in function - " + name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteBuiltinFunction (String name) throws Exception
|
||||||
|
{
|
||||||
|
if (delbfn (name) == -1)
|
||||||
|
{
|
||||||
|
throw new Exception (
|
||||||
|
"cannot delete the built-in function - " + name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* == console name setters == */
|
/* == console name setters == */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h,v 1.156 2006-11-29 02:39:09 bacon Exp $
|
* $Id: awk.h,v 1.157 2006-11-29 14:52:06 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ASE_AWK_AWK_H_
|
#ifndef _ASE_AWK_AWK_H_
|
||||||
@ -205,6 +205,7 @@ enum
|
|||||||
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_EEXIST, /* existing data found */
|
||||||
|
ASE_AWK_ENOENT, /* no such data entry 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 */
|
||||||
@ -293,7 +294,8 @@ enum
|
|||||||
ASE_AWK_EPIPE, /* pipe operation error */
|
ASE_AWK_EPIPE, /* pipe operation error */
|
||||||
ASE_AWK_ENEXTCALL, /* next called from BEGIN or END */
|
ASE_AWK_ENEXTCALL, /* next called from BEGIN or END */
|
||||||
ASE_AWK_ENEXTFILECALL, /* nextfile called from BEGIN or END */
|
ASE_AWK_ENEXTFILECALL, /* nextfile called from BEGIN or END */
|
||||||
ASE_AWK_EIOIMPL, /* wrong implementation of user io handler */
|
ASE_AWK_EIOIMPL, /* wrong user io handler implementation */
|
||||||
|
ASE_AWK_EBFNIMPL, /* wrong builtin function implementation */
|
||||||
ASE_AWK_ENOSUCHIO, /* no such io name found */
|
ASE_AWK_ENOSUCHIO, /* no such io name found */
|
||||||
ASE_AWK_EIOHANDLER, /* io handler has returned an error */
|
ASE_AWK_EIOHANDLER, /* io handler has returned an error */
|
||||||
ASE_AWK_EFMTARG, /* arguments to format string not sufficient */
|
ASE_AWK_EFMTARG, /* arguments to format string not sufficient */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: err.c,v 1.55 2006-11-29 02:54:15 bacon Exp $
|
* $Id: err.c,v 1.56 2006-11-29 14:52:06 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ase/awk/awk_i.h>
|
#include <ase/awk/awk_i.h>
|
||||||
@ -17,6 +17,7 @@ const ase_char_t* ase_awk_geterrstr (int errnum)
|
|||||||
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("existing data found"),
|
||||||
|
ASE_T("no such data entry 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"),
|
||||||
@ -105,6 +106,7 @@ const ase_char_t* ase_awk_geterrstr (int errnum)
|
|||||||
ASE_T("next cannot be called from the BEGIN or END block"),
|
ASE_T("next cannot be called from the BEGIN or END block"),
|
||||||
ASE_T("nextfile cannot be called from the BEGIN or END block"),
|
ASE_T("nextfile cannot be called from the BEGIN or END block"),
|
||||||
ASE_T("wrong implementation of user-defined io handler"),
|
ASE_T("wrong implementation of user-defined io handler"),
|
||||||
|
ASE_T("wrong implementation of built-in function handler"),
|
||||||
ASE_T("no such io name found"),
|
ASE_T("no such io name found"),
|
||||||
ASE_T("io handler has returned an error"),
|
ASE_T("io handler has returned an error"),
|
||||||
ASE_T("not sufficient arguments to formatting sequence"),
|
ASE_T("not sufficient arguments to formatting sequence"),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: func.c,v 1.83 2006-11-29 03:18:18 bacon Exp $
|
* $Id: func.c,v 1.84 2006-11-29 14:52:06 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ase/awk/awk_i.h>
|
#include <ase/awk/awk_i.h>
|
||||||
@ -69,6 +69,7 @@ void* ase_awk_addbfn (
|
|||||||
awk->errnum = ASE_AWK_ENOMEM;
|
awk->errnum = ASE_AWK_ENOMEM;
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
p->name.len = name_len;
|
p->name.len = name_len;
|
||||||
p->valid = when_valid;
|
p->valid = when_valid;
|
||||||
p->arg.min = min_args;
|
p->arg.min = min_args;
|
||||||
@ -97,7 +98,7 @@ int ase_awk_delbfn (ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len)
|
|||||||
{
|
{
|
||||||
ase_awk_bfn_t* p, * pp = ASE_NULL;
|
ase_awk_bfn_t* p, * pp = ASE_NULL;
|
||||||
|
|
||||||
for (p = awk->bfn.user; p != ASE_NULL; p++)
|
for (p = awk->bfn.user; p != ASE_NULL; p = p->next)
|
||||||
{
|
{
|
||||||
if (ase_awk_strxncmp (
|
if (ase_awk_strxncmp (
|
||||||
p->name.ptr, p->name.len, name, name_len) == 0)
|
p->name.ptr, p->name.len, name, name_len) == 0)
|
||||||
@ -116,6 +117,7 @@ int ase_awk_delbfn (ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len)
|
|||||||
pp = p;
|
pp = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
awk->errnum = ASE_AWK_ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
311
ase/awk/jni.c
311
ase/awk/jni.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: jni.c,v 1.33 2006-11-29 11:41:14 bacon Exp $
|
* $Id: jni.c,v 1.34 2006-11-29 14:52:06 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ase/awk/jni.h>
|
#include <ase/awk/jni.h>
|
||||||
@ -67,8 +67,23 @@ struct run_data_t
|
|||||||
|
|
||||||
jclass string_class;
|
jclass string_class;
|
||||||
jclass integer_class;
|
jclass integer_class;
|
||||||
|
jclass long_class;
|
||||||
|
jclass short_class;
|
||||||
|
jclass float_class;
|
||||||
jclass double_class;
|
jclass double_class;
|
||||||
jclass object_class;
|
jclass object_class;
|
||||||
|
|
||||||
|
jmethodID integer_init;
|
||||||
|
jmethodID long_init;
|
||||||
|
jmethodID short_init;
|
||||||
|
jmethodID float_init;
|
||||||
|
jmethodID double_init;
|
||||||
|
|
||||||
|
jmethodID integer_value;
|
||||||
|
jmethodID long_value;
|
||||||
|
jmethodID short_value;
|
||||||
|
jmethodID float_value;
|
||||||
|
jmethodID double_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void* __awk_malloc (ase_size_t n, void* custom_data)
|
static void* __awk_malloc (ase_size_t n, void* custom_data)
|
||||||
@ -355,14 +370,59 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
|
|||||||
/* would global reference be necessary? */
|
/* would global reference be necessary? */
|
||||||
run_data.string_class = (*env)->FindClass (env, "java/lang/String");
|
run_data.string_class = (*env)->FindClass (env, "java/lang/String");
|
||||||
run_data.integer_class = (*env)->FindClass (env, "java/lang/Integer");
|
run_data.integer_class = (*env)->FindClass (env, "java/lang/Integer");
|
||||||
|
run_data.long_class = (*env)->FindClass (env, "java/lang/Long");
|
||||||
|
run_data.short_class = (*env)->FindClass (env, "java/lang/Short");
|
||||||
|
run_data.float_class = (*env)->FindClass (env, "java/lang/Float");
|
||||||
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");
|
||||||
|
|
||||||
ASE_AWK_ASSERT (awk, run_data.string_class != NULL);
|
ASE_AWK_ASSERT (awk, run_data.string_class != NULL);
|
||||||
ASE_AWK_ASSERT (awk, run_data.integer_class != NULL);
|
ASE_AWK_ASSERT (awk, run_data.integer_class != NULL);
|
||||||
|
ASE_AWK_ASSERT (awk, run_data.short_class != NULL);
|
||||||
|
ASE_AWK_ASSERT (awk, run_data.long_class != NULL);
|
||||||
|
ASE_AWK_ASSERT (awk, run_data.float_class != NULL);
|
||||||
ASE_AWK_ASSERT (awk, run_data.double_class != NULL);
|
ASE_AWK_ASSERT (awk, run_data.double_class != NULL);
|
||||||
ASE_AWK_ASSERT (awk, run_data.object_class != NULL);
|
ASE_AWK_ASSERT (awk, run_data.object_class != NULL);
|
||||||
|
|
||||||
|
run_data.integer_init = (*env)->GetMethodID (
|
||||||
|
env, run_data.integer_class, "<init>", "(I)V");
|
||||||
|
run_data.long_init = (*env)->GetMethodID (
|
||||||
|
env, run_data.long_class, "<init>", "(J)V");
|
||||||
|
run_data.short_init = (*env)->GetMethodID (
|
||||||
|
env, run_data.short_class, "<init>", "(S)V");
|
||||||
|
run_data.float_init = (*env)->GetMethodID (
|
||||||
|
env, run_data.float_class, "<init>", "(F)V");
|
||||||
|
run_data.double_init = (*env)->GetMethodID (
|
||||||
|
env, run_data.double_class, "<init>", "(D)V");
|
||||||
|
|
||||||
|
ASE_AWK_ASSERT (awk, run_data.integer_init != NULL);
|
||||||
|
ASE_AWK_ASSERT (awk, run_data.long_init != NULL);
|
||||||
|
ASE_AWK_ASSERT (awk, run_data.short_init != NULL);
|
||||||
|
ASE_AWK_ASSERT (awk, run_data.float_init != NULL);
|
||||||
|
ASE_AWK_ASSERT (awk, run_data.double_init != NULL);
|
||||||
|
|
||||||
|
run_data.integer_value = (*env)->GetMethodID (
|
||||||
|
env, run_data.integer_class, "intValue", "()I");
|
||||||
|
run_data.long_value = (*env)->GetMethodID (
|
||||||
|
env, run_data.long_class, "longValue", "()J");
|
||||||
|
run_data.short_value = (*env)->GetMethodID (
|
||||||
|
env, run_data.short_class, "shortValue", "()S");
|
||||||
|
run_data.float_value = (*env)->GetMethodID (
|
||||||
|
env, run_data.float_class, "floatValue", "()F");
|
||||||
|
run_data.double_value = (*env)->GetMethodID (
|
||||||
|
env, run_data.double_class, "doubleValue", "()D");
|
||||||
|
|
||||||
|
ASE_AWK_ASSERTX (awk, run_data.integer_value != NULL,
|
||||||
|
"The Integer class must has the method - int intValue()");
|
||||||
|
ASE_AWK_ASSERTX (awk, run_data.long_value != NULL,
|
||||||
|
"The Long class must has the method - long longValue()");
|
||||||
|
ASE_AWK_ASSERTX (awk, run_data.short_value != NULL,
|
||||||
|
"The Short class must has the method - short shortValue()");
|
||||||
|
ASE_AWK_ASSERTX (awk, run_data.float_value != NULL,
|
||||||
|
"The Float class must has the method - float floatValue()");
|
||||||
|
ASE_AWK_ASSERTX (awk, run_data.double_value != NULL,
|
||||||
|
"The Double class must has the method - double doubleValue()");
|
||||||
|
|
||||||
runio_data.env = env;
|
runio_data.env = env;
|
||||||
runio_data.obj = obj;
|
runio_data.obj = obj;
|
||||||
|
|
||||||
@ -393,6 +453,8 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
|
|||||||
(*env)->DeleteLocalRef (env, except);
|
(*env)->DeleteLocalRef (env, except);
|
||||||
|
|
||||||
(*env)->DeleteLocalRef (env, run_data.integer_class);
|
(*env)->DeleteLocalRef (env, run_data.integer_class);
|
||||||
|
(*env)->DeleteLocalRef (env, run_data.long_class);
|
||||||
|
(*env)->DeleteLocalRef (env, run_data.float_class);
|
||||||
(*env)->DeleteLocalRef (env, run_data.double_class);
|
(*env)->DeleteLocalRef (env, run_data.double_class);
|
||||||
(*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);
|
||||||
@ -400,6 +462,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
(*env)->DeleteLocalRef (env, run_data.integer_class);
|
(*env)->DeleteLocalRef (env, run_data.integer_class);
|
||||||
|
(*env)->DeleteLocalRef (env, run_data.long_class);
|
||||||
|
(*env)->DeleteLocalRef (env, run_data.short_class);
|
||||||
|
(*env)->DeleteLocalRef (env, run_data.float_class);
|
||||||
(*env)->DeleteLocalRef (env, run_data.double_class);
|
(*env)->DeleteLocalRef (env, run_data.double_class);
|
||||||
(*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);
|
||||||
@ -551,10 +616,7 @@ static ase_ssize_t __java_open_extio (
|
|||||||
jint ret;
|
jint ret;
|
||||||
|
|
||||||
extio_class = (*env)->FindClass (env, CLASS_EXTIO);
|
extio_class = (*env)->FindClass (env, CLASS_EXTIO);
|
||||||
if (extio_class == NULL)
|
if (extio_class == NULL) return -1;
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the constructor */
|
/* get the constructor */
|
||||||
extio_cons = (*env)->GetMethodID (
|
extio_cons = (*env)->GetMethodID (
|
||||||
@ -903,7 +965,7 @@ 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 method, init;
|
jmethodID method;
|
||||||
jthrowable thrown;
|
jthrowable thrown;
|
||||||
jstring name;
|
jstring name;
|
||||||
const char* name_utf;
|
const char* name_utf;
|
||||||
@ -913,11 +975,8 @@ static int __handle_bfn (
|
|||||||
jint i, nargs;
|
jint i, nargs;
|
||||||
jobjectArray args;
|
jobjectArray args;
|
||||||
jobject arg, ret;
|
jobject arg, ret;
|
||||||
|
|
||||||
ase_awk_t* awk;
|
|
||||||
ase_awk_val_t* v;
|
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);
|
nargs = ase_awk_getnargs (run);
|
||||||
|
|
||||||
@ -947,7 +1006,11 @@ static int __handle_bfn (
|
|||||||
(*env)->DeleteLocalRef (env, name);
|
(*env)->DeleteLocalRef (env, name);
|
||||||
if (method == NULL)
|
if (method == NULL)
|
||||||
{
|
{
|
||||||
ase_awk_setrunerrnum (run, ASE_AWK_ENOSUCHFN);
|
/* if the method is not found, the exception is thrown.
|
||||||
|
* so clear it to prevent it from being thrown */
|
||||||
|
if ((*env)->ExceptionOccurred (env))
|
||||||
|
(*env)->ExceptionClear (env);
|
||||||
|
ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -967,27 +1030,21 @@ static int __handle_bfn (
|
|||||||
|
|
||||||
if (v->type == ASE_AWK_VAL_INT)
|
if (v->type == ASE_AWK_VAL_INT)
|
||||||
{
|
{
|
||||||
jint jv;
|
jlong jv;
|
||||||
|
|
||||||
init = (*env)->GetMethodID (env,
|
|
||||||
run_data->integer_class, "<init>", "(I)V");
|
|
||||||
ASE_AWK_ASSERT (awk, init != NULL);
|
|
||||||
|
|
||||||
jv = ((ase_awk_val_int_t*)v)->val;
|
jv = ((ase_awk_val_int_t*)v)->val;
|
||||||
arg = (*env)->NewObject (env,
|
arg = (*env)->NewObject (env,
|
||||||
run_data->integer_class, init, jv);
|
run_data->long_class,
|
||||||
|
run_data->long_init, jv);
|
||||||
}
|
}
|
||||||
else if (v->type == ASE_AWK_VAL_REAL)
|
else if (v->type == ASE_AWK_VAL_REAL)
|
||||||
{
|
{
|
||||||
jdouble jv;
|
jdouble jv;
|
||||||
|
|
||||||
init = (*env)->GetMethodID (env,
|
|
||||||
run_data->double_class, "<init>", "(D)V");
|
|
||||||
ASE_AWK_ASSERT (awk, init != NULL);
|
|
||||||
|
|
||||||
jv = ((ase_awk_val_real_t*)v)->val;
|
jv = ((ase_awk_val_real_t*)v)->val;
|
||||||
arg = (*env)->NewObject (env,
|
arg = (*env)->NewObject (env,
|
||||||
run_data->double_class, init, jv);
|
run_data->double_class,
|
||||||
|
run_data->double_init, jv);
|
||||||
}
|
}
|
||||||
else if (v->type == ASE_AWK_VAL_STR)
|
else if (v->type == ASE_AWK_VAL_STR)
|
||||||
{
|
{
|
||||||
@ -1014,125 +1071,183 @@ static int __handle_bfn (
|
|||||||
(*env)->ExceptionDescribe (env);
|
(*env)->ExceptionDescribe (env);
|
||||||
(*env)->ExceptionClear (env);
|
(*env)->ExceptionClear (env);
|
||||||
(*env)->DeleteLocalRef (env, args);
|
(*env)->DeleteLocalRef (env, args);
|
||||||
ase_awk_setrunerrnum (run, ASE_AWK_EINTERNAL);
|
ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO ... */
|
(*env)->DeleteLocalRef (env, args);
|
||||||
if ((*env)->IsInstanceOf (env, ret, run_data->string_class))
|
|
||||||
|
if (ret == NULL)
|
||||||
{
|
{
|
||||||
ase_awk_setretval (...);
|
ase_awk_setretval (run, ase_awk_val_nil);
|
||||||
}
|
}
|
||||||
else if ((*env)->IsInstanceOf (env, ret, run_data->integer_class))
|
else if ((*env)->IsInstanceOf (env, ret, run_data->integer_class))
|
||||||
{
|
{
|
||||||
ase_awk_setretval (...);
|
jint jv = (*env)->CallIntMethod (
|
||||||
|
env, ret, run_data->integer_value);
|
||||||
|
|
||||||
|
v = ase_awk_makeintval (run, jv);
|
||||||
|
if (v == NULL)
|
||||||
|
{
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setretval (run, v);
|
||||||
|
}
|
||||||
|
else if ((*env)->IsInstanceOf (env, ret, run_data->long_class))
|
||||||
|
{
|
||||||
|
jlong jv = (*env)->CallLongMethod (
|
||||||
|
env, ret, run_data->long_value);
|
||||||
|
|
||||||
|
v = ase_awk_makeintval (run, jv);
|
||||||
|
if (v == NULL)
|
||||||
|
{
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setretval (run, v);
|
||||||
|
}
|
||||||
|
else if ((*env)->IsInstanceOf (env, ret, run_data->short_class))
|
||||||
|
{
|
||||||
|
jshort jv = (*env)->CallShortMethod (
|
||||||
|
env, ret, run_data->short_value);
|
||||||
|
|
||||||
|
v = ase_awk_makeintval (run, jv);
|
||||||
|
if (v == NULL)
|
||||||
|
{
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setretval (run, v);
|
||||||
|
}
|
||||||
|
else if ((*env)->IsInstanceOf (env, ret, run_data->float_class))
|
||||||
|
{
|
||||||
|
jfloat jv = (*env)->CallFloatMethod (
|
||||||
|
env, ret, run_data->float_value);
|
||||||
|
v = ase_awk_makerealval (run, jv);
|
||||||
|
if (v == NULL)
|
||||||
|
{
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setretval (run, v);
|
||||||
}
|
}
|
||||||
else if ((*env)->IsInstanceOf (env, ret, run_data->double_class))
|
else if ((*env)->IsInstanceOf (env, ret, run_data->double_class))
|
||||||
{
|
{
|
||||||
ase_awk_setretval (...);
|
jdouble jv = (*env)->CallDoubleMethod (
|
||||||
|
env, ret, run_data->double_value);
|
||||||
|
v = ase_awk_makerealval (run, jv);
|
||||||
|
if (v == NULL)
|
||||||
|
{
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setretval (run, v);
|
||||||
|
}
|
||||||
|
else if ((*env)->IsInstanceOf (env, ret, run_data->string_class))
|
||||||
|
{
|
||||||
|
jsize len;
|
||||||
|
const jchar* ptr;
|
||||||
|
|
||||||
|
len = (*env)->GetStringLength (env, ret);
|
||||||
|
ptr = (*env)->GetStringChars (env, ret, JNI_FALSE);
|
||||||
|
if (ptr == NULL)
|
||||||
|
{
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = ase_awk_makestrval (run, ptr, len);
|
||||||
|
if (v == NULL)
|
||||||
|
{
|
||||||
|
(*env)->ReleaseStringChars (env, ret, ptr);
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*env)->ReleaseStringChars (env, ret, ptr);
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setretval (run, v);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*env)->DeleteLocalRef (env, ret);
|
||||||
|
ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*env)->DeleteLocalRef (env, args);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (
|
JNIEXPORT jint JNICALL Java_ase_awk_Awk_addbfn (
|
||||||
JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args)
|
JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args)
|
||||||
{
|
{
|
||||||
jclass class;
|
jclass class;
|
||||||
jfieldID fid_handle;
|
jfieldID handle;
|
||||||
jthrowable except;
|
jint n;
|
||||||
|
|
||||||
ase_awk_t* awk;
|
ase_awk_t* awk;
|
||||||
const jchar* str;
|
const jchar* ptr;
|
||||||
jint len;
|
jsize len;
|
||||||
|
|
||||||
class = (*env)->GetObjectClass(env, obj);
|
class = (*env)->GetObjectClass(env, obj);
|
||||||
|
handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
|
||||||
fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
|
|
||||||
if (fid_handle == NULL)
|
|
||||||
{
|
|
||||||
(*env)->DeleteLocalRef (env, class);
|
(*env)->DeleteLocalRef (env, class);
|
||||||
return;
|
if (handle == NULL) return;
|
||||||
}
|
|
||||||
|
|
||||||
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, fid_handle);
|
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
|
||||||
|
|
||||||
str = (*env)->GetStringChars (env, name, JNI_FALSE);
|
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
|
||||||
len = (*env)->GetStringLength (env, name);
|
len = (*env)->GetStringLength (env, name);
|
||||||
|
|
||||||
if (ase_awk_addbfn (awk, str, len, 0,
|
n = (ase_awk_addbfn (awk, ptr, len, 0,
|
||||||
min_args, max_args, ASE_NULL, __handle_bfn) == ASE_NULL)
|
min_args, max_args, ASE_NULL, __handle_bfn) == NULL)? -1: 0;
|
||||||
{
|
(*env)->ReleaseStringChars (env, name, ptr);
|
||||||
char msg[MSG_SIZE];
|
|
||||||
int n;
|
|
||||||
|
|
||||||
(*env)->ReleaseStringChars (env, name, str);
|
return n;
|
||||||
(*env)->DeleteLocalRef (env, class);
|
|
||||||
|
|
||||||
except = (*env)->FindClass (env, CLASS_EXCEPTION);
|
|
||||||
if (except == NULL) return;
|
|
||||||
|
|
||||||
/* 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);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*env)->ReleaseStringChars (env, name, str);
|
JNIEXPORT jint JNICALL Java_ase_awk_Awk_delbfn (
|
||||||
(*env)->DeleteLocalRef (env, class);
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn (
|
|
||||||
JNIEnv* env, jobject obj, jstring name)
|
JNIEnv* env, jobject obj, jstring name)
|
||||||
{
|
{
|
||||||
jclass class;
|
jclass class;
|
||||||
jfieldID fid_handle;
|
jfieldID handle;
|
||||||
jthrowable except;
|
jint n;
|
||||||
|
|
||||||
ase_awk_t* awk;
|
ase_awk_t* awk;
|
||||||
const jchar* str;
|
const jchar* ptr;
|
||||||
jint len;
|
jsize len;
|
||||||
|
|
||||||
class = (*env)->GetObjectClass(env, obj);
|
class = (*env)->GetObjectClass(env, obj);
|
||||||
|
handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
|
||||||
fid_handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
|
|
||||||
if (fid_handle == NULL)
|
|
||||||
{
|
|
||||||
(*env)->DeleteLocalRef (env, class);
|
(*env)->DeleteLocalRef (env, class);
|
||||||
return;
|
if (handle == NULL) return -1; /* should never happen */
|
||||||
}
|
|
||||||
|
|
||||||
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, fid_handle);
|
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
|
||||||
|
|
||||||
str = (*env)->GetStringChars (env, name, JNI_FALSE);
|
|
||||||
len = (*env)->GetStringLength (env, name);
|
len = (*env)->GetStringLength (env, name);
|
||||||
|
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
|
||||||
|
n = ase_awk_delbfn (awk, ptr, len);
|
||||||
|
(*env)->ReleaseStringChars (env, name, ptr);
|
||||||
|
|
||||||
if (ase_awk_delbfn (awk, str, len) == -1)
|
return n;
|
||||||
{
|
|
||||||
char msg[MSG_SIZE];
|
|
||||||
int n;
|
|
||||||
|
|
||||||
(*env)->ReleaseStringChars (env, name, str);
|
|
||||||
(*env)->DeleteLocalRef (env, class);
|
|
||||||
|
|
||||||
except = (*env)->FindClass (env, CLASS_EXCEPTION);
|
|
||||||
if (except == NULL) return;
|
|
||||||
|
|
||||||
/* TODO: more intuitive message */
|
|
||||||
n = snprintf (msg, sizeof(msg), "cannot delete the function");
|
|
||||||
if (n < 0 || n >= sizeof(msg)) msg[sizeof(msg)-1] = '\0';
|
|
||||||
|
|
||||||
(*env)->ThrowNew (env, except, msg);
|
|
||||||
(*env)->DeleteLocalRef (env, except);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*env)->ReleaseStringChars (env, name, str);
|
|
||||||
(*env)->DeleteLocalRef (env, class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename (
|
JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename (
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: jni.h,v 1.12 2006-11-29 02:39:10 bacon Exp $
|
* $Id: jni.h,v 1.13 2006-11-29 14:52:06 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ASE_AWK_JNI_H_
|
#ifndef _ASE_AWK_JNI_H_
|
||||||
@ -16,9 +16,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj);
|
|||||||
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj);
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj);
|
||||||
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj);
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj);
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (
|
JNIEXPORT jint JNICALL Java_ase_awk_Awk_addbfn (
|
||||||
JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args);
|
JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args);
|
||||||
JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn (
|
JNIEXPORT jint JNICALL Java_ase_awk_Awk_delbfn (
|
||||||
JNIEnv* env, jobject obj, jstring name);
|
JNIEnv* env, jobject obj, jstring name);
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename (
|
JNIEXPORT jint JNICALL Java_ase_awk_Awk_setfilename (
|
||||||
|
@ -1,25 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.java,v 1.16 2006-11-29 11:41:15 bacon Exp $
|
* $Id: Awk.java,v 1.17 2006-11-29 14:52:36 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ase.test.awk;
|
package ase.test.awk;
|
||||||
|
|
||||||
public class Awk extends ase.awk.StdAwk
|
public class Awk extends ase.awk.StdAwk
|
||||||
{
|
{
|
||||||
private String[] cin;
|
|
||||||
private int cin_no;
|
|
||||||
|
|
||||||
private String[] cout;
|
|
||||||
private int cout_no;
|
|
||||||
|
|
||||||
public Awk () throws ase.awk.Exception
|
public Awk () throws ase.awk.Exception
|
||||||
{
|
{
|
||||||
super ();
|
super ();
|
||||||
|
|
||||||
try { addBuiltinFunction ("sin", 1, 10); }
|
addBuiltinFunction ("sin", 1, 10);
|
||||||
catch (ase.awk.Exception e) { System.out.println (">>>>>> CANNOT ADD sin"); }
|
addBuiltinFunction ("xxx", 1, 1);
|
||||||
try { addBuiltinFunction ("xxx", 1, 1); }
|
//addBuiltinFunction ("xxx", 1, 1);
|
||||||
catch (ase.awk.Exception e) { System.out.println (">>>>>> CANNOT ADD xxx"); }
|
|
||||||
|
//deleteBuiltinFunction ("sin");
|
||||||
|
//deleteBuiltinFunction ("sin");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object xxx (Object[] args)
|
public Object xxx (Object[] args)
|
||||||
@ -27,6 +23,7 @@ public class Awk extends ase.awk.StdAwk
|
|||||||
System.out.println ("BFN_XXX");
|
System.out.println ("BFN_XXX");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object sin (Object[] args)
|
public Object sin (Object[] args)
|
||||||
{
|
{
|
||||||
System.out.println ("<<BFN_SIN>>");
|
System.out.println ("<<BFN_SIN>>");
|
||||||
@ -38,6 +35,12 @@ public class Awk extends ase.awk.StdAwk
|
|||||||
else System.out.println (args[i].toString());
|
else System.out.println (args[i].toString());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
//return new String ("return value");
|
||||||
|
//return new Double (1.234);
|
||||||
|
//return new Float (1.234);
|
||||||
|
//return new Integer (1001);
|
||||||
|
//return new Long (1001);
|
||||||
|
//return new Short ((short)1001);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] getInputConsoleNames ()
|
protected String[] getInputConsoleNames ()
|
||||||
|
Loading…
Reference in New Issue
Block a user