diff --git a/ase/net/Awk.cpp b/ase/net/Awk.cpp index 50da9e04..2492bdf8 100644 --- a/ase/net/Awk.cpp +++ b/ase/net/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.7 2007/07/18 11:12:34 bacon Exp $ + * $Id: Awk.cpp,v 1.8 2007/07/19 14:35:10 bacon Exp $ */ #include "stdafx.h" @@ -124,8 +124,9 @@ namespace ASE int openPipe (Pipe& io) { - ASE::Net::Awk::Pipe^ nio = gcnew ASE::Net::Awk::Pipe (); - nio->Mode = (ASE::Net::Awk::Pipe::MODE)io.getMode(); + ASE::Net::Awk::Pipe^ nio = gcnew ASE::Net::Awk::Pipe ( + gcnew System::String (io.getName ()), + (ASE::Net::Awk::Pipe::MODE)io.getMode()); GCHandle gh = GCHandle::Alloc (nio); io.setHandle (GCHandle::ToIntPtr(gh).ToPointer()); @@ -171,8 +172,9 @@ namespace ASE int openFile (File& io) { - ASE::Net::Awk::File^ nio = gcnew ASE::Net::Awk::File (); - nio->Mode = (ASE::Net::Awk::File::MODE)io.getMode(); + ASE::Net::Awk::File^ nio = gcnew ASE::Net::Awk::File ( + gcnew System::String (io.getName ()), + (ASE::Net::Awk::File::MODE)io.getMode()); GCHandle gh = GCHandle::Alloc (nio); io.setHandle (GCHandle::ToIntPtr(gh).ToPointer()); @@ -218,8 +220,9 @@ namespace ASE int openConsole (Console& io) { - ASE::Net::Awk::Console^ nio = gcnew ASE::Net::Awk::Console (); - nio->Mode = (ASE::Net::Awk::Console::MODE)io.getMode(); + ASE::Net::Awk::Console^ nio = gcnew ASE::Net::Awk::Console ( + gcnew System::String (io.getName ()), + (ASE::Net::Awk::Console::MODE)io.getMode()); GCHandle gh = GCHandle::Alloc (nio); io.setHandle (GCHandle::ToIntPtr(gh).ToPointer()); diff --git a/ase/net/Awk.hpp b/ase/net/Awk.hpp index b24b2c20..dc663543 100644 --- a/ase/net/Awk.hpp +++ b/ase/net/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.5 2007/07/18 11:12:34 bacon Exp $ + * $Id: Awk.hpp,v 1.6 2007/07/19 14:35:10 bacon Exp $ */ #pragma once @@ -39,8 +39,9 @@ namespace ASE ref class Extio { public: - Extio (): handle (nullptr) + Extio (System::String^ name): handle (nullptr) { + this->name = name; } property Object^ Handle @@ -49,8 +50,14 @@ namespace ASE void set (Object^ handle) { this->handle = handle; } } + property System::String^ Name + { + System::String^ get () { return this->name; } + }; + private: Object^ handle; + System::String^ name; }; ref class Pipe: public Extio @@ -65,9 +72,13 @@ namespace ASE property MODE^ Mode { MODE^ get () { return this->mode; } - void set (MODE^ mode) { this->mode = mode; } }; + Pipe (System::String^ name, MODE^ mode): Extio (name) + { + this->mode = mode; + } + private: MODE^ mode; }; @@ -85,9 +96,13 @@ namespace ASE property MODE^ Mode { MODE^ get () { return this->mode; } - void set (MODE^ mode) { this->mode = mode; } }; + File (System::String^ name, MODE^ mode): Extio (name) + { + this->mode = mode; + } + private: MODE^ mode; }; @@ -104,9 +119,13 @@ namespace ASE property MODE^ Mode { MODE^ get () { return this->mode; } - void set (MODE^ mode) { this->mode = mode; } }; + Console (System::String^ name, MODE^ mode): Extio (name) + { + this->mode = mode; + } + private: MODE^ mode; }; diff --git a/ase/net/StdAwk.cpp b/ase/net/StdAwk.cpp index 9c4d5a54..4d52c0c7 100644 --- a/ase/net/StdAwk.cpp +++ b/ase/net/StdAwk.cpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.cpp,v 1.1 2007/07/15 16:31:59 bacon Exp $ + * $Id: StdAwk.cpp,v 1.2 2007/07/19 14:35:10 bacon Exp $ */ #include "stdafx.h" @@ -11,5 +11,106 @@ namespace ASE namespace Net { + StdAwk::StdAwk () + { + OpenFileHandler += gcnew OpenFile (this, &StdAwk::openFile); + CloseFileHandler += gcnew CloseFile (this, &StdAwk::closeFile); + ReadFileHandler += gcnew ReadFile (this, &StdAwk::readFile); + WriteFileHandler += gcnew WriteFile (this, &StdAwk::writeFile); + FlushFileHandler += gcnew FlushFile (this, &StdAwk::flushFile); + } + + StdAwk::~StdAwk () + { + } + + int StdAwk::openFile (File^ file) + { + System::IO::FileMode mode; + System::IO::FileAccess access; + System::IO::FileStream^ fs; + + try + { + if (file->Mode->Equals(File::MODE::READ)) + { + mode = System::IO::FileMode::Open; + access = System::IO::FileAccess::Read; + + fs = gcnew System::IO::FileStream (file->Name, mode, access); + System::IO::StreamReader^ rd = gcnew System::IO::StreamReader (fs); + file->Handle = rd; + } + else if (file->Mode->Equals(File::MODE::WRITE)) + { + mode = System::IO::FileMode::Create; + access = System::IO::FileAccess::Write; + + fs = gcnew System::IO::FileStream (file->Name, mode, access); + System::IO::StreamWriter^ wr = gcnew System::IO::StreamWriter (fs); + file->Handle = wr; + } + else /* File::MODE::APPEND */ + { + mode = System::IO::FileMode::Append; + access = System::IO::FileAccess::Write; + + fs = gcnew System::IO::FileStream (file->Name, mode, access); + System::IO::StreamWriter^ wr = gcnew System::IO::StreamWriter (fs); + file->Handle = wr; + } + + return 1; + } + catch (System::Exception^) + { + return -1; + } + } + + int StdAwk::closeFile (File^ file) + { + if (file->Mode == File::MODE::READ) + { + System::IO::StreamReader^ sr = (System::IO::StreamReader^)file->Handle; + sr->Close (); + } + else + { + System::IO::StreamWriter^ sw = (System::IO::StreamWriter^)file->Handle; + sw->Close (); + } + return 0; + } + + int StdAwk::readFile (File^ file, cli::array^ buf, int len) + { + System::IO::StreamReader^ sr = (System::IO::StreamReader^)file->Handle; + try { return sr->Read (buf, 0, len); } + catch (System::Exception^) { return -1; } + } + + int StdAwk::writeFile (File^ file, cli::array^ buf, int len) + { + System::IO::StreamWriter^ sw = (System::IO::StreamWriter^)file->Handle; + try + { + sw->Write (buf, 0, len); + return len; + } + catch (System::Exception^) { return -1; } + } + + int StdAwk::flushFile (File^ file) + { + System::IO::StreamWriter^ sw = (System::IO::StreamWriter^)file->Handle; + try + { + sw->Flush (); + return 0; + } + catch (System::Exception^) { return -1; } + } + } -} \ No newline at end of file +} diff --git a/ase/net/StdAwk.hpp b/ase/net/StdAwk.hpp index 58a73f35..598188c6 100644 --- a/ase/net/StdAwk.hpp +++ b/ase/net/StdAwk.hpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.hpp,v 1.2 2007/07/16 11:12:12 bacon Exp $ + * $Id: StdAwk.hpp,v 1.3 2007/07/19 14:35:10 bacon Exp $ */ #include @@ -12,7 +12,17 @@ namespace ASE public ref class StdAwk: Awk { public: + StdAwk (); + ~StdAwk (); + + protected: + int openFile (File^ file); + int closeFile (File^ file); + int readFile (File^ file, cli::array^ buf, int len); + int writeFile (File^ file, cli::array^ buf, int len); + int flushFile (File^ file); + }; } -} \ No newline at end of file +} diff --git a/ase/test/net/Form1.cs b/ase/test/net/Form1.cs index 8076ba9e..a9ad4ba7 100644 --- a/ase/test/net/Form1.cs +++ b/ase/test/net/Form1.cs @@ -19,8 +19,8 @@ namespace asetestnet { ASE.Net.Awk awk = new ASE.Net.StdAwk(); - awk.OpenFileHandler += new ASE.Net.Awk.OpenFile (OpenFile); - awk.CloseFileHandler += CloseFile; + /*awk.OpenFileHandler += new ASE.Net.Awk.OpenFile (OpenFile); + awk.CloseFileHandler += CloseFile;*/ //awk.Open(); awk.SourceInputStream = new System.IO.FileStream("t.awk", System.IO.FileMode.Open, System.IO.FileAccess.Read); @@ -30,6 +30,7 @@ namespace asetestnet awk.Run(); } + /* private int OpenFile(ASE.Net.Awk.File file) { MessageBox.Show("OpenFile"); @@ -41,7 +42,7 @@ namespace asetestnet { MessageBox.Show("CloseFile" + (string)file.Handle); return 0; - } + }*/ } } \ No newline at end of file