Recovered from cvs revision 2007-07-17 09:46:00
This commit is contained in:
parent
0f87fb5842
commit
af7146069a
102
ase/net/Awk.cpp
102
ase/net/Awk.cpp
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp,v 1.3 2007/07/15 16:31:59 bacon Exp $
|
||||
* $Id: Awk.cpp,v 1.5 2007/07/16 11:16:46 bacon Exp $
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
@ -17,6 +17,7 @@ namespace ASE
|
||||
class StubAwk: public Awk
|
||||
{
|
||||
public:
|
||||
|
||||
StubAwk (Net::Awk^ wrapper): wrapper(wrapper)
|
||||
{
|
||||
}
|
||||
@ -31,39 +32,101 @@ namespace ASE
|
||||
|
||||
int openSource (Source& io)
|
||||
{
|
||||
/*
|
||||
Net::Awk::Source^ nio = gcnew Net::Awk::Source ();
|
||||
int n = wrapper->OpenSource (nio);
|
||||
return n;
|
||||
*/
|
||||
if (io.getMode() == Source::READ)
|
||||
{
|
||||
//wrapper->SourceInputStream->BeginRead ();
|
||||
if (wrapper->SourceInputStream == nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!wrapper->SourceInputStream->CanRead)
|
||||
{
|
||||
wrapper->SourceInputStream->Close ();
|
||||
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::Runtime::InteropServices::GCHandle* handle = (System::Runtime::InteropServices::GCHandle*)malloc (sizeof(System::Runtime::InteropServices::GCHandle));
|
||||
if (handle == NULL)
|
||||
{
|
||||
reader->Close ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle->Alloc (reader/*, System::Runtime::InteropServices::GCHandleType::Pinned */);
|
||||
io.setHandle (handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
//wrapper->SourceOutputStream->BeginWrite ();
|
||||
if (wrapper->SourceOutputStream == nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!wrapper->SourceOutputStream->CanWrite)
|
||||
{
|
||||
wrapper->SourceOutputStream->Close ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
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));
|
||||
if (handle == NULL)
|
||||
{
|
||||
writer->Close ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle->Alloc (writer/*, System::Runtime::InteropServices::GCHandleType::Pinned*/);
|
||||
io.setHandle (handle);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int closeSource (Source& io)
|
||||
{
|
||||
//System::IO::Stream^ stream = io.getHandle();
|
||||
//stream->Close ();
|
||||
System::Runtime::InteropServices::GCHandle* handle = (System::Runtime::InteropServices::GCHandle*)io.getHandle();
|
||||
|
||||
if (io.getMode() == Source::READ)
|
||||
{
|
||||
System::IO::StreamReader^ reader = (System::IO::StreamReader^)handle->Target;
|
||||
reader->Close ();
|
||||
}
|
||||
else
|
||||
{
|
||||
System::IO::StreamWriter^ writer = (System::IO::StreamWriter^)handle->Target;
|
||||
writer->Close ();
|
||||
}
|
||||
|
||||
handle->Free ();
|
||||
::free (handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t readSource (Source& io, char_t* buf, size_t len)
|
||||
{
|
||||
//System::IO::Stream^ stream = io.getHandle();
|
||||
return 0;
|
||||
System::Runtime::InteropServices::GCHandle* handle = (System::Runtime::InteropServices::GCHandle*)io.getHandle();
|
||||
System::IO::StreamReader^ reader = (System::IO::StreamReader^)handle->Target;
|
||||
|
||||
cli::array<char_t>^ b = gcnew cli::array<char_t>(len);
|
||||
int n = reader->Read (b, 0, len);
|
||||
for (int i = 0; i < n; i++) buf[i] = b[i];
|
||||
return n;
|
||||
}
|
||||
|
||||
ssize_t writeSource (Source& io, char_t* buf, size_t len)
|
||||
{
|
||||
//System::IO::Stream^ stream = io.getHandle();
|
||||
return 0;
|
||||
System::Runtime::InteropServices::GCHandle* handle = (System::Runtime::InteropServices::GCHandle*)io.getHandle();
|
||||
System::IO::StreamWriter^ writer = (System::IO::StreamWriter^)handle->Target;
|
||||
|
||||
cli::array<char_t>^ b = gcnew cli::array<char_t>(len);
|
||||
for (int i = 0; i < (int)len; i++) buf[i] = b[i];
|
||||
writer->Write (b, 0, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
int openPipe (Pipe& io) {return 0; }
|
||||
@ -129,13 +192,24 @@ namespace ASE
|
||||
Awk::Awk ()
|
||||
{
|
||||
awk = new ASE::StubAwk (this);
|
||||
if (awk->open () == -1)
|
||||
{
|
||||
// TODO:...
|
||||
//throw new AwkException ("cannot open awk");
|
||||
}
|
||||
}
|
||||
|
||||
Awk::~Awk ()
|
||||
{
|
||||
Close ();
|
||||
delete awk;
|
||||
}
|
||||
|
||||
void Awk::Close ()
|
||||
{
|
||||
awk->close ();
|
||||
}
|
||||
|
||||
bool Awk::Parse ()
|
||||
{
|
||||
return awk->parse () == 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp,v 1.2 2007/07/15 16:31:59 bacon Exp $
|
||||
* $Id: Awk.hpp,v 1.3 2007/07/16 11:12:12 bacon Exp $
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@ -16,6 +16,7 @@ namespace ASE
|
||||
public ref class Awk abstract
|
||||
{
|
||||
public:
|
||||
/*
|
||||
ref class Source
|
||||
{
|
||||
public:
|
||||
@ -33,7 +34,7 @@ namespace ASE
|
||||
|
||||
private:
|
||||
MODE^ mode;
|
||||
};
|
||||
};*/
|
||||
|
||||
ref class Extio
|
||||
{
|
||||
@ -101,6 +102,9 @@ namespace ASE
|
||||
Awk ();
|
||||
virtual ~Awk ();
|
||||
|
||||
bool Open ();
|
||||
void Close ();
|
||||
|
||||
bool Parse ();
|
||||
bool Run ();
|
||||
|
||||
@ -109,10 +113,6 @@ namespace ASE
|
||||
bool AddFunction (System::String^ name, int minArgs, int maxArgs, FunctionHandler^ handler);
|
||||
bool DeleteFunction (System::String^ name);
|
||||
|
||||
virtual int OpenSource (Source^ io) = 0;
|
||||
virtual int CloseSource (Source^ io) = 0;
|
||||
virtual int ReadSource (Source^ io, ASE::Awk::char_t* buf, ASE::Awk::size_t len) = 0;
|
||||
virtual int WriteSource (Source^ io, ASE::Awk::char_t* buf, ASE::Awk::size_t len) = 0;
|
||||
|
||||
property System::IO::Stream^ SourceInputStream
|
||||
{
|
||||
@ -142,6 +142,7 @@ namespace ASE
|
||||
|
||||
protected:
|
||||
ASE::Awk* awk;
|
||||
|
||||
System::IO::Stream^ sourceInputStream;
|
||||
System::IO::Stream^ sourceOutputStream;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: StdAwk.hpp,v 1.1 2007/07/15 16:31:59 bacon Exp $
|
||||
* $Id: StdAwk.hpp,v 1.2 2007/07/16 11:12:12 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/net/Awk.hpp>
|
||||
@ -8,9 +8,11 @@ namespace ASE
|
||||
{
|
||||
namespace Net
|
||||
{
|
||||
|
||||
public ref class StdAwk: Awk
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: assert.cpp,v 1.1 2007/07/15 16:31:59 bacon Exp $
|
||||
* $Id: assert.cpp,v 1.2 2007/07/16 11:12:12 bacon Exp $
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
@ -12,6 +12,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
#pragma unmanaged
|
||||
|
||||
void ase_assert_abort (void)
|
||||
{
|
||||
::abort ();
|
||||
|
@ -17,7 +17,13 @@ namespace asetestnet
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
ASE.Net.Awk awk = new ASE.Net.Awk();
|
||||
ASE.Net.Awk awk = new ASE.Net.StdAwk();
|
||||
|
||||
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.Parse();
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<OutputPath>..\..\Debug\bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
@ -22,7 +22,7 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<OutputPath>..\..\Release\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
|
Loading…
Reference in New Issue
Block a user