diff --git a/ase/ase.sln b/ase/ase.sln index c05f9db7..7281c666 100644 --- a/ase/ase.sln +++ b/ase/ase.sln @@ -12,20 +12,20 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aseawk", "awk\aseawk.vcproj EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aseawk_jni", "awk\aseawk_jni.vcproj", "{23B58791-FD44-4F95-9F77-34E4AF45A296}" ProjectSection(ProjectDependencies) = postProject - {5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83} {17621C83-40C9-4305-BAF9-132E250B5FE3} = {17621C83-40C9-4305-BAF9-132E250B5FE3} + {5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asecom", "com\asecom.vcproj", "{963AF7B5-12E6-42B6-8CBE-89136C1A109B}" ProjectSection(ProjectDependencies) = postProject - {5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83} {C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD} = {C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD} + {5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asetestawk", "test\awk\asetestawk.vcproj", "{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}" ProjectSection(ProjectDependencies) = postProject - {5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83} {C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD} = {C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD} + {5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aselsp", "lsp\aselsp.vcproj", "{42FE7CED-34B7-45C8-92C9-8856E16640D2}" @@ -35,8 +35,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aselsp", "lsp\aselsp.vcproj EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asetestlsp", "test\lsp\asetestlsp.vcproj", "{868702B0-CB6B-4F1D-B98A-32193347EFAF}" ProjectSection(ProjectDependencies) = postProject - {42FE7CED-34B7-45C8-92C9-8856E16640D2} = {42FE7CED-34B7-45C8-92C9-8856E16640D2} {C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD} = {C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD} + {42FE7CED-34B7-45C8-92C9-8856E16640D2} = {42FE7CED-34B7-45C8-92C9-8856E16640D2} EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "asetestcnt", "test\cnt\asetestcnt.csproj", "{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}" @@ -53,6 +53,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aseawk++", "awk\aseawk++.vc {5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asetestawk++", "test\awk\asetestawk++.vcproj", "{3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}" + ProjectSection(ProjectDependencies) = postProject + {E7A8B741-4E9D-4ED4-9F77-E7F637A678A5} = {E7A8B741-4E9D-4ED4-9F77-E7F637A678A5} + {57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F} = {57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -183,6 +189,16 @@ Global {E7A8B741-4E9D-4ED4-9F77-E7F637A678A5}.Release|Mixed Platforms.Build.0 = Release|Win32 {E7A8B741-4E9D-4ED4-9F77-E7F637A678A5}.Release|Win32.ActiveCfg = Release|Win32 {E7A8B741-4E9D-4ED4-9F77-E7F637A678A5}.Release|Win32.Build.0 = Release|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Debug|Win32.ActiveCfg = Debug|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Debug|Win32.Build.0 = Debug|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Release|Any CPU.ActiveCfg = Release|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Release|Mixed Platforms.Build.0 = Release|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Release|Win32.ActiveCfg = Release|Win32 + {3BEA6CFE-C158-4BFB-B5FB-ED85251E3F98}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ase/awk/Awk.cpp b/ase/awk/Awk.cpp index 982b47bc..9d385068 100644 --- a/ase/awk/Awk.cpp +++ b/ase/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.17 2007/05/10 16:08:37 bacon Exp $ + * $Id: Awk.cpp,v 1.21 2007/05/11 16:40:20 bacon Exp $ */ #include @@ -75,13 +75,13 @@ namespace ASE return this->mode; } - Awk::Value::Value (): run (ASE_NULL), val (ASE_NULL) + Awk::Argument::Argument (): run (ASE_NULL), val (ASE_NULL) { this->str.ptr = ASE_NULL; this->str.len = 0; } - Awk::Value::~Value () + Awk::Argument::~Argument () { if (this->str.ptr != ASE_NULL) { @@ -95,140 +95,185 @@ namespace ASE if (this->val != ASE_NULL) { ASE_ASSERT (this->run != ASE_NULL); - ase_awk_refdownval ( - ase_awk_getrunawk(this->run), this->val); + ase_awk_refdownval (this->run, this->val); } } - void Awk::Value::init (ase_awk_run_t* run, ase_awk_val_t* val) + int Awk::Argument::init (ase_awk_run_t* run, ase_awk_val_t* v) { /* this method is used internally. * and should never be called more than once */ - ASE_ASSERT (this->run == ASE_NULL && this->val == ASE_NULL && - run != ASE_NULL && val != ASE_NULL); + ASE_ASSERT (this->run == ASE_NULL && this->val == ASE_NULL); + ASE_ASSERT (run != ASE_NULL && v != ASE_NULL); + ase_awk_refupval (run, v); this->run = run; - this->val = val; + this->val = v; - ase_awk_refupval (this->run, this->val); - } - - bool Awk::Value::isNil () const - { - return val == ASE_NULL || val->type == ASE_AWK_VAL_NIL; - } - - bool Awk::Value::isInt () const - { - return val != ASE_NULL && val->type == ASE_AWK_VAL_INT; - } - - bool Awk::Value::isReal () const - { - return val != ASE_NULL && val->type == ASE_AWK_VAL_REAL; - } - - bool Awk::Value::isStr () const - { - return val != ASE_NULL && val->type == ASE_AWK_VAL_STR; - } - - Awk::long_t Awk::Value::toInt () const - { - if (this->val == ASE_NULL) return 0; - - long_t l; - real_t r; - - n = ase_awk_valtonum (this->run, this->val, &l, &r); - if (n == 0) return 1; - if (n == 1) return (long_t)r; - - return 0; /* return 0 on error */ - } - - Awk::real_t Awk::Value::toReal () const - { - if (this->val == ASE_NULL) return 0; - - long_t l; - real_t r; - - n = ase_awk_valtonum (this->run, this->val, &l, &r); - if (n == 0) return (real_t)1; - if (n == 1) return r; - - return 0.0; /* return 0 on error */ - } - - const Awk::char_t* Awk::Value::toStr (ase_awk_t* awk, size_t* len) const - { - if (this->val == ASE_NULL) + if (v->type == ASE_AWK_VAL_STR) { - tmp = ase_awk_strxdup( - ase_awk_getrunawk(this->run), ASE_T(""), 0); + int n = ase_awk_valtonum ( + run, v, &this->inum, &this->rnum); + if (n == 0) + { + this->rnum = (ase_real_t)this->inum; + return 0; + } + else if (n == 1) + { + this->inum = (ase_long_t)this->rnum; + return 0; + } + } + else if (v->type == ASE_AWK_VAL_INT) + { + this->inum = ((ase_awk_val_int_t*)v)->val; + this->rnum = (ase_real_t)((ase_awk_val_int_t*)v)->val; + + this->str.ptr = ase_awk_valtostr (run, v, 0, ASE_NULL, &this->str.len); + if (this->str.ptr != ASE_NULL) return 0; + } + else if (v->type == ASE_AWK_VAL_REAL) + { + this->inum = (ase_long_t)((ase_awk_val_real_t*)v)->val; + this->rnum = ((ase_awk_val_real_t*)v)->val; + + this->str.ptr = ase_awk_valtostr (run, v, 0, ASE_NULL, &this->str.len); + if (this->str.ptr != ASE_NULL) return 0; + } + else if (v->type == ASE_AWK_VAL_NIL) + { + this->inum = 0; + this->rnum = 0.0; + + this->str.ptr = ase_awk_valtostr (run, v, 0, ASE_NULL, &this->str.len); + if (this->str.ptr != ASE_NULL) return 0; + } + + ase_awk_refdownval (run, v); + this->run = ASE_NULL; + this->val = ASE_NULL; + return -1; + } + + Awk::long_t Awk::Argument::toInt () const + { + ASE_ASSERT (this->run != ASE_NULL && this->val != ASE_NULL); + return this->inum; + } + + Awk::real_t Awk::Argument::toReal () const + { + ASE_ASSERT (this->run != ASE_NULL && this->val != ASE_NULL); + return this->rnum; + } + + const Awk::char_t* Awk::Argument::toStr (size_t* len) const + { + ASE_ASSERT (this->run != ASE_NULL && this->val != ASE_NULL); + + if (this->str.ptr != ASE_NULL) + { + *len = this->str.len; + return this->str.ptr; } else { + ASE_ASSERT (val->type == ASE_AWK_VAL_STR); + *len = ((ase_awk_val_str_t*)this->val)->len; + return ((ase_awk_val_str_t*)this->val)->buf; } } - void Awk::Value::setInt (long_t l) + Awk::Return::Return (ase_awk_run_t* run): run (run), type (ASE_AWK_VAL_NIL) { - if (this->type == ASE_AWK_VAL_INT && - this->num.l == l) return; + } - if (this->str.ptr != ASE_NULL) + Awk::Return::~Return () + { + clear (); + } + + ase_awk_val_t* Awk::Return::toVal () const + { + switch (this->type) { - ASE_ASSERT (this->str.awk != ASE_NULL); - ase_awk_free (this->str.awk, this->str.ptr); - this->str.ptr = ASE_NULL; - this->str.awk = ASE_NULL; + case ASE_AWK_VAL_NIL: + return ase_awk_val_nil; + + case ASE_AWK_VAL_INT: + return ase_awk_makeintval (this->run, this->v.inum); + + case ASE_AWK_VAL_REAL: + return ase_awk_makerealval (this->run, this->v.rnum); + + case ASE_AWK_VAL_STR: + return ase_awk_makestrval ( + this->run, this->v.str.ptr, this->v.str.len); } + return ASE_NULL; + } + + ase_awk_run_t* Awk::Return::getRun () const + { + return this->run; + } + + ase_awk_t* Awk::Return::getAwk () const + { + return ase_awk_getrunawk (this->run); + } + + int Awk::Return::set (long_t v) + { + clear (); + this->type = ASE_AWK_VAL_INT; - this->num.l = l; + this->v.inum = v; + + return 0; } - void Awk::Value::setReal (real_t r) + int Awk::Return::set (real_t v) { - if (this->type == ASE_AWK_VAL_REAL && - this->num.r == r) return; - - if (this->str.ptr != ASE_NULL) - { - ASE_ASSERT (this->str.awk != ASE_NULL); - ase_awk_free (this->str.awk, this->str.ptr); - this->str.ptr = ASE_NULL; - this->str.awk = ASE_NULL; - } + clear (); this->type = ASE_AWK_VAL_REAL; - this->num.r = r; + this->v.rnum = v; + + return 0; } - const Awk::char_t* Awk::Value::setStr ( - ase_awk_t* awk, const char_t* ptr, size_t len) + int Awk::Return::set (char_t* ptr, size_t len) { + ase_awk_t* awk = ase_awk_getrunawk(this->run); char_t* tmp = ase_awk_strxdup (awk, ptr, len); - if (tmp == ASE_NULL) return ASE_NULL; + if (tmp == ASE_NULL) return -1; - if (this->str.ptr != ASE_NULL) + clear (); + + this->type = ASE_AWK_VAL_STR; + this->v.str.ptr = tmp; + this->v.str.len = len; + + return 0; + } + + void Awk::Return::clear () + { + if (this->type == ASE_AWK_VAL_STR) { - ASE_ASSERT (this->str.awk != ASE_NULL); - ase_awk_free (this->str.awk, this->str.ptr); - this->str.ptr = ASE_NULL; - this->str.awk = ASE_NULL; + ASE_ASSERT (this->v.str.ptr != ASE_NULL); + ase_awk_t* awk = ase_awk_getrunawk(this->run); + ase_awk_free (awk, this->v.str.ptr); + this->v.str.ptr = ASE_NULL; + this->v.str.len = 0; } - this->str.awk = awk; - this->str.ptr = tmp; - this->str.len = len; - - return tmp; + this->type = ASE_AWK_VAL_NIL; } - Awk::Awk (): awk (ASE_NULL), functionMap (ASE_NULL), sourceIn (Source::READ), sourceOut (Source::WRITE) { @@ -337,55 +382,61 @@ namespace ASE ase_awk_run_t* run, const char_t* name, size_t len) { ase_awk_pair_t* pair; + ase_awk_t* awk; + + awk = ase_awk_getrunawk (run); pair = ase_awk_map_get (functionMap, name, len); - if (pair == ASE_NULL) return -1; + if (pair == ASE_NULL) + { + // TODO: SET ERROR INFO + return -1; + } FunctionHandler handler; handler = *(FunctionHandler*)ASE_AWK_PAIR_VAL(pair); size_t i, nargs = ase_awk_getnargs(run); - Value* args = new Value [nargs]; + Argument* args = ASE_NULL; + try { args = new Argument [nargs]; } catch (...) {} + if (args == ASE_NULL) + { + // TODO: SET ERROR INFO + return -1; + } for (i = 0; i < nargs; i++) { ase_awk_val_t* v = ase_awk_getarg (run, i); - Value* obj = ASE_NULL; - - switch (v->type) + if (args[i].init (run, v) == -1) { - case ASE_AWK_VAL_INT: - args[i].setInt (((ase_awk_val_int_t*)v)->val); - break; - - case ASE_AWK_VAL_REAL: - args[i].setReal (((ase_awk_val_real_t*)v)->val); - break; - - case ASE_AWK_VAL_STR: - if (args[i].setStr (awk, - ((ase_awk_val_str_t*)v)->buf, - ((ase_awk_val_str_t*)v)->len) == ASE_NULL) - { - // TODO: handle error... - } - break; - - case ASE_AWK_VAL_NIL: - break; + delete[] args; + // TODO: SET ERROR INFO + return -1; } } + - Value ret; - int n = (this->*handler) (nargs, args, &ret); + Return ret (run); + int n = (this->*handler) (&ret, args, nargs); delete[] args; - if (n <= -1) return -1; + if (n <= -1) + { + // TODO: SET ERROR INFO + return -1; + } - // TODO: convert the return value to normal value... + ase_awk_val_t* r = ret.toVal (); + if (r == ASE_NULL) + { + // TODO: SET ERROR INFO + return -1; + } + ase_awk_setretval (run, r); return 0; } diff --git a/ase/awk/Awk.hpp b/ase/awk/Awk.hpp index 97ec141c..b6153788 100644 --- a/ase/awk/Awk.hpp +++ b/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.16 2007/05/10 16:08:37 bacon Exp $ + * $Id: Awk.hpp,v 1.21 2007/05/11 17:21:01 bacon Exp $ */ #ifndef _ASE_AWK_AWK_HPP_ @@ -109,42 +109,76 @@ namespace ASE Mode mode; }; - class Value + class Argument { - public: - Value (); - ~Value (); + protected: + friend class Awk; + + Argument (); + ~Argument (); + + private: + Argument (const Argument&); + Argument& operator= (const Argument&); protected: - void init (ase_awk_run_t* run, ase_awk_val_t* v); + int init (ase_awk_run_t* run, ase_awk_val_t* v); public: - bool isNil () const; - bool isInt () const; - bool isReal () const; - bool isStr () const; - long_t toInt () const; real_t toReal () const; - const char_t* toStr ( - ase_awk_t* awk, size_t* len) const; - - void setInt (long_t l); - void setReal (real_t r); - const char_t* setStr ( - ase_awk_t* awk, const char_t* ptr, size_t len); + const char_t* toStr (size_t* len) const; protected: ase_awk_run_t* run; ase_awk_val_t* val; - mutable struct + ase_long_t inum; + ase_real_t rnum; + + struct { char_t* ptr; size_t len; } str; }; + class Return + { + protected: + friend class Awk; + + Return (ase_awk_run_t* run); + ~Return (); + + ase_awk_val_t* toVal () const; + + public: + ase_awk_run_t* getRun () const; + ase_awk_t* getAwk () const; + + int set (long_t v); + int set (real_t v); + int set (char_t* ptr, size_t len); + void clear (); + + protected: + ase_awk_run_t* run; + int type; + + union + { + ase_long_t inum; + ase_real_t rnum; + + struct + { + char_t* ptr; + size_t len; + } str; + } v; + }; + Awk (); virtual ~Awk (); @@ -156,7 +190,7 @@ namespace ASE const char_t** args = ASE_NULL); typedef int (Awk::*FunctionHandler) ( - size_t nargs, const Value* args, Value* ret); + Return* ret, const Argument* args, size_t nargs); virtual int addFunction ( const char_t* name, size_t minArgs, size_t maxArgs, diff --git a/ase/awk/StdAwk.cpp b/ase/awk/StdAwk.cpp index 06b2f306..e6bbcb1e 100644 --- a/ase/awk/StdAwk.cpp +++ b/ase/awk/StdAwk.cpp @@ -1,14 +1,26 @@ /* - * $Id: StdAwk.cpp,v 1.6 2007/05/09 16:07:44 bacon Exp $ + * $Id: StdAwk.cpp,v 1.11 2007/05/11 17:21:01 bacon Exp $ */ #include +#include +#include +#include + +#ifdef _WIN32 +#include +#else +#include +#endif + namespace ASE { StdAwk::StdAwk () { + seed = ::time(NULL); + ::srand (seed); } int StdAwk::open () @@ -31,26 +43,156 @@ namespace ASE ASE_AWK_ARGSTOMAIN*/; ase_awk_setoption (awk, opt); + addFunction (ASE_T("sin"), 1, 1, (FunctionHandler)&StdAwk::sin); addFunction (ASE_T("cos"), 1, 1, (FunctionHandler)&StdAwk::cos); addFunction (ASE_T("tan"), 1, 1, (FunctionHandler)&StdAwk::tan); + addFunction (ASE_T("atan2"), 2, 2, (FunctionHandler)&StdAwk::atan2); + addFunction (ASE_T("log"), 1, 1, (FunctionHandler)&StdAwk::log); + addFunction (ASE_T("exp"), 1, 1, (FunctionHandler)&StdAwk::exp); + addFunction (ASE_T("sqrt"), 1, 1, (FunctionHandler)&StdAwk::sqrt); + addFunction (ASE_T("int"), 1, 1, (FunctionHandler)&StdAwk::fnint); + addFunction (ASE_T("rand"), 0, 0, (FunctionHandler)&StdAwk::rand); + addFunction (ASE_T("srand"), 1, 1, (FunctionHandler)&StdAwk::srand); + addFunction (ASE_T("systime"), 0, 0, (FunctionHandler)&StdAwk::systime); + addFunction (ASE_T("strftime"), 0, 2, (FunctionHandler)&StdAwk::strftime); + addFunction (ASE_T("strfgmtime"), 0, 2, (FunctionHandler)&StdAwk::strfgmtime); + addFunction (ASE_T("system"), 1, 1, (FunctionHandler)&StdAwk::system); } return n; } - int StdAwk::sin (size_t nargs, const Value* args, Value* ret) + int StdAwk::sin (Return* ret, const Argument* args, size_t nargs) { - return 0; + return ret->set ((real_t)::sin(args[0].toReal())); } - int StdAwk::cos (size_t nargs, const Value* args, Value* ret) + int StdAwk::cos (Return* ret, const Argument* args, size_t nargs) { - return 0; + return ret->set ((real_t)::cos(args[0].toReal())); } - int StdAwk::tan (size_t nargs, const Value* args, Value* ret) + int StdAwk::tan (Return* ret, const Argument* args, size_t nargs) { - return 0; + return ret->set ((real_t)::tan(args[0].toReal())); + } + + int StdAwk::atan2 (Return* ret, const Argument* args, size_t nargs) + { + return ret->set ((real_t)::atan2(args[0].toReal(), args[1].toReal())); + } + + int StdAwk::log (Return* ret, const Argument* args, size_t nargs) + { + return ret->set ((real_t)::log(args[0].toReal())); + } + + int StdAwk::exp (Return* ret, const Argument* args, size_t nargs) + { + return ret->set ((real_t)::exp(args[0].toReal())); + } + + int StdAwk::sqrt (Return* ret, const Argument* args, size_t nargs) + { + return ret->set ((real_t)::sqrt(args[0].toReal())); + } + + int StdAwk::fnint (Return* ret, const Argument* args, size_t nargs) + { + return ret->set (args[0].toInt()); + } + + int StdAwk::rand (Return* ret, const Argument* args, size_t nargs) + { + return ret->set ((long_t)::rand()); + } + + int StdAwk::srand (Return* ret, const Argument* args, size_t nargs) + { + unsigned int prevSeed = seed; + seed = (unsigned int)args[0].toInt(); + ::srand (seed); + return ret->set ((long_t)prevSeed); + } + + int StdAwk::systime (Return* ret, const Argument* args, size_t nargs) + { + return ret->set ((long_t)::time(NULL)); + } + + int StdAwk::strftime (Return* ret, const Argument* args, size_t nargs) + { + const char_t* fmt; + size_t fln; + + fmt = (nargs < 1)? ASE_T("%c"): args[0].toStr(&fln); + time_t t = (nargs < 2)? ::time(NULL): (time_t)args[1].toInt(); + + char_t buf[128]; + struct tm* tm; + #ifdef _WIN32 + tm = localtime (&t); + #else + struct tm tmb; + tm = localtime_r (&t, &tmb); + #endif + + #ifdef ASE_CHAR_IS_MCHAR + size_t len = strftime (buf, ASE_COUNTOF(buf), fmt, tm); + #else + size_t len = wcsftime (buf, ASE_COUNTOF(buf), fmt, tm); + #endif + + return ret->set (buf, len); + } + + int StdAwk::strfgmtime (Return* ret, const Argument* args, size_t nargs) + { + const char_t* fmt; + size_t fln; + + fmt = (nargs < 1)? ASE_T("%c"): args[0].toStr(&fln); + time_t t = (nargs < 2)? ::time(NULL): (time_t)args[1].toInt(); + + char_t buf[128]; + struct tm* tm; + #ifdef _WIN32 + tm = gmtime (&t); + #else + struct tm tmb; + tm = gmtime_r (&t, &tmb); + #endif + + #ifdef ASE_CHAR_IS_MCHAR + size_t len = strftime (buf, ASE_COUNTOF(buf), fmt, tm); + #else + size_t len = wcsftime (buf, ASE_COUNTOF(buf), fmt, tm); + #endif + + return ret->set (buf, len); + } + + int StdAwk::system (Return* ret, const Argument* args, size_t nargs) + { + size_t len; + const char_t* ptr = args[0].toStr(&len); + + #ifdef _WIN32 + return ret->set ((long_t)::_tsystem(ptr)); + #elif defined(ASE_CHAR_IS_MCHAR) + return ret->set ((long_t)::system(ptr)); + #else + char* mbs = (char*)ase_awk_malloc (ret->getAwk(), len*5+1); + if (mbs == ASE_NULL) return -1; + + ::size_t mbl = ::wcstombs (mbs, ptr, len*5); + if (mbl == (::size_t)-1) return -1; + mbs[mbl] = '\0'; + int n = ret->set ((long_t)::system(mbs)); + + ase_awk_free (ret->getAwk(), mbs); + return n; + #endif } } diff --git a/ase/awk/StdAwk.hpp b/ase/awk/StdAwk.hpp index cc421d05..65a25900 100644 --- a/ase/awk/StdAwk.hpp +++ b/ase/awk/StdAwk.hpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.hpp,v 1.5 2007/05/09 16:07:44 bacon Exp $ + * $Id: StdAwk.hpp,v 1.7 2007/05/11 16:25:38 bacon Exp $ */ #ifndef _ASE_AWK_STDAWK_HPP_ @@ -18,9 +18,23 @@ namespace ASE int open (); protected: - int sin (size_t nargs, const Value* args, Value* ret); - int cos (size_t nargs, const Value* args, Value* ret); - int tan (size_t nargs, const Value* args, Value* ret); + int sin (Return* ret, const Argument* args, size_t nargs); + int cos (Return* ret, const Argument* args, size_t nargs); + int tan (Return* ret, const Argument* args, size_t nargs); + int atan2 (Return* ret, const Argument* args, size_t nargs); + int log (Return* ret, const Argument* args, size_t nargs); + int exp (Return* ret, const Argument* args, size_t nargs); + int sqrt (Return* ret, const Argument* args, size_t nargs); + int fnint (Return* ret, const Argument* args, size_t nargs); + int rand (Return* ret, const Argument* args, size_t nargs); + int srand (Return* ret, const Argument* args, size_t nargs); + int systime (Return* ret, const Argument* args, size_t nargs); + int strftime (Return* ret, const Argument* args, size_t nargs); + int strfgmtime (Return* ret, const Argument* args, size_t nargs); + int system (Return* ret, const Argument* args, size_t nargs); + + protected: + unsigned int seed; }; } diff --git a/ase/awk/StdAwk.java b/ase/awk/StdAwk.java index 16d42d48..0ec06408 100644 --- a/ase/awk/StdAwk.java +++ b/ase/awk/StdAwk.java @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.java,v 1.4 2007/05/05 16:32:46 bacon Exp $ + * $Id: StdAwk.java,v 1.5 2007/05/11 16:25:38 bacon Exp $ * * {License} */ @@ -63,7 +63,7 @@ public abstract class StdAwk extends Awk addFunction ("rand", 0, 0); addFunction ("systime", 0, 0); - addFunction ("strftime", 0, Integer.MAX_VALUE); + addFunction ("strftime", 0, 2); addFunction ("system", 1, 1); } diff --git a/ase/awk/aseawk++.vcproj b/ase/awk/aseawk++.vcproj index 28e7831b..55cca9f5 100644 --- a/ase/awk/aseawk++.vcproj +++ b/ase/awk/aseawk++.vcproj @@ -17,7 +17,7 @@ @@ -145,7 +136,6 @@ /> @@ -69,7 +65,6 @@ /> @@ -144,7 +135,6 @@ /> @@ -68,7 +64,6 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ase/test/awk/asetestawk.vcproj b/ase/test/awk/asetestawk.vcproj index 4f53c430..cf3543ac 100644 --- a/ase/test/awk/asetestawk.vcproj +++ b/ase/test/awk/asetestawk.vcproj @@ -50,10 +50,6 @@ StringPooling="true" RuntimeLibrary="0" EnableFunctionLevelLinking="true" - PrecompiledHeaderFile=".\release/asetestawk.pch" - AssemblerListingLocation=".\release/" - ObjectFile=".\release/" - ProgramDataBaseFileName=".\release/" WarningLevel="3" SuppressStartupBanner="true" /> @@ -75,7 +71,6 @@ LinkIncremental="1" SuppressStartupBanner="true" AdditionalLibraryDirectories="..\..\release\lib" - ProgramDatabaseFile=".\../../release/bin/aseawk.pdb" SubSystem="1" TargetMachine="1" /> @@ -141,10 +136,6 @@ MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="1" - PrecompiledHeaderFile=".\debug/asetestawk.pch" - AssemblerListingLocation=".\debug/" - ObjectFile=".\debug/" - ProgramDataBaseFileName=".\debug/" BrowseInformation="1" WarningLevel="3" SuppressStartupBanner="true" @@ -169,7 +160,6 @@ SuppressStartupBanner="true" AdditionalLibraryDirectories="..\..\debug\lib" GenerateDebugInformation="true" - ProgramDatabaseFile=".\../../debug/bin/aseawk.pdb" SubSystem="1" TargetMachine="1" /> diff --git a/ase/test/lsp/asetestlsp.vcproj b/ase/test/lsp/asetestlsp.vcproj index 80985b85..8df42170 100644 --- a/ase/test/lsp/asetestlsp.vcproj +++ b/ase/test/lsp/asetestlsp.vcproj @@ -49,10 +49,6 @@ MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="1" - PrecompiledHeaderFile=".\debug/asetestlsp.pch" - AssemblerListingLocation=".\debug/" - ObjectFile=".\debug/" - ProgramDataBaseFileName=".\debug/" BrowseInformation="1" WarningLevel="3" SuppressStartupBanner="true" @@ -144,10 +140,6 @@ StringPooling="true" RuntimeLibrary="0" EnableFunctionLevelLinking="true" - PrecompiledHeaderFile=".\release/asetestlsp.pch" - AssemblerListingLocation=".\release/" - ObjectFile=".\release/" - ProgramDataBaseFileName=".\release/" WarningLevel="3" SuppressStartupBanner="true" /> diff --git a/ase/utl/aseutl.vcproj b/ase/utl/aseutl.vcproj index 77a44bdc..282cbce9 100644 --- a/ase/utl/aseutl.vcproj +++ b/ase/utl/aseutl.vcproj @@ -49,10 +49,6 @@ RuntimeLibrary="0" EnableFunctionLevelLinking="true" DisableLanguageExtensions="true" - PrecompiledHeaderFile=".\release/aseutl.pch" - AssemblerListingLocation=".\release/" - ObjectFile=".\release/" - ProgramDataBaseFileName=".\release/" WarningLevel="3" SuppressStartupBanner="true" /> @@ -69,7 +65,6 @@ />