This commit is contained in:
parent
c17dc12bbd
commit
8f01118529
@ -418,7 +418,7 @@ int Awk::Argument::getIndexed (
|
|||||||
|
|
||||||
// get the value from the map.
|
// get the value from the map.
|
||||||
ase_awk_val_map_t* m = (ase_awk_val_map_t*)this->val;
|
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);
|
pair_t* pair = ase_map_get (m->map, idxptr, idxlen);
|
||||||
|
|
||||||
// the key is not found. it is not an error. val is just nil
|
// the key is not found. it is not an error. val is just nil
|
||||||
if (pair == ASE_NULL) return 0;
|
if (pair == ASE_NULL) return 0;
|
||||||
@ -462,7 +462,7 @@ int Awk::Argument::getIndexed (long_t idx, Argument& val) const
|
|||||||
|
|
||||||
// get the value from the map.
|
// get the value from the map.
|
||||||
ase_awk_val_map_t* m = (ase_awk_val_map_t*)this->val;
|
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);
|
pair_t* pair = ase_map_get (m->map, ri, rl);
|
||||||
|
|
||||||
// the key is not found. it is not an error. val is just nil
|
// the key is not found. it is not an error. val is just nil
|
||||||
if (pair == ASE_NULL) return 0;
|
if (pair == ASE_NULL) return 0;
|
||||||
@ -480,7 +480,7 @@ int Awk::Argument::getFirstIndex (Awk::Argument& val) const
|
|||||||
|
|
||||||
ase_size_t buckno;
|
ase_size_t buckno;
|
||||||
ase_awk_val_map_t* m = (ase_awk_val_map_t*)this->val;
|
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);
|
pair_t* pair = ase_map_getfirstpair (m->map, &buckno);
|
||||||
if (pair == ASE_NULL) return 0; // no more key
|
if (pair == ASE_NULL) return 0; // no more key
|
||||||
|
|
||||||
if (val.init (pair->key.ptr, pair->key.len) == -1) return -1;
|
if (val.init (pair->key.ptr, pair->key.len) == -1) return -1;
|
||||||
@ -501,10 +501,10 @@ int Awk::Argument::getNextIndex (Awk::Argument& val) const
|
|||||||
|
|
||||||
ase_awk_val_map_t* m = (ase_awk_val_map_t*)this->val;
|
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;
|
pair_t* pair = (pair_t*)this->str.ptr;
|
||||||
ase_size_t buckno = this->str.len;
|
ase_size_t buckno = this->str.len;
|
||||||
|
|
||||||
pair = ase_awk_map_getnextpair (m->map, pair, &buckno);
|
pair = ase_map_getnextpair (m->map, pair, &buckno);
|
||||||
if (pair == ASE_NULL) return 0;
|
if (pair == ASE_NULL) return 0;
|
||||||
|
|
||||||
if (val.init (pair->key.ptr, pair->key.len) == -1) return -1;
|
if (val.init (pair->key.ptr, pair->key.len) == -1) return -1;
|
||||||
@ -617,7 +617,7 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, long_t v)
|
|||||||
|
|
||||||
ase_awk_refupval (this->run->run, x2);
|
ase_awk_refupval (this->run->run, x2);
|
||||||
|
|
||||||
ase_awk_pair_t* pair = ase_awk_map_put (
|
pair_t* pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)x)->map, idx, iln, x2);
|
((ase_awk_val_map_t*)x)->map, idx, iln, x2);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -637,7 +637,7 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, long_t v)
|
|||||||
|
|
||||||
ase_awk_refupval (this->run->run, x2);
|
ase_awk_refupval (this->run->run, x2);
|
||||||
|
|
||||||
ase_awk_pair_t* pair = ase_awk_map_put (
|
pair_t* pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)this->val)->map, idx, iln, x2);
|
((ase_awk_val_map_t*)this->val)->map, idx, iln, x2);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -678,7 +678,7 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, real_t v)
|
|||||||
|
|
||||||
ase_awk_refupval (this->run->run, x2);
|
ase_awk_refupval (this->run->run, x2);
|
||||||
|
|
||||||
ase_awk_pair_t* pair = ase_awk_map_put (
|
pair_t* pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)x)->map, idx, iln, x2);
|
((ase_awk_val_map_t*)x)->map, idx, iln, x2);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -698,7 +698,7 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, real_t v)
|
|||||||
|
|
||||||
ase_awk_refupval (this->run->run, x2);
|
ase_awk_refupval (this->run->run, x2);
|
||||||
|
|
||||||
ase_awk_pair_t* pair = ase_awk_map_put (
|
pair_t* pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)this->val)->map, idx, iln, x2);
|
((ase_awk_val_map_t*)this->val)->map, idx, iln, x2);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -739,7 +739,7 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, const char_t* str, s
|
|||||||
|
|
||||||
ase_awk_refupval (this->run->run, x2);
|
ase_awk_refupval (this->run->run, x2);
|
||||||
|
|
||||||
ase_awk_pair_t* pair = ase_awk_map_put (
|
pair_t* pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)x)->map, idx, iln, x2);
|
((ase_awk_val_map_t*)x)->map, idx, iln, x2);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -759,7 +759,7 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, const char_t* str, s
|
|||||||
|
|
||||||
ase_awk_refupval (this->run->run, x2);
|
ase_awk_refupval (this->run->run, x2);
|
||||||
|
|
||||||
ase_awk_pair_t* pair = ase_awk_map_put (
|
pair_t* pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)this->val)->map, idx, iln, x2);
|
((ase_awk_val_map_t*)this->val)->map, idx, iln, x2);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -1165,8 +1165,9 @@ int Awk::open ()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
functionMap = ase_awk_map_open (
|
functionMap = ase_map_open (
|
||||||
this, 512, 70, freeFunctionMapValue, ASE_NULL, awk);
|
this, 512, 70, freeFunctionMapValue, ASE_NULL,
|
||||||
|
ase_awk_getmmgr(awk));
|
||||||
if (functionMap == ASE_NULL)
|
if (functionMap == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_close (awk);
|
ase_awk_close (awk);
|
||||||
@ -1192,7 +1193,7 @@ void Awk::close ()
|
|||||||
{
|
{
|
||||||
if (functionMap != ASE_NULL)
|
if (functionMap != ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_map_close (functionMap);
|
ase_map_close (functionMap);
|
||||||
functionMap = ASE_NULL;
|
functionMap = ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1376,7 +1377,7 @@ int Awk::dispatchFunction (Run* run, const char_t* name, size_t len)
|
|||||||
|
|
||||||
//awk = ase_awk_getrunawk (run);
|
//awk = ase_awk_getrunawk (run);
|
||||||
|
|
||||||
pair = ase_awk_map_get (functionMap, name, len);
|
pair = ase_map_get (functionMap, name, len);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
run->setError (ERR_FNNONE, 0, name, len);
|
run->setError (ERR_FNNONE, 0, name, len);
|
||||||
@ -1384,7 +1385,7 @@ int Awk::dispatchFunction (Run* run, const char_t* name, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FunctionHandler handler;
|
FunctionHandler handler;
|
||||||
handler = *(FunctionHandler*)ASE_AWK_PAIR_VAL(pair);
|
handler = *(FunctionHandler*)ASE_PAIR_VAL(pair);
|
||||||
|
|
||||||
size_t i, nargs = ase_awk_getnargs(run->run);
|
size_t i, nargs = ase_awk_getnargs(run->run);
|
||||||
|
|
||||||
@ -1474,7 +1475,7 @@ int Awk::addFunction (
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair_t* pair = ase_awk_map_put (functionMap, name, nameLen, tmp);
|
pair_t* pair = ase_map_put (functionMap, name, nameLen, tmp);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_delfunc (awk, name, nameLen);
|
ase_awk_delfunc (awk, name, nameLen);
|
||||||
@ -1494,7 +1495,7 @@ int Awk::deleteFunction (const char_t* name)
|
|||||||
size_t nameLen = ase_strlen(name);
|
size_t nameLen = ase_strlen(name);
|
||||||
|
|
||||||
int n = ase_awk_delfunc (awk, name, nameLen);
|
int n = ase_awk_delfunc (awk, name, nameLen);
|
||||||
if (n == 0) ase_awk_map_remove (functionMap, name, nameLen);
|
if (n == 0) ase_map_remove (functionMap, name, nameLen);
|
||||||
else retrieveError ();
|
else retrieveError ();
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#define _ASE_AWK_AWK_HPP_
|
#define _ASE_AWK_AWK_HPP_
|
||||||
|
|
||||||
#include <ase/awk/awk.h>
|
#include <ase/awk/awk.h>
|
||||||
#include <ase/awk/map.h>
|
#include <ase/cmn/map.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
@ -35,12 +35,13 @@ public:
|
|||||||
typedef ase_long_t long_t;
|
typedef ase_long_t long_t;
|
||||||
/** Represents a floating-point number */
|
/** Represents a floating-point number */
|
||||||
typedef ase_real_t real_t;
|
typedef ase_real_t real_t;
|
||||||
|
/** Represents the internal hash table */
|
||||||
|
typedef ase_map_t map_t;
|
||||||
|
/** Represents a key/value pair */
|
||||||
|
typedef ase_pair_t pair_t;
|
||||||
|
|
||||||
/** Represents an internal awk value */
|
/** Represents an internal awk value */
|
||||||
typedef ase_awk_val_t val_t;
|
typedef ase_awk_val_t val_t;
|
||||||
/** Represents the internal hash table */
|
|
||||||
typedef ase_awk_map_t map_t;
|
|
||||||
/** Represents a key/value pair */
|
|
||||||
typedef ase_awk_pair_t pair_t;
|
|
||||||
/** Represents the external I/O context */
|
/** Represents the external I/O context */
|
||||||
typedef ase_awk_extio_t extio_t;
|
typedef ase_awk_extio_t extio_t;
|
||||||
/** Represents the run-time context */
|
/** Represents the run-time context */
|
||||||
|
@ -200,7 +200,6 @@
|
|||||||
<FILE FILENAME="err.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="err" FORMNAME="" DESIGNCLASS=""/>
|
<FILE FILENAME="err.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="err" FORMNAME="" DESIGNCLASS=""/>
|
||||||
<FILE FILENAME="extio.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="extio" FORMNAME="" DESIGNCLASS=""/>
|
<FILE FILENAME="extio.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="extio" FORMNAME="" DESIGNCLASS=""/>
|
||||||
<FILE FILENAME="func.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="func" FORMNAME="" DESIGNCLASS=""/>
|
<FILE FILENAME="func.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="func" FORMNAME="" DESIGNCLASS=""/>
|
||||||
<FILE FILENAME="map.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="map" FORMNAME="" DESIGNCLASS=""/>
|
|
||||||
<FILE FILENAME="misc.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="misc" FORMNAME="" DESIGNCLASS=""/>
|
<FILE FILENAME="misc.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="misc" FORMNAME="" DESIGNCLASS=""/>
|
||||||
<FILE FILENAME="parse.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="parse" FORMNAME="" DESIGNCLASS=""/>
|
<FILE FILENAME="parse.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="parse" FORMNAME="" DESIGNCLASS=""/>
|
||||||
<FILE FILENAME="rec.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="rec" FORMNAME="" DESIGNCLASS=""/>
|
<FILE FILENAME="rec.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="rec" FORMNAME="" DESIGNCLASS=""/>
|
||||||
|
@ -111,10 +111,6 @@ SOURCE=.\func.c
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\map.c
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=.\misc.c
|
SOURCE=.\misc.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
@ -167,10 +163,6 @@ SOURCE=.\func.h
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\map.h
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=.\parse.h
|
SOURCE=.\parse.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
@ -467,46 +467,6 @@
|
|||||||
/>
|
/>
|
||||||
</FileConfiguration>
|
</FileConfiguration>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="map.c"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
AdditionalIncludeDirectories=""
|
|
||||||
PreprocessorDefinitions=""
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|x64"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
AdditionalIncludeDirectories=""
|
|
||||||
PreprocessorDefinitions=""
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
AdditionalIncludeDirectories=""
|
|
||||||
PreprocessorDefinitions=""
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|x64"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
AdditionalIncludeDirectories=""
|
|
||||||
PreprocessorDefinitions=""
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="misc.c"
|
RelativePath="misc.c"
|
||||||
>
|
>
|
||||||
@ -848,10 +808,6 @@
|
|||||||
RelativePath="func.h"
|
RelativePath="func.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="map.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="parse.h"
|
RelativePath="parse.h"
|
||||||
>
|
>
|
||||||
|
135
ase/awk/awk.c
135
ase/awk/awk.c
@ -68,7 +68,8 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
|
|||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
awk->wtab = ase_awk_map_open (awk, 512, 70, free_word, ASE_NULL, awk);
|
awk->wtab = ase_map_open (
|
||||||
|
awk, 512, 70, free_word, ASE_NULL, &awk->prmfns.mmgr);
|
||||||
if (awk->wtab == ASE_NULL)
|
if (awk->wtab == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
@ -76,44 +77,48 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
|
|||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
awk->rwtab = ase_awk_map_open (awk, 512, 70, free_word, ASE_NULL, awk);
|
awk->rwtab = ase_map_open (
|
||||||
|
awk, 512, 70, free_word, ASE_NULL, &awk->prmfns.mmgr);
|
||||||
if (awk->rwtab == ASE_NULL)
|
if (awk->rwtab == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
ASE_AWK_FREE (awk, awk);
|
ASE_AWK_FREE (awk, awk);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: initial map size?? */
|
/* TODO: initial map size?? */
|
||||||
awk->tree.afns = ase_awk_map_open (awk, 512, 70, free_afn, ASE_NULL, awk);
|
awk->tree.afns = ase_map_open (
|
||||||
|
awk, 512, 70, free_afn, ASE_NULL, &awk->prmfns.mmgr);
|
||||||
if (awk->tree.afns == ASE_NULL)
|
if (awk->tree.afns == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_map_close (awk->rwtab);
|
ase_map_close (awk->rwtab);
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
ASE_AWK_FREE (awk, awk);
|
ASE_AWK_FREE (awk, awk);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
awk->parse.afns = ase_awk_map_open (awk, 256, 70, ASE_NULL, ASE_NULL, awk);
|
awk->parse.afns = ase_map_open (
|
||||||
|
awk, 256, 70, ASE_NULL, ASE_NULL, &awk->prmfns.mmgr);
|
||||||
if (awk->parse.afns == ASE_NULL)
|
if (awk->parse.afns == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_map_close (awk->tree.afns);
|
ase_map_close (awk->tree.afns);
|
||||||
ase_awk_map_close (awk->rwtab);
|
ase_map_close (awk->rwtab);
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
ASE_AWK_FREE (awk, awk);
|
ASE_AWK_FREE (awk, awk);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
awk->parse.named = ase_awk_map_open (awk, 256, 70, ASE_NULL, ASE_NULL, awk);
|
awk->parse.named = ase_map_open (
|
||||||
|
awk, 256, 70, ASE_NULL, ASE_NULL, &awk->prmfns.mmgr);
|
||||||
if (awk->parse.named == ASE_NULL)
|
if (awk->parse.named == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_map_close (awk->parse.afns);
|
ase_map_close (awk->parse.afns);
|
||||||
ase_awk_map_close (awk->tree.afns);
|
ase_map_close (awk->tree.afns);
|
||||||
ase_awk_map_close (awk->rwtab);
|
ase_map_close (awk->rwtab);
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
ASE_AWK_FREE (awk, awk);
|
ASE_AWK_FREE (awk, awk);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -121,11 +126,11 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
|
|||||||
|
|
||||||
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
|
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_map_close (awk->parse.named);
|
ase_map_close (awk->parse.named);
|
||||||
ase_awk_map_close (awk->parse.afns);
|
ase_map_close (awk->parse.afns);
|
||||||
ase_awk_map_close (awk->tree.afns);
|
ase_map_close (awk->tree.afns);
|
||||||
ase_awk_map_close (awk->rwtab);
|
ase_map_close (awk->rwtab);
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
ASE_AWK_FREE (awk, awk);
|
ASE_AWK_FREE (awk, awk);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -134,11 +139,11 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
|
|||||||
if (ase_awk_tab_open (&awk->parse.locals, awk) == ASE_NULL)
|
if (ase_awk_tab_open (&awk->parse.locals, awk) == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_tab_close (&awk->parse.globals);
|
ase_awk_tab_close (&awk->parse.globals);
|
||||||
ase_awk_map_close (awk->parse.named);
|
ase_map_close (awk->parse.named);
|
||||||
ase_awk_map_close (awk->parse.afns);
|
ase_map_close (awk->parse.afns);
|
||||||
ase_awk_map_close (awk->tree.afns);
|
ase_map_close (awk->tree.afns);
|
||||||
ase_awk_map_close (awk->rwtab);
|
ase_map_close (awk->rwtab);
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
ASE_AWK_FREE (awk, awk);
|
ASE_AWK_FREE (awk, awk);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -148,11 +153,11 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
|
|||||||
{
|
{
|
||||||
ase_awk_tab_close (&awk->parse.locals);
|
ase_awk_tab_close (&awk->parse.locals);
|
||||||
ase_awk_tab_close (&awk->parse.globals);
|
ase_awk_tab_close (&awk->parse.globals);
|
||||||
ase_awk_map_close (awk->parse.named);
|
ase_map_close (awk->parse.named);
|
||||||
ase_awk_map_close (awk->parse.afns);
|
ase_map_close (awk->parse.afns);
|
||||||
ase_awk_map_close (awk->tree.afns);
|
ase_map_close (awk->tree.afns);
|
||||||
ase_awk_map_close (awk->rwtab);
|
ase_map_close (awk->rwtab);
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
ASE_AWK_FREE (awk, awk);
|
ASE_AWK_FREE (awk, awk);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -191,17 +196,18 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
|
|||||||
|
|
||||||
awk->bfn.sys = ASE_NULL;
|
awk->bfn.sys = ASE_NULL;
|
||||||
/*awk->bfn.user = ASE_NULL;*/
|
/*awk->bfn.user = ASE_NULL;*/
|
||||||
awk->bfn.user = ase_awk_map_open (awk, 512, 70, free_bfn, ASE_NULL, awk);
|
awk->bfn.user = ase_map_open (
|
||||||
|
awk, 512, 70, free_bfn, ASE_NULL, &awk->prmfns.mmgr);
|
||||||
if (awk->bfn.user == ASE_NULL)
|
if (awk->bfn.user == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_tab_close (&awk->parse.params);
|
ase_awk_tab_close (&awk->parse.params);
|
||||||
ase_awk_tab_close (&awk->parse.locals);
|
ase_awk_tab_close (&awk->parse.locals);
|
||||||
ase_awk_tab_close (&awk->parse.globals);
|
ase_awk_tab_close (&awk->parse.globals);
|
||||||
ase_awk_map_close (awk->parse.named);
|
ase_map_close (awk->parse.named);
|
||||||
ase_awk_map_close (awk->parse.afns);
|
ase_map_close (awk->parse.afns);
|
||||||
ase_awk_map_close (awk->tree.afns);
|
ase_map_close (awk->tree.afns);
|
||||||
ase_awk_map_close (awk->rwtab);
|
ase_map_close (awk->rwtab);
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
ASE_AWK_FREE (awk, awk);
|
ASE_AWK_FREE (awk, awk);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -222,15 +228,15 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
|
|||||||
|
|
||||||
if (ase_awk_initglobals (awk) == -1)
|
if (ase_awk_initglobals (awk) == -1)
|
||||||
{
|
{
|
||||||
ase_awk_map_close (awk->bfn.user);
|
ase_map_close (awk->bfn.user);
|
||||||
ase_awk_tab_close (&awk->parse.params);
|
ase_awk_tab_close (&awk->parse.params);
|
||||||
ase_awk_tab_close (&awk->parse.locals);
|
ase_awk_tab_close (&awk->parse.locals);
|
||||||
ase_awk_tab_close (&awk->parse.globals);
|
ase_awk_tab_close (&awk->parse.globals);
|
||||||
ase_awk_map_close (awk->parse.named);
|
ase_map_close (awk->parse.named);
|
||||||
ase_awk_map_close (awk->parse.afns);
|
ase_map_close (awk->parse.afns);
|
||||||
ase_awk_map_close (awk->tree.afns);
|
ase_map_close (awk->tree.afns);
|
||||||
ase_awk_map_close (awk->rwtab);
|
ase_map_close (awk->rwtab);
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
ASE_AWK_FREE (awk, awk);
|
ASE_AWK_FREE (awk, awk);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -267,17 +273,17 @@ int ase_awk_close (ase_awk_t* awk)
|
|||||||
|
|
||||||
if (ase_awk_clear (awk) == -1) return -1;
|
if (ase_awk_clear (awk) == -1) return -1;
|
||||||
/*ase_awk_clrbfn (awk);*/
|
/*ase_awk_clrbfn (awk);*/
|
||||||
ase_awk_map_close (awk->bfn.user);
|
ase_map_close (awk->bfn.user);
|
||||||
|
|
||||||
ase_awk_tab_close (&awk->parse.params);
|
ase_awk_tab_close (&awk->parse.params);
|
||||||
ase_awk_tab_close (&awk->parse.locals);
|
ase_awk_tab_close (&awk->parse.locals);
|
||||||
ase_awk_tab_close (&awk->parse.globals);
|
ase_awk_tab_close (&awk->parse.globals);
|
||||||
ase_awk_map_close (awk->parse.named);
|
ase_map_close (awk->parse.named);
|
||||||
ase_awk_map_close (awk->parse.afns);
|
ase_map_close (awk->parse.afns);
|
||||||
|
|
||||||
ase_awk_map_close (awk->tree.afns);
|
ase_map_close (awk->tree.afns);
|
||||||
ase_awk_map_close (awk->rwtab);
|
ase_map_close (awk->rwtab);
|
||||||
ase_awk_map_close (awk->wtab);
|
ase_map_close (awk->wtab);
|
||||||
|
|
||||||
ase_str_close (&awk->token.name);
|
ase_str_close (&awk->token.name);
|
||||||
|
|
||||||
@ -316,8 +322,8 @@ int ase_awk_clear (ase_awk_t* awk)
|
|||||||
|
|
||||||
ase_awk_tab_clear (&awk->parse.locals);
|
ase_awk_tab_clear (&awk->parse.locals);
|
||||||
ase_awk_tab_clear (&awk->parse.params);
|
ase_awk_tab_clear (&awk->parse.params);
|
||||||
ase_awk_map_clear (awk->parse.named);
|
ase_map_clear (awk->parse.named);
|
||||||
ase_awk_map_clear (awk->parse.afns);
|
ase_map_clear (awk->parse.afns);
|
||||||
|
|
||||||
awk->parse.nlocals_max = 0;
|
awk->parse.nlocals_max = 0;
|
||||||
awk->parse.depth.cur.block = 0;
|
awk->parse.depth.cur.block = 0;
|
||||||
@ -332,7 +338,7 @@ int ase_awk_clear (ase_awk_t* awk)
|
|||||||
|
|
||||||
awk->tree.cur_afn.ptr = ASE_NULL;
|
awk->tree.cur_afn.ptr = ASE_NULL;
|
||||||
awk->tree.cur_afn.len = 0;
|
awk->tree.cur_afn.len = 0;
|
||||||
ase_awk_map_clear (awk->tree.afns);
|
ase_map_clear (awk->tree.afns);
|
||||||
|
|
||||||
if (awk->tree.begin != ASE_NULL)
|
if (awk->tree.begin != ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -379,6 +385,11 @@ void ase_awk_setoption (ase_awk_t* awk, int opt)
|
|||||||
awk->option = opt;
|
awk->option = opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ase_mmgr_t* ase_awk_getmmgr (ase_awk_t* awk)
|
||||||
|
{
|
||||||
|
return &awk->prmfns.mmgr;
|
||||||
|
}
|
||||||
|
|
||||||
void* ase_awk_getcustomdata (ase_awk_t* awk)
|
void* ase_awk_getcustomdata (ase_awk_t* awk)
|
||||||
{
|
{
|
||||||
return awk->custom_data;
|
return awk->custom_data;
|
||||||
@ -393,9 +404,9 @@ int ase_awk_getword (ase_awk_t* awk,
|
|||||||
const ase_char_t* okw, ase_size_t olen,
|
const ase_char_t* okw, ase_size_t olen,
|
||||||
const ase_char_t** nkw, ase_size_t* nlen)
|
const ase_char_t** nkw, ase_size_t* nlen)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* p;
|
ase_pair_t* p;
|
||||||
|
|
||||||
p = ase_awk_map_get (awk->wtab, okw, olen);
|
p = ase_map_get (awk->wtab, okw, olen);
|
||||||
if (p == ASE_NULL) return -1;
|
if (p == ASE_NULL) return -1;
|
||||||
|
|
||||||
*nkw = ((ase_cstr_t*)p->val)->ptr;
|
*nkw = ((ase_cstr_t*)p->val)->ptr;
|
||||||
@ -412,23 +423,23 @@ int ase_awk_setword (ase_awk_t* awk,
|
|||||||
|
|
||||||
if (nkw == ASE_NULL || nlen == 0)
|
if (nkw == ASE_NULL || nlen == 0)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* p;
|
ase_pair_t* p;
|
||||||
|
|
||||||
if (okw == ASE_NULL || olen == 0)
|
if (okw == ASE_NULL || olen == 0)
|
||||||
{
|
{
|
||||||
/* clear the entire table */
|
/* clear the entire table */
|
||||||
ase_awk_map_clear (awk->wtab);
|
ase_map_clear (awk->wtab);
|
||||||
ase_awk_map_clear (awk->rwtab);
|
ase_map_clear (awk->rwtab);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* delete the word */
|
/* delete the word */
|
||||||
p = ase_awk_map_get (awk->wtab, okw, olen);
|
p = ase_map_get (awk->wtab, okw, olen);
|
||||||
if (p != ASE_NULL)
|
if (p != ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_cstr_t* s = (ase_cstr_t*)p->val;
|
ase_cstr_t* s = (ase_cstr_t*)p->val;
|
||||||
ase_awk_map_remove (awk->rwtab, s->ptr, s->len);
|
ase_map_remove (awk->rwtab, s->ptr, s->len);
|
||||||
ase_awk_map_remove (awk->wtab, okw, olen);
|
ase_map_remove (awk->wtab, okw, olen);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -467,7 +478,7 @@ int ase_awk_setword (ase_awk_t* awk,
|
|||||||
vo->ptr = (const ase_char_t*)(vo + 1);
|
vo->ptr = (const ase_char_t*)(vo + 1);
|
||||||
ase_strncpy ((ase_char_t*)vo->ptr, okw, olen);
|
ase_strncpy ((ase_char_t*)vo->ptr, okw, olen);
|
||||||
|
|
||||||
if (ase_awk_map_put (awk->wtab, okw, olen, vn) == ASE_NULL)
|
if (ase_map_put (awk->wtab, okw, olen, vn) == ASE_NULL)
|
||||||
{
|
{
|
||||||
ASE_AWK_FREE (awk, vo);
|
ASE_AWK_FREE (awk, vo);
|
||||||
ASE_AWK_FREE (awk, vn);
|
ASE_AWK_FREE (awk, vn);
|
||||||
@ -475,9 +486,9 @@ int ase_awk_setword (ase_awk_t* awk,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ase_awk_map_put (awk->rwtab, nkw, nlen, vo) == ASE_NULL)
|
if (ase_map_put (awk->rwtab, nkw, nlen, vo) == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_map_remove (awk->wtab, okw, olen);
|
ase_map_remove (awk->wtab, okw, olen);
|
||||||
ASE_AWK_FREE (awk, vo);
|
ASE_AWK_FREE (awk, vo);
|
||||||
SETERR (awk, ASE_AWK_ENOMEM);
|
SETERR (awk, ASE_AWK_ENOMEM);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
|
|
||||||
#include <ase/cmn/types.h>
|
#include <ase/cmn/types.h>
|
||||||
#include <ase/cmn/macros.h>
|
#include <ase/cmn/macros.h>
|
||||||
|
#include <ase/cmn/map.h>
|
||||||
|
|
||||||
typedef struct ase_awk_t ase_awk_t;
|
typedef struct ase_awk_t ase_awk_t;
|
||||||
typedef struct ase_awk_run_t ase_awk_run_t;
|
typedef struct ase_awk_run_t ase_awk_run_t;
|
||||||
typedef struct ase_awk_val_t ase_awk_val_t;
|
typedef struct ase_awk_val_t ase_awk_val_t;
|
||||||
typedef struct ase_awk_map_t ase_awk_map_t;
|
|
||||||
typedef struct ase_awk_extio_t ase_awk_extio_t;
|
typedef struct ase_awk_extio_t ase_awk_extio_t;
|
||||||
|
|
||||||
typedef struct ase_awk_prmfns_t ase_awk_prmfns_t;
|
typedef struct ase_awk_prmfns_t ase_awk_prmfns_t;
|
||||||
@ -465,6 +465,7 @@ ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data);
|
|||||||
int ase_awk_close (ase_awk_t* awk);
|
int ase_awk_close (ase_awk_t* awk);
|
||||||
int ase_awk_clear (ase_awk_t* awk);
|
int ase_awk_clear (ase_awk_t* awk);
|
||||||
|
|
||||||
|
ase_mmgr_t* ase_awk_getmmgr (ase_awk_t* awk);
|
||||||
void* ase_awk_getcustomdata (ase_awk_t* awk);
|
void* ase_awk_getcustomdata (ase_awk_t* awk);
|
||||||
|
|
||||||
const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num);
|
const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num);
|
||||||
@ -617,7 +618,7 @@ int ase_awk_setofilename (
|
|||||||
|
|
||||||
ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* awk);
|
ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* awk);
|
||||||
void* ase_awk_getruncustomdata (ase_awk_run_t* awk);
|
void* ase_awk_getruncustomdata (ase_awk_run_t* awk);
|
||||||
ase_awk_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk);
|
ase_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk);
|
||||||
|
|
||||||
/* functions to manipulate the run-time error */
|
/* functions to manipulate the run-time error */
|
||||||
int ase_awk_getrunerrnum (ase_awk_run_t* run);
|
int ase_awk_getrunerrnum (ase_awk_run_t* run);
|
||||||
|
@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
#include <ase/cmn/mem.h>
|
#include <ase/cmn/mem.h>
|
||||||
#include <ase/cmn/str.h>
|
#include <ase/cmn/str.h>
|
||||||
|
#include <ase/cmn/map.h>
|
||||||
|
|
||||||
typedef struct ase_awk_chain_t ase_awk_chain_t;
|
typedef struct ase_awk_chain_t ase_awk_chain_t;
|
||||||
typedef struct ase_awk_tree_t ase_awk_tree_t;
|
typedef struct ase_awk_tree_t ase_awk_tree_t;
|
||||||
|
|
||||||
#include <ase/awk/awk.h>
|
#include <ase/awk/awk.h>
|
||||||
#include <ase/awk/rex.h>
|
#include <ase/awk/rex.h>
|
||||||
#include <ase/awk/map.h>
|
|
||||||
#include <ase/awk/tree.h>
|
#include <ase/awk/tree.h>
|
||||||
#include <ase/awk/val.h>
|
#include <ase/awk/val.h>
|
||||||
#include <ase/awk/func.h>
|
#include <ase/awk/func.h>
|
||||||
@ -57,7 +57,7 @@ struct ase_awk_tree_t
|
|||||||
ase_size_t nglobals; /* total number of globals */
|
ase_size_t nglobals; /* total number of globals */
|
||||||
ase_size_t nbglobals; /* number of intrinsic globals */
|
ase_size_t nbglobals; /* number of intrinsic globals */
|
||||||
ase_cstr_t cur_afn;
|
ase_cstr_t cur_afn;
|
||||||
ase_awk_map_t* afns; /* awk function map */
|
ase_map_t* afns; /* awk function map */
|
||||||
|
|
||||||
ase_awk_nde_t* begin;
|
ase_awk_nde_t* begin;
|
||||||
ase_awk_nde_t* begin_tail;
|
ase_awk_nde_t* begin_tail;
|
||||||
@ -81,9 +81,9 @@ struct ase_awk_t
|
|||||||
int option;
|
int option;
|
||||||
|
|
||||||
/* word table */
|
/* word table */
|
||||||
ase_awk_map_t* wtab;
|
ase_map_t* wtab;
|
||||||
/* reverse word table */
|
/* reverse word table */
|
||||||
ase_awk_map_t* rwtab;
|
ase_map_t* rwtab;
|
||||||
|
|
||||||
/* regular expression processing routines */
|
/* regular expression processing routines */
|
||||||
ase_awk_rexfns_t* rexfns;
|
ase_awk_rexfns_t* rexfns;
|
||||||
@ -118,10 +118,10 @@ struct ase_awk_t
|
|||||||
} depth;
|
} depth;
|
||||||
|
|
||||||
/* function calls */
|
/* function calls */
|
||||||
ase_awk_map_t* afns;
|
ase_map_t* afns;
|
||||||
|
|
||||||
/* named variables */
|
/* named variables */
|
||||||
ase_awk_map_t* named;
|
ase_map_t* named;
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
ase_awk_tab_t globals;
|
ase_awk_tab_t globals;
|
||||||
@ -185,7 +185,7 @@ struct ase_awk_t
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
ase_awk_bfn_t* sys;
|
ase_awk_bfn_t* sys;
|
||||||
ase_awk_map_t* user;
|
ase_map_t* user;
|
||||||
} bfn;
|
} bfn;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
@ -236,7 +236,7 @@ struct ase_awk_chain_t
|
|||||||
struct ase_awk_run_t
|
struct ase_awk_run_t
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
ase_awk_map_t* named;
|
ase_map_t* named;
|
||||||
|
|
||||||
void** stack;
|
void** stack;
|
||||||
ase_size_t stack_top;
|
ase_size_t stack_top;
|
||||||
|
@ -98,7 +98,7 @@ void* ase_awk_addfunc (
|
|||||||
|
|
||||||
bfn->handler = handler;
|
bfn->handler = handler;
|
||||||
|
|
||||||
if (ase_awk_map_put (awk->bfn.user, name, name_len, bfn) == ASE_NULL)
|
if (ase_map_put (awk->bfn.user, name, name_len, bfn) == ASE_NULL)
|
||||||
{
|
{
|
||||||
ASE_AWK_FREE (awk, bfn);
|
ASE_AWK_FREE (awk, bfn);
|
||||||
ase_awk_seterrnum (awk, ASE_AWK_ENOMEM);
|
ase_awk_seterrnum (awk, ASE_AWK_ENOMEM);
|
||||||
@ -111,7 +111,7 @@ void* ase_awk_addfunc (
|
|||||||
int ase_awk_delfunc (
|
int ase_awk_delfunc (
|
||||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len)
|
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len)
|
||||||
{
|
{
|
||||||
if (ase_awk_map_remove (awk->bfn.user, name, name_len) == -1)
|
if (ase_map_remove (awk->bfn.user, name, name_len) == -1)
|
||||||
{
|
{
|
||||||
ase_cstr_t errarg;
|
ase_cstr_t errarg;
|
||||||
|
|
||||||
@ -127,14 +127,14 @@ int ase_awk_delfunc (
|
|||||||
|
|
||||||
void ase_awk_clrbfn (ase_awk_t* awk)
|
void ase_awk_clrbfn (ase_awk_t* awk)
|
||||||
{
|
{
|
||||||
ase_awk_map_clear (awk->bfn.user);
|
ase_map_clear (awk->bfn.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_bfn_t* ase_awk_getbfn (
|
ase_awk_bfn_t* ase_awk_getbfn (
|
||||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
|
ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
|
||||||
{
|
{
|
||||||
ase_awk_bfn_t* bfn;
|
ase_awk_bfn_t* bfn;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
const ase_char_t* k;
|
const ase_char_t* k;
|
||||||
ase_size_t l;
|
ase_size_t l;
|
||||||
|
|
||||||
@ -144,8 +144,7 @@ ase_awk_bfn_t* ase_awk_getbfn (
|
|||||||
if (bfn->valid != 0 &&
|
if (bfn->valid != 0 &&
|
||||||
(awk->option & bfn->valid) != bfn->valid) continue;
|
(awk->option & bfn->valid) != bfn->valid) continue;
|
||||||
|
|
||||||
pair = ase_awk_map_get (
|
pair = ase_map_get (awk->wtab, bfn->name.ptr, bfn->name.len);
|
||||||
awk->wtab, bfn->name.ptr, bfn->name.len);
|
|
||||||
if (pair != ASE_NULL)
|
if (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
/* found in the customized word table */
|
/* found in the customized word table */
|
||||||
@ -165,7 +164,7 @@ ase_awk_bfn_t* ase_awk_getbfn (
|
|||||||
* because I'm trying to support ase_awk_setword in
|
* because I'm trying to support ase_awk_setword in
|
||||||
* a very flimsy way here. Would it be better to drop
|
* a very flimsy way here. Would it be better to drop
|
||||||
* ase_awk_setword totally? */
|
* ase_awk_setword totally? */
|
||||||
pair = ase_awk_map_get (awk->rwtab, name, len);
|
pair = ase_map_get (awk->rwtab, name, len);
|
||||||
if (pair != ASE_NULL)
|
if (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
/* the current name is a target name for
|
/* the current name is a target name for
|
||||||
@ -175,7 +174,7 @@ ase_awk_bfn_t* ase_awk_getbfn (
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pair = ase_awk_map_get (awk->wtab, name, len);
|
pair = ase_map_get (awk->wtab, name, len);
|
||||||
if (pair != ASE_NULL)
|
if (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
k = ((ase_cstr_t*)(pair->val))->ptr;
|
k = ((ase_cstr_t*)(pair->val))->ptr;
|
||||||
@ -203,7 +202,7 @@ ase_awk_bfn_t* ase_awk_getbfn (
|
|||||||
}
|
}
|
||||||
/* END NOTE */
|
/* END NOTE */
|
||||||
|
|
||||||
pair = ase_awk_map_get (awk->bfn.user, k, l);
|
pair = ase_map_get (awk->bfn.user, k, l);
|
||||||
if (pair == ASE_NULL) return ASE_NULL;
|
if (pair == ASE_NULL) return ASE_NULL;
|
||||||
|
|
||||||
bfn = (ase_awk_bfn_t*)pair->val;
|
bfn = (ase_awk_bfn_t*)pair->val;
|
||||||
@ -797,7 +796,7 @@ static int bfn_split (
|
|||||||
* it is decremented if the assignement fails. */
|
* it is decremented if the assignement fails. */
|
||||||
ase_awk_refupval (run, t2);
|
ase_awk_refupval (run, t2);
|
||||||
|
|
||||||
if (ase_awk_map_putx (
|
if (ase_map_putx (
|
||||||
((ase_awk_val_map_t*)t1)->map,
|
((ase_awk_val_map_t*)t1)->map,
|
||||||
key, key_len, t2, ASE_NULL) == -1)
|
key, key_len, t2, ASE_NULL) == -1)
|
||||||
{
|
{
|
||||||
|
@ -2407,7 +2407,7 @@ JNIEXPORT jobject JNICALL Java_ase_awk_Argument_getindexed (JNIEnv* env, jobject
|
|||||||
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
ase_awk_val_t* val = (ase_awk_val_t*)valid;
|
||||||
ase_awk_t* awk = ase_awk_getrunawk (run);
|
ase_awk_t* awk = ase_awk_getrunawk (run);
|
||||||
run_data_t* run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
run_data_t* run_data = (run_data_t*)ase_awk_getruncustomdata (run);
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
jobject arg;
|
jobject arg;
|
||||||
|
|
||||||
const jchar* ptr;
|
const jchar* ptr;
|
||||||
@ -2433,7 +2433,7 @@ JNIEXPORT jobject JNICALL Java_ase_awk_Argument_getindexed (JNIEnv* env, jobject
|
|||||||
}
|
}
|
||||||
else rptr = (ase_char_t*)ptr;
|
else rptr = (ase_char_t*)ptr;
|
||||||
|
|
||||||
pair = ase_awk_map_get (((ase_awk_val_map_t*)val)->map, rptr, len);
|
pair = ase_map_get (((ase_awk_val_map_t*)val)->map, rptr, len);
|
||||||
if (ptr != rptr) ase_awk_free (awk, rptr);
|
if (ptr != rptr) ase_awk_free (awk, rptr);
|
||||||
(*env)->ReleaseStringChars (env, index, ptr);
|
(*env)->ReleaseStringChars (env, index, ptr);
|
||||||
|
|
||||||
@ -2593,7 +2593,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedintval (JNIEnv* env, jobjec
|
|||||||
{
|
{
|
||||||
ase_awk_val_t* x;
|
ase_awk_val_t* x;
|
||||||
ase_awk_val_t* x2;
|
ase_awk_val_t* x2;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
x = ase_awk_makemapval (run);
|
x = ase_awk_makemapval (run);
|
||||||
if (x == ASE_NULL)
|
if (x == ASE_NULL)
|
||||||
@ -2622,7 +2622,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedintval (JNIEnv* env, jobjec
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair = ase_awk_map_put (
|
pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)x)->map, aptr, len, x2);
|
((ase_awk_val_map_t*)x)->map, aptr, len, x2);
|
||||||
free_str (env, awk, index, jptr, aptr);
|
free_str (env, awk, index, jptr, aptr);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
@ -2639,7 +2639,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedintval (JNIEnv* env, jobjec
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ase_awk_val_t* x2;
|
ase_awk_val_t* x2;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
x2 = ase_awk_makeintval (run, newval);
|
x2 = ase_awk_makeintval (run, newval);
|
||||||
if (x2 == ASE_NULL)
|
if (x2 == ASE_NULL)
|
||||||
@ -2656,7 +2656,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedintval (JNIEnv* env, jobjec
|
|||||||
THROW_NOMEM_EXCEPTION (env);
|
THROW_NOMEM_EXCEPTION (env);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pair = ase_awk_map_put (
|
pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)val)->map, aptr, len, x2);
|
((ase_awk_val_map_t*)val)->map, aptr, len, x2);
|
||||||
free_str (env, awk, index, jptr, aptr);
|
free_str (env, awk, index, jptr, aptr);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
@ -2696,7 +2696,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedrealval (JNIEnv* env, jobje
|
|||||||
{
|
{
|
||||||
ase_awk_val_t* x;
|
ase_awk_val_t* x;
|
||||||
ase_awk_val_t* x2;
|
ase_awk_val_t* x2;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
x = ase_awk_makemapval (run);
|
x = ase_awk_makemapval (run);
|
||||||
if (x == ASE_NULL)
|
if (x == ASE_NULL)
|
||||||
@ -2725,7 +2725,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedrealval (JNIEnv* env, jobje
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair = ase_awk_map_put (
|
pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)x)->map, aptr, len, x2);
|
((ase_awk_val_map_t*)x)->map, aptr, len, x2);
|
||||||
free_str (env, awk, index, jptr, aptr);
|
free_str (env, awk, index, jptr, aptr);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
@ -2742,7 +2742,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedrealval (JNIEnv* env, jobje
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ase_awk_val_t* x2;
|
ase_awk_val_t* x2;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
x2 = ase_awk_makerealval (run, newval);
|
x2 = ase_awk_makerealval (run, newval);
|
||||||
if (x2 == ASE_NULL)
|
if (x2 == ASE_NULL)
|
||||||
@ -2759,7 +2759,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedrealval (JNIEnv* env, jobje
|
|||||||
THROW_NOMEM_EXCEPTION (env);
|
THROW_NOMEM_EXCEPTION (env);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pair = ase_awk_map_put (
|
pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)val)->map, aptr, len, x2);
|
((ase_awk_val_map_t*)val)->map, aptr, len, x2);
|
||||||
free_str (env, awk, index, jptr, aptr);
|
free_str (env, awk, index, jptr, aptr);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
@ -2799,7 +2799,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedstrval (JNIEnv* env, jobjec
|
|||||||
{
|
{
|
||||||
ase_awk_val_t* x;
|
ase_awk_val_t* x;
|
||||||
ase_awk_val_t* x2;
|
ase_awk_val_t* x2;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
x = ase_awk_makemapval (run);
|
x = ase_awk_makemapval (run);
|
||||||
if (x == ASE_NULL)
|
if (x == ASE_NULL)
|
||||||
@ -2834,7 +2834,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedstrval (JNIEnv* env, jobjec
|
|||||||
THROW_NOMEM_EXCEPTION (env);
|
THROW_NOMEM_EXCEPTION (env);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pair = ase_awk_map_put (
|
pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)x)->map, aptr, len, x2);
|
((ase_awk_val_map_t*)x)->map, aptr, len, x2);
|
||||||
free_str (env, awk, index, jptr, aptr);
|
free_str (env, awk, index, jptr, aptr);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
@ -2851,7 +2851,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedstrval (JNIEnv* env, jobjec
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ase_awk_val_t* x2;
|
ase_awk_val_t* x2;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
if (get_str(env,awk,newval,&jptr,&aptr,&len) == -1)
|
if (get_str(env,awk,newval,&jptr,&aptr,&len) == -1)
|
||||||
{
|
{
|
||||||
@ -2874,7 +2874,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Return_setindexedstrval (JNIEnv* env, jobjec
|
|||||||
THROW_NOMEM_EXCEPTION (env);
|
THROW_NOMEM_EXCEPTION (env);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pair = ase_awk_map_put (
|
pair = ase_map_put (
|
||||||
((ase_awk_val_map_t*)val)->map, aptr, len, x2);
|
((ase_awk_val_map_t*)val)->map, aptr, len, x2);
|
||||||
free_str (env, awk, index, jptr, aptr);
|
free_str (env, awk, index, jptr, aptr);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
|
@ -45,7 +45,6 @@ OBJ_FILES_LIB = \
|
|||||||
$(TMP_DIR)/err.o \
|
$(TMP_DIR)/err.o \
|
||||||
$(TMP_DIR)/tree.o \
|
$(TMP_DIR)/tree.o \
|
||||||
$(TMP_DIR)/tab.o \
|
$(TMP_DIR)/tab.o \
|
||||||
$(TMP_DIR)/map.o \
|
|
||||||
$(TMP_DIR)/parse.o \
|
$(TMP_DIR)/parse.o \
|
||||||
$(TMP_DIR)/run.o \
|
$(TMP_DIR)/run.o \
|
||||||
$(TMP_DIR)/rec.o \
|
$(TMP_DIR)/rec.o \
|
||||||
@ -129,9 +128,6 @@ $(TMP_DIR)/tree.o: tree.c
|
|||||||
$(TMP_DIR)/tab.o: tab.c
|
$(TMP_DIR)/tab.o: tab.c
|
||||||
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c tab.c
|
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c tab.c
|
||||||
|
|
||||||
$(TMP_DIR)/map.o: map.c
|
|
||||||
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c map.c
|
|
||||||
|
|
||||||
$(TMP_DIR)/parse.o: parse.c
|
$(TMP_DIR)/parse.o: parse.c
|
||||||
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c parse.c
|
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c parse.c
|
||||||
|
|
||||||
|
112
ase/awk/map.h
112
ase/awk/map.h
@ -1,112 +0,0 @@
|
|||||||
/*
|
|
||||||
* $Id: map.h,v 1.8 2007/09/30 15:12:20 bacon Exp $
|
|
||||||
*
|
|
||||||
* {License}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ASE_AWK_MAP_H_
|
|
||||||
#define _ASE_AWK_MAP_H_
|
|
||||||
|
|
||||||
#ifndef _ASE_AWK_AWK_H_
|
|
||||||
#error Include <ase/awk/awk.h> first
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*typedef struct ase_awk_map_t ase_awk_map_t;*/
|
|
||||||
typedef struct ase_awk_pair_t ase_awk_pair_t;
|
|
||||||
|
|
||||||
struct ase_awk_pair_t
|
|
||||||
{
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
ase_char_t* ptr;
|
|
||||||
ase_size_t len;
|
|
||||||
} key;
|
|
||||||
|
|
||||||
void* val;
|
|
||||||
|
|
||||||
/* used internally */
|
|
||||||
ase_awk_pair_t* next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ase_awk_map_t
|
|
||||||
{
|
|
||||||
void* owner;
|
|
||||||
ase_size_t size;
|
|
||||||
ase_size_t capa;
|
|
||||||
unsigned int factor;
|
|
||||||
ase_size_t threshold;
|
|
||||||
ase_awk_pair_t** buck;
|
|
||||||
void (*freeval) (void*,void*);
|
|
||||||
void (*sameval) (void*,void*);
|
|
||||||
ase_awk_t* awk;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define ASE_AWK_PAIR_KEYPTR(p) ((p)->key.ptr)
|
|
||||||
#define ASE_AWK_PAIR_KEYLEN(p) ((p)->key.len)
|
|
||||||
#define ASE_AWK_PAIR_VAL(p) ((p)->val)
|
|
||||||
#define ASE_AWK_PAIR_LNK(p) ((p)->next)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ase_awk_map_t* ase_awk_map_open (
|
|
||||||
void* owner, ase_size_t capa, unsigned int factor,
|
|
||||||
void(*freeval)(void*,void*), void(*sameval)(void*,void*),
|
|
||||||
ase_awk_t* awk);
|
|
||||||
|
|
||||||
void ase_awk_map_close (ase_awk_map_t* map);
|
|
||||||
|
|
||||||
void ase_awk_map_clear (ase_awk_map_t* map);
|
|
||||||
|
|
||||||
ase_size_t ase_awk_map_getsize (ase_awk_map_t* map);
|
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_get (
|
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen);
|
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_put (
|
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
|
||||||
void* val);
|
|
||||||
|
|
||||||
int ase_awk_map_putx (
|
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
|
||||||
void* val, ase_awk_pair_t** px);
|
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_set (
|
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
|
||||||
void* val);
|
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_getpair (
|
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
|
||||||
void** val);
|
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_setpair (
|
|
||||||
ase_awk_map_t* map, ase_awk_pair_t* pair, void* val);
|
|
||||||
|
|
||||||
int ase_awk_map_remove (
|
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen);
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
#endif
|
|
@ -50,7 +50,6 @@ OBJ_FILES_LIB = \
|
|||||||
$(TMP_DIR)\err.obj \
|
$(TMP_DIR)\err.obj \
|
||||||
$(TMP_DIR)\tree.obj \
|
$(TMP_DIR)\tree.obj \
|
||||||
$(TMP_DIR)\tab.obj \
|
$(TMP_DIR)\tab.obj \
|
||||||
$(TMP_DIR)\map.obj \
|
|
||||||
$(TMP_DIR)\parse.obj \
|
$(TMP_DIR)\parse.obj \
|
||||||
$(TMP_DIR)\run.obj \
|
$(TMP_DIR)\run.obj \
|
||||||
$(TMP_DIR)\rec.obj \
|
$(TMP_DIR)\rec.obj \
|
||||||
@ -124,9 +123,6 @@ $(TMP_DIR)\tree.obj: tree.c
|
|||||||
$(TMP_DIR)\tab.obj: tab.c
|
$(TMP_DIR)\tab.obj: tab.c
|
||||||
$(CC) $(CFLAGS) -o$@ -c tab.c
|
$(CC) $(CFLAGS) -o$@ -c tab.c
|
||||||
|
|
||||||
$(TMP_DIR)\map.obj: map.c
|
|
||||||
$(CC) $(CFLAGS) -o$@ -c map.c
|
|
||||||
|
|
||||||
$(TMP_DIR)\parse.obj: parse.c
|
$(TMP_DIR)\parse.obj: parse.c
|
||||||
$(CC) $(CFLAGS) -o$@ -c parse.c
|
$(CC) $(CFLAGS) -o$@ -c parse.c
|
||||||
|
|
||||||
|
@ -50,7 +50,6 @@ OBJ_FILES_LIB = \
|
|||||||
$(TMP_DIR)\err.obj \
|
$(TMP_DIR)\err.obj \
|
||||||
$(TMP_DIR)\tree.obj \
|
$(TMP_DIR)\tree.obj \
|
||||||
$(TMP_DIR)\tab.obj \
|
$(TMP_DIR)\tab.obj \
|
||||||
$(TMP_DIR)\map.obj \
|
|
||||||
$(TMP_DIR)\parse.obj \
|
$(TMP_DIR)\parse.obj \
|
||||||
$(TMP_DIR)\run.obj \
|
$(TMP_DIR)\run.obj \
|
||||||
$(TMP_DIR)\rec.obj \
|
$(TMP_DIR)\rec.obj \
|
||||||
@ -134,9 +133,6 @@ $(TMP_DIR)\tree.obj: tree.c
|
|||||||
$(TMP_DIR)\tab.obj: tab.c
|
$(TMP_DIR)\tab.obj: tab.c
|
||||||
$(CC) $(CFLAGS) /Fo$@ /c tab.c
|
$(CC) $(CFLAGS) /Fo$@ /c tab.c
|
||||||
|
|
||||||
$(TMP_DIR)\map.obj: map.c
|
|
||||||
$(CC) $(CFLAGS) /Fo$@ /c map.c
|
|
||||||
|
|
||||||
$(TMP_DIR)\parse.obj: parse.c
|
$(TMP_DIR)\parse.obj: parse.c
|
||||||
$(CC) $(CFLAGS) /Fo$@ /c parse.c
|
$(CC) $(CFLAGS) /Fo$@ /c parse.c
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ OBJ_FILES_LIB = \
|
|||||||
$(TMP_DIR)\err.obj \
|
$(TMP_DIR)\err.obj \
|
||||||
$(TMP_DIR)\tree.obj \
|
$(TMP_DIR)\tree.obj \
|
||||||
$(TMP_DIR)\tab.obj \
|
$(TMP_DIR)\tab.obj \
|
||||||
$(TMP_DIR)\map.obj \
|
|
||||||
$(TMP_DIR)\parse.obj \
|
$(TMP_DIR)\parse.obj \
|
||||||
$(TMP_DIR)\run.obj \
|
$(TMP_DIR)\run.obj \
|
||||||
$(TMP_DIR)\rec.obj \
|
$(TMP_DIR)\rec.obj \
|
||||||
@ -81,9 +80,6 @@ $(TMP_DIR)\tree.obj: tree.c
|
|||||||
$(TMP_DIR)\tab.obj: tab.c
|
$(TMP_DIR)\tab.obj: tab.c
|
||||||
$(CC) $(CFLAGS) -o$@ -c tab.c
|
$(CC) $(CFLAGS) -o$@ -c tab.c
|
||||||
|
|
||||||
$(TMP_DIR)\map.obj: map.c
|
|
||||||
$(CC) $(CFLAGS) -o$@ -c map.c
|
|
||||||
|
|
||||||
$(TMP_DIR)\parse.obj: parse.c
|
$(TMP_DIR)\parse.obj: parse.c
|
||||||
$(CC) $(CFLAGS) -o$@ -c parse.c
|
$(CC) $(CFLAGS) -o$@ -c parse.c
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ static int is_plain_var (ase_awk_nde_t* nde);
|
|||||||
static int is_var (ase_awk_nde_t* nde);
|
static int is_var (ase_awk_nde_t* nde);
|
||||||
|
|
||||||
static int deparse (ase_awk_t* awk);
|
static int deparse (ase_awk_t* awk);
|
||||||
static int deparse_func (ase_awk_pair_t* pair, void* arg);
|
static int deparse_func (ase_pair_t* pair, void* arg);
|
||||||
static int put_char (ase_awk_t* awk, ase_char_t c);
|
static int put_char (ase_awk_t* awk, ase_char_t c);
|
||||||
static int flush_out (ase_awk_t* awk);
|
static int flush_out (ase_awk_t* awk);
|
||||||
|
|
||||||
@ -443,11 +443,11 @@ const ase_char_t* ase_awk_getglobalname (
|
|||||||
|
|
||||||
const ase_char_t* ase_awk_getkw (ase_awk_t* awk, const ase_char_t* kw)
|
const ase_char_t* ase_awk_getkw (ase_awk_t* awk, const ase_char_t* kw)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* p;
|
ase_pair_t* p;
|
||||||
|
|
||||||
ASE_ASSERT (kw != ASE_NULL);
|
ASE_ASSERT (kw != ASE_NULL);
|
||||||
|
|
||||||
p = ase_awk_map_get (awk->wtab, kw, ase_strlen(kw));
|
p = ase_map_get (awk->wtab, kw, ase_strlen(kw));
|
||||||
if (p != ASE_NULL) return ((ase_cstr_t*)p->val)->ptr;
|
if (p != ASE_NULL) return ((ase_cstr_t*)p->val)->ptr;
|
||||||
|
|
||||||
return kw;
|
return kw;
|
||||||
@ -529,13 +529,13 @@ static int parse (ase_awk_t* awk)
|
|||||||
if ((awk->option & ASE_AWK_EXPLICIT) &&
|
if ((awk->option & ASE_AWK_EXPLICIT) &&
|
||||||
!(awk->option & ASE_AWK_IMPLICIT))
|
!(awk->option & ASE_AWK_IMPLICIT))
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* p;
|
ase_pair_t* p;
|
||||||
ase_size_t buckno;
|
ase_size_t buckno;
|
||||||
|
|
||||||
p = ase_awk_map_getfirstpair (awk->parse.afns, &buckno);
|
p = ase_map_getfirstpair (awk->parse.afns, &buckno);
|
||||||
while (p != ASE_NULL)
|
while (p != ASE_NULL)
|
||||||
{
|
{
|
||||||
if (ase_awk_map_get (awk->tree.afns,
|
if (ase_map_get (awk->tree.afns,
|
||||||
p->key.ptr, p->key.len) == ASE_NULL)
|
p->key.ptr, p->key.len) == ASE_NULL)
|
||||||
{
|
{
|
||||||
/* TODO: set better error no & line */
|
/* TODO: set better error no & line */
|
||||||
@ -548,7 +548,7 @@ static int parse (ase_awk_t* awk)
|
|||||||
goto exit_parse;
|
goto exit_parse;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = ase_awk_map_getnextpair (awk->parse.afns, p, &buckno);
|
p = ase_map_getnextpair (awk->parse.afns, p, &buckno);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -814,7 +814,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
|||||||
ase_awk_nde_t* body;
|
ase_awk_nde_t* body;
|
||||||
ase_awk_afn_t* afn;
|
ase_awk_afn_t* afn;
|
||||||
ase_size_t nargs, g;
|
ase_size_t nargs, g;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
/* eat up the keyword 'function' and get the next token */
|
/* eat up the keyword 'function' and get the next token */
|
||||||
@ -839,7 +839,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
|||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ase_awk_map_get(awk->tree.afns, name, name_len) != ASE_NULL)
|
if (ase_map_get(awk->tree.afns, name, name_len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
/* the function is defined previously */
|
/* the function is defined previously */
|
||||||
SETERRARG (
|
SETERRARG (
|
||||||
@ -934,7 +934,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
|||||||
/* check if a parameter conflicts with a function
|
/* check if a parameter conflicts with a function
|
||||||
* function f (f) { print f; } */
|
* function f (f) { print f; } */
|
||||||
if (ase_strxncmp (name_dup, name_len, param, param_len) == 0 ||
|
if (ase_strxncmp (name_dup, name_len, param, param_len) == 0 ||
|
||||||
ase_awk_map_get (awk->tree.afns, param, param_len) != ASE_NULL)
|
ase_map_get (awk->tree.afns, param, param_len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
ASE_AWK_FREE (awk, name_dup);
|
ASE_AWK_FREE (awk, name_dup);
|
||||||
ase_awk_tab_clear (&awk->parse.params);
|
ase_awk_tab_clear (&awk->parse.params);
|
||||||
@ -1081,7 +1081,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
|||||||
afn->nargs = nargs;
|
afn->nargs = nargs;
|
||||||
afn->body = body;
|
afn->body = body;
|
||||||
|
|
||||||
n = ase_awk_map_putx (awk->tree.afns, name_dup, name_len, afn, &pair);
|
n = ase_map_putx (awk->tree.afns, name_dup, name_len, afn, &pair);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
ASE_AWK_FREE (awk, name_dup);
|
ASE_AWK_FREE (awk, name_dup);
|
||||||
@ -1095,12 +1095,12 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
|||||||
/* duplicate functions should have been detected previously */
|
/* duplicate functions should have been detected previously */
|
||||||
ASE_ASSERT (n != 0);
|
ASE_ASSERT (n != 0);
|
||||||
|
|
||||||
afn->name = ASE_AWK_PAIR_KEYPTR(pair); /* do some trick to save a string. */
|
afn->name = ASE_PAIR_KEYPTR(pair); /* do some trick to save a string. */
|
||||||
afn->name_len = ASE_AWK_PAIR_KEYLEN(pair);
|
afn->name_len = ASE_PAIR_KEYLEN(pair);
|
||||||
ASE_AWK_FREE (awk, name_dup);
|
ASE_AWK_FREE (awk, name_dup);
|
||||||
|
|
||||||
/* remove the undefined function call entries from parse.afn table */
|
/* remove the undefined function call entries from parse.afn table */
|
||||||
ase_awk_map_remove (awk->parse.afns, afn->name, name_len);
|
ase_map_remove (awk->parse.afns, afn->name, name_len);
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1418,9 +1418,9 @@ static void trans_global (
|
|||||||
*/
|
*/
|
||||||
if (index < awk->tree.nbglobals)
|
if (index < awk->tree.nbglobals)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
pair = ase_awk_map_get (awk->wtab, word->ptr, word->len);
|
pair = ase_map_get (awk->wtab, word->ptr, word->len);
|
||||||
if (pair != ASE_NULL)
|
if (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
word->ptr = ((ase_cstr_t*)(pair->val))->ptr;
|
word->ptr = ((ase_cstr_t*)(pair->val))->ptr;
|
||||||
@ -1465,7 +1465,7 @@ static int add_global (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if it conflict with a function name */
|
/* check if it conflict with a function name */
|
||||||
if (ase_awk_map_get (awk->tree.afns, name, len) != ASE_NULL)
|
if (ase_map_get (awk->tree.afns, name, len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
SETERRARG (
|
SETERRARG (
|
||||||
awk, ASE_AWK_EAFNRED, line,
|
awk, ASE_AWK_EAFNRED, line,
|
||||||
@ -1475,7 +1475,7 @@ static int add_global (
|
|||||||
|
|
||||||
/* check if it conflict with a function name
|
/* check if it conflict with a function name
|
||||||
* caught in the function call table */
|
* caught in the function call table */
|
||||||
if (ase_awk_map_get (awk->parse.afns, name, len) != ASE_NULL)
|
if (ase_map_get (awk->parse.afns, name, len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
SETERRARG (
|
SETERRARG (
|
||||||
awk, ASE_AWK_EAFNRED, line,
|
awk, ASE_AWK_EAFNRED, line,
|
||||||
@ -1655,7 +1655,7 @@ static ase_awk_t* collect_locals (
|
|||||||
local, local_len) == 0);
|
local, local_len) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscur || ase_awk_map_get (awk->tree.afns, local, local_len) != ASE_NULL)
|
if (iscur || ase_map_get (awk->tree.afns, local, local_len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
SETERRARG (
|
SETERRARG (
|
||||||
awk, ASE_AWK_EAFNRED, awk->token.line,
|
awk, ASE_AWK_EAFNRED, awk->token.line,
|
||||||
@ -1665,7 +1665,7 @@ static ase_awk_t* collect_locals (
|
|||||||
|
|
||||||
/* check if it conflict with a function name
|
/* check if it conflict with a function name
|
||||||
* caught in the function call table */
|
* caught in the function call table */
|
||||||
if (ase_awk_map_get (awk->parse.afns, local, local_len) != ASE_NULL)
|
if (ase_map_get (awk->parse.afns, local, local_len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
SETERRARG (
|
SETERRARG (
|
||||||
awk, ASE_AWK_EAFNRED, awk->token.line,
|
awk, ASE_AWK_EAFNRED, awk->token.line,
|
||||||
@ -3238,7 +3238,7 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
|
|||||||
|
|
||||||
if (awk->option & ASE_AWK_IMPLICIT)
|
if (awk->option & ASE_AWK_IMPLICIT)
|
||||||
{
|
{
|
||||||
if (ase_awk_map_get (awk->parse.named, name_dup, name_len) != ASE_NULL)
|
if (ase_map_get (awk->parse.named, name_dup, name_len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
/* a function call conflicts with a named variable */
|
/* a function call conflicts with a named variable */
|
||||||
SETERRARG (awk, ASE_AWK_EVARRED, line, name_dup, name_len);
|
SETERRARG (awk, ASE_AWK_EVARRED, line, name_dup, name_len);
|
||||||
@ -3289,14 +3289,14 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
|
|||||||
name_dup, name_len) == 0);
|
name_dup, name_len) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscur || ase_awk_map_get (awk->tree.afns, name_dup, name_len) != ASE_NULL)
|
if (iscur || ase_map_get (awk->tree.afns, name_dup, name_len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
/* the function is defined previously */
|
/* the function is defined previously */
|
||||||
SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len);
|
SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len);
|
||||||
goto exit_func;
|
goto exit_func;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ase_awk_map_get (awk->parse.afns, name_dup, name_len) != ASE_NULL)
|
if (ase_map_get (awk->parse.afns, name_dup, name_len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
/* is it one of the function calls found so far? */
|
/* is it one of the function calls found so far? */
|
||||||
SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len);
|
SETERRARG (awk, ASE_AWK_EAFNRED, line, name_dup, name_len);
|
||||||
@ -3315,7 +3315,7 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
|
|||||||
nde->idx = ASE_NULL;
|
nde->idx = ASE_NULL;
|
||||||
|
|
||||||
/* collect unique instances of a named variables for reference */
|
/* collect unique instances of a named variables for reference */
|
||||||
if (ase_awk_map_put (awk->parse.named,
|
if (ase_map_put (awk->parse.named,
|
||||||
name_dup, name_len, (void*)line) == ASE_NULL)
|
name_dup, name_len, (void*)line) == ASE_NULL)
|
||||||
{
|
{
|
||||||
SETERRLIN (awk, ASE_AWK_ENOMEM, line);
|
SETERRLIN (awk, ASE_AWK_ENOMEM, line);
|
||||||
@ -3470,14 +3470,14 @@ static ase_awk_nde_t* parse_hashidx (
|
|||||||
name, name_len) == 0);
|
name, name_len) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscur || ase_awk_map_get (awk->tree.afns, name, name_len) != ASE_NULL)
|
if (iscur || ase_map_get (awk->tree.afns, name, name_len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
/* the function is defined previously */
|
/* the function is defined previously */
|
||||||
SETERRARG (awk, ASE_AWK_EAFNRED, line, name, name_len);
|
SETERRARG (awk, ASE_AWK_EAFNRED, line, name, name_len);
|
||||||
goto exit_func;
|
goto exit_func;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ase_awk_map_get (awk->parse.afns, name, name_len) != ASE_NULL)
|
if (ase_map_get (awk->parse.afns, name, name_len) != ASE_NULL)
|
||||||
{
|
{
|
||||||
/* is it one of the function calls found so far? */
|
/* is it one of the function calls found so far? */
|
||||||
SETERRARG (awk, ASE_AWK_EAFNRED, line, name, name_len);
|
SETERRARG (awk, ASE_AWK_EAFNRED, line, name, name_len);
|
||||||
@ -3629,7 +3629,7 @@ static ase_awk_nde_t* parse_fncall (
|
|||||||
|
|
||||||
/* this line number might be truncated as
|
/* this line number might be truncated as
|
||||||
* sizeof(line) could be > sizeof(void*) */
|
* sizeof(line) could be > sizeof(void*) */
|
||||||
if (ase_awk_map_put (awk->parse.afns,
|
if (ase_map_put (awk->parse.afns,
|
||||||
name, name_len, (void*)line) == ASE_NULL)
|
name, name_len, (void*)line) == ASE_NULL)
|
||||||
{
|
{
|
||||||
ASE_AWK_FREE (awk, call);
|
ASE_AWK_FREE (awk, call);
|
||||||
@ -5381,7 +5381,7 @@ static int classify_ident (
|
|||||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
|
ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
|
||||||
{
|
{
|
||||||
kwent_t* kwp;
|
kwent_t* kwp;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
for (kwp = kwtab; kwp->name != ASE_NULL; kwp++)
|
for (kwp = kwtab; kwp->name != ASE_NULL; kwp++)
|
||||||
{
|
{
|
||||||
@ -5391,7 +5391,7 @@ static int classify_ident (
|
|||||||
if (kwp->valid != 0 &&
|
if (kwp->valid != 0 &&
|
||||||
(awk->option & kwp->valid) != kwp->valid) continue;
|
(awk->option & kwp->valid) != kwp->valid) continue;
|
||||||
|
|
||||||
pair = ase_awk_map_get (awk->wtab, kwp->name, kwp->name_len);
|
pair = ase_map_get (awk->wtab, kwp->name, kwp->name_len);
|
||||||
if (pair != ASE_NULL)
|
if (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
k = ((ase_cstr_t*)(pair->val))->ptr;
|
k = ((ase_cstr_t*)(pair->val))->ptr;
|
||||||
@ -5595,7 +5595,7 @@ static int deparse (ase_awk_t* awk)
|
|||||||
df.tmp = tmp;
|
df.tmp = tmp;
|
||||||
df.tmp_len = ASE_COUNTOF(tmp);
|
df.tmp_len = ASE_COUNTOF(tmp);
|
||||||
|
|
||||||
if (ase_awk_map_walk (awk->tree.afns, deparse_func, &df) == -1)
|
if (ase_map_walk (awk->tree.afns, deparse_func, &df) == -1)
|
||||||
{
|
{
|
||||||
EXIT_DEPARSE ();
|
EXIT_DEPARSE ();
|
||||||
}
|
}
|
||||||
@ -5693,13 +5693,13 @@ exit_deparse:
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int deparse_func (ase_awk_pair_t* pair, void* arg)
|
static int deparse_func (ase_pair_t* pair, void* arg)
|
||||||
{
|
{
|
||||||
struct deparse_func_t* df = (struct deparse_func_t*)arg;
|
struct deparse_func_t* df = (struct deparse_func_t*)arg;
|
||||||
ase_awk_afn_t* afn = (ase_awk_afn_t*)pair->val;
|
ase_awk_afn_t* afn = (ase_awk_afn_t*)pair->val;
|
||||||
ase_size_t i, n;
|
ase_size_t i, n;
|
||||||
|
|
||||||
ASE_ASSERT (ase_strxncmp (ASE_AWK_PAIR_KEYPTR(pair), ASE_AWK_PAIR_KEYLEN(pair), afn->name, afn->name_len) == 0);
|
ASE_ASSERT (ase_strxncmp (ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair), afn->name, afn->name_len) == 0);
|
||||||
|
|
||||||
if (ase_awk_putsrcstr(df->awk,ase_awk_getkw(df->awk,ASE_T("function"))) == -1) return -1;
|
if (ase_awk_putsrcstr(df->awk,ase_awk_getkw(df->awk,ASE_T("function"))) == -1) return -1;
|
||||||
if (ase_awk_putsrcstr (df->awk, ASE_T(" ")) == -1) return -1;
|
if (ase_awk_putsrcstr (df->awk, ASE_T(" ")) == -1) return -1;
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#include <ase/awk/awk_i.h>
|
#include <ase/awk/awk_i.h>
|
||||||
|
|
||||||
static int __split_record (ase_awk_run_t* run);
|
static int split_record (ase_awk_run_t* run);
|
||||||
static int __recomp_record_fields (
|
static int recomp_record_fields (
|
||||||
ase_awk_run_t* run, ase_size_t lv,
|
ase_awk_run_t* run, ase_size_t lv,
|
||||||
const ase_char_t* str, ase_size_t len);
|
const ase_char_t* str, ase_size_t len);
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ int ase_awk_setrec (
|
|||||||
run->inrec.d0 = v;
|
run->inrec.d0 = v;
|
||||||
ase_awk_refupval (run, v);
|
ase_awk_refupval (run, v);
|
||||||
|
|
||||||
if (__split_record (run) == -1)
|
if (split_record (run) == -1)
|
||||||
{
|
{
|
||||||
ase_awk_clrrec (run, ase_false);
|
ase_awk_clrrec (run, ase_false);
|
||||||
return -1;
|
return -1;
|
||||||
@ -58,7 +58,7 @@ int ase_awk_setrec (
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (__recomp_record_fields (run, idx, str, len) == -1)
|
if (recomp_record_fields (run, idx, str, len) == -1)
|
||||||
{
|
{
|
||||||
ase_awk_clrrec (run, ase_false);
|
ase_awk_clrrec (run, ase_false);
|
||||||
return -1;
|
return -1;
|
||||||
@ -82,7 +82,7 @@ int ase_awk_setrec (
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __split_record (ase_awk_run_t* run)
|
static int split_record (ase_awk_run_t* run)
|
||||||
{
|
{
|
||||||
ase_char_t* p, * tok;
|
ase_char_t* p, * tok;
|
||||||
ase_size_t len, tok_len, nflds;
|
ase_size_t len, tok_len, nflds;
|
||||||
@ -91,7 +91,7 @@ static int __split_record (ase_awk_run_t* run)
|
|||||||
ase_size_t fs_len;
|
ase_size_t fs_len;
|
||||||
int errnum;
|
int errnum;
|
||||||
|
|
||||||
/* inrec should be cleared before __split_record is called */
|
/* inrec should be cleared before split_record is called */
|
||||||
ASE_ASSERT (run->inrec.nflds == 0);
|
ASE_ASSERT (run->inrec.nflds == 0);
|
||||||
|
|
||||||
/* get FS */
|
/* get FS */
|
||||||
@ -274,7 +274,7 @@ int ase_awk_clrrec (ase_awk_run_t* run, ase_bool_t skip_inrec_line)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __recomp_record_fields (
|
static int recomp_record_fields (
|
||||||
ase_awk_run_t* run, ase_size_t lv,
|
ase_awk_run_t* run, ase_size_t lv,
|
||||||
const ase_char_t* str, ase_size_t len)
|
const ase_char_t* str, ase_size_t len)
|
||||||
{
|
{
|
||||||
|
101
ase/awk/run.c
101
ase/awk/run.c
@ -601,7 +601,7 @@ void* ase_awk_getruncustomdata (ase_awk_run_t* run)
|
|||||||
return run->custom_data;
|
return run->custom_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk)
|
ase_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk)
|
||||||
{
|
{
|
||||||
return awk->named;
|
return awk->named;
|
||||||
}
|
}
|
||||||
@ -624,7 +624,7 @@ int ase_awk_run (ase_awk_t* awk,
|
|||||||
awk->tree.begin == ASE_NULL &&
|
awk->tree.begin == ASE_NULL &&
|
||||||
awk->tree.end == ASE_NULL &&
|
awk->tree.end == ASE_NULL &&
|
||||||
awk->tree.chain_size == 0 &&
|
awk->tree.chain_size == 0 &&
|
||||||
ase_awk_map_getsize(awk->tree.afns) == 0)
|
ase_map_getsize(awk->tree.afns) == 0)
|
||||||
{
|
{
|
||||||
/* if not, deny the run */
|
/* if not, deny the run */
|
||||||
ase_awk_seterror (awk, ASE_AWK_ENOPER, 0, ASE_NULL, 0);
|
ase_awk_seterror (awk, ASE_AWK_ENOPER, 0, ASE_NULL, 0);
|
||||||
@ -787,8 +787,9 @@ static int init_run (
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
run->named = ase_awk_map_open (
|
run->named = ase_map_open (
|
||||||
run, 1024, 70, free_namedval, same_namedval, run->awk);
|
run, 1024, 70, free_namedval, same_namedval,
|
||||||
|
&run->awk->prmfns.mmgr);
|
||||||
if (run->named == ASE_NULL)
|
if (run->named == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_str_close (&run->format.fmt);
|
ase_str_close (&run->format.fmt);
|
||||||
@ -802,7 +803,7 @@ static int init_run (
|
|||||||
ASE_AWK_MALLOC (run->awk, 4096*ASE_SIZEOF(ase_char_t*));
|
ASE_AWK_MALLOC (run->awk, 4096*ASE_SIZEOF(ase_char_t*));
|
||||||
if (run->format.tmp.ptr == ASE_NULL)
|
if (run->format.tmp.ptr == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_map_close (run->named);
|
ase_map_close (run->named);
|
||||||
ase_str_close (&run->format.fmt);
|
ase_str_close (&run->format.fmt);
|
||||||
ase_str_close (&run->format.out);
|
ase_str_close (&run->format.out);
|
||||||
ase_str_close (&run->inrec.line);
|
ase_str_close (&run->inrec.line);
|
||||||
@ -819,7 +820,7 @@ static int init_run (
|
|||||||
if (run->pattern_range_state == ASE_NULL)
|
if (run->pattern_range_state == ASE_NULL)
|
||||||
{
|
{
|
||||||
ASE_AWK_FREE (run->awk, run->format.tmp.ptr);
|
ASE_AWK_FREE (run->awk, run->format.tmp.ptr);
|
||||||
ase_awk_map_close (run->named);
|
ase_map_close (run->named);
|
||||||
ase_str_close (&run->format.fmt);
|
ase_str_close (&run->format.fmt);
|
||||||
ase_str_close (&run->format.out);
|
ase_str_close (&run->format.out);
|
||||||
ase_str_close (&run->inrec.line);
|
ase_str_close (&run->inrec.line);
|
||||||
@ -948,7 +949,7 @@ static void deinit_run (ase_awk_run_t* run)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* destroy named variables */
|
/* destroy named variables */
|
||||||
ase_awk_map_close (run->named);
|
ase_map_close (run->named);
|
||||||
|
|
||||||
/* destroy values in free list */
|
/* destroy values in free list */
|
||||||
while (run->fcache_count > 0)
|
while (run->fcache_count > 0)
|
||||||
@ -1028,7 +1029,7 @@ static int build_runarg (
|
|||||||
* it has successfully been assigned into ARGV. */
|
* it has successfully been assigned into ARGV. */
|
||||||
ase_awk_refupval (run, v_tmp);
|
ase_awk_refupval (run, v_tmp);
|
||||||
|
|
||||||
if (ase_awk_map_putx (
|
if (ase_map_putx (
|
||||||
((ase_awk_val_map_t*)v_argv)->map,
|
((ase_awk_val_map_t*)v_argv)->map,
|
||||||
key, key_len, v_tmp, ASE_NULL) == -1)
|
key, key_len, v_tmp, ASE_NULL) == -1)
|
||||||
{
|
{
|
||||||
@ -2195,13 +2196,13 @@ struct __foreach_walker_t
|
|||||||
ase_awk_nde_t* body;
|
ase_awk_nde_t* body;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __walk_foreach (ase_awk_pair_t* pair, void* arg)
|
static int __walk_foreach (ase_pair_t* pair, void* arg)
|
||||||
{
|
{
|
||||||
struct __foreach_walker_t* w = (struct __foreach_walker_t*)arg;
|
struct __foreach_walker_t* w = (struct __foreach_walker_t*)arg;
|
||||||
ase_awk_val_t* str;
|
ase_awk_val_t* str;
|
||||||
|
|
||||||
str = (ase_awk_val_t*) ase_awk_makestrval (
|
str = (ase_awk_val_t*) ase_awk_makestrval (
|
||||||
w->run, ASE_AWK_PAIR_KEYPTR(pair), ASE_AWK_PAIR_KEYLEN(pair));
|
w->run, ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair));
|
||||||
if (str == ASE_NULL)
|
if (str == ASE_NULL)
|
||||||
{
|
{
|
||||||
/* adjust the error line */
|
/* adjust the error line */
|
||||||
@ -2231,7 +2232,7 @@ static int run_foreach (ase_awk_run_t* run, ase_awk_nde_foreach_t* nde)
|
|||||||
int n;
|
int n;
|
||||||
ase_awk_nde_exp_t* test;
|
ase_awk_nde_exp_t* test;
|
||||||
ase_awk_val_t* rv;
|
ase_awk_val_t* rv;
|
||||||
ase_awk_map_t* map;
|
ase_map_t* map;
|
||||||
struct __foreach_walker_t walker;
|
struct __foreach_walker_t walker;
|
||||||
|
|
||||||
test = (ase_awk_nde_exp_t*)nde->test;
|
test = (ase_awk_nde_exp_t*)nde->test;
|
||||||
@ -2260,7 +2261,7 @@ static int run_foreach (ase_awk_run_t* run, ase_awk_nde_foreach_t* nde)
|
|||||||
walker.run = run;
|
walker.run = run;
|
||||||
walker.var = test->left;
|
walker.var = test->left;
|
||||||
walker.body = nde->body;
|
walker.body = nde->body;
|
||||||
n = ase_awk_map_walk (map, __walk_foreach, &walker);
|
n = ase_map_walk (map, __walk_foreach, &walker);
|
||||||
|
|
||||||
ase_awk_refdownval (run, rv);
|
ase_awk_refdownval (run, rv);
|
||||||
return n;
|
return n;
|
||||||
@ -2447,14 +2448,14 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
|||||||
if (var->type == ASE_AWK_NDE_NAMED ||
|
if (var->type == ASE_AWK_NDE_NAMED ||
|
||||||
var->type == ASE_AWK_NDE_NAMEDIDX)
|
var->type == ASE_AWK_NDE_NAMEDIDX)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
ASE_ASSERTX (
|
ASE_ASSERTX (
|
||||||
(var->type == ASE_AWK_NDE_NAMED && var->idx == ASE_NULL) ||
|
(var->type == ASE_AWK_NDE_NAMED && var->idx == ASE_NULL) ||
|
||||||
(var->type == ASE_AWK_NDE_NAMEDIDX && var->idx != ASE_NULL),
|
(var->type == ASE_AWK_NDE_NAMEDIDX && var->idx != ASE_NULL),
|
||||||
"if a named variable has an index part and a named indexed variable doesn't have an index part, the program is definitely wrong");
|
"if a named variable has an index part and a named indexed variable doesn't have an index part, the program is definitely wrong");
|
||||||
|
|
||||||
pair = ase_awk_map_get (
|
pair = ase_map_get (
|
||||||
run->named, var->id.name, var->id.name_len);
|
run->named, var->id.name, var->id.name_len);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -2471,7 +2472,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair = ase_awk_map_put (run->named,
|
pair = ase_map_put (run->named,
|
||||||
var->id.name, var->id.name_len, tmp);
|
var->id.name, var->id.name_len, tmp);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -2491,7 +2492,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ase_awk_val_t* val;
|
ase_awk_val_t* val;
|
||||||
ase_awk_map_t* map;
|
ase_map_t* map;
|
||||||
|
|
||||||
val = (ase_awk_val_t*)pair->val;
|
val = (ase_awk_val_t*)pair->val;
|
||||||
ASE_ASSERT (val != ASE_NULL);
|
ASE_ASSERT (val != ASE_NULL);
|
||||||
@ -2546,12 +2547,12 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_map_remove (map, key, keylen);
|
ase_map_remove (map, key, keylen);
|
||||||
if (key != buf) ASE_AWK_FREE (run->awk, key);
|
if (key != buf) ASE_AWK_FREE (run->awk, key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ase_awk_map_clear (map);
|
ase_map_clear (map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2618,7 +2619,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ase_awk_map_t* map;
|
ase_map_t* map;
|
||||||
|
|
||||||
if (val->type != ASE_AWK_VAL_MAP)
|
if (val->type != ASE_AWK_VAL_MAP)
|
||||||
{
|
{
|
||||||
@ -2670,12 +2671,12 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
|||||||
run->errlin = var->line;
|
run->errlin = var->line;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ase_awk_map_remove (map, key, keylen);
|
ase_map_remove (map, key, keylen);
|
||||||
if (key != buf) ASE_AWK_FREE (run->awk, key);
|
if (key != buf) ASE_AWK_FREE (run->awk, key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ase_awk_map_clear (map);
|
ase_map_clear (map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2707,7 +2708,7 @@ static int run_reset (ase_awk_run_t* run, ase_awk_nde_reset_t* nde)
|
|||||||
|
|
||||||
/* a named variable can be reset if removed from a internal map
|
/* a named variable can be reset if removed from a internal map
|
||||||
to manage it */
|
to manage it */
|
||||||
ase_awk_map_remove (run->named, var->id.name, var->id.name_len);
|
ase_map_remove (run->named, var->id.name, var->id.name_len);
|
||||||
}
|
}
|
||||||
else if (var->type == ASE_AWK_NDE_GLOBAL ||
|
else if (var->type == ASE_AWK_NDE_GLOBAL ||
|
||||||
var->type == ASE_AWK_NDE_LOCAL ||
|
var->type == ASE_AWK_NDE_LOCAL ||
|
||||||
@ -3331,10 +3332,10 @@ static ase_awk_val_t* do_assignment_scalar (
|
|||||||
|
|
||||||
if (var->type == ASE_AWK_NDE_NAMED)
|
if (var->type == ASE_AWK_NDE_NAMED)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
pair = ase_awk_map_get (
|
pair = ase_map_get (
|
||||||
run->named, var->id.name, var->id.name_len);
|
run->named, var->id.name, var->id.name_len);
|
||||||
if (pair != ASE_NULL &&
|
if (pair != ASE_NULL &&
|
||||||
((ase_awk_val_t*)pair->val)->type == ASE_AWK_VAL_MAP)
|
((ase_awk_val_t*)pair->val)->type == ASE_AWK_VAL_MAP)
|
||||||
@ -3351,7 +3352,7 @@ static ase_awk_val_t* do_assignment_scalar (
|
|||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = ase_awk_map_putx (run->named,
|
n = ase_map_putx (run->named,
|
||||||
var->id.name, var->id.name_len, val, ASE_NULL);
|
var->id.name, var->id.name_len, val, ASE_NULL);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
@ -3435,8 +3436,8 @@ static ase_awk_val_t* do_assignment_map (
|
|||||||
|
|
||||||
if (var->type == ASE_AWK_NDE_NAMEDIDX)
|
if (var->type == ASE_AWK_NDE_NAMEDIDX)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
pair = ase_awk_map_get (
|
pair = ase_map_get (
|
||||||
run->named, var->id.name, var->id.name_len);
|
run->named, var->id.name, var->id.name_len);
|
||||||
map = (pair == ASE_NULL)?
|
map = (pair == ASE_NULL)?
|
||||||
(ase_awk_val_map_t*)ase_awk_val_nil:
|
(ase_awk_val_map_t*)ase_awk_val_nil:
|
||||||
@ -3468,8 +3469,8 @@ static ase_awk_val_t* do_assignment_map (
|
|||||||
{
|
{
|
||||||
/* doesn't have to decrease the reference count
|
/* doesn't have to decrease the reference count
|
||||||
* of the previous value here as it is done by
|
* of the previous value here as it is done by
|
||||||
* ase_awk_map_put */
|
* ase_map_put */
|
||||||
if (ase_awk_map_put (run->named,
|
if (ase_map_put (run->named,
|
||||||
var->id.name, var->id.name_len, tmp) == ASE_NULL)
|
var->id.name, var->id.name_len, tmp) == ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_refupval (run, tmp);
|
ase_awk_refupval (run, tmp);
|
||||||
@ -3531,7 +3532,7 @@ static ase_awk_val_t* do_assignment_map (
|
|||||||
str, (int)map->ref, (int)map->type);
|
str, (int)map->ref, (int)map->type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
n = ase_awk_map_putx (map->map, str, len, val, ASE_NULL);
|
n = ase_map_putx (map->map, str, len, val, ASE_NULL);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
if (str != idxbuf) ASE_AWK_FREE (run->awk, str);
|
if (str != idxbuf) ASE_AWK_FREE (run->awk, str);
|
||||||
@ -3853,10 +3854,10 @@ static ase_awk_val_t* eval_binop_in (
|
|||||||
else if (rv->type == ASE_AWK_VAL_MAP)
|
else if (rv->type == ASE_AWK_VAL_MAP)
|
||||||
{
|
{
|
||||||
ase_awk_val_t* res;
|
ase_awk_val_t* res;
|
||||||
ase_awk_map_t* map;
|
ase_map_t* map;
|
||||||
|
|
||||||
map = ((ase_awk_val_map_t*)rv)->map;
|
map = ((ase_awk_val_map_t*)rv)->map;
|
||||||
res = (ase_awk_map_get (map, str, len) == ASE_NULL)?
|
res = (ase_map_get (map, str, len) == ASE_NULL)?
|
||||||
ase_awk_val_zero: ase_awk_val_one;
|
ase_awk_val_zero: ase_awk_val_one;
|
||||||
|
|
||||||
if (str != idxbuf) ASE_AWK_FREE (run->awk, str);
|
if (str != idxbuf) ASE_AWK_FREE (run->awk, str);
|
||||||
@ -5385,9 +5386,9 @@ static ase_awk_val_t* eval_afn_intrinsic (
|
|||||||
{
|
{
|
||||||
ase_awk_nde_call_t* call = (ase_awk_nde_call_t*)nde;
|
ase_awk_nde_call_t* call = (ase_awk_nde_call_t*)nde;
|
||||||
ase_awk_afn_t* afn;
|
ase_awk_afn_t* afn;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
pair = ase_awk_map_get (run->awk->tree.afns,
|
pair = ase_map_get (run->awk->tree.afns,
|
||||||
call->what.afn.name.ptr, call->what.afn.name.len);
|
call->what.afn.name.ptr, call->what.afn.name.len);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
@ -5741,16 +5742,16 @@ static int get_reference (
|
|||||||
|
|
||||||
if (nde->type == ASE_AWK_NDE_NAMED)
|
if (nde->type == ASE_AWK_NDE_NAMED)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
pair = ase_awk_map_get (
|
pair = ase_map_get (
|
||||||
run->named, tgt->id.name, tgt->id.name_len);
|
run->named, tgt->id.name, tgt->id.name_len);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
/* it is bad that the named variable has to be
|
/* it is bad that the named variable has to be
|
||||||
* created in the function named "__get_refernce".
|
* created in the function named "__get_refernce".
|
||||||
* would there be any better ways to avoid this? */
|
* would there be any better ways to avoid this? */
|
||||||
pair = ase_awk_map_put (
|
pair = ase_map_put (
|
||||||
run->named, tgt->id.name,
|
run->named, tgt->id.name,
|
||||||
tgt->id.name_len, ase_awk_val_nil);
|
tgt->id.name_len, ase_awk_val_nil);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
@ -5786,13 +5787,13 @@ static int get_reference (
|
|||||||
|
|
||||||
if (nde->type == ASE_AWK_NDE_NAMEDIDX)
|
if (nde->type == ASE_AWK_NDE_NAMEDIDX)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
pair = ase_awk_map_get (
|
pair = ase_map_get (
|
||||||
run->named, tgt->id.name, tgt->id.name_len);
|
run->named, tgt->id.name, tgt->id.name_len);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
pair = ase_awk_map_put (
|
pair = ase_map_put (
|
||||||
run->named, tgt->id.name,
|
run->named, tgt->id.name,
|
||||||
tgt->id.name_len, ase_awk_val_nil);
|
tgt->id.name_len, ase_awk_val_nil);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
@ -5875,7 +5876,7 @@ static int get_reference (
|
|||||||
static ase_awk_val_t** get_reference_indexed (
|
static ase_awk_val_t** get_reference_indexed (
|
||||||
ase_awk_run_t* run, ase_awk_nde_var_t* nde, ase_awk_val_t** val)
|
ase_awk_run_t* run, ase_awk_nde_var_t* nde, ase_awk_val_t** val)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
ase_char_t* str;
|
ase_char_t* str;
|
||||||
ase_size_t len;
|
ase_size_t len;
|
||||||
ase_char_t idxbuf[IDXBUFSIZE];
|
ase_char_t idxbuf[IDXBUFSIZE];
|
||||||
@ -5914,10 +5915,10 @@ static ase_awk_val_t** get_reference_indexed (
|
|||||||
if (str == ASE_NULL) return ASE_NULL;
|
if (str == ASE_NULL) return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair = ase_awk_map_get ((*(ase_awk_val_map_t**)val)->map, str, len);
|
pair = ase_map_get ((*(ase_awk_val_map_t**)val)->map, str, len);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
pair = ase_awk_map_put (
|
pair = ase_map_put (
|
||||||
(*(ase_awk_val_map_t**)val)->map,
|
(*(ase_awk_val_map_t**)val)->map,
|
||||||
str, len, ase_awk_val_nil);
|
str, len, ase_awk_val_nil);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
@ -6000,9 +6001,9 @@ static ase_awk_val_t* eval_rex (ase_awk_run_t* run, ase_awk_nde_t* nde)
|
|||||||
|
|
||||||
static ase_awk_val_t* eval_named (ase_awk_run_t* run, ase_awk_nde_t* nde)
|
static ase_awk_val_t* eval_named (ase_awk_run_t* run, ase_awk_nde_t* nde)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
pair = ase_awk_map_get (run->named,
|
pair = ase_map_get (run->named,
|
||||||
((ase_awk_nde_var_t*)nde)->id.name,
|
((ase_awk_nde_var_t*)nde)->id.name,
|
||||||
((ase_awk_nde_var_t*)nde)->id.name_len);
|
((ase_awk_nde_var_t*)nde)->id.name_len);
|
||||||
|
|
||||||
@ -6027,7 +6028,7 @@ static ase_awk_val_t* eval_arg (ase_awk_run_t* run, ase_awk_nde_t* nde)
|
|||||||
static ase_awk_val_t* eval_indexed (
|
static ase_awk_val_t* eval_indexed (
|
||||||
ase_awk_run_t* run, ase_awk_nde_var_t* nde, ase_awk_val_t** val)
|
ase_awk_run_t* run, ase_awk_nde_var_t* nde, ase_awk_val_t** val)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
ase_char_t* str;
|
ase_char_t* str;
|
||||||
ase_size_t len;
|
ase_size_t len;
|
||||||
ase_char_t idxbuf[IDXBUFSIZE];
|
ase_char_t idxbuf[IDXBUFSIZE];
|
||||||
@ -6066,7 +6067,7 @@ static ase_awk_val_t* eval_indexed (
|
|||||||
if (str == ASE_NULL) return ASE_NULL;
|
if (str == ASE_NULL) return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair = ase_awk_map_get ((*(ase_awk_val_map_t**)val)->map, str, len);
|
pair = ase_map_get ((*(ase_awk_val_map_t**)val)->map, str, len);
|
||||||
if (str != idxbuf) ASE_AWK_FREE (run->awk, str);
|
if (str != idxbuf) ASE_AWK_FREE (run->awk, str);
|
||||||
|
|
||||||
return (pair == ASE_NULL)? ase_awk_val_nil: (ase_awk_val_t*)pair->val;
|
return (pair == ASE_NULL)? ase_awk_val_nil: (ase_awk_val_t*)pair->val;
|
||||||
@ -6075,12 +6076,12 @@ static ase_awk_val_t* eval_indexed (
|
|||||||
static ase_awk_val_t* eval_namedidx (ase_awk_run_t* run, ase_awk_nde_t* nde)
|
static ase_awk_val_t* eval_namedidx (ase_awk_run_t* run, ase_awk_nde_t* nde)
|
||||||
{
|
{
|
||||||
ase_awk_nde_var_t* tgt = (ase_awk_nde_var_t*)nde;
|
ase_awk_nde_var_t* tgt = (ase_awk_nde_var_t*)nde;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
pair = ase_awk_map_get (run->named, tgt->id.name, tgt->id.name_len);
|
pair = ase_map_get (run->named, tgt->id.name, tgt->id.name_len);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
pair = ase_awk_map_put (run->named,
|
pair = ase_map_put (run->named,
|
||||||
tgt->id.name, tgt->id.name_len, ase_awk_val_nil);
|
tgt->id.name, tgt->id.name_len, ase_awk_val_nil);
|
||||||
if (pair == ASE_NULL)
|
if (pair == ASE_NULL)
|
||||||
{
|
{
|
||||||
|
@ -381,8 +381,8 @@ ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run)
|
|||||||
|
|
||||||
val->type = ASE_AWK_VAL_MAP;
|
val->type = ASE_AWK_VAL_MAP;
|
||||||
val->ref = 0;
|
val->ref = 0;
|
||||||
val->map = ase_awk_map_open (
|
val->map = ase_map_open (
|
||||||
run, 256, 70, free_mapval, same_mapval, run->awk);
|
run, 256, 70, free_mapval, same_mapval, &run->awk->prmfns.mmgr);
|
||||||
if (val->map == ASE_NULL)
|
if (val->map == ASE_NULL)
|
||||||
{
|
{
|
||||||
ASE_AWK_FREE (run->awk, val);
|
ASE_AWK_FREE (run->awk, val);
|
||||||
@ -503,7 +503,7 @@ void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache)
|
|||||||
}
|
}
|
||||||
else if (val->type == ASE_AWK_VAL_MAP)
|
else if (val->type == ASE_AWK_VAL_MAP)
|
||||||
{
|
{
|
||||||
ase_awk_map_close (((ase_awk_val_map_t*)val)->map);
|
ase_map_close (((ase_awk_val_map_t*)val)->map);
|
||||||
ASE_AWK_FREE (run->awk, val);
|
ASE_AWK_FREE (run->awk, val);
|
||||||
}
|
}
|
||||||
else if (val->type == ASE_AWK_VAL_REF)
|
else if (val->type == ASE_AWK_VAL_REF)
|
||||||
@ -991,7 +991,7 @@ int ase_awk_strtonum (
|
|||||||
#define DPRINTF run->awk->prmfns.misc.dprintf
|
#define DPRINTF run->awk->prmfns.misc.dprintf
|
||||||
#define DCUSTOM run->awk->prmfns.misc.custom_data
|
#define DCUSTOM run->awk->prmfns.misc.custom_data
|
||||||
|
|
||||||
static int print_pair (ase_awk_pair_t* pair, void* arg)
|
static int print_pair (ase_pair_t* pair, void* arg)
|
||||||
{
|
{
|
||||||
ase_awk_run_t* run = (ase_awk_run_t*)arg;
|
ase_awk_run_t* run = (ase_awk_run_t*)arg;
|
||||||
|
|
||||||
@ -1044,7 +1044,7 @@ void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val)
|
|||||||
|
|
||||||
case ASE_AWK_VAL_MAP:
|
case ASE_AWK_VAL_MAP:
|
||||||
DPRINTF (DCUSTOM, ASE_T("MAP["));
|
DPRINTF (DCUSTOM, ASE_T("MAP["));
|
||||||
ase_awk_map_walk (((ase_awk_val_map_t*)val)->map, print_pair, run);
|
ase_map_walk (((ase_awk_val_map_t*)val)->map, print_pair, run);
|
||||||
DPRINTF (DCUSTOM, ASE_T("]"));
|
DPRINTF (DCUSTOM, ASE_T("]"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ase/cmn/str.h>
|
#include <ase/cmn/str.h>
|
||||||
#include <ase/awk/map.h>
|
|
||||||
|
|
||||||
|
|
||||||
enum ase_awk_val_type_t
|
enum ase_awk_val_type_t
|
||||||
{
|
{
|
||||||
@ -138,7 +136,7 @@ struct ase_awk_val_map_t
|
|||||||
* integers switch to map dynamically once the
|
* integers switch to map dynamically once the
|
||||||
* non-integral index is seen.
|
* non-integral index is seen.
|
||||||
*/
|
*/
|
||||||
ase_awk_map_t* map;
|
ase_map_t* map;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ASE_AWK_VAL_REF */
|
/* ASE_AWK_VAL_REF */
|
||||||
|
@ -4,38 +4,38 @@
|
|||||||
* {License}
|
* {License}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ase/awk/awk_i.h>
|
#include <ase/cmn/map.h>
|
||||||
|
#include <ase/cmn/str.h>
|
||||||
|
|
||||||
static ase_size_t hashkey (const ase_char_t* keyptr, ase_size_t keylen);
|
static ase_size_t hashkey (const ase_char_t* keyptr, ase_size_t keylen);
|
||||||
static int rehash (ase_awk_map_t* map);
|
static int rehash (ase_map_t* map);
|
||||||
|
|
||||||
#define FREE_PAIR(map,pair) \
|
#define FREE_PAIR(map,pair) \
|
||||||
do { \
|
do { \
|
||||||
ASE_AWK_FREE ((map)->awk, (ase_char_t*)ASE_AWK_PAIR_KEYPTR(pair)); \
|
ASE_FREE ((map)->mmgr, (ase_char_t*)ASE_PAIR_KEYPTR(pair)); \
|
||||||
if ((map)->freeval != ASE_NULL) \
|
if ((map)->freeval != ASE_NULL) \
|
||||||
(map)->freeval ((map)->owner, ASE_AWK_PAIR_VAL(pair)); \
|
(map)->freeval ((map)->owner, ASE_PAIR_VAL(pair)); \
|
||||||
ASE_AWK_FREE ((map)->awk, pair); \
|
ASE_FREE ((map)->mmgr, pair); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
ase_awk_map_t* ase_awk_map_open (
|
ase_map_t* ase_map_open (
|
||||||
void* owner, ase_size_t capa, unsigned int factor,
|
void* owner, ase_size_t capa, unsigned int factor,
|
||||||
void(*freeval)(void*,void*), void(*sameval)(void*,void*),
|
void(*freeval)(void*,void*), void(*sameval)(void*,void*),
|
||||||
ase_awk_t* awk)
|
ase_mmgr_t* mmgr)
|
||||||
{
|
{
|
||||||
ase_awk_map_t* map;
|
ase_map_t* map;
|
||||||
|
|
||||||
ASE_ASSERTX (capa > 0, "the initial capacity should be greater than 0");
|
ASE_ASSERTX (capa > 0, "the initial capacity should be greater than 0");
|
||||||
|
|
||||||
map = (ase_awk_map_t*) ASE_AWK_MALLOC (
|
map = (ase_map_t*) ASE_MALLOC (mmgr, ASE_SIZEOF(ase_map_t));
|
||||||
awk, ASE_SIZEOF(ase_awk_map_t));
|
|
||||||
if (map == ASE_NULL) return ASE_NULL;
|
if (map == ASE_NULL) return ASE_NULL;
|
||||||
|
|
||||||
map->awk = awk;
|
map->mmgr = mmgr;
|
||||||
map->buck = (ase_awk_pair_t**)
|
map->buck = (ase_pair_t**)
|
||||||
ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_pair_t*) * capa);
|
ASE_MALLOC (mmgr, ASE_SIZEOF(ase_pair_t*)*capa);
|
||||||
if (map->buck == ASE_NULL)
|
if (map->buck == ASE_NULL)
|
||||||
{
|
{
|
||||||
ASE_AWK_FREE (awk, map);
|
ASE_FREE (mmgr, map);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,17 +52,17 @@ ase_awk_map_t* ase_awk_map_open (
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ase_awk_map_close (ase_awk_map_t* map)
|
void ase_map_close (ase_map_t* map)
|
||||||
{
|
{
|
||||||
ase_awk_map_clear (map);
|
ase_map_clear (map);
|
||||||
ASE_AWK_FREE (map->awk, map->buck);
|
ASE_FREE (map->mmgr, map->buck);
|
||||||
ASE_AWK_FREE (map->awk, map);
|
ASE_FREE (map->mmgr, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ase_awk_map_clear (ase_awk_map_t* map)
|
void ase_map_clear (ase_map_t* map)
|
||||||
{
|
{
|
||||||
ase_size_t i;
|
ase_size_t i;
|
||||||
ase_awk_pair_t* pair, * next;
|
ase_pair_t* pair, * next;
|
||||||
|
|
||||||
for (i = 0; i < map->capa; i++)
|
for (i = 0; i < map->capa; i++)
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ void ase_awk_map_clear (ase_awk_map_t* map)
|
|||||||
|
|
||||||
while (pair != ASE_NULL)
|
while (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
next = ASE_AWK_PAIR_LNK(pair);
|
next = ASE_PAIR_LNK(pair);
|
||||||
FREE_PAIR (map, pair);
|
FREE_PAIR (map, pair);
|
||||||
map->size--;
|
map->size--;
|
||||||
pair = next;
|
pair = next;
|
||||||
@ -80,15 +80,15 @@ void ase_awk_map_clear (ase_awk_map_t* map)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_size_t ase_awk_map_getsize (ase_awk_map_t* map)
|
ase_size_t ase_map_getsize (ase_map_t* map)
|
||||||
{
|
{
|
||||||
return map->size;
|
return map->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_get (
|
ase_pair_t* ase_map_get (
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen)
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
ase_size_t hc;
|
ase_size_t hc;
|
||||||
|
|
||||||
hc = hashkey(keyptr,keylen) % map->capa;
|
hc = hashkey(keyptr,keylen) % map->capa;
|
||||||
@ -97,32 +97,32 @@ ase_awk_pair_t* ase_awk_map_get (
|
|||||||
while (pair != ASE_NULL)
|
while (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
if (ase_strxncmp (
|
if (ase_strxncmp (
|
||||||
ASE_AWK_PAIR_KEYPTR(pair), ASE_AWK_PAIR_KEYLEN(pair),
|
ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair),
|
||||||
keyptr, keylen) == 0) return pair;
|
keyptr, keylen) == 0) return pair;
|
||||||
|
|
||||||
pair = ASE_AWK_PAIR_LNK(pair);
|
pair = ASE_PAIR_LNK(pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_put (
|
ase_pair_t* ase_map_put (
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
||||||
void* val)
|
void* val)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
ase_awk_pair_t* px;
|
ase_pair_t* px;
|
||||||
|
|
||||||
n = ase_awk_map_putx (map, keyptr, keylen, val, &px);
|
n = ase_map_putx (map, keyptr, keylen, val, &px);
|
||||||
if (n < 0) return ASE_NULL;
|
if (n < 0) return ASE_NULL;
|
||||||
return px;
|
return px;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ase_awk_map_putx (
|
int ase_map_putx (
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
||||||
void* val, ase_awk_pair_t** px)
|
void* val, ase_pair_t** px)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
ase_size_t hc;
|
ase_size_t hc;
|
||||||
|
|
||||||
hc = hashkey(keyptr,keylen) % map->capa;
|
hc = hashkey(keyptr,keylen) % map->capa;
|
||||||
@ -131,17 +131,17 @@ int ase_awk_map_putx (
|
|||||||
while (pair != ASE_NULL)
|
while (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
if (ase_strxncmp (
|
if (ase_strxncmp (
|
||||||
ASE_AWK_PAIR_KEYPTR(pair), ASE_AWK_PAIR_KEYLEN(pair),
|
ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair),
|
||||||
keyptr, keylen) == 0)
|
keyptr, keylen) == 0)
|
||||||
{
|
{
|
||||||
if (px != ASE_NULL)
|
if (px != ASE_NULL)
|
||||||
*px = ase_awk_map_setpair (map, pair, val);
|
*px = ase_map_setpair (map, pair, val);
|
||||||
else
|
else
|
||||||
ase_awk_map_setpair (map, pair, val);
|
ase_map_setpair (map, pair, val);
|
||||||
|
|
||||||
return 0; /* value changed for the existing key */
|
return 0; /* value changed for the existing key */
|
||||||
}
|
}
|
||||||
pair = ASE_AWK_PAIR_LNK(pair);
|
pair = ASE_PAIR_LNK(pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map->threshold > 0 &&
|
if (map->threshold > 0 &&
|
||||||
@ -153,21 +153,20 @@ int ase_awk_map_putx (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pair = (ase_awk_pair_t*) ASE_AWK_MALLOC (
|
pair = (ase_pair_t*) ASE_MALLOC (map->mmgr, ASE_SIZEOF(ase_pair_t));
|
||||||
map->awk, ASE_SIZEOF(ase_awk_pair_t));
|
|
||||||
if (pair == ASE_NULL) return -1; /* error */
|
if (pair == ASE_NULL) return -1; /* error */
|
||||||
|
|
||||||
/* duplicate the key if it is new */
|
/* duplicate the key if it is new */
|
||||||
ASE_AWK_PAIR_KEYPTR(pair) = ase_awk_strxdup (map->awk, keyptr, keylen);
|
ASE_PAIR_KEYPTR(pair) = ase_strxdup (keyptr, keylen, map->mmgr);
|
||||||
if (ASE_AWK_PAIR_KEYPTR(pair) == ASE_NULL)
|
if (ASE_PAIR_KEYPTR(pair) == ASE_NULL)
|
||||||
{
|
{
|
||||||
ASE_AWK_FREE (map->awk, pair);
|
ASE_FREE (map->mmgr, pair);
|
||||||
return -1; /* error */
|
return -1; /* error */
|
||||||
}
|
}
|
||||||
|
|
||||||
ASE_AWK_PAIR_KEYLEN(pair) = keylen;
|
ASE_PAIR_KEYLEN(pair) = keylen;
|
||||||
ASE_AWK_PAIR_VAL(pair) = val;
|
ASE_PAIR_VAL(pair) = val;
|
||||||
ASE_AWK_PAIR_LNK(pair) = map->buck[hc];
|
ASE_PAIR_LNK(pair) = map->buck[hc];
|
||||||
map->buck[hc] = pair;
|
map->buck[hc] = pair;
|
||||||
map->size++;
|
map->size++;
|
||||||
|
|
||||||
@ -175,11 +174,11 @@ int ase_awk_map_putx (
|
|||||||
return 1; /* new key added */
|
return 1; /* new key added */
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_set (
|
ase_pair_t* ase_map_set (
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
||||||
void* val)
|
void* val)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
ase_size_t hc;
|
ase_size_t hc;
|
||||||
|
|
||||||
hc = hashkey(keyptr,keylen) % map->capa;
|
hc = hashkey(keyptr,keylen) % map->capa;
|
||||||
@ -188,35 +187,35 @@ ase_awk_pair_t* ase_awk_map_set (
|
|||||||
while (pair != ASE_NULL)
|
while (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
if (ase_strxncmp (
|
if (ase_strxncmp (
|
||||||
ASE_AWK_PAIR_KEYPTR(pair), ASE_AWK_PAIR_KEYLEN(pair),
|
ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair),
|
||||||
keyptr, keylen) == 0)
|
keyptr, keylen) == 0)
|
||||||
{
|
{
|
||||||
return ase_awk_map_setpair (map, pair, val);
|
return ase_map_setpair (map, pair, val);
|
||||||
}
|
}
|
||||||
pair = ASE_AWK_PAIR_LNK(pair);
|
pair = ASE_PAIR_LNK(pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_getpair (
|
ase_pair_t* ase_map_getpair (
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
||||||
void** val)
|
void** val)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
pair = ase_awk_map_get (map, keyptr, keylen);
|
pair = ase_map_get (map, keyptr, keylen);
|
||||||
if (pair == ASE_NULL) return ASE_NULL;
|
if (pair == ASE_NULL) return ASE_NULL;
|
||||||
*val = ASE_AWK_PAIR_VAL(pair);
|
*val = ASE_PAIR_VAL(pair);
|
||||||
|
|
||||||
return pair;
|
return pair;
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_setpair (
|
ase_pair_t* ase_map_setpair (
|
||||||
ase_awk_map_t* map, ase_awk_pair_t* pair, void* val)
|
ase_map_t* map, ase_pair_t* pair, void* val)
|
||||||
{
|
{
|
||||||
/* use this function with care */
|
/* use this function with care */
|
||||||
if (ASE_AWK_PAIR_VAL(pair) == val)
|
if (ASE_PAIR_VAL(pair) == val)
|
||||||
{
|
{
|
||||||
/* if the old value and the new value are the same,
|
/* if the old value and the new value are the same,
|
||||||
* it just calls the handler for this condition.
|
* it just calls the handler for this condition.
|
||||||
@ -231,21 +230,21 @@ ase_awk_pair_t* ase_awk_map_setpair (
|
|||||||
/* frees the old value */
|
/* frees the old value */
|
||||||
if (map->freeval != ASE_NULL)
|
if (map->freeval != ASE_NULL)
|
||||||
{
|
{
|
||||||
map->freeval (map->owner, ASE_AWK_PAIR_VAL(pair));
|
map->freeval (map->owner, ASE_PAIR_VAL(pair));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the new value takes the place */
|
/* the new value takes the place */
|
||||||
ASE_AWK_PAIR_VAL(pair) = val;
|
ASE_PAIR_VAL(pair) = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return pair;
|
return pair;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ase_awk_map_remove (
|
int ase_map_remove (
|
||||||
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen)
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair, * prev;
|
ase_pair_t* pair, * prev;
|
||||||
ase_size_t hc;
|
ase_size_t hc;
|
||||||
|
|
||||||
hc = hashkey(keyptr,keylen) % map->capa;
|
hc = hashkey(keyptr,keylen) % map->capa;
|
||||||
@ -255,12 +254,12 @@ int ase_awk_map_remove (
|
|||||||
while (pair != ASE_NULL)
|
while (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
if (ase_strxncmp (
|
if (ase_strxncmp (
|
||||||
ASE_AWK_PAIR_KEYPTR(pair), ASE_AWK_PAIR_KEYLEN(pair),
|
ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair),
|
||||||
keyptr, keylen) == 0)
|
keyptr, keylen) == 0)
|
||||||
{
|
{
|
||||||
if (prev == ASE_NULL)
|
if (prev == ASE_NULL)
|
||||||
map->buck[hc] = ASE_AWK_PAIR_LNK(pair);
|
map->buck[hc] = ASE_PAIR_LNK(pair);
|
||||||
else prev->next = ASE_AWK_PAIR_LNK(pair);
|
else prev->next = ASE_PAIR_LNK(pair);
|
||||||
|
|
||||||
FREE_PAIR (map, pair);
|
FREE_PAIR (map, pair);
|
||||||
map->size--;
|
map->size--;
|
||||||
@ -269,17 +268,17 @@ int ase_awk_map_remove (
|
|||||||
}
|
}
|
||||||
|
|
||||||
prev = pair;
|
prev = pair;
|
||||||
pair = ASE_AWK_PAIR_LNK(pair);
|
pair = ASE_PAIR_LNK(pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ase_awk_map_walk (ase_awk_map_t* map,
|
int ase_map_walk (ase_map_t* map,
|
||||||
int (*walker) (ase_awk_pair_t*,void*), void* arg)
|
int (*walker) (ase_pair_t*,void*), void* arg)
|
||||||
{
|
{
|
||||||
ase_size_t i;
|
ase_size_t i;
|
||||||
ase_awk_pair_t* pair, * next;
|
ase_pair_t* pair, * next;
|
||||||
|
|
||||||
for (i = 0; i < map->capa; i++)
|
for (i = 0; i < map->capa; i++)
|
||||||
{
|
{
|
||||||
@ -287,7 +286,7 @@ int ase_awk_map_walk (ase_awk_map_t* map,
|
|||||||
|
|
||||||
while (pair != ASE_NULL)
|
while (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
next = ASE_AWK_PAIR_LNK(pair);
|
next = ASE_PAIR_LNK(pair);
|
||||||
if (walker(pair,arg) == -1) return -1;
|
if (walker(pair,arg) == -1) return -1;
|
||||||
pair = next;
|
pair = next;
|
||||||
}
|
}
|
||||||
@ -296,11 +295,11 @@ int ase_awk_map_walk (ase_awk_map_t* map,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_getfirstpair (
|
ase_pair_t* ase_map_getfirstpair (
|
||||||
ase_awk_map_t* map, ase_size_t* buckno)
|
ase_map_t* map, ase_size_t* buckno)
|
||||||
{
|
{
|
||||||
ase_size_t i;
|
ase_size_t i;
|
||||||
ase_awk_pair_t* pair;
|
ase_pair_t* pair;
|
||||||
|
|
||||||
for (i = 0; i < map->capa; i++)
|
for (i = 0; i < map->capa; i++)
|
||||||
{
|
{
|
||||||
@ -315,13 +314,13 @@ ase_awk_pair_t* ase_awk_map_getfirstpair (
|
|||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_awk_pair_t* ase_awk_map_getnextpair (
|
ase_pair_t* ase_map_getnextpair (
|
||||||
ase_awk_map_t* map, ase_awk_pair_t* pair, ase_size_t* buckno)
|
ase_map_t* map, ase_pair_t* pair, ase_size_t* buckno)
|
||||||
{
|
{
|
||||||
ase_size_t i;
|
ase_size_t i;
|
||||||
ase_awk_pair_t* next;
|
ase_pair_t* next;
|
||||||
|
|
||||||
next = ASE_AWK_PAIR_LNK(pair);
|
next = ASE_PAIR_LNK(pair);
|
||||||
if (next != ASE_NULL)
|
if (next != ASE_NULL)
|
||||||
{
|
{
|
||||||
/* no change in bucket number */
|
/* no change in bucket number */
|
||||||
@ -357,15 +356,15 @@ static ase_size_t hashkey (const ase_char_t* keyptr, ase_size_t keylen)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rehash (ase_awk_map_t* map)
|
static int rehash (ase_map_t* map)
|
||||||
{
|
{
|
||||||
ase_size_t i, hc, new_capa;
|
ase_size_t i, hc, new_capa;
|
||||||
ase_awk_pair_t** new_buck;
|
ase_pair_t** new_buck;
|
||||||
|
|
||||||
new_capa = (map->capa >= 65536)? (map->capa + 65536): (map->capa << 1);
|
new_capa = (map->capa >= 65536)? (map->capa + 65536): (map->capa << 1);
|
||||||
|
|
||||||
new_buck = (ase_awk_pair_t**) ASE_AWK_MALLOC (
|
new_buck = (ase_pair_t**) ASE_MALLOC (
|
||||||
map->awk, ASE_SIZEOF(ase_awk_pair_t*) * new_capa);
|
map->mmgr, ASE_SIZEOF(ase_pair_t*) * new_capa);
|
||||||
if (new_buck == ASE_NULL)
|
if (new_buck == ASE_NULL)
|
||||||
{
|
{
|
||||||
/* once rehash fails, the rehashing is disabled */
|
/* once rehash fails, the rehashing is disabled */
|
||||||
@ -377,24 +376,24 @@ static int rehash (ase_awk_map_t* map)
|
|||||||
|
|
||||||
for (i = 0; i < map->capa; i++)
|
for (i = 0; i < map->capa; i++)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* pair = map->buck[i];
|
ase_pair_t* pair = map->buck[i];
|
||||||
|
|
||||||
while (pair != ASE_NULL)
|
while (pair != ASE_NULL)
|
||||||
{
|
{
|
||||||
ase_awk_pair_t* next = ASE_AWK_PAIR_LNK(pair);
|
ase_pair_t* next = ASE_PAIR_LNK(pair);
|
||||||
|
|
||||||
hc = hashkey(
|
hc = hashkey(
|
||||||
ASE_AWK_PAIR_KEYPTR(pair),
|
ASE_PAIR_KEYPTR(pair),
|
||||||
ASE_AWK_PAIR_KEYLEN(pair)) % new_capa;
|
ASE_PAIR_KEYLEN(pair)) % new_capa;
|
||||||
|
|
||||||
ASE_AWK_PAIR_LNK(pair) = new_buck[hc];
|
ASE_PAIR_LNK(pair) = new_buck[hc];
|
||||||
new_buck[hc] = pair;
|
new_buck[hc] = pair;
|
||||||
|
|
||||||
pair = next;
|
pair = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASE_AWK_FREE (map->awk, map->buck);
|
ASE_FREE (map->mmgr, map->buck);
|
||||||
map->buck = new_buck;
|
map->buck = new_buck;
|
||||||
map->capa = new_capa;
|
map->capa = new_capa;
|
||||||
map->threshold = ((ase_size_t)map->factor) * map->capa / 100;
|
map->threshold = ((ase_size_t)map->factor) * map->capa / 100;
|
133
ase/cmn/map.h
Normal file
133
ase/cmn/map.h
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* $Id: map.h,v 1.8 2007/09/30 15:12:20 bacon Exp $
|
||||||
|
*
|
||||||
|
* {License}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ASE_CMN_MAP_H_
|
||||||
|
#define _ASE_CMN_MAP_H_
|
||||||
|
|
||||||
|
#include <ase/cmn/types.h>
|
||||||
|
#include <ase/cmn/macros.h>
|
||||||
|
|
||||||
|
typedef struct ase_map_t ase_map_t;
|
||||||
|
typedef struct ase_pair_t ase_pair_t;
|
||||||
|
|
||||||
|
struct ase_pair_t
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ase_char_t* ptr;
|
||||||
|
ase_size_t len;
|
||||||
|
} key;
|
||||||
|
|
||||||
|
void* val;
|
||||||
|
|
||||||
|
/* used internally */
|
||||||
|
ase_pair_t* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ase_map_t
|
||||||
|
{
|
||||||
|
/* map owner. passed to freeval and sameval as the first argument */
|
||||||
|
void* owner;
|
||||||
|
|
||||||
|
ase_size_t size;
|
||||||
|
ase_size_t capa;
|
||||||
|
|
||||||
|
unsigned int factor;
|
||||||
|
ase_size_t threshold;
|
||||||
|
|
||||||
|
ase_pair_t** buck;
|
||||||
|
|
||||||
|
void (*freeval) (void* owner,void* val);
|
||||||
|
void (*sameval) (void* owner,void* val);
|
||||||
|
|
||||||
|
/* the mmgr pointed at by mmgr should be valid
|
||||||
|
* while the map is alive as the contents are
|
||||||
|
* not replicated */
|
||||||
|
ase_mmgr_t* mmgr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ASE_PAIR_KEYPTR(p) ((p)->key.ptr)
|
||||||
|
#define ASE_PAIR_KEYLEN(p) ((p)->key.len)
|
||||||
|
#define ASE_PAIR_VAL(p) ((p)->val)
|
||||||
|
#define ASE_PAIR_LNK(p) ((p)->next)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a hashed map with a dynamic array bucket and a list of values linked
|
||||||
|
*
|
||||||
|
* @param owner [in]
|
||||||
|
* @param capa [in]
|
||||||
|
* @param factor [in]
|
||||||
|
* @param freeval [in]
|
||||||
|
* @param sameval [in]
|
||||||
|
* @param mmgr [in]
|
||||||
|
*/
|
||||||
|
ase_map_t* ase_map_open (
|
||||||
|
void* owner, ase_size_t capa, unsigned int factor,
|
||||||
|
void(*freeval)(void*,void*), void(*sameval)(void*,void*),
|
||||||
|
ase_mmgr_t* mmgr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys a hashed map
|
||||||
|
*/
|
||||||
|
void ase_map_close (ase_map_t* map);
|
||||||
|
|
||||||
|
void ase_map_clear (ase_map_t* map);
|
||||||
|
|
||||||
|
ase_size_t ase_map_getsize (ase_map_t* map);
|
||||||
|
|
||||||
|
ase_pair_t* ase_map_get (
|
||||||
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen);
|
||||||
|
|
||||||
|
ase_pair_t* ase_map_put (
|
||||||
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
||||||
|
void* val);
|
||||||
|
|
||||||
|
int ase_map_putx (
|
||||||
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
||||||
|
void* val, ase_pair_t** px);
|
||||||
|
|
||||||
|
ase_pair_t* ase_map_set (
|
||||||
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
||||||
|
void* val);
|
||||||
|
|
||||||
|
ase_pair_t* ase_map_getpair (
|
||||||
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
||||||
|
void** val);
|
||||||
|
|
||||||
|
ase_pair_t* ase_map_setpair (
|
||||||
|
ase_map_t* map, ase_pair_t* pair, void* val);
|
||||||
|
|
||||||
|
int ase_map_remove (
|
||||||
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen);
|
||||||
|
|
||||||
|
int ase_map_walk (ase_map_t* map,
|
||||||
|
int (*walker)(ase_pair_t*,void*), void* arg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the pointer to the first pair in the map.
|
||||||
|
* @param map [in]
|
||||||
|
* @param buckno [out]
|
||||||
|
*/
|
||||||
|
ase_pair_t* ase_map_getfirstpair (
|
||||||
|
ase_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_pair_t* ase_map_getnextpair (
|
||||||
|
ase_map_t* map, ase_pair_t* pair, ase_size_t* buckno);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -23,6 +23,7 @@ TMP_DIR = $(MODE)
|
|||||||
OBJ_FILES_LIB = \
|
OBJ_FILES_LIB = \
|
||||||
$(TMP_DIR)\mem.obj \
|
$(TMP_DIR)\mem.obj \
|
||||||
$(TMP_DIR)\str.obj \
|
$(TMP_DIR)\str.obj \
|
||||||
|
$(TMP_DIR)\map.obj \
|
||||||
$(TMP_DIR)\misc.obj
|
$(TMP_DIR)\misc.obj
|
||||||
|
|
||||||
all: lib
|
all: lib
|
||||||
@ -40,6 +41,9 @@ $(TMP_DIR)\mem.obj: mem.c
|
|||||||
$(TMP_DIR)\str.obj: str.c
|
$(TMP_DIR)\str.obj: str.c
|
||||||
$(CC) $(CFLAGS) /Fo$@ /c str.c
|
$(CC) $(CFLAGS) /Fo$@ /c str.c
|
||||||
|
|
||||||
|
$(TMP_DIR)\map.obj: map.c
|
||||||
|
$(CC) $(CFLAGS) /Fo$@ /c map.c
|
||||||
|
|
||||||
$(TMP_DIR)\misc.obj: misc.c
|
$(TMP_DIR)\misc.obj: misc.c
|
||||||
$(CC) $(CFLAGS) /Fo$@ /c misc.c
|
$(CC) $(CFLAGS) /Fo$@ /c misc.c
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include <ase/awk/awk.h>
|
#include <ase/awk/awk.h>
|
||||||
#include <ase/awk/val.h>
|
#include <ase/awk/val.h>
|
||||||
#include <ase/awk/map.h>
|
|
||||||
|
|
||||||
#include <ase/utl/ctype.h>
|
#include <ase/utl/ctype.h>
|
||||||
#include <ase/utl/stdio.h>
|
#include <ase/utl/stdio.h>
|
||||||
@ -850,7 +849,7 @@ static void on_run_start (ase_awk_run_t* run, void* custom)
|
|||||||
dprintf (ASE_T("[AWK ABOUT TO START]\n"));
|
dprintf (ASE_T("[AWK ABOUT TO START]\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int print_awk_value (ase_awk_pair_t* pair, void* arg)
|
static int print_awk_value (ase_pair_t* pair, void* arg)
|
||||||
{
|
{
|
||||||
ase_awk_run_t* run = (ase_awk_run_t*)arg;
|
ase_awk_run_t* run = (ase_awk_run_t*)arg;
|
||||||
dprintf (ASE_T("%.*s = "), pair->key.len, pair->key.ptr);
|
dprintf (ASE_T("%.*s = "), pair->key.len, pair->key.ptr);
|
||||||
@ -873,7 +872,7 @@ static void on_run_return (
|
|||||||
dprintf (ASE_T("\n"));
|
dprintf (ASE_T("\n"));
|
||||||
|
|
||||||
dprintf (ASE_T("[NAMED VARIABLES]\n"));
|
dprintf (ASE_T("[NAMED VARIABLES]\n"));
|
||||||
ase_awk_map_walk (ase_awk_getrunnamedvarmap(run), print_awk_value, run);
|
ase_map_walk (ase_awk_getrunnamedvarmap(run), print_awk_value, run);
|
||||||
dprintf (ASE_T("[END NAMED VARIABLES]\n"));
|
dprintf (ASE_T("[END NAMED VARIABLES]\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user