From 24b4d82eea92569aac79d6dc4114dc5a1c3dedba Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 25 Aug 2007 01:06:00 +0000 Subject: [PATCH] Recovered from cvs revision 2007-08-24 13:17:00 --- ase/awk/generrcode-net.awk | 34 ++++++++ ase/net/Awk.cpp | 152 +++++++++++++++++++++++++++++++++--- ase/net/Awk.hpp | 155 +++++++++++++++++++++++++++++++++++-- ase/test/net/Awk.cs | 5 +- ase/test/net/AwkForm.cs | Bin 5108 -> 5616 bytes 5 files changed, 328 insertions(+), 18 deletions(-) create mode 100644 ase/awk/generrcode-net.awk diff --git a/ase/awk/generrcode-net.awk b/ase/awk/generrcode-net.awk new file mode 100644 index 00000000..c760334e --- /dev/null +++ b/ase/awk/generrcode-net.awk @@ -0,0 +1,34 @@ +# +# generrcode-net.awk +# +# aseawk -f generrcode-net.awk awk.h +# + +BEGIN { + collect=0; + tab3="\t\t"; + tab4="\t\t\t"; +} + +/^[[:space:]]*enum[[:space:]]+ase_awk_errnum_t[[:space:]]*$/ { + collect=1; + print tab3 "// generated by generrcode-net.awk"; + print tab3 "enum class ERROR: int"; + print tab3 "{"; +} + +collect && /^[[:space:]]*};[[:space:]]*$/ { + print tab3 "};"; + print tab3 "// end of enum class ERROR"; + print ""; + collect=0; +} + +collect && /^[[:space:]]*ASE_AWK_E[[:alnum:]]+/ { + split ($1, flds, ","); + name=flds[1]; + + x = substr (name,10,length(name)-9); + print tab4 x " = ASE::Awk::ERR_" x ","; +} + diff --git a/ase/net/Awk.cpp b/ase/net/Awk.cpp index 0f6f8da9..1e04bdab 100644 --- a/ase/net/Awk.cpp +++ b/ase/net/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.18 2007/08/21 14:24:37 bacon Exp $ + * $Id: Awk.cpp,v 1.21 2007/08/22 13:56:21 bacon Exp $ */ #include "stdafx.h" @@ -9,13 +9,12 @@ #include #include #include +#include #include #include -using System::Runtime::InteropServices::GCHandle; - -extern "C" void outputxxx (const wchar_t* x); +using System::Runtime::InteropServices::GCHandle; namespace ASE { @@ -61,6 +60,21 @@ namespace ASE this->wrapper = nullptr; } + const char_t* getErrorMessage (ASE::Net::Awk^ wrapper) const + { + this->wrapper = wrapper; + const char_t* x = Awk::getErrorMessage(); + this->wrapper = nullptr; + return x; + } + + void setError (ASE::Net::Awk^ wrapper) + { + this->wrapper = wrapper; + //Awk::setError (code); + this->wrapper = nullptr; + } + int parse (ASE::Net::Awk^ wrapper) { this->wrapper = wrapper; @@ -135,21 +149,32 @@ namespace ASE { if (wrapper->OnRunStart != nullptr) { - wrapper->OnRunStart (); + wrapper->OnRunStart (wrapper); } } void onRunEnd (const Run& run) { + if (run.getErrorCode() != ERR_NOERR) + { + // TODO: SET THE ERROR CODE TO THIS AWK OBJECT... + // TODO: set the error properly when an error is returned through this callback. + // this callback should always be available.... + ASE::Awk::setError (run.getErrorCode(), run.getErrorLine()); + + // TODO: also make Run to return false in this case. Unlike normal c++ awk, this version of awk doesn't support multiple run instances. + // wrapper->runFailureReported = true; + } + if (wrapper->OnRunEnd != nullptr) { - wrapper->OnRunEnd (); + wrapper->OnRunEnd (wrapper); } } void onRunReturn (const Run& run, const Argument& ret) { if (wrapper->OnRunReturn != nullptr) { - wrapper->OnRunReturn (); + wrapper->OnRunReturn (wrapper); } } @@ -157,7 +182,7 @@ namespace ASE { if (wrapper->OnRunStatement != nullptr) { - wrapper->OnRunStatement (); + wrapper->OnRunStatement (wrapper); } } @@ -561,8 +586,10 @@ namespace ASE } //option = (OPTION)(awk->getOption (this) | MojoAwk::OPT_CRLF); - option = (OPTION)(awk->getOption (this) | ASE::Awk::OPT_CRLF); + option = (OPTION)(awk->getOption (this) | ASE::Awk::OPT_CRLF); awk->setOption (this, (int)option); + + errorMsg = ""; } Awk::~Awk () @@ -595,6 +622,13 @@ System::Diagnostics::Debug::Print ("Awk::!Awk"); } } + System::String^ Awk::ErrorMessage::get () + { + if (awk != NULL) + this->errorMsg = gcnew System::String(awk->getErrorMessage (this)); + return this->errorMsg; + } + Awk::OPTION Awk::Option::get () { if (awk != NULL) this->option = (OPTION)awk->getOption (this); @@ -631,6 +665,11 @@ System::Diagnostics::Debug::Print ("Awk::!Awk"); } bool Awk::Run () + { + return Run (nullptr, nullptr); + } + + bool Awk::Run (System::String^ entryPoint, cli::array^ args) { if (awk == NULL) return false; @@ -640,7 +679,94 @@ System::Diagnostics::Debug::Print ("Awk::!Awk"); awk->enableRunCallback (this); } - return awk->run (this) == 0; + if (args == nullptr || args->Length <= 0) + { + if (entryPoint == nullptr || entryPoint->Length <= 0) + { + return awk->run (this) == 0; + } + else + { + cli::pin_ptr nptr = PtrToStringChars(entryPoint); + return awk->run (this, nptr) == 0; + } + } + else + { + int nargs = args->Length; + ASE::Awk::char_t** ptr = ASE_NULL; + + try + { + bool r = false; + + ptr = (ASE::Awk::char_t**)awk->allocMem (nargs * ASE_SIZEOF(ASE::Awk::char_t*)); + if (ptr == ASE_NULL) + { + // TODO: error handling + return false; + } + for (int i = 0; i < nargs; i++) ptr[i] = ASE_NULL; + for (int i = 0; i < nargs; i++) + { + cli::pin_ptr nptr = PtrToStringChars (args[i]); + ptr[i] = (ASE::Awk::char_t*)awk->allocMem ((args[i]->Length+1)*ASE_SIZEOF(ASE::Awk::char_t)); + if (ptr[i] == ASE_NULL) + { + r = false; + goto exit_run; + } + memcpy (ptr[i], nptr, args[i]->Length*ASE_SIZEOF(ASE::Awk::char_t)); + ptr[i][args[i]->Length] = ASE_T('\0'); + } + + if (entryPoint == nullptr || entryPoint->Length <= 0) + { + r = (awk->run (this, ASE_NULL, (const ASE::Awk::char_t**)ptr, nargs) == 0); + } + else + { + cli::pin_ptr nptr = PtrToStringChars(entryPoint); + r = (awk->run (this, nptr, (const ASE::Awk::char_t**)ptr, nargs) == 0); + } + + exit_run: + if (ptr != ASE_NULL) + { + for (int i = 0; i < nargs; i++) + { + if (ptr[i] != ASE_NULL) + { + awk->freeMem (ptr[i]); + ptr[i] = ASE_NULL; + } + } + awk->freeMem (ptr); + ptr = ASE_NULL; + } + + return r; + } + catch (...) + { + if (ptr != ASE_NULL) + { + for (int i = 0; i < nargs; i++) + { + if (ptr[i] != ASE_NULL) + { + awk->freeMem (ptr[i]); + ptr[i] = ASE_NULL; + } + } + awk->freeMem (ptr); + ptr = ASE_NULL; + } + + // TODO: error... + return false; + } + } } bool Awk::AddFunction ( @@ -715,6 +841,12 @@ System::Diagnostics::Debug::Print ("Awk::!Awk"); return true; } + void Awk::SetError () + { + if (awk == NULL) return; + awk->setError (this); + } + } } diff --git a/ase/net/Awk.hpp b/ase/net/Awk.hpp index 658daaaf..cfa4fb27 100644 --- a/ase/net/Awk.hpp +++ b/ase/net/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.15 2007/08/21 14:24:37 bacon Exp $ + * $Id: Awk.hpp,v 1.18 2007/08/22 13:56:21 bacon Exp $ */ #pragma once @@ -328,6 +328,139 @@ namespace ASE REX_MATCH = ASE::Awk::DEPTH_REX_MATCH }; + // generated by generrcode-net.awk + enum class ERROR: int + { + NOERR = ASE::Awk::ERR_NOERR, + INVAL = ASE::Awk::ERR_INVAL, + NOMEM = ASE::Awk::ERR_NOMEM, + NOSUP = ASE::Awk::ERR_NOSUP, + NOPER = ASE::Awk::ERR_NOPER, + NODEV = ASE::Awk::ERR_NODEV, + NOSPC = ASE::Awk::ERR_NOSPC, + MFILE = ASE::Awk::ERR_MFILE, + MLINK = ASE::Awk::ERR_MLINK, + AGAIN = ASE::Awk::ERR_AGAIN, + NOENT = ASE::Awk::ERR_NOENT, + EXIST = ASE::Awk::ERR_EXIST, + FTBIG = ASE::Awk::ERR_FTBIG, + TBUSY = ASE::Awk::ERR_TBUSY, + ISDIR = ASE::Awk::ERR_ISDIR, + IOERR = ASE::Awk::ERR_IOERR, + OPEN = ASE::Awk::ERR_OPEN, + READ = ASE::Awk::ERR_READ, + WRITE = ASE::Awk::ERR_WRITE, + CLOSE = ASE::Awk::ERR_CLOSE, + INTERN = ASE::Awk::ERR_INTERN, + RUNTIME = ASE::Awk::ERR_RUNTIME, + BLKNST = ASE::Awk::ERR_BLKNST, + EXPRNST = ASE::Awk::ERR_EXPRNST, + SINOP = ASE::Awk::ERR_SINOP, + SINCL = ASE::Awk::ERR_SINCL, + SINRD = ASE::Awk::ERR_SINRD, + SOUTOP = ASE::Awk::ERR_SOUTOP, + SOUTCL = ASE::Awk::ERR_SOUTCL, + SOUTWR = ASE::Awk::ERR_SOUTWR, + LXCHR = ASE::Awk::ERR_LXCHR, + LXDIG = ASE::Awk::ERR_LXDIG, + LXUNG = ASE::Awk::ERR_LXUNG, + ENDSRC = ASE::Awk::ERR_ENDSRC, + ENDCMT = ASE::Awk::ERR_ENDCMT, + ENDSTR = ASE::Awk::ERR_ENDSTR, + ENDREX = ASE::Awk::ERR_ENDREX, + LBRACE = ASE::Awk::ERR_LBRACE, + LPAREN = ASE::Awk::ERR_LPAREN, + RPAREN = ASE::Awk::ERR_RPAREN, + RBRACK = ASE::Awk::ERR_RBRACK, + COMMA = ASE::Awk::ERR_COMMA, + SCOLON = ASE::Awk::ERR_SCOLON, + COLON = ASE::Awk::ERR_COLON, + STMEND = ASE::Awk::ERR_STMEND, + IN = ASE::Awk::ERR_IN, + NOTVAR = ASE::Awk::ERR_NOTVAR, + EXPRES = ASE::Awk::ERR_EXPRES, + WHILE = ASE::Awk::ERR_WHILE, + ASSIGN = ASE::Awk::ERR_ASSIGN, + IDENT = ASE::Awk::ERR_IDENT, + FNNAME = ASE::Awk::ERR_FNNAME, + BLKBEG = ASE::Awk::ERR_BLKBEG, + BLKEND = ASE::Awk::ERR_BLKEND, + DUPBEG = ASE::Awk::ERR_DUPBEG, + DUPEND = ASE::Awk::ERR_DUPEND, + BFNRED = ASE::Awk::ERR_BFNRED, + AFNRED = ASE::Awk::ERR_AFNRED, + GBLRED = ASE::Awk::ERR_GBLRED, + PARRED = ASE::Awk::ERR_PARRED, + DUPPAR = ASE::Awk::ERR_DUPPAR, + DUPGBL = ASE::Awk::ERR_DUPGBL, + DUPLCL = ASE::Awk::ERR_DUPLCL, + BADPAR = ASE::Awk::ERR_BADPAR, + BADVAR = ASE::Awk::ERR_BADVAR, + UNDEF = ASE::Awk::ERR_UNDEF, + LVALUE = ASE::Awk::ERR_LVALUE, + GBLTM = ASE::Awk::ERR_GBLTM, + LCLTM = ASE::Awk::ERR_LCLTM, + PARTM = ASE::Awk::ERR_PARTM, + DELETE = ASE::Awk::ERR_DELETE, + BREAK = ASE::Awk::ERR_BREAK, + CONTINUE = ASE::Awk::ERR_CONTINUE, + NEXTBEG = ASE::Awk::ERR_NEXTBEG, + NEXTEND = ASE::Awk::ERR_NEXTEND, + NEXTFBEG = ASE::Awk::ERR_NEXTFBEG, + NEXTFEND = ASE::Awk::ERR_NEXTFEND, + PRINTFARG = ASE::Awk::ERR_PRINTFARG, + PREPST = ASE::Awk::ERR_PREPST, + GLNCPS = ASE::Awk::ERR_GLNCPS, + DIVBY0 = ASE::Awk::ERR_DIVBY0, + OPERAND = ASE::Awk::ERR_OPERAND, + POSIDX = ASE::Awk::ERR_POSIDX, + ARGTF = ASE::Awk::ERR_ARGTF, + ARGTM = ASE::Awk::ERR_ARGTM, + FNNONE = ASE::Awk::ERR_FNNONE, + NOTIDX = ASE::Awk::ERR_NOTIDX, + NOTDEL = ASE::Awk::ERR_NOTDEL, + NOTMAP = ASE::Awk::ERR_NOTMAP, + NOTMAPIN = ASE::Awk::ERR_NOTMAPIN, + NOTMAPNILIN = ASE::Awk::ERR_NOTMAPNILIN, + NOTREF = ASE::Awk::ERR_NOTREF, + NOTASS = ASE::Awk::ERR_NOTASS, + IDXVALASSMAP = ASE::Awk::ERR_IDXVALASSMAP, + POSVALASSMAP = ASE::Awk::ERR_POSVALASSMAP, + MAPTOSCALAR = ASE::Awk::ERR_MAPTOSCALAR, + SCALARTOMAP = ASE::Awk::ERR_SCALARTOMAP, + MAPNOTALLOWED = ASE::Awk::ERR_MAPNOTALLOWED, + VALTYPE = ASE::Awk::ERR_VALTYPE, + RDELETE = ASE::Awk::ERR_RDELETE, + RNEXTBEG = ASE::Awk::ERR_RNEXTBEG, + RNEXTEND = ASE::Awk::ERR_RNEXTEND, + RNEXTFBEG = ASE::Awk::ERR_RNEXTFBEG, + RNEXTFEND = ASE::Awk::ERR_RNEXTFEND, + BFNUSER = ASE::Awk::ERR_BFNUSER, + BFNIMPL = ASE::Awk::ERR_BFNIMPL, + IOUSER = ASE::Awk::ERR_IOUSER, + IONONE = ASE::Awk::ERR_IONONE, + IOIMPL = ASE::Awk::ERR_IOIMPL, + IONMEM = ASE::Awk::ERR_IONMEM, + IONMNL = ASE::Awk::ERR_IONMNL, + FMTARG = ASE::Awk::ERR_FMTARG, + FMTCNV = ASE::Awk::ERR_FMTCNV, + CONVFMTCHR = ASE::Awk::ERR_CONVFMTCHR, + OFMTCHR = ASE::Awk::ERR_OFMTCHR, + REXRECUR = ASE::Awk::ERR_REXRECUR, + REXRPAREN = ASE::Awk::ERR_REXRPAREN, + REXRBRACKET = ASE::Awk::ERR_REXRBRACKET, + REXRBRACE = ASE::Awk::ERR_REXRBRACE, + REXUNBALPAR = ASE::Awk::ERR_REXUNBALPAR, + REXCOLON = ASE::Awk::ERR_REXCOLON, + REXCRANGE = ASE::Awk::ERR_REXCRANGE, + REXCCLASS = ASE::Awk::ERR_REXCCLASS, + REXBRANGE = ASE::Awk::ERR_REXBRANGE, + REXEND = ASE::Awk::ERR_REXEND, + REXGARBAGE = ASE::Awk::ERR_REXGARBAGE + }; + // end of enum class ERROR + + typedef ASE::Awk::char_t char_t; Awk (); @@ -337,18 +470,19 @@ namespace ASE virtual void Close (); virtual bool Parse (); virtual bool Run (); + virtual bool Run (System::String^ entryPoint, cli::array^ args); - delegate void RunStartHandler (); - delegate void RunEndHandler (); - delegate void RunReturnHandler (); - delegate void RunStatementHandler (); + delegate void RunStartHandler (Awk^ awk); + delegate void RunEndHandler (Awk^ awk); + delegate void RunReturnHandler (Awk^ awk); + delegate void RunStatementHandler (Awk^ awk); /*event*/ RunStartHandler^ OnRunStart; /*event*/ RunEndHandler^ OnRunEnd; /*event*/ RunReturnHandler^ OnRunReturn; /*event*/ RunStatementHandler^ OnRunStatement; - delegate bool FunctionHandler (System::String^ name, array^ args, Return^ ret); + delegate bool FunctionHandler (System::String^ name, cli::array^ args, Return^ ret); virtual bool AddFunction (System::String^ name, int minArgs, int maxArgs, FunctionHandler^ handler); virtual bool DeleteFunction (System::String^ name); @@ -365,10 +499,19 @@ namespace ASE void set (OPTION opt); //{ this->option = opt; } } + // TODO: Error code, Error line + property System::String^ ErrorMessage + { + System::String^ get (); + } + + void SetError (); + protected: MojoAwk* awk; OPTION option; System::Collections::Hashtable^ funcs; + System::String^ errorMsg; public protected: // Source diff --git a/ase/test/net/Awk.cs b/ase/test/net/Awk.cs index fe20257a..ed5928fd 100644 --- a/ase/test/net/Awk.cs +++ b/ase/test/net/Awk.cs @@ -23,11 +23,12 @@ namespace asetestnet public bool Run( System.Windows.Forms.TextBox consoleInput, - System.Windows.Forms.TextBox consoleOutput) + System.Windows.Forms.TextBox consoleOutput, + System.String main, System.String[] args) { this.consoleInput = consoleInput; this.consoleOutput = consoleOutput; - return base.Run(); + return base.Run(main, args); } protected override int OpenSource(ASE.Net.StdAwk.Source source) diff --git a/ase/test/net/AwkForm.cs b/ase/test/net/AwkForm.cs index d5648fd60b80a82324d0377e3bc4294bd28ef20e..bf2169c5188d1c4185fbf3947f9cf128fcefa671 100644 GIT binary patch delta 648 zcma)4OG^S_6utS#9LJf_ObY|WA}z&g*Mky+2qPab^L60f(uM)Wjf!OmPx?83%`eHmZqAqD{M&p>vQmzA z*~S=o*!<*1zcPpytAJk7hCrL7#^X%y!Lzj+vpTyW&DEysG;eXOv45*~zx>fUqWz=6 zaeNwGSQ4a;hE0_-g1<%WK@L=FOH}8QrzFl57dk~BvL?ZhqD^LfcoieKkgUViX;F~k zw8uTBxVJ3x6Ksu{LtJW{J#k9VB1JeV#<5}E#SCv^k#Uq!g#V5sBs&lk#Ze;}o8)S) z(#QJ8yw9%CKa@z|qpH--4}^?)85+r>FVGI{;Km$S#J5s7Ce0HP|cg8d9)e%l^6mT5*dmZiWyQF6c|z`@8p$c_@(Br=pUWHabZHsllKR$#CNnv~3t#83g` zi?fCRO|F=Hkzbe{rb?Pmn-#2TGB2Mer!~+teUN#R{RO3kt