Recovered from cvs revision 2007-10-01 11:45:00
This commit is contained in:
parent
5c8dda1041
commit
6bc6f6c9db
204
ase/awk/Awk.cpp
204
ase/awk/Awk.cpp
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp,v 1.60 2007/09/27 11:30:20 bacon Exp $
|
||||
* $Id: Awk.cpp,v 1.61 2007/09/30 15:12:20 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -137,6 +137,9 @@ Awk::Console::Mode Awk::Console::getMode () const
|
||||
|
||||
Awk::Argument::Argument (): run (ASE_NULL), val (ASE_NULL)
|
||||
{
|
||||
this->inum = 0;
|
||||
this->rnum = 0.0;
|
||||
|
||||
this->str.ptr = ASE_NULL;
|
||||
this->str.len = 0;
|
||||
}
|
||||
@ -148,21 +151,52 @@ Awk::Argument::~Argument ()
|
||||
|
||||
void Awk::Argument::clear ()
|
||||
{
|
||||
if (this->str.ptr != ASE_NULL)
|
||||
if (this->val == ASE_NULL)
|
||||
{
|
||||
/* case 1. not initialized.
|
||||
* case 2. initialized with the second init.
|
||||
* none of the cases creates a new string so the sttring
|
||||
* that str.ptr is pointing at doesn't have to be freed */
|
||||
this->str.ptr = ASE_NULL;
|
||||
this->str.len = 0;
|
||||
}
|
||||
else if (this->val->type == ASE_AWK_VAL_MAP)
|
||||
{
|
||||
ASE_ASSERT (this->run != ASE_NULL);
|
||||
|
||||
/* when the value is a map, str.ptr and str.len are
|
||||
* used for index iteration in getFirstIndex & getNextIndex */
|
||||
ase_awk_refdownval (this->run, this->val);
|
||||
this->val = ASE_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASE_ASSERT (this->run != ASE_NULL);
|
||||
|
||||
if (this->str.ptr != ASE_NULL)
|
||||
{
|
||||
if (this->val->type != ASE_AWK_VAL_STR)
|
||||
{
|
||||
ase_awk_free (
|
||||
ase_awk_getrunawk(this->run), this->str.ptr);
|
||||
ase_awk_getrunawk(this->run),
|
||||
this->str.ptr);
|
||||
}
|
||||
|
||||
this->str.ptr = ASE_NULL;
|
||||
this->str.len = 0;
|
||||
}
|
||||
|
||||
if (this->val != ASE_NULL)
|
||||
{
|
||||
ASE_ASSERT (this->run != ASE_NULL);
|
||||
ase_awk_refdownval (this->run, this->val);
|
||||
this->val = ASE_NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this->rnum = 0.0;
|
||||
this->inum = 0;
|
||||
this->run = ASE_NULL;
|
||||
}
|
||||
|
||||
void* Awk::Argument::operator new (size_t n, awk_t* awk) throw ()
|
||||
@ -232,13 +266,17 @@ int Awk::Argument::init (run_t* run, val_t* v)
|
||||
this->inum = (ase_long_t)this->rnum;
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->str.ptr = ((ase_awk_val_str_t*)this->val)->buf;
|
||||
this->str.len = ((ase_awk_val_str_t*)this->val)->len;
|
||||
}
|
||||
else if (v->type == ASE_AWK_VAL_INT)
|
||||
{
|
||||
this->inum = ((ase_awk_val_int_t*)v)->val;
|
||||
this->rnum = (ase_real_t)((ase_awk_val_int_t*)v)->val;
|
||||
|
||||
this->str.ptr = ase_awk_valtostr (run, v, 0, ASE_NULL, &this->str.len);
|
||||
this->str.ptr = ase_awk_valtostr (
|
||||
run, v, 0, ASE_NULL, &this->str.len);
|
||||
if (this->str.ptr != ASE_NULL) return 0;
|
||||
}
|
||||
else if (v->type == ASE_AWK_VAL_REAL)
|
||||
@ -246,7 +284,8 @@ int Awk::Argument::init (run_t* run, val_t* v)
|
||||
this->inum = (ase_long_t)((ase_awk_val_real_t*)v)->val;
|
||||
this->rnum = ((ase_awk_val_real_t*)v)->val;
|
||||
|
||||
this->str.ptr = ase_awk_valtostr (run, v, 0, ASE_NULL, &this->str.len);
|
||||
this->str.ptr = ase_awk_valtostr (
|
||||
run, v, 0, ASE_NULL, &this->str.len);
|
||||
if (this->str.ptr != ASE_NULL) return 0;
|
||||
}
|
||||
else if (v->type == ASE_AWK_VAL_NIL)
|
||||
@ -254,51 +293,151 @@ int Awk::Argument::init (run_t* run, val_t* v)
|
||||
this->inum = 0;
|
||||
this->rnum = 0.0;
|
||||
|
||||
this->str.ptr = ase_awk_valtostr (run, v, 0, ASE_NULL, &this->str.len);
|
||||
this->str.ptr = ase_awk_valtostr (
|
||||
run, v, 0, ASE_NULL, &this->str.len);
|
||||
if (this->str.ptr != ASE_NULL) return 0;
|
||||
}
|
||||
else if (v->type == ASE_AWK_VAL_MAP)
|
||||
{
|
||||
// TODO: support this propertly...
|
||||
this->inum = 0;
|
||||
this->rnum = 0.0;
|
||||
this->str.ptr = ASE_NULL;
|
||||
this->str.len = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// an error has occurred
|
||||
ase_awk_refdownval (run, v);
|
||||
this->run = ASE_NULL;
|
||||
this->val = ASE_NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Awk::Argument::init (run_t* run, const char_t* str, size_t len)
|
||||
{
|
||||
ASE_ASSERT (this->run == ASE_NULL && this->val == ASE_NULL);
|
||||
|
||||
this->run = run;
|
||||
this->str.ptr = (char_t*)str;
|
||||
this->str.len = len;
|
||||
|
||||
if (ase_awk_strtonum (run, str, len, &this->inum, &this->rnum) == 0)
|
||||
{
|
||||
this->rnum = (real_t)this->inum;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->inum = (long_t)this->rnum;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Awk::long_t Awk::Argument::toInt () const
|
||||
{
|
||||
if (this->run == ASE_NULL || this->val == ASE_NULL) return 0;
|
||||
return this->inum;
|
||||
}
|
||||
|
||||
Awk::real_t Awk::Argument::toReal () const
|
||||
{
|
||||
if (this->run == ASE_NULL || this->val == ASE_NULL) return 0.0;
|
||||
return this->rnum;
|
||||
}
|
||||
|
||||
const Awk::char_t* Awk::Argument::toStr (size_t* len) const
|
||||
{
|
||||
if (this->run == ASE_NULL || this->val == ASE_NULL)
|
||||
|
||||
if (this->val != ASE_NULL && this->val->type == ASE_AWK_VAL_MAP)
|
||||
{
|
||||
*len = 0;
|
||||
return ASE_NULL;
|
||||
return ASE_T("");
|
||||
}
|
||||
|
||||
if (this->str.ptr != ASE_NULL)
|
||||
else if (this->str.ptr == ASE_NULL)
|
||||
{
|
||||
*len = 0;
|
||||
return ASE_T("");
|
||||
}
|
||||
else
|
||||
{
|
||||
*len = this->str.len;
|
||||
return this->str.ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASE_ASSERT (val->type == ASE_AWK_VAL_STR);
|
||||
*len = ((ase_awk_val_str_t*)this->val)->len;
|
||||
return ((ase_awk_val_str_t*)this->val)->buf;
|
||||
}
|
||||
}
|
||||
|
||||
bool Awk::Argument::isIndexed () const
|
||||
{
|
||||
if (this->val == ASE_NULL) return false;
|
||||
return this->val->type == ASE_AWK_VAL_MAP;
|
||||
}
|
||||
|
||||
int Awk::Argument::getIndexedAt (const char_t* idxptr, Awk::Argument& val) const
|
||||
{
|
||||
return getIndexedAt (idxptr, ase_strlen(idxptr), val);
|
||||
}
|
||||
|
||||
int Awk::Argument::getIndexedAt (const char_t* idxptr, size_t idxlen, Awk::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;
|
||||
|
||||
// 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, idxptr, idxlen);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
#include <ase/utl/stdio.h>
|
||||
int Awk::Argument::getFirstIndex (Awk::Argument& val) const
|
||||
{
|
||||
val.clear ();
|
||||
|
||||
if (this->val == ASE_NULL) return -1;
|
||||
if (this->val->type != ASE_AWK_VAL_MAP) return -1;
|
||||
|
||||
ase_size_t buckno;
|
||||
ase_awk_val_map_t* m = (ase_awk_val_map_t*)this->val;
|
||||
ase_awk_pair_t* pair = ase_awk_map_getfirstpair (m->map, &buckno);
|
||||
if (pair == ASE_NULL) return 0; // no more key
|
||||
|
||||
if (val.init (this->run, pair->key.ptr, pair->key.len) == -1) return -1;
|
||||
|
||||
// reuse the string field as an interator.
|
||||
this->str.ptr = (char_t*)pair;
|
||||
this->str.len = buckno;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Awk::Argument::getNextIndex (Awk::Argument& val) const
|
||||
{
|
||||
val.clear ();
|
||||
|
||||
if (this->val == ASE_NULL) return -1;
|
||||
if (this->val->type != ASE_AWK_VAL_MAP) return -1;
|
||||
|
||||
ase_awk_val_map_t* m = (ase_awk_val_map_t*)this->val;
|
||||
|
||||
ase_awk_pair_t* pair = (ase_awk_pair_t*)this->str.ptr;
|
||||
ase_size_t buckno = this->str.len;
|
||||
|
||||
pair = ase_awk_map_getnextpair (m->map, pair, &buckno);
|
||||
if (pair == ASE_NULL) return 0;
|
||||
|
||||
if (val.init (this->run, pair->key.ptr, pair->key.len) == -1) return -1;
|
||||
|
||||
// reuse the string field as an interator.
|
||||
this->str.ptr = (char_t*)pair;
|
||||
this->str.len = buckno;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@ -427,6 +566,22 @@ const Awk::char_t* Awk::Run::getErrorMessage () const
|
||||
return ase_awk_getrunerrmsg (this->run);
|
||||
}
|
||||
|
||||
void Awk::Run::setError (
|
||||
ErrorCode code, size_t line, const char_t* arg, size_t len)
|
||||
{
|
||||
ASE_ASSERT (this->run != ASE_NULL);
|
||||
|
||||
ase_cstr_t x = { arg, len };
|
||||
ase_awk_setrunerror (this->run, code, line, &x, 1);
|
||||
}
|
||||
|
||||
void Awk::Run::setError (
|
||||
ErrorCode code, size_t line, const char_t* msg)
|
||||
{
|
||||
ASE_ASSERT (this->run != ASE_NULL);
|
||||
ase_awk_setrunerrmsg (this->run, code, line, msg);
|
||||
}
|
||||
|
||||
int Awk::Run::setGlobal (int id, long_t v)
|
||||
{
|
||||
ASE_ASSERT (this->run != ASE_NULL);
|
||||
@ -434,8 +589,7 @@ int Awk::Run::setGlobal (int id, long_t v)
|
||||
ase_awk_val_t* tmp = ase_awk_makeintval (run, v);
|
||||
if (tmp == ASE_NULL)
|
||||
{
|
||||
ase_awk_setrunerror (
|
||||
this->run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
|
||||
setError (ERR_NOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -452,8 +606,7 @@ int Awk::Run::setGlobal (int id, real_t v)
|
||||
ase_awk_val_t* tmp = ase_awk_makerealval (run, v);
|
||||
if (tmp == ASE_NULL)
|
||||
{
|
||||
ase_awk_setrunerror (
|
||||
this->run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
|
||||
setError (ERR_NOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -470,8 +623,7 @@ int Awk::Run::setGlobal (int id, const char_t* ptr, size_t len)
|
||||
ase_awk_val_t* tmp = ase_awk_makestrval (run, ptr, len);
|
||||
if (tmp == ASE_NULL)
|
||||
{
|
||||
ase_awk_setrunerror (
|
||||
this->run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
|
||||
setError (ERR_NOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp,v 1.62 2007/09/27 11:04:10 bacon Exp $
|
||||
* $Id: Awk.hpp,v 1.63 2007/09/30 15:12:20 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -315,20 +315,28 @@ public:
|
||||
|
||||
protected:
|
||||
int init (run_t* run, val_t* v);
|
||||
int init (run_t* run, const char_t* str, size_t len);
|
||||
|
||||
public:
|
||||
long_t toInt () const;
|
||||
real_t toReal () const;
|
||||
const char_t* toStr (size_t* len) const;
|
||||
|
||||
bool isIndexed () const;
|
||||
|
||||
int getIndexedAt (const char_t* idxptr, Awk::Argument& val) const;
|
||||
int getIndexedAt (const char_t* idxptr, size_t idxlen, Awk::Argument& val) const;
|
||||
|
||||
int getFirstIndex (Awk::Argument& val) const;
|
||||
int getNextIndex (Awk::Argument& val) const;
|
||||
|
||||
protected:
|
||||
run_t* run;
|
||||
val_t* val;
|
||||
|
||||
ase_long_t inum;
|
||||
ase_real_t rnum;
|
||||
|
||||
struct
|
||||
mutable struct
|
||||
{
|
||||
char_t* ptr;
|
||||
size_t len;
|
||||
@ -346,6 +354,11 @@ public:
|
||||
Return (awk_t* awk);
|
||||
~Return ();
|
||||
|
||||
private:
|
||||
Return (const Return&);
|
||||
Return& operator= (const Return&);
|
||||
|
||||
protected:
|
||||
val_t* toVal (run_t* run) const;
|
||||
|
||||
public:
|
||||
@ -355,6 +368,8 @@ public:
|
||||
|
||||
void clear ();
|
||||
|
||||
// TODO: Support MAP HERE...
|
||||
|
||||
protected:
|
||||
awk_t* awk;
|
||||
int type;
|
||||
@ -556,6 +571,10 @@ public:
|
||||
size_t getErrorLine () const;
|
||||
const char_t* getErrorMessage () const;
|
||||
|
||||
void setError (ErrorCode code, size_t line = 0,
|
||||
const char_t* arg = ASE_NULL, size_t len = 0);
|
||||
void setError (ErrorCode code, size_t line, const char_t* msg);
|
||||
|
||||
/**
|
||||
* Sets the value of a global variable. The global variable
|
||||
* is indicated by the first parameter.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: map.c,v 1.9 2007/07/25 09:53:28 bacon Exp $
|
||||
* $Id: map.c,v 1.10 2007/09/30 15:12:20 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -281,6 +281,52 @@ int ase_awk_map_walk (ase_awk_map_t* map,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ase_awk_pair_t* ase_awk_map_getfirstpair (
|
||||
ase_awk_map_t* map, ase_size_t* buckno)
|
||||
{
|
||||
ase_size_t i;
|
||||
ase_awk_pair_t* pair;
|
||||
|
||||
for (i = 0; i < map->capa; i++)
|
||||
{
|
||||
pair = map->buck[i];
|
||||
if (pair != ASE_NULL)
|
||||
{
|
||||
*buckno = i;
|
||||
return pair;
|
||||
}
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
ase_awk_pair_t* ase_awk_map_getnextpair (
|
||||
ase_awk_map_t* map, ase_awk_pair_t* pair, ase_size_t* buckno)
|
||||
{
|
||||
ase_size_t i;
|
||||
ase_awk_pair_t* next;
|
||||
|
||||
next = ASE_AWK_PAIR_LNK(pair);
|
||||
if (next != ASE_NULL)
|
||||
{
|
||||
/* no change in bucket number */
|
||||
return next;
|
||||
}
|
||||
|
||||
for (i = (*buckno)+1; i < map->capa; i++)
|
||||
{
|
||||
pair = map->buck[i];
|
||||
if (pair != ASE_NULL)
|
||||
{
|
||||
*buckno = i;
|
||||
return pair;
|
||||
}
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
|
||||
static ase_size_t hashkey (const ase_char_t* keyptr, ase_size_t keylen)
|
||||
{
|
||||
ase_size_t n = 0, i;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: map.h,v 1.7 2007/07/25 07:00:09 bacon Exp $
|
||||
* $Id: map.h,v 1.8 2007/09/30 15:12:20 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -23,6 +23,8 @@ struct ase_awk_pair_t
|
||||
} key;
|
||||
|
||||
void* val;
|
||||
|
||||
/* used internally */
|
||||
ase_awk_pair_t* next;
|
||||
};
|
||||
|
||||
@ -85,6 +87,22 @@ int ase_awk_map_remove (
|
||||
int ase_awk_map_walk (ase_awk_map_t* map,
|
||||
int (*walker)(ase_awk_pair_t*,void*), void* arg);
|
||||
|
||||
/**
|
||||
* Gets the pointer to the first pair in the map.
|
||||
* @param map [in]
|
||||
* @param buckno [out]
|
||||
*/
|
||||
ase_awk_pair_t* ase_awk_map_getfirstpair (
|
||||
ase_awk_map_t* map, ase_size_t* buckno);
|
||||
/**
|
||||
* Gets the pointer to the next pair in the map.
|
||||
* @param map [in]
|
||||
* @param pair [in]
|
||||
* @param buckno [in out]
|
||||
*/
|
||||
ase_awk_pair_t* ase_awk_map_getnextpair (
|
||||
ase_awk_map_t* map, ase_awk_pair_t* pair, ase_size_t* buckno);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -10,13 +10,13 @@
|
||||
- Awk::OPT_RESET (awk/Awk.hpp)
|
||||
- Awk::OPTION::RESET (net/Awk.hpp)
|
||||
- Awk.OPTION_RESET (awk/Awk.java)
|
||||
- TODO: add it to com
|
||||
- Awk::EnableReset (net/asecom.idl, net/Awk.h)
|
||||
* added an option
|
||||
- ASE_AWK_MAPTOVAR (awk/awk.h)
|
||||
- Awk::OPT_MAPTOVAR (awk/Awk.hpp)
|
||||
- Awk::OPTION::MAPTOVAR (net/Awk.hpp)
|
||||
- Awk.OPTION_MAPTOVAR (awk/Awk.java)
|
||||
- TODO: add it to com
|
||||
- Awk::AllowMapToVar (net/asecom.idl, net/Awk.h)
|
||||
|
||||
* enhanced Awk::dispatchFunction to set a more accurate error code (awk/Awk.cpp)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp,v 1.8 2007/09/23 16:48:55 bacon Exp $
|
||||
* $Id: Awk.cpp,v 1.9 2007/09/30 15:12:20 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -1277,14 +1277,14 @@ STDMETHODIMP CAwk::put_StripSpaces(VARIANT_BOOL newVal)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CAwk::get_Nextofile(VARIANT_BOOL *pVal)
|
||||
STDMETHODIMP CAwk::get_EnableNextofile(VARIANT_BOOL *pVal)
|
||||
{
|
||||
if (handle != NULL) option = ase_awk_getoption (handle);
|
||||
*pVal = (option & ASE_AWK_NEXTOFILE) == 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CAwk::put_Nextofile(VARIANT_BOOL newVal)
|
||||
STDMETHODIMP CAwk::put_EnableNextofile(VARIANT_BOOL newVal)
|
||||
{
|
||||
if (newVal) option = option | ASE_AWK_NEXTOFILE;
|
||||
else option = option & ~ASE_AWK_NEXTOFILE;
|
||||
@ -1322,6 +1322,36 @@ STDMETHODIMP CAwk::put_ArgumentsToEntryPoint(VARIANT_BOOL newVal)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CAwk::get_EnableReset(VARIANT_BOOL *pVal)
|
||||
{
|
||||
if (handle != NULL) option = ase_awk_getoption (handle);
|
||||
*pVal = (option & ASE_AWK_RESET) == 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CAwk::put_EnableReset(VARIANT_BOOL newVal)
|
||||
{
|
||||
if (newVal) option = option | ASE_AWK_RESET;
|
||||
else option = option & ~ASE_AWK_RESET;
|
||||
if (handle != NULL) ase_awk_setoption (handle, option);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CAwk::get_AllowMapToVar(VARIANT_BOOL *pVal)
|
||||
{
|
||||
if (handle != NULL) option = ase_awk_getoption (handle);
|
||||
*pVal = (option & ASE_AWK_MAPTOVAR) == 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CAwk::put_AllowMapToVar(VARIANT_BOOL newVal)
|
||||
{
|
||||
if (newVal) option = option | ASE_AWK_MAPTOVAR;
|
||||
else option = option & ~ASE_AWK_MAPTOVAR;
|
||||
if (handle != NULL) ase_awk_setoption (handle, option);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CAwk::get_MaxDepthForBlockParse(int *pVal)
|
||||
{
|
||||
if (handle != NULL)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.h,v 1.7 2007/08/26 14:33:38 bacon Exp $
|
||||
* $Id: Awk.h,v 1.8 2007/09/30 15:12:20 bacon Exp $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -141,12 +141,16 @@ public:
|
||||
STDMETHOD(put_MaxDepthForBlockRun)(/*[in]*/ int newVal);
|
||||
STDMETHOD(get_MaxDepthForBlockParse)(/*[out, retval]*/ int *pVal);
|
||||
STDMETHOD(put_MaxDepthForBlockParse)(/*[in]*/ int newVal);
|
||||
STDMETHOD(get_AllowMapToVar)(/*[out, retval]*/ VARIANT_BOOL *pVal);
|
||||
STDMETHOD(put_AllowMapToVar)(/*[in]*/ VARIANT_BOOL newVal);
|
||||
STDMETHOD(get_EnableReset)(/*[out, retval]*/ VARIANT_BOOL *pVal);
|
||||
STDMETHOD(put_EnableReset)(/*[in]*/ VARIANT_BOOL newVal);
|
||||
STDMETHOD(get_ArgumentsToEntryPoint)(/*[out, retval]*/ VARIANT_BOOL *pVal);
|
||||
STDMETHOD(put_ArgumentsToEntryPoint)(/*[in]*/ VARIANT_BOOL newVal);
|
||||
STDMETHOD(get_UseCrlf)(/*[out, retval]*/ VARIANT_BOOL *pVal);
|
||||
STDMETHOD(put_UseCrlf)(/*[in]*/ VARIANT_BOOL newVal);
|
||||
STDMETHOD(get_Nextofile)(/*[out, retval]*/ VARIANT_BOOL *pVal);
|
||||
STDMETHOD(put_Nextofile)(/*[in]*/ VARIANT_BOOL newVal);
|
||||
STDMETHOD(get_EnableNextofile)(/*[out, retval]*/ VARIANT_BOOL *pVal);
|
||||
STDMETHOD(put_EnableNextofile)(/*[in]*/ VARIANT_BOOL newVal);
|
||||
STDMETHOD(get_StripSpaces)(/*[out, retval]*/ VARIANT_BOOL *pVal);
|
||||
STDMETHOD(put_StripSpaces)(/*[in]*/ VARIANT_BOOL newVal);
|
||||
STDMETHOD(get_BaseOne)(/*[out, retval]*/ VARIANT_BOOL *pVal);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: asecom.idl,v 1.7 2007/08/26 14:33:38 bacon Exp $
|
||||
* $Id: asecom.idl,v 1.8 2007/09/30 15:12:20 bacon Exp $
|
||||
*/
|
||||
|
||||
import "oaidl.idl";
|
||||
@ -100,10 +100,10 @@ interface IAwk : IDispatch
|
||||
[propput, id(21), helpstring("property StripSpaces")]
|
||||
HRESULT StripSpaces([in] VARIANT_BOOL newVal);
|
||||
|
||||
[propget, id(22), helpstring("property Nextofile")]
|
||||
HRESULT Nextofile([out,retval] VARIANT_BOOL *pVal);
|
||||
[propput, id(22), helpstring("property Nextofile")]
|
||||
HRESULT Nextofile([in] VARIANT_BOOL newVal);
|
||||
[propget, id(22), helpstring("property EnableNextofile")]
|
||||
HRESULT EnableNextofile([out,retval] VARIANT_BOOL *pVal);
|
||||
[propput, id(22), helpstring("property EnableNextofile")]
|
||||
HRESULT EnableNextofile([in] VARIANT_BOOL newVal);
|
||||
|
||||
[propget, id(23), helpstring("property UseCrlf")]
|
||||
HRESULT UseCrlf([out,retval] VARIANT_BOOL *pVal);
|
||||
@ -115,49 +115,59 @@ interface IAwk : IDispatch
|
||||
[propput, id(24), helpstring("property ArgumentsToEntryPoint")]
|
||||
HRESULT ArgumentsToEntryPoint([in] VARIANT_BOOL newVal);
|
||||
|
||||
[propget, id(25), helpstring("property MaxDepthForBlockParse")]
|
||||
[propget, id(25), helpstring("property EnableReset")]
|
||||
HRESULT EnableReset([out,retval] VARIANT_BOOL *pVal);
|
||||
[propput, id(25), helpstring("property EnableReset")]
|
||||
HRESULT EnableReset([in] VARIANT_BOOL newVal);
|
||||
|
||||
[propget, id(26), helpstring("property AllowMapToVar")]
|
||||
HRESULT AllowMapToVar([out,retval] VARIANT_BOOL *pVal);
|
||||
[propput, id(26), helpstring("property AllowMapToVar")]
|
||||
HRESULT AllowMapToVar([in] VARIANT_BOOL newVal);
|
||||
|
||||
[propget, id(27), helpstring("property MaxDepthForBlockParse")]
|
||||
HRESULT MaxDepthForBlockParse([out,retval] int *pVal);
|
||||
[propput, id(25), helpstring("property MaxDepthForBlockParse")]
|
||||
[propput, id(27), helpstring("property MaxDepthForBlockParse")]
|
||||
HRESULT MaxDepthForBlockParse([in] int newVal);
|
||||
|
||||
[propget, id(26), helpstring("property MaxDepthForBlockRun")]
|
||||
[propget, id(28), helpstring("property MaxDepthForBlockRun")]
|
||||
HRESULT MaxDepthForBlockRun([out,retval] int *pVal);
|
||||
[propput, id(26), helpstring("property MaxDepthForBlockRun")]
|
||||
[propput, id(28), helpstring("property MaxDepthForBlockRun")]
|
||||
HRESULT MaxDepthForBlockRun([in] int newVal);
|
||||
|
||||
[propget, id(27), helpstring("property MaxDepthForExprParse")]
|
||||
[propget, id(29), helpstring("property MaxDepthForExprParse")]
|
||||
HRESULT MaxDepthForExprParse([out,retval] int *pVal);
|
||||
[propput, id(27), helpstring("property MaxDepthForExprParse")]
|
||||
[propput, id(29), helpstring("property MaxDepthForExprParse")]
|
||||
HRESULT MaxDepthForExprParse([in] int newVal);
|
||||
|
||||
[propget, id(28), helpstring("property MaxDepthForExprRun")]
|
||||
[propget, id(30), helpstring("property MaxDepthForExprRun")]
|
||||
HRESULT MaxDepthForExprRun([out,retval] int *pVal);
|
||||
[propput, id(28), helpstring("property MaxDepthForExprRun")]
|
||||
[propput, id(30), helpstring("property MaxDepthForExprRun")]
|
||||
HRESULT MaxDepthForExprRun([in] int newVal);
|
||||
|
||||
[propget, id(29), helpstring("property MaxDepthForRexBuild")]
|
||||
[propget, id(31), helpstring("property MaxDepthForRexBuild")]
|
||||
HRESULT MaxDepthForRexBuild([out,retval] int *pVal);
|
||||
[propput, id(29), helpstring("property MaxDepthForRexBuild")]
|
||||
[propput, id(31), helpstring("property MaxDepthForRexBuild")]
|
||||
HRESULT MaxDepthForRexBuild([in] int newVal);
|
||||
|
||||
[propget, id(30), helpstring("property MaxDepthForRexMatch")]
|
||||
[propget, id(32), helpstring("property MaxDepthForRexMatch")]
|
||||
HRESULT MaxDepthForRexMatch([out,retval] int *pVal);
|
||||
[propput, id(30), helpstring("property MaxDepthForRexMatch")]
|
||||
[propput, id(32), helpstring("property MaxDepthForRexMatch")]
|
||||
HRESULT MaxDepthForRexMatch([in] int newVal);
|
||||
|
||||
[propget, id(31), helpstring("property EntryPoint")]
|
||||
[propget, id(33), helpstring("property EntryPoint")]
|
||||
HRESULT EntryPoint([out,retval] BSTR *pVal);
|
||||
[propput, id(31), helpstring("property EntryPoint")]
|
||||
[propput, id(33), helpstring("property EntryPoint")]
|
||||
HRESULT EntryPoint([in] BSTR newVal);
|
||||
|
||||
[propget, id(32), helpstring("property Debug")]
|
||||
[propget, id(34), helpstring("property Debug")]
|
||||
HRESULT Debug([out,retval] VARIANT_BOOL *pVal);
|
||||
[propput, id(32), helpstring("property Debug")]
|
||||
[propput, id(34), helpstring("property Debug")]
|
||||
HRESULT Debug([in] VARIANT_BOOL newVal);
|
||||
|
||||
[propget, id(33), helpstring("property UseLongLong")]
|
||||
[propget, id(35), helpstring("property UseLongLong")]
|
||||
HRESULT UseLongLong([out,retval] VARIANT_BOOL *pVal);
|
||||
[propput, id(33), helpstring("property UseLongLong")]
|
||||
[propput, id(35), helpstring("property UseLongLong")]
|
||||
HRESULT UseLongLong([in] VARIANT_BOOL newVal);
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp,v 1.36 2007/09/27 11:30:20 bacon Exp $
|
||||
* $Id: Awk.cpp,v 1.37 2007/09/30 15:12:20 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/StdAwk.hpp>
|
||||
@ -45,12 +45,27 @@ public:
|
||||
#else
|
||||
int n = ASE::StdAwk::open ();
|
||||
#endif
|
||||
if (n == -1)
|
||||
{
|
||||
HeapDestroy (heap);
|
||||
heap = ASE_NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
idLastSleep = addGlobal (ASE_T("LAST_SLEEP"));
|
||||
if (idLastSleep == -1 ||
|
||||
addFunction (ASE_T("sleep"), 1, 1,
|
||||
(FunctionHandler)&TestAwk::sleep) == -1)
|
||||
{
|
||||
if (idLastSleep == -1) goto failure;
|
||||
|
||||
if (addFunction (ASE_T("sleep"), 1, 1,
|
||||
(FunctionHandler)&TestAwk::sleep) == -1) goto failure;
|
||||
|
||||
if (addFunction (ASE_T("sumintarray"), 1, 1,
|
||||
(FunctionHandler)&TestAwk::sumintarray) == -1) goto failure;
|
||||
|
||||
if (addFunction (ASE_T("arrayindices"), 1, 1,
|
||||
(FunctionHandler)&TestAwk::arrayindices) == -1) goto failure;
|
||||
return 0;
|
||||
|
||||
failure:
|
||||
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
||||
StdAwk::close ();
|
||||
#else
|
||||
@ -64,9 +79,6 @@ public:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void close ()
|
||||
{
|
||||
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
||||
@ -90,6 +102,12 @@ public:
|
||||
int sleep (Run& run, Return& ret, const Argument* args, size_t nargs,
|
||||
const char_t* name, size_t len)
|
||||
{
|
||||
if (args[0].isIndexed())
|
||||
{
|
||||
run.setError (ERR_INVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
long_t x = args[0].toInt();
|
||||
|
||||
/*Argument arg;
|
||||
@ -101,13 +119,60 @@ public:
|
||||
if (run.setGlobal (idLastSleep, x) == -1) return -1;
|
||||
|
||||
#ifdef _WIN32
|
||||
::Sleep (x * 1000);
|
||||
::Sleep ((DWORD)(x * 1000));
|
||||
return ret.set ((long_t)0);
|
||||
#else
|
||||
return ret.set ((long_t)::sleep (x));
|
||||
#endif
|
||||
}
|
||||
|
||||
int sumintarray (Run& run, Return& ret, const Argument* args, size_t nargs,
|
||||
const char_t* name, size_t len)
|
||||
{
|
||||
long_t x = 0;
|
||||
|
||||
if (args[0].isIndexed())
|
||||
{
|
||||
Argument idx, val;
|
||||
|
||||
int n = args[0].getFirstIndex (idx);
|
||||
while (n > 0)
|
||||
{
|
||||
size_t len;
|
||||
const char_t* ptr = idx.toStr(&len);
|
||||
|
||||
if (args[0].getIndexedAt (ptr, len, val) == -1) return -1;
|
||||
x += val.toInt ();
|
||||
|
||||
n = args[0].getNextIndex (idx);
|
||||
}
|
||||
if (n != 0) return -1;
|
||||
}
|
||||
else x += args[0].toInt();
|
||||
|
||||
return ret.set (x);
|
||||
}
|
||||
|
||||
int arrayindices (Run& run, Return& ret, const Argument* args, size_t nargs,
|
||||
const char_t* name, size_t len)
|
||||
{
|
||||
if (!args[0].isIndexed()) return 0;
|
||||
|
||||
Argument idx;
|
||||
|
||||
int n = args[0].getFirstIndex (idx);
|
||||
while (n > 0)
|
||||
{
|
||||
size_t len;
|
||||
const char_t* ptr = idx.toStr(&len);
|
||||
|
||||
n = args[0].getNextIndex (idx);
|
||||
}
|
||||
if (n != 0) return -1;
|
||||
|
||||
return ret.set (L"XXXX", 4);
|
||||
}
|
||||
|
||||
int addConsoleInput (const char_t* file)
|
||||
{
|
||||
if (numConInFiles < ASE_COUNTOF(conInFile))
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c,v 1.16 2007/09/27 11:30:20 bacon Exp $
|
||||
* $Id: awk.c,v 1.17 2007/09/30 15:12:20 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk.h>
|
||||
@ -866,7 +866,7 @@ static int bfn_sleep (
|
||||
if (n == 1) lv = (ase_long_t)rv;
|
||||
|
||||
#ifdef _WIN32
|
||||
Sleep (lv * 1000);
|
||||
Sleep ((DWORD)(lv * 1000));
|
||||
n = 0;
|
||||
#else
|
||||
n = sleep (lv);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cs,v 1.3 2007/09/18 14:30:41 bacon Exp $
|
||||
* $Id: Awk.cs,v 1.4 2007/09/30 15:12:20 bacon Exp $
|
||||
*/
|
||||
|
||||
using System;
|
||||
@ -154,10 +154,10 @@ namespace ase.com
|
||||
set { awk.StripSpaces = value; }
|
||||
}
|
||||
|
||||
public bool Nextofile
|
||||
public bool EnableNextofile
|
||||
{
|
||||
get { return awk.Nextofile; }
|
||||
set { awk.Nextofile = value; }
|
||||
get { return awk.EnableNextofile; }
|
||||
set { awk.EnableNextofile = value; }
|
||||
}
|
||||
|
||||
public bool Usecrlf
|
||||
@ -166,6 +166,18 @@ namespace ase.com
|
||||
set { awk.UseCrlf = value; }
|
||||
}
|
||||
|
||||
public bool EnableReset
|
||||
{
|
||||
get { return awk.EnableReset; }
|
||||
set { awk.EnableReset = value; }
|
||||
}
|
||||
|
||||
public bool AllowMapToVar
|
||||
{
|
||||
get { return awk.AllowMapToVar; }
|
||||
set { awk.AllowMapToVar = value; }
|
||||
}
|
||||
|
||||
public string EntryPoint
|
||||
{
|
||||
get { return awk.EntryPoint; }
|
||||
|
Loading…
Reference in New Issue
Block a user