Recovered from cvs revision 2007-06-25 10:17:00
This commit is contained in:
		| @ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
|  * $Id: Awk.java,v 1.10 2007/05/26 10:52:48 bacon Exp $ |  * $Id: Awk.java,v 1.11 2007/06/24 11:14:58 bacon Exp $ | ||||||
|  * |  * | ||||||
|  * {License} |  * {License} | ||||||
|  */ |  */ | ||||||
| @ -75,6 +75,8 @@ public abstract class Awk | |||||||
| 	private native boolean getdebug (); | 	private native boolean getdebug (); | ||||||
| 	private native void setdebug (boolean debug); | 	private native void setdebug (boolean debug); | ||||||
|  |  | ||||||
|  | 	private native void setword (String ow, String nw); | ||||||
|  |  | ||||||
| 	private native void addbfn ( | 	private native void addbfn ( | ||||||
| 		String name, int min_args, int max_args) throws Exception; | 		String name, int min_args, int max_args) throws Exception; | ||||||
| 	private native void delbfn (String name) throws Exception; | 	private native void delbfn (String name) throws Exception; | ||||||
| @ -256,6 +258,11 @@ public abstract class Awk | |||||||
| 		setdebug (debug); | 		setdebug (debug); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	public void setWord (String ow, String nw) | ||||||
|  | 	{ | ||||||
|  | 		setword (ow, nw); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/* == source code management == */ | 	/* == source code management == */ | ||||||
| 	protected abstract int openSource (int mode); | 	protected abstract int openSource (int mode); | ||||||
| 	protected abstract int closeSource (int mode); | 	protected abstract int closeSource (int mode); | ||||||
|  | |||||||
							
								
								
									
										117
									
								
								ase/awk/jni.c
									
									
									
									
									
								
							
							
						
						
									
										117
									
								
								ase/awk/jni.c
									
									
									
									
									
								
							| @ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
|  * $Id: jni.c,v 1.10 2007/05/25 14:41:48 bacon Exp $ |  * $Id: jni.c,v 1.11 2007/06/24 11:14:58 bacon Exp $ | ||||||
|  * |  * | ||||||
|  * {License} |  * {License} | ||||||
|  */ |  */ | ||||||
| @ -2009,6 +2009,119 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( | |||||||
| 	((awk_data_t*)ase_awk_getcustomdata(awk))->debug = debug; | 	((awk_data_t*)ase_awk_getcustomdata(awk))->debug = debug; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | JNIEXPORT void JNICALL Java_ase_awk_Awk_setword ( | ||||||
|  | 	JNIEnv* env, jobject obj, jstring ow, jstring nw) | ||||||
|  | {	 | ||||||
|  | 	jclass class;  | ||||||
|  | 	jfieldID handle; | ||||||
|  | 	ase_awk_t* awk; | ||||||
|  | 	const jchar* op, * np; | ||||||
|  | 	jsize ol, nl; | ||||||
|  | 	ase_char_t* ox, * nx; | ||||||
|  | 	jint r; | ||||||
|  |  | ||||||
|  | 	class = (*env)->GetObjectClass(env, obj); | ||||||
|  | 	handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); | ||||||
|  | 	(*env)->DeleteLocalRef (env, class); | ||||||
|  | 	if (handle == NULL) | ||||||
|  | 	{ | ||||||
|  | 		/* internal error. no handle field  | ||||||
|  | 		 * NoSuchFieldError, ExceptionInitializerError,  | ||||||
|  | 		 * OutOfMemoryError might occur */ | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); | ||||||
|  |  | ||||||
|  | 	ol = (*env)->GetStringLength (env, ow); | ||||||
|  | 	op = (*env)->GetStringChars (env, ow, JNI_FALSE); | ||||||
|  | 	if (op == NULL)  | ||||||
|  | 	{ | ||||||
|  | 		(*env)->ExceptionClear (env); | ||||||
|  | 		throw_exception ( | ||||||
|  | 			env,  | ||||||
|  | 			ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), | ||||||
|  | 			ASE_AWK_ENOMEM, | ||||||
|  | 			0); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	nl = (*env)->GetStringLength (env, nw); | ||||||
|  | 	np = (*env)->GetStringChars (env, nw, JNI_FALSE); | ||||||
|  | 	if (np == NULL)  | ||||||
|  | 	{ | ||||||
|  | 		(*env)->ReleaseStringChars (env, ow, op); | ||||||
|  | 		(*env)->ExceptionClear (env); | ||||||
|  | 		throw_exception ( | ||||||
|  | 			env,  | ||||||
|  | 			ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), | ||||||
|  | 			ASE_AWK_ENOMEM, | ||||||
|  | 			0); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (ol > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) | ||||||
|  | 	{ | ||||||
|  | 		ase_size_t i; | ||||||
|  | 		ox = (ase_char_t*)malloc (ASE_SIZEOF(ase_char_t)*ol); | ||||||
|  | 		if (ox == ASE_NULL) | ||||||
|  | 		{ | ||||||
|  | 			(*env)->ReleaseStringChars (env, nw, np); | ||||||
|  | 			(*env)->ReleaseStringChars (env, ow, op); | ||||||
|  |  | ||||||
|  | 			throw_exception ( | ||||||
|  | 				env,  | ||||||
|  | 				ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), | ||||||
|  | 				ASE_AWK_ENOMEM,  | ||||||
|  | 				0); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		for (i =  0; i < ol; i++) ox[i] = (ase_char_t)op[i]; | ||||||
|  | 	} | ||||||
|  | 	else ox = (ase_char_t*)op; | ||||||
|  |  | ||||||
|  | 	if (nl > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) | ||||||
|  | 	{ | ||||||
|  | 		ase_size_t i; | ||||||
|  | 		nx = (ase_char_t*) malloc (ASE_SIZEOF(ase_char_t)*nl); | ||||||
|  | 		if (nx == ASE_NULL) | ||||||
|  | 		{ | ||||||
|  | 			if (ox != (ase_char_t*)op) free (ox); | ||||||
|  |  | ||||||
|  | 			(*env)->ReleaseStringChars (env, nw, np); | ||||||
|  | 			(*env)->ReleaseStringChars (env, ow, op); | ||||||
|  |  | ||||||
|  | 			throw_exception ( | ||||||
|  | 				env,  | ||||||
|  | 				ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), | ||||||
|  | 				ASE_AWK_ENOMEM,  | ||||||
|  | 				0); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		for (i =  0; i < nl; i++) nx[i] = (ase_char_t)np[i]; | ||||||
|  | 	} | ||||||
|  | 	else nx = (ase_char_t*)np; | ||||||
|  |  | ||||||
|  | 	r = ase_awk_setword (awk, ox, ol, nx, nl); | ||||||
|  |  | ||||||
|  | 	if (nx != (ase_char_t*)np) free (nx); | ||||||
|  | 	if (ox != (ase_char_t*)op) free (ox); | ||||||
|  |  | ||||||
|  | 	(*env)->ReleaseStringChars (env, nw, np); | ||||||
|  | 	(*env)->ReleaseStringChars (env, ow, op); | ||||||
|  |  | ||||||
|  | 	if (r == -1) | ||||||
|  | 	{ | ||||||
|  | 		throw_exception ( | ||||||
|  | 			env,  | ||||||
|  | 			ase_awk_geterrmsg(awk),  | ||||||
|  | 			ase_awk_geterrnum(awk),  | ||||||
|  | 			ase_awk_geterrlin(awk)); | ||||||
|  | 	}	 | ||||||
|  | } | ||||||
|  |  | ||||||
| JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( | JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( | ||||||
| 	JNIEnv* env, jobject obj, jlong runid, jstring name) | 	JNIEnv* env, jobject obj, jlong runid, jstring name) | ||||||
| { | { | ||||||
| @ -2506,6 +2619,8 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_system ( | |||||||
| 	for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; | 	for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; | ||||||
| 	tmp[i] = ASE_T('\0'); | 	tmp[i] = ASE_T('\0'); | ||||||
|  |  | ||||||
|  | 	(*env)->ReleaseStringChars (env, cmd, ptr); | ||||||
|  |  | ||||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||||
| 	ret = _tsystem(tmp); | 	ret = _tsystem(tmp); | ||||||
| #else | #else | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
|  * $Id: jni.h,v 1.3 2007/04/30 05:47:33 bacon Exp $ |  * $Id: jni.h,v 1.4 2007/06/24 11:14:58 bacon Exp $ | ||||||
|  * |  * | ||||||
|  * {License} |  * {License} | ||||||
|  */ |  */ | ||||||
| @ -43,6 +43,9 @@ JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug ( | |||||||
| JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( | JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( | ||||||
| 	JNIEnv* env, jobject obj, jboolean debug); | 	JNIEnv* env, jobject obj, jboolean debug); | ||||||
|  |  | ||||||
|  | JNIEXPORT void JNICALL Java_ase_awk_Awk_setword ( | ||||||
|  | 	JNIEnv* env, jobject obj, jstring ow, jstring nw); | ||||||
|  |  | ||||||
| JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( | JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( | ||||||
| 	JNIEnv* env, jobject obj, jlong runid, jstring name); | 	JNIEnv* env, jobject obj, jlong runid, jstring name); | ||||||
| JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename ( | JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename ( | ||||||
| @ -53,6 +56,13 @@ JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum ( | |||||||
| JNIEXPORT jstring JNICALL Java_ase_awk_Awk_valtostr ( | JNIEXPORT jstring JNICALL Java_ase_awk_Awk_valtostr ( | ||||||
| 	JNIEnv* env, jobject obj, jlong runid, jobject val); | 	JNIEnv* env, jobject obj, jlong runid, jobject val); | ||||||
|  |  | ||||||
|  | JNIEXPORT jstring JNICALL Java_ase_awk_Awk_strftime ( | ||||||
|  | 	JNIEnv* env, jobject obj, jstring fmt, jlong sec); | ||||||
|  | JNIEXPORT jstring JNICALL Java_ase_awk_Awk_strfgmtime ( | ||||||
|  | 	JNIEnv* env, jobject obj, jstring fmt, jlong sec); | ||||||
|  | JNIEXPORT jint JNICALL Java_ase_awk_Awk_system ( | ||||||
|  | 	JNIEnv* env, jobject obj, jstring cmd); | ||||||
|  |  | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -2,12 +2,15 @@ | |||||||
|  |  | ||||||
| * added ase_awk_setword to enable customization of keywords and | * added ase_awk_setword to enable customization of keywords and | ||||||
|   intrinsic function names. |   intrinsic function names. | ||||||
| * added setWord method to the awk c++ class. | * added setWord method to the awk c++ class (awk/Awk.cpp) | ||||||
| * added setErrorString method to the awk c++ class. | * added setErrorString method to the awk c++ class (awk/Awk.cpp) | ||||||
|  | * added setWord method to the awk java class (awk/Awk.java) | ||||||
|  |  | ||||||
| * changed the wrong macro name WIN32 to _WIN32 in utl/stdio.h | * changed the wrong macro name WIN32 to _WIN32 in utl/stdio.h | ||||||
| * changed test/awk/Awk.cpp to include an option(-w) to utilize | * changed test/awk/Awk.cpp to include an option(-w) to utilize | ||||||
|   the setWord method. |   the setWord method. | ||||||
|  | * changed test/awk/AseAwk.java to include an option(-w) to utilize | ||||||
|  |   the setWord method. | ||||||
|  |  | ||||||
| [0.2.0] | [0.2.0] | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
|  * $Id: AseAwk.java,v 1.8 2007/05/28 10:29:57 bacon Exp $ |  * $Id: AseAwk.java,v 1.9 2007/06/24 11:14:58 bacon Exp $ | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| import java.awt.*; | import java.awt.*; | ||||||
| @ -53,15 +53,18 @@ public class AseAwk extends StdAwk | |||||||
| 		System.out.print ("Usage: "); | 		System.out.print ("Usage: "); | ||||||
| 		System.out.print (AseAwk.class.getName()); | 		System.out.print (AseAwk.class.getName()); | ||||||
|  |  | ||||||
| 		System.out.println (" [-m main] [-si file]? [-so file]? [-ci file]* [-co file]* [-a arg]*"); | 		System.out.println (" [-m main] [-si file]? [-so file]? [-ci file]* [-co file]* [-a arg]* [-w o:n]*"); | ||||||
| 		System.out.println ("    -m  main  Specify the main function name\n"); | 		System.out.println ("    -m  main  Specify the main function name"); | ||||||
| 		System.out.println ("    -si file  Specify the input source file\n"); | 		System.out.println ("    -si file  Specify the input source file"); | ||||||
| 		System.out.println ("              The source code is read from stdin when it is not specified\n"); | 		System.out.println ("              The source code is read from stdin when it is not specified"); | ||||||
| 		System.out.println ("    -so file  Specify the output source file\n"); | 		System.out.println ("    -so file  Specify the output source file"); | ||||||
| 		System.out.println ("              The deparsed code is not output when is it not specified\n"); | 		System.out.println ("              The deparsed code is not output when is it not specified"); | ||||||
| 		System.out.println ("    -ci file  Specify the input console file\n"); | 		System.out.println ("    -ci file  Specify the input console file"); | ||||||
| 		System.out.println ("    -co file  Specify the output console file\n"); | 		System.out.println ("    -co file  Specify the output console file"); | ||||||
| 		System.out.println ("    -a  str   Specify an argument\n"); | 		System.out.println ("    -a  str   Specify an argument"); | ||||||
|  | 		System.out.println ("    -w  o:n   Specify an old and new word pair"); | ||||||
|  | 		System.out.println ("              o - an original word"); | ||||||
|  | 		System.out.println ("              n - the new word to replace the original word"); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	private static void print_error (String msg) | 	private static void print_error (String msg) | ||||||
| @ -143,6 +146,7 @@ public class AseAwk extends StdAwk | |||||||
| 				else if (arg.equals("-co")) mode = 4; | 				else if (arg.equals("-co")) mode = 4; | ||||||
| 				else if (arg.equals("-a")) mode = 5; | 				else if (arg.equals("-a")) mode = 5; | ||||||
| 				else if (arg.equals("-m")) mode = 6; | 				else if (arg.equals("-m")) mode = 6; | ||||||
|  | 				else if (arg.equals("-w")) mode = 7; | ||||||
| 				else  | 				else  | ||||||
| 				{ | 				{ | ||||||
| 					print_usage (); | 					print_usage (); | ||||||
| @ -207,6 +211,20 @@ public class AseAwk extends StdAwk | |||||||
| 					mainfn = arg; | 					mainfn = arg; | ||||||
| 					mode = 0; | 					mode = 0; | ||||||
| 				} | 				} | ||||||
|  | 				else if (mode == 7) | ||||||
|  | 				{ | ||||||
|  | 					int idx = arg.indexOf(':'); | ||||||
|  | 					if (idx == -1) | ||||||
|  | 					{ | ||||||
|  | 						print_usage (); | ||||||
|  | 						return; | ||||||
|  | 					} | ||||||
|  |  | ||||||
|  | 					String ow = arg.substring (0, idx); | ||||||
|  | 					String nw = arg.substring (idx+1); | ||||||
|  | 					awk.setWord (ow, nw); | ||||||
|  | 					mode = 0; | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user