Recovered from cvs revision 2007-08-21 14:24:00

This commit is contained in:
hyung-hwan 2007-08-21 23:24:00 +00:00
parent 72c5c9174c
commit a7a4d8de4c
5 changed files with 159 additions and 84 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.cpp,v 1.16 2007/08/18 15:42:04 bacon Exp $ * $Id: Awk.cpp,v 1.17 2007/08/20 14:19:58 bacon Exp $
*/ */
#include "stdafx.h" #include "stdafx.h"
@ -99,7 +99,7 @@ namespace ASE
const char_t* name, size_t len) const char_t* name, size_t len)
{ {
return wrapper->DispatchFunction (ret, args, nargs, name, len); return wrapper->DispatchFunction (ret, args, nargs, name, len)? 0: -1;
} }
int openSource (Source& io) int openSource (Source& io)
@ -558,7 +558,7 @@ System::Diagnostics::Debug::Print ("Awk::!Awk");
return n == 0; return n == 0;
} }
int Awk::DispatchFunction (ASE::Awk::Return* ret, bool Awk::DispatchFunction (ASE::Awk::Return* ret,
const ASE::Awk::Argument* args, size_t nargs, const ASE::Awk::Argument* args, size_t nargs,
const char_t* name, size_t len) const char_t* name, size_t len)
{ {
@ -569,64 +569,9 @@ System::Diagnostics::Debug::Print ("Awk::!Awk");
cli::array<Argument^>^ arg_arr = gcnew cli::array<Argument^> (nargs); cli::array<Argument^>^ arg_arr = gcnew cli::array<Argument^> (nargs);
for (size_t i = 0; i < nargs; i++) arg_arr[i] = gcnew Argument(args[i]); for (size_t i = 0; i < nargs; i++) arg_arr[i] = gcnew Argument(args[i]);
System::Object^ r = fh (nm, arg_arr);
if (r == nullptr) return -1;
System::Type^ type = r->GetType(); Return^ r = gcnew Return (*ret);
if (System::String::typeid == type) return fh(nm, arg_arr, r);
{
System::String^ str = (System::String^)r;
cli::pin_ptr<const ASE::Awk::char_t> nptr = PtrToStringChars(str);
ret->set (nptr, str->Length);
}
else if (System::SByte::typeid == type)
{
ret->set ((ASE::Awk::long_t)(__int8)r);
}
else if (System::Int16::typeid == type)
{
ret->set ((ASE::Awk::long_t)(__int16)r);
}
else if (System::Int32::typeid == type)
{
ret->set ((ASE::Awk::long_t)(__int32)r);
}
else if (System::Int64::typeid == type)
{
ret->set ((ASE::Awk::long_t)(__int64)r);
}
else if (System::Byte::typeid == type)
{
ret->set ((ASE::Awk::long_t)(unsigned __int8)r);
}
else if (System::UInt16::typeid == type)
{
ret->set ((ASE::Awk::long_t)(unsigned __int16)r);
}
else if (System::UInt32::typeid == type)
{
ret->set ((ASE::Awk::long_t)(unsigned __int32)r);
}
else if (System::UInt64::typeid == type)
{
ret->set ((ASE::Awk::long_t)(unsigned __int64)r);
}
else if (System::Single::typeid == type)
{
ret->set ((ASE::Awk::real_t)(float)r);
}
else if (System::Double::typeid == type)
{
ret->set ((ASE::Awk::real_t)(double)r);
}
else
{
System::String^ str = r->ToString();
cli::pin_ptr<const ASE::Awk::char_t> nptr = PtrToStringChars(str);
ret->set (nptr, str->Length);
}
return 0;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.hpp,v 1.13 2007/08/18 15:42:04 bacon Exp $ * $Id: Awk.hpp,v 1.14 2007/08/20 14:19:58 bacon Exp $
*/ */
#pragma once #pragma once
@ -26,25 +26,33 @@ namespace ASE
ref class Argument ref class Argument
{ {
public protected: public protected:
Argument (const ASE::Awk::Argument& arg) Argument (const ASE::Awk::Argument& arg): arg(arg)
{ {
size_t len;
const char_t* s = arg.toStr(&len);
str = gcnew System::String (s, 0, len);
inum = arg.toInt ();
rnum = arg.toReal ();
} }
public: public:
long_t ToInt () { return inum; } property long_t LongValue
real_t ToReal () { return rnum; } {
System::String^ ToStr () { return str; } long_t get () { return arg.toInt(); }
}
property real_t RealValue
{
real_t get () { return arg.toReal(); }
}
property System::String^ StringValue
{
System::String^ get ()
{
size_t len;
const char_t* s = arg.toStr(&len);
return gcnew System::String (s, 0, len);
}
}
protected: protected:
long_t inum; const ASE::Awk::Argument& arg;
real_t rnum;
System::String^ str;
}; };
ref class Return ref class Return
@ -54,23 +62,111 @@ namespace ASE
{ {
} }
property System::Object^ Value public:
property System::String^ StringValue
{ {
void set (System::String^ v) void set (System::String^ v)
{ {
cli::pin_ptr<const char_t> nptr = PtrToStringChars(v); cli::pin_ptr<const char_t> nptr = PtrToStringChars(v);
ret.set (nptr, v->Length); ret.set (nptr, v->Length);
} }
}
property long_t LongValue
{
void set (long_t v)
{
ret.set (v);
}
}
property real_t RealValue
{
void set (real_t v)
{
ret.set (v);
}
}
property System::Single^ SingleValue
{
void set (System::Single^ v) void set (System::Single^ v)
{ {
ret.set ((real_t)(float)v); ret.set ((real_t)(float)v);
} }
}
property System::Double^ DoubleValue
{
void set (System::Double^ v) void set (System::Double^ v)
{ {
ret.set ((real_t)(double)v); ret.set ((real_t)(double)v);
} }
} }
property System::SByte^ SByteValue
{
void set (System::SByte^ v)
{
ret.set ((long_t)(__int8)v);
}
}
property System::Int16^ Int16Value
{
void set (System::Int16^ v)
{
ret.set ((long_t)(__int16)v);
}
}
property System::Int32^ Int32Value
{
void set (System::Int32^ v)
{
ret.set ((long_t)(__int32)v);
}
}
property System::Int64^ Int64Value
{
void set (System::Int64^ v)
{
ret.set ((long_t)(__int64)v);
}
}
property System::Byte^ ByteValue
{
void set (System::Byte^ v)
{
ret.set ((long_t)(unsigned __int8)v);
}
}
property System::UInt16^ UInt16Value
{
void set (System::UInt16^ v)
{
ret.set ((long_t)(unsigned __int16)v);
}
}
property System::UInt32^ UInt32Value
{
void set (System::UInt32^ v)
{
ret.set ((long_t)(unsigned __int32)v);
}
}
property System::UInt64^ UInt64Value
{
void set (System::UInt64^ v)
{
ret.set ((long_t)(unsigned __int64)v);
}
}
public: public:
ASE::Awk::Return& ret; ASE::Awk::Return& ret;
@ -233,7 +329,7 @@ namespace ASE
bool Parse (); bool Parse ();
bool Run (); bool Run ();
delegate System::Object^ FunctionHandler (System::String^ name, array<Argument^>^ args); delegate bool FunctionHandler (System::String^ name, array<Argument^>^ args, Return^ ret);
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);
@ -287,7 +383,7 @@ namespace ASE
virtual int NextConsole (Console^ console) = 0; virtual int NextConsole (Console^ console) = 0;
public protected: public protected:
int Awk::DispatchFunction (ASE::Awk::Return* ret, bool Awk::DispatchFunction (ASE::Awk::Return* ret,
const ASE::Awk::Argument* args, size_t nargs, const ASE::Awk::Argument* args, size_t nargs,
const char_t* name, size_t len); const char_t* name, size_t len);
}; };

View File

@ -1,5 +1,5 @@
/* /*
* $Id: StdAwk.cpp,v 1.3 2007/07/20 09:23:37 bacon Exp $ * $Id: StdAwk.cpp,v 1.5 2007/08/20 14:27:47 bacon Exp $
*/ */
#include "stdafx.h" #include "stdafx.h"
@ -17,12 +17,34 @@ namespace ASE
StdAwk::StdAwk () StdAwk::StdAwk ()
{ {
// TODO: exception/error handling....
AddFunction ("sin", 1, 1, gcnew FunctionHandler (this, &StdAwk::Sin));
AddFunction ("cos", 1, 1, gcnew FunctionHandler (this, &StdAwk::Cos));
AddFunction ("tan", 1, 1, gcnew FunctionHandler (this, &StdAwk::Tan));
} }
StdAwk::~StdAwk () StdAwk::~StdAwk ()
{ {
} }
bool StdAwk::Sin (System::String^ name, array<Argument^>^ args, Return^ ret)
{
ret->RealValue = System::Math::Sin (args[0]->RealValue);
return true;
}
bool StdAwk::Cos (System::String^ name, array<Argument^>^ args, Return^ ret)
{
ret->RealValue = System::Math::Cos (args[0]->RealValue);
return true;
}
bool StdAwk::Tan (System::String^ name, array<Argument^>^ args, Return^ ret)
{
ret->RealValue = System::Math::Tan (args[0]->RealValue);
return true;
}
int StdAwk::OpenFile (File^ file) int StdAwk::OpenFile (File^ file)
{ {
System::IO::FileMode mode; System::IO::FileMode mode;
@ -183,6 +205,7 @@ namespace ASE
{ {
if (fputwc (*ptr, fp) == WEOF) if (fputwc (*ptr, fp) == WEOF)
{ {
::free (mbp);
return -1; return -1;
} }
left -= 1; ptr += 1; left -= 1; ptr += 1;
@ -190,7 +213,11 @@ namespace ASE
else else
{ {
int n = fprintf (fp, "%.*s", left, ptr); int n = fprintf (fp, "%.*s", left, ptr);
if (n < 0 || n > left) return -1; if (n < 0 || n > left)
{
::free (mbp);
return -1;
}
left -= n; ptr += n; left -= n; ptr += n;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: StdAwk.hpp,v 1.4 2007/07/20 09:23:37 bacon Exp $ * $Id: StdAwk.hpp,v 1.5 2007/08/20 14:19:58 bacon Exp $
*/ */
#include <ase/net/Awk.hpp> #include <ase/net/Awk.hpp>
@ -15,6 +15,11 @@ namespace ASE
StdAwk (); StdAwk ();
~StdAwk (); ~StdAwk ();
protected:
bool Sin (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Cos (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Tan (System::String^ name, array<Argument^>^ args, Return^ ret);
public protected: public protected:
// File // File
virtual int OpenFile (File^ file) override; virtual int OpenFile (File^ file) override;

View File

@ -16,10 +16,12 @@ namespace asetestnet
InitializeComponent(); InitializeComponent();
} }
object sin(string name, ASE.Net.Awk.Argument[] args) /*bool sin(string name, ASE.Net.Awk.Argument[] args, ASE.Net.Awk.Return ret)
{ {
return System.Math.Sin(args[0].ToReal()); //ret.DoubleValue = System.Math.Sin(args[0].RealValue);
} ret.RealValue = System.Math.Sin(args[0].RealValue);
return true;
}*/
private void btnRun_Click(object sender, EventArgs e) private void btnRun_Click(object sender, EventArgs e)
{ {
@ -31,7 +33,7 @@ namespace asetestnet
tbxSourceOutput.Text = ""; tbxSourceOutput.Text = "";
tbxConsoleOutput.Text = ""; tbxConsoleOutput.Text = "";
awk.AddFunction("sin", 1, 1, sin); //awk.AddFunction("sin", 1, 1, sin);
if (!awk.Parse(tbxSourceInput, tbxSourceOutput)) if (!awk.Parse(tbxSourceInput, tbxSourceOutput))
{ {
MessageBox.Show("Parse error"); MessageBox.Show("Parse error");