diff --git a/ase/cmd/awk/awk.c b/ase/cmd/awk/awk.c index 5b61f3eb..dfa0a493 100644 --- a/ase/cmd/awk/awk.c +++ b/ase/cmd/awk/awk.c @@ -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) diff --git a/ase/include/ase/awk/Awk.hpp b/ase/include/ase/awk/Awk.hpp index d00a15aa..b73b7221 100644 --- a/ase/include/ase/awk/Awk.hpp +++ b/ase/include/ase/awk/Awk.hpp @@ -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; }; ///////////////////////////////// diff --git a/ase/include/ase/awk/awk.h b/ase/include/ase/awk/awk.h index f3af2fe0..d63ba7b7 100644 --- a/ase/include/ase/awk/awk.h +++ b/ase/include/ase/awk/awk.h @@ -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 ( diff --git a/ase/include/ase/types.h b/ase/include/ase/types.h index 02ec0c58..1b4fe428 100644 --- a/ase/include/ase/types.h +++ b/ase/include/ase/types.h @@ -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; diff --git a/ase/lib/awk/Awk.cpp b/ase/lib/awk/Awk.cpp index ccdf49bb..329a92ad 100644 --- a/ase/lib/awk/Awk.cpp +++ b/ase/lib/awk/Awk.cpp @@ -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, diff --git a/ase/lib/awk/awk.c b/ase/lib/awk/awk.c index 92d6b182..f8ff60ac 100644 --- a/ase/lib/awk/awk.c +++ b/ase/lib/awk/awk.c @@ -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)