From d60e97954b32b8e9fa6ac1e1ac497804a71a566d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 26 Oct 2007 21:49:00 +0000 Subject: [PATCH] Recovered from cvs revision 2007-10-26 12:49:00 --- ase/awk/Awk.hpp | 3 +- ase/awk/awk.h | 3 +- ase/awk/extio.c | 18 +++++++---- ase/awk/func.c | 4 +-- ase/awk/parse.c | 59 +++++++++++++++++++++++++++-------- ase/awk/run.c | 4 +-- ase/test/awk/AseAwkPanel.java | 3 +- 7 files changed, 65 insertions(+), 29 deletions(-) diff --git a/ase/awk/Awk.hpp b/ase/awk/Awk.hpp index 6baad562..c99804cb 100644 --- a/ase/awk/Awk.hpp +++ b/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.78 2007/10/21 07:59:35 bacon Exp $ + * $Id: Awk.hpp,v 1.79 2007/10/25 14:43:17 bacon Exp $ * * {License} */ @@ -571,7 +571,6 @@ public: GBL_ARGC = ASE_AWK_GLOBAL_ARGC, GBL_ARGV = ASE_AWK_GLOBAL_ARGV, GBL_CONVFMT = ASE_AWK_GLOBAL_CONVFMT, - GBL_ENVIRON = ASE_AWK_GLOBAL_ENVIRON, GBL_FILENAME = ASE_AWK_GLOBAL_FILENAME, GBL_FNR = ASE_AWK_GLOBAL_FNR, GBL_FS = ASE_AWK_GLOBAL_FS, diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 878c94ba..acdad536 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.22 2007/10/24 09:57:45 bacon Exp $ + * $Id: awk.h,v 1.23 2007/10/25 14:43:17 bacon Exp $ * * {License} */ @@ -408,7 +408,6 @@ enum ase_awk_global_id_t ASE_AWK_GLOBAL_ARGC, ASE_AWK_GLOBAL_ARGV, ASE_AWK_GLOBAL_CONVFMT, - ASE_AWK_GLOBAL_ENVIRON, ASE_AWK_GLOBAL_FILENAME, ASE_AWK_GLOBAL_FNR, ASE_AWK_GLOBAL_FS, diff --git a/ase/awk/extio.c b/ase/awk/extio.c index 066931d5..6493ce07 100644 --- a/ase/awk/extio.c +++ b/ase/awk/extio.c @@ -1,5 +1,5 @@ /* - * $Id: extio.c,v 1.5 2007/10/21 13:58:47 bacon Exp $ + * $Id: extio.c,v 1.6 2007/10/25 14:43:17 bacon Exp $ * * {License} */ @@ -74,6 +74,8 @@ static int out_mask_map[] = MASK_WRITE }; +#include +#include int ase_awk_readextio ( ase_awk_run_t* run, int in_type, const ase_char_t* name, ase_str_t* buf) @@ -409,12 +411,16 @@ int ase_awk_readextio ( { if (n == 1) lv = (ase_long_t)rv; + +// TODO---> WRONG: NR SHOULD BE UPDATED FOR CONSOLE INPUT... +// { print "NR=" NR; a=getline<"awk.c"; print a; } +{ + wchar_t x[100]; + _sntprintf (x, 100, _T("ddd %d\n"), (int)lv); +OutputDebugStringW (x); +} nr = ase_awk_makeintval (run, lv + 1); - if (nr == ASE_NULL) - { - /*ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);*/ - ret = -1; - } + if (nr == ASE_NULL) ret = -1; else { if (ase_awk_setglobal ( diff --git a/ase/awk/func.c b/ase/awk/func.c index 5834e6ec..e21f577b 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,5 +1,5 @@ /* - * $Id: func.c,v 1.12 2007/10/24 09:57:45 bacon Exp $ + * $Id: func.c,v 1.13 2007/10/25 14:43:17 bacon Exp $ * * {License} */ @@ -142,7 +142,7 @@ ase_awk_bfn_t* ase_awk_getbfn ( for (bfn = sys_bfn; bfn->name.ptr != ASE_NULL; bfn++) { if (bfn->valid != 0 && - (awk->option & bfn->valid) == 0) continue; + (awk->option & bfn->valid) != bfn->valid) continue; pair = ase_awk_map_get ( awk->kwtab, bfn->name.ptr, bfn->name.len); diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 5b051bbf..3549a79b 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.22 2007/10/24 14:17:32 bacon Exp $ + * $Id: parse.c,v 1.23 2007/10/25 14:43:17 bacon Exp $ * * {License} */ @@ -82,7 +82,6 @@ enum TOKEN_EXIT, TOKEN_NEXT, TOKEN_NEXTFILE, - TOKEN_NEXTINFILE, TOKEN_NEXTOFILE, TOKEN_DELETE, TOKEN_RESET, @@ -256,9 +255,9 @@ static kwent_t kwtab[] = { ASE_T("continue"), 8, TOKEN_CONTINUE, 0 }, { ASE_T("return"), 6, TOKEN_RETURN, 0 }, { ASE_T("exit"), 4, TOKEN_EXIT, 0 }, - { ASE_T("next"), 4, TOKEN_NEXT, 0 }, - { ASE_T("nextfile"), 8, TOKEN_NEXTFILE, 0 }, - { ASE_T("nextofile"), 9, TOKEN_NEXTOFILE, ASE_AWK_NEXTOFILE }, + { ASE_T("next"), 4, TOKEN_NEXT, ASE_AWK_PABLOCK }, + { ASE_T("nextfile"), 8, TOKEN_NEXTFILE, ASE_AWK_PABLOCK }, + { ASE_T("nextofile"), 9, TOKEN_NEXTOFILE, ASE_AWK_PABLOCK | ASE_AWK_NEXTOFILE }, { ASE_T("delete"), 6, TOKEN_DELETE, 0 }, { ASE_T("reset"), 5, TOKEN_RESET, ASE_AWK_RESET }, { ASE_T("print"), 5, TOKEN_PRINT, ASE_AWK_EXTIO }, @@ -283,18 +282,42 @@ static global_t gtab[] = { { ASE_T("ARGC"), 4, 0 }, { ASE_T("ARGV"), 4, 0 }, + + /* output real-to-str conversion format for other cases than 'print' */ { ASE_T("CONVFMT"), 7, 0 }, - { ASE_T("ENVIRON"), 7, 0 }, - { ASE_T("FILENAME"), 8, 0 }, - { ASE_T("FNR"), 3, 0 }, + + /* current input file name */ + { ASE_T("FILENAME"), 8, ASE_AWK_PABLOCK }, + + /* input record number in current file */ + { ASE_T("FNR"), 3, ASE_AWK_PABLOCK }, + + /* input field separator */ { ASE_T("FS"), 2, 0 }, + + /* ignore case in string comparison */ { ASE_T("IGNORECASE"), 10, 0 }, + + /* number of fields in current input record */ { ASE_T("NF"), 2, 0 }, + + /* input record number */ { ASE_T("NR"), 2, 0 }, - { ASE_T("OFILENAME"), 9, ASE_AWK_NEXTOFILE }, - { ASE_T("OFMT"), 4, 0 }, - { ASE_T("OFS"), 3, 0 }, - { ASE_T("ORS"), 3, 0 }, + + /* current output file name */ + { ASE_T("OFILENAME"), 9, ASE_AWK_PABLOCK | ASE_AWK_NEXTOFILE }, + + /* output real-to-str conversion format for 'print' */ + { ASE_T("OFMT"), 4, ASE_AWK_EXTIO}, + + /* output field separator for 'print' */ + { ASE_T("OFS"), 3, ASE_AWK_EXTIO }, + + /* output record separator. used for 'print' and blockless output + * ASE_AWK_BLOCKLESS desn't have to be specified becuase + * it requires ASE_AWK_EXTIO to be ON. */ + { ASE_T("ORS"), 3, ASE_AWK_EXTIO }, + { ASE_T("RLENGTH"), 7, 0 }, { ASE_T("RS"), 2, 0 }, { ASE_T("RSTART"), 6, 0 }, @@ -718,6 +741,7 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk) { /* blockless pattern */ ase_bool_t newline = MATCH(awk,TOKEN_NEWLINE); + ase_size_t tline = awk->token.prev.line; awk->parse.id.block = PARSE_ACTION_BLOCK; if (parse_pattern_block ( @@ -738,6 +762,15 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk) return ASE_NULL; } } + + if ((awk->option & ASE_AWK_EXTIO) != ASE_AWK_EXTIO) + { + /* blockless pattern requires ASE_AWK_EXTIO + * to be ON because the implicit block is + * "print $0" */ + SETERRLIN (awk, ASE_AWK_ENOSUP, tline); + return ASE_NULL; + } } else { @@ -5029,7 +5062,7 @@ static int classify_ident ( ase_size_t l; if (kwp->valid != 0 && - (awk->option & kwp->valid) == 0) continue; + (awk->option & kwp->valid) != kwp->valid) continue; pair = ase_awk_map_get (awk->kwtab, kwp->name, kwp->name_len); if (pair != ASE_NULL) diff --git a/ase/awk/run.c b/ase/awk/run.c index 2caf57da..04113aed 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.18 2007/10/21 13:58:47 bacon Exp $ + * $Id: run.c,v 1.19 2007/10/25 14:43:17 bacon Exp $ * * {License} */ @@ -1624,7 +1624,6 @@ static int run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) /* adjust the error line */ run->errlin = nde->line; - return -1; } @@ -1637,7 +1636,6 @@ static int run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) /* adjust the error line */ run->errlin = nde->line; - return -1; } diff --git a/ase/test/awk/AseAwkPanel.java b/ase/test/awk/AseAwkPanel.java index 37ff30a3..f42cc8d8 100644 --- a/ase/test/awk/AseAwkPanel.java +++ b/ase/test/awk/AseAwkPanel.java @@ -1,5 +1,5 @@ /* - * $Id: AseAwkPanel.java,v 1.10 2007/10/24 14:17:32 bacon Exp $ + * $Id: AseAwkPanel.java,v 1.11 2007/10/25 14:43:17 bacon Exp $ */ import java.awt.*; @@ -97,6 +97,7 @@ public class AseAwkPanel extends Panel setWord ("OFMT", "ofmt"); setOption (getOption() | StdAwk.OPTION_MAPTOVAR); + //setOption (getOption() & ~StdAwk.OPTION_EXTIO); } public void sleep (Context ctx, String name, Return ret, Argument[] args)