*** empty log message ***

This commit is contained in:
hyung-hwan 2007-01-31 09:31:29 +00:00
parent 53718209e3
commit 911ab2b4b7
5 changed files with 115 additions and 66 deletions

View File

@ -1,13 +1,9 @@
/*
* $Id: Awk.java,v 1.23 2007-01-26 15:27:00 bacon Exp $
* $Id: Awk.java,v 1.24 2007-01-31 09:31:02 bacon Exp $
*/
package ase.awk;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.net.URL;
public abstract class Awk
{
// mode for open_source & close_source
@ -38,33 +34,6 @@ public abstract class Awk
public static final int OPTION_NEXTOFILE = (1 << 12);
public static final int OPTION_CRLF = (1 << 13);
static
{
/*
System.getProperty("os.name")); os.arch / os.version;
*/
//System.load ("c://projects//ase/awk/aseawk.dll");
URL url = ase.awk.Awk.class.getResource("aseawk_jni.dll");
if (url == null) url = ase.awk.Awk.class.getResource("aseawk_jni.so");
if (url != null) System.load (url.getFile());
/*
AccessController.doPrivileged (new PrivilegedAction ()
{
public Object run ()
{
URL url = ase.awk.Awk.class.getResource("aseawk.dll");
if (url == null) url = ase.awk.Awk.class.getResource("libaseawk_jni.so");
if (url != null) System.load (url.getFile());
//System.load ("c://projects//ase/awk/aseawk.dll");
//System.loadLibrary ("aseawk");
return null;
}
});
*/
}
private long handle;
public Awk () throws Exception
@ -85,7 +54,7 @@ public abstract class Awk
private native void open () throws Exception;
public native void close ();
public native void parse () throws Exception;
public native void run () throws Exception;
public native void run (String main) throws Exception;
private native int getmaxdepth (int id);
private native void setmaxdepth (int id, int depth);
@ -110,6 +79,12 @@ public abstract class Awk
private native String valtostr (
long runid, Object obj) throws Exception;
/* == simpler run method == */
public void run () throws Exception
{
run (null);
}
/* == builtin functions == */
public void addBuiltinFunction (
String name, int min_args, int max_args) throws Exception

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.java,v 1.15 2007-01-31 08:23:59 bacon Exp $
* $Id: StdAwk.java,v 1.16 2007-01-31 09:31:03 bacon Exp $
*/
package ase.awk;
@ -52,11 +52,16 @@ public abstract class StdAwk extends Awk
super.parse ();
}
public void run () throws Exception
public void run (String main) throws Exception
{
cin = consoleInputNames (); cin_no = 0;
cout = consoleOutputNames (); cout_no = 0;
super.run ();
super.run (main);
}
public void run () throws Exception
{
run (null);
}
/* == source code names == */
@ -207,6 +212,7 @@ public abstract class StdAwk extends Awk
cout_no = 0;
if (cout == null || cout_no >= cout.length) return 0;
osw = get_stream_writer (cout[cout_no]);
if (osw == null) return -1;

View File

@ -1,5 +1,5 @@
/*
* $Id: jni.c,v 1.62 2007-01-31 08:23:59 bacon Exp $
* $Id: jni.c,v 1.63 2007-01-31 09:31:03 bacon Exp $
*/
#include <stdio.h>
@ -386,7 +386,17 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj)
}
}
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
#define DELETE_CLASS_REFS(env, run_data) \
do { \
(*env)->DeleteLocalRef (env, run_data.integer_class); \
(*env)->DeleteLocalRef (env, run_data.long_class); \
(*env)->DeleteLocalRef (env, run_data.float_class); \
(*env)->DeleteLocalRef (env, run_data.double_class); \
(*env)->DeleteLocalRef (env, run_data.string_class); \
(*env)->DeleteLocalRef (env, run_data.object_class); \
} while (0)
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jstring mfn)
{
jclass class;
jfieldID handle;
@ -395,14 +405,10 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
ase_awk_runios_t runios;
runio_data_t runio_data;
run_data_t run_data;
ase_char_t* mmm;
static int depth_ids[] =
{
ASE_AWK_DEPTH_BLOCK_PARSE,
ASE_AWK_DEPTH_EXPR_PARSE,
ASE_AWK_DEPTH_REX_BUILD,
ASE_AWK_DEPTH_REX_MATCH
};
ase_size_t len;
jchar* ptr;
class = (*env)->GetObjectClass (env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J");
@ -485,31 +491,88 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj)
runios.console = __process_extio;
runios.custom_data = &runio_data;
if (ase_awk_run (awk,
ASE_NULL, &runios, ASE_NULL, ASE_NULL, &run_data) == -1)
if (mfn == NULL)
{
mmm = NULL;
ptr = NULL;
}
else
{
len = (*env)->GetStringLength (env, mfn);
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
{
ase_size_t i;
ptr = (*env)->GetStringChars (env, mfn, JNI_FALSE);
if (ptr == NULL)
{
(*env)->ExceptionClear (env);
DELETE_CLASS_REFS (env, run_data);
throw_exception (
env,
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
}
mmm = (ase_char_t*) malloc (ASE_SIZEOF(ase_char_t)*(len+1));
if (mmm == ASE_NULL)
{
(*env)->ReleaseStringChars (env, mfn, ptr);
DELETE_CLASS_REFS (env, run_data);
throw_exception (
env,
ase_awk_geterrstr(ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return;
}
for (i = 0; i < len; i++)
{
mmm[i] = (ase_char_t)ptr[i];
if (mmm[i] == ASE_T('\0'))
{
free (mmm);
(*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
{
mmm = (ase_char_t*)mfn;
ptr = NULL;
}
}
if (ase_awk_run (awk,
mmm, &runios, ASE_NULL, ASE_NULL, &run_data) == -1)
{
if (mmm != NULL && mmm != mfn) free (mmm);
if (ptr != NULL) (*env)->ReleaseStringChars (env, mfn, ptr);
DELETE_CLASS_REFS (env, run_data);
throw_exception (
env,
ase_awk_geterrmsg(awk),
ase_awk_geterrnum(awk),
ase_awk_geterrlin(awk));
(*env)->DeleteLocalRef (env, run_data.integer_class);
(*env)->DeleteLocalRef (env, run_data.long_class);
(*env)->DeleteLocalRef (env, run_data.float_class);
(*env)->DeleteLocalRef (env, run_data.double_class);
(*env)->DeleteLocalRef (env, run_data.string_class);
(*env)->DeleteLocalRef (env, run_data.object_class);
return;
}
(*env)->DeleteLocalRef (env, run_data.integer_class);
(*env)->DeleteLocalRef (env, run_data.long_class);
(*env)->DeleteLocalRef (env, run_data.short_class);
(*env)->DeleteLocalRef (env, run_data.float_class);
(*env)->DeleteLocalRef (env, run_data.double_class);
(*env)->DeleteLocalRef (env, run_data.string_class);
(*env)->DeleteLocalRef (env, run_data.object_class);
if (mmm != NULL && mmm != mfn) free (mmm);
if (ptr != NULL) (*env)->ReleaseStringChars (env, mfn, ptr);
DELETE_CLASS_REFS (env, run_data);
}
static ase_ssize_t __java_open_source (JNIEnv* env, jobject obj, int mode)

View File

@ -1,5 +1,5 @@
/*
* $Id: jni.h,v 1.19 2007-01-30 10:55:27 bacon Exp $
* $Id: jni.h,v 1.20 2007-01-31 09:31:03 bacon Exp $
*/
#ifndef _ASE_AWK_JNI_H_
@ -18,7 +18,7 @@ extern "C" {
JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jstring mfn);
JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (
JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args);

View File

@ -1,9 +1,11 @@
/*
* $Id: Awk.java,v 1.24 2007-01-30 11:24:40 bacon Exp $
* $Id: Awk.java,v 1.25 2007-01-31 09:31:29 bacon Exp $
*/
package ase.test.awk;
import java.net.URL;
public class Awk extends ase.awk.StdAwk
{
public Awk () throws ase.awk.Exception
@ -84,6 +86,10 @@ public class Awk extends ase.awk.StdAwk
{
Awk awk = null;
URL url = ase.awk.Awk.class.getResource ("aseawk_jni.dll");
if (url == null) url = ase.awk.Awk.class.getResource ("aseawk_jni.so");
if (url != null) System.load (url.getFile());
try
{
awk = new Awk ();
@ -95,8 +101,7 @@ public class Awk extends ase.awk.StdAwk
System.out.println ("Option: [" + awk.getOption() + "]");
awk.parse ();
System.out.println ("about to run the program");
awk.run ();
awk.run ("main");
}
catch (ase.awk.Exception e)
{