From 5c8dda1041c920bd07806081fed42a7e7e64fe4f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 1 Oct 2007 00:12:00 +0000 Subject: [PATCH] Recovered from cvs revision 2007-09-29 01:11:00 --- ase/awk/Awk.cpp | 10 +---- ase/awk/Awk.hpp | 6 ++- ase/awk/Awk.java | 4 +- ase/awk/awk.h | 9 +++-- ase/awk/run.c | 40 +++++++++++--------- ase/change.log | 11 +++++- ase/net/Awk.hpp | 5 ++- ase/test/awk/Awk.cpp | 79 ++++++++++++++++++++++++++++------------ ase/test/awk/asm.awk | 6 +-- ase/test/awk/awk.c | 20 ++++++---- ase/test/awk/err-003.awk | 2 - ase/test/awk/err-003.out | 2 +- ase/test/awk/err-004.out | 2 +- ase/test/awk/err-005.out | 2 +- ase/test/awk/err-006.out | 2 +- ase/test/awk/err-020.out | 2 +- ase/test/awk/err-021.out | 2 +- 17 files changed, 126 insertions(+), 78 deletions(-) diff --git a/ase/awk/Awk.cpp b/ase/awk/Awk.cpp index f624b20e..3777830a 100644 --- a/ase/awk/Awk.cpp +++ b/ase/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.59 2007/09/25 07:17:30 bacon Exp $ + * $Id: Awk.cpp,v 1.60 2007/09/27 11:30:20 bacon Exp $ * * {License} */ @@ -630,17 +630,11 @@ int Awk::open () int opt = OPT_IMPLICIT | - OPT_EXPLICIT | OPT_UNIQUEFN | - OPT_IDIV | OPT_SHADING | - OPT_SHIFT | OPT_EXTIO | OPT_BLOCKLESS | - OPT_BASEONE | - OPT_STRIPSPACES | - OPT_NEXTOFILE | - OPT_ARGSTOMAIN; + OPT_BASEONE; ase_awk_setoption (awk, opt); runCallback = false; diff --git a/ase/awk/Awk.hpp b/ase/awk/Awk.hpp index a51f3403..ab4e6365 100644 --- a/ase/awk/Awk.hpp +++ b/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.61 2007/09/25 15:27:54 bacon Exp $ + * $Id: Awk.hpp,v 1.62 2007/09/27 11:04:10 bacon Exp $ * * {License} */ @@ -533,7 +533,9 @@ public: */ OPT_ARGSTOMAIN = ASE_AWK_ARGSTOMAIN, /** Enables the keyword 'reset' */ - OPT_RESET = ASE_AWK_RESET + OPT_RESET = ASE_AWK_RESET, + /** Allows the assignment of a map value to a variable */ + OPT_MAPTOVAR = ASE_AWK_MAPTOVAR }; // end of enum Option diff --git a/ase/awk/Awk.java b/ase/awk/Awk.java index aaeab00b..3732fbf0 100644 --- a/ase/awk/Awk.java +++ b/ase/awk/Awk.java @@ -1,5 +1,5 @@ /* - * $Id: Awk.java,v 1.14 2007/09/23 16:48:55 bacon Exp $ + * $Id: Awk.java,v 1.15 2007/09/27 11:04:10 bacon Exp $ * * {License} */ @@ -38,6 +38,8 @@ public abstract class Awk public static final int OPTION_NEXTOFILE = (1 << 12); public static final int OPTION_CRLF = (1 << 13); public static final int OPTION_ARGSTOMAIN = (1 << 14); + public static final int OPTION_RESET = (1 << 15); + public static final int OPTION_MAPTOVAR = (1 << 16); protected final static Reader stdin = new BufferedReader (new InputStreamReader (System.in)); diff --git a/ase/awk/awk.h b/ase/awk/awk.h index c5bc1c30..80d1cba4 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.14 2007/09/25 15:27:54 bacon Exp $ + * $Id: awk.h,v 1.16 2007/09/27 11:30:54 bacon Exp $ * * {License} */ @@ -162,7 +162,7 @@ enum ase_awk_option_t /* support getline and print */ ASE_AWK_EXTIO = (1 << 7), - /* support co-process */ + /* support co-process - NOT IMPLEMENTED YET */ ASE_AWK_COPROC = (1 << 8), /* support blockless patterns */ @@ -196,7 +196,10 @@ enum ase_awk_option_t ASE_AWK_ARGSTOMAIN = (1 << 14), /* enable the non-standard keyworkd reset */ - ASE_AWK_RESET = (1 << 15) + ASE_AWK_RESET = (1 << 15), + + /* allows the assignment of a map value to a variable */ + ASE_AWK_MAPTOVAR = (1 << 16) }; /* error code */ diff --git a/ase/awk/run.c b/ase/awk/run.c index 4eb13831..f782577e 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.15 2007/09/25 15:27:54 bacon Exp $ + * $Id: run.c,v 1.16 2007/09/27 11:04:10 bacon Exp $ * * {License} */ @@ -2173,18 +2173,20 @@ static int run_return (ase_awk_run_t* run, ase_awk_nde_return_t* nde) val = eval_expression (run, nde->val); if (val == ASE_NULL) return -1; - #ifdef PROHIBIT_MAP_ASSIGNMENT_TO_VARIABLE - if (val->type == ASE_AWK_VAL_MAP) + if ((run->awk->option & ASE_AWK_MAPTOVAR) == 0) { - /* cannot return a map */ - ase_awk_refupval (run, val); - ase_awk_refdownval (run, val); + if (val->type == ASE_AWK_VAL_MAP) + { + /* cannot return a map */ + ase_awk_refupval (run, val); + ase_awk_refdownval (run, val); - ase_awk_setrunerror (run, - ASE_AWK_EMAPNOTALLOWED, nde->line, ASE_NULL, 0); - return -1; + ase_awk_setrunerror ( + run, ASE_AWK_EMAPNOTALLOWED, + nde->line, ASE_NULL, 0); + return -1; + } } - #endif ase_awk_refdownval (run, STACK_RETVAL(run)); STACK_RETVAL(run) = val; @@ -3089,13 +3091,15 @@ static ase_awk_val_t* do_assignment ( var->type == ASE_AWK_NDE_LOCAL || var->type == ASE_AWK_NDE_ARG) { - #ifdef PROHIBIT_MAP_ASSIGNMENT_TO_VARIABLE - if (val->type == ASE_AWK_VAL_MAP) + if ((run->awk->option & ASE_AWK_MAPTOVAR) == 0) { - errnum = ASE_AWK_ENOTASS; - goto exit_on_error; + if (val->type == ASE_AWK_VAL_MAP) + { + errnum = ASE_AWK_ENOTASS; + goto exit_on_error; + } } - #endif + ret = do_assignment_scalar (run, (ase_awk_nde_var_t*)var, val); } else if (var->type == ASE_AWK_NDE_NAMEDIDX || @@ -3145,9 +3149,9 @@ static ase_awk_val_t* do_assignment_scalar ( var->type == ASE_AWK_NDE_LOCAL || var->type == ASE_AWK_NDE_ARG) && var->idx == ASE_NULL); - #ifdef PROHIBIT_MAP_ASSIGNMENT_TO_VARIABLE - ASE_ASSERT (val->type != ASE_AWK_VAL_MAP); - #endif + ASE_ASSERT ( + (run->awk->option & ASE_AWK_MAPTOVAR) || + val->type != ASE_AWK_VAL_MAP); if (var->type == ASE_AWK_NDE_NAMED) { diff --git a/ase/change.log b/ase/change.log index 99f82fc4..fda28176 100644 --- a/ase/change.log +++ b/ase/change.log @@ -7,9 +7,16 @@ - enhanced ase_awk_getglobalname * added an option - ASE_AWK_RESET (awk/awk.h) - - Awk::OPT_RESET (awk/Awk.hpp) + - Awk::OPT_RESET (awk/Awk.hpp) - Awk::OPTION::RESET (net/Awk.hpp) - - TODO: add it to com&java + - Awk.OPTION_RESET (awk/Awk.java) + - TODO: add it to com +* added an option + - ASE_AWK_MAPTOVAR (awk/awk.h) + - Awk::OPT_MAPTOVAR (awk/Awk.hpp) + - Awk::OPTION::MAPTOVAR (net/Awk.hpp) + - Awk.OPTION_MAPTOVAR (awk/Awk.java) + - TODO: add it to com * enhanced Awk::dispatchFunction to set a more accurate error code (awk/Awk.cpp) diff --git a/ase/net/Awk.hpp b/ase/net/Awk.hpp index f79b4851..2839c9fb 100644 --- a/ase/net/Awk.hpp +++ b/ase/net/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.26 2007/09/25 15:27:54 bacon Exp $ + * $Id: Awk.hpp,v 1.27 2007/09/27 11:04:11 bacon Exp $ * * {License} */ @@ -391,7 +391,8 @@ namespace ASE NEXTOFILE = ASE::Awk::OPT_NEXTOFILE, CRLF = ASE::Awk::OPT_CRLF, ARGSTOMAIN = ASE::Awk::OPT_ARGSTOMAIN, - RESET = ASE::Awk::OPT_RESET + RESET = ASE::Awk::OPT_RESET, + MAPTOVAR = ASE::Awk::OPT_MAPTOVAR }; enum class DEPTH: int diff --git a/ase/test/awk/Awk.cpp b/ase/test/awk/Awk.cpp index 31e9923f..5d72c38e 100644 --- a/ase/test/awk/Awk.cpp +++ b/ase/test/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.35 2007/09/25 15:27:54 bacon Exp $ + * $Id: Awk.cpp,v 1.36 2007/09/27 11:30:20 bacon Exp $ */ #include @@ -544,8 +544,6 @@ static void print_usage (const ase_char_t* argv0) ase_printf (ASE_T(" -w o:n Specify an old and new word pair\n")); ase_printf (ASE_T(" o - an original word\n")); ase_printf (ASE_T(" n - the new word to replace the original\n")); - ase_printf (ASE_T(" -ns Don't strip whitespaces\n")); - ase_printf (ASE_T(" The STRIPSPACES option is truned off\n")); } int awk_main (int argc, ase_char_t* argv[]) @@ -560,6 +558,30 @@ int awk_main (int argc, ase_char_t* argv[]) ase_size_t nsrcins = 0; ase_size_t nsrcouts = 0; + struct + { + const ase_char_t* name; + TestAwk::Option opt; + } otab[] = + { + { ASE_T("implicit"), TestAwk::OPT_IMPLICIT }, + { ASE_T("explicit"), TestAwk::OPT_EXPLICIT }, + { ASE_T("uniquefn"), TestAwk::OPT_UNIQUEFN }, + { ASE_T("shading"), TestAwk::OPT_SHADING }, + { ASE_T("shift"), TestAwk::OPT_SHIFT }, + { ASE_T("idiv"), TestAwk::OPT_IDIV }, + { ASE_T("strconcat"), TestAwk::OPT_STRCONCAT }, + { ASE_T("extio"), TestAwk::OPT_EXTIO }, + { ASE_T("blockless"), TestAwk::OPT_BLOCKLESS }, + { ASE_T("baseone"), TestAwk::OPT_BASEONE }, + { ASE_T("stripspaces"), TestAwk::OPT_STRIPSPACES }, + { ASE_T("nextofile"), TestAwk::OPT_NEXTOFILE }, + { ASE_T("crfl"), TestAwk::OPT_CRLF }, + { ASE_T("argstomain"), TestAwk::OPT_ARGSTOMAIN }, + { ASE_T("reset"), TestAwk::OPT_RESET }, + { ASE_T("maptovar"), TestAwk::OPT_MAPTOVAR } + }; + if (awk.open() == -1) { ase_fprintf (stderr, ASE_T("cannot open awk\n")); @@ -577,30 +599,41 @@ int awk_main (int argc, ase_char_t* argv[]) else if (ase_strcmp(argv[i], ASE_T("-a")) == 0) mode = 5; else if (ase_strcmp(argv[i], ASE_T("-m")) == 0) mode = 6; else if (ase_strcmp(argv[i], ASE_T("-w")) == 0) mode = 7; - else if (ase_strcmp(argv[i], ASE_T("-nostripspaces")) == 0) - { - awk.setOption (awk.getOption () & ~TestAwk::OPT_STRIPSPACES); - } - else if (ase_strcmp(argv[i], ASE_T("-noimplicit")) == 0) - { - awk.setOption (awk.getOption () & ~TestAwk::OPT_IMPLICIT); - } - else if (ase_strcmp(argv[i], ASE_T("-noexplicit")) == 0) - { - awk.setOption (awk.getOption () & ~TestAwk::OPT_EXPLICIT); - } - else if (ase_strcmp(argv[i], ASE_T("-noshading")) == 0) - { - awk.setOption (awk.getOption () & ~TestAwk::OPT_SHADING); - } - else if (ase_strcmp(argv[i], ASE_T("-reset")) == 0) - { - awk.setOption (awk.getOption () | TestAwk::OPT_RESET); - } else { + if (argv[i][0] == ASE_T('-')) + { + int j; + + if (argv[i][1] == ASE_T('n') && argv[i][2] == ASE_T('o')) + { + for (j = 0; j < ASE_COUNTOF(otab); j++) + { + if (ase_strcmp(&argv[i][3], otab[j].name) == 0) + { + awk.setOption (awk.getOption() & ~otab[j].opt); + goto ok_valid; + } + } + } + else + { + for (j = 0; j < ASE_COUNTOF(otab); j++) + { + if (ase_strcmp(&argv[i][1], otab[j].name) == 0) + { + awk.setOption (awk.getOption() | otab[j].opt); + goto ok_valid; + } + } + } + } + print_usage (argv[0]); return -1; + + ok_valid: + ; } } else diff --git a/ase/test/awk/asm.awk b/ase/test/awk/asm.awk index e306ec29..e0bc6345 100644 --- a/ase/test/awk/asm.awk +++ b/ase/test/awk/asm.awk @@ -1,8 +1,8 @@ # +# $Id: asm.awk,v 1.4 2007/09/27 11:33:45 bacon Exp $ +# # Taken from the book "The AWK Programming Language" -# aseawk++ -si asm.awk -nostripspaces -a asm.s -# -# ASEAWK should turn on STRIPSPACES & BASEONE to run this program. +# aseawk++ -si asm.awk -a asm.s -nostripspaces -baseone # BEGIN { diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index d14bad8f..d4c2fc3b 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.15 2007/09/23 16:48:55 bacon Exp $ + * $Id: awk.c,v 1.16 2007/09/27 11:30:20 bacon Exp $ */ #include @@ -900,17 +900,21 @@ static int awk_main (int argc, ase_char_t* argv[]) int deparse = 0; opt = ASE_AWK_IMPLICIT | - ASE_AWK_EXPLICIT | + /*ASE_AWK_EXPLICIT |*/ ASE_AWK_UNIQUEFN | - ASE_AWK_IDIV | ASE_AWK_SHADING | - ASE_AWK_SHIFT | + /*ASE_AWK_SHIFT |*/ + /*ASE_AWK_IDIV |*/ + /*ASE_AWK_STRCONCAT |*/ ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | - ASE_AWK_BASEONE | - ASE_AWK_STRIPSPACES | - ASE_AWK_NEXTOFILE /*| - ASE_AWK_ARGSTOMAIN*/; + ASE_AWK_BASEONE /*|*/ + /*ASE_AWK_STRIPSPACES |*/ + /*ASE_AWK_NEXTOFILE |*/ + /*ASE_AWK_CRLF |*/ + /*ASE_AWK_ARGSTOMAIN |*/ + /*ASE_AWK_RESET*/ + /*ASE_AWK_MAPTOVAR*/; if (argc <= 1) { diff --git a/ase/test/awk/err-003.awk b/ase/test/awk/err-003.awk index b86a5e5b..954b1c4d 100644 --- a/ase/test/awk/err-003.awk +++ b/ase/test/awk/err-003.awk @@ -1,5 +1,3 @@ -global abc; - BEGIN { abc[20] = "abc"; abc = 10; diff --git a/ase/test/awk/err-003.out b/ase/test/awk/err-003.out index 2a17eb76..46f72e51 100644 --- a/ase/test/awk/err-003.out +++ b/ase/test/awk/err-003.out @@ -5,4 +5,4 @@ BEGIN { abc = 10; } -RUN ERROR: CODE [95] LINE [5] map 'abc' not assignable with a scalar +RUN ERROR: CODE [96] LINE [5] map 'abc' not assignable with a scalar diff --git a/ase/test/awk/err-004.out b/ase/test/awk/err-004.out index 320f8a3a..7ca2e470 100644 --- a/ase/test/awk/err-004.out +++ b/ase/test/awk/err-004.out @@ -2,4 +2,4 @@ BEGIN { delete ARGC; } -RUN ERROR: CODE [87] LINE [2] variable 'ARGC' not deletable +RUN ERROR: CODE [88] LINE [2] variable 'ARGC' not deletable diff --git a/ase/test/awk/err-005.out b/ase/test/awk/err-005.out index 5c75e4f6..1f97254c 100644 --- a/ase/test/awk/err-005.out +++ b/ase/test/awk/err-005.out @@ -3,4 +3,4 @@ BEGIN { delete iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix; } -RUN ERROR: CODE [87] LINE [3] variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...' not deletable +RUN ERROR: CODE [88] LINE [3] variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...' not deletable diff --git a/ase/test/awk/err-006.out b/ase/test/awk/err-006.out index 77e79728..42a898d9 100644 --- a/ase/test/awk/err-006.out +++ b/ase/test/awk/err-006.out @@ -2,4 +2,4 @@ BEGIN { helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhelphelp (); } -RUN ERROR: CODE [85] LINE [2] function 'helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhel...' not found +RUN ERROR: CODE [86] LINE [2] function 'helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhel...' not found diff --git a/ase/test/awk/err-020.out b/ase/test/awk/err-020.out index 230dfc22..1d6b6567 100644 --- a/ase/test/awk/err-020.out +++ b/ase/test/awk/err-020.out @@ -2,4 +2,4 @@ BEGIN { print abc > "123\0abc"; } -RUN ERROR: CODE [110] LINE [2] i/o name containing a null character +RUN ERROR: CODE [112] LINE [2] i/o name containing a null character diff --git a/ase/test/awk/err-021.out b/ase/test/awk/err-021.out index a3c85504..ef98d7bb 100644 --- a/ase/test/awk/err-021.out +++ b/ase/test/awk/err-021.out @@ -3,4 +3,4 @@ BEGIN { split ("a b c",xx); } -RUN ERROR: CODE [96] LINE [3] cannot change a scalar value to a map +RUN ERROR: CODE [97] LINE [3] cannot change a scalar value to a map