From 0098186950eba25393c9441b11e5b9bc804b6a4f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 23 Nov 2006 14:27:52 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/awk.h | 6 +-- ase/awk/extio.c | 3 +- ase/awk/jni.c | 4 +- ase/awk/parse.c | 98 +++++++++++++++++++++++++++++-------------------- ase/awk/run.c | 3 +- ase/awk/run.h | 7 ++-- ase/awk/val.c | 16 +++++--- ase/awk/val.h | 4 +- 8 files changed, 84 insertions(+), 57 deletions(-) diff --git a/ase/awk/awk.h b/ase/awk/awk.h index b2fcc269..c73fd223 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.149 2006-11-23 03:31:35 bacon Exp $ + * $Id: awk.h,v 1.150 2006-11-23 14:27:51 bacon Exp $ */ #ifndef _ASE_AWK_AWK_H_ @@ -190,10 +190,10 @@ enum ASE_AWK_STRIPSPACES = (1 << 12), /* enable the nextoutfile keyword */ - ASE_AWK_NEXTOUTFILE = (1 << 13), + ASE_AWK_NEXTOFILE = (1 << 13), /* a newline terminates a statement */ - ASE_AWK_NEWLINE = (1 << 14) + ASE_AWK_NEWLINE = (1 << 14) }; /* error code */ diff --git a/ase/awk/extio.c b/ase/awk/extio.c index 86bf233f..05ac7a12 100644 --- a/ase/awk/extio.c +++ b/ase/awk/extio.c @@ -1,5 +1,5 @@ /* - * $Id: extio.c,v 1.63 2006-11-23 03:31:35 bacon Exp $ + * $Id: extio.c,v 1.64 2006-11-23 14:27:51 bacon Exp $ */ #include @@ -283,6 +283,7 @@ int ase_awk_readextio ( * terminator of the previous line */ /* TODO: handle different line terminator like \r\n */ ASE_AWK_STR_LEN(buf) -= 1; + break; } } diff --git a/ase/awk/jni.c b/ase/awk/jni.c index fef3ee95..709e5933 100644 --- a/ase/awk/jni.c +++ b/ase/awk/jni.c @@ -1,5 +1,5 @@ /* - * $Id: jni.c,v 1.21 2006-11-23 03:31:36 bacon Exp $ + * $Id: jni.c,v 1.22 2006-11-23 14:27:51 bacon Exp $ */ #include @@ -197,7 +197,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj) opt = ASE_AWK_EXPLICIT | ASE_AWK_UNIQUE | ASE_AWK_DBLSLASHES | ASE_AWK_SHADING | ASE_AWK_IMPLICIT | ASE_AWK_SHIFT | ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_HASHSIGN | - ASE_AWK_NEXTOUTFILE; + ASE_AWK_NEXTOFILE; ase_awk_setopt (awk, opt); printf ("__awk(native) done => %u, 0x%X\n", awk, awk); diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 138b7fc4..a4d099b5 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.205 2006-11-23 03:31:36 bacon Exp $ + * $Id: parse.c,v 1.206 2006-11-23 14:27:51 bacon Exp $ */ #include @@ -79,7 +79,7 @@ enum TOKEN_NEXT, TOKEN_NEXTFILE, TOKEN_NEXTINFILE, - TOKEN_NEXTOUTFILE, + TOKEN_NEXTOFILE, TOKEN_DELETE, TOKEN_PRINT, TOKEN_PRINTF, @@ -128,7 +128,7 @@ static ase_awk_t* __parse_progunit (ase_awk_t* awk); static ase_awk_t* __collect_globals (ase_awk_t* awk); static ase_awk_t* __add_builtin_globals (ase_awk_t* awk); static ase_awk_t* __add_global ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len); + ase_awk_t* awk, const ase_char_t* name, ase_size_t len, int force); static ase_awk_t* __collect_locals (ase_awk_t* awk, ase_size_t nlocals); static ase_awk_nde_t* __parse_function (ase_awk_t* awk); @@ -245,7 +245,7 @@ static struct __kwent __kwtab[] = { ASE_T("exit"), 4, TOKEN_EXIT, 0 }, { ASE_T("next"), 4, TOKEN_NEXT, 0 }, { ASE_T("nextfile"), 8, TOKEN_NEXTFILE, 0 }, - { ASE_T("nextoutfile"), 11, TOKEN_NEXTOUTFILE, ASE_AWK_NEXTOUTFILE }, + { ASE_T("nextofile"), 9, TOKEN_NEXTOFILE, ASE_AWK_NEXTOFILE }, { ASE_T("delete"), 6, TOKEN_DELETE, 0 }, { ASE_T("print"), 5, TOKEN_PRINT, ASE_AWK_EXTIO }, { ASE_T("printf"), 6, TOKEN_PRINTF, ASE_AWK_EXTIO }, @@ -265,26 +265,25 @@ struct __bvent static struct __bvent __bvtab[] = { - { ASE_T("ARGC"), 4, 0 }, - { ASE_T("ARGV"), 4, 0 }, - { ASE_T("CONVFMT"), 7, 0 }, - { ASE_T("ENVIRON"), 7, 0 }, - { ASE_T("ERRNO"), 5, 0 }, - { ASE_T("FILENAME"), 8, 0 }, - { ASE_T("FNR"), 3, 0 }, - { ASE_T("FS"), 2, 0 }, - { ASE_T("IGNORECASE"), 10, 0 }, - { ASE_T("NF"), 2, 0 }, - { ASE_T("NR"), 2, 0 }, - { ASE_T("OFMT"), 4, 0 }, - { ASE_T("OFS"), 3, 0 }, - { ASE_T("ORS"), 3, 0 }, - { ASE_T("RS"), 2, 0 }, - { ASE_T("RT"), 2, 0 }, - { ASE_T("RSTART"), 6, 0 }, - { ASE_T("RLENGTH"), 7, 0 }, - { ASE_T("SUBSEP"), 6, 0 }, - { ASE_NULL, 0, 0 } + { ASE_T("ARGC"), 4, 0 }, + { ASE_T("ARGV"), 4, 0 }, + { ASE_T("CONVFMT"), 7, 0 }, + { ASE_T("ENVIRON"), 7, 0 }, + { ASE_T("ERRNO"), 5, 0 }, + { ASE_T("FILENAME"), 8, 0 }, + { ASE_T("FNR"), 3, 0 }, + { ASE_T("FS"), 2, 0 }, + { ASE_T("IGNORECASE"), 10, 0 }, + { ASE_T("NF"), 2, 0 }, + { ASE_T("NR"), 2, 0 }, + { ASE_T("OFMT"), 4, 0 }, + { ASE_T("OFS"), 3, 0 }, + { ASE_T("ORS"), 3, 0 }, + { ASE_T("RLENGTH"), 7, 0 }, + { ASE_T("RS"), 2, 0 }, + { ASE_T("RSTART"), 6, 0 }, + { ASE_T("SUBSEP"), 6, 0 }, + { ASE_NULL, 0, 0 } }; #define GET_CHAR(awk) \ @@ -1009,12 +1008,26 @@ and merged to top-level block */ static ase_awk_t* __add_builtin_globals (ase_awk_t* awk) { struct __bvent* p = __bvtab; + ase_awk_t* tmp; awk->tree.nbglobals = 0; while (p->name != ASE_NULL) { - if (__add_global (awk, - p->name, p->name_len) == ASE_NULL) return ASE_NULL; + + if (p->valid != 0 && (awk->option & p->valid) == 0) + { + /* an invalid global variable are still added + * to the global variable table with an empty name. + * this is to prevent the run-time from looking up + * the variable */ + tmp =__add_global (awk, ASE_T(""), 0, 1); + } + else + { + tmp =__add_global (awk, p->name, p->name_len, 0); + } + if (tmp == ASE_NULL) return ASE_NULL; + awk->tree.nbglobals++; p++; } @@ -1023,21 +1036,26 @@ static ase_awk_t* __add_builtin_globals (ase_awk_t* awk) } static ase_awk_t* __add_global ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t len) + ase_awk_t* awk, const ase_char_t* name, ase_size_t len, int force) { - if (awk->option & ASE_AWK_UNIQUE) + if (!force) { - /* check if it conflict with a function name */ - if (ase_awk_map_get(&awk->tree.afns, name, len) != ASE_NULL) + if (awk->option & ASE_AWK_UNIQUE) { - PANIC (awk, ASE_AWK_EDUPNAME); + /* check if it conflict with a function name */ + if (ase_awk_map_get ( + &awk->tree.afns, name, len) != ASE_NULL) + { + PANIC (awk, ASE_AWK_EDUPNAME); + } } - } - /* check if it conflicts with other global variable names */ - if (ase_awk_tab_find (&awk->parse.globals, 0, name, len) != (ase_size_t)-1) - { - PANIC (awk, ASE_AWK_EDUPVAR); + /* check if it conflicts with other global variable names */ + if (ase_awk_tab_find ( + &awk->parse.globals, 0, name, len) != (ase_size_t)-1) + { + PANIC (awk, ASE_AWK_EDUPVAR); + } } if (ase_awk_tab_getsize(&awk->parse.globals) >= ASE_AWK_MAX_GLOBALS) @@ -1062,9 +1080,11 @@ static ase_awk_t* __collect_globals (ase_awk_t* awk) PANIC (awk, ASE_AWK_EIDENT); } - if (__add_global (awk, + if (__add_global ( + awk, ASE_AWK_STR_BUF(&awk->token.name), - ASE_AWK_STR_LEN(&awk->token.name)) == ASE_NULL) return ASE_NULL; + ASE_AWK_STR_LEN(&awk->token.name), + 0) == ASE_NULL) return ASE_NULL; if (__get_token(awk) == -1) return ASE_NULL; @@ -1261,7 +1281,7 @@ awk->parse.nl_semicolon = 1; if (__get_token(awk) == -1) return ASE_NULL; nde = __parse_nextfile (awk, 0); } - else if (MATCH(awk,TOKEN_NEXTOUTFILE)) + else if (MATCH(awk,TOKEN_NEXTOFILE)) { if (__get_token(awk) == -1) return ASE_NULL; nde = __parse_nextfile (awk, 1); diff --git a/ase/awk/run.c b/ase/awk/run.c index 2bed9a54..8a609121 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.282 2006-11-23 03:45:06 bacon Exp $ + * $Id: run.c,v 1.283 2006-11-23 14:27:51 bacon Exp $ */ #include @@ -2049,7 +2049,6 @@ static int __run_nextoutfile (ase_awk_run_t* run) return 0; } - /* TODO: update_ofnr */ return 0; } diff --git a/ase/awk/run.h b/ase/awk/run.h index 1faef18e..07a495c8 100644 --- a/ase/awk/run.h +++ b/ase/awk/run.h @@ -1,5 +1,5 @@ /* - * $Id: run.h,v 1.26 2006-11-19 11:55:17 bacon Exp $ + * $Id: run.h,v 1.27 2006-11-23 14:27:52 bacon Exp $ */ #ifndef _ASE_AWK_RUN_H_ @@ -93,10 +93,9 @@ enum ase_awk_global_id_t ASE_AWK_GLOBAL_OFMT, ASE_AWK_GLOBAL_OFS, ASE_AWK_GLOBAL_ORS, - ASE_AWK_GLOBAL_RS, - ASE_AWK_GLOBAL_RT, - ASE_AWK_GLOBAL_RSTART, ASE_AWK_GLOBAL_RLENGTH, + ASE_AWK_GLOBAL_RS, + ASE_AWK_GLOBAL_RSTART, ASE_AWK_GLOBAL_SUBSEP }; diff --git a/ase/awk/val.c b/ase/awk/val.c index fe23bf21..0ac3fe45 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -1,5 +1,5 @@ /* - * $Id: val.c,v 1.92 2006-11-22 06:05:45 bacon Exp $ + * $Id: val.c,v 1.93 2006-11-23 14:27:52 bacon Exp $ */ #include @@ -15,10 +15,13 @@ static ase_char_t* __val_real_to_str ( int opt, ase_awk_str_t* buf, ase_size_t* len); static ase_awk_val_nil_t __awk_nil = { ASE_AWK_VAL_NIL, 0 }; -ase_awk_val_t* ase_awk_val_nil = (ase_awk_val_t*)&__awk_nil; - static ase_awk_val_str_t __awk_zls = { ASE_AWK_VAL_STR, 0, ASE_T(""), 0 }; +/* TODO: consider different line ending schemes */ +static ase_awk_val_str_t __awk_nl = { ASE_AWK_VAL_STR, 0, ASE_T("\n"), 1 }; + +ase_awk_val_t* ase_awk_val_nil = (ase_awk_val_t*)&__awk_nil; ase_awk_val_t* ase_awk_val_zls = (ase_awk_val_t*)&__awk_zls; +ase_awk_val_t* ase_awk_val_nl = (ase_awk_val_t*)&__awk_nl; static ase_awk_val_int_t __awk_int[] = { @@ -249,8 +252,11 @@ ase_awk_val_t* ase_awk_makerefval (ase_awk_run_t* run, int id, ase_awk_val_t** a ase_bool_t ase_awk_isbuiltinval (ase_awk_val_t* val) { return val == ASE_NULL || - val == ase_awk_val_nil || val == ase_awk_val_zls || - val == ase_awk_val_zero || val == ase_awk_val_one || + val == ase_awk_val_nil || + val == ase_awk_val_zls || + val == ase_awk_val_nl || + val == ase_awk_val_zero || + val == ase_awk_val_one || (val >= (ase_awk_val_t*)&__awk_int[0] && val <= (ase_awk_val_t*)&__awk_int[ase_countof(__awk_int)-1]); } diff --git a/ase/awk/val.h b/ase/awk/val.h index 355ddf77..0d3fcef8 100644 --- a/ase/awk/val.h +++ b/ase/awk/val.h @@ -1,5 +1,5 @@ /* - * $Id: val.h,v 1.52 2006-11-19 11:55:17 bacon Exp $ + * $Id: val.h,v 1.53 2006-11-23 14:27:52 bacon Exp $ */ #ifndef _ASE_AWK_VAL_H_ @@ -137,6 +137,8 @@ extern "C" { extern ase_awk_val_t* ase_awk_val_nil; extern ase_awk_val_t* ase_awk_val_zls; +extern ase_awk_val_t* ase_awk_val_nl; +extern ase_awk_val_t* ase_awk_val_bnl; extern ase_awk_val_t* ase_awk_val_zero; extern ase_awk_val_t* ase_awk_val_one;