2007-05-02 01:07:00 +00:00
|
|
|
/*
|
2008-08-21 03:17:25 +00:00
|
|
|
* $Id: jni.c 337 2008-08-20 09:17:25Z baconevi $
|
2007-05-02 01:07:00 +00:00
|
|
|
*
|
|
|
|
* {License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <wctype.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <math.h>
|
2007-05-26 01:30:00 +00:00
|
|
|
#include <time.h>
|
2007-05-02 01:07:00 +00:00
|
|
|
#include <ase/awk/jni.h>
|
|
|
|
#include <ase/awk/awk.h>
|
|
|
|
|
2008-08-19 05:21:48 +00:00
|
|
|
#include "../cmn/mem.h"
|
2008-08-21 03:17:25 +00:00
|
|
|
#include "../cmn/chr.h"
|
2007-05-02 01:07:00 +00:00
|
|
|
#include <ase/utl/stdio.h>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#endif
|
|
|
|
|
2007-10-15 01:34:00 +00:00
|
|
|
#if defined(_WIN32) && defined(_DEBUG) && defined(_MSC_VER)
|
2007-10-13 15:28:00 +00:00
|
|
|
#define _CRTDBG_MAP_ALLOC
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#endif
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
#ifndef ASE_CHAR_IS_WCHAR
|
|
|
|
#error this module supports ASE_CHAR_IS_WCHAR only
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CLASS_OUTOFMEMORYERROR "java/lang/OutOfMemoryError"
|
|
|
|
#define CLASS_EXCEPTION "ase/awk/Exception"
|
|
|
|
#define CLASS_EXTIO "ase/awk/Extio"
|
2007-10-16 01:15:00 +00:00
|
|
|
#define CLASS_CONTEXT "ase/awk/Context"
|
2007-10-19 14:05:00 +00:00
|
|
|
#define CLASS_ARGUMENT "ase/awk/Argument"
|
2007-10-24 18:57:00 +00:00
|
|
|
#define CLASS_RETURN "ase/awk/Return"
|
2007-10-17 00:30:00 +00:00
|
|
|
#define FIELD_AWKID "awkid"
|
|
|
|
#define FIELD_RUNID "runid"
|
2007-10-24 00:18:00 +00:00
|
|
|
#define FIELD_VALID "valid"
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-10 22:33:00 +00:00
|
|
|
#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1400)
|
|
|
|
#pragma warning(disable:4996)
|
|
|
|
|
|
|
|
#define time_t __time64_t
|
|
|
|
#define time _time64
|
|
|
|
#define localtime _localtime64
|
|
|
|
#define gmtime _gmtime64
|
|
|
|
#endif
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SOURCE_READ = 1,
|
|
|
|
SOURCE_WRITE = 2
|
|
|
|
};
|
|
|
|
|
2007-10-13 15:28:00 +00:00
|
|
|
static ase_ssize_t read_source (
|
2008-02-13 01:57:21 +00:00
|
|
|
int cmd, void* arg, ase_char_t* data, ase_size_t count);
|
2007-10-13 15:28:00 +00:00
|
|
|
static ase_ssize_t write_source (
|
2008-02-13 01:57:21 +00:00
|
|
|
int cmd, void* arg, ase_char_t* data, ase_size_t count);
|
2007-10-13 15:28:00 +00:00
|
|
|
static ase_ssize_t process_extio (
|
2008-02-13 01:57:21 +00:00
|
|
|
int cmd, void* arg, ase_char_t* data, ase_size_t count);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
static ase_char_t* dup_str (
|
|
|
|
ase_awk_t* awk, const jchar* str, ase_size_t len);
|
2007-10-24 23:17:00 +00:00
|
|
|
static int get_str (
|
|
|
|
JNIEnv* env, ase_awk_t* awk, jstring str,
|
|
|
|
const jchar** jptr, ase_char_t** aptr, jsize* outlen);
|
|
|
|
static void free_str (
|
|
|
|
JNIEnv* env, ase_awk_t* awk, jstring str,
|
|
|
|
const jchar* jptr, ase_char_t* aptr);
|
|
|
|
|
2007-11-09 00:08:00 +00:00
|
|
|
static jstring new_str (
|
|
|
|
JNIEnv* env, ase_awk_t* awk, const ase_char_t* ptr, ase_size_t len);
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
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;
|
|
|
|
jobject obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct runio_data_t
|
|
|
|
{
|
|
|
|
JNIEnv* env;
|
|
|
|
jobject obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct run_data_t
|
|
|
|
{
|
|
|
|
JNIEnv* env;
|
|
|
|
jobject obj;
|
|
|
|
|
2007-10-21 00:06:00 +00:00
|
|
|
ase_size_t errlin;
|
2008-02-13 01:57:21 +00:00
|
|
|
int errnum;
|
2007-10-21 00:06:00 +00:00
|
|
|
ase_char_t errmsg[256];
|
|
|
|
|
2007-10-22 00:05:00 +00:00
|
|
|
jclass exception_class;
|
2007-10-17 00:30:00 +00:00
|
|
|
jclass context_class;
|
2007-10-19 14:05:00 +00:00
|
|
|
jclass argument_class;
|
2007-10-24 18:57:00 +00:00
|
|
|
jclass return_class;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
jmethodID context_init;
|
2007-10-19 14:05:00 +00:00
|
|
|
jmethodID argument_init;
|
2007-10-24 18:57:00 +00:00
|
|
|
jmethodID return_init;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-22 00:05:00 +00:00
|
|
|
jmethodID exception_get_code;
|
|
|
|
jmethodID exception_get_line;
|
|
|
|
jmethodID exception_get_message;
|
|
|
|
|
2007-10-31 22:56:00 +00:00
|
|
|
jmethodID context_clear;
|
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
jfieldID argument_valid;
|
2007-10-24 18:57:00 +00:00
|
|
|
jfieldID return_valid;
|
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
jobject context_object;
|
2007-05-02 01:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static ase_real_t awk_pow (void* custom, ase_real_t x, ase_real_t y)
|
|
|
|
{
|
|
|
|
return pow (x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int awk_sprintf (
|
|
|
|
void* custom, ase_char_t* buf, ase_size_t size,
|
|
|
|
const ase_char_t* fmt, ...)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
|
|
n = ase_vsprintf (buf, size, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void awk_dprintf (void* custom, const ase_char_t* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
|
|
ase_vfprintf (stderr, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
void ase_assert_abort (void)
|
|
|
|
{
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ase_assert_printf (const ase_char_t* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
2007-10-24 00:18:00 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
{
|
|
|
|
TCHAR buf[512];
|
|
|
|
_vsntprintf (buf, ASE_COUNTOF(buf), fmt, ap);
|
2007-10-24 23:17:00 +00:00
|
|
|
MessageBox (ASE_NULL, buf, _T("ASSERTION FAILURE"), MB_OK | MB_ICONERROR);
|
2007-10-24 00:18:00 +00:00
|
|
|
}
|
|
|
|
#else
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_vfprintf (stdout, fmt, ap);
|
2007-10-24 00:18:00 +00:00
|
|
|
#endif
|
2007-05-02 01:07:00 +00:00
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void throw_exception (
|
|
|
|
JNIEnv* env, const ase_char_t* msg, jint code, jint line)
|
|
|
|
{
|
|
|
|
jclass except_class;
|
|
|
|
jmethodID except_cons;
|
|
|
|
jstring except_msg;
|
|
|
|
jthrowable except_obj;
|
|
|
|
ase_size_t len;
|
2007-11-11 00:30:00 +00:00
|
|
|
jsize chunk;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
except_class = (*env)->FindClass (env, CLASS_EXCEPTION);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (except_class == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* the exception to be thrown by FindClass is not cleared.
|
|
|
|
* 1. this should not happend as the ase.awk.Exception
|
|
|
|
* class should always be there.
|
|
|
|
* 2. if it happens, this exception may abort the entire
|
|
|
|
* program as the exception is not likely to be handled
|
|
|
|
* explicitly by the java program. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
except_cons = (*env)->GetMethodID (
|
|
|
|
env, except_class, "<init>", "(Ljava/lang/String;II)V");
|
2007-10-24 23:17:00 +00:00
|
|
|
if (except_cons == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* the potential exception to be thrown by the GetMethodID
|
|
|
|
* method is not cleared here for the same reason as the
|
|
|
|
* FindClass method above */
|
|
|
|
(*env)->DeleteLocalRef (env, except_class);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = ase_strlen(msg);
|
2007-11-11 00:30:00 +00:00
|
|
|
chunk = (len > ASE_TYPE_MAX(jsize))? ASE_TYPE_MAX(jsize): (jsize)len;
|
|
|
|
|
|
|
|
if (chunk > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-11-11 00:30:00 +00:00
|
|
|
jsize i;
|
2007-10-15 01:34:00 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(__DMC__)
|
2007-11-11 00:30:00 +00:00
|
|
|
jchar* tmp = (jchar*) GlobalAlloc (GMEM_FIXED, ASE_SIZEOF(jchar)*chunk);
|
2007-10-15 01:34:00 +00:00
|
|
|
#else
|
2007-11-11 00:30:00 +00:00
|
|
|
jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*chunk);
|
2007-10-15 01:34:00 +00:00
|
|
|
#endif
|
2007-10-24 23:17:00 +00:00
|
|
|
if (tmp == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->DeleteLocalRef (env, except_class);
|
|
|
|
|
|
|
|
except_class = (*env)->FindClass (
|
|
|
|
env, CLASS_OUTOFMEMORYERROR);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (except_class == ASE_NULL) return;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
(*env)->ThrowNew (env, except_class, "out of memory");
|
|
|
|
(*env)->DeleteLocalRef (env, except_class);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
for (i = 0; i < chunk; i++) tmp[i] = (jchar)msg[i];
|
|
|
|
except_msg = (*env)->NewString (env, tmp, chunk);
|
2007-10-15 01:34:00 +00:00
|
|
|
#if defined(_WIN32) && defined(__DMC__)
|
|
|
|
GlobalFree ((HGLOBAL)tmp);
|
|
|
|
#else
|
2007-05-02 01:07:00 +00:00
|
|
|
free (tmp);
|
2007-10-15 01:34:00 +00:00
|
|
|
#endif
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-11 00:30:00 +00:00
|
|
|
except_msg = (*env)->NewString (env, (jchar*)msg, chunk);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (except_msg == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->DeleteLocalRef (env, except_class);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
except_obj = (*env)->NewObject (
|
|
|
|
env, except_class, except_cons,
|
|
|
|
except_msg, code, line);
|
|
|
|
|
|
|
|
(*env)->DeleteLocalRef (env, except_msg);
|
|
|
|
(*env)->DeleteLocalRef (env, except_class);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (except_obj == ASE_NULL) return;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
(*env)->Throw (env, except_obj);
|
|
|
|
(*env)->DeleteLocalRef (env, except_obj);
|
|
|
|
}
|
|
|
|
|
2007-10-22 00:05:00 +00:00
|
|
|
#define THROW_STATIC_EXCEPTION(env,errnum) \
|
2007-10-25 23:43:00 +00:00
|
|
|
throw_exception (env, ase_awk_geterrstr(ASE_NULL, errnum), errnum, 0)
|
2007-10-22 00:05:00 +00:00
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
#define EXCEPTION_ON_ASE_NULL_AWK(env,awk) \
|
|
|
|
if (awk == ASE_NULL) \
|
2007-10-22 00:05:00 +00:00
|
|
|
{ \
|
|
|
|
THROW_STATIC_EXCEPTION(env,ASE_AWK_ENOPER); \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
#define EXCEPTION_ON_ASE_NULL_AWK_RETURNING(env,awk,ret) \
|
|
|
|
if (awk == ASE_NULL) \
|
2007-10-22 00:05:00 +00:00
|
|
|
{ \
|
|
|
|
THROW_STATIC_EXCEPTION(env,ASE_AWK_ENOPER); \
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define THROW_NOMEM_EXCEPTION(env) \
|
|
|
|
THROW_STATIC_EXCEPTION(env,ASE_AWK_ENOMEM)
|
|
|
|
|
|
|
|
#define THROW_AWK_EXCEPTION(env,awk) \
|
|
|
|
throw_exception ( \
|
|
|
|
env, \
|
|
|
|
ase_awk_geterrmsg(awk), \
|
2007-11-11 00:30:00 +00:00
|
|
|
(jint)ase_awk_geterrnum(awk), \
|
|
|
|
(jint)ase_awk_geterrlin(awk))
|
2007-10-22 00:05:00 +00:00
|
|
|
|
|
|
|
#define THROW_RUN_EXCEPTION(env,run) \
|
|
|
|
throw_exception ( \
|
|
|
|
env, \
|
|
|
|
ase_awk_getrunerrmsg(run), \
|
2007-11-11 00:30:00 +00:00
|
|
|
(jint)ase_awk_getrunerrnum(run), \
|
|
|
|
(jint)ase_awk_getrunerrlin(run))
|
2007-10-22 00:05:00 +00:00
|
|
|
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
static jboolean is_debug (ase_awk_t* awk)
|
|
|
|
{
|
2008-07-21 06:42:39 +00:00
|
|
|
awk_data_t* awk_data = (awk_data_t*)ase_awk_getextension (awk);
|
2007-05-02 01:07:00 +00:00
|
|
|
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_prmfns_t prmfns;
|
|
|
|
awk_data_t* awk_data;
|
|
|
|
int opt;
|
2007-10-15 01:34:00 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(_DEBUG)
|
2007-10-13 15:28:00 +00:00
|
|
|
OutputDebugStringW (L"<<<OPENING AWK>>>\n");
|
2007-10-15 01:34:00 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
_CrtSetDbgFlag (_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF);
|
|
|
|
#endif
|
2007-10-13 15:28:00 +00:00
|
|
|
#endif
|
2007-10-15 01:34:00 +00:00
|
|
|
|
2008-08-19 05:21:48 +00:00
|
|
|
awk = ase_awk_open (ASE_NULL, ASE_SIZEOF(awk_data_t), ASE_NULL);
|
2008-07-21 06:42:39 +00:00
|
|
|
if (awk == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-21 06:42:39 +00:00
|
|
|
awk_data = (awk_data_t*) ase_awk_getextension (awk);
|
2007-10-15 01:34:00 +00:00
|
|
|
awk_data->debug = 0;
|
2008-07-21 06:42:39 +00:00
|
|
|
awk_data->prmfns.pow = awk_pow;
|
|
|
|
awk_data->prmfns.sprintf = awk_sprintf;
|
|
|
|
awk_data->prmfns.dprintf = awk_dprintf;
|
2008-08-19 05:21:48 +00:00
|
|
|
awk_data->prmfns.data = ASE_NULL;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-07-21 06:42:39 +00:00
|
|
|
ase_awk_setccls (awk, ASE_GETCCLS());
|
|
|
|
ase_awk_setprmfns (awk, &awk_data->prmfns);
|
2008-06-29 03:38:00 +00:00
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* internal error. no handle field
|
|
|
|
* NoSuchFieldError, ExceptionInitializerError,
|
2007-10-17 00:30:00 +00:00
|
|
|
* OutOfMemoryError might have occurred */
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_awk_close (awk);
|
2007-10-15 01:34:00 +00:00
|
|
|
#if defined(_WIN32) && defined(__DMC__)
|
|
|
|
awk_free (heap, awk_data);
|
|
|
|
HeapDestroy (heap);
|
|
|
|
#else
|
2007-10-24 23:17:00 +00:00
|
|
|
awk_free (ASE_NULL, awk_data);
|
2007-10-15 01:34:00 +00:00
|
|
|
#endif
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->SetLongField (env, obj, handle, (jlong)awk);
|
|
|
|
|
2007-05-26 21:41:00 +00:00
|
|
|
opt = ASE_AWK_IMPLICIT |
|
|
|
|
ASE_AWK_EXTIO |
|
|
|
|
ASE_AWK_BLOCKLESS |
|
2007-09-02 00:43:00 +00:00
|
|
|
ASE_AWK_BASEONE |
|
2007-10-12 00:13:00 +00:00
|
|
|
ASE_AWK_PABLOCK;
|
2007-05-26 21:41:00 +00:00
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_awk_setoption (awk, opt);
|
2007-10-15 01:34:00 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(_DEBUG)
|
|
|
|
OutputDebugStringW (L"<<<OPENED AWK DONE>>>\n");
|
|
|
|
#endif
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj, jlong awkid)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
ase_awk_t* awk;
|
2007-10-19 14:05:00 +00:00
|
|
|
awk_data_t* tmp;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
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 */
|
2007-10-24 23:17:00 +00:00
|
|
|
if (awk == ASE_NULL) return;
|
2007-10-19 14:05:00 +00:00
|
|
|
|
2007-10-15 01:34:00 +00:00
|
|
|
#if defined(_WIN32) && defined(_DEBUG)
|
|
|
|
OutputDebugStringW (L"<<<CLOSING AWK>>>\n");
|
|
|
|
#endif
|
|
|
|
|
2008-07-21 06:42:39 +00:00
|
|
|
tmp = (awk_data_t*)ase_awk_getextension (awk);
|
2007-10-15 01:34:00 +00:00
|
|
|
#if defined(_WIN32) && defined(__DMC__)
|
2007-10-19 14:05:00 +00:00
|
|
|
HANDLE heap = tmp->heap;
|
2007-10-15 01:34:00 +00:00
|
|
|
#endif
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_close (awk);
|
2007-10-15 01:34:00 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(__DMC__)
|
2007-10-19 14:05:00 +00:00
|
|
|
awk_free (heap, tmp);
|
|
|
|
HeapDestroy (heap);
|
2007-10-15 01:34:00 +00:00
|
|
|
#else
|
2007-10-24 23:17:00 +00:00
|
|
|
awk_free (ASE_NULL, tmp);
|
2007-10-15 01:34:00 +00:00
|
|
|
#endif
|
2007-10-13 15:28:00 +00:00
|
|
|
|
2007-10-15 01:34:00 +00:00
|
|
|
#if defined(_WIN32) && defined(_DEBUG)
|
|
|
|
OutputDebugStringW (L"<<<CLOSED AWK>>>\n");
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
_CrtDumpMemoryLeaks ();
|
|
|
|
#endif
|
2007-10-13 15:28:00 +00:00
|
|
|
#endif
|
2007-10-19 14:05:00 +00:00
|
|
|
|
2007-10-22 00:05:00 +00:00
|
|
|
}
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj, jlong awkid)
|
|
|
|
{
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_awk_t* awk;
|
|
|
|
ase_awk_srcios_t srcios;
|
|
|
|
srcio_data_t srcio_data;
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
awk = (ase_awk_t*) awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK (env, awk);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
srcio_data.env = env;
|
|
|
|
srcio_data.obj = obj;
|
|
|
|
|
2007-10-13 15:28:00 +00:00
|
|
|
srcios.in = read_source;
|
|
|
|
srcios.out = write_source;
|
2008-08-19 05:21:48 +00:00
|
|
|
srcios.data = &srcio_data;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
if (ase_awk_parse (awk, &srcios) == -1)
|
|
|
|
{
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_AWK_EXCEPTION (env, awk);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DELETE_CLASS_REFS(env, run_data) \
|
|
|
|
do { \
|
2007-10-22 00:05:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, run_data.exception_class); \
|
2007-10-17 00:30:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, run_data.context_class); \
|
2007-10-19 14:05:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, run_data.argument_class); \
|
2007-10-24 18:57:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, run_data.return_class); \
|
2007-10-24 23:17:00 +00:00
|
|
|
if (run_data.context_object != ASE_NULL) \
|
2007-10-17 00:30:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, run_data.context_object); \
|
2007-05-02 01:07:00 +00:00
|
|
|
} while (0)
|
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
static void on_run_start (ase_awk_run_t* run, void* custom)
|
2007-10-16 01:15:00 +00:00
|
|
|
{
|
2007-10-17 00:30:00 +00:00
|
|
|
run_data_t* run_data;
|
|
|
|
JNIEnv* env;
|
|
|
|
jobject obj;
|
|
|
|
jfieldID runid;
|
2007-10-16 01:15:00 +00:00
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
2007-10-16 01:15:00 +00:00
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
env = run_data->env;
|
|
|
|
obj = run_data->obj;
|
2007-10-16 01:15:00 +00:00
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
runid = (*env)->GetFieldID (env, run_data->context_class, FIELD_RUNID, "J");
|
|
|
|
(*env)->SetLongField (env, run_data->context_object, runid, (jlong)run);
|
2007-10-16 01:15:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
static void on_run_end (ase_awk_run_t* run, int errnum, void* custom)
|
2007-10-16 01:15:00 +00:00
|
|
|
{
|
2007-10-17 00:30:00 +00:00
|
|
|
run_data_t* run_data;
|
|
|
|
JNIEnv* env;
|
|
|
|
jobject obj;
|
2007-10-21 00:06:00 +00:00
|
|
|
jfieldID runid_field;
|
|
|
|
jlong runid;
|
2007-10-17 00:30:00 +00:00
|
|
|
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
|
|
|
|
|
|
|
env = run_data->env;
|
|
|
|
obj = run_data->obj;
|
|
|
|
|
2007-10-21 00:06:00 +00:00
|
|
|
runid_field = (*env)->GetFieldID (env, run_data->context_class, FIELD_RUNID, "J");
|
|
|
|
runid = (*env)->GetLongField (env, run_data->context_object, runid_field);
|
|
|
|
|
|
|
|
if (errnum != ASE_AWK_ENOERR)
|
|
|
|
{
|
|
|
|
ase_char_t* tmp;
|
|
|
|
|
|
|
|
ase_awk_getrunerror (
|
|
|
|
(ase_awk_run_t*)runid, &run_data->errnum,
|
|
|
|
&run_data->errlin, &tmp);
|
|
|
|
ase_strxcpy (run_data->errmsg,
|
|
|
|
ASE_COUNTOF(run_data->errmsg), tmp);
|
|
|
|
}
|
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
/* runid field is not valid any more */
|
2007-10-21 00:06:00 +00:00
|
|
|
(*env)->SetLongField (env, run_data->context_object, runid_field, (jlong)0);
|
|
|
|
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jlong awkid, jstring mfn, jobjectArray args)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
ase_awk_t* awk;
|
2007-10-16 01:15:00 +00:00
|
|
|
ase_awk_runcbs_t runcbs;
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_awk_runios_t runios;
|
|
|
|
runio_data_t runio_data;
|
|
|
|
run_data_t run_data;
|
|
|
|
ase_char_t* mmm;
|
2007-10-24 23:17:00 +00:00
|
|
|
ase_awk_runarg_t* runarg = ASE_NULL;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
jsize len, i, j;
|
2007-05-02 01:07:00 +00:00
|
|
|
const jchar* ptr;
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
awk = (ase_awk_t*) awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK (env, awk);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-21 00:06:00 +00:00
|
|
|
memset (&run_data, 0, sizeof(run_data));
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
run_data.env = env;
|
|
|
|
run_data.obj = obj;
|
|
|
|
|
2007-10-21 00:06:00 +00:00
|
|
|
run_data.errnum = ASE_AWK_ENOERR;
|
|
|
|
run_data.errlin = 0;
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
/* would global reference be necessary? */
|
2007-10-22 00:05:00 +00:00
|
|
|
run_data.exception_class = (*env)->FindClass (env, CLASS_EXCEPTION);
|
2007-10-17 00:30:00 +00:00
|
|
|
run_data.context_class = (*env)->FindClass (env, CLASS_CONTEXT);
|
2007-10-19 14:05:00 +00:00
|
|
|
run_data.argument_class = (*env)->FindClass (env, CLASS_ARGUMENT);
|
2007-10-24 18:57:00 +00:00
|
|
|
run_data.return_class = (*env)->FindClass (env, CLASS_RETURN);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
ASE_ASSERT (run_data.exception_class != ASE_NULL);
|
|
|
|
ASE_ASSERT (run_data.context_class != ASE_NULL);
|
|
|
|
ASE_ASSERT (run_data.argument_class != ASE_NULL);
|
|
|
|
ASE_ASSERT (run_data.return_class != ASE_NULL);
|
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
run_data.context_init = (*env)->GetMethodID (
|
|
|
|
env, run_data.context_class, "<init>", "(Lase/awk/Awk;)V");
|
2007-10-19 14:05:00 +00:00
|
|
|
run_data.argument_init = (*env)->GetMethodID (
|
2007-11-03 23:35:00 +00:00
|
|
|
env, run_data.argument_class, "<init>", "(Lase/awk/Context;JJ)V");
|
2007-10-24 18:57:00 +00:00
|
|
|
run_data.return_init = (*env)->GetMethodID (
|
|
|
|
env, run_data.return_class, "<init>", "(JJ)V");
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
ASE_ASSERT (run_data.context_init != ASE_NULL);
|
|
|
|
ASE_ASSERT (run_data.argument_init != ASE_NULL);
|
|
|
|
ASE_ASSERT (run_data.return_init != ASE_NULL);
|
2007-10-22 00:05:00 +00:00
|
|
|
|
|
|
|
run_data.exception_get_code = (*env)->GetMethodID (
|
|
|
|
env, run_data.exception_class, "getCode", "()I");
|
|
|
|
run_data.exception_get_line = (*env)->GetMethodID (
|
|
|
|
env, run_data.exception_class, "getLine", "()I");
|
|
|
|
run_data.exception_get_message = (*env)->GetMethodID (
|
|
|
|
env, run_data.exception_class, "getMessage", "()Ljava/lang/String;");
|
2007-10-31 22:56:00 +00:00
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
ASE_ASSERT (run_data.exception_get_code != ASE_NULL);
|
|
|
|
ASE_ASSERT (run_data.exception_get_line != ASE_NULL);
|
|
|
|
ASE_ASSERT (run_data.exception_get_message != ASE_NULL);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-31 22:56:00 +00:00
|
|
|
run_data.context_clear = (*env)->GetMethodID (
|
|
|
|
env, run_data.context_class, "clear", "()V");
|
|
|
|
|
|
|
|
ASE_ASSERT (run_data.context_clear != ASE_NULL);
|
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
run_data.argument_valid = (*env)->GetFieldID (
|
|
|
|
env, run_data.argument_class, FIELD_VALID, "J");
|
2007-10-24 18:57:00 +00:00
|
|
|
run_data.return_valid = (*env)->GetFieldID (
|
|
|
|
env, run_data.return_class, FIELD_VALID, "J");
|
2007-11-03 23:35:00 +00:00
|
|
|
if (run_data.argument_valid == ASE_NULL ||
|
|
|
|
run_data.return_valid == ASE_NULL)
|
2007-10-24 18:57:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-17 00:30:00 +00:00
|
|
|
/* No NewGlobalRef are needed on obj and run_data->context_object
|
|
|
|
* because they are valid while this run method runs */
|
|
|
|
run_data.context_object = (*env)->NewObject (
|
|
|
|
env, run_data.context_class, run_data.context_init, obj);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (run_data.context_object == ASE_NULL)
|
2007-10-17 00:30:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-10-17 00:30:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
runio_data.env = env;
|
|
|
|
runio_data.obj = obj;
|
|
|
|
|
2007-10-13 15:28:00 +00:00
|
|
|
runios.pipe = process_extio;
|
2007-10-25 23:43:00 +00:00
|
|
|
runios.coproc = ASE_NULL;
|
2007-10-13 15:28:00 +00:00
|
|
|
runios.file = process_extio;
|
|
|
|
runios.console = process_extio;
|
2008-08-19 05:21:48 +00:00
|
|
|
runios.data = &runio_data;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-08-19 05:21:48 +00:00
|
|
|
ASE_MEMSET (&runcbs, 0, ASE_SIZEOF(runcbs));
|
2007-10-16 01:15:00 +00:00
|
|
|
runcbs.on_start = on_run_start;
|
2007-10-17 00:30:00 +00:00
|
|
|
runcbs.on_end = on_run_end;
|
2008-08-19 05:21:48 +00:00
|
|
|
runcbs.data = ASE_NULL;
|
2007-10-16 01:15:00 +00:00
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mfn == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-24 23:17:00 +00:00
|
|
|
mmm = ASE_NULL;
|
|
|
|
ptr = ASE_NULL;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* process the main entry point */
|
|
|
|
len = (*env)->GetStringLength (env, mfn);
|
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
ptr = (*env)->GetStringChars (env, mfn, JNI_FALSE);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ptr == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-08-21 03:17:25 +00:00
|
|
|
mmm = (ase_char_t*) ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*(len+1));
|
2007-10-25 23:43:00 +00:00
|
|
|
if (mmm == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ReleaseStringChars (env, mfn, ptr);
|
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-21 00:06:00 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
mmm[i] = (ase_char_t)ptr[i];
|
|
|
|
if (mmm[i] == ASE_T('\0'))
|
|
|
|
{
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_free (awk, mmm);
|
2007-05-02 01:07:00 +00:00
|
|
|
(*env)->ReleaseStringChars (env, mfn, ptr);
|
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
|
|
|
throw_exception (
|
|
|
|
env,
|
|
|
|
ASE_T("main function name not valid"),
|
|
|
|
ASE_AWK_EINVAL,
|
|
|
|
0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mmm[len] = ASE_T('\0');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-24 23:17:00 +00:00
|
|
|
mmm = ASE_NULL;
|
|
|
|
ptr = ASE_NULL;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (args != ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* compose arguments */
|
|
|
|
|
|
|
|
len = (*env)->GetArrayLength (env, args);
|
|
|
|
|
2008-08-21 03:17:25 +00:00
|
|
|
runarg = ase_awk_alloc (awk, sizeof(ase_awk_runarg_t) * (len+1));
|
2007-10-24 23:17:00 +00:00
|
|
|
if (runarg == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mmm != ASE_NULL) ase_awk_free (awk, mmm);
|
|
|
|
if (ptr != ASE_NULL) (*env)->ReleaseStringChars (env, mfn, ptr);
|
2007-05-02 01:07:00 +00:00
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
const jchar* tmp;
|
|
|
|
jstring obj = (jstring)(*env)->GetObjectArrayElement (env, args, i);
|
|
|
|
|
|
|
|
runarg[i].len = (*env)->GetStringLength (env, obj);
|
|
|
|
tmp = (*env)->GetStringChars (env, obj, JNI_FALSE);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (tmp == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-15 01:34:00 +00:00
|
|
|
for (j = 0; j < i; j++) ase_awk_free (awk, runarg[j].ptr);
|
|
|
|
ase_awk_free (awk, runarg);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
(*env)->DeleteLocalRef (env, obj);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mmm != ASE_NULL && mmm) ase_awk_free (awk, mmm);
|
|
|
|
if (ptr != ASE_NULL) (*env)->ReleaseStringChars (env, mfn, ptr);
|
2007-05-02 01:07:00 +00:00
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
|
|
|
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
runarg[i].ptr = dup_str (awk, tmp, runarg[i].len);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (runarg[i].ptr == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-15 01:34:00 +00:00
|
|
|
for (j = 0; j < i; j++) ase_awk_free (awk, runarg[j].ptr);
|
|
|
|
ase_awk_free (awk, runarg);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
(*env)->ReleaseStringChars (env, obj, tmp);
|
|
|
|
(*env)->DeleteLocalRef (env, obj);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mmm != ASE_NULL) ase_awk_free (awk, mmm);
|
|
|
|
if (ptr != ASE_NULL) (*env)->ReleaseStringChars (env, mfn, ptr);
|
2007-05-02 01:07:00 +00:00
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->ReleaseStringChars (env, obj, tmp);
|
|
|
|
(*env)->DeleteLocalRef (env, obj);
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
runarg[i].ptr = ASE_NULL;
|
2007-05-02 01:07:00 +00:00
|
|
|
runarg[i].len = 0;
|
|
|
|
}
|
|
|
|
|
2007-10-21 00:06:00 +00:00
|
|
|
if (ase_awk_run (awk, mmm, &runios, &runcbs, runarg, &run_data) == -1 ||
|
|
|
|
run_data.errnum != ASE_AWK_ENOERR)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-24 23:17:00 +00:00
|
|
|
if (runarg != ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-15 01:34:00 +00:00
|
|
|
for (i = 0; i < len; i++) ase_awk_free (awk, runarg[i].ptr);
|
|
|
|
ase_awk_free (awk, runarg);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mmm != ASE_NULL) ase_awk_free (awk, mmm);
|
|
|
|
if (ptr != ASE_NULL) (*env)->ReleaseStringChars (env, mfn, ptr);
|
2007-05-02 01:07:00 +00:00
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
|
|
|
|
2007-10-21 00:06:00 +00:00
|
|
|
if (run_data.errnum != ASE_AWK_ENOERR)
|
|
|
|
{
|
|
|
|
throw_exception (
|
|
|
|
env,
|
|
|
|
run_data.errmsg,
|
2007-11-11 00:30:00 +00:00
|
|
|
(jint)run_data.errnum,
|
|
|
|
(jint)run_data.errlin);
|
2007-10-21 00:06:00 +00:00
|
|
|
}
|
2007-10-22 00:05:00 +00:00
|
|
|
else THROW_AWK_EXCEPTION (env, awk);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (runarg != ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-15 01:34:00 +00:00
|
|
|
for (i = 0; i < len; i++) ase_awk_free (awk, runarg[i].ptr);
|
|
|
|
ase_awk_free (awk, runarg);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mmm != ASE_NULL) ase_awk_free (awk, mmm);
|
|
|
|
if (ptr != ASE_NULL) (*env)->ReleaseStringChars (env, mfn, ptr);
|
2007-05-02 01:07:00 +00:00
|
|
|
DELETE_CLASS_REFS (env, run_data);
|
|
|
|
}
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_stop (JNIEnv* env, jobject obj, jlong awkid)
|
2007-10-13 15:28:00 +00:00
|
|
|
{
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_t* awk = (ase_awk_t*)awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK (env, awk);
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_stopall (awk);
|
2007-10-13 15:28:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_open_source (JNIEnv* env, jobject obj, int mode)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
jclass class;
|
|
|
|
jfieldID handle;
|
|
|
|
jmethodID mid;
|
|
|
|
jint ret;
|
|
|
|
ase_awk_t* awk;
|
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, "openSource", "(I)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, mode);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_close_source (JNIEnv* env, jobject obj, int mode)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
jclass class;
|
|
|
|
jfieldID handle;
|
|
|
|
jmethodID mid;
|
|
|
|
jint ret;
|
|
|
|
ase_awk_t* awk;
|
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, "closeSource", "(I)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, mode);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_read_source (
|
2007-05-02 01:07:00 +00:00
|
|
|
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;
|
|
|
|
ase_awk_t* awk;
|
2007-11-10 00:20:00 +00:00
|
|
|
jsize chunk;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, "readSource", "([CI)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-11-10 00:20:00 +00:00
|
|
|
chunk = (size > ASE_TYPE_MAX(jsize))? ASE_TYPE_MAX(jsize): (jsize)size;
|
|
|
|
|
|
|
|
array = (*env)->NewCharArray (env, chunk);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (array == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-11-10 00:20:00 +00:00
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, array, chunk);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = (*env)->GetCharArrayElements (env, array, 0);
|
|
|
|
for (i = 0; i < ret; i++) buf[i] = (ase_char_t)tmp[i];
|
|
|
|
(*env)->ReleaseCharArrayElements (env, array, tmp, 0);
|
|
|
|
|
|
|
|
(*env)->DeleteLocalRef (env, array);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_write_source (
|
2007-05-02 01:07:00 +00:00
|
|
|
JNIEnv* env, jobject obj, ase_char_t* buf, ase_size_t size)
|
|
|
|
{
|
|
|
|
jclass class;
|
|
|
|
jfieldID handle;
|
|
|
|
jmethodID mid;
|
|
|
|
jcharArray array;
|
|
|
|
jchar* tmp;
|
|
|
|
jint ret;
|
|
|
|
ase_awk_t* awk;
|
2007-11-11 00:30:00 +00:00
|
|
|
jsize chunk, i;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, "writeSource", "([CI)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-11-10 00:20:00 +00:00
|
|
|
/* handle upto 'chunk' characters, let the rest be handled by
|
|
|
|
* the underlying engine */
|
|
|
|
chunk = (size > ASE_TYPE_MAX(jsize))? ASE_TYPE_MAX(jsize): (jsize)size;
|
|
|
|
|
|
|
|
array = (*env)->NewCharArray (env, chunk);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (array == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = (*env)->GetCharArrayElements (env, array, 0);
|
2007-11-10 00:20:00 +00:00
|
|
|
for (i = 0; i < chunk; i++) tmp[i] = (jchar)buf[i];
|
2007-05-02 01:07:00 +00:00
|
|
|
(*env)->ReleaseCharArrayElements (env, array, tmp, 0);
|
|
|
|
|
2007-11-10 00:20:00 +00:00
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, array, chunk);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->DeleteLocalRef (env, array);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_open_extio (
|
2007-05-02 01:07:00 +00:00
|
|
|
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);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for extio class */
|
|
|
|
extio_class = (*env)->FindClass (env, CLASS_EXTIO);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (extio_class == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the constructor */
|
|
|
|
extio_cons = (*env)->GetMethodID (
|
|
|
|
env, extio_class, "<init>", "(Ljava/lang/String;IIJ)V");
|
2007-10-24 23:17:00 +00:00
|
|
|
if (extio_cons == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
(*env)->DeleteLocalRef (env, extio_class);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct the name */
|
2007-11-09 00:08:00 +00:00
|
|
|
extio_name = new_str (env, awk, extio->name, ase_strlen(extio->name));
|
2007-10-24 23:17:00 +00:00
|
|
|
if (extio_name == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->DeleteLocalRef (env, extio_class);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct the extio object */
|
|
|
|
extio_object = (*env)->NewObject (
|
|
|
|
env, extio_class, extio_cons,
|
|
|
|
extio_name, extio->type & 0xFF, extio->mode, (jlong)extio->run);
|
|
|
|
(*env)->DeleteLocalRef (env, extio_class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (extio_object == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
(*env)->DeleteLocalRef (env, extio_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->DeleteLocalRef (env, extio_name);
|
|
|
|
|
|
|
|
/* execute the method */
|
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, extio_object);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* clear the exception */
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
/* ret == -1 failed to open the stream
|
|
|
|
* ret == 0 opened the stream and reached its end
|
|
|
|
* ret == 1 opened the stream. */
|
|
|
|
extio->handle = (*env)->NewGlobalRef (env, extio_object);
|
|
|
|
/*
|
2007-10-24 23:17:00 +00:00
|
|
|
if (extio->handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
// TODO: close the stream ...
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->DeleteLocalRef (env, extio_object);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_close_extio (
|
2007-05-02 01:07:00 +00:00
|
|
|
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);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, extio->handle);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
/* ret == -1 failed to close the stream
|
|
|
|
* ret == 0 closed the stream */
|
|
|
|
(*env)->DeleteGlobalRef (env, extio->handle);
|
2007-10-24 23:17:00 +00:00
|
|
|
extio->handle = ASE_NULL;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_read_extio (
|
2007-05-02 01:07:00 +00:00
|
|
|
JNIEnv* env, jobject obj, char* meth,
|
|
|
|
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;
|
|
|
|
ase_awk_t* awk;
|
2007-11-10 00:20:00 +00:00
|
|
|
jsize chunk;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-11-10 00:20:00 +00:00
|
|
|
/* shrink the buffer if it exceeds java's capability */
|
|
|
|
chunk = (size > ASE_TYPE_MAX(jsize))? ASE_TYPE_MAX(jsize): (jsize)size;
|
|
|
|
|
|
|
|
array = (*env)->NewCharArray (env, chunk);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (array == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-11-10 00:20:00 +00:00
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, extio->handle, array, chunk);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
tmp = (*env)->GetCharArrayElements (env, array, 0);
|
|
|
|
for (i = 0; i < ret; i++) buf[i] = (ase_char_t)tmp[i];
|
|
|
|
(*env)->ReleaseCharArrayElements (env, array, tmp, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->DeleteLocalRef (env, array);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_write_extio (
|
2007-05-02 01:07:00 +00:00
|
|
|
JNIEnv* env, jobject obj, char* meth,
|
|
|
|
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_awk_t* awk;
|
2007-11-11 00:30:00 +00:00
|
|
|
jsize chunk, i;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-11-10 00:20:00 +00:00
|
|
|
chunk = (size > ASE_TYPE_MAX(jsize))? ASE_TYPE_MAX(jsize): (jsize)size;
|
|
|
|
|
|
|
|
array = (*env)->NewCharArray (env, chunk);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (array == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = (*env)->GetCharArrayElements (env, array, 0);
|
2007-11-10 00:20:00 +00:00
|
|
|
for (i = 0; i < chunk; i++) tmp[i] = (jchar)data[i];
|
2007-05-02 01:07:00 +00:00
|
|
|
(*env)->ReleaseCharArrayElements (env, array, tmp, 0);
|
|
|
|
|
2007-11-10 00:20:00 +00:00
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, extio->handle, array, chunk);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->DeleteLocalRef (env, array);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_flush_extio (
|
2007-05-02 01:07:00 +00:00
|
|
|
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);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, extio->handle);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
static ase_ssize_t java_next_extio (
|
2007-05-02 01:07:00 +00:00
|
|
|
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);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I");
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mid == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (*env)->CallIntMethod (env, obj, mid, extio->handle);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-13 15:28:00 +00:00
|
|
|
static ase_ssize_t read_source (
|
2008-02-13 01:57:21 +00:00
|
|
|
int cmd, void* arg, ase_char_t* data, ase_size_t count)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
srcio_data_t* srcio_data = (srcio_data_t*)arg;
|
|
|
|
|
|
|
|
if (cmd == ASE_AWK_IO_OPEN)
|
|
|
|
{
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_open_source (
|
2007-05-02 01:07:00 +00:00
|
|
|
srcio_data->env, srcio_data->obj, SOURCE_READ);
|
|
|
|
}
|
|
|
|
else if (cmd == ASE_AWK_IO_CLOSE)
|
|
|
|
{
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_close_source (
|
2007-05-02 01:07:00 +00:00
|
|
|
srcio_data->env, srcio_data->obj, SOURCE_READ);
|
|
|
|
}
|
|
|
|
else if (cmd == ASE_AWK_IO_READ)
|
|
|
|
{
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_read_source (
|
2007-05-02 01:07:00 +00:00
|
|
|
srcio_data->env, srcio_data->obj, data, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-13 15:28:00 +00:00
|
|
|
static ase_ssize_t write_source (
|
2008-02-13 01:57:21 +00:00
|
|
|
int cmd, void* arg, ase_char_t* data, ase_size_t count)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
srcio_data_t* srcio_data = (srcio_data_t*)arg;
|
|
|
|
|
|
|
|
if (cmd == ASE_AWK_IO_OPEN)
|
|
|
|
{
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_open_source (
|
2007-05-02 01:07:00 +00:00
|
|
|
srcio_data->env, srcio_data->obj, SOURCE_WRITE);
|
|
|
|
}
|
|
|
|
else if (cmd == ASE_AWK_IO_CLOSE)
|
|
|
|
{
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_close_source (
|
2007-05-02 01:07:00 +00:00
|
|
|
srcio_data->env, srcio_data->obj, SOURCE_WRITE);
|
|
|
|
}
|
|
|
|
else if (cmd == ASE_AWK_IO_WRITE)
|
|
|
|
{
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_write_source (
|
2007-05-02 01:07:00 +00:00
|
|
|
srcio_data->env, srcio_data->obj, data, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-13 15:28:00 +00:00
|
|
|
static ase_ssize_t process_extio (
|
2008-02-13 01:57:21 +00:00
|
|
|
int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
|
2008-08-19 05:21:48 +00:00
|
|
|
runio_data_t* runio_data = (runio_data_t*)epa->data;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-05-06 19:44:00 +00:00
|
|
|
switch (cmd)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-05-06 19:44:00 +00:00
|
|
|
|
|
|
|
case ASE_AWK_IO_OPEN:
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_open_extio (
|
2007-05-06 19:44:00 +00:00
|
|
|
runio_data->env, runio_data->obj,
|
|
|
|
"openExtio", epa);
|
|
|
|
|
|
|
|
case ASE_AWK_IO_CLOSE:
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_close_extio (
|
2007-05-06 19:44:00 +00:00
|
|
|
runio_data->env, runio_data->obj,
|
|
|
|
"closeExtio", epa);
|
|
|
|
|
|
|
|
case ASE_AWK_IO_READ:
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_read_extio (
|
2007-05-06 19:44:00 +00:00
|
|
|
runio_data->env, runio_data->obj,
|
|
|
|
"readExtio", epa, data, size);
|
|
|
|
|
|
|
|
case ASE_AWK_IO_WRITE:
|
|
|
|
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_write_extio (
|
2007-05-06 19:44:00 +00:00
|
|
|
runio_data->env, runio_data->obj,
|
|
|
|
"writeExtio", epa, data, size);
|
|
|
|
|
|
|
|
case ASE_AWK_IO_FLUSH:
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_flush_extio (
|
2007-05-06 19:44:00 +00:00
|
|
|
runio_data->env, runio_data->obj,
|
|
|
|
"flushExtio", epa);
|
|
|
|
|
|
|
|
case ASE_AWK_IO_NEXT:
|
2007-10-16 01:15:00 +00:00
|
|
|
return java_next_extio (
|
2007-05-06 19:44:00 +00:00
|
|
|
runio_data->env, runio_data->obj,
|
|
|
|
"nextExtio", epa);
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-13 15:28:00 +00:00
|
|
|
static int handle_bfn (
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl)
|
|
|
|
{
|
2007-10-24 18:57:00 +00:00
|
|
|
run_data_t* run_data;
|
|
|
|
ase_awk_t* awk;
|
|
|
|
|
|
|
|
JNIEnv* env;
|
|
|
|
jobject obj;
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
jclass class;
|
|
|
|
jmethodID method;
|
2007-10-22 00:05:00 +00:00
|
|
|
jthrowable throwable;
|
2007-05-02 01:07:00 +00:00
|
|
|
jstring name;
|
2007-11-11 00:30:00 +00:00
|
|
|
jsize i, nargs;
|
2007-05-02 01:07:00 +00:00
|
|
|
jobjectArray args;
|
|
|
|
jobject arg, ret;
|
|
|
|
ase_awk_val_t* v;
|
2007-10-24 18:57:00 +00:00
|
|
|
jlong vi;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
ase_size_t nargs_ase;
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
awk = ase_awk_getrunawk (run);
|
2007-11-11 00:30:00 +00:00
|
|
|
run_data = ase_awk_getruncustomdata (run);
|
|
|
|
|
|
|
|
nargs_ase = ase_awk_getnargs (run);
|
|
|
|
nargs = (nargs_ase > ASE_TYPE_MAX(jsize))? ASE_TYPE_MAX(jsize): (jsize)nargs_ase;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
env = run_data->env;
|
|
|
|
obj = run_data->obj;
|
|
|
|
|
2007-11-09 00:08:00 +00:00
|
|
|
name = new_str (env, awk, fnm, fnl);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (name == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-13 15:28:00 +00:00
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
|
|
|
method = (*env)->GetMethodID (
|
|
|
|
env, class, "handleFunction",
|
2007-10-24 18:57:00 +00:00
|
|
|
"(Lase/awk/Context;Ljava/lang/String;Lase/awk/Return;[Lase/awk/Argument;)V");
|
2007-05-02 01:07:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (method == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* if the method is not found, the exception is thrown.
|
|
|
|
* clear it to prevent it from being thrown */
|
2007-10-13 15:28:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, name);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
2007-10-24 00:18:00 +00:00
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_EINTERN);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-24 18:57:00 +00:00
|
|
|
ret = (*env)->NewObject (env,
|
2007-11-03 23:35:00 +00:00
|
|
|
run_data->return_class, run_data->return_init,
|
|
|
|
(jlong)run, (jlong)0);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ret == ASE_NULL)
|
2007-10-24 18:57:00 +00:00
|
|
|
{
|
|
|
|
(*env)->DeleteLocalRef (env, name);
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
args = (*env)->NewObjectArray (
|
2007-10-24 23:17:00 +00:00
|
|
|
env, nargs, run_data->argument_class, ASE_NULL);
|
|
|
|
if (args == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-24 18:57:00 +00:00
|
|
|
/* no ref-down on ret.runid as it is still ase_awk_val_nil */
|
|
|
|
(*env)->DeleteLocalRef (env, ret);
|
|
|
|
|
2007-10-13 15:28:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, name);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nargs; i++)
|
|
|
|
{
|
|
|
|
v = ase_awk_getarg (run, i);
|
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
/* these arguments are not registered for clearance into
|
|
|
|
* the context. so ASE_NULL is passed as the first argument
|
|
|
|
* to the constructor of the Argument class. It is because
|
|
|
|
* the reference count of these arguments are still positive
|
|
|
|
* while this function runs. However, if you ever use an
|
|
|
|
* argument outside the current context, it may cause
|
|
|
|
* a program failure such as program crash */
|
2007-10-19 14:05:00 +00:00
|
|
|
arg = (*env)->NewObject (env,
|
2007-11-02 22:16:00 +00:00
|
|
|
run_data->argument_class, run_data->argument_init,
|
2007-11-03 23:35:00 +00:00
|
|
|
ASE_NULL, (jlong)run, (jlong)v);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (arg == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk))
|
|
|
|
(*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
}
|
|
|
|
(*env)->DeleteLocalRef (env, args);
|
2007-10-24 18:57:00 +00:00
|
|
|
|
|
|
|
/* no ref-down on ret.runid as it is
|
|
|
|
* still ase_awk_val_nil */
|
|
|
|
(*env)->DeleteLocalRef (env, ret);
|
2007-10-13 15:28:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, name);
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->SetObjectArrayElement (env, args, i, arg);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (arg != ASE_NULL) (*env)->DeleteLocalRef (env, arg);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-24 18:57:00 +00:00
|
|
|
(*env)->CallVoidMethod (
|
|
|
|
env, obj, method, run_data->context_object, name, ret, args);
|
2007-10-24 00:18:00 +00:00
|
|
|
throwable = (*env)->ExceptionOccurred(env);
|
2007-10-22 00:05:00 +00:00
|
|
|
if (throwable)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-24 00:18:00 +00:00
|
|
|
jint code;
|
2007-10-22 00:05:00 +00:00
|
|
|
jstring mesg;
|
2007-10-24 00:18:00 +00:00
|
|
|
ase_char_t* rptr;
|
2007-10-22 00:05:00 +00:00
|
|
|
const jchar* ptr;
|
|
|
|
jsize len;
|
2007-10-24 00:18:00 +00:00
|
|
|
jclass class;
|
2007-10-22 00:05:00 +00:00
|
|
|
|
2007-10-24 00:18:00 +00:00
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
(*env)->DeleteLocalRef (env, args);
|
2007-10-31 22:56:00 +00:00
|
|
|
|
|
|
|
/* invoke context.clear */
|
|
|
|
(*env)->CallVoidMethod (env, run_data->context_object, run_data->context_clear);
|
|
|
|
if ((*env)->ExceptionCheck(env))
|
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
}
|
|
|
|
|
2007-10-24 18:57:00 +00:00
|
|
|
/* refdown on ret.valid is needed here */
|
|
|
|
vi = (*env)->GetLongField (env, ret, run_data->return_valid);
|
2007-11-03 23:35:00 +00:00
|
|
|
if (vi != 0)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, (ase_awk_val_t*)vi);
|
|
|
|
(*env)->SetLongField (env, ret, run_data->return_valid ,(jlong)0);
|
|
|
|
}
|
2007-10-24 18:57:00 +00:00
|
|
|
|
|
|
|
(*env)->DeleteLocalRef (env, ret);
|
2007-10-24 00:18:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, name);
|
|
|
|
|
|
|
|
class = (*env)->GetObjectClass (env, throwable);
|
|
|
|
if (!(*env)->IsSameObject(env,class,run_data->exception_class))
|
|
|
|
{
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-22 00:05:00 +00:00
|
|
|
|
|
|
|
code = (*env)->CallIntMethod (env, throwable, run_data->exception_get_code);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (code == ASE_AWK_ENOERR) code = ASE_AWK_EBFNIMPL;
|
|
|
|
|
|
|
|
/* the line information is not important in this context.
|
|
|
|
* it will be replaced by the underlying engine anyhow. */
|
|
|
|
/*line = (*env)->CallIntMethod (env, throwable, run_data->exception_get_line);*/
|
2007-10-22 00:05:00 +00:00
|
|
|
mesg = (*env)->CallObjectMethod (env, throwable, run_data->exception_get_message);
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-22 00:05:00 +00:00
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (mesg == ASE_NULL)
|
2007-10-24 00:18:00 +00:00
|
|
|
{
|
|
|
|
/* there is no message given */
|
|
|
|
ase_awk_setrunerrnum (run, code);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-24 00:18:00 +00:00
|
|
|
len = (*env)->GetStringLength (env, mesg);
|
|
|
|
ptr = (*env)->GetStringChars (env, mesg, JNI_FALSE);
|
2007-10-22 00:05:00 +00:00
|
|
|
|
2007-10-24 00:18:00 +00:00
|
|
|
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
|
|
|
{
|
|
|
|
jsize x;
|
2008-08-21 03:17:25 +00:00
|
|
|
rptr = (ase_char_t*) ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*len);
|
2007-10-25 23:43:00 +00:00
|
|
|
if (rptr == ASE_NULL)
|
2007-10-24 00:18:00 +00:00
|
|
|
{
|
|
|
|
/* ran out of memory in exception handling.
|
|
|
|
* it is freaking studid. */
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
|
|
|
|
goto error_in_exception_handler;
|
|
|
|
}
|
|
|
|
for (x = 0; x < len; x++) rptr[x] = (ase_char_t)ptr[x];
|
|
|
|
}
|
|
|
|
else rptr = (ase_char_t*)ptr;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-10-24 00:18:00 +00:00
|
|
|
ase_awk_setrunerrmsg (run, code, 0, rptr);
|
|
|
|
if (rptr != ptr) ase_awk_free (awk, rptr);
|
2007-10-22 00:05:00 +00:00
|
|
|
|
2007-10-24 00:18:00 +00:00
|
|
|
error_in_exception_handler:
|
|
|
|
(*env)->ReleaseStringChars (env, mesg, ptr);
|
|
|
|
(*env)->DeleteLocalRef (env, throwable);
|
2007-05-02 01:07:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-24 18:57:00 +00:00
|
|
|
vi = (*env)->GetLongField (env, ret, run_data->return_valid);
|
|
|
|
if (vi != 0)
|
|
|
|
{
|
|
|
|
ase_awk_setretval (run, (ase_awk_val_t*)vi);
|
2007-10-31 00:01:00 +00:00
|
|
|
|
|
|
|
/* invalidate the value field in return object */
|
2007-10-24 18:57:00 +00:00
|
|
|
ase_awk_refdownval (run, (ase_awk_val_t*)vi);
|
2007-10-31 00:01:00 +00:00
|
|
|
(*env)->SetLongField (env, ret, run_data->return_valid, (jlong)0);
|
2007-10-24 18:57:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, args);
|
2007-10-24 18:57:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, ret);
|
2007-10-13 15:28:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, name);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
(*env)->CallVoidMethod (env,
|
|
|
|
run_data->context_object, run_data->context_clear);
|
2007-10-31 22:56:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-25 00:12:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_addfunc (
|
2007-05-02 01:07:00 +00:00
|
|
|
JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args)
|
|
|
|
{
|
|
|
|
jclass class;
|
|
|
|
jfieldID handle;
|
|
|
|
jint n;
|
|
|
|
|
|
|
|
ase_awk_t* awk;
|
|
|
|
const jchar* ptr;
|
|
|
|
jsize len;
|
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* internal error. no handle field
|
|
|
|
* NoSuchFieldError, ExceptionInitializerError,
|
2007-10-17 00:30:00 +00:00
|
|
|
* OutOfMemoryError might have occurred */
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
|
|
|
|
|
|
|
|
len = (*env)->GetStringLength (env, name);
|
|
|
|
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ptr == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
|
|
|
{
|
2007-10-10 22:33:00 +00:00
|
|
|
jsize x;
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_char_t* tmp = (ase_char_t*)
|
2008-08-21 03:17:25 +00:00
|
|
|
ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*len);
|
2007-10-25 23:43:00 +00:00
|
|
|
if (tmp == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ReleaseStringChars (env, name, ptr);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-10 22:33:00 +00:00
|
|
|
for (x = 0; x < len; x++) tmp[x] = (ase_char_t)ptr[x];
|
2007-09-25 00:12:00 +00:00
|
|
|
n = (ase_awk_addfunc (awk, tmp, len, 0,
|
2007-10-25 23:43:00 +00:00
|
|
|
min_args, max_args, ASE_NULL, handle_bfn) == ASE_NULL)? -1: 0;
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_free (awk, tmp);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-25 00:12:00 +00:00
|
|
|
n = (ase_awk_addfunc (awk, (ase_char_t*)ptr, len, 0,
|
2007-10-25 23:43:00 +00:00
|
|
|
min_args, max_args, ASE_NULL, handle_bfn) == ASE_NULL)? -1: 0;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
(*env)->ReleaseStringChars (env, name, ptr);
|
2007-10-22 00:05:00 +00:00
|
|
|
if (n == -1) THROW_AWK_EXCEPTION (env, awk);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-09-25 00:12:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_delfunc (
|
2007-05-02 01:07:00 +00:00
|
|
|
JNIEnv* env, jobject obj, jstring name)
|
|
|
|
{
|
|
|
|
jclass class;
|
|
|
|
jfieldID handle;
|
|
|
|
jint n;
|
|
|
|
|
|
|
|
ase_awk_t* awk;
|
|
|
|
const jchar* ptr;
|
|
|
|
jsize len;
|
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-05-02 01:07:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* internal error. no handle field
|
|
|
|
* NoSuchFieldError, ExceptionInitializerError,
|
2007-10-17 00:30:00 +00:00
|
|
|
* OutOfMemoryError might have occurred */
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
|
|
|
|
|
|
|
|
len = (*env)->GetStringLength (env, name);
|
|
|
|
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ptr == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
|
|
|
{
|
2007-10-10 22:33:00 +00:00
|
|
|
jsize x;
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_char_t* tmp = (ase_char_t*)
|
2008-08-21 03:17:25 +00:00
|
|
|
ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*len);
|
2007-10-25 23:43:00 +00:00
|
|
|
if (tmp == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ReleaseStringChars (env, name, ptr);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-10 22:33:00 +00:00
|
|
|
for (x = 0; x < len; x++) tmp[x] = (ase_char_t)ptr[x];
|
2007-09-25 00:12:00 +00:00
|
|
|
n = ase_awk_delfunc (awk, tmp, len);
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_free (awk, tmp);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-25 00:12:00 +00:00
|
|
|
n = ase_awk_delfunc (awk, (ase_char_t*)ptr, len);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->ReleaseStringChars (env, name, ptr);
|
2007-10-22 00:05:00 +00:00
|
|
|
if (n == -1) THROW_AWK_EXCEPTION (env, awk);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth (JNIEnv* env, jobject obj, jlong awkid, jint id)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_t* awk = (ase_awk_t*)awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK_RETURNING (env, awk, 0);
|
2007-05-02 01:07:00 +00:00
|
|
|
return (jint)ase_awk_getmaxdepth (awk, id);
|
|
|
|
}
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth (JNIEnv* env, jobject obj, jlong awkid, jint ids, jint depth)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_t* awk = (ase_awk_t*)awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK (env, awk);
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_awk_setmaxdepth (awk, ids, depth);
|
|
|
|
}
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption (JNIEnv* env, jobject obj, jlong awkid)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_t* awk = (ase_awk_t*)awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK_RETURNING (env, awk, 0);
|
2007-05-02 01:07:00 +00:00
|
|
|
return ase_awk_getoption (awk);
|
|
|
|
}
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption (JNIEnv* env, jobject obj, jlong awkid, jint options)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_t* awk = (ase_awk_t*)awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK (env, awk);
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_awk_setoption (awk, (int)options);
|
|
|
|
}
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug (JNIEnv* env, jobject obj, jlong awkid)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_t* awk = (ase_awk_t*)awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK_RETURNING (env, awk, JNI_FALSE);
|
2008-07-21 06:42:39 +00:00
|
|
|
return ((awk_data_t*)ase_awk_getextension(awk))->debug? JNI_TRUE: JNI_FALSE;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug (
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEnv* env, jobject obj, jlong awkid, jboolean debug)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_t* awk = (ase_awk_t*)awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK (env, awk);
|
2008-07-21 06:42:39 +00:00
|
|
|
((awk_data_t*)ase_awk_getextension(awk))->debug = debug;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-11-09 00:08:00 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_ase_awk_Awk_getword (
|
|
|
|
JNIEnv* env, jobject obj, jlong awkid, jstring ow)
|
|
|
|
{
|
|
|
|
ase_awk_t* awk;
|
|
|
|
const jchar* ojp = ASE_NULL;
|
2007-11-11 00:30:00 +00:00
|
|
|
jsize olen = 0;
|
|
|
|
ase_size_t nlen;
|
2007-11-09 00:08:00 +00:00
|
|
|
ase_char_t* oap, * nap;
|
|
|
|
jstring ret;
|
|
|
|
|
|
|
|
awk = (ase_awk_t*) awkid;
|
|
|
|
EXCEPTION_ON_ASE_NULL_AWK_RETURNING (env, awk, ASE_NULL);
|
|
|
|
|
|
|
|
if (ow == ASE_NULL) return ASE_NULL;
|
|
|
|
|
|
|
|
if (get_str(env,awk,ow,&ojp,&oap,&olen) == -1)
|
|
|
|
{
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return ASE_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ase_awk_getword (awk, oap, olen, &nap, &nlen) == -1)
|
|
|
|
{
|
|
|
|
free_str (env, awk, ow, ojp, oap);
|
|
|
|
return ASE_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_str (env, awk, ow, ojp, oap);
|
|
|
|
|
|
|
|
ret = new_str (env, awk, nap, nlen);
|
|
|
|
if (ret == ASE_NULL) THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-06-25 23:15:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_setword (
|
2007-10-19 14:05:00 +00:00
|
|
|
JNIEnv* env, jobject obj, jlong awkid, jstring ow, jstring nw)
|
2007-06-25 23:15:00 +00:00
|
|
|
{
|
|
|
|
ase_awk_t* awk;
|
2007-11-09 00:08:00 +00:00
|
|
|
const jchar* ojp = ASE_NULL, * njp = ASE_NULL;
|
|
|
|
jsize olen = 0, nlen = 0;
|
|
|
|
ase_char_t* oap = ASE_NULL, * nap = ASE_NULL;
|
2007-06-25 23:15:00 +00:00
|
|
|
jint r;
|
|
|
|
|
2007-10-19 14:05:00 +00:00
|
|
|
awk = (ase_awk_t*) awkid;
|
2007-10-24 23:17:00 +00:00
|
|
|
EXCEPTION_ON_ASE_NULL_AWK (env, awk);
|
2007-06-25 23:15:00 +00:00
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ow != ASE_NULL)
|
2007-06-25 23:15:00 +00:00
|
|
|
{
|
2007-11-09 00:08:00 +00:00
|
|
|
if (get_str(env,awk,ow,&ojp,&oap,&olen) == -1)
|
2007-06-29 20:40:00 +00:00
|
|
|
{
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-06-29 20:40:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-06-25 23:15:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (nw != ASE_NULL)
|
2007-06-25 23:15:00 +00:00
|
|
|
{
|
2007-11-09 00:08:00 +00:00
|
|
|
if (get_str(env,awk,nw,&njp,&nap,&nlen) == -1)
|
2007-06-29 20:40:00 +00:00
|
|
|
{
|
2007-11-09 00:08:00 +00:00
|
|
|
if (ow != ASE_NULL) free_str (env, awk, ow, ojp, oap);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-06-29 20:40:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-06-25 23:15:00 +00:00
|
|
|
}
|
|
|
|
|
2007-11-09 00:08:00 +00:00
|
|
|
r = ase_awk_setword (awk, oap, olen, nap, nlen);
|
2007-06-25 23:15:00 +00:00
|
|
|
|
2007-11-09 00:08:00 +00:00
|
|
|
if (nw != ASE_NULL) free_str (env, awk, nw, njp, nap);
|
|
|
|
if (ow != ASE_NULL) free_str (env, awk, ow, ojp, oap);
|
2007-06-25 23:15:00 +00:00
|
|
|
|
2007-10-22 00:05:00 +00:00
|
|
|
if (r == -1) THROW_AWK_EXCEPTION (env, awk);
|
2007-06-25 23:15:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename (
|
|
|
|
JNIEnv* env, jobject obj, jlong runid, jstring name)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
const jchar* ptr;
|
|
|
|
jsize len;
|
|
|
|
jint n;
|
|
|
|
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_t* awk = ase_awk_getrunawk (run);
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
len = (*env)->GetStringLength (env, name);
|
|
|
|
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ptr == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
|
|
|
{
|
2007-10-10 22:33:00 +00:00
|
|
|
jsize x;
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_char_t* tmp = (ase_char_t*)
|
2008-08-21 03:17:25 +00:00
|
|
|
ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*len);
|
2007-10-25 23:43:00 +00:00
|
|
|
if (tmp == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ReleaseStringChars (env, name, ptr);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-10 22:33:00 +00:00
|
|
|
for (x = 0; x < len; x++) tmp[x] = (ase_char_t)ptr[x];
|
2007-05-02 01:07:00 +00:00
|
|
|
n = ase_awk_setfilename (run, tmp, len);
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_free (awk, tmp);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = ase_awk_setfilename (run, (ase_char_t*)ptr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->ReleaseStringChars (env, name, ptr);
|
|
|
|
|
2007-10-22 00:05:00 +00:00
|
|
|
if (n == -1) THROW_RUN_EXCEPTION (env, run);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename (
|
|
|
|
JNIEnv* env, jobject obj, jlong runid, jstring name)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
const jchar* ptr;
|
|
|
|
jsize len;
|
|
|
|
jint n;
|
|
|
|
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_t* awk = ase_awk_getrunawk (run);
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
len = (*env)->GetStringLength (env, name);
|
|
|
|
ptr = (*env)->GetStringChars (env, name, JNI_FALSE);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ptr == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
|
|
|
{
|
2007-10-10 22:33:00 +00:00
|
|
|
jsize x;
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_char_t* tmp = (ase_char_t*)
|
2008-08-21 03:17:25 +00:00
|
|
|
ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*len);
|
2007-10-25 23:43:00 +00:00
|
|
|
if (tmp == ASE_NULL)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ReleaseStringChars (env, name, ptr);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-02 01:07:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-10 22:33:00 +00:00
|
|
|
for (x = 0; x < len; x++) tmp[x] = (ase_char_t)ptr[x];
|
2007-05-02 01:07:00 +00:00
|
|
|
n = ase_awk_setofilename (run, tmp, len);
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_free (awk, tmp);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = ase_awk_setofilename (run, (ase_char_t*)ptr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->ReleaseStringChars (env, name, ptr);
|
|
|
|
|
2007-10-22 00:05:00 +00:00
|
|
|
if (n == -1) THROW_RUN_EXCEPTION (env, run);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-26 01:30:00 +00:00
|
|
|
static jstring JNICALL call_strftime (
|
|
|
|
JNIEnv* env, jobject obj, jstring fmt, struct tm* tm)
|
|
|
|
{
|
|
|
|
ase_char_t buf[128];
|
|
|
|
ase_size_t len, i;
|
|
|
|
const jchar* ptr;
|
|
|
|
ase_char_t* tmp;
|
|
|
|
jstring ret;
|
|
|
|
|
2007-10-15 01:34:00 +00:00
|
|
|
jclass class;
|
|
|
|
jfieldID handle;
|
|
|
|
ase_awk_t* awk;
|
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-10-15 01:34:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-10-15 01:34:00 +00:00
|
|
|
{
|
|
|
|
/* internal error. no handle field
|
|
|
|
* NoSuchFieldError, ExceptionInitializerError,
|
2007-10-17 00:30:00 +00:00
|
|
|
* OutOfMemoryError might have occurred */
|
2007-10-24 23:17:00 +00:00
|
|
|
return ASE_NULL;
|
2007-10-15 01:34:00 +00:00
|
|
|
}
|
|
|
|
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
|
|
|
|
|
2007-05-26 01:30:00 +00:00
|
|
|
len = (*env)->GetStringLength (env, fmt);
|
|
|
|
ptr = (*env)->GetStringChars (env, fmt, JNI_FALSE);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ptr == ASE_NULL)
|
2007-05-26 01:30:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-10-24 23:17:00 +00:00
|
|
|
return ASE_NULL;
|
2007-05-26 01:30:00 +00:00
|
|
|
}
|
|
|
|
|
2008-08-21 03:17:25 +00:00
|
|
|
tmp = (ase_char_t*) ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*(len+1));
|
2007-10-24 23:17:00 +00:00
|
|
|
if (tmp == ASE_NULL)
|
2007-05-26 01:30:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ReleaseStringChars (env, fmt, ptr);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-10-24 23:17:00 +00:00
|
|
|
return ASE_NULL;
|
2007-05-26 01:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i];
|
|
|
|
tmp[i] = ASE_T('\0');
|
|
|
|
|
|
|
|
len = wcsftime (buf, ASE_COUNTOF(buf), tmp, tm);
|
|
|
|
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_free (awk, tmp);
|
2007-05-26 01:30:00 +00:00
|
|
|
(*env)->ReleaseStringChars (env, fmt, ptr);
|
|
|
|
|
2007-11-09 00:08:00 +00:00
|
|
|
ret = new_str (env, awk, buf, len);
|
|
|
|
if (ret == ASE_NULL) THROW_NOMEM_EXCEPTION (env);
|
2007-05-26 01:30:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_ase_awk_Awk_strftime (
|
|
|
|
JNIEnv* env, jobject obj, jstring fmt, jlong sec)
|
|
|
|
{
|
|
|
|
struct tm* tm;
|
|
|
|
time_t t = (time_t)sec;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
tm = localtime (&t);
|
|
|
|
#else
|
|
|
|
struct tm tmb;
|
|
|
|
tm = localtime_r (&t, &tmb);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return call_strftime (env, obj, fmt, tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_ase_awk_Awk_strfgmtime (
|
|
|
|
JNIEnv* env, jobject obj, jstring fmt, jlong sec)
|
|
|
|
{
|
|
|
|
struct tm* tm;
|
|
|
|
time_t t = (time_t)sec;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
tm = gmtime (&t);
|
|
|
|
#else
|
|
|
|
struct tm tmb;
|
|
|
|
tm = gmtime_r (&t, &tmb);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return call_strftime (env, obj, fmt, tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ase_awk_Awk_system (
|
|
|
|
JNIEnv* env, jobject obj, jstring cmd)
|
|
|
|
{
|
|
|
|
ase_size_t len, i;
|
|
|
|
const jchar* ptr;
|
|
|
|
ase_char_t* tmp;
|
|
|
|
jint ret;
|
|
|
|
|
2007-10-15 01:34:00 +00:00
|
|
|
jclass class;
|
|
|
|
jfieldID handle;
|
|
|
|
ase_awk_t* awk;
|
|
|
|
|
|
|
|
class = (*env)->GetObjectClass(env, obj);
|
2007-10-17 00:30:00 +00:00
|
|
|
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
|
2007-10-15 01:34:00 +00:00
|
|
|
(*env)->DeleteLocalRef (env, class);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (handle == ASE_NULL)
|
2007-10-15 01:34:00 +00:00
|
|
|
{
|
|
|
|
/* internal error. no handle field
|
|
|
|
* NoSuchFieldError, ExceptionInitializerError,
|
2007-10-17 00:30:00 +00:00
|
|
|
* OutOfMemoryError might have occurred */
|
2007-10-15 01:34:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle);
|
|
|
|
|
2007-05-26 21:41:00 +00:00
|
|
|
len = (*env)->GetStringLength (env, cmd);
|
|
|
|
ptr = (*env)->GetStringChars (env, cmd, JNI_FALSE);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ptr == ASE_NULL)
|
2007-05-26 01:30:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ExceptionClear (env);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-26 21:41:00 +00:00
|
|
|
return -1;
|
2007-05-26 01:30:00 +00:00
|
|
|
}
|
|
|
|
|
2008-08-21 03:17:25 +00:00
|
|
|
tmp = (ase_char_t*) ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*(len+1));
|
2007-10-24 23:17:00 +00:00
|
|
|
if (tmp == ASE_NULL)
|
2007-05-26 01:30:00 +00:00
|
|
|
{
|
2007-05-26 21:41:00 +00:00
|
|
|
(*env)->ReleaseStringChars (env, cmd, ptr);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-05-26 21:41:00 +00:00
|
|
|
return -1;
|
2007-05-26 01:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i];
|
|
|
|
tmp[i] = ASE_T('\0');
|
|
|
|
|
2007-06-25 23:15:00 +00:00
|
|
|
(*env)->ReleaseStringChars (env, cmd, ptr);
|
|
|
|
|
2007-05-26 01:30:00 +00:00
|
|
|
#ifdef _WIN32
|
2007-05-26 21:41:00 +00:00
|
|
|
ret = _tsystem(tmp);
|
2007-05-26 01:30:00 +00:00
|
|
|
#else
|
2008-08-21 03:17:25 +00:00
|
|
|
char* mbs = (char*)ase_awk_alloc (awk, len*5+1);
|
2007-10-25 23:43:00 +00:00
|
|
|
if (mbs == ASE_NULL)
|
2007-10-15 01:34:00 +00:00
|
|
|
{
|
|
|
|
ase_awk_free (awk, tmp);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-05-26 01:30:00 +00:00
|
|
|
|
2007-05-26 21:41:00 +00:00
|
|
|
size_t mbl = wcstombs (mbs, tmp, len*5);
|
2007-09-25 20:25:00 +00:00
|
|
|
if (mbl == (size_t)-1)
|
|
|
|
{
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_free (awk, mbs);
|
|
|
|
ase_awk_free (awk, tmp);
|
2007-09-25 20:25:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-05-26 01:30:00 +00:00
|
|
|
mbs[mbl] = '\0';
|
|
|
|
ret = system(mbs);
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_free (awk, mbs);
|
2007-05-26 01:30:00 +00:00
|
|
|
#endif
|
|
|
|
|
2007-10-15 01:34:00 +00:00
|
|
|
ase_awk_free (awk, tmp);
|
2007-05-26 01:30:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2007-10-18 23:51:00 +00:00
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Context_stop (JNIEnv* env, jobject obj, jlong runid)
|
|
|
|
{
|
|
|
|
ase_awk_stop ((ase_awk_run_t*)runid);
|
|
|
|
}
|
|
|
|
|
2007-10-31 00:01:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Context_setglobal (JNIEnv* env, jobject obj, jlong runid, jint id, jobject ret)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
run_data_t* run_data;
|
2007-11-02 22:16:00 +00:00
|
|
|
ase_awk_val_t* v;
|
2007-10-31 00:01:00 +00:00
|
|
|
jlong vi;
|
|
|
|
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
|
|
|
|
|
|
|
vi = (*env)->GetLongField (env, ret, run_data->return_valid);
|
2007-11-02 22:16:00 +00:00
|
|
|
v = (vi == 0)? ase_awk_val_nil: (ase_awk_val_t*)vi;
|
|
|
|
/* invalidate the value field in the return object */
|
|
|
|
(*env)->SetLongField (env, ret, run_data->return_valid, (jlong)0);
|
|
|
|
|
|
|
|
if (ase_awk_setglobal(run,id,v) == -1)
|
2007-10-31 00:01:00 +00:00
|
|
|
{
|
2007-11-02 22:16:00 +00:00
|
|
|
if (vi != 0) ase_awk_refdownval (run, v);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
2007-10-31 00:01:00 +00:00
|
|
|
|
2007-11-02 22:16:00 +00:00
|
|
|
if (vi != 0) ase_awk_refdownval (run, v);
|
|
|
|
}
|
2007-10-31 00:01:00 +00:00
|
|
|
|
2007-11-02 22:16:00 +00:00
|
|
|
JNIEXPORT jobject JNICALL Java_ase_awk_Context_getglobal (JNIEnv* env, jobject obj, jlong runid, jint id)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_t* awk;
|
|
|
|
run_data_t* run_data;
|
|
|
|
ase_awk_val_t* g;
|
|
|
|
jobject arg;
|
|
|
|
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
|
|
|
awk = ase_awk_getrunawk (run);
|
|
|
|
|
|
|
|
g = ase_awk_getglobal(run, id);
|
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
ASE_ASSERTX ((*env)->IsSameObject(env,obj,run_data->context_object),
|
|
|
|
"this object(obj) should be the same object as the context object(run_data->context_object)");
|
|
|
|
|
2007-11-02 22:16:00 +00:00
|
|
|
arg = (*env)->NewObject (env,
|
|
|
|
run_data->argument_class, run_data->argument_init,
|
2007-11-03 23:35:00 +00:00
|
|
|
obj, (jlong)run, (jlong)g);
|
2007-11-02 22:16:00 +00:00
|
|
|
if (arg == ASE_NULL)
|
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return ASE_NULL;
|
2007-10-31 00:01:00 +00:00
|
|
|
}
|
2007-11-02 22:16:00 +00:00
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
/* the reference is incremented. this incremented reference is
|
|
|
|
* decremented in Argument.clear called from Context.clear.
|
|
|
|
* Note that the context object (obj) is passed to the contrustor of
|
|
|
|
* the argument class in the call to NewObject above */
|
|
|
|
ase_awk_refupval (run, g);
|
2007-11-02 22:16:00 +00:00
|
|
|
return arg;
|
2007-10-31 00:01:00 +00:00
|
|
|
}
|
2007-10-18 23:51:00 +00:00
|
|
|
|
2007-10-20 00:02:00 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_ase_awk_Argument_getintval (JNIEnv* env, jobject obj, jlong runid, jlong valid)
|
2007-10-18 23:51:00 +00:00
|
|
|
{
|
2007-10-21 00:06:00 +00:00
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
2007-10-18 23:51:00 +00:00
|
|
|
int n;
|
2007-10-22 00:05:00 +00:00
|
|
|
ase_long_t lv = 0;
|
|
|
|
ase_real_t rv = 0.0;
|
2007-10-18 23:51:00 +00:00
|
|
|
|
2007-10-24 00:18:00 +00:00
|
|
|
n = ase_awk_valtonum (run, (ase_awk_val_t*)valid, &lv, &rv);
|
2007-10-22 00:05:00 +00:00
|
|
|
if (n == -1) THROW_RUN_EXCEPTION (env, run);
|
|
|
|
else if (n == 1) lv = (ase_long_t)rv;
|
2007-10-18 23:51:00 +00:00
|
|
|
|
|
|
|
return (jlong)lv;
|
|
|
|
}
|
|
|
|
|
2007-10-20 00:02:00 +00:00
|
|
|
JNIEXPORT jdouble JNICALL Java_ase_awk_Argument_getrealval (JNIEnv* env, jobject obj, jlong runid, jlong valid)
|
2007-10-18 23:51:00 +00:00
|
|
|
{
|
2007-10-21 00:06:00 +00:00
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
2007-10-18 23:51:00 +00:00
|
|
|
int n;
|
2007-10-22 00:05:00 +00:00
|
|
|
ase_long_t lv = 0;
|
|
|
|
ase_real_t rv = 0.0;
|
2007-10-18 23:51:00 +00:00
|
|
|
|
2007-10-24 00:18:00 +00:00
|
|
|
n = ase_awk_valtonum (run, (ase_awk_val_t*)valid, &lv, &rv);
|
2007-10-22 00:05:00 +00:00
|
|
|
if (n == -1) THROW_RUN_EXCEPTION (env, run);
|
|
|
|
else if (n == 0) rv = (ase_real_t)lv;
|
2007-10-18 23:51:00 +00:00
|
|
|
|
|
|
|
return (jdouble)rv;
|
|
|
|
}
|
|
|
|
|
2007-10-20 00:02:00 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_ase_awk_Argument_getstrval (JNIEnv* env, jobject obj, jlong runid, jlong valid)
|
2007-10-18 23:51:00 +00:00
|
|
|
{
|
2007-10-19 14:05:00 +00:00
|
|
|
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);
|
|
|
|
|
2007-10-18 23:51:00 +00:00
|
|
|
ase_char_t* str;
|
|
|
|
ase_size_t len;
|
2007-10-24 23:17:00 +00:00
|
|
|
jstring ret = ASE_NULL;
|
2007-10-18 23:51:00 +00:00
|
|
|
|
|
|
|
str = ase_awk_valtostr (
|
2007-10-25 23:43:00 +00:00
|
|
|
run, val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len);
|
|
|
|
if (str == ASE_NULL)
|
2007-10-21 00:06:00 +00:00
|
|
|
{
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
2007-10-21 00:06:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2007-10-18 23:51:00 +00:00
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
ret = new_str (env, awk, str, len);
|
2007-10-19 14:05:00 +00:00
|
|
|
ase_awk_free (awk, str);
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ret == ASE_NULL)
|
2007-10-19 14:05:00 +00:00
|
|
|
{
|
2007-11-11 00:30:00 +00:00
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-10-19 14:05:00 +00:00
|
|
|
}
|
2007-10-18 23:51:00 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2007-10-21 00:06:00 +00:00
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_ase_awk_Argument_isindexed (JNIEnv* env, jobject obj, jlong runid, jlong valid)
|
|
|
|
{
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
2007-10-22 00:05:00 +00:00
|
|
|
return (ASE_AWK_VAL_TYPE(val) == ASE_AWK_VAL_MAP)? JNI_TRUE: JNI_FALSE;
|
2007-10-21 00:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL Java_ase_awk_Argument_getindexed (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring index)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
run_data_t* run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-10-21 00:06:00 +00:00
|
|
|
jobject arg;
|
|
|
|
|
|
|
|
const jchar* ptr;
|
|
|
|
ase_char_t* rptr;
|
|
|
|
ase_size_t len;
|
|
|
|
|
2007-10-25 23:43:00 +00:00
|
|
|
if (ASE_AWK_VAL_TYPE(val) != ASE_AWK_VAL_MAP) return ASE_NULL;
|
2007-10-21 00:06:00 +00:00
|
|
|
|
|
|
|
len = (*env)->GetStringLength (env, index);
|
|
|
|
ptr = (*env)->GetStringChars (env, index, JNI_FALSE);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (ptr == ASE_NULL) goto nomem;
|
2007-10-21 00:06:00 +00:00
|
|
|
|
|
|
|
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
|
|
|
{
|
|
|
|
ase_size_t x;
|
2008-08-21 03:17:25 +00:00
|
|
|
rptr = (ase_char_t*) ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*len);
|
2007-10-25 23:43:00 +00:00
|
|
|
if (rptr == ASE_NULL)
|
2007-10-21 00:06:00 +00:00
|
|
|
{
|
|
|
|
(*env)->ReleaseStringChars (env, index, ptr);
|
|
|
|
goto nomem;
|
|
|
|
}
|
|
|
|
for (x = 0; x < len; x++) rptr[x] = (ase_char_t)ptr[x];
|
|
|
|
}
|
|
|
|
else rptr = (ase_char_t*)ptr;
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ase_map_get (((ase_awk_val_map_t*)val)->map, rptr, len);
|
2007-10-21 00:06:00 +00:00
|
|
|
if (ptr != rptr) ase_awk_free (awk, rptr);
|
|
|
|
(*env)->ReleaseStringChars (env, index, ptr);
|
|
|
|
|
|
|
|
/* the key is not found. it is not an error. val is just nil */
|
2007-10-25 23:43:00 +00:00
|
|
|
if (pair == ASE_NULL) return ASE_NULL;;
|
2007-10-21 00:06:00 +00:00
|
|
|
|
|
|
|
arg = (*env)->NewObject (env,
|
2007-11-02 22:16:00 +00:00
|
|
|
run_data->argument_class, run_data->argument_init,
|
2007-11-03 23:35:00 +00:00
|
|
|
run_data->context_object, (jlong)run, (jlong)pair->val);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (arg == ASE_NULL) goto nomem;
|
2007-10-21 00:06:00 +00:00
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
/* the reference is incremented. this incremented reference is
|
|
|
|
* decremented in Argument.clear called from Context.clear.
|
|
|
|
* Note that the context object (run_data->context_object) is
|
|
|
|
* passed to the contrustor of the argument class in the call
|
|
|
|
* to NewObject above */
|
|
|
|
ase_awk_refupval (run, pair->val);
|
2007-10-21 00:06:00 +00:00
|
|
|
return arg;
|
|
|
|
|
|
|
|
nomem:
|
2007-10-24 00:18:00 +00:00
|
|
|
if ((*env)->ExceptionCheck(env))
|
2007-10-21 00:06:00 +00:00
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
}
|
|
|
|
|
2007-10-22 00:05:00 +00:00
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
2007-10-25 23:43:00 +00:00
|
|
|
return ASE_NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-03 23:35:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Argument_clearval (JNIEnv* env, jobject obj, jlong runid, jlong valid)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
|
|
|
run_data_t* run_data;
|
|
|
|
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
|
|
|
|
|
|
|
if (val != ASE_NULL) ase_awk_refdownval (run, val);
|
|
|
|
(*env)->SetLongField (env, obj, run_data->argument_valid, (jlong)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-25 23:43:00 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_ase_awk_Return_isindexed (JNIEnv* env, jobject obj, jlong runid, jlong valid)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
|
|
|
|
|
|
|
return (val != ASE_NULL && ASE_AWK_VAL_TYPE(val) == ASE_AWK_VAL_MAP)? JNI_TRUE: JNI_FALSE;
|
2007-10-21 00:06:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-24 00:18:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Return_setintval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jlong newval)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
|
|
|
ase_awk_val_t* nv;
|
2007-10-24 23:17:00 +00:00
|
|
|
run_data_t* run_data;
|
|
|
|
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
2007-10-24 00:18:00 +00:00
|
|
|
|
|
|
|
nv = ase_awk_makeintval (run, newval);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (nv == ASE_NULL)
|
2007-10-24 00:18:00 +00:00
|
|
|
{
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (val != ASE_NULL) ase_awk_refdownval (run, val);
|
2007-10-24 00:18:00 +00:00
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
(*env)->SetLongField (env, obj, run_data->return_valid, (jlong)nv);
|
|
|
|
ase_awk_refupval (run, nv);
|
2007-10-24 00:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Return_setrealval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jdouble newval)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
|
|
|
ase_awk_val_t* nv;
|
2007-10-24 23:17:00 +00:00
|
|
|
run_data_t* run_data;
|
|
|
|
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
2007-10-24 00:18:00 +00:00
|
|
|
|
|
|
|
nv = ase_awk_makerealval (run, newval);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (nv == ASE_NULL)
|
2007-10-24 00:18:00 +00:00
|
|
|
{
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (val != ASE_NULL) ase_awk_refdownval (run, val);
|
2007-10-24 00:18:00 +00:00
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
(*env)->SetLongField (env, obj, run_data->return_valid, (jlong)nv);
|
|
|
|
ase_awk_refupval (run, nv);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Return_setstrval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring newval)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
|
|
|
ase_awk_val_t* nv;
|
|
|
|
ase_awk_t* awk;
|
|
|
|
run_data_t* run_data;
|
|
|
|
|
|
|
|
const jchar* jptr;
|
|
|
|
ase_char_t* aptr;
|
|
|
|
jsize len;
|
|
|
|
|
|
|
|
awk = ase_awk_getrunawk (run);
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
|
|
|
|
|
|
|
if (get_str(env,awk,newval,&jptr,&aptr,&len) == -1)
|
|
|
|
{
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nv = (ase_awk_val_t*)ase_awk_makestrval (run, aptr, len);
|
|
|
|
if (nv == ASE_NULL)
|
2007-10-24 00:18:00 +00:00
|
|
|
{
|
2007-10-24 23:17:00 +00:00
|
|
|
free_str (env, awk, newval, jptr, aptr);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
2007-10-24 00:18:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
free_str (env, awk, newval, jptr, aptr);
|
|
|
|
if (val != ASE_NULL) ase_awk_refdownval (run, val);
|
|
|
|
|
|
|
|
(*env)->SetLongField (env, obj, run_data->return_valid, (jlong)nv);
|
2007-10-24 18:57:00 +00:00
|
|
|
ase_awk_refupval (run, nv);
|
2007-10-24 00:18:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedintval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring index, jlong newval)
|
2007-10-24 00:18:00 +00:00
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
2007-10-24 23:17:00 +00:00
|
|
|
ase_awk_t* awk;
|
|
|
|
run_data_t* run_data;
|
2007-10-24 00:18:00 +00:00
|
|
|
|
2007-10-25 23:43:00 +00:00
|
|
|
int opt;
|
|
|
|
const jchar* jptr;
|
|
|
|
ase_char_t* aptr;
|
|
|
|
jsize len;
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
awk = ase_awk_getrunawk (run);
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
|
|
|
|
2007-10-25 23:43:00 +00:00
|
|
|
opt = ase_awk_getoption (awk);
|
|
|
|
if ((opt & ASE_AWK_MAPTOVAR) != ASE_AWK_MAPTOVAR)
|
2007-10-24 00:18:00 +00:00
|
|
|
{
|
2007-10-25 23:43:00 +00:00
|
|
|
/* refer to run_return in run.c */
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_EMAPNOTALLOWED);
|
2007-10-24 00:18:00 +00:00
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-25 23:43:00 +00:00
|
|
|
if (val == ASE_NULL || ASE_AWK_VAL_TYPE(val) != ASE_AWK_VAL_MAP)
|
2007-10-24 23:17:00 +00:00
|
|
|
{
|
2007-10-25 23:43:00 +00:00
|
|
|
ase_awk_val_t* x;
|
|
|
|
ase_awk_val_t* x2;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-10-25 23:43:00 +00:00
|
|
|
|
|
|
|
x = ase_awk_makemapval (run);
|
|
|
|
if (x == ASE_NULL)
|
2007-10-24 23:17:00 +00:00
|
|
|
{
|
2007-10-25 23:43:00 +00:00
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ase_awk_refupval (run, x);
|
|
|
|
|
|
|
|
x2 = ase_awk_makeintval (run, newval);
|
|
|
|
if (x2 == ASE_NULL)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ase_awk_refupval (run, x2);
|
|
|
|
|
|
|
|
if (get_str(env,awk,index,&jptr,&aptr,&len) == -1)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ase_map_put (
|
2007-10-25 23:43:00 +00:00
|
|
|
((ase_awk_val_map_t*)x)->map, aptr, len, x2);
|
|
|
|
free_str (env, awk, index, jptr, aptr);
|
|
|
|
if (pair == ASE_NULL)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val != ASE_NULL) ase_awk_refdownval (run, val);
|
|
|
|
(*env)->SetLongField (env, obj, run_data->return_valid, (jlong)x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ase_awk_val_t* x2;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-10-25 23:43:00 +00:00
|
|
|
|
|
|
|
x2 = ase_awk_makeintval (run, newval);
|
|
|
|
if (x2 == ASE_NULL)
|
|
|
|
{
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ase_awk_refupval (run, x2);
|
|
|
|
|
|
|
|
if (get_str(env,awk,index,&jptr,&aptr,&len) == -1)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ase_map_put (
|
2007-10-25 23:43:00 +00:00
|
|
|
((ase_awk_val_map_t*)val)->map, aptr, len, x2);
|
|
|
|
free_str (env, awk, index, jptr, aptr);
|
|
|
|
if (pair == ASE_NULL)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
2007-10-24 23:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-24 00:18:00 +00:00
|
|
|
|
2007-10-25 23:43:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedrealval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring index, jdouble newval)
|
2007-10-24 23:17:00 +00:00
|
|
|
{
|
2007-10-25 23:43:00 +00:00
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
|
|
|
ase_awk_t* awk;
|
|
|
|
run_data_t* run_data;
|
|
|
|
|
|
|
|
int opt;
|
|
|
|
const jchar* jptr;
|
|
|
|
ase_char_t* aptr;
|
|
|
|
jsize len;
|
|
|
|
|
|
|
|
awk = ase_awk_getrunawk (run);
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
|
|
|
|
|
|
|
opt = ase_awk_getoption (awk);
|
|
|
|
if ((opt & ASE_AWK_MAPTOVAR) != ASE_AWK_MAPTOVAR)
|
|
|
|
{
|
|
|
|
/* refer to run_return in run.c */
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_EMAPNOTALLOWED);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val == ASE_NULL || ASE_AWK_VAL_TYPE(val) != ASE_AWK_VAL_MAP)
|
|
|
|
{
|
|
|
|
ase_awk_val_t* x;
|
|
|
|
ase_awk_val_t* x2;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-10-25 23:43:00 +00:00
|
|
|
|
|
|
|
x = ase_awk_makemapval (run);
|
|
|
|
if (x == ASE_NULL)
|
|
|
|
{
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ase_awk_refupval (run, x);
|
|
|
|
|
|
|
|
x2 = ase_awk_makerealval (run, newval);
|
|
|
|
if (x2 == ASE_NULL)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ase_awk_refupval (run, x2);
|
|
|
|
|
|
|
|
if (get_str(env,awk,index,&jptr,&aptr,&len) == -1)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ase_map_put (
|
2007-10-25 23:43:00 +00:00
|
|
|
((ase_awk_val_map_t*)x)->map, aptr, len, x2);
|
|
|
|
free_str (env, awk, index, jptr, aptr);
|
|
|
|
if (pair == ASE_NULL)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val != ASE_NULL) ase_awk_refdownval (run, val);
|
|
|
|
(*env)->SetLongField (env, obj, run_data->return_valid, (jlong)x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ase_awk_val_t* x2;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-10-25 23:43:00 +00:00
|
|
|
|
|
|
|
x2 = ase_awk_makerealval (run, newval);
|
|
|
|
if (x2 == ASE_NULL)
|
|
|
|
{
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
2007-10-24 23:17:00 +00:00
|
|
|
|
2007-10-25 23:43:00 +00:00
|
|
|
ase_awk_refupval (run, x2);
|
|
|
|
|
|
|
|
if (get_str(env,awk,index,&jptr,&aptr,&len) == -1)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ase_map_put (
|
2007-10-25 23:43:00 +00:00
|
|
|
((ase_awk_val_map_t*)val)->map, aptr, len, x2);
|
|
|
|
free_str (env, awk, index, jptr, aptr);
|
|
|
|
if (pair == ASE_NULL)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-10-24 23:17:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-25 23:43:00 +00:00
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedstrval (JNIEnv* env, jobject obj, jlong runid, jlong valid, jstring index, jstring newval)
|
2007-10-24 23:17:00 +00:00
|
|
|
{
|
2007-10-25 23:43:00 +00:00
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
|
|
|
ase_awk_t* awk;
|
|
|
|
run_data_t* run_data;
|
|
|
|
|
|
|
|
int opt;
|
|
|
|
const jchar* jptr;
|
|
|
|
ase_char_t* aptr;
|
|
|
|
jsize len;
|
|
|
|
|
|
|
|
awk = ase_awk_getrunawk (run);
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
|
|
|
|
|
|
|
opt = ase_awk_getoption (awk);
|
|
|
|
if ((opt & ASE_AWK_MAPTOVAR) != ASE_AWK_MAPTOVAR)
|
|
|
|
{
|
|
|
|
/* refer to run_return in run.c */
|
|
|
|
ase_awk_setrunerrnum (run, ASE_AWK_EMAPNOTALLOWED);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val == ASE_NULL || ASE_AWK_VAL_TYPE(val) != ASE_AWK_VAL_MAP)
|
|
|
|
{
|
|
|
|
ase_awk_val_t* x;
|
|
|
|
ase_awk_val_t* x2;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-10-25 23:43:00 +00:00
|
|
|
|
|
|
|
x = ase_awk_makemapval (run);
|
|
|
|
if (x == ASE_NULL)
|
|
|
|
{
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ase_awk_refupval (run, x);
|
|
|
|
|
|
|
|
if (get_str(env,awk,newval,&jptr,&aptr,&len) == -1)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
x2 = ase_awk_makestrval (run, aptr, len);
|
|
|
|
free_str (env, awk, index, jptr, aptr);
|
|
|
|
if (x2 == ASE_NULL)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ase_awk_refupval (run, x2);
|
|
|
|
|
|
|
|
if (get_str(env,awk,index,&jptr,&aptr,&len) == -1)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ase_map_put (
|
2007-10-25 23:43:00 +00:00
|
|
|
((ase_awk_val_map_t*)x)->map, aptr, len, x2);
|
|
|
|
free_str (env, awk, index, jptr, aptr);
|
|
|
|
if (pair == ASE_NULL)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
ase_awk_refdownval (run, x);
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val != ASE_NULL) ase_awk_refdownval (run, val);
|
|
|
|
(*env)->SetLongField (env, obj, run_data->return_valid, (jlong)x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ase_awk_val_t* x2;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-10-25 23:43:00 +00:00
|
|
|
|
|
|
|
if (get_str(env,awk,newval,&jptr,&aptr,&len) == -1)
|
|
|
|
{
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
x2 = ase_awk_makestrval (run, aptr, len);
|
|
|
|
free_str (env, awk, index, jptr, aptr);
|
|
|
|
if (x2 == ASE_NULL)
|
|
|
|
{
|
|
|
|
THROW_RUN_EXCEPTION (env, run);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ase_awk_refupval (run, x2);
|
|
|
|
|
|
|
|
if (get_str(env,awk,index,&jptr,&aptr,&len) == -1)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ase_map_put (
|
2007-10-25 23:43:00 +00:00
|
|
|
((ase_awk_val_map_t*)val)->map, aptr, len, x2);
|
|
|
|
free_str (env, awk, index, jptr, aptr);
|
|
|
|
if (pair == ASE_NULL)
|
|
|
|
{
|
|
|
|
ase_awk_refdownval (run, x2);
|
|
|
|
THROW_NOMEM_EXCEPTION (env);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-10-24 23:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_ase_awk_Return_clearval (JNIEnv* env, jobject obj, jlong runid, jlong valid)
|
|
|
|
{
|
|
|
|
ase_awk_run_t* run = (ase_awk_run_t*)runid;
|
|
|
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
|
|
|
run_data_t* run_data;
|
|
|
|
|
|
|
|
run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
|
|
|
|
|
|
|
if (val != ASE_NULL) ase_awk_refdownval (run, val);
|
|
|
|
(*env)->SetLongField (env, obj, run_data->return_valid, (jlong)0);
|
|
|
|
}
|
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
static ase_char_t* dup_str (ase_awk_t* awk, const jchar* str, ase_size_t len)
|
|
|
|
{
|
|
|
|
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
|
|
|
{
|
|
|
|
ase_char_t* tmp;
|
|
|
|
ase_size_t i;
|
|
|
|
|
2008-08-21 03:17:25 +00:00
|
|
|
tmp = (ase_char_t*) ase_awk_alloc (awk, (len+1) * ASE_SIZEOF(ase_char_t));
|
2007-11-11 00:30:00 +00:00
|
|
|
if (tmp == ASE_NULL) return ASE_NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < (ase_size_t)len; i++) tmp[i] = (ase_char_t)str[i];
|
|
|
|
tmp[i] = ASE_T('\0');
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ase_char_t* tmp;
|
|
|
|
|
2008-08-21 03:17:25 +00:00
|
|
|
tmp = (ase_char_t*) ase_awk_alloc (awk, (len+1) * ASE_SIZEOF(ase_char_t));
|
2007-11-11 00:30:00 +00:00
|
|
|
if (tmp == ASE_NULL) return ASE_NULL;
|
|
|
|
|
|
|
|
ase_strncpy (tmp, (ase_char_t*)str, len);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
static int get_str (
|
|
|
|
JNIEnv* env, ase_awk_t* awk, jstring str,
|
|
|
|
const jchar** jptr, ase_char_t** aptr, jsize* outlen)
|
|
|
|
{
|
|
|
|
jsize len;
|
|
|
|
const jchar* ptr;
|
|
|
|
|
|
|
|
len = (*env)->GetStringLength (env, str);
|
|
|
|
ptr = (*env)->GetStringChars (env, str, JNI_FALSE);
|
|
|
|
if (ptr == ASE_NULL)
|
2007-10-24 00:18:00 +00:00
|
|
|
{
|
2007-10-24 23:17:00 +00:00
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return -1;
|
2007-10-24 00:18:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-24 23:17:00 +00:00
|
|
|
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
|
|
|
{
|
|
|
|
jsize x;
|
|
|
|
|
|
|
|
ase_char_t* tmp = (ase_char_t*)
|
2008-08-21 03:17:25 +00:00
|
|
|
ase_awk_alloc (awk, ASE_SIZEOF(ase_char_t)*len);
|
2007-10-24 23:17:00 +00:00
|
|
|
if (tmp == ASE_NULL)
|
|
|
|
{
|
|
|
|
(*env)->ReleaseStringChars (env, str, ptr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = 0; x < len; x++) tmp[x] = (ase_char_t)ptr[x];
|
|
|
|
|
|
|
|
*outlen = len;
|
|
|
|
*jptr = ptr;
|
|
|
|
*aptr = tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*outlen = len;
|
|
|
|
*jptr = ptr;
|
|
|
|
*aptr = (ase_char_t*)ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_str (
|
|
|
|
JNIEnv* env, ase_awk_t* awk, jstring str,
|
|
|
|
const jchar* jptr, ase_char_t* aptr)
|
|
|
|
{
|
|
|
|
if (jptr != aptr) ase_awk_free (awk, aptr);
|
|
|
|
(*env)->ReleaseStringChars (env, str, jptr);
|
2007-10-24 00:18:00 +00:00
|
|
|
}
|
2007-11-09 00:08:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
static jstring new_str (
|
|
|
|
JNIEnv* env, ase_awk_t* awk, const ase_char_t* ptr, ase_size_t len)
|
|
|
|
{
|
|
|
|
jstring ret;
|
2007-11-11 00:30:00 +00:00
|
|
|
jsize i, chunk;
|
|
|
|
|
|
|
|
chunk = (len > ASE_TYPE_MAX(jsize))? ASE_TYPE_MAX(jsize): (jsize)len;
|
|
|
|
if (chunk > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
|
2007-11-09 00:08:00 +00:00
|
|
|
{
|
2008-08-21 03:17:25 +00:00
|
|
|
jchar* tmp = (jchar*) ase_awk_alloc (awk, ASE_SIZEOF(jchar)*chunk);
|
2007-11-09 00:08:00 +00:00
|
|
|
if (tmp == ASE_NULL) return ASE_NULL;
|
|
|
|
|
2007-11-11 00:30:00 +00:00
|
|
|
for (i = 0; i < chunk; i++) tmp[i] = (jchar)ptr[i];
|
|
|
|
ret = (*env)->NewString (env, tmp, chunk);
|
2007-11-09 00:08:00 +00:00
|
|
|
ase_awk_free (awk, tmp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-11 00:30:00 +00:00
|
|
|
|
|
|
|
ret = (*env)->NewString (env, (jchar*)ptr, chunk);
|
2007-11-09 00:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == ASE_NULL)
|
|
|
|
{
|
|
|
|
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
|
|
|
|
(*env)->ExceptionClear (env);
|
|
|
|
return ASE_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|