From 99bed82ac3bb37e95d00bbccc2fa198f3ffd2aa6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 16 May 2007 01:03:00 +0000 Subject: [PATCH] Recovered from cvs revision 2007-05-15 06:47:00 --- ase/awk/Awk.cpp | 173 ++++++++++++++++++++++++++++++------------- ase/awk/Awk.hpp | 91 +++++++++++++++-------- ase/test/awk/Awk.cpp | 14 +++- 3 files changed, 194 insertions(+), 84 deletions(-) diff --git a/ase/awk/Awk.cpp b/ase/awk/Awk.cpp index 68b229a4..51b6dd82 100644 --- a/ase/awk/Awk.cpp +++ b/ase/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.27 2007/05/13 14:57:43 bacon Exp $ + * $Id: Awk.cpp,v 1.28 2007/05/14 08:40:13 bacon Exp $ */ #include @@ -10,6 +10,10 @@ namespace ASE { + ////////////////////////////////////////////////////////////////// + // Awk::Source + ////////////////////////////////////////////////////////////////// + Awk::Source::Source (Mode mode): mode (mode) { } @@ -29,7 +33,11 @@ namespace ASE this->handle = handle; } - Awk::Extio::Extio (ase_awk_extio_t* extio): extio (extio) + ////////////////////////////////////////////////////////////////// + // Awk::Extio + ////////////////////////////////////////////////////////////////// + + Awk::Extio::Extio (extio_t* extio): extio (extio) { } @@ -48,25 +56,47 @@ namespace ASE extio->handle = handle; } - ase_awk_run_t* Awk::Extio::getRun () const + Awk::run_t* Awk::Extio::getRun () const { return extio->run; } - ase_awk_t* Awk::Extio::getAwk () const + Awk::awk_t* Awk::Extio::getAwk () const { return ase_awk_getrunawk(extio->run); } - Awk::Pipe::Pipe (ase_awk_extio_t* extio): Extio(extio) + ////////////////////////////////////////////////////////////////// + // Awk::Pipe + ////////////////////////////////////////////////////////////////// + + Awk::Pipe::Pipe (extio_t* extio): Extio(extio) { } - Awk::File::File (ase_awk_extio_t* extio): Extio(extio) + Awk::Pipe::Mode Awk::Pipe::getMode () const + { + return (Mode)extio->mode; + } + + ////////////////////////////////////////////////////////////////// + // Awk::File + ////////////////////////////////////////////////////////////////// + + Awk::File::File (extio_t* extio): Extio(extio) { } + + Awk::File::Mode Awk::File::getMode () const + { + return (Mode)extio->mode; + } + + ////////////////////////////////////////////////////////////////// + // Awk::Console + ////////////////////////////////////////////////////////////////// - Awk::Console::Console (ase_awk_extio_t* extio): Extio(extio), filename(ASE_NULL) + Awk::Console::Console (extio_t* extio): Extio(extio), filename(ASE_NULL) { } @@ -92,21 +122,15 @@ namespace ASE } } - Awk::Pipe::Mode Awk::Pipe::getMode () const - { - return (Mode)extio->mode; - } - - Awk::File::Mode Awk::File::getMode () const - { - return (Mode)extio->mode; - } - Awk::Console::Mode Awk::Console::getMode () const { return (Mode)extio->mode; } + ////////////////////////////////////////////////////////////////// + // Awk::Argument + ////////////////////////////////////////////////////////////////// + Awk::Argument::Argument (): run (ASE_NULL), val (ASE_NULL) { this->str.ptr = ASE_NULL; @@ -131,10 +155,10 @@ namespace ASE } } - int Awk::Argument::init (ase_awk_run_t* run, ase_awk_val_t* v) + int Awk::Argument::init (run_t* run, ase_awk_val_t* v) { - /* this method is used internally only - * and should never be called more than once */ + // this method is used internally only + // and should never be called more than once ASE_ASSERT (this->run == ASE_NULL && this->val == ASE_NULL); ASE_ASSERT (run != ASE_NULL && v != ASE_NULL); @@ -217,19 +241,23 @@ namespace ASE } } - ase_awk_run_t* Awk::Argument::getRun () const + Awk::run_t* Awk::Argument::getRun () const { ASE_ASSERT (this->run != ASE_NULL); return this->run; } - ase_awk_t* Awk::Argument::getAwk () const + Awk::awk_t* Awk::Argument::getAwk () const { ASE_ASSERT (this->run != ASE_NULL); return ase_awk_getrunawk (this->run); } - Awk::Return::Return (ase_awk_run_t* run): run (run), type (ASE_AWK_VAL_NIL) + ////////////////////////////////////////////////////////////////// + // Awk::Return + ////////////////////////////////////////////////////////////////// + + Awk::Return::Return (run_t* run): run (run), type (ASE_AWK_VAL_NIL) { } @@ -259,12 +287,12 @@ namespace ASE return ASE_NULL; } - ase_awk_run_t* Awk::Return::getRun () const + Awk::run_t* Awk::Return::getRun () const { return this->run; } - ase_awk_t* Awk::Return::getAwk () const + Awk::awk_t* Awk::Return::getAwk () const { return ase_awk_getrunawk (this->run); } @@ -291,7 +319,7 @@ namespace ASE int Awk::Return::set (char_t* ptr, size_t len) { - ase_awk_t* awk = ase_awk_getrunawk(this->run); + awk_t* awk = ase_awk_getrunawk(this->run); char_t* tmp = ase_awk_strxdup (awk, ptr, len); if (tmp == ASE_NULL) return -1; @@ -309,7 +337,7 @@ namespace ASE if (this->type == ASE_AWK_VAL_STR) { ASE_ASSERT (this->v.str.ptr != ASE_NULL); - ase_awk_t* awk = ase_awk_getrunawk(this->run); + 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; @@ -318,6 +346,19 @@ namespace ASE this->type = ASE_AWK_VAL_NIL; } + + ////////////////////////////////////////////////////////////////// + // Awk::Run + ////////////////////////////////////////////////////////////////// + + Awk::Run::Run (run_t* run): run (run) + { + } + + ////////////////////////////////////////////////////////////////// + // Awk + ////////////////////////////////////////////////////////////////// + Awk::Awk (): awk (ASE_NULL), functionMap (ASE_NULL), sourceIn (Source::READ), sourceOut (Source::WRITE) { @@ -346,14 +387,21 @@ namespace ASE size_t i; ase_awk_runios_t runios; + ase_awk_runcbs_t runcbs; ase_awk_runarg_t* runarg = ASE_NULL; - runios.pipe = pipeHandler; - runios.coproc = ASE_NULL; - runios.file = fileHandler; - runios.console = consoleHandler; + runios.pipe = pipeHandler; + runios.coproc = ASE_NULL; + runios.file = fileHandler; + runios.console = consoleHandler; runios.custom_data = this; + runcbs.on_start = onRunStart; + runcbs.on_end = onRunEnd; + runcbs.on_return = ASE_NULL; + runcbs.on_statement = ASE_NULL; + runcbs.custom_data = this; + if (nargs > 0) { runarg = (ase_awk_runarg_t*) ase_awk_malloc ( @@ -389,7 +437,7 @@ namespace ASE } int n = ase_awk_run ( - awk, main, &runios, ASE_NULL, runarg, this); + awk, main, &runios, &runcbs, runarg, this); if (runarg != ASE_NULL) { @@ -470,10 +518,10 @@ namespace ASE } int Awk::dispatchFunction ( - ase_awk_run_t* run, const char_t* name, size_t len) + run_t* run, const char_t* name, size_t len) { - ase_awk_pair_t* pair; - ase_awk_t* awk; + pair_t* pair; + awk_t* awk; awk = ase_awk_getrunawk (run); @@ -559,8 +607,7 @@ namespace ASE return -1; } - ase_awk_pair_t* pair; - pair = ase_awk_map_put (functionMap, name, nameLen, tmp); + pair_t* pair = ase_awk_map_put (functionMap, name, nameLen, tmp); if (pair == ASE_NULL) { // TODO: SET ERROR INFO @@ -584,6 +631,14 @@ namespace ASE return n; } + void Awk::onRunStart (const Run& run) + { + } + + void Awk::onRunEnd (const Run& run, int errnum) + { + } + Awk::ssize_t Awk::sourceReader ( int cmd, void* arg, char_t* data, size_t count) { @@ -623,12 +678,12 @@ namespace ASE Awk::ssize_t Awk::pipeHandler ( int cmd, void* arg, char_t* data, size_t count) { - ase_awk_extio_t* epa = (ase_awk_extio_t*)arg; - Awk* awk = (Awk*)epa->custom_data; + extio_t* extio = (extio_t*)arg; + Awk* awk = (Awk*)extio->custom_data; - ASE_ASSERT ((epa->type & 0xFF) == ASE_AWK_EXTIO_PIPE); + ASE_ASSERT ((extio->type & 0xFF) == ASE_AWK_EXTIO_PIPE); - Pipe pipe (epa); + Pipe pipe (extio); switch (cmd) { @@ -644,8 +699,9 @@ namespace ASE case ASE_AWK_IO_FLUSH: return awk->flushPipe (pipe); + case ASE_AWK_IO_NEXT: - return awk->nextPipe (pipe); + return -1; } return -1; @@ -654,12 +710,12 @@ namespace ASE Awk::ssize_t Awk::fileHandler ( int cmd, void* arg, char_t* data, size_t count) { - ase_awk_extio_t* epa = (ase_awk_extio_t*)arg; - Awk* awk = (Awk*)epa->custom_data; + extio_t* extio = (extio_t*)arg; + Awk* awk = (Awk*)extio->custom_data; - ASE_ASSERT ((epa->type & 0xFF) == ASE_AWK_EXTIO_FILE); + ASE_ASSERT ((extio->type & 0xFF) == ASE_AWK_EXTIO_FILE); - File file (epa); + File file (extio); switch (cmd) { @@ -675,8 +731,9 @@ namespace ASE case ASE_AWK_IO_FLUSH: return awk->flushFile (file); + case ASE_AWK_IO_NEXT: - return awk->nextFile (file); + return -1; } return -1; @@ -685,12 +742,12 @@ namespace ASE Awk::ssize_t Awk::consoleHandler ( int cmd, void* arg, char_t* data, size_t count) { - ase_awk_extio_t* epa = (ase_awk_extio_t*)arg; - Awk* awk = (Awk*)epa->custom_data; + extio_t* extio = (extio_t*)arg; + Awk* awk = (Awk*)extio->custom_data; - ASE_ASSERT ((epa->type & 0xFF) == ASE_AWK_EXTIO_CONSOLE); + ASE_ASSERT ((extio->type & 0xFF) == ASE_AWK_EXTIO_CONSOLE); - Console console (epa); + Console console (extio); switch (cmd) { @@ -714,7 +771,7 @@ namespace ASE } int Awk::functionHandler ( - ase_awk_run_t* run, const char_t* name, size_t len) + run_t* run, const char_t* name, size_t len) { Awk* awk = (Awk*) ase_awk_getruncustomdata (run); return awk->dispatchFunction (run, name, len); @@ -726,6 +783,18 @@ namespace ASE ase_awk_free (awk->awk, value); } + void Awk::onRunStart (run_t* run, void* custom) + { + Awk* awk = (Awk*)custom; + awk->onRunStart (Run(run)); + } + + void Awk::onRunEnd (run_t* run, int errnum, void* custom) + { + Awk* awk = (Awk*)custom; + awk->onRunEnd (Run(run), errnum); + } + void* Awk::allocMem (void* custom, size_t n) { return ((Awk*)custom)->allocMem (n); diff --git a/ase/awk/Awk.hpp b/ase/awk/Awk.hpp index 8c66d690..432a0436 100644 --- a/ase/awk/Awk.hpp +++ b/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.25 2007/05/13 14:43:58 bacon Exp $ + * $Id: Awk.hpp,v 1.26 2007/05/14 08:40:13 bacon Exp $ */ #ifndef _ASE_AWK_AWK_HPP_ @@ -23,6 +23,12 @@ namespace ASE typedef ase_long_t long_t; typedef ase_real_t real_t; + typedef ase_awk_map_t map_t; + typedef ase_awk_pair_t pair_t; + typedef ase_awk_extio_t extio_t; + typedef ase_awk_run_t run_t; + typedef ase_awk_t awk_t; + class Source { public: @@ -45,36 +51,44 @@ namespace ASE class Extio { - public: - Extio (ase_awk_extio_t* extio); + protected: + Extio (extio_t* extio); + public: const char_t* getName() const; const void* getHandle () const; void setHandle (void* handle); - ase_awk_run_t* getRun () const; - ase_awk_t* getAwk () const; + run_t* getRun () const; + awk_t* getAwk () const; protected: - ase_awk_extio_t* extio; + extio_t* extio; }; class Pipe: public Extio { public: + friend class Awk; + enum Mode { READ = ASE_AWK_EXTIO_PIPE_READ, WRITE = ASE_AWK_EXTIO_PIPE_WRITE }; - Pipe (ase_awk_extio_t* extio); + protected: + Pipe (extio_t* extio); + + public: Mode getMode () const; }; class File: public Extio { public: + friend class Awk; + enum Mode { READ = ASE_AWK_EXTIO_FILE_READ, @@ -82,26 +96,33 @@ namespace ASE APPEND = ASE_AWK_EXTIO_FILE_APPEND }; - File (ase_awk_extio_t* extio); + protected: + File (extio_t* extio); + + public: Mode getMode () const; }; class Console: public Extio { public: + friend class Awk; + enum Mode { READ = ASE_AWK_EXTIO_CONSOLE_READ, WRITE = ASE_AWK_EXTIO_CONSOLE_WRITE }; - Console (ase_awk_extio_t* extio); + protected: + Console (extio_t* extio); ~Console (); + public: Mode getMode () const; int setFileName (const char_t* name); - private: + protected: char_t* filename; }; @@ -118,18 +139,18 @@ namespace ASE Argument& operator= (const Argument&); protected: - int init (ase_awk_run_t* run, ase_awk_val_t* v); + int init (run_t* run, ase_awk_val_t* v); public: long_t toInt () const; real_t toReal () const; const char_t* toStr (size_t* len) const; - ase_awk_run_t* getRun () const; - ase_awk_t* getAwk () const; + run_t* getRun () const; + awk_t* getAwk () const; protected: - ase_awk_run_t* run; + run_t* run; ase_awk_val_t* val; ase_long_t inum; @@ -147,14 +168,14 @@ namespace ASE protected: friend class Awk; - Return (ase_awk_run_t* run); + Return (run_t* run); ~Return (); ase_awk_val_t* toVal () const; public: - ase_awk_run_t* getRun () const; - ase_awk_t* getAwk () const; + run_t* getRun () const; + awk_t* getAwk () const; int set (long_t v); int set (real_t v); @@ -162,7 +183,7 @@ namespace ASE void clear (); protected: - ase_awk_run_t* run; + run_t* run; int type; union @@ -178,6 +199,16 @@ namespace ASE } v; }; + class Run + { + protected: + friend class Awk; + Run (run_t* run); + + protected: + run_t* run; + }; + Awk (); virtual ~Awk (); @@ -199,7 +230,7 @@ namespace ASE protected: virtual int dispatchFunction ( - ase_awk_run_t* run, const char_t* name, size_t len); + run_t* run, const char_t* name, size_t len); // source code io handlers virtual int openSource (Source& io) = 0; @@ -213,7 +244,6 @@ namespace ASE virtual ssize_t readPipe (Pipe& io, char_t* buf, size_t len) = 0; virtual ssize_t writePipe (Pipe& io, char_t* buf, size_t len) = 0; virtual int flushPipe (Pipe& io) = 0; - virtual int nextPipe (Pipe& io) = 0; // file io handlers virtual int openFile (File& io) = 0; @@ -221,7 +251,6 @@ namespace ASE virtual ssize_t readFile (File& io, char_t* buf, size_t len) = 0; virtual ssize_t writeFile (File& io, char_t* buf, size_t len) = 0; virtual int flushFile (File& io) = 0; - virtual int nextFile (File& io) = 0; // console io handlers virtual int openConsole (Console& io) = 0; @@ -232,11 +261,8 @@ namespace ASE virtual int nextConsole (Console& io) = 0; // run-time callbacks - /* - virtual void onStart () {} - virtual void onReturn () {} - virtual void onStop () {} - */ + virtual void onRunStart (const Run& run); + virtual void onRunEnd (const Run& run, int errnum); // primitive handlers virtual void* allocMem (size_t n) = 0; @@ -276,9 +302,12 @@ namespace ASE int cmd, void* arg, char_t* data, size_t count); static int functionHandler ( - ase_awk_run_t* run, const char_t* name, size_t len); + run_t* run, const char_t* name, size_t len); static void freeFunctionMapValue (void* owner, void* value); + static void onRunStart (run_t* run, void* custom); + static void onRunEnd (run_t* run, int errnum, void* custom); + static void* allocMem (void* custom, size_t n); static void* reallocMem (void* custom, void* ptr, size_t n); static void freeMem (void* custom, void* ptr); @@ -303,11 +332,15 @@ namespace ASE static void dprintf (void* custom, const char_t* fmt, ...); protected: - ase_awk_t* awk; - ase_awk_map_t* functionMap; + awk_t* awk; + map_t* functionMap; Source sourceIn; Source sourceOut; + + private: + Awk (const Awk&); + Awk& operator= (const Awk&); }; } diff --git a/ase/test/awk/Awk.cpp b/ase/test/awk/Awk.cpp index af3f6d27..edcb6fcf 100644 --- a/ase/test/awk/Awk.cpp +++ b/ase/test/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.11 2007/05/13 14:43:58 bacon Exp $ + * $Id: Awk.cpp,v 1.12 2007/05/14 08:40:13 bacon Exp $ */ #include @@ -60,6 +60,16 @@ public: protected: + void onRunStart (const Run& run) + { + wprintf (L"*** awk run started ***\n"); + } + + void onRunEnd (const Run& run, int errnum) + { + wprintf (L"*** awk run ended ***\n"); + } + int openSource (Source& io) { Source::Mode mode = io.getMode(); @@ -225,7 +235,6 @@ protected: } int flushPipe (Pipe& io) { return ::fflush ((FILE*)io.getHandle()); } - int nextPipe (Pipe& io) { return -1; } // file io handlers int openFile (File& io) @@ -294,7 +303,6 @@ protected: } int flushFile (File& io) { return ::fflush ((FILE*)io.getHandle()); } - int nextFile (File& io) { return -1; } // console io handlers int openConsole (Console& io)