Recovered from cvs revision 2007-07-18 11:12:00
This commit is contained in:
parent
af7146069a
commit
5c7341a6d3
193
ase/net/Awk.cpp
193
ase/net/Awk.cpp
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.cpp,v 1.5 2007/07/16 11:16:46 bacon Exp $
|
* $Id: Awk.cpp,v 1.6 2007/07/17 09:46:19 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <msclr/auto_gcroot.h>
|
#include <msclr/auto_gcroot.h>
|
||||||
|
|
||||||
|
using System::Runtime::InteropServices::GCHandle;
|
||||||
|
|
||||||
namespace ASE
|
namespace ASE
|
||||||
{
|
{
|
||||||
class StubAwk: public Awk
|
class StubAwk: public Awk
|
||||||
@ -45,19 +47,10 @@ namespace ASE
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//interior_ptr<System::IO::Stream> p = wrapper->SourceInputStream;
|
|
||||||
//io.setHandle (wrapper->SourceInputStream);
|
|
||||||
|
|
||||||
System::IO::StreamReader^ reader = gcnew System::IO::StreamReader (wrapper->SourceInputStream);
|
System::IO::StreamReader^ reader = gcnew System::IO::StreamReader (wrapper->SourceInputStream);
|
||||||
System::Runtime::InteropServices::GCHandle* handle = (System::Runtime::InteropServices::GCHandle*)malloc (sizeof(System::Runtime::InteropServices::GCHandle));
|
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::Alloc (reader);
|
||||||
if (handle == NULL)
|
System::IntPtr^ ip = System::Runtime::InteropServices::GCHandle::ToIntPtr(gh);
|
||||||
{
|
io.setHandle (ip->ToPointer());
|
||||||
reader->Close ();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
handle->Alloc (reader/*, System::Runtime::InteropServices::GCHandleType::Pinned */);
|
|
||||||
io.setHandle (handle);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -73,15 +66,9 @@ namespace ASE
|
|||||||
}
|
}
|
||||||
|
|
||||||
System::IO::StreamWriter^ writer = gcnew System::IO::StreamWriter (wrapper->SourceOutputStream);
|
System::IO::StreamWriter^ writer = gcnew System::IO::StreamWriter (wrapper->SourceOutputStream);
|
||||||
System::Runtime::InteropServices::GCHandle* handle = (System::Runtime::InteropServices::GCHandle*)::malloc (sizeof(System::Runtime::InteropServices::GCHandle));
|
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::Alloc (writer);
|
||||||
if (handle == NULL)
|
System::IntPtr^ ip = System::Runtime::InteropServices::GCHandle::ToIntPtr(gh);
|
||||||
{
|
io.setHandle (ip->ToPointer());
|
||||||
writer->Close ();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
handle->Alloc (writer/*, System::Runtime::InteropServices::GCHandleType::Pinned*/);
|
|
||||||
io.setHandle (handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -89,57 +76,129 @@ namespace ASE
|
|||||||
|
|
||||||
int closeSource (Source& io)
|
int closeSource (Source& io)
|
||||||
{
|
{
|
||||||
System::Runtime::InteropServices::GCHandle* handle = (System::Runtime::InteropServices::GCHandle*)io.getHandle();
|
System::IntPtr ip ((void*)io.getHandle());
|
||||||
|
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::FromIntPtr (ip);
|
||||||
|
|
||||||
if (io.getMode() == Source::READ)
|
if (io.getMode() == Source::READ)
|
||||||
{
|
{
|
||||||
System::IO::StreamReader^ reader = (System::IO::StreamReader^)handle->Target;
|
System::IO::StreamReader^ reader = (System::IO::StreamReader^)gh.Target;
|
||||||
reader->Close ();
|
reader->Close ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System::IO::StreamWriter^ writer = (System::IO::StreamWriter^)handle->Target;
|
System::IO::StreamWriter^ writer = (System::IO::StreamWriter^)gh.Target;
|
||||||
writer->Close ();
|
writer->Close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
handle->Free ();
|
gh.Free ();
|
||||||
::free (handle);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t readSource (Source& io, char_t* buf, size_t len)
|
ssize_t readSource (Source& io, char_t* buf, size_t len)
|
||||||
{
|
{
|
||||||
System::Runtime::InteropServices::GCHandle* handle = (System::Runtime::InteropServices::GCHandle*)io.getHandle();
|
System::IntPtr ip ((void*)io.getHandle());
|
||||||
System::IO::StreamReader^ reader = (System::IO::StreamReader^)handle->Target;
|
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::FromIntPtr (ip);
|
||||||
|
|
||||||
|
System::IO::StreamReader^ reader = (System::IO::StreamReader^)gh.Target;
|
||||||
|
|
||||||
cli::array<char_t>^ b = gcnew cli::array<char_t>(len);
|
cli::array<char_t>^ b = gcnew cli::array<char_t>(len);
|
||||||
int n = reader->Read (b, 0, len);
|
int n = reader->Read (b, 0, len);
|
||||||
for (int i = 0; i < n; i++) buf[i] = b[i];
|
for (int i = 0; i < n; i++) buf[i] = b[i];
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t writeSource (Source& io, char_t* buf, size_t len)
|
ssize_t writeSource (Source& io, char_t* buf, size_t len)
|
||||||
{
|
{
|
||||||
System::Runtime::InteropServices::GCHandle* handle = (System::Runtime::InteropServices::GCHandle*)io.getHandle();
|
System::IntPtr ip ((void*)io.getHandle());
|
||||||
System::IO::StreamWriter^ writer = (System::IO::StreamWriter^)handle->Target;
|
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::FromIntPtr (ip);
|
||||||
|
|
||||||
|
System::IO::StreamWriter^ writer = (System::IO::StreamWriter^)gh.Target;
|
||||||
|
|
||||||
cli::array<char_t>^ b = gcnew cli::array<char_t>(len);
|
cli::array<char_t>^ b = gcnew cli::array<char_t>(len);
|
||||||
for (int i = 0; i < (int)len; i++) buf[i] = b[i];
|
for (int i = 0; i < (int)len; i++) b[i] = buf[i];
|
||||||
writer->Write (b, 0, len);
|
writer->Write (b, 0, len);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int openPipe (Pipe& io) {return 0; }
|
int openPipe (Pipe& io)
|
||||||
int closePipe (Pipe& io) {return 0; }
|
{
|
||||||
ssize_t readPipe (Pipe& io, char_t* buf, size_t len) {return 0; }
|
ASE::Net::Awk::Pipe^ nio = gcnew ASE::Net::Awk::Pipe ();
|
||||||
ssize_t writePipe (Pipe& io, char_t* buf, size_t len) {return 0; }
|
nio->Mode = (ASE::Net::Awk::Pipe::MODE)io.getMode();
|
||||||
int flushPipe (Pipe& io) {return 0; }
|
|
||||||
|
|
||||||
int openFile (File& io) {return 0; }
|
GCHandle gh = GCHandle::Alloc (nio);
|
||||||
int closeFile (File& io) {return 0; }
|
io.setHandle (GCHandle::ToIntPtr(gh).ToPointer());
|
||||||
ssize_t readFile (File& io, char_t* buf, size_t len) {return 0; }
|
|
||||||
ssize_t writeFile (File& io, char_t* buf, size_t len) {return 0; }
|
return wrapper->FireOpenPipe (nio);
|
||||||
int flushFile (File& io) {return 0; }
|
}
|
||||||
|
|
||||||
|
int closePipe (Pipe& io)
|
||||||
|
{
|
||||||
|
IntPtr ip ((void*)io.getHandle ());
|
||||||
|
GCHandle gh = GCHandle::FromIntPtr (ip);
|
||||||
|
int n = wrapper->FireClosePipe ((ASE::Net::Awk::Pipe^)gh.Target);
|
||||||
|
gh.Free ();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t readPipe (Pipe& io, char_t* buf, size_t len)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t writePipe (Pipe& io, char_t* buf, size_t len)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int flushPipe (Pipe& io)
|
||||||
|
{
|
||||||
|
IntPtr ip ((void*)io.getHandle());
|
||||||
|
GCHandle gh = GCHandle::FromIntPtr (ip);
|
||||||
|
return wrapper->FireFlushPipe ((ASE::Net::Awk::Pipe^)gh.Target);
|
||||||
|
}
|
||||||
|
|
||||||
|
int openFile (File& io)
|
||||||
|
{
|
||||||
|
ASE::Net::Awk::File^ nio = gcnew ASE::Net::Awk::File ();
|
||||||
|
nio->Mode = (ASE::Net::Awk::File::MODE)io.getMode();
|
||||||
|
|
||||||
|
GCHandle gh = GCHandle::Alloc (nio);
|
||||||
|
io.setHandle (GCHandle::ToIntPtr(gh).ToPointer());
|
||||||
|
|
||||||
|
return wrapper->FireOpenFile (nio);
|
||||||
|
}
|
||||||
|
|
||||||
|
int closeFile (File& io)
|
||||||
|
{
|
||||||
|
IntPtr ip ((void*)io.getHandle ());
|
||||||
|
GCHandle gh = GCHandle::FromIntPtr (ip);
|
||||||
|
int n = wrapper->FireCloseFile ((ASE::Net::Awk::File^)gh.Target);
|
||||||
|
gh.Free ();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t readFile (File& io, char_t* buf, size_t len)
|
||||||
|
{
|
||||||
|
IntPtr ip ((void*)io.getHandle());
|
||||||
|
GCHandle gh = GCHandle::FromIntPtr (ip);
|
||||||
|
return wrapper->FireReadFile ((ASE::Net::Awk::File^)gh.Target);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t writeFile (File& io, char_t* buf, size_t len)
|
||||||
|
{
|
||||||
|
IntPtr ip ((void*)io.getHandle());
|
||||||
|
GCHandle gh = GCHandle::FromIntPtr (ip);
|
||||||
|
return wrapper->FireWriteFile ((ASE::Net::Awk::File^)gh.Target);
|
||||||
|
}
|
||||||
|
|
||||||
|
int flushFile (File& io)
|
||||||
|
{
|
||||||
|
IntPtr ip ((void*)io.getHandle());
|
||||||
|
GCHandle gh = GCHandle::FromIntPtr (ip);
|
||||||
|
return wrapper->FireFlushFile ((ASE::Net::Awk::File^)gh.Target);
|
||||||
|
}
|
||||||
|
|
||||||
int openConsole (Console& io) {return 0; }
|
int openConsole (Console& io) {return 0; }
|
||||||
int closeConsole (Console& io) {return 0; }
|
int closeConsole (Console& io) {return 0; }
|
||||||
@ -183,12 +242,11 @@ namespace ASE
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
msclr::auto_gcroot<Net::Awk^> wrapper;
|
msclr::auto_gcroot<ASE::Net::Awk^> wrapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Net
|
namespace Net
|
||||||
{
|
{
|
||||||
|
|
||||||
Awk::Awk ()
|
Awk::Awk ()
|
||||||
{
|
{
|
||||||
awk = new ASE::StubAwk (this);
|
awk = new ASE::StubAwk (this);
|
||||||
@ -239,6 +297,53 @@ namespace ASE
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Awk::FireOpenFile (File^ file)
|
||||||
|
{
|
||||||
|
return OpenFileHandler (file);
|
||||||
|
}
|
||||||
|
int Awk::FireCloseFile (File^ file)
|
||||||
|
{
|
||||||
|
return CloseFileHandler (file);
|
||||||
|
}
|
||||||
|
int Awk::FireReadFile (File^ file)
|
||||||
|
{
|
||||||
|
int n = ReadFileHandler (file);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
int Awk::FireWriteFile (File^ file)
|
||||||
|
{
|
||||||
|
int n = WriteFileHandler (file);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
int Awk::FireFlushFile (File^ file)
|
||||||
|
{
|
||||||
|
return FlushFileHandler (file);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Awk::FireOpenPipe (Pipe^ pipe)
|
||||||
|
{
|
||||||
|
return OpenPipeHandler (pipe);
|
||||||
|
}
|
||||||
|
int Awk::FireClosePipe (Pipe^ pipe)
|
||||||
|
{
|
||||||
|
return ClosePipeHandler (pipe);
|
||||||
|
}
|
||||||
|
int Awk::FireReadPipe (Pipe^ pipe)
|
||||||
|
{
|
||||||
|
int n = ReadPipeHandler (pipe);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
int Awk::FireWritePipe (Pipe^ pipe)
|
||||||
|
{
|
||||||
|
int n = WritePipeHandler (pipe);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
int Awk::FireFlushPipe (Pipe^ pipe)
|
||||||
|
{
|
||||||
|
return FlushPipeHandler (pipe);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.hpp,v 1.3 2007/07/16 11:12:12 bacon Exp $
|
* $Id: Awk.hpp,v 1.4 2007/07/17 09:46:19 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -38,7 +38,19 @@ namespace ASE
|
|||||||
|
|
||||||
ref class Extio
|
ref class Extio
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
Extio (): handle (nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
property Object^ Handle
|
||||||
|
{
|
||||||
|
Object^ get () { return this->handle; }
|
||||||
|
void set (Object^ handle) { this->handle = handle; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Object^ handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
ref class Pipe: public Extio
|
ref class Pipe: public Extio
|
||||||
@ -102,7 +114,7 @@ namespace ASE
|
|||||||
Awk ();
|
Awk ();
|
||||||
virtual ~Awk ();
|
virtual ~Awk ();
|
||||||
|
|
||||||
bool Open ();
|
//bool Open ();
|
||||||
void Close ();
|
void Close ();
|
||||||
|
|
||||||
bool Parse ();
|
bool Parse ();
|
||||||
@ -113,7 +125,6 @@ namespace ASE
|
|||||||
bool AddFunction (System::String^ name, int minArgs, int maxArgs, FunctionHandler^ handler);
|
bool AddFunction (System::String^ name, int minArgs, int maxArgs, FunctionHandler^ handler);
|
||||||
bool DeleteFunction (System::String^ name);
|
bool DeleteFunction (System::String^ name);
|
||||||
|
|
||||||
|
|
||||||
property System::IO::Stream^ SourceInputStream
|
property System::IO::Stream^ SourceInputStream
|
||||||
{
|
{
|
||||||
System::IO::Stream^ get ()
|
System::IO::Stream^ get ()
|
||||||
@ -140,6 +151,30 @@ namespace ASE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delegate int OpenPipe (Pipe^ pipe);
|
||||||
|
delegate int ClosePipe (Pipe^ pipe);
|
||||||
|
delegate int ReadPipe (Pipe^ pipe);
|
||||||
|
delegate int WritePipe (Pipe^ pipe);
|
||||||
|
delegate int FlushPipe (Pipe^ pipe);
|
||||||
|
|
||||||
|
delegate int OpenFile (File^ file);
|
||||||
|
delegate int CloseFile (File^ file);
|
||||||
|
delegate int ReadFile (File^ file);
|
||||||
|
delegate int WriteFile (File^ file);
|
||||||
|
delegate int FlushFile (File^ file);
|
||||||
|
|
||||||
|
event OpenPipe^ OpenPipeHandler;
|
||||||
|
event ClosePipe^ ClosePipeHandler;
|
||||||
|
event ReadPipe^ ReadPipeHandler;
|
||||||
|
event WritePipe^ WritePipeHandler;
|
||||||
|
event FlushPipe^ FlushPipeHandler;
|
||||||
|
|
||||||
|
event OpenFile^ OpenFileHandler;
|
||||||
|
event CloseFile^ CloseFileHandler;
|
||||||
|
event ReadFile^ ReadFileHandler;
|
||||||
|
event WriteFile^ WriteFileHandler;
|
||||||
|
event FlushFile^ FlushFileHandler;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ASE::Awk* awk;
|
ASE::Awk* awk;
|
||||||
|
|
||||||
@ -147,7 +182,19 @@ namespace ASE
|
|||||||
System::IO::Stream^ sourceOutputStream;
|
System::IO::Stream^ sourceOutputStream;
|
||||||
|
|
||||||
public protected:
|
public protected:
|
||||||
int Awk::DispatchFunction (System::String^ name);
|
int DispatchFunction (System::String^ name);
|
||||||
|
|
||||||
|
int FireOpenFile (File^ file);
|
||||||
|
int FireCloseFile (File^ file);
|
||||||
|
int FireReadFile (File^ file);
|
||||||
|
int FireWriteFile (File^ file);
|
||||||
|
int FireFlushFile (File^ file);
|
||||||
|
|
||||||
|
int FireOpenPipe (Pipe^ pipe);
|
||||||
|
int FireClosePipe (Pipe^ pipe);
|
||||||
|
int FireReadPipe (Pipe^ pipe);
|
||||||
|
int FireWritePipe (Pipe^ pipe);
|
||||||
|
int FireFlushPipe (Pipe^ pipe);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -172,14 +172,6 @@
|
|||||||
RelativePath="System.dll"
|
RelativePath="System.dll"
|
||||||
AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
|
AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
|
||||||
/>
|
/>
|
||||||
<AssemblyReference
|
|
||||||
RelativePath="System.Data.dll"
|
|
||||||
AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86"
|
|
||||||
/>
|
|
||||||
<AssemblyReference
|
|
||||||
RelativePath="System.XML.dll"
|
|
||||||
AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
|
|
||||||
/>
|
|
||||||
</References>
|
</References>
|
||||||
<Files>
|
<Files>
|
||||||
<Filter
|
<Filter
|
||||||
|
@ -19,11 +19,29 @@ namespace asetestnet
|
|||||||
{
|
{
|
||||||
ASE.Net.Awk awk = new ASE.Net.StdAwk();
|
ASE.Net.Awk awk = new ASE.Net.StdAwk();
|
||||||
|
|
||||||
awk.Open();
|
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);
|
awk.SourceInputStream = new System.IO.FileStream("t.awk", System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
||||||
awk.SourceOutputStream = new System.IO.FileStream("t.out", System.IO.FileMode.Create, System.IO.FileAccess.Write);
|
awk.SourceOutputStream = new System.IO.FileStream("t.out", System.IO.FileMode.Create, System.IO.FileAccess.Write);
|
||||||
|
|
||||||
awk.Parse();
|
awk.Parse();
|
||||||
|
awk.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int OpenFile(ASE.Net.Awk.File file)
|
||||||
|
{
|
||||||
|
MessageBox.Show("OpenFile");
|
||||||
|
file.Handle = "abc";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int CloseFile(ASE.Net.Awk.File file)
|
||||||
|
{
|
||||||
|
MessageBox.Show("CloseFile" + (string)file.Handle);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user