Recovered from cvs revision 2007-10-04 14:26:00

This commit is contained in:
hyung-hwan 2007-10-04 23:26:00 +00:00
parent aac112ab21
commit 78ec0d59a4
6 changed files with 100 additions and 42 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.65 2007/10/03 09:47:07 bacon Exp $
* $Id: Awk.cpp,v 1.66 2007/10/04 04:48:27 bacon Exp $
*
* {License}
*/
@ -375,7 +375,8 @@ int Awk::Argument::getIndexed (const char_t* idxptr, Awk::Argument& val) const
return getIndexed (idxptr, ase_strlen(idxptr), val);
}
int Awk::Argument::getIndexed (const char_t* idxptr, size_t idxlen, Awk::Argument& val) const
int Awk::Argument::getIndexed (
const char_t* idxptr, size_t idxlen, Awk::Argument& val) const
{
val.clear ();
@ -395,6 +396,51 @@ int Awk::Argument::getIndexed (const char_t* idxptr, size_t idxlen, Awk::Argumen
return val.init (this->run, (val_t*)pair->val);
}
int Awk::Argument::getIndexed (long_t idx, Argument& val) const
{
val.clear ();
// not initialized yet. val is just nil. not an error
if (this->val == ASE_NULL) return 0;
// not a map. val is just nil. not an error
if (this->val->type != ASE_AWK_VAL_MAP) return 0;
char_t ri[128];
Awk* awk = (Awk*)ase_awk_getcustomdata(ase_awk_getrunawk(this->run));
int rl = Awk::sprintf (
awk, ri, ASE_COUNTOF(ri),
#if ASE_SIZEOF_LONG_LONG > 0
ASE_T("%lld"), (long long)idx
#elif ASE_SIZEOF___INT64 > 0
ASE_T("%I64d"), (__int64)idx
#elif ASE_SIZEOF_LONG > 0
ASE_T("%ld"), (long)idx
#elif ASE_SIZEOF_INT > 0
ASE_T("%d"), (int)idx
#else
#error unsupported size
#endif
);
if (rl < 0)
{
ase_awk_setrunerror (this->run, ERR_INTERN, 0, ASE_NULL, 0);
return -1;
}
// get the value from the map.
ase_awk_val_map_t* m = (ase_awk_val_map_t*)this->val;
ase_awk_pair_t* pair = ase_awk_map_get (m->map, ri, rl);
// the key is not found. it is not an error. val is just nil
if (pair == ASE_NULL) return 0;
// if val.init fails, it should return an error
return val.init (this->run, (val_t*)pair->val);
}
int Awk::Argument::getFirstIndex (Awk::Argument& val) const
{
val.clear ();

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.66 2007/10/02 15:21:44 bacon Exp $
* $Id: Awk.hpp,v 1.67 2007/10/04 04:48:27 bacon Exp $
*
* {License}
*/
@ -295,6 +295,7 @@ public:
protected:
void clear ();
public:
// initialization
void* operator new (size_t n, awk_t* awk) throw ();
void* operator new[] (size_t n, awk_t* awk) throw ();
@ -326,6 +327,7 @@ public:
int getIndexed (const char_t* idxptr, Argument& val) const;
int getIndexed (const char_t* idxptr, size_t idxlen, Argument& val) const;
int getIndexed (long_t idx, Argument& val) const;
int getFirstIndex (Awk::Argument& val) const;
int getNextIndex (Awk::Argument& val) const;

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.27 2007/10/03 09:47:07 bacon Exp $
* $Id: Awk.cpp,v 1.28 2007/10/04 04:48:27 bacon Exp $
*
* {License}
*/
@ -13,7 +13,7 @@
#include <math.h>
#include <tchar.h>
#include <msclr/auto_gcroot.h>
//#include <msclr/auto_gcroot.h>
#include <msclr/gcroot.h>
using System::Runtime::InteropServices::GCHandle;
@ -921,7 +921,8 @@ namespace ASE
const ASE::Awk::Argument* args, size_t nargs,
const char_t* name, size_t len)
{
System::String^ nm = gcnew System::String (name, 0, len);
System::String^ nm =
gcnew System::String (name, 0, len);
FunctionHandler^ fh = (FunctionHandler^)funcs[nm];
if (fh == nullptr)
@ -930,13 +931,21 @@ namespace ASE
return false;
}
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]);
Return^ r = gcnew Return (ret);
cli::array<Argument^>^ a =
gcnew cli::array<Argument^> (nargs);
return fh (nm, arg_arr, r);
size_t i;
for (i = 0; i < nargs; i++)
a[i] = gcnew Argument(args[i]);
bool n = fh (nm, a, r);
while (i > 0) delete a[--i];
delete a;
delete r;
return n;
}
bool Awk::SetWord (System::String^ ow, System::String^ nw)

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.29 2007/10/03 09:47:07 bacon Exp $
* $Id: Awk.hpp,v 1.30 2007/10/04 04:48:27 bacon Exp $
*
* {License}
*/
@ -28,33 +28,20 @@ namespace ASE
ref class Argument
{
public:
/*
Argument ()
{
arg = new ASE::Awk::Argument ();
}
~Argument ()
{
delete arg;
}*/
public protected:
Argument (const ASE::Awk::Argument& arg): arg(&arg)
Argument (const ASE::Awk::Argument& arg): arg(arg)
{
}
public:
property long_t LongValue
{
long_t get () { return arg->toInt(); }
long_t get () { return arg.toInt(); }
}
property real_t RealValue
{
real_t get () { return arg->toReal(); }
real_t get () { return arg.toReal(); }
}
property System::String^ StringValue
@ -62,27 +49,43 @@ namespace ASE
System::String^ get ()
{
size_t len;
const char_t* s = arg->toStr(&len);
const char_t* s = arg.toStr(&len);
return gcnew System::String (s, 0, len);
}
}
bool GetIndexed (System::String^ idx)
bool GetIndexedLong (System::String^ idx, [System::Runtime::InteropServices::Out] long_t% v)
{
ASE::Awk::Argument x;
cli::pin_ptr<const char_t> ip = PtrToStringChars(idx);
return arg->getIndexed (ip, idx->Length, x) == 0;
if (arg.getIndexed (ip, idx->Length, x) == -1) return false;
v = x.toInt ();
return true;
}
/*
ttt = arg.GetIndexed ("abc");
if (ttt == nullptr)
bool GetIndexedReal (System::String^ idx, [System::Runtime::InteropServices::Out] real_t% v)
{
}*/
ASE::Awk::Argument x;
cli::pin_ptr<const char_t> ip = PtrToStringChars(idx);
if (arg.getIndexed (ip, idx->Length, x) == -1) return false;
v = x.toReal ();
return true;
}
bool GetIndexedString (System::String^ idx, [System::Runtime::InteropServices::Out] System::String^% v)
{
ASE::Awk::Argument x;
cli::pin_ptr<const char_t> ip = PtrToStringChars(idx);
if (arg.getIndexed (ip, idx->Length, x) == -1) return false;
size_t len;
const char_t* s = arg.toStr(&len);
v = gcnew System::String (s, 0, len);
return true;
}
protected:
const ASE::Awk::Argument* arg;
ASE::Awk::Argument x;
const ASE::Awk::Argument& arg;
};
ref class Return

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.39 2007/10/02 15:21:44 bacon Exp $
* $Id: Awk.cpp,v 1.40 2007/10/04 04:48:27 bacon Exp $
*/
#include <ase/awk/StdAwk.hpp>
@ -160,7 +160,6 @@ public:
Argument idx;
long_t i;
char_t buf[128];
int n = args[0].getFirstIndex (idx);
for (i = 0; n > 0; i++)

View File

@ -45,8 +45,7 @@ namespace ase.net
protected bool Sleep(string name, Argument[] args, Return ret)
{
System.Threading.Thread.Sleep((int)(args[0].LongValue*1000));
ret.LongValue = 0;
return true;
return ret.Set(0);
}
protected override int OpenSource(ASE.Net.StdAwk.Source source)