This commit is contained in:
hyung-hwan 2008-07-21 23:27:34 +00:00
parent a2d5d649ba
commit b363d651b1
6 changed files with 62 additions and 45 deletions

View File

@ -1031,10 +1031,24 @@ static void handle_args (argc, argv)
typedef struct extension_t
{
ase_mmgr_t mmgr;
ase_awk_prmfns_t prmfns;
}
extension_t;
static void* fuser (void* org, void* space)
{
extension_t* ext = (extension_t*)space;
ext->mmgr = *(ase_mmgr_t*)org;
ext->prmfns.pow = custom_awk_pow;
ext->prmfns.sprintf = custom_awk_sprintf;
ext->prmfns.dprintf = custom_awk_dprintf;
ext->prmfns.custom_data = ASE_NULL;
return &ext->mmgr;
}
static int awk_main (int argc, ase_char_t* argv[])
{
ase_awk_t* awk;
@ -1094,7 +1108,7 @@ static int awk_main (int argc, ase_char_t* argv[])
mmgr.custom_data = ASE_NULL;
#endif
awk = ase_awk_open (&mmgr, ASE_SIZEOF(extension_t));
awk = ase_awk_open (&mmgr, ASE_SIZEOF(extension_t), fuser);
if (awk == ASE_NULL)
{
#ifdef _WIN32
@ -1107,16 +1121,9 @@ static int awk_main (int argc, ase_char_t* argv[])
app_awk = awk;
extension = (extension_t*) ase_awk_getextension (awk);
//extension->mmgr = mmgr;
extension->prmfns.pow = custom_awk_pow;
extension->prmfns.sprintf = custom_awk_sprintf;
extension->prmfns.dprintf = custom_awk_dprintf;
extension->prmfns.custom_data = ASE_NULL;
ase_awk_setccls (awk, ASE_GETCCLS());
ase_awk_setprmfns (awk, &extension->prmfns);
if (ase_awk_addfunc (awk,
ASE_T("sleep"), 5, 0,
1, 1, ASE_NULL, bfn_sleep) == ASE_NULL)

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 245 2008-07-15 05:56:32Z baconevi $
* $Id: Awk.hpp 279 2008-07-21 05:27:34Z baconevi $
*
* {License}
*/
@ -1104,6 +1104,10 @@ private:
Awk& operator= (const Awk&);
void triggerOnRunStart (Run& run);
ase_mmgr_t mmgr;
ase_ccls_t ccls;
ase_awk_prmfns_t prmfns;
};
/////////////////////////////////

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 278 2008-07-21 03:49:09Z baconevi $
* $Id: awk.h 279 2008-07-21 05:27:34Z baconevi $
*
* {License}
*/
@ -597,6 +597,12 @@ extern ase_awk_val_t* ase_awk_val_one;
* is valid until it is successfully destroyed using the ase_ase_close()
* function.
*
* The mmgr_fuser() function is called if mmgr_fuser is not ASE_NULL.
* It is passed two parameters; the memory manager pointer as passed
* into the ase_awk_open() function and the pointer to the extension
* area allocated. It should return the pointer to the location of the
* memory manager fused into the extension area.
*
* RETURNS the pointer to an ase_awk_t instance on success, ASE_NULL on failure
*/
ase_awk_t* ase_awk_open (

View File

@ -1,5 +1,5 @@
/*
* $Id: types.h 278 2008-07-21 03:49:09Z baconevi $
* $Id: types.h 279 2008-07-21 05:27:34Z baconevi $
*
* {License}
*/
@ -314,9 +314,10 @@ typedef int ase_mcint_t;
#endif
#endif
/* a fuser should fuse(copy and combine) the orginal data into the given space
/* ase_fuser_t is an abstract function type that can be used to
* fuse(copy and combine) the orginal data into the given space
* and return the pointer to its new location in the space */
typedef void* (*ase_fuser_t) (void* org, void* space, ase_size_t size);
typedef void* (*ase_fuser_t) (void* org, void* space);
typedef struct ase_cstr_t ase_cstr_t;
typedef struct ase_mmgr_t ase_mmgr_t;

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp 245 2008-07-15 05:56:32Z baconevi $
* $Id: Awk.cpp 279 2008-07-21 05:27:34Z baconevi $
*
* {License}
*/
@ -1028,6 +1028,31 @@ Awk::Awk (): awk (ASE_NULL), functionMap (ASE_NULL),
{
this->errmsg[0] = ASE_T('\0');
mmgr.malloc = allocMem;
mmgr.realloc = reallocMem;
mmgr.free = freeMem;
mmgr.custom_data = this;
ccls.is_upper = isUpper;
ccls.is_lower = isLower;
ccls.is_alpha = isAlpha;
ccls.is_digit = isDigit;
ccls.is_xdigit = isXdigit;
ccls.is_alnum = isAlnum;
ccls.is_space = isSpace;
ccls.is_print = isPrint;
ccls.is_graph = isGraph;
ccls.is_cntrl = isCntrl;
ccls.is_punct = isPunct;
ccls.to_upper = toUpper;
ccls.to_lower = toLower;
ccls.custom_data = this;
prmfns.pow = pow;
prmfns.sprintf = sprintf;
prmfns.dprintf = dprintf;
prmfns.custom_data = this;
}
Awk::~Awk ()
@ -1130,41 +1155,15 @@ int Awk::open ()
{
ASE_ASSERT (awk == ASE_NULL && functionMap == ASE_NULL);
ase_awk_prmfns_t prmfns;
prmfns.mmgr.malloc = allocMem;
prmfns.mmgr.realloc = reallocMem;
prmfns.mmgr.free = freeMem;
prmfns.mmgr.custom_data = this;
prmfns.ccls.is_upper = isUpper;
prmfns.ccls.is_lower = isLower;
prmfns.ccls.is_alpha = isAlpha;
prmfns.ccls.is_digit = isDigit;
prmfns.ccls.is_xdigit = isXdigit;
prmfns.ccls.is_alnum = isAlnum;
prmfns.ccls.is_space = isSpace;
prmfns.ccls.is_print = isPrint;
prmfns.ccls.is_graph = isGraph;
prmfns.ccls.is_cntrl = isCntrl;
prmfns.ccls.is_punct = isPunct;
prmfns.ccls.to_upper = toUpper;
prmfns.ccls.to_lower = toLower;
prmfns.ccls.custom_data = this;
prmfns.misc.pow = pow;
prmfns.misc.sprintf = sprintf;
prmfns.misc.dprintf = dprintf;
prmfns.misc.custom_data = this;
awk = ase_awk_open (&prmfns);
awk = ase_awk_open (&mmgr, 0, ASE_NULL);
if (awk == ASE_NULL)
{
setError (ERR_NOMEM);
return -1;
}
ase_awk_setassocdata (awk, this);
ase_awk_setccls (awk, &ccls);
ase_awk_setprmfns (awk, &prmfns);
functionMap = ase_map_open (
this, 512, 70, freeFunctionMapValue, ASE_NULL,

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 278 2008-07-21 03:49:09Z baconevi $
* $Id: awk.c 279 2008-07-21 05:27:34Z baconevi $
*
* {License}
*/
@ -37,7 +37,7 @@ ase_awk_t* ase_awk_open (
if (awk == ASE_NULL) return ASE_NULL;
ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t) + extension);
if (mmgr_fuser) mmgr = mmgr_fuser (mmgr, awk + 1, extension);
if (mmgr_fuser) mmgr = mmgr_fuser (mmgr, awk + 1);
awk->mmgr = mmgr;
if (ase_str_open (&awk->token.name, 128, mmgr) == ASE_NULL)