Recovered from cvs revision 2007-07-21 04:14:00

This commit is contained in:
2007-07-25 18:53:00 +00:00
parent f263c4f96f
commit 21550f9acf
24 changed files with 532 additions and 340 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.8 2007/07/19 14:35:10 bacon Exp $
* $Id: Awk.cpp,v 1.9 2007/07/20 09:23:37 bacon Exp $
*/
#include "stdafx.h"
@ -48,8 +48,8 @@ namespace ASE
}
System::IO::StreamReader^ reader = gcnew System::IO::StreamReader (wrapper->SourceInputStream);
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::Alloc (reader);
System::IntPtr^ ip = System::Runtime::InteropServices::GCHandle::ToIntPtr(gh);
GCHandle gh = GCHandle::Alloc (reader);
System::IntPtr^ ip = GCHandle::ToIntPtr(gh);
io.setHandle (ip->ToPointer());
}
else
@ -66,8 +66,8 @@ namespace ASE
}
System::IO::StreamWriter^ writer = gcnew System::IO::StreamWriter (wrapper->SourceOutputStream);
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::Alloc (writer);
System::IntPtr^ ip = System::Runtime::InteropServices::GCHandle::ToIntPtr(gh);
GCHandle gh = GCHandle::Alloc (writer);
System::IntPtr^ ip = GCHandle::ToIntPtr(gh);
io.setHandle (ip->ToPointer());
}
@ -77,7 +77,7 @@ namespace ASE
int closeSource (Source& io)
{
System::IntPtr ip ((void*)io.getHandle());
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::FromIntPtr (ip);
GCHandle gh = GCHandle::FromIntPtr (ip);
if (io.getMode() == Source::READ)
{
@ -97,7 +97,7 @@ namespace ASE
ssize_t readSource (Source& io, char_t* buf, size_t len)
{
System::IntPtr ip ((void*)io.getHandle());
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::FromIntPtr (ip);
GCHandle gh = GCHandle::FromIntPtr (ip);
System::IO::StreamReader^ reader = (System::IO::StreamReader^)gh.Target;
@ -111,7 +111,7 @@ namespace ASE
ssize_t writeSource (Source& io, char_t* buf, size_t len)
{
System::IntPtr ip ((void*)io.getHandle());
System::Runtime::InteropServices::GCHandle gh = System::Runtime::InteropServices::GCHandle::FromIntPtr (ip);
GCHandle gh = GCHandle::FromIntPtr (ip);
System::IO::StreamWriter^ writer = (System::IO::StreamWriter^)gh.Target;
@ -131,16 +131,28 @@ namespace ASE
GCHandle gh = GCHandle::Alloc (nio);
io.setHandle (GCHandle::ToIntPtr(gh).ToPointer());
return wrapper->FireOpenPipe (nio);
try { return wrapper->OpenPipe (nio); }
catch (...)
{
gh.Free ();
io.setHandle (NULL);
return -1;
}
}
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;
try
{
return wrapper->ClosePipe (
(ASE::Net::Awk::Pipe^)gh.Target);
}
catch (...) { return -1; }
finally { gh.Free (); }
}
ssize_t readPipe (Pipe& io, char_t* buf, size_t len)
@ -148,26 +160,48 @@ namespace ASE
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
cli::array<char_t>^ b = gcnew cli::array<char_t> (len);
int n = wrapper->FireReadPipe ((ASE::Net::Awk::Pipe^)gh.Target, b, len);
for (int i = 0; i < n; i++) buf[i] = b[i];
return n;
cli::array<char_t>^ b = nullptr;
try
{
b = gcnew cli::array<char_t> (len);
int n = wrapper->ReadPipe (
(ASE::Net::Awk::Pipe^)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 writePipe (Pipe& io, char_t* buf, size_t len)
{
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
cli::array<char_t>^ b = gcnew cli::array<char_t> (len);
for (int i = 0; i < len; i++) b[i] = buf[i];
return wrapper->FireWritePipe ((ASE::Net::Awk::Pipe^)gh.Target, b, len);
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->WritePipe (
(ASE::Net::Awk::Pipe^)gh.Target, b, len);
}
catch (...) { return -1; }
finally { if (b != nullptr) delete b; }
}
int flushPipe (Pipe& io)
{
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
return wrapper->FireFlushPipe ((ASE::Net::Awk::Pipe^)gh.Target);
try
{
return wrapper->FlushPipe (
(ASE::Net::Awk::Pipe^)gh.Target);
}
catch (...) { return -1; }
}
int openFile (File& io)
@ -179,16 +213,27 @@ namespace ASE
GCHandle gh = GCHandle::Alloc (nio);
io.setHandle (GCHandle::ToIntPtr(gh).ToPointer());
return wrapper->FireOpenFile (nio);
try { return wrapper->OpenFile (nio); }
catch (...)
{
gh.Free ();
io.setHandle (NULL);
return -1;
}
}
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;
try
{
return wrapper->CloseFile (
(ASE::Net::Awk::File^)gh.Target);
}
catch (...) { return -1; }
finally { gh.Free (); }
}
ssize_t readFile (File& io, char_t* buf, size_t len)
@ -196,26 +241,47 @@ namespace ASE
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
cli::array<char_t>^ b = gcnew cli::array<char_t> (len);
int n = wrapper->FireReadFile ((ASE::Net::Awk::File^)gh.Target, b, len);
for (int i = 0; i < n; i++) buf[i] = b[i];
return n;
cli::array<char_t>^ b = nullptr;
try
{
b = gcnew cli::array<char_t> (len);
int n = wrapper->ReadFile (
(ASE::Net::Awk::File^)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 writeFile (File& io, char_t* buf, size_t len)
{
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
cli::array<char_t>^ b = gcnew cli::array<char_t> (len);
for (int i = 0; i < len; i++) b[i] = buf[i];
return wrapper->FireWriteFile ((ASE::Net::Awk::File^)gh.Target, b, len);
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->WriteFile (
(ASE::Net::Awk::File^)gh.Target, b, len);
}
catch (...) { return -1; }
finally { if (b != nullptr) delete b; }
}
int flushFile (File& io)
{
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
return wrapper->FireFlushFile ((ASE::Net::Awk::File^)gh.Target);
try
{
return wrapper->FlushFile (
(ASE::Net::Awk::File^)gh.Target);
}
catch (...) { return -1; }
}
int openConsole (Console& io)
@ -227,49 +293,88 @@ namespace ASE
GCHandle gh = GCHandle::Alloc (nio);
io.setHandle (GCHandle::ToIntPtr(gh).ToPointer());
return wrapper->FireOpenConsole (nio);
try { return wrapper->OpenConsole (nio); }
catch (...)
{
gh.Free ();
io.setHandle (NULL);
return -1;
}
}
int closeConsole (Console& io)
{
IntPtr ip ((void*)io.getHandle ());
GCHandle gh = GCHandle::FromIntPtr (ip);
int n = wrapper->FireCloseConsole ((ASE::Net::Awk::Console^)gh.Target);
gh.Free ();
return n;
try
{
return wrapper->CloseConsole (
(ASE::Net::Awk::Console^)gh.Target);
}
catch (...) { return -1; }
finally { gh.Free (); }
}
ssize_t readConsole (Console& io, char_t* buf, size_t len)
{
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
cli::array<char_t>^ b = gcnew cli::array<char_t> (len);
int n = wrapper->FireReadConsole ((ASE::Net::Awk::Console^)gh.Target, b, len);
for (int i = 0; i < n; i++) buf[i] = b[i];
return n;
cli::array<char_t>^ b = nullptr;
try
{
b = gcnew cli::array<char_t> (len);
int n = wrapper->ReadConsole (
(ASE::Net::Awk::Console^)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 writeConsole (Console& io, char_t* buf, size_t len)
{
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
cli::array<char_t>^ b = gcnew cli::array<char_t> (len);
for (int i = 0; i < len; i++) b[i] = buf[i];
return wrapper->FireWriteConsole ((ASE::Net::Awk::Console^)gh.Target, b, len);
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->WriteConsole (
(ASE::Net::Awk::Console^)gh.Target, b, len);
}
catch (...) { return -1; }
finally { if (b != nullptr) delete b; }
}
int flushConsole (Console& io)
{
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
return wrapper->FireFlushConsole ((ASE::Net::Awk::Console^)gh.Target);
try
{
return wrapper->FlushConsole (
(ASE::Net::Awk::Console^)gh.Target);
}
catch (...) { return -1; }
}
int nextConsole (Console& io)
{
IntPtr ip ((void*)io.getHandle());
GCHandle gh = GCHandle::FromIntPtr (ip);
return wrapper->FireNextConsole ((ASE::Net::Awk::Console^)gh.Target);
try
{
return wrapper->NextConsole (
(ASE::Net::Awk::Console^)gh.Target);
}
catch (...) { return -1; }
}
// primitive operations
@ -363,73 +468,6 @@ namespace ASE
return 0;
}
int Awk::FireOpenFile (File^ file)
{
return OpenFileHandler (file);
}
int Awk::FireCloseFile (File^ file)
{
return CloseFileHandler (file);
}
int Awk::FireReadFile (File^ file, cli::array<char_t>^ buf, int len)
{
return ReadFileHandler (file, buf, len);
}
int Awk::FireWriteFile (File^ file, cli::array<char_t>^ buf, int len)
{
return WriteFileHandler (file, buf, len);
}
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, cli::array<char_t>^ buf, int len)
{
return ReadPipeHandler (pipe, buf, len);
}
int Awk::FireWritePipe (Pipe^ pipe, cli::array<char_t>^ buf, int len)
{
return WritePipeHandler (pipe, buf, len);
}
int Awk::FireFlushPipe (Pipe^ pipe)
{
return FlushPipeHandler (pipe);
}
int Awk::FireOpenConsole (Console^ console)
{
return OpenConsoleHandler (console);
}
int Awk::FireCloseConsole (Console^ console)
{
return CloseConsoleHandler (console);
}
int Awk::FireReadConsole (Console^ console, cli::array<char_t>^ buf, int len)
{
return ReadConsoleHandler (console, buf, len);
}
int Awk::FireWriteConsole (Console^ console, cli::array<char_t>^ buf, int len)
{
return WriteConsoleHandler (console, buf, len);
}
int Awk::FireFlushConsole (Console^ console)
{
return FlushConsoleHandler (console);
}
int Awk::FireNextConsole (Console^ console)
{
return NextConsoleHandler (console);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.6 2007/07/19 14:35:10 bacon Exp $
* $Id: Awk.hpp,v 1.7 2007/07/20 09:23:37 bacon Exp $
*/
#pragma once
@ -172,71 +172,46 @@ namespace ASE
}
}
delegate int OpenPipe (Pipe^ pipe);
delegate int ClosePipe (Pipe^ pipe);
delegate int ReadPipe (Pipe^ pipe, cli::array<char_t>^ buf, int len);
delegate int WritePipe (Pipe^ pipe, cli::array<char_t>^ buf, int len);
delegate int FlushPipe (Pipe^ pipe);
delegate int OpenFile (File^ file);
delegate int CloseFile (File^ file);
delegate int ReadFile (File^ file, cli::array<char_t>^ buf, int len);
delegate int WriteFile (File^ file, cli::array<char_t>^ buf, int len);
delegate int FlushFile (File^ file);
delegate int OpenConsole (Console^ console);
delegate int CloseConsole (Console^ console);
delegate int ReadConsole (Console^ console, cli::array<char_t>^ buf, int len);
delegate int WriteConsole (Console^ console, cli::array<char_t>^ buf, int len);
delegate int FlushConsole (Console^ console);
delegate int NextConsole (Console^ console);
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;
event OpenConsole^ OpenConsoleHandler;
event CloseConsole^ CloseConsoleHandler;
event ReadConsole^ ReadConsoleHandler;
event WriteConsole^ WriteConsoleHandler;
event FlushConsole^ FlushConsoleHandler;
event NextConsole^ NextConsoleHandler;
protected:
ASE::Awk* awk;
System::IO::Stream^ sourceInputStream;
System::IO::Stream^ sourceOutputStream;
public protected:
// File
virtual int OpenFile (File^ file) = 0;
virtual int CloseFile (File^ file) = 0;
virtual int ReadFile (
File^ file, cli::array<char_t>^ buf, int len) = 0;
virtual int WriteFile (
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;
virtual int ReadPipe (
Pipe^ pipe, cli::array<char_t>^ buf, int len) = 0;
virtual int WritePipe (
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;
virtual int ReadConsole (
Console^ console, cli::array<char_t>^ buf, int len) = 0;
virtual int WriteConsole (
Console^ console, cli::array<char_t>^ buf, int len) = 0;
virtual int FlushConsole (Console^ console) = 0;
virtual int NextConsole (Console^ console) = 0;
public protected:
int DispatchFunction (System::String^ name);
int FireOpenFile (File^ file);
int FireCloseFile (File^ file);
int FireReadFile (File^ file, cli::array<char_t>^ buf, int len);
int FireWriteFile (File^ file, cli::array<char_t>^ buf, int len);
int FireFlushFile (File^ file);
int FireOpenPipe (Pipe^ pipe);
int FireClosePipe (Pipe^ pipe);
int FireReadPipe (Pipe^ pipe, cli::array<char_t>^ buf, int len);
int FireWritePipe (Pipe^ pipe, cli::array<char_t>^ buf, int len);
int FireFlushPipe (Pipe^ pipe);
int FireOpenConsole (Console^ console);
int FireCloseConsole (Console^ console);
int FireReadConsole (Console^ console, cli::array<char_t>^ buf, int len);
int FireWriteConsole (Console^ console, cli::array<char_t>^ buf, int len);
int FireFlushConsole (Console^ console);
int FireNextConsole (Console^ console);
};
}

View File

@ -1,10 +1,14 @@
/*
* $Id: StdAwk.cpp,v 1.2 2007/07/19 14:35:10 bacon Exp $
* $Id: StdAwk.cpp,v 1.3 2007/07/20 09:23:37 bacon Exp $
*/
#include "stdafx.h"
#include "misc.h"
#include <ase/net/StdAwk.hpp>
#include <stdio.h>
#include <tchar.h>
#include <vcclr.h>
namespace ASE
{
@ -13,62 +17,50 @@ namespace ASE
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)
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))
{
if (file->Mode->Equals(File::MODE::READ))
{
mode = System::IO::FileMode::Open;
access = System::IO::FileAccess::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;
fs = gcnew System::IO::FileStream (file->Name, mode, access);
System::IO::StreamReader^ rd = gcnew System::IO::StreamReader (fs);
file->Handle = rd;
}
catch (System::Exception^)
else if (file->Mode->Equals(File::MODE::WRITE))
{
return -1;
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;
}
int StdAwk::closeFile (File^ file)
int StdAwk::CloseFile (File^ file)
{
if (file->Mode == File::MODE::READ)
{
@ -83,34 +75,135 @@ namespace ASE
return 0;
}
int StdAwk::readFile (File^ file, cli::array<char_t>^ buf, int len)
int StdAwk::ReadFile (File^ file, cli::array<char_t>^ buf, int len)
{
System::IO::StreamReader^ sr = (System::IO::StreamReader^)file->Handle;
try { return sr->Read (buf, 0, len); }
catch (System::Exception^) { return -1; }
return sr->Read (buf, 0, len);
}
int StdAwk::writeFile (File^ file, cli::array<char_t>^ buf, int len)
int StdAwk::WriteFile (File^ file, cli::array<char_t>^ 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; }
sw->Write (buf, 0, len);
return len;
}
int StdAwk::flushFile (File^ file)
int StdAwk::FlushFile (File^ file)
{
System::IO::StreamWriter^ sw = (System::IO::StreamWriter^)file->Handle;
try
{
sw->Flush ();
return 0;
}
catch (System::Exception^) { return -1; }
sw->Flush ();
return 0;
}
int StdAwk::OpenPipe (Pipe^ pipe)
{
FILE* fp = NULL;
cli::pin_ptr<const wchar_t> name =
PtrToStringChars(pipe->Name);
if (pipe->Mode->Equals(Pipe::MODE::READ))
{
fp = _wpopen (name, L"r");
}
else // Pipe::MODE::WRITE
{
fp = _wpopen (name, L"w");
}
if (fp == NULL) return -1;
pipe->Handle = IntPtr ((void*)fp);
return 1;
}
int StdAwk::ClosePipe (Pipe^ pipe)
{
IntPtr ip = (IntPtr)pipe->Handle;
FILE* fp = (FILE*)ip.ToPointer();
return (::_pclose (fp) == EOF)? -1: 0;
}
int StdAwk::ReadPipe (Pipe^ pipe, cli::array<char_t>^ buf, int len)
{
IntPtr ip = (IntPtr)pipe->Handle;
FILE* fp = (FILE*)ip.ToPointer();
int n = 0;
while (n < len)
{
wint_t c = fgetwc (fp);
if (c == WEOF) break;
buf[n++] = c;
if (c == L'\n') break;
}
return n;
}
int StdAwk::WritePipe (Pipe^ pipe, cli::array<char_t>^ buf, int len)
{
IntPtr ip = (IntPtr)pipe->Handle;
FILE* fp = (FILE*)ip.ToPointer();
int left;
cli::pin_ptr<char_t> bp = &buf[0];
/* somehow, fwprintf returns 0 when non-ascii
* characters are included in the buffer.
while (left > 0)
{
if (*bp == ASE_T('\0'))
{
if (fputwc (*ptr, fp) == WEOF)
{
return -1;
}
left -= 1; bp += 1;
}
else
{
int n = fwprintf (fp, L"%.*s", left, bp);
if (n < 0 || n > left) return -1;
left -= n; bp += n;
}
}*/
/* so the scheme has been changed to the following */
char* mbp = unicode_to_multibyte (bp, len, &left);
if (mbp == NULL) return -1;
char* ptr = mbp;
while (left > 0)
{
if (*ptr == '\0')
{
if (fputwc (*ptr, fp) == WEOF)
{
return -1;
}
left -= 1; ptr += 1;
}
else
{
int n = fprintf (fp, "%.*s", left, ptr);
if (n < 0 || n > left) return -1;
left -= n; ptr += n;
}
}
::free (mbp);
return len;
}
int StdAwk::FlushPipe (Pipe^ pipe)
{
IntPtr ip = (IntPtr)pipe->Handle;
FILE* fp = (FILE*)ip.ToPointer();
return (::fflush (fp) == EOF)? -1: 0;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.hpp,v 1.3 2007/07/19 14:35:10 bacon Exp $
* $Id: StdAwk.hpp,v 1.4 2007/07/20 09:23:37 bacon Exp $
*/
#include <ase/net/Awk.hpp>
@ -9,20 +9,30 @@ namespace ASE
namespace Net
{
public ref class StdAwk: Awk
public ref class StdAwk abstract: public Awk
{
public:
StdAwk ();
~StdAwk ();
protected:
int openFile (File^ file);
int closeFile (File^ file);
int readFile (File^ file, cli::array<char_t>^ buf, int len);
int writeFile (File^ file, cli::array<char_t>^ buf, int len);
int flushFile (File^ file);
};
public protected:
// File
virtual int OpenFile (File^ file) override;
virtual int CloseFile (File^ file) override;
virtual int ReadFile (
File^ file, cli::array<char_t>^ buf, int len) override;
virtual int WriteFile (
File^ file, cli::array<char_t>^ buf, int len) override;
virtual int FlushFile (File^ file) override;
// Pipe
virtual int OpenPipe (Pipe^ pipe) override;
virtual int ClosePipe (Pipe^ pipe) override;
virtual int ReadPipe (
Pipe^ pipe, cli::array<char_t>^ buf, int len) override;
virtual int WritePipe (
Pipe^ pipe, cli::array<char_t>^ buf, int len) override;
virtual int FlushPipe (Pipe^ pipe) override;
};
}
}

View File

@ -188,11 +188,11 @@
>
</File>
<File
RelativePath=".\assert.cpp"
RelativePath=".\Awk.cpp"
>
</File>
<File
RelativePath=".\Awk.cpp"
RelativePath=".\misc.cpp"
>
</File>
<File
@ -233,6 +233,10 @@
RelativePath=".\Awk.hpp"
>
</File>
<File
RelativePath=".\misc.h"
>
</File>
<File
RelativePath=".\resource.h"
>

View File

@ -1,8 +1,9 @@
/*
* $Id: assert.cpp,v 1.2 2007/07/16 11:12:12 bacon Exp $
* $Id: misc.cpp,v 1.1 2007/07/20 09:23:37 bacon Exp $
*/
#include "stdafx.h"
#include "misc.h"
#ifndef NDEBUG
@ -41,3 +42,14 @@ void ase_assert_printf (const ase_char_t* fmt, ...)
}
#endif
char* unicode_to_multibyte (const wchar_t* in, int inlen, int* outlen)
{
int n;
n = WideCharToMultiByte (CP_UTF8, 0, in, inlen, NULL, 0, NULL, 0);
char* ptr = (char*)::malloc (sizeof(char)*n);
if (ptr == NULL) return NULL;
*outlen = WideCharToMultiByte (CP_UTF8, 0, in, inlen, ptr, n, NULL, 0);
return ptr;
}

18
ase/net/misc.h Normal file
View File

@ -0,0 +1,18 @@
/*
* $Id: misc.h,v 1.1 2007/07/20 09:23:37 bacon Exp $
*/
#ifndef _MISC_H_
#define _MISC_H_
#ifdef __cplusplus
extern "C" {
#endif
char* unicode_to_multibyte (const wchar_t* in, int inlen, int* outlen);
#ifdef __cplusplus
}
#endif
#endif