From 1fb4e03c11a7889faec1f83f91ebdab2143076f2 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 29 Oct 2007 00:11:00 +0000 Subject: [PATCH] Recovered from cvs revision 2007-10-28 06:12:00 --- ase/awk/extio.c | 16 ++------- ase/awk/parse.c | 8 +++-- ase/net/Awk.hpp | 83 +++++++++++++++++++++++++++++----------------- ase/test/awk/awk.c | 10 +++++- 4 files changed, 69 insertions(+), 48 deletions(-) diff --git a/ase/awk/extio.c b/ase/awk/extio.c index 6493ce07..155bde9d 100644 --- a/ase/awk/extio.c +++ b/ase/awk/extio.c @@ -1,5 +1,5 @@ /* - * $Id: extio.c,v 1.6 2007/10/25 14:43:17 bacon Exp $ + * $Id: extio.c,v 1.7 2007/10/26 12:49:24 bacon Exp $ * * {License} */ @@ -74,8 +74,6 @@ 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) @@ -394,8 +392,8 @@ int ase_awk_readextio ( rs->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, rs_ptr); ase_awk_refdownval (run, rs); - /* increment NR */ - if (ret != -1 && ret != 0) + /* increment NR for console input */ + if (extio_type == ASE_AWK_EXTIO_CONSOLE && ret != -1 && ret != 0) { ase_awk_val_t* nr; ase_long_t lv; @@ -411,14 +409,6 @@ 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) ret = -1; else diff --git a/ase/awk/parse.c b/ase/awk/parse.c index 3549a79b..90dcbbf7 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.23 2007/10/25 14:43:17 bacon Exp $ + * $Id: parse.c,v 1.24 2007/10/26 12:49:24 bacon Exp $ * * {License} */ @@ -298,11 +298,13 @@ static global_t gtab[] = /* ignore case in string comparison */ { ASE_T("IGNORECASE"), 10, 0 }, - /* number of fields in current input record */ + /* number of fields in current input record + * NF is also updated if you assign a value to $0. so it is not + * associated with ASE_AWK_PABLOCK */ { ASE_T("NF"), 2, 0 }, /* input record number */ - { ASE_T("NR"), 2, 0 }, + { ASE_T("NR"), 2, ASE_AWK_PABLOCK }, /* current output file name */ { ASE_T("OFILENAME"), 9, ASE_AWK_PABLOCK | ASE_AWK_NEXTOFILE }, diff --git a/ase/net/Awk.hpp b/ase/net/Awk.hpp index e581ce92..5e423640 100644 --- a/ase/net/Awk.hpp +++ b/ase/net/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.40 2007/10/21 07:59:35 bacon Exp $ + * $Id: Awk.hpp,v 1.41 2007/10/26 12:49:24 bacon Exp $ * * {License} */ @@ -442,6 +442,27 @@ public: } public: + enum class GLOBAL: int + { + ARGC = ASE::Awk::GBL_ARGC, + ARGV = ASE::Awk::GBL_ARGV, + CONVFMT = ASE::Awk::GBL_CONVFMT, + FILENAME = ASE::Awk::GBL_FILENAME, + FNR = ASE::Awk::GBL_FNR, + FS = ASE::Awk::GBL_FS, + IGNORECASE = ASE::Awk::GBL_IGNORECASE, + NF = ASE::Awk::GBL_NF, + NR = ASE::Awk::GBL_NR, + OFILENAME = ASE::Awk::GBL_OFILENAME, + OFMT = ASE::Awk::GBL_OFMT, + OFS = ASE::Awk::GBL_OFS, + ORS = ASE::Awk::GBL_ORS, + RLENGTH = ASE::Awk::GBL_RLENGTH, + RS = ASE::Awk::GBL_RS, + RSTART = ASE::Awk::GBL_RSTART, + SUBSEP = ASE::Awk::GBL_SUBSEP + }; + property Awk^ Owner { Awk^ get () { return this->owner; } @@ -482,70 +503,70 @@ public: (ASE::Awk::ErrorCode)num, line, p); } - bool SetGlobal (int id, System::String^ v) + bool SetGlobal (GLOBAL id, System::String^ v) { cli::pin_ptr nptr = PtrToStringChars(v); - return run.setGlobal (id, nptr, v->Length) == 0; + return run.setGlobal ((ASE::Awk::Global)id, nptr, v->Length) == 0; } - bool SetGlobal (int id, long_t v) + bool SetGlobal (GLOBAL id, long_t v) { - return run.setGlobal (id, v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, v) == 0; } - bool SetGlobal (int id, System::SByte^ v) + bool SetGlobal (GLOBAL id, System::SByte^ v) { - return run.setGlobal (id, (long_t)(__int8)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (long_t)(__int8)v) == 0; } - bool SetGlobal (int id, System::Int16^ v) + bool SetGlobal (GLOBAL id, System::Int16^ v) { - return run.setGlobal (id, (long_t)(__int16)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (long_t)(__int16)v) == 0; } - bool SetGlobal (int id, System::Int32^ v) + bool SetGlobal (GLOBAL id, System::Int32^ v) { - return run.setGlobal (id, (long_t)(__int32)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (long_t)(__int32)v) == 0; } - bool SetGlobal (int id, System::Int64^ v) + bool SetGlobal (GLOBAL id, System::Int64^ v) { - return run.setGlobal (id, (long_t)(__int64)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (long_t)(__int64)v) == 0; } - bool SetGlobal (int id, System::Byte^ v) + bool SetGlobal (GLOBAL id, System::Byte^ v) { - return run.setGlobal (id, (long_t)(unsigned __int8)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (long_t)(unsigned __int8)v) == 0; } - bool SetGlobal (int id, System::UInt16^ v) + bool SetGlobal (GLOBAL id, System::UInt16^ v) { - return run.setGlobal (id, (long_t)(unsigned __int16)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (long_t)(unsigned __int16)v) == 0; } - bool SetGlobal (int id, System::UInt32^ v) + bool SetGlobal (GLOBAL id, System::UInt32^ v) { - return run.setGlobal (id, (long_t)(unsigned __int32)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (long_t)(unsigned __int32)v) == 0; } - bool SetGlobal (int id, System::UInt64^ v) + bool SetGlobal (GLOBAL id, System::UInt64^ v) { - return run.setGlobal (id, (long_t)(unsigned __int64)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (long_t)(unsigned __int64)v) == 0; } - bool SetGlobal (int id, real_t v) + bool SetGlobal (GLOBAL id, real_t v) { - return run.setGlobal (id, v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, v) == 0; } - bool SetGlobal (int id, System::Single^ v) + bool SetGlobal (GLOBAL id, System::Single^ v) { - return run.setGlobal (id, (real_t)(float)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (real_t)(float)v) == 0; } - bool SetGlobal (int id, System::Double^ v) + bool SetGlobal (GLOBAL id, System::Double^ v) { - return run.setGlobal (id, (real_t)(double)v) == 0; + return run.setGlobal ((ASE::Awk::Global)id, (real_t)(double)v) == 0; } - bool SetGlobal (int id, Return^ v) + bool SetGlobal (GLOBAL id, Return^ v) { - return run.setGlobal (id, v->ret) == 0; + return run.setGlobal ((ASE::Awk::Global)id, v->ret) == 0; } - bool GetGlobal (int id, [System::Runtime::InteropServices::Out] Argument^% v) + bool GetGlobal (GLOBAL id, [System::Runtime::InteropServices::Out] Argument^% v) { - return run.getGlobal (id, *v->arg) == 0; + return run.getGlobal ((ASE::Awk::Global)id, *v->arg) == 0; } public protected: diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index e6ae4514..10e02f55 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.19 2007/10/11 14:39:46 bacon Exp $ + * $Id: awk.c,v 1.20 2007/10/26 12:49:24 bacon Exp $ */ #include @@ -554,6 +554,14 @@ static ase_ssize_t awk_extio_console ( return -1; } + if (ase_awk_setglobal ( + epa->run, ASE_AWK_GLOBAL_NR, ase_awk_val_zero) == -1) + { + /* need to reset NR */ + fclose (fp); + return -1; + } + if (epa->handle != ASE_NULL && epa->handle != stdin && epa->handle != stdout &&