diff --git a/ase/awk/Awk.cpp b/ase/awk/Awk.cpp index 186420f9..cfa920b4 100644 --- a/ase/awk/Awk.cpp +++ b/ase/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.36 2007/05/22 16:01:25 bacon Exp $ + * $Id: Awk.cpp,v 1.37 2007/05/23 11:43:24 bacon Exp $ */ #include @@ -364,16 +364,6 @@ namespace ASE { } - void Awk::Run::setMaxBlockDepth (size_t n) - { - ase_awk_setmaxdepth (awk->awk, ASE_AWK_DEPTH_BLOCK_RUN, n); - } - - void Awk::Run::setMaxExpressionDepth (size_t n) - { - ase_awk_setmaxdepth (awk->awk, ASE_AWK_DEPTH_EXPR_RUN, n); - } - int Awk::Run::stop () { ASE_ASSERT (this->run != ASE_NULL); @@ -570,6 +560,18 @@ namespace ASE return ase_awk_getoption (awk); } + void Awk::setDepth (int id, size_t depth) + { + ASE_ASSERT (awk != ASE_NULL); + ase_awk_setmaxdepth (awk, id, depth); + } + + int Awk::getDepth (int id) + { + ASE_ASSERT (awk != ASE_NULL); + return ase_awk_getmaxdepth (awk, id); + } + int Awk::parse () { ASE_ASSERT (awk != ASE_NULL); diff --git a/ase/awk/Awk.hpp b/ase/awk/Awk.hpp index bed69c4d..320fa6c8 100644 --- a/ase/awk/Awk.hpp +++ b/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.34 2007/05/22 16:01:25 bacon Exp $ + * $Id: Awk.hpp,v 1.35 2007/05/23 11:43:24 bacon Exp $ */ #ifndef _ASE_AWK_AWK_HPP_ @@ -369,9 +369,6 @@ namespace ASE size_t getErrorLine () const; const char_t* getErrorMessage () const; - void setMaxBlockDepth (size_t n); - void setMaxExpressionDepth (size_t n); - protected: Awk* awk; run_t* run; @@ -399,6 +396,19 @@ namespace ASE virtual void setOption (int opt); virtual int getOption () const; + enum Depth + { + DEPTH_BLOCK_PARSE = ASE_AWK_DEPTH_BLOCK_PARSE, + DEPTH_BLOCK_RUN = ASE_AWK_DEPTH_BLOCK_RUN, + DEPTH_EXPR_PARSE = ASE_AWK_DEPTH_EXPR_PARSE, + DEPTH_EXPR_RUN = ASE_AWK_DEPTH_EXPR_RUN, + DEPTH_REX_BUILD = ASE_AWK_DEPTH_REX_BUILD, + DEPTH_REX_MATCH = ASE_AWK_DEPTH_REX_MATCH + }; + + virtual void setDepth (int id, size_t depth); + virtual int getDepth (int id); + virtual int parse (); virtual int run (const char_t* main = ASE_NULL, const char_t** args = ASE_NULL, size_t nargs = 0); diff --git a/ase/awk/StdAwk.cpp b/ase/awk/StdAwk.cpp index ce5e4159..ec81d886 100644 --- a/ase/awk/StdAwk.cpp +++ b/ase/awk/StdAwk.cpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.cpp,v 1.19 2007/05/20 16:21:09 bacon Exp $ + * $Id: StdAwk.cpp,v 1.21 2007/05/23 14:15:16 bacon Exp $ */ #include @@ -29,7 +29,11 @@ namespace ASE #define ADD_FUNC(name,min,max,impl) \ do { \ if (addFunction (name, min, max, \ - (FunctionHandler)impl) == -1) return -1; \ + (FunctionHandler)impl) == -1) \ + { \ + Awk::close (); \ + return -1; \ + } \ } while (0) int StdAwk::open () diff --git a/ase/awk/StdAwk.hpp b/ase/awk/StdAwk.hpp index 28e609fb..3cd5231e 100644 --- a/ase/awk/StdAwk.hpp +++ b/ase/awk/StdAwk.hpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.hpp,v 1.9 2007/05/16 14:44:13 bacon Exp $ + * $Id: StdAwk.hpp,v 1.11 2007/05/23 14:15:16 bacon Exp $ */ #ifndef _ASE_AWK_STDAWK_HPP_ @@ -34,7 +34,6 @@ namespace ASE int strfgmtime (Return* ret, const Argument* args, size_t nargs); int system (Return* ret, const Argument* args, size_t nargs); - // pipe io handlers int openPipe (Pipe& io); int closePipe (Pipe& io); diff --git a/ase/test/awk/Awk.cpp b/ase/test/awk/Awk.cpp index b0ccd0e5..1cb407a7 100644 --- a/ase/test/awk/Awk.cpp +++ b/ase/test/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.17 2007/05/19 16:45:27 bacon Exp $ + * $Id: Awk.cpp,v 1.18 2007/05/23 14:15:16 bacon Exp $ */ #include @@ -12,6 +12,8 @@ #if defined(_WIN32) #include +#else +#include #endif class TestAwk: public ASE::StdAwk @@ -34,11 +36,24 @@ public: { #ifdef _WIN32 ASE_ASSERT (heap == ASE_NULL); - heap = HeapCreate (0, 1000000, 1000000); + heap = ::HeapCreate (0, 1000000, 1000000); if (heap == ASE_NULL) return -1; #endif - return StdAwk::open (); + int n = StdAwk::open (); + + if (addFunction (ASE_T("sleep"), 1, 1, + (FunctionHandler)&TestAwk::sleep) == -1) + { + StdAwk::close (); + #ifdef _WIN32 + HeapDestroy (heap); + heap = ASE_NULL; + #endif + return -1; + } + + return n; } void close () @@ -54,6 +69,16 @@ public: #endif } + int sleep (Return* ret, const Argument* args, size_t nargs) + { + #ifdef _WIN32 + ::Sleep (args[0].toInt() * 1000); + #else + ::sleep (args[0].toInt()); + #endif + return 0; + } + int addConsoleInput (const char_t* file) { if (numConInFiles < ASE_COUNTOF(conInFile)) diff --git a/ase/test/awk/cou-027.awk b/ase/test/awk/cou-027.awk index f8464883..a3ec5f31 100644 --- a/ase/test/awk/cou-027.awk +++ b/ase/test/awk/cou-027.awk @@ -1,5 +1,13 @@ BEGIN { FS = "\t"; } { pop[$4] += $3; } -END { for (c in pop) +END { + for (c in pop) printf ("%15s\t%6d\n", c, pop[c]) | "sort -t'\t' +1rn"; - } + + # the following two statements make the program behave + # consistently across different platforms. + # on some platforms, the sort command output has + # been delayed until the program exits. + close ("sort -t'\t' +1rn"); + sleep (1); +}