From 754c2970af4ad242499b8c0b689a264171c3e44d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 15 Jul 2008 23:56:32 +0000 Subject: [PATCH] --- ase/cmd/awk/Awk.cpp | 2 +- ase/cmd/awk/awk.c | 7 +++--- ase/include/ase/awk/Awk.hpp | 11 +++++----- ase/include/ase/awk/awk.h | 11 ++++------ ase/lib/awk/Awk.cpp | 4 ++-- ase/lib/awk/parse.c | 43 ++++++++++--------------------------- 6 files changed, 27 insertions(+), 51 deletions(-) diff --git a/ase/cmd/awk/Awk.cpp b/ase/cmd/awk/Awk.cpp index 89ea5226..097fcc07 100644 --- a/ase/cmd/awk/Awk.cpp +++ b/ase/cmd/awk/Awk.cpp @@ -646,7 +646,7 @@ static struct { 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("newline"), TestAwk::OPT_NEWLINE }, { ASE_T("baseone"), TestAwk::OPT_BASEONE }, { ASE_T("stripspaces"), TestAwk::OPT_STRIPSPACES }, { ASE_T("nextofile"), TestAwk::OPT_NEXTOFILE }, diff --git a/ase/cmd/awk/awk.c b/ase/cmd/awk/awk.c index a7815819..8a3892ca 100644 --- a/ase/cmd/awk/awk.c +++ b/ase/cmd/awk/awk.c @@ -869,7 +869,7 @@ static struct { ASE_T("idiv"), ASE_AWK_IDIV }, { ASE_T("strconcat"), ASE_AWK_STRCONCAT }, { ASE_T("extio"), ASE_AWK_EXTIO }, - { ASE_T("blockless"), ASE_AWK_BLOCKLESS }, + { ASE_T("newline"), ASE_AWK_NEWLINE }, { ASE_T("baseone"), ASE_AWK_BASEONE }, { ASE_T("stripspaces"), ASE_AWK_STRIPSPACES }, { ASE_T("nextofile"), ASE_AWK_NEXTOFILE }, @@ -877,8 +877,7 @@ static struct { ASE_T("argstomain"), ASE_AWK_ARGSTOMAIN }, { ASE_T("reset"), ASE_AWK_RESET }, { ASE_T("maptovar"), ASE_AWK_MAPTOVAR }, - { ASE_T("pablock"), ASE_AWK_PABLOCK }, - { ASE_T("newline"), ASE_AWK_NEWLINE } + { ASE_T("pablock"), ASE_AWK_PABLOCK } }; static void print_usage (const ase_char_t* argv0) @@ -1001,7 +1000,7 @@ static int awk_main (int argc, ase_char_t* argv[]) opt = ASE_AWK_IMPLICIT | ASE_AWK_EXTIO | - ASE_AWK_BLOCKLESS | + ASE_AWK_NEWLINE | ASE_AWK_BASEONE | ASE_AWK_PABLOCK; diff --git a/ase/include/ase/awk/Awk.hpp b/ase/include/ase/awk/Awk.hpp index 0278870b..d00a15aa 100644 --- a/ase/include/ase/awk/Awk.hpp +++ b/ase/include/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp 240 2008-07-11 14:41:16Z baconevi $ + * $Id: Awk.hpp 245 2008-07-15 05:56:32Z baconevi $ * * {License} */ @@ -545,7 +545,10 @@ public: OPT_STRCONCAT = ASE_AWK_STRCONCAT, OPT_EXTIO = ASE_AWK_EXTIO, OPT_COPROC = ASE_AWK_COPROC, - OPT_BLOCKLESS = ASE_AWK_BLOCKLESS, + + /** Can terminate a statement with a new line */ + OPT_NEWLINE = ASE_AWK_NEWLINE, + OPT_BASEONE = ASE_AWK_BASEONE, OPT_STRIPSPACES = ASE_AWK_STRIPSPACES, @@ -564,9 +567,7 @@ public: /** Allows the assignment of a map value to a variable */ OPT_MAPTOVAR = ASE_AWK_MAPTOVAR, /** Allows BEGIN, END, pattern-action blocks */ - OPT_PABLOCK = ASE_AWK_PABLOCK, - /** Can terminate a statement with a new line */ - OPT_NEWLINE = ASE_AWK_NEWLINE + OPT_PABLOCK = ASE_AWK_PABLOCK }; // end of enum Option diff --git a/ase/include/ase/awk/awk.h b/ase/include/ase/awk/awk.h index 9edc789d..7c886f25 100644 --- a/ase/include/ase/awk/awk.h +++ b/ase/include/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h 239 2008-07-11 11:07:17Z baconevi $ + * $Id: awk.h 245 2008-07-15 05:56:32Z baconevi $ * * {License} */ @@ -189,8 +189,8 @@ enum ase_awk_option_t /* support co-process - NOT IMPLEMENTED YET */ ASE_AWK_COPROC = (1 << 8), - /* support blockless patterns */ - ASE_AWK_BLOCKLESS = (1 << 9), + /* can terminate a statement with a new line */ + ASE_AWK_NEWLINE = (1 << 9), /* use 1 as the start index for string operations and ARGV */ ASE_AWK_BASEONE = (1 << 10), @@ -226,10 +226,7 @@ enum ase_awk_option_t ASE_AWK_MAPTOVAR = (1 << 16), /* allows BEGIN, END, pattern-action blocks */ - ASE_AWK_PABLOCK = (1 << 17), - - /* can terminate a statement with a new line */ - ASE_AWK_NEWLINE = (1 << 18) + ASE_AWK_PABLOCK = (1 << 17) }; /* error code */ diff --git a/ase/lib/awk/Awk.cpp b/ase/lib/awk/Awk.cpp index 9653e82d..ccdf49bb 100644 --- a/ase/lib/awk/Awk.cpp +++ b/ase/lib/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp 237 2008-07-09 13:20:08Z baconevi $ + * $Id: Awk.cpp 245 2008-07-15 05:56:32Z baconevi $ * * {License} */ @@ -1181,7 +1181,7 @@ int Awk::open () int opt = OPT_IMPLICIT | OPT_EXTIO | - OPT_BLOCKLESS | + OPT_NEWLINE | OPT_BASEONE | OPT_PABLOCK; ase_awk_setoption (awk, opt); diff --git a/ase/lib/awk/parse.c b/ase/lib/awk/parse.c index 78fb5d7d..b39806ea 100644 --- a/ase/lib/awk/parse.c +++ b/ase/lib/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c 243 2008-07-14 13:53:31Z baconevi $ + * $Id: parse.c 245 2008-07-15 05:56:32Z baconevi $ * * {License} */ @@ -324,9 +324,7 @@ static global_t gtab[] = /* 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. */ + /* output record separator. used for 'print' and blockless output */ { ASE_T("ORS"), 3, ASE_AWK_EXTIO }, { ASE_T("RLENGTH"), 7, 0 }, @@ -636,10 +634,9 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk) awk->parse.id.block = PARSE_BEGIN; if (get_token(awk) == -1) return ASE_NULL; - if ((awk->option & ASE_AWK_BLOCKLESS) && - (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF))) + if (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF)) { - /* when the blockless pattern is supported + /* when ASE_AWK_NEWLINE is set, * BEGIN and { should be located on the same line */ SETERRLIN (awk, ASE_AWK_EBLKBEG, awk->token.prev.line); return ASE_NULL; @@ -673,10 +670,9 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk) awk->parse.id.block = PARSE_END; if (get_token(awk) == -1) return ASE_NULL; - if ((awk->option & ASE_AWK_BLOCKLESS) && - (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF))) + if (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF)) { - /* when the blockless pattern is supported + /* when ASE_AWK_NEWLINE is set, * END and { should be located on the same line */ SETERRLIN (awk, ASE_AWK_EBLKEND, awk->token.prev.line); return ASE_NULL; @@ -746,16 +742,14 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk) } } - if ((awk->option & ASE_AWK_BLOCKLESS) && - (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF))) + if (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF)) { /* 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 ( - awk, ptn, ASE_TRUE) == ASE_NULL) + if (parse_pattern_block(awk,ptn,ASE_TRUE) == ASE_NULL) { ase_awk_clrpt (awk, ptn); return ASE_NULL; @@ -763,7 +757,7 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk) if (newline) { - if (get_token (awk) == -1) + if (get_token(awk) == -1) { /* ptn has been added to the chain. * it doesn't have to be cleared here @@ -1108,7 +1102,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk) /* duplicate functions should have been detected previously */ ASE_ASSERT (n != 0); - afn->name = ASE_PAIR_KEYPTR(pair); /* do some trick to save a string. */ + afn->name = ASE_PAIR_KEYPTR(pair); /* do some trick to save a string. */ afn->name_len = ASE_PAIR_KEYLEN(pair); ASE_AWK_FREE (awk, name_dup); @@ -4534,20 +4528,6 @@ static int get_token (ase_awk_t* awk) awk->token.line = awk->src.lex.line; awk->token.column = awk->src.lex.column; - /* TODO; remove this - if (line != 0 && (awk->option & ASE_AWK_BLOCKLESS) && - (awk->parse.id.block == PARSE_PATTERN || - awk->parse.id.block == PARSE_BEGIN || - awk->parse.id.block == PARSE_END)) - { - if (awk->token.line != line) - { - SET_TOKEN_TYPE (awk, TOKEN_NEWLINE); - return 0; - } - } - */ - c = awk->src.lex.curc; if (c == ASE_CHAR_EOF) @@ -4979,7 +4959,6 @@ static int get_token (ase_awk_t* awk) } get_token_ok: - wprintf (L"token = [%S]\n", awk->token.name.buf); return 0; } @@ -5386,7 +5365,7 @@ static int skip_comment (ase_awk_t* awk) } while (c != ASE_T('\n') && c != ASE_CHAR_EOF); - GET_CHAR (awk); + if (!(awk->option & ASE_AWK_NEWLINE)) GET_CHAR (awk); return 1; /* comment by # */ }