*** empty log message ***

This commit is contained in:
2006-11-22 15:12:04 +00:00
parent b6c4b73452
commit 2de8c5f69e
8 changed files with 203 additions and 40 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.java,v 1.5 2006-11-22 05:58:26 bacon Exp $
* $Id: Awk.java,v 1.6 2006-11-22 15:12:03 bacon Exp $
*/
package ase.awk;
@ -28,6 +28,17 @@ public abstract class Awk
public native void parse () throws Exception;
public native void run () throws Exception;
private native void open () throws Exception;
private native int setconsolename (long run_id, String name);
public void setConsoleName (long run_id, String name) //throws Exception
{
/* TODO: setconsolename is not safe. for example, it can
* crash the program if run_id is invalid. so this wrapper
* needs to do some sanity check. */
//if (setconsolename (run_id, name) == -1)
// throw new Exception ("cannot set the consle name");
setconsolename (run_id, name);
}
/* abstrace methods */
protected abstract int open_source (int mode);

View File

@ -20,13 +20,15 @@ public class Extio
private String name;
private int type;
private int mode;
private long run_id;
private Object handle;
protected Extio (String name, int type, int mode)
protected Extio (String name, int type, int mode, long run_id)
{
this.name = name;
this.type = type;
this.mode = mode;
this.run_id = run_id;
this.handle = null;
}
@ -45,6 +47,11 @@ public class Extio
return this.mode;
}
public long getRunId ()
{
return this.run_id;
}
public void setHandle (Object handle)
{
this.handle = handle;

View File

@ -1,5 +1,5 @@
/*
* $Id: extio.c,v 1.61 2006-11-21 15:06:14 bacon Exp $
* $Id: extio.c,v 1.62 2006-11-22 15:12:04 bacon Exp $
*/
#include <ase/awk/awk_i.h>
@ -678,6 +678,10 @@ int ase_awk_nextextio_read (
/* as the next stream has been opened successfully,
* the eof flag should be cleared if set */
p->in.eof = ase_false;
/* also the previous input buffer must be reset */
p->in.pos = 0;
p->in.len = 0;
}
return n;

View File

@ -1,5 +1,5 @@
/*
* $Id: jni.c,v 1.19 2006-11-22 05:58:26 bacon Exp $
* $Id: jni.c,v 1.20 2006-11-22 15:12:04 bacon Exp $
*/
#include <ase/awk/jni.h>
@ -460,7 +460,7 @@ static ase_ssize_t __call_java_open_extio (
/* get the constructor */
extio_cons = (*env)->GetMethodID (
env, extio_class, "<init>", "(Ljava/lang/String;II)V");
env, extio_class, "<init>", "(Ljava/lang/String;IIJ)V");
if (extio_cons == NULL)
{
(*env)->DeleteLocalRef (env, extio_class);
@ -490,7 +490,7 @@ static ase_ssize_t __call_java_open_extio (
/* construct the extio object */
extio_object = (*env)->NewObject (
env, extio_class, extio_cons,
extio_name, extio->type & 0xFF, extio->mode);
extio_name, extio->type & 0xFF, extio->mode, extio->run);
if (extio_object == NULL)
{
(*env)->DeleteLocalRef (env, extio_name);
@ -574,6 +574,7 @@ static ase_ssize_t __call_java_read_extio (
jint ret, i;
jthrowable thrown;
printf ("java_read_extio>>>\n");
class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I");
@ -655,6 +656,37 @@ static ase_ssize_t __call_java_write_extio (
return ret;
}
static ase_ssize_t __call_java_next_extio (
JNIEnv* env, jobject obj, char* meth, ase_awk_extio_t* extio)
{
jclass class;
jmethodID mid;
jthrowable thrown;
jint ret;
class = (*env)->GetObjectClass(env, obj);
mid = (*env)->GetMethodID (
env, class, meth, "(Lase/awk/Extio;)I");
if (mid == NULL)
{
(*env)->DeleteLocalRef (env, class);
return -1;
}
ret = (*env)->CallIntMethod (env, obj, mid, extio->handle);
thrown = (*env)->ExceptionOccurred (env);
if (thrown)
{
(*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env);
ret = -1;
}
(*env)->DeleteLocalRef (env, class);
return ret;
}
static ase_ssize_t __read_source (
int cmd, void* arg, ase_char_t* data, ase_size_t count)
{
@ -733,6 +765,12 @@ static ase_ssize_t __process_extio (
runio_data->env, runio_data->obj,
"write_extio", epa, data, size);
}
else if (cmd == ASE_AWK_IO_NEXT)
{
return __call_java_next_extio (
runio_data->env, runio_data->obj,
"next_console", epa);
}
#if 0
else if (cmd == ASE_AWK_IO_FLUSH)
{
@ -740,13 +778,22 @@ static ase_ssize_t __process_extio (
runio_data->env, runio_data->obj, "flush_console",
data, size);
}
else if (cmd == ASE_AWK_IO_NEXT)
{
return __call_java_next_extio (
runio_data->env, runio_data->obj, "flush_console",
data, size);
}
#endif
return -1;
}
JNIEXPORT int JNICALL Java_ase_awk_Awk_setconsolename (JNIEnv* env, jobject obj, jlong run_id, jstring name)
{
ase_awk_run_t* run = (ase_awk_run_t*)run_id;
const jchar* str;
int len, n;
str = (*env)->GetStringChars (env, name, JNI_FALSE);
len = (*env)->GetStringLength (env, name);
n = ase_awk_setconsolename (run, str, len);
(*env)->ReleaseStringChars (env, name, str);
return n;
}

View File

@ -5,6 +5,5 @@ EXPORTS
Java_ase_awk_Awk_close
Java_ase_awk_Awk_parse
Java_ase_awk_Awk_run
Java_ase_awk_Awk_get_1extio
Java_ase_awk_Awk_set_1extio
Java_ase_awk_Awk_setconsolename

View File

@ -1,5 +1,5 @@
/*
* $Id: jni.h,v 1.7 2006-10-24 04:10:12 bacon Exp $
* $Id: jni.h,v 1.8 2006-11-22 15:12:04 bacon Exp $
*/
#ifndef _ASE_AWK_JNI_H_
@ -15,6 +15,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv*, jobject);
JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv*, jobject);
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv*, jobject);
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv*, jobject);
JNIEXPORT int JNICALL Java_ase_awk_Awk_setconsolename (JNIEnv*, jobject, jlong, jstring);
#ifdef __cplusplus
}