Recovered from cvs revision 2007-11-10 10:28:00

This commit is contained in:
hyung-hwan 2007-11-11 00:30:00 +00:00
parent 795c082519
commit 035bc48265
37 changed files with 331 additions and 274 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: extio.c,v 1.8 2007/10/28 06:12:37 bacon Exp $ * $Id: extio.c,v 1.9 2007/11/09 07:43:42 bacon Exp $
* *
* {License} * {License}
*/ */
@ -80,7 +80,8 @@ int ase_awk_readextio (
{ {
ase_awk_extio_t* p = run->extio.chain; ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler; ase_awk_io_t handler;
int extio_type, extio_mode, extio_mask, n, ret; int extio_type, extio_mode, extio_mask, ret, n;
ase_ssize_t x;
ase_awk_val_t* rs; ase_awk_val_t* rs;
ase_char_t* rs_ptr; ase_char_t* rs_ptr;
ase_size_t rs_len; ase_size_t rs_len;
@ -117,8 +118,7 @@ int ase_awk_readextio (
run->awk, ASE_SIZEOF(ase_awk_extio_t)); run->awk, ASE_SIZEOF(ase_awk_extio_t));
if (p == ASE_NULL) if (p == ASE_NULL)
{ {
ase_awk_setrunerror ( ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
@ -126,8 +126,7 @@ int ase_awk_readextio (
if (p->name == ASE_NULL) if (p->name == ASE_NULL)
{ {
ASE_AWK_FREE (run->awk, p); ASE_AWK_FREE (run->awk, p);
ase_awk_setrunerror ( ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
@ -146,8 +145,8 @@ int ase_awk_readextio (
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_OPEN, p, ASE_NULL, 0); x = handler (ASE_AWK_IO_OPEN, p, ASE_NULL, 0);
if (n <= -1) if (x <= -1)
{ {
ASE_AWK_FREE (run->awk, p->name); ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p); ASE_AWK_FREE (run->awk, p);
@ -166,12 +165,12 @@ int ase_awk_readextio (
p->next = run->extio.chain; p->next = run->extio.chain;
run->extio.chain = p; run->extio.chain = p;
/* usually, n == 0 indicates that it has reached the end /* usually, x == 0 indicates that it has reached the end
* of the input. the user io handler can return 0 for the * of the input. the user io handler can return 0 for the
* open request if it doesn't have any files to open. One * open request if it doesn't have any files to open. One
* advantage of doing this would be that you can skip the * advantage of doing this would be that you can skip the
* entire pattern-block matching and exeuction. */ * entire pattern-block matching and exeuction. */
if (n == 0) if (x == 0)
{ {
p->in.eos = ase_true; p->in.eos = ase_true;
return 0; return 0;
@ -429,7 +428,8 @@ int ase_awk_writeextio_str (
{ {
ase_awk_extio_t* p = run->extio.chain; ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler; ase_awk_io_t handler;
int extio_type, extio_mode, extio_mask, n; int extio_type, extio_mode, extio_mask;
ase_ssize_t n;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map)); ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map)); ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
@ -569,7 +569,8 @@ int ase_awk_flushextio (
{ {
ase_awk_extio_t* p = run->extio.chain; ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler; ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask, n; int extio_type, /*extio_mode,*/ extio_mask;
ase_ssize_t n;
ase_bool_t ok = ase_false; ase_bool_t ok = ase_false;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map)); ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
@ -623,7 +624,8 @@ int ase_awk_nextextio_read (
{ {
ase_awk_extio_t* p = run->extio.chain; ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler; ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask, n; int extio_type, /*extio_mode,*/ extio_mask;
ase_ssize_t n;
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map)); ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map)); ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map));
@ -679,6 +681,7 @@ int ase_awk_nextextio_read (
* set the eos flags so that the next call to nextextio_read * set the eos flags so that the next call to nextextio_read
* will return 0 without executing the handler */ * will return 0 without executing the handler */
p->in.eos = ase_true; p->in.eos = ase_true;
return 0;
} }
else else
{ {
@ -689,9 +692,9 @@ int ase_awk_nextextio_read (
/* also the previous input buffer must be reset */ /* also the previous input buffer must be reset */
p->in.pos = 0; p->in.pos = 0;
p->in.len = 0; p->in.len = 0;
}
return n; return 1;
}
} }
int ase_awk_nextextio_write ( int ase_awk_nextextio_write (
@ -699,7 +702,8 @@ int ase_awk_nextextio_write (
{ {
ase_awk_extio_t* p = run->extio.chain; ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler; ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask, n; int extio_type, /*extio_mode,*/ extio_mask;
ase_ssize_t n;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map)); ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map)); ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
@ -755,15 +759,15 @@ int ase_awk_nextextio_write (
* set the eos flags so that the next call to nextextio_write * set the eos flags so that the next call to nextextio_write
* will return 0 without executing the handler */ * will return 0 without executing the handler */
p->out.eos = ase_true; p->out.eos = ase_true;
return 0;
} }
else else
{ {
/* as the next stream has been opened successfully, /* as the next stream has been opened successfully,
* the eof flag should be cleared if set */ * the eof flag should be cleared if set */
p->out.eof = ase_false; p->out.eof = ase_false;
return 1;
} }
return n;
} }
int ase_awk_closeextio_read ( int ase_awk_closeextio_read (
@ -930,7 +934,7 @@ void ase_awk_clearextio (ase_awk_run_t* run)
{ {
ase_awk_extio_t* next; ase_awk_extio_t* next;
ase_awk_io_t handler; ase_awk_io_t handler;
int n; ase_ssize_t n;
while (run->extio.chain != ASE_NULL) while (run->extio.chain != ASE_NULL)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: func.c,v 1.19 2007/11/07 14:40:37 bacon Exp $ * $Id: func.c,v 1.20 2007/11/09 07:43:42 bacon Exp $
* *
* {License} * {License}
*/ */
@ -560,11 +560,14 @@ static int bfn_substr (
} }
if (ase_awk_getoption(run->awk) & ASE_AWK_BASEONE) lindex = lindex - 1; if (ase_awk_getoption(run->awk) & ASE_AWK_BASEONE) lindex = lindex - 1;
if (lindex >= len) lindex = len; if (lindex >= (ase_long_t)len) lindex = (ase_long_t)len;
else if (lindex < 0) lindex = 0; else if (lindex < 0) lindex = 0;
if (lcount < 0) lcount = 0; if (lcount < 0) lcount = 0;
else if (lcount > len - lindex) lcount = len - lindex; else if (lcount > (ase_long_t)len - lindex)
{
lcount = (ase_long_t)len - lindex;
}
r = ase_awk_makestrval (run, &str[lindex], (ase_size_t)lcount); r = ase_awk_makestrval (run, &str[lindex], (ase_size_t)lcount);
if (r == ASE_NULL) if (r == ASE_NULL)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: jni.c,v 1.48 2007/11/08 15:08:06 bacon Exp $ * $Id: jni.c,v 1.50 2007/11/09 15:08:41 bacon Exp $
* *
* {License} * {License}
*/ */
@ -67,6 +67,8 @@ static ase_ssize_t write_source (
static ase_ssize_t process_extio ( static ase_ssize_t process_extio (
int cmd, void* arg, ase_char_t* data, ase_size_t count); int cmd, void* arg, ase_char_t* data, ase_size_t count);
static ase_char_t* dup_str (
ase_awk_t* awk, const jchar* str, ase_size_t len);
static int get_str ( static int get_str (
JNIEnv* env, ase_awk_t* awk, jstring str, JNIEnv* env, ase_awk_t* awk, jstring str,
const jchar** jptr, ase_char_t** aptr, jsize* outlen); const jchar** jptr, ase_char_t** aptr, jsize* outlen);
@ -286,6 +288,7 @@ static void throw_exception (
jstring except_msg; jstring except_msg;
jthrowable except_obj; jthrowable except_obj;
ase_size_t len; ase_size_t len;
jsize chunk;
except_class = (*env)->FindClass (env, CLASS_EXCEPTION); except_class = (*env)->FindClass (env, CLASS_EXCEPTION);
if (except_class == ASE_NULL) if (except_class == ASE_NULL)
@ -311,14 +314,16 @@ static void throw_exception (
} }
len = ase_strlen(msg); len = ase_strlen(msg);
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) chunk = (len > ASE_TYPE_MAX(jsize))? ASE_TYPE_MAX(jsize): (jsize)len;
if (chunk > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
{ {
ase_size_t i; jsize i;
#if defined(_WIN32) && defined(__DMC__) #if defined(_WIN32) && defined(__DMC__)
jchar* tmp = (jchar*) GlobalAlloc (GMEM_FIXED, ASE_SIZEOF(jchar)*len); jchar* tmp = (jchar*) GlobalAlloc (GMEM_FIXED, ASE_SIZEOF(jchar)*chunk);
#else #else
jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*len); jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*chunk);
#endif #endif
if (tmp == ASE_NULL) if (tmp == ASE_NULL)
{ {
@ -333,8 +338,8 @@ static void throw_exception (
return; return;
} }
for (i = 0; i < len; i++) tmp[i] = (jchar)msg[i]; for (i = 0; i < chunk; i++) tmp[i] = (jchar)msg[i];
except_msg = (*env)->NewString (env, tmp, len); except_msg = (*env)->NewString (env, tmp, chunk);
#if defined(_WIN32) && defined(__DMC__) #if defined(_WIN32) && defined(__DMC__)
GlobalFree ((HGLOBAL)tmp); GlobalFree ((HGLOBAL)tmp);
#else #else
@ -343,7 +348,7 @@ static void throw_exception (
} }
else else
{ {
except_msg = (*env)->NewString (env, (jchar*)msg, len); except_msg = (*env)->NewString (env, (jchar*)msg, chunk);
} }
if (except_msg == ASE_NULL) if (except_msg == ASE_NULL)
@ -389,15 +394,15 @@ static void throw_exception (
throw_exception ( \ throw_exception ( \
env, \ env, \
ase_awk_geterrmsg(awk), \ ase_awk_geterrmsg(awk), \
ase_awk_geterrnum(awk), \ (jint)ase_awk_geterrnum(awk), \
ase_awk_geterrlin(awk)) (jint)ase_awk_geterrlin(awk))
#define THROW_RUN_EXCEPTION(env,run) \ #define THROW_RUN_EXCEPTION(env,run) \
throw_exception ( \ throw_exception ( \
env, \ env, \
ase_awk_getrunerrmsg(run), \ ase_awk_getrunerrmsg(run), \
ase_awk_getrunerrnum(run), \ (jint)ase_awk_getrunerrnum(run), \
ase_awk_getrunerrlin(run)) (jint)ase_awk_getrunerrlin(run))
static jboolean is_debug (ase_awk_t* awk) static jboolean is_debug (ase_awk_t* awk)
@ -603,33 +608,6 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj, jlong a
(*env)->DeleteLocalRef (env, run_data.context_object); \ (*env)->DeleteLocalRef (env, run_data.context_object); \
} while (0) } while (0)
static ase_char_t* java_strxdup (ase_awk_t* awk, const jchar* str, jint len)
{
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
{
ase_char_t* tmp;
ase_size_t i;
tmp = (ase_char_t*) ase_awk_malloc (awk, (len+1) * ASE_SIZEOF(ase_char_t));
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;
tmp = (ase_char_t*) ase_awk_malloc (awk, (len+1) * ASE_SIZEOF(ase_char_t));
if (tmp == ASE_NULL) return ASE_NULL;
ase_strncpy (tmp, (ase_char_t*)str, (ase_size_t)len);
return tmp;
}
}
static void on_run_start (ase_awk_run_t* run, void* custom) static void on_run_start (ase_awk_run_t* run, void* custom)
{ {
run_data_t* run_data; run_data_t* run_data;
@ -689,7 +667,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jlong awk
ase_char_t* mmm; ase_char_t* mmm;
ase_awk_runarg_t* runarg = ASE_NULL; ase_awk_runarg_t* runarg = ASE_NULL;
ase_size_t len, i; jsize len, i, j;
const jchar* ptr; const jchar* ptr;
awk = (ase_awk_t*) awkid; awk = (ase_awk_t*) awkid;
@ -794,8 +772,6 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jlong awk
if (len > 0) if (len > 0)
{ {
ase_size_t i;
ptr = (*env)->GetStringChars (env, mfn, JNI_FALSE); ptr = (*env)->GetStringChars (env, mfn, JNI_FALSE);
if (ptr == ASE_NULL) if (ptr == ASE_NULL)
{ {
@ -864,8 +840,6 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jlong awk
tmp = (*env)->GetStringChars (env, obj, JNI_FALSE); tmp = (*env)->GetStringChars (env, obj, JNI_FALSE);
if (tmp == ASE_NULL) if (tmp == ASE_NULL)
{ {
ase_size_t j;
for (j = 0; j < i; j++) ase_awk_free (awk, runarg[j].ptr); for (j = 0; j < i; j++) ase_awk_free (awk, runarg[j].ptr);
ase_awk_free (awk, runarg); ase_awk_free (awk, runarg);
@ -879,11 +853,9 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jlong awk
return; return;
} }
runarg[i].ptr = java_strxdup (awk, tmp, runarg[i].len); runarg[i].ptr = dup_str (awk, tmp, runarg[i].len);
if (runarg[i].ptr == ASE_NULL) if (runarg[i].ptr == ASE_NULL)
{ {
ase_size_t j;
for (j = 0; j < i; j++) ase_awk_free (awk, runarg[j].ptr); for (j = 0; j < i; j++) ase_awk_free (awk, runarg[j].ptr);
ase_awk_free (awk, runarg); ase_awk_free (awk, runarg);
@ -923,8 +895,8 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jlong awk
throw_exception ( throw_exception (
env, env,
run_data.errmsg, run_data.errmsg,
run_data.errnum, (jint)run_data.errnum,
run_data.errlin); (jint)run_data.errlin);
} }
else THROW_AWK_EXCEPTION (env, awk); else THROW_AWK_EXCEPTION (env, awk);
return; return;
@ -1087,9 +1059,8 @@ static ase_ssize_t java_write_source (
jcharArray array; jcharArray array;
jchar* tmp; jchar* tmp;
jint ret; jint ret;
ase_size_t i;
ase_awk_t* awk; ase_awk_t* awk;
jsize chunk; jsize chunk, i;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J"); handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
@ -1362,9 +1333,8 @@ static ase_ssize_t java_write_extio (
jcharArray array; jcharArray array;
jchar* tmp; jchar* tmp;
jint ret; jint ret;
ase_size_t i;
ase_awk_t* awk; ase_awk_t* awk;
jsize chunk; jsize chunk, i;
class = (*env)->GetObjectClass(env, obj); class = (*env)->GetObjectClass(env, obj);
handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J"); handle = (*env)->GetFieldID (env, class, FIELD_AWKID, "J");
@ -1590,15 +1560,19 @@ static int handle_bfn (
jmethodID method; jmethodID method;
jthrowable throwable; jthrowable throwable;
jstring name; jstring name;
jint i, nargs; jsize i, nargs;
jobjectArray args; jobjectArray args;
jobject arg, ret; jobject arg, ret;
ase_awk_val_t* v; ase_awk_val_t* v;
jlong vi; jlong vi;
run_data = ase_awk_getruncustomdata (run); ase_size_t nargs_ase;
nargs = ase_awk_getnargs (run);
awk = ase_awk_getrunawk (run); awk = ase_awk_getrunawk (run);
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;
env = run_data->env; env = run_data->env;
obj = run_data->obj; obj = run_data->obj;
@ -1982,7 +1956,8 @@ JNIEXPORT jstring JNICALL Java_ase_awk_Awk_getword (
{ {
ase_awk_t* awk; ase_awk_t* awk;
const jchar* ojp = ASE_NULL; const jchar* ojp = ASE_NULL;
jsize olen = 0, nlen; jsize olen = 0;
ase_size_t nlen;
ase_char_t* oap, * nap; ase_char_t* oap, * nap;
jstring ret; jstring ret;
@ -2409,37 +2384,13 @@ JNIEXPORT jstring JNICALL Java_ase_awk_Argument_getstrval (JNIEnv* env, jobject
return ret; return ret;
} }
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) ret = new_str (env, awk, str, len);
{
jchar* tmp;
ase_size_t i;
tmp = (jchar*) ase_awk_malloc (awk, ASE_SIZEOF(jchar)*len);
if (tmp == ASE_NULL)
{
ase_awk_free (awk, str);
goto nomem;
}
for (i = 0; i < len; i++) tmp[i] = (jchar)str[i];
ret = (*env)->NewString (env, tmp, len);
ase_awk_free (awk, tmp);
}
else
{
ret = (*env)->NewString (env, (jchar*)str, len);
}
ase_awk_free (awk, str); ase_awk_free (awk, str);
if (ret == ASE_NULL) if (ret == ASE_NULL)
{ {
nomem: if (is_debug(awk)) (*env)->ExceptionDescribe (env);
if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear (env);
{
if (is_debug(awk)) (*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env);
}
THROW_NOMEM_EXCEPTION (env); THROW_NOMEM_EXCEPTION (env);
} }
@ -2949,6 +2900,33 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_clearval (JNIEnv* env, jobject obj, j
(*env)->SetLongField (env, obj, run_data->return_valid, (jlong)0); (*env)->SetLongField (env, obj, run_data->return_valid, (jlong)0);
} }
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;
tmp = (ase_char_t*) ase_awk_malloc (awk, (len+1) * ASE_SIZEOF(ase_char_t));
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;
tmp = (ase_char_t*) ase_awk_malloc (awk, (len+1) * ASE_SIZEOF(ase_char_t));
if (tmp == ASE_NULL) return ASE_NULL;
ase_strncpy (tmp, (ase_char_t*)str, len);
return tmp;
}
}
static int get_str ( static int get_str (
JNIEnv* env, ase_awk_t* awk, jstring str, JNIEnv* env, ase_awk_t* awk, jstring str,
const jchar** jptr, ase_char_t** aptr, jsize* outlen) const jchar** jptr, ase_char_t** aptr, jsize* outlen)
@ -3005,20 +2983,22 @@ static jstring new_str (
JNIEnv* env, ase_awk_t* awk, const ase_char_t* ptr, ase_size_t len) JNIEnv* env, ase_awk_t* awk, const ase_char_t* ptr, ase_size_t len)
{ {
jstring ret; jstring ret;
jsize i, chunk;
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) chunk = (len > ASE_TYPE_MAX(jsize))? ASE_TYPE_MAX(jsize): (jsize)len;
if (chunk > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
{ {
ase_size_t i; jchar* tmp = (jchar*) ase_awk_malloc (awk, ASE_SIZEOF(jchar)*chunk);
jchar* tmp = (jchar*) ase_awk_malloc (awk, ASE_SIZEOF(jchar)*len);
if (tmp == ASE_NULL) return ASE_NULL; if (tmp == ASE_NULL) return ASE_NULL;
for (i = 0; i < len; i++) tmp[i] = (jchar)ptr[i]; for (i = 0; i < chunk; i++) tmp[i] = (jchar)ptr[i];
ret = (*env)->NewString (env, tmp, len); ret = (*env)->NewString (env, tmp, chunk);
ase_awk_free (awk, tmp); ase_awk_free (awk, tmp);
} }
else else
{ {
ret = (*env)->NewString (env, (jchar*)ptr, len);
ret = (*env)->NewString (env, (jchar*)ptr, chunk);
} }
if (ret == ASE_NULL) if (ret == ASE_NULL)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.29 2007/11/07 15:32:41 bacon Exp $ * $Id: parse.c,v 1.31 2007/11/09 15:08:41 bacon Exp $
* *
* {License} * {License}
*/ */
@ -528,6 +528,16 @@ int ase_awk_setword (ase_awk_t* awk,
return 0; return 0;
} }
const ase_char_t* ase_awk_getkw (ase_awk_t* awk, const ase_char_t* kw)
{
ase_awk_pair_t* p;
p = ase_awk_map_get (awk->wtab, kw, ase_strlen(kw));
if (p != ASE_NULL) return ((ase_cstr_t*)p->val)->ptr;
return kw;
}
int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios) int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios)
{ {
int n; int n;
@ -551,7 +561,8 @@ int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios)
static int parse (ase_awk_t* awk) static int parse (ase_awk_t* awk)
{ {
int n = 0, op; int n = 0;
ase_ssize_t op;
ASE_ASSERT (awk->src.ios.in != ASE_NULL); ASE_ASSERT (awk->src.ios.in != ASE_NULL);
@ -3163,6 +3174,26 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
return (ase_awk_nde_t*)nde; return (ase_awk_nde_t*)nde;
} }
#if 0
// TODO:...
{
/* check if it is a function name */
ase_awk_pair_t* pair;
pair = ase_awk_map_get (awk->tree.afns, name_dup, name_len);
afn = (ase_awk_afn_t*)pair->val;
nde->type = ASE_AWK_NDE_VARAFN;
nde->line = line;
nde->next = ASE_NULL;
/*nde->id.name = ASE_NULL;*/
nde->id.name = name_dup;
nde->id.name_len = name_len;
nde->id.idxa = idxa; /* pointer... */
nde->idx = ASE_NULL;
}
// END TODO:...
#endif
if (awk->option & ASE_AWK_IMPLICIT) if (awk->option & ASE_AWK_IMPLICIT)
{ {
if (awk->option & ASE_AWK_UNIQUEFN) if (awk->option & ASE_AWK_UNIQUEFN)
@ -5257,7 +5288,8 @@ static int deparse (ase_awk_t* awk)
ase_awk_chain_t* chain; ase_awk_chain_t* chain;
ase_char_t tmp[ASE_SIZEOF(ase_size_t)*8 + 32]; ase_char_t tmp[ASE_SIZEOF(ase_size_t)*8 + 32];
struct deparse_func_t df; struct deparse_func_t df;
int n = 0, op; int n = 0;
ase_ssize_t op;
ASE_ASSERT (awk->src.ios.out != ASE_NULL); ASE_ASSERT (awk->src.ios.out != ASE_NULL);
@ -5297,7 +5329,11 @@ static int deparse (ase_awk_t* awk)
ase_size_t i/*, len*/; ase_size_t i/*, len*/;
ASE_ASSERT (awk->tree.nglobals > 0); ASE_ASSERT (awk->tree.nglobals > 0);
if (ase_awk_putsrcstr (awk, ASE_T("global ")) == -1) if (ase_awk_putsrcstr(awk,ase_awk_getkw(awk,ASE_T("global"))) == -1)
{
EXIT_DEPARSE ();
}
if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1)
{ {
EXIT_DEPARSE (); EXIT_DEPARSE ();
} }
@ -5367,7 +5403,11 @@ static int deparse (ase_awk_t* awk)
if (awk->tree.begin != ASE_NULL) if (awk->tree.begin != ASE_NULL)
{ {
if (ase_awk_putsrcstr (awk, ASE_T("BEGIN ")) == -1) if (ase_awk_putsrcstr(awk,ase_awk_getkw(awk,ASE_T("BEGIN"))) == -1)
{
EXIT_DEPARSE ();
}
if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1)
{ {
EXIT_DEPARSE (); EXIT_DEPARSE ();
} }
@ -5429,7 +5469,9 @@ static int deparse (ase_awk_t* awk)
if (awk->tree.end != ASE_NULL) if (awk->tree.end != ASE_NULL)
{ {
if (ase_awk_putsrcstr (awk, ASE_T("END ")) == -1) if (ase_awk_putsrcstr(awk,ase_awk_getkw(awk,ASE_T("END"))) == -1)
EXIT_DEPARSE ();
if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1)
EXIT_DEPARSE (); EXIT_DEPARSE ();
if (ase_awk_prnpt (awk, awk->tree.end) == -1) if (ase_awk_prnpt (awk, awk->tree.end) == -1)
EXIT_DEPARSE (); EXIT_DEPARSE ();
@ -5460,7 +5502,8 @@ static int deparse_func (ase_awk_pair_t* pair, void* arg)
ASE_ASSERT (ase_strxncmp (ASE_AWK_PAIR_KEYPTR(pair), ASE_AWK_PAIR_KEYLEN(pair), afn->name, afn->name_len) == 0); ASE_ASSERT (ase_strxncmp (ASE_AWK_PAIR_KEYPTR(pair), ASE_AWK_PAIR_KEYLEN(pair), afn->name, afn->name_len) == 0);
if (ase_awk_putsrcstr (df->awk, ASE_T("func ")) == -1) return -1; if (ase_awk_putsrcstr(df->awk,ase_awk_getkw(df->awk,ASE_T("func"))) == -1)
if (ase_awk_putsrcstr (df->awk, ASE_T(" ")) == -1) return -1;
if (ase_awk_putsrcstr (df->awk, afn->name) == -1) return -1; if (ase_awk_putsrcstr (df->awk, afn->name) == -1) return -1;
if (ase_awk_putsrcstr (df->awk, ASE_T(" (")) == -1) return -1; if (ase_awk_putsrcstr (df->awk, ASE_T(" (")) == -1) return -1;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.h,v 1.4 2007/09/23 16:48:55 bacon Exp $ * $Id: parse.h,v 1.5 2007/11/09 15:08:41 bacon Exp $
* *
* {License} * {License}
*/ */
@ -21,6 +21,7 @@ int ase_awk_putsrcstrx (
const ase_char_t* ase_awk_getglobalname ( const ase_char_t* ase_awk_getglobalname (
ase_awk_t* awk, ase_size_t idx, ase_size_t* len); ase_awk_t* awk, ase_size_t idx, ase_size_t* len);
const ase_char_t* ase_awk_getkw (ase_awk_t* awk, const ase_char_t* kw);
int ase_awk_initglobals (ase_awk_t* awk); int ase_awk_initglobals (ase_awk_t* awk);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: rex.c,v 1.3 2007/04/30 05:47:33 bacon Exp $ * $Id: rex.c,v 1.4 2007/11/09 07:43:42 bacon Exp $
* *
* {License} * {License}
*/ */
@ -87,8 +87,8 @@ struct builder_t
struct struct
{ {
int max; ase_size_t max;
int cur; ase_size_t cur;
} depth; } depth;
int errnum; int errnum;
@ -109,8 +109,8 @@ struct matcher_t
struct struct
{ {
int max; ase_size_t max;
int cur; ase_size_t cur;
} depth; } depth;
int ignorecase; int ignorecase;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.22 2007/11/07 14:40:37 bacon Exp $ * $Id: run.c,v 1.23 2007/11/09 07:43:42 bacon Exp $
* *
* {License} * {License}
*/ */
@ -391,7 +391,7 @@ static int set_global (
if (n == -1) return -1; if (n == -1) return -1;
if (n == 1) lv = (ase_long_t)rv; if (n == 1) lv = (ase_long_t)rv;
if (lv < run->inrec.nflds) if (lv < (ase_long_t)run->inrec.nflds)
{ {
if (shorten_record (run, (ase_size_t)lv) == -1) if (shorten_record (run, (ase_size_t)lv) == -1)
{ {
@ -2472,7 +2472,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
var->type == ASE_AWK_NDE_GLOBALIDX) var->type == ASE_AWK_NDE_GLOBALIDX)
{ {
if (ase_awk_setglobal ( if (ase_awk_setglobal (
run, var->id.idxa, tmp) == -1) run, (int)var->id.idxa, tmp) == -1)
{ {
ase_awk_refupval (run, tmp); ase_awk_refupval (run, tmp);
ase_awk_refdownval (run, tmp); ase_awk_refdownval (run, tmp);
@ -3315,7 +3315,7 @@ static ase_awk_val_t* do_assignment_map (
else if (var->type == ASE_AWK_NDE_GLOBALIDX) else if (var->type == ASE_AWK_NDE_GLOBALIDX)
{ {
ase_awk_refupval (run, tmp); ase_awk_refupval (run, tmp);
if (ase_awk_setglobal (run, var->id.idxa, tmp) == -1) if (ase_awk_setglobal (run, (int)var->id.idxa, tmp) == -1)
{ {
ase_awk_refdownval (run, tmp); ase_awk_refdownval (run, tmp);
@ -5936,7 +5936,7 @@ static ase_awk_val_t* eval_pos (ase_awk_run_t* run, ase_awk_nde_t* nde)
return ASE_NULL; return ASE_NULL;
} }
if (lv == 0) v = run->inrec.d0; if (lv == 0) v = run->inrec.d0;
else if (lv > 0 && lv <= run->inrec.nflds) else if (lv > 0 && lv <= (ase_long_t)run->inrec.nflds)
v = run->inrec.flds[lv-1].val; v = run->inrec.flds[lv-1].val;
else v = ase_awk_val_zls; /*ase_awk_val_nil;*/ else v = ase_awk_val_zls; /*ase_awk_val_nil;*/
@ -6864,7 +6864,7 @@ ase_char_t* ase_awk_format (
return ASE_NULL; return ASE_NULL;
} }
if (prec == -1 || prec == 0 || prec > ch_len) prec = ch_len; if (prec == -1 || prec == 0 || prec > (ase_long_t)ch_len) prec = (ase_long_t)ch_len;
if (prec > width) width = prec; if (prec > width) width = prec;
if (!minus) if (!minus)
@ -6910,7 +6910,8 @@ ase_char_t* ase_awk_format (
else if (fmt[i] == ASE_T('s')) else if (fmt[i] == ASE_T('s'))
{ {
ase_char_t* str, * str_free = ASE_NULL; ase_char_t* str, * str_free = ASE_NULL;
ase_size_t str_len, k; ase_size_t str_len;
ase_long_t k;
ase_awk_val_t* v; ase_awk_val_t* v;
if (args == ASE_NULL) if (args == ASE_NULL)
@ -6971,7 +6972,7 @@ ase_char_t* ase_awk_format (
str_free = str; str_free = str;
} }
if (prec == -1 || prec > str_len ) prec = str_len; if (prec == -1 || prec > (ase_long_t)str_len ) prec = (ase_long_t)str_len;
if (prec > width) width = prec; if (prec > width) width = prec;
if (!minus) if (!minus)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tree.c,v 1.6 2007/11/06 09:47:12 bacon Exp $ * $Id: tree.c,v 1.7 2007/11/09 15:08:41 bacon Exp $
* *
* {License} * {License}
*/ */
@ -524,7 +524,7 @@ static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde)
PUT_SRCSTR (awk, ASE_T(" ")); PUT_SRCSTR (awk, ASE_T(" "));
} }
PUT_SRCSTR (awk, ASE_T("getline")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("getline")));
if (px->var != ASE_NULL) if (px->var != ASE_NULL)
{ {
PUT_SRCSTR (awk, ASE_T(" ")); PUT_SRCSTR (awk, ASE_T(" "));
@ -595,7 +595,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
if (px->nlocals > 0) if (px->nlocals > 0)
{ {
PRINT_TABS (awk, depth + 1); PRINT_TABS (awk, depth + 1);
PUT_SRCSTR (awk, ASE_T("local ")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("local")));
PUT_SRCSTR (awk, ASE_T(" "));
for (i = 0; i < px->nlocals - 1; i++) for (i = 0; i < px->nlocals - 1; i++)
{ {
@ -628,7 +629,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
ase_awk_nde_if_t* px = (ase_awk_nde_if_t*)p; ase_awk_nde_if_t* px = (ase_awk_nde_if_t*)p;
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("if (")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("if")));
PUT_SRCSTR (awk, ASE_T(" ("));
PRINT_EXPRESSION (awk, px->test); PRINT_EXPRESSION (awk, px->test);
PUT_SRCSTR (awk, ASE_T(")")); PUT_SRCSTR (awk, ASE_T(")"));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
@ -642,7 +644,7 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
if (px->else_part != ASE_NULL) if (px->else_part != ASE_NULL)
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("else")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("else")));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
if (px->else_part->type == ASE_AWK_NDE_BLK) if (px->else_part->type == ASE_AWK_NDE_BLK)
PRINT_STATEMENTS (awk, px->else_part, depth); PRINT_STATEMENTS (awk, px->else_part, depth);
@ -657,7 +659,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p; ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p;
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("while (")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("while")));
PUT_SRCSTR (awk, ASE_T(" ("));
PRINT_EXPRESSION (awk, px->test); PRINT_EXPRESSION (awk, px->test);
PUT_SRCSTR (awk, ASE_T(")")); PUT_SRCSTR (awk, ASE_T(")"));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
@ -677,7 +680,7 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p; ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p;
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("do")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("do")));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
if (px->body->type == ASE_AWK_NDE_BLK) if (px->body->type == ASE_AWK_NDE_BLK)
{ {
@ -689,7 +692,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
} }
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("while (")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("while")));
PUT_SRCSTR (awk, ASE_T(" ("));
PRINT_EXPRESSION (awk, px->test); PRINT_EXPRESSION (awk, px->test);
PUT_SRCSTR (awk, ASE_T(");")); PUT_SRCSTR (awk, ASE_T(");"));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
@ -701,7 +705,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
ase_awk_nde_for_t* px = (ase_awk_nde_for_t*)p; ase_awk_nde_for_t* px = (ase_awk_nde_for_t*)p;
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("for (")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("for")));
PUT_SRCSTR (awk, ASE_T(" ("));
if (px->init != ASE_NULL) if (px->init != ASE_NULL)
{ {
PRINT_EXPRESSION (awk, px->init); PRINT_EXPRESSION (awk, px->init);
@ -735,7 +740,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
ase_awk_nde_foreach_t* px = (ase_awk_nde_foreach_t*)p; ase_awk_nde_foreach_t* px = (ase_awk_nde_foreach_t*)p;
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("for ")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("for")));
PUT_SRCSTR (awk, ASE_T(" "));
PRINT_EXPRESSION (awk, px->test); PRINT_EXPRESSION (awk, px->test);
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
if (px->body->type == ASE_AWK_NDE_BLK) if (px->body->type == ASE_AWK_NDE_BLK)
@ -752,7 +758,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
case ASE_AWK_NDE_BREAK: case ASE_AWK_NDE_BREAK:
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("break;")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("break")));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
break; break;
} }
@ -760,7 +767,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
case ASE_AWK_NDE_CONTINUE: case ASE_AWK_NDE_CONTINUE:
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("continue;")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("continue")));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
break; break;
} }
@ -770,12 +778,14 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
if (((ase_awk_nde_return_t*)p)->val == ASE_NULL) if (((ase_awk_nde_return_t*)p)->val == ASE_NULL)
{ {
PUT_SRCSTR (awk, ASE_T("return;")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("return")));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
} }
else else
{ {
PUT_SRCSTR (awk, ASE_T("return ")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("return")));
PUT_SRCSTR (awk, ASE_T(" "));
ASE_ASSERT (((ase_awk_nde_return_t*)p)->val->next == ASE_NULL); ASE_ASSERT (((ase_awk_nde_return_t*)p)->val->next == ASE_NULL);
PRINT_EXPRESSION (awk, ((ase_awk_nde_return_t*)p)->val); PRINT_EXPRESSION (awk, ((ase_awk_nde_return_t*)p)->val);
@ -792,12 +802,14 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
if (px->val == ASE_NULL) if (px->val == ASE_NULL)
{ {
PUT_SRCSTR (awk, ASE_T("exit;")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("exit")));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
} }
else else
{ {
PUT_SRCSTR (awk, ASE_T("exit ")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("exit")));
PUT_SRCSTR (awk, ASE_T(" "));
ASE_ASSERT (px->val->next == ASE_NULL); ASE_ASSERT (px->val->next == ASE_NULL);
PRINT_EXPRESSION (awk, px->val); PRINT_EXPRESSION (awk, px->val);
PUT_SRCSTR (awk, ASE_T(";")); PUT_SRCSTR (awk, ASE_T(";"));
@ -809,7 +821,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
case ASE_AWK_NDE_NEXT: case ASE_AWK_NDE_NEXT:
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("next;")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("next")));
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
break; break;
} }
@ -818,9 +831,14 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
if (((ase_awk_nde_nextfile_t*)p)->out) if (((ase_awk_nde_nextfile_t*)p)->out)
PUT_SRCSTR (awk, ASE_T("nextofile;")); {
PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("nextofile")));
}
else else
PUT_SRCSTR (awk, ASE_T("nextfile;")); {
PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("nextfile")));
}
PUT_SRCSTR (awk, ASE_T(";"));
PUT_NEWLINE (awk); PUT_NEWLINE (awk);
break; break;
} }
@ -828,7 +846,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
case ASE_AWK_NDE_DELETE: case ASE_AWK_NDE_DELETE:
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("delete ")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("delete")));
PUT_SRCSTR (awk, ASE_T(" "));
ase_awk_prnpt (awk, ((ase_awk_nde_delete_t*)p)->var); ase_awk_prnpt (awk, ((ase_awk_nde_delete_t*)p)->var);
break; break;
} }
@ -836,7 +855,8 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
case ASE_AWK_NDE_RESET: case ASE_AWK_NDE_RESET:
{ {
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
PUT_SRCSTR (awk, ASE_T("reset ")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("reset")));
PUT_SRCSTR (awk, ASE_T(" "));
ase_awk_prnpt (awk, ((ase_awk_nde_reset_t*)p)->var); ase_awk_prnpt (awk, ((ase_awk_nde_reset_t*)p)->var);
break; break;
} }
@ -849,8 +869,13 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
PRINT_TABS (awk, depth); PRINT_TABS (awk, depth);
if (p->type == ASE_AWK_NDE_PRINT) if (p->type == ASE_AWK_NDE_PRINT)
PUT_SRCSTR (awk, ASE_T("print")); {
else PUT_SRCSTR (awk, ASE_T("printf")); PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("print")));
}
else
{
PUT_SRCSTR (awk, ase_awk_getkw(awk,ASE_T("printf")));
}
if (px->args != ASE_NULL) if (px->args != ASE_NULL)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.c,v 1.11 2007/11/02 13:08:58 bacon Exp $ * $Id: val.c,v 1.13 2007/11/09 15:20:02 bacon Exp $
* *
* {License} * {License}
*/ */
@ -135,27 +135,6 @@ ase_awk_val_t* ase_awk_makestrval (
{ {
ase_awk_val_str_t* val; ase_awk_val_str_t* val;
/*
val = (ase_awk_val_str_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_str_t));
if (val == ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return ASE_NULL;
}
val->type = ASE_AWK_VAL_STR;
val->ref = 0;
val->len = len;
val->buf = ase_strxdup (str, len, &run->awk->prmfns.mmgr);
if (val->buf == ASE_NULL)
{
ASE_AWK_FREE (run->awk, val);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return ASE_NULL;
}
*/
val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( val = (ase_awk_val_str_t*) ASE_AWK_MALLOC (
run->awk, run->awk,
ASE_SIZEOF(ase_awk_val_str_t) + ASE_SIZEOF(ase_awk_val_str_t) +
@ -206,27 +185,6 @@ ase_awk_val_t* ase_awk_makestrval2 (
{ {
ase_awk_val_str_t* val; ase_awk_val_str_t* val;
/*
val = (ase_awk_val_str_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_str_t));
if (val == ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return ASE_NULL;
}
val->type = ASE_AWK_VAL_STR;
val->ref = 0;
val->len = len1 + len2;
val->buf = ase_strxdup2 (str1, len1, str2, len2, &run->awk->prmfns.mmgr);
if (val->buf == ASE_NULL)
{
ASE_AWK_FREE (run->awk, val);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return ASE_NULL;
}
*/
val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( val = (ase_awk_val_str_t*) ASE_AWK_MALLOC (
run->awk, run->awk,
ASE_SIZEOF(ase_awk_val_str_t) + ASE_SIZEOF(ase_awk_val_str_t) +

View File

@ -1,5 +1,5 @@
/* /*
* $Id: types.h,v 1.6 2007/05/06 08:08:22 bacon Exp $ * $Id: types.h,v 1.7 2007/11/09 07:43:42 bacon Exp $
* *
* {License} * {License}
*/ */
@ -163,8 +163,9 @@ typedef ase_uint_t ase_word_t;
typedef char ase_mchar_t; typedef char ase_mchar_t;
typedef int ase_mcint_t; typedef int ase_mcint_t;
#if defined(__cplusplus) && !(defined(_MSC_VER)&&(_MSC_VER<=1200)) #if defined(__cplusplus) && (!defined(_MSC_VER) || (defined(_MSC_VER)&&defined(_NATIVE_WCHAR_T_DEFINED)))
/* C++ */ /* C++ */
typedef wchar_t ase_wchar_t; typedef wchar_t ase_wchar_t;
typedef wchar_t ase_wcint_t; typedef wchar_t ase_wcint_t;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.cpp,v 1.47 2007/11/08 15:08:06 bacon Exp $ * $Id: Awk.cpp,v 1.48 2007/11/09 08:09:29 bacon Exp $
*/ */
#include <ase/awk/StdAwk.hpp> #include <ase/awk/StdAwk.hpp>
@ -315,7 +315,7 @@ protected:
} }
else else
{ {
int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): left; int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)left;
int n = ase_fprintf (fp, ASE_T("%.*s"), chunk, buf); int n = ase_fprintf (fp, ASE_T("%.*s"), chunk, buf);
if (n < 0 || n > chunk) return -1; if (n < 0 || n > chunk) return -1;
left -= n; buf += n; left -= n; buf += n;
@ -458,7 +458,7 @@ protected:
} }
else else
{ {
int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): left; int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)left;
int n = ase_fprintf (fp, ASE_T("%.*s"), chunk, buf); int n = ase_fprintf (fp, ASE_T("%.*s"), chunk, buf);
if (n < 0 || n > chunk) return -1; if (n < 0 || n > chunk) return -1;
left -= n; buf += n; left -= n; buf += n;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.23 2007/11/08 15:08:06 bacon Exp $ * $Id: awk.c,v 1.25 2007/11/09 08:29:49 bacon Exp $
*/ */
#include <ase/awk/awk.h> #include <ase/awk/awk.h>
@ -321,7 +321,8 @@ static ase_ssize_t awk_extio_pipe (
case ASE_AWK_IO_READ: case ASE_AWK_IO_READ:
{ {
if (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL) int chunk = (size > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)size;
if (ase_fgets (data, chunk, (FILE*)epa->handle) == ASE_NULL)
{ {
if (ferror((FILE*)epa->handle)) return -1; if (ferror((FILE*)epa->handle)) return -1;
return 0; return 0;
@ -442,7 +443,8 @@ static ase_ssize_t awk_extio_file (
case ASE_AWK_IO_READ: case ASE_AWK_IO_READ:
{ {
if (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL) int chunk = (size > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)size;
if (ase_fgets (data, chunk, (FILE*)epa->handle) == ASE_NULL)
{ {
if (ferror((FILE*)epa->handle)) return -1; if (ferror((FILE*)epa->handle)) return -1;
return 0; return 0;
@ -516,7 +518,9 @@ static ase_ssize_t awk_extio_console (
} }
else if (cmd == ASE_AWK_IO_READ) else if (cmd == ASE_AWK_IO_READ)
{ {
while (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL) int chunk = (size > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)size;
while (ase_fgets (data, chunk, (FILE*)epa->handle) == ASE_NULL)
{ {
if (ferror((FILE*)epa->handle)) return -1; if (ferror((FILE*)epa->handle)) return -1;

View File

@ -1 +1 @@
PARSE ERROR: CODE [30] LINE [2] invalid character '' PARSE ERROR: CODE [31] LINE [2] invalid character ''

View File

@ -3,4 +3,4 @@ BEGIN {
abc = 10; abc = 10;
} }
RUN ERROR: CODE [97] LINE [3] map 'abc' not assignable with a scalar RUN ERROR: CODE [98] LINE [3] map 'abc' not assignable with a scalar

View File

@ -2,4 +2,4 @@ BEGIN {
delete ARGC; delete ARGC;
} }
RUN ERROR: CODE [89] LINE [2] variable 'ARGC' not deletable RUN ERROR: CODE [90] LINE [2] variable 'ARGC' not deletable

View File

@ -3,4 +3,4 @@ BEGIN {
delete iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix; delete iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix;
} }
RUN ERROR: CODE [89] LINE [3] variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...' not deletable RUN ERROR: CODE [90] LINE [3] variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...' not deletable

View File

@ -2,4 +2,4 @@ BEGIN {
helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhelphelp (); helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhelphelp ();
} }
RUN ERROR: CODE [87] LINE [2] function 'helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhel...' not found RUN ERROR: CODE [88] LINE [2] function 'helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhel...' not found

View File

@ -1 +1 @@
PARSE ERROR: CODE [57] LINE [2] intrinsic function 'substr' redefined PARSE ERROR: CODE [58] LINE [2] intrinsic function 'substr' redefined

View File

@ -1 +1 @@
PARSE ERROR: CODE [57] LINE [3] intrinsic function 'substr' redefined PARSE ERROR: CODE [58] LINE [3] intrinsic function 'substr' redefined

View File

@ -1 +1 @@
PARSE ERROR: CODE [58] LINE [9] function 'abc' redefined PARSE ERROR: CODE [59] LINE [9] function 'abc' redefined

View File

@ -1 +1 @@
PARSE ERROR: CODE [59] LINE [4] global variable 'abc' redefined PARSE ERROR: CODE [60] LINE [4] global variable 'abc' redefined

View File

@ -1 +1 @@
PARSE ERROR: CODE [60] LINE [4] parameter 'x' redefined PARSE ERROR: CODE [61] LINE [4] parameter 'x' redefined

View File

@ -1 +1 @@
PARSE ERROR: CODE [58] LINE [11] function 'abc' redefined PARSE ERROR: CODE [59] LINE [11] function 'abc' redefined

View File

@ -1 +1 @@
PARSE ERROR: CODE [58] LINE [1] function 'abc' redefined PARSE ERROR: CODE [59] LINE [1] function 'abc' redefined

View File

@ -1 +1 @@
PARSE ERROR: CODE [43] LINE [5] a colon expected in place of ';' PARSE ERROR: CODE [44] LINE [5] a colon expected in place of ';'

View File

@ -1 +1 @@
PARSE ERROR: CODE [38] LINE [2] a left parenthesis expected in place of '=' PARSE ERROR: CODE [39] LINE [2] a left parenthesis expected in place of '='

View File

@ -1 +1 @@
PARSE ERROR: CODE [53] LINE [2] BEGIN not followed by a left bracket on the same line PARSE ERROR: CODE [54] LINE [2] BEGIN not followed by a left bracket on the same line

View File

@ -1 +1 @@
PARSE ERROR: CODE [64] LINE [1] '+' not a valid parameter name PARSE ERROR: CODE [65] LINE [1] '+' not a valid parameter name

View File

@ -1 +1 @@
PARSE ERROR: CODE [65] LINE [1] '+' not a valid variable name PARSE ERROR: CODE [66] LINE [1] '+' not a valid variable name

View File

@ -1 +1 @@
PARSE ERROR: CODE [65] LINE [3] '+' not a valid variable name PARSE ERROR: CODE [66] LINE [3] '+' not a valid variable name

View File

@ -2,4 +2,4 @@ BEGIN {
print abc > "123\0abc"; print abc > "123\0abc";
} }
RUN ERROR: CODE [113] LINE [2] i/o name containing a null character RUN ERROR: CODE [114] LINE [2] i/o name containing a null character

View File

@ -3,4 +3,4 @@ BEGIN {
split ("a b c",xx); split ("a b c",xx);
} }
RUN ERROR: CODE [98] LINE [3] cannot change a scalar value to a map RUN ERROR: CODE [99] LINE [3] cannot change a scalar value to a map

View File

@ -1 +1 @@
PARSE ERROR: CODE [62] LINE [1] duplicate global variable 'ARGV' PARSE ERROR: CODE [63] LINE [1] duplicate global variable 'ARGV'

View File

@ -1,43 +0,0 @@
CC = cl
CFLAGS = /nologo /MT /W3 /GR- -I..\..\..
LDFLAGS = /libpath:..\..\cmn /libpath:..\..\awk /libpath:..\..\utl
LIBS = asecmn.lib aseawk.lib aseutl.lib kernel32.lib user32.lib
!if !defined(CPU) || "$(CPU)" == ""
CPU = $(PROCESSOR_ARCHITECTURE)
!endif
!if "$(CPU)" == ""
CPU = i386
!endif
!if "$(CPU)" == "IA64" || "$(CPU)" == "AMD64"
LIBS = $(LIBS) bufferoverflowu.lib
!endif
all: aseawk
aseawk: awk.obj
link /nologo /out:$@.exe $(LDFLAGS) $(LIBS) awk.obj
mini: mini.obj
link /nologo /out:$@.exe $(LDFLAGS) $(LIBS) mini.obj
java:
javac -classpath ../../.. Awk.java
javac -classpath ../../.. AwkApplet.java
jrun:
java -classpath ../../.. ase.test.awk.Awk
cert:
keytool -genkey -keystore ase.store -alias asecert
keytool -export -keystore ase.store -alias asecert -file ase.cer
clean:
del $(OBJS) *.obj aseawk.exe mini.exe
.SUFFIXES: .c .obj
.c.obj:
$(CC) /c $(CFLAGS) $<

80
ase/test/awk/msw-cl.mak Normal file
View File

@ -0,0 +1,80 @@
NAME = aseawk
MODE = release
CC = cl
CXX = cl
LD = link
CFLAGS = /nologo /W3 -I..\..\..
CXXFLAGS = /nologo /W3 -I..\..\..
LDFLAGS = /libpath:..\..\$(MODE)\lib
LIBS = asecmn.lib aseawk.lib aseutl.lib kernel32.lib user32.lib
LIBS_CXX = $(LIBS) aseawk++.lib
!IF "$(MODE)" == "debug"
CFLAGS = $(CFLAGS) -D_DEBUG -DDEBUG /MTd
CXXFLAGS = $(CXXFLAGS) -D_DEBUG -DDEBUG /MTd
!ELSEIF "$(MODE)" == "release"
CFLAGS = $(CFLAGS) -DNDEBUG /MT /O2
CXXFLAGS = $(CXXFLAGS) -DNDEBUG /MT /O2
!ELSE
CFLAGS = $(CFLAGS) /MT
CXXFLAGS = $(CXXFLAGS) /MT
!ENDIF
!if !defined(CPU) || "$(CPU)" == ""
CPU = $(PROCESSOR_ARCHITECTURE)
!endif
!if "$(CPU)" == ""
CPU = i386
!endif
!if "$(CPU)" == "IA64" || "$(CPU)" == "AMD64"
# comment out the following line if you encounter this link error.
# LINK : fatal error LNK1181: cannot open input file 'bufferoverflowu.lib'
LIBS = $(LIBS) bufferoverflowu.lib
!endif
OUT_DIR = ..\..\$(MODE)\bin
OUT_FILE_BIN = $(OUT_DIR)\$(NAME).exe
OUT_FILE_BIN_CXX = $(OUT_DIR)\$(NAME)++.exe
TMP_DIR = $(MODE)
TMP_DIR_CXX = $(TMP_DIR)\cxx
OBJ_FILES_BIN = $(TMP_DIR)\awk.obj
OBJ_FILES_BIN_CXX = $(TMP_DIR_CXX)\Awk.obj
all: bin
bin: $(OUT_FILE_BIN) $(OUT_FILE_BIN_CXX)
$(OUT_FILE_BIN): $(TMP_DIR) $(OUT_DIR) $(OBJ_FILES_BIN)
$(LD) /nologo /out:$@ $(LDFLAGS) $(LIBS) $(OBJ_FILES_BIN)
$(OUT_FILE_BIN_CXX): $(TMP_DIR_CXX) $(OUT_FILE_BIN) $(OBJ_FILES_BIN_CXX)
$(LD) /nologo /out:$@ $(LDFLAGS) $(LIBS_CXX) $(OBJ_FILES_BIN_CXX)
$(TMP_DIR)\awk.obj: awk.c
$(CC) $(CFLAGS) /Fo$@ /c awk.c
$(TMP_DIR_CXX)\Awk.obj: Awk.cpp
$(CC) $(CXXFLAGS) /Fo$@ /c Awk.cpp
$(OUT_DIR):
-md $(OUT_DIR)
$(TMP_DIR):
-md $(TMP_DIR)
$(TMP_DIR_CXX): $(TMP_DIR)
-md $(TMP_DIR_CXX)
clean:
-del $(OUT_FILE_BIN)
-del $(OUT_FILE_BIN_CXX)
-del $(OBJ_FILES_BIN)
-del $(OBJ_FILES_BIN_CXX)