Recovered from cvs revision 2007-07-30 11:48:00
This commit is contained in:
parent
2f04ca531b
commit
b2047feb46
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp,v 1.9 2007/07/20 09:23:37 bacon Exp $
|
||||
* $Id: Awk.cpp,v 1.10 2007/07/29 14:42:33 bacon Exp $
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
@ -32,6 +32,7 @@ namespace ASE
|
||||
return wrapper->DispatchFunction (nm);
|
||||
}
|
||||
|
||||
#if 0
|
||||
int openSource (Source& io)
|
||||
{
|
||||
if (io.getMode() == Source::READ)
|
||||
@ -121,6 +122,75 @@ namespace ASE
|
||||
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
int openSource (Source& io)
|
||||
{
|
||||
ASE::Net::Awk::Source^ nio = gcnew ASE::Net::Awk::Source (
|
||||
(ASE::Net::Awk::Source::MODE)io.getMode());
|
||||
|
||||
GCHandle gh = GCHandle::Alloc (nio);
|
||||
io.setHandle (GCHandle::ToIntPtr(gh).ToPointer());
|
||||
|
||||
try { return wrapper->OpenSource (nio); }
|
||||
catch (...)
|
||||
{
|
||||
gh.Free ();
|
||||
io.setHandle (NULL);
|
||||
return -1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int closeSource (Source& io)
|
||||
{
|
||||
IntPtr ip ((void*)io.getHandle ());
|
||||
GCHandle gh = GCHandle::FromIntPtr (ip);
|
||||
|
||||
try
|
||||
{
|
||||
return wrapper->CloseSource (
|
||||
(ASE::Net::Awk::Source^)gh.Target);
|
||||
}
|
||||
catch (...) { return -1; }
|
||||
finally { gh.Free (); }
|
||||
}
|
||||
|
||||
ssize_t readSource (Source& io, char_t* buf, size_t len)
|
||||
{
|
||||
IntPtr ip ((void*)io.getHandle());
|
||||
GCHandle gh = GCHandle::FromIntPtr (ip);
|
||||
|
||||
cli::array<char_t>^ b = nullptr;
|
||||
|
||||
try
|
||||
{
|
||||
b = gcnew cli::array<char_t> (len);
|
||||
int n = wrapper->ReadSource (
|
||||
(ASE::Net::Awk::Source^)gh.Target, b, len);
|
||||
for (int i = 0; i < n; i++) buf[i] = b[i];
|
||||
return n;
|
||||
}
|
||||
catch (...) { return -1; }
|
||||
finally { if (b != nullptr) delete b; }
|
||||
}
|
||||
|
||||
ssize_t writeSource (Source& io, char_t* buf, size_t len)
|
||||
{
|
||||
IntPtr ip ((void*)io.getHandle());
|
||||
GCHandle gh = GCHandle::FromIntPtr (ip);
|
||||
|
||||
cli::array<char_t>^ b = nullptr;
|
||||
try
|
||||
{
|
||||
b = gcnew cli::array<char_t> (len);
|
||||
for (int i = 0; i < len; i++) b[i] = buf[i];
|
||||
return wrapper->WriteSource (
|
||||
(ASE::Net::Awk::Source^)gh.Target, b, len);
|
||||
}
|
||||
catch (...) { return -1; }
|
||||
finally { if (b != nullptr) delete b; }
|
||||
}
|
||||
|
||||
int openPipe (Pipe& io)
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp,v 1.7 2007/07/20 09:23:37 bacon Exp $
|
||||
* $Id: Awk.hpp,v 1.8 2007/07/29 14:42:33 bacon Exp $
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@ -16,7 +16,6 @@ namespace ASE
|
||||
public ref class Awk abstract
|
||||
{
|
||||
public:
|
||||
/*
|
||||
ref class Source
|
||||
{
|
||||
public:
|
||||
@ -26,15 +25,26 @@ namespace ASE
|
||||
WRITE = ASE::Awk::Source::WRITE
|
||||
};
|
||||
|
||||
Source (MODE^ mode): handle (nullptr)
|
||||
{
|
||||
this->mode = mode;
|
||||
}
|
||||
|
||||
property Object^ Handle
|
||||
{
|
||||
Object^ get () { return this->handle; }
|
||||
void set (Object^ handle) { this->handle = handle; }
|
||||
}
|
||||
|
||||
property MODE^ Mode
|
||||
{
|
||||
MODE^ get () { return this->mode; }
|
||||
void set (MODE^ mode) { this->mode = mode; }
|
||||
};
|
||||
|
||||
private:
|
||||
MODE^ mode;
|
||||
};*/
|
||||
Object^ handle;
|
||||
};
|
||||
|
||||
ref class Extio
|
||||
{
|
||||
@ -146,6 +156,7 @@ namespace ASE
|
||||
bool AddFunction (System::String^ name, int minArgs, int maxArgs, FunctionHandler^ handler);
|
||||
bool DeleteFunction (System::String^ name);
|
||||
|
||||
#if 0
|
||||
property System::IO::Stream^ SourceInputStream
|
||||
{
|
||||
System::IO::Stream^ get ()
|
||||
@ -171,14 +182,25 @@ namespace ASE
|
||||
this->sourceOutputStream = stream;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
ASE::Awk* awk;
|
||||
|
||||
#if 0
|
||||
System::IO::Stream^ sourceInputStream;
|
||||
System::IO::Stream^ sourceOutputStream;
|
||||
#endif
|
||||
|
||||
public protected:
|
||||
// Source
|
||||
virtual int OpenSource (Source^ source) = 0;
|
||||
virtual int CloseSource (Source^ source) = 0;
|
||||
virtual int ReadSource (
|
||||
Source^ source, cli::array<char_t>^ buf, int len) = 0;
|
||||
virtual int WriteSource (
|
||||
Source^ source, cli::array<char_t>^ buf, int len) = 0;
|
||||
|
||||
// File
|
||||
virtual int OpenFile (File^ file) = 0;
|
||||
virtual int CloseFile (File^ file) = 0;
|
||||
@ -188,7 +210,6 @@ namespace ASE
|
||||
File^ file, cli::array<char_t>^ buf, int len) = 0;
|
||||
virtual int FlushFile (File^ file) = 0;
|
||||
|
||||
|
||||
// Pipe
|
||||
virtual int OpenPipe (Pipe^ pipe) = 0;
|
||||
virtual int ClosePipe (Pipe^ pipe) = 0;
|
||||
@ -198,7 +219,6 @@ namespace ASE
|
||||
Pipe^ pipe, cli::array<char_t>^ buf, int len) = 0;
|
||||
virtual int FlushPipe (Pipe^ pipe) = 0;
|
||||
|
||||
|
||||
// Console
|
||||
virtual int OpenConsole (Console^ console) = 0;
|
||||
virtual int CloseConsole (Console^ console) = 0;
|
||||
|
@ -14,6 +14,66 @@ namespace asetestnet
|
||||
|
||||
public class Awk : ASE.Net.StdAwk
|
||||
{
|
||||
|
||||
protected override int OpenSource(ASE.Net.StdAwk.Source source)
|
||||
{
|
||||
System.IO.FileMode mode;
|
||||
System.IO.FileAccess access;
|
||||
System.IO.FileStream fs;
|
||||
|
||||
if (source.Mode.Equals(ASE.Net.StdAwk.Source.MODE.READ))
|
||||
{
|
||||
mode = System.IO.FileMode.Open;
|
||||
access = System.IO.FileAccess.Read;
|
||||
|
||||
fs = new System.IO.FileStream ("t.awk", mode, access);
|
||||
source.Handle = new System.IO.StreamReader (fs);
|
||||
return 1;
|
||||
}
|
||||
else if (source.Mode.Equals(ASE.Net.StdAwk.Source.MODE.WRITE))
|
||||
{
|
||||
mode = System.IO.FileMode.Create;
|
||||
access = System.IO.FileAccess.Write;
|
||||
|
||||
fs = new System.IO.FileStream("t.out", mode, access);
|
||||
source.Handle = new System.IO.StreamWriter(fs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected override int CloseSource(ASE.Net.StdAwk.Source source)
|
||||
{
|
||||
if (source.Mode.Equals(ASE.Net.StdAwk.Source.MODE.READ))
|
||||
{
|
||||
System.IO.StreamReader sr = (System.IO.StreamReader)source.Handle;
|
||||
sr.Close ();
|
||||
return 0;
|
||||
}
|
||||
else if (source.Mode.Equals(ASE.Net.StdAwk.Source.MODE.WRITE))
|
||||
{
|
||||
System.IO.StreamWriter sw = (System.IO.StreamWriter)source.Handle;
|
||||
sw.Close ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected override int ReadSource(ASE.Net.StdAwk.Source source, char[] buf, int len)
|
||||
{
|
||||
System.IO.StreamReader sr = (System.IO.StreamReader)source.Handle;
|
||||
return sr.Read (buf, 0, len);
|
||||
}
|
||||
|
||||
protected override int WriteSource(ASE.Net.StdAwk.Source source, char[] buf, int len)
|
||||
{
|
||||
System.IO.StreamWriter sw = (System.IO.StreamWriter)source.Handle;
|
||||
sw.Write(buf, 0, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
protected override int OpenConsole(ASE.Net.StdAwk.Console console)
|
||||
{
|
||||
return -1;
|
||||
@ -58,8 +118,8 @@ namespace asetestnet
|
||||
awk.CloseFileHandler += CloseFile;*/
|
||||
|
||||
//awk.Open();
|
||||
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.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.Parse();
|
||||
awk.Run();
|
||||
|
Loading…
Reference in New Issue
Block a user