This commit is contained in:
hyung-hwan 2008-07-20 23:53:29 +00:00
parent 39d80c6e86
commit a665af8f49
12 changed files with 186 additions and 325 deletions

View File

@ -1,7 +1,5 @@
/* awk.h - functions to embed an AWK interpreter */
/* /*
* $Id: awk.h 269 2008-07-19 14:48:47Z baconevi $ * $Id: awk.h 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -67,7 +65,6 @@ struct ase_awk_extio_t
struct ase_awk_prmfns_t struct ase_awk_prmfns_t
{ {
ase_mmgr_t mmgr;
ase_ccls_t ccls; ase_ccls_t ccls;
struct struct
@ -606,11 +603,13 @@ extern ase_awk_val_t* ase_awk_val_one;
* is valid until it is successfully destroyed using the ase_ase_close() * is valid until it is successfully destroyed using the ase_ase_close()
* function. * function.
* *
* returns the pointer to an ase_awk_t instance on success, ASE_NULL on failure * RETURNS the pointer to an ase_awk_t instance on success, ASE_NULL on failure
*/ */
ase_awk_t* ase_awk_open ( ase_awk_t* ase_awk_open (
/* memory manager */ /* memory manager */
const ase_mmgr_t* mmgr ase_mmgr_t* mmgr,
/* size of extension area to allocate in bytes */
unsigned int extension;
); );
/* /*
@ -620,13 +619,49 @@ ase_awk_t* ase_awk_open (
* when finished being used. The instance passed is not valid any more once * when finished being used. The instance passed is not valid any more once
* the function returns success. * the function returns success.
* *
* returns 0 on success, -1 on failure * RETURNS 0 on success, -1 on failure
*/ */
int ase_awk_close ( int ase_awk_close (
/* the pointer to an ase_awk_t instance */ /* the pointer to an ase_awk_t instance */
ase_awk_t* awk ase_awk_t* awk
); );
/*
* get the pointer to the memory manager in use
* RETURNS the pointer to the memory manager set through ase_awk_open()
*/
ase_mmgr_t* ase_awk_getmmgr (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk
);
/*
* NAME
* get the pointer to extension area requested upon a call to ase_awk_open()
*
* DESCRIPTION
* The extension area is allocated in the ase_awk_open() function when it is
* given a positive extension size. The pointer to the beginning of the area
* can be acquired using the ase_awk_getextension() function and be utilized
* for various purposes.
*
* RETURNS the pointer to the extension area
*/
void* ase_awk_getextension (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk
);
/*
* set the character classfier
*/
void ase_awk_setccls (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk,
/* the pointer to a character classfiler */
ase_ccls_t* ccls
);
/* /*
* clear an ase_awk_t instance * clear an ase_awk_t instance
* *
@ -634,7 +669,7 @@ int ase_awk_close (
* you may call ase_awk_close instead of destroying and creating a new * you may call ase_awk_close instead of destroying and creating a new
* ase_awk_t instance using ase_awk_close() and ase_awk_open(). * ase_awk_t instance using ase_awk_close() and ase_awk_open().
* *
* returns 0 on success, -1 on failure * RETURNS 0 on success, -1 on failure
*/ */
int ase_awk_clear ( int ase_awk_clear (
/* the pointer to an ase_awk_t instance */ /* the pointer to an ase_awk_t instance */
@ -661,7 +696,7 @@ void ase_awk_setassocdata (
* The ase_awk_getassocdata() function is used to retrieve custom data * The ase_awk_getassocdata() function is used to retrieve custom data
* specified by a user with the ase_awk_setassocdata() function. * specified by a user with the ase_awk_setassocdata() function.
* *
* returns the pointer to the user-specified data through ase_awk_setassocdata * RETURNS the pointer to the user-specified data through ase_awk_setassocdata
* is returned. ASE_NULL is returned if ase_awk_setassocdata was never called. * is returned. ASE_NULL is returned if ase_awk_setassocdata was never called.
*/ */
void* ase_awk_getassocdata ( void* ase_awk_getassocdata (
@ -669,14 +704,6 @@ void* ase_awk_getassocdata (
ase_awk_t* awk ase_awk_t* awk
); );
/*
* return the pointer to the memory manager in use
* returns the pointer to the memory manager set through ase_awk_open
*/
ase_mmgr_t* ase_awk_getmmgr (
/* the pointer to an ase_awk_t instance */
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);
int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str); int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str);
@ -716,7 +743,7 @@ int ase_awk_getword (ase_awk_t* awk,
* it unsets the replacement for okw and olen. If all of them are valid, * it unsets the replacement for okw and olen. If all of them are valid,
* it sets the word replace for okw and olen to nkw and nlen. * it sets the word replace for okw and olen to nkw and nlen.
* *
* returns 0 on success, -1 on failure * RETURNS 0 on success, -1 on failure
*/ */
int ase_awk_setword ( int ase_awk_setword (
/* the pointer to an ase_awk_t instance */ /* the pointer to an ase_awk_t instance */
@ -734,7 +761,7 @@ int ase_awk_setword (
/* /*
* set the customized regular processing routine. (TODO: NOT YET IMPLEMENTED) * set the customized regular processing routine. (TODO: NOT YET IMPLEMENTED)
* *
* returns 0 on success, -1 on failure * RETURNS 0 on success, -1 on failure
*/ */
int ase_awk_setrexfns (ase_awk_t* awk, ase_awk_rexfns_t* rexfns); int ase_awk_setrexfns (ase_awk_t* awk, ase_awk_rexfns_t* rexfns);
@ -869,11 +896,66 @@ int ase_awk_clrrec (ase_awk_run_t* run, ase_bool_t skip_inrec_line);
int ase_awk_setrec (ase_awk_run_t* run, ase_size_t idx, const ase_char_t* str, ase_size_t len); int ase_awk_setrec (ase_awk_run_t* run, ase_size_t idx, const ase_char_t* str, ase_size_t len);
/* utility functions exported by awk.h */ /* utility functions exported by awk.h */
void* ase_awk_malloc (ase_awk_t* awk, ase_size_t size);
void ase_awk_free (ase_awk_t* awk, void* ptr);
ase_char_t* ase_awk_strxdup ( /*
ase_awk_t* awk, const ase_char_t* ptr, ase_size_t len); * NAME allocate dynamic memory
*
* DESCRIPTION
*
*
* RETURNS
* the pointer to the memory area allocated on success, ASE_NULL on failure
*/
void* ase_awk_malloc (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk,
/* the size of memory to allocate in bytes */
ase_size_t size
);
/*
* NAME free dynamic memory
*
* DESCRIPTION
*/
void ase_awk_free (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk,
/* the pointer to the memory area to free */
void* ptr
);
/*
* NAME duplicate a string
*
* DESCRIPTION
* The ase_awk_strdup() function is used to duplicate a string using
* the memory manager used by the associated ase_awk_t instance.
* The new string should be freed using the ase_awk_free() function.
*
* RETURNS
* The pointer to a new string which is a duplicate of the string s.
*/
ase_char_t* ase_awk_strdup (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk,
/* the pointer to a string */
const ase_char_t* s
);
/*
* NAME duplicate a string of a length given
*
* DESCRIPTION
* The ase_awk_strdup() function is used to duplicate a string whose length
* is as long as l characters using the memory manager used by the associated
* ase_awk_t instance. The new string should be freed using the ase_awk_free()
* function.
*
* RETURNS
* The pointer to a new string which is a duplicate of the string s.
*/
ase_char_t* ase_awk_strxdup (ase_awk_t* awk, const ase_char_t* s, ase_size_t l);
ase_long_t ase_awk_strxtolong ( ase_long_t ase_awk_strxtolong (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len, ase_awk_t* awk, const ase_char_t* str, ase_size_t len,

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c 268 2008-07-19 08:03:49Z baconevi $ * $Id: awk.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -24,229 +24,7 @@ static void free_bfn (void* awk, void* afn);
ase_awk_seterror ((awk), (code), (line), &errarg, 1); \ ase_awk_seterror ((awk), (code), (line), &errarg, 1); \
} while (0) } while (0)
#if 0 ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr, unsigned int extension)
ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns)
{
ase_awk_t* awk;
ASE_ASSERT (prmfns != ASE_NULL);
ASE_ASSERT (prmfns->mmgr.malloc != ASE_NULL &&
prmfns->mmgr.free != ASE_NULL);
ASE_ASSERT (prmfns->ccls.is_upper != ASE_NULL &&
prmfns->ccls.is_lower != ASE_NULL &&
prmfns->ccls.is_alpha != ASE_NULL &&
prmfns->ccls.is_digit != ASE_NULL &&
prmfns->ccls.is_xdigit != ASE_NULL &&
prmfns->ccls.is_alnum != ASE_NULL &&
prmfns->ccls.is_space != ASE_NULL &&
prmfns->ccls.is_print != ASE_NULL &&
prmfns->ccls.is_graph != ASE_NULL &&
prmfns->ccls.is_cntrl != ASE_NULL &&
prmfns->ccls.is_punct != ASE_NULL &&
prmfns->ccls.to_upper != ASE_NULL &&
prmfns->ccls.to_lower != ASE_NULL);
ASE_ASSERT (prmfns->misc.pow != ASE_NULL &&
prmfns->misc.sprintf != ASE_NULL &&
prmfns->misc.dprintf != ASE_NULL);
/* use ASE_MALLOC instead of ASE_AWK_MALLOC because
* the awk object has not been initialized yet */
awk = ASE_MALLOC (&prmfns->mmgr, ASE_SIZEOF(ase_awk_t));
if (awk == ASE_NULL) return ASE_NULL;
/* it uses the built-in ase_awk_memset because awk is not
* fully initialized yet */
ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t));
ase_memcpy (&awk->prmfns, prmfns, ASE_SIZEOF(awk->prmfns));
if (ase_str_open (
&awk->token.name, 128, &awk->prmfns.mmgr) == ASE_NULL)
{
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->wtab = ase_map_open (
awk, 512, 70, free_word, ASE_NULL, &awk->prmfns.mmgr);
if (awk->wtab == ASE_NULL)
{
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->rwtab = ase_map_open (
awk, 512, 70, free_word, ASE_NULL, &awk->prmfns.mmgr);
if (awk->rwtab == ASE_NULL)
{
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
/* TODO: initial map size?? */
awk->tree.afns = ase_map_open (
awk, 512, 70, free_afn, ASE_NULL, &awk->prmfns.mmgr);
if (awk->tree.afns == ASE_NULL)
{
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->parse.afns = ase_map_open (
awk, 256, 70, ASE_NULL, ASE_NULL, &awk->prmfns.mmgr);
if (awk->parse.afns == ASE_NULL)
{
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->parse.named = ase_map_open (
awk, 256, 70, ASE_NULL, ASE_NULL, &awk->prmfns.mmgr);
if (awk->parse.named == ASE_NULL)
{
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
{
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_tab_open (&awk->parse.locals, awk) == ASE_NULL)
{
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_tab_open (&awk->parse.params, awk) == ASE_NULL)
{
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->option = 0;
awk->errnum = ASE_AWK_ENOERR;
awk->errlin = 0;
awk->stopall = ASE_FALSE;
awk->parse.nlocals_max = 0;
awk->tree.nglobals = 0;
awk->tree.nbglobals = 0;
awk->tree.begin = ASE_NULL;
awk->tree.begin_tail = ASE_NULL;
awk->tree.end = ASE_NULL;
awk->tree.end_tail = ASE_NULL;
awk->tree.chain = ASE_NULL;
awk->tree.chain_tail = ASE_NULL;
awk->tree.chain_size = 0;
awk->token.prev.type = 0;
awk->token.prev.line = 0;
awk->token.prev.column = 0;
awk->token.type = 0;
awk->token.line = 0;
awk->token.column = 0;
awk->src.lex.curc = ASE_CHAR_EOF;
awk->src.lex.ungotc_count = 0;
awk->src.lex.line = 1;
awk->src.lex.column = 1;
awk->src.shared.buf_pos = 0;
awk->src.shared.buf_len = 0;
awk->bfn.sys = ASE_NULL;
/*awk->bfn.user = ASE_NULL;*/
awk->bfn.user = ase_map_open (
awk, 512, 70, free_bfn, ASE_NULL, &awk->prmfns.mmgr);
if (awk->bfn.user == ASE_NULL)
{
ase_awk_tab_close (&awk->parse.params);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->parse.depth.cur.block = 0;
awk->parse.depth.cur.loop = 0;
awk->parse.depth.cur.expr = 0;
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_BLOCK_PARSE, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_BLOCK_RUN, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_EXPR_PARSE, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_EXPR_RUN, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_BUILD, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_MATCH, 0);
awk->assoc_data = ASE_NULL;
if (ase_awk_initglobals (awk) == -1)
{
ase_map_close (awk->bfn.user);
ase_awk_tab_close (&awk->parse.params);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.globals);
ase_map_close (awk->parse.named);
ase_map_close (awk->parse.afns);
ase_map_close (awk->tree.afns);
ase_map_close (awk->rwtab);
ase_map_close (awk->wtab);
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
return awk;
}
#endif
ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr)
{ {
ase_awk_t* awk; ase_awk_t* awk;
@ -254,26 +32,21 @@ ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr)
ASE_ASSERT (mmgr->malloc != ASE_NULL); ASE_ASSERT (mmgr->malloc != ASE_NULL);
ASE_ASSERT (mmgr->free != ASE_NULL); ASE_ASSERT (mmgr->free != ASE_NULL);
/* use ASE_MALLOC instead of ASE_AWK_MALLOC because awk = ASE_MALLOC (mmgr, ASE_SIZEOF(ase_awk_t) + extension);
* the awk object has not been initialized yet */
awk = ASE_MALLOC (mmgr, ASE_SIZEOF(ase_awk_t));
if (awk == ASE_NULL) return ASE_NULL; if (awk == ASE_NULL) return ASE_NULL;
/* it uses the built-in ase_awk_memset because awk is not /* it uses the built-in ase_awk_memset because awk is not
* fully initialized yet */ * fully initialized yet */
ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t)); ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t));
awk->prmfns.mmgr = *mmgr; awk->mmgr = mmgr;
//ase_memcpy (&awk->prmfns, prmfns, ASE_SIZEOF(awk->prmfns));
if (ase_str_open ( if (ase_str_open (&awk->token.name, 128, mmgr) == ASE_NULL)
&awk->token.name, 128, &awk->prmfns.mmgr) == ASE_NULL)
{ {
ASE_AWK_FREE (awk, awk); ASE_AWK_FREE (awk, awk);
return ASE_NULL; return ASE_NULL;
} }
awk->wtab = ase_map_open ( awk->wtab = ase_map_open (awk, 512, 70, free_word, ASE_NULL, mmgr);
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);
@ -281,8 +54,7 @@ ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr)
return ASE_NULL; return ASE_NULL;
} }
awk->rwtab = ase_map_open ( awk->rwtab = ase_map_open (awk, 512, 70, free_word, ASE_NULL, mmgr);
awk, 512, 70, free_word, ASE_NULL, &awk->prmfns.mmgr);
if (awk->rwtab == ASE_NULL) if (awk->rwtab == ASE_NULL)
{ {
ase_map_close (awk->wtab); ase_map_close (awk->wtab);
@ -292,8 +64,7 @@ ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr)
} }
/* TODO: initial map size?? */ /* TODO: initial map size?? */
awk->tree.afns = ase_map_open ( awk->tree.afns = ase_map_open (awk, 512, 70, free_afn, ASE_NULL, mmgr);
awk, 512, 70, free_afn, ASE_NULL, &awk->prmfns.mmgr);
if (awk->tree.afns == ASE_NULL) if (awk->tree.afns == ASE_NULL)
{ {
ase_map_close (awk->rwtab); ase_map_close (awk->rwtab);
@ -303,8 +74,7 @@ ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr)
return ASE_NULL; return ASE_NULL;
} }
awk->parse.afns = ase_map_open ( awk->parse.afns = ase_map_open (awk, 256, 70, ASE_NULL, ASE_NULL, mmgr);
awk, 256, 70, ASE_NULL, ASE_NULL, &awk->prmfns.mmgr);
if (awk->parse.afns == ASE_NULL) if (awk->parse.afns == ASE_NULL)
{ {
ase_map_close (awk->tree.afns); ase_map_close (awk->tree.afns);
@ -315,8 +85,7 @@ ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr)
return ASE_NULL; return ASE_NULL;
} }
awk->parse.named = ase_map_open ( awk->parse.named = ase_map_open (awk, 256, 70, ASE_NULL, ASE_NULL, mmgr);
awk, 256, 70, ASE_NULL, ASE_NULL, &awk->prmfns.mmgr);
if (awk->parse.named == ASE_NULL) if (awk->parse.named == ASE_NULL)
{ {
ase_map_close (awk->parse.afns); ase_map_close (awk->parse.afns);
@ -400,8 +169,7 @@ ase_awk_t* ase_awk_open (const ase_mmgr_t* mmgr)
awk->bfn.sys = ASE_NULL; awk->bfn.sys = ASE_NULL;
/*awk->bfn.user = ASE_NULL;*/ /*awk->bfn.user = ASE_NULL;*/
awk->bfn.user = ase_map_open ( awk->bfn.user = ase_map_open (awk, 512, 70, free_bfn, ASE_NULL, mmgr);
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);
@ -579,6 +347,16 @@ int ase_awk_clear (ase_awk_t* awk)
return 0; return 0;
} }
ase_mmgr_t* ase_awk_getmmgr (ase_awk_t* awk)
{
return awk->mmgr;
}
void* ase_awk_getextension (ase_awk_t* awk)
{
return (void*)(awk + 1);
}
void ase_awk_setassocdata (ase_awk_t* awk, void* data) void ase_awk_setassocdata (ase_awk_t* awk, void* data)
{ {
awk->assoc_data = data; awk->assoc_data = data;
@ -599,10 +377,6 @@ 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_stopall (ase_awk_t* awk) void ase_awk_stopall (ase_awk_t* awk)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk_i.h 237 2008-07-09 13:20:08Z baconevi $ * $Id: awk_i.h 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -33,9 +33,9 @@ typedef struct ase_awk_tree_t ase_awk_tree_t;
#define ASE_AWK_MAX_LOCALS 9999 #define ASE_AWK_MAX_LOCALS 9999
#define ASE_AWK_MAX_PARAMS 9999 #define ASE_AWK_MAX_PARAMS 9999
#define ASE_AWK_MALLOC(awk,size) ASE_MALLOC(&(awk)->prmfns.mmgr,size) #define ASE_AWK_MALLOC(awk,size) ASE_MALLOC((awk)->mmgr,size)
#define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC(&(awk)->prmfns.mmgr,ptr,size) #define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC((awk)->mmgr,ptr,size)
#define ASE_AWK_FREE(awk,ptr) ASE_FREE(&(awk)->prmfns.mmgr,ptr) #define ASE_AWK_FREE(awk,ptr) ASE_FREE((awk)->mmgr,ptr)
#define ASE_AWK_ISUPPER(awk,c) ASE_ISUPPER(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISUPPER(awk,c) ASE_ISUPPER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISLOWER(awk,c) ASE_ISLOWER(&(awk)->prmfns.ccls,c) #define ASE_AWK_ISLOWER(awk,c) ASE_ISLOWER(&(awk)->prmfns.ccls,c)
@ -51,6 +51,9 @@ typedef struct ase_awk_tree_t ase_awk_tree_t;
#define ASE_AWK_TOUPPER(awk,c) ASE_TOUPPER(&(awk)->prmfns.ccls,c) #define ASE_AWK_TOUPPER(awk,c) ASE_TOUPPER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_TOLOWER(awk,c) ASE_TOLOWER(&(awk)->prmfns.ccls,c) #define ASE_AWK_TOLOWER(awk,c) ASE_TOLOWER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_STRDUP(awk,str) (ase_strdup(str,(awk)->mmgr))
#define ASE_AWK_STRXDUP(awk,str,len) (ase_strxdup(str,len,(awk)->mmgr))
struct ase_awk_tree_t struct ase_awk_tree_t
{ {
ase_size_t nglobals; /* total number of globals */ ase_size_t nglobals; /* total number of globals */
@ -73,6 +76,9 @@ struct ase_awk_tree_t
struct ase_awk_t struct ase_awk_t
{ {
ase_mmgr_t* mmgr;
ase_ccls_t* ccls;
ase_awk_prmfns_t prmfns; ase_awk_prmfns_t prmfns;
void* assoc_data; void* assoc_data;
@ -365,7 +371,7 @@ struct ase_awk_run_t
}; };
#define ASE_AWK_FREEREX(awk,code) ase_freerex(&(awk)->prmfns.mmgr,code) #define ASE_AWK_FREEREX(awk,code) ase_freerex((awk)->mmgr,code)
#define ASE_AWK_ISEMPTYREX(awk,code) ase_isemptyrex(code) #define ASE_AWK_ISEMPTYREX(awk,code) ase_isemptyrex(code)
#define ASE_AWK_BUILDREX(awk,ptn,len,errnum) \ #define ASE_AWK_BUILDREX(awk,ptn,len,errnum) \
ase_awk_buildrex(awk,ptn,len,errnum) ase_awk_buildrex(awk,ptn,len,errnum)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: err.c 229 2008-06-26 10:46:39Z baconevi $ * $Id: err.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -176,7 +176,7 @@ int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str)
if (str == ASE_NULL) dup = ASE_NULL; if (str == ASE_NULL) dup = ASE_NULL;
else else
{ {
dup = ase_strdup (str, &awk->prmfns.mmgr); dup = ASE_STRDUP(awk, str);
if (dup == ASE_NULL) return -1; if (dup == ASE_NULL) return -1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: extio.c 197 2008-06-09 06:24:10Z baconevi $ * $Id: extio.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -122,7 +122,7 @@ int ase_awk_readextio (
return -1; return -1;
} }
p->name = ase_strdup (name, &run->awk->prmfns.mmgr); p->name = ASE_AWK_STRDUP (run->awk, name);
if (p->name == ASE_NULL) if (p->name == ASE_NULL)
{ {
ASE_AWK_FREE (run->awk, p); ASE_AWK_FREE (run->awk, p);
@ -478,7 +478,7 @@ int ase_awk_writeextio_str (
return -1; return -1;
} }
p->name = ase_strdup (name, &run->awk->prmfns.mmgr); p->name = ASE_AWK_STRDUP (run->awk, name);
if (p->name == ASE_NULL) if (p->name == ASE_NULL)
{ {
ASE_AWK_FREE (run->awk, p); ASE_AWK_FREE (run->awk, p);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: func.c 192 2008-06-06 10:33:44Z baconevi $ * $Id: func.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -1044,7 +1044,7 @@ static int __substitute (ase_awk_run_t* run, ase_long_t max_count)
} }
} }
if (ase_str_open (&new, a2_len, &run->awk->prmfns.mmgr) == ASE_NULL) if (ase_str_open (&new, a2_len, run->awk->mmgr) == ASE_NULL)
{ {
FREE_A_PTRS (run->awk); FREE_A_PTRS (run->awk);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
@ -1347,12 +1347,12 @@ static int bfn_sprintf (
nargs = ase_awk_getnargs (run); nargs = ase_awk_getnargs (run);
ASE_ASSERT (nargs > 0); ASE_ASSERT (nargs > 0);
if (ase_str_open (&out, 256, &run->awk->prmfns.mmgr) == ASE_NULL) if (ase_str_open (&out, 256, run->awk->mmgr) == ASE_NULL)
{ {
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1; return -1;
} }
if (ase_str_open (&fbu, 256, &run->awk->prmfns.mmgr) == ASE_NULL) if (ase_str_open (&fbu, 256, run->awk->mmgr) == ASE_NULL)
{ {
ase_str_close (&out); ase_str_close (&out);
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: misc.c 192 2008-06-06 10:33:44Z baconevi $ * $Id: misc.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -16,10 +16,14 @@ void ase_awk_free (ase_awk_t* awk, void* ptr)
ASE_AWK_FREE (awk, ptr); ASE_AWK_FREE (awk, ptr);
} }
ase_char_t* ase_awk_strxdup ( ase_char_t* ase_awk_strdup (ase_awk_t* awk, const ase_char_t* s)
ase_awk_t* awk, const ase_char_t* ptr, ase_size_t len)
{ {
return ase_strxdup (ptr, len, &awk->prmfns.mmgr); return ASE_AWK_STRDUP (awk, s);
}
ase_char_t* ase_awk_strxdup (ase_awk_t* awk, const ase_char_t* s, ase_size_t l)
{
return ASE_AWK_STRXDUP (awk, s, l);
} }
ase_long_t ase_awk_strxtolong ( ase_long_t ase_awk_strxtolong (
@ -932,7 +936,7 @@ void* ase_awk_buildrex (
void* p; void* p;
p = ase_buildrex ( p = ase_buildrex (
&awk->prmfns.mmgr, awk->rex.depth.max.build, ptn, len, &err); awk->mmgr, awk->rex.depth.max.build, ptn, len, &err);
if (p == ASE_NULL) *errnum = ASE_AWK_REXERRTOERR(err); if (p == ASE_NULL) *errnum = ASE_AWK_REXERRTOERR(err);
return p; return p;
} }
@ -945,7 +949,7 @@ int ase_awk_matchrex (
int err, x; int err, x;
x = ase_matchrex ( x = ase_matchrex (
&awk->prmfns.mmgr, &awk->prmfns.ccls, awk->rex.depth.max.match, awk->mmgr, &awk->prmfns.ccls, awk->rex.depth.max.match,
code, option, str, len, match_ptr, match_len, &err); code, option, str, len, match_ptr, match_len, &err);
if (x < 0) *errnum = ASE_AWK_REXERRTOERR(err); if (x < 0) *errnum = ASE_AWK_REXERRTOERR(err);
return x; return x;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c 256 2008-07-18 12:54:19Z baconevi $ * $Id: parse.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -868,7 +868,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
#endif #endif
/* clone the function name before it is overwritten */ /* clone the function name before it is overwritten */
name_dup = ase_awk_strxdup (awk, name, name_len); name_dup = ASE_AWK_STRXDUP (awk, name, name_len);
if (name_dup == ASE_NULL) if (name_dup == ASE_NULL)
{ {
SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line); SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line);
@ -2775,7 +2775,7 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
nde->val = ase_awk_strxtolong (awk, nde->val = ase_awk_strxtolong (awk,
ASE_STR_BUF(&awk->token.name), ASE_STR_BUF(&awk->token.name),
ASE_STR_LEN(&awk->token.name), 0, ASE_NULL); ASE_STR_LEN(&awk->token.name), 0, ASE_NULL);
nde->str = ase_awk_strxdup (awk, nde->str = ASE_AWK_STRXDUP (awk,
ASE_STR_BUF(&awk->token.name), ASE_STR_BUF(&awk->token.name),
ASE_STR_LEN(&awk->token.name)); ASE_STR_LEN(&awk->token.name));
if (nde->str == ASE_NULL) if (nde->str == ASE_NULL)
@ -2816,7 +2816,7 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
nde->val = ase_awk_strxtoreal (awk, nde->val = ase_awk_strxtoreal (awk,
ASE_STR_BUF(&awk->token.name), ASE_STR_BUF(&awk->token.name),
ASE_STR_LEN(&awk->token.name), ASE_NULL); ASE_STR_LEN(&awk->token.name), ASE_NULL);
nde->str = ase_awk_strxdup (awk, nde->str = ASE_AWK_STRXDUP (awk,
ASE_STR_BUF(&awk->token.name), ASE_STR_BUF(&awk->token.name),
ASE_STR_LEN(&awk->token.name)); ASE_STR_LEN(&awk->token.name));
if (nde->str == ASE_NULL) if (nde->str == ASE_NULL)
@ -2855,7 +2855,7 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
nde->line = line; nde->line = line;
nde->next = ASE_NULL; nde->next = ASE_NULL;
nde->len = ASE_STR_LEN(&awk->token.name); nde->len = ASE_STR_LEN(&awk->token.name);
nde->buf = ase_awk_strxdup (awk, nde->buf = ASE_AWK_STRXDUP (awk,
ASE_STR_BUF(&awk->token.name), nde->len); ASE_STR_BUF(&awk->token.name), nde->len);
if (nde->buf == ASE_NULL) if (nde->buf == ASE_NULL)
{ {
@ -2899,7 +2899,7 @@ static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line)
nde->next = ASE_NULL; nde->next = ASE_NULL;
nde->len = ASE_STR_LEN(&awk->token.name); nde->len = ASE_STR_LEN(&awk->token.name);
nde->buf = ase_awk_strxdup (awk, nde->buf = ASE_AWK_STRXDUP (awk,
ASE_STR_BUF(&awk->token.name), ASE_STR_BUF(&awk->token.name),
ASE_STR_LEN(&awk->token.name)); ASE_STR_LEN(&awk->token.name));
if (nde->buf == ASE_NULL) if (nde->buf == ASE_NULL)
@ -3123,7 +3123,7 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
ASE_ASSERT (MATCH(awk,TOKEN_IDENT)); ASE_ASSERT (MATCH(awk,TOKEN_IDENT));
name_dup = ase_awk_strxdup (awk, name_dup = ASE_AWK_STRXDUP (awk,
ASE_STR_BUF(&awk->token.name), ASE_STR_BUF(&awk->token.name),
ASE_STR_LEN(&awk->token.name)); ASE_STR_LEN(&awk->token.name));
if (name_dup == ASE_NULL) if (name_dup == ASE_NULL)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: rec.c 197 2008-06-09 06:24:10Z baconevi $ * $Id: rec.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -296,7 +296,7 @@ static int recomp_record_fields (
* number of fields that the current record can hold, * number of fields that the current record can hold,
* the field spaces are resized */ * the field spaces are resized */
if (run->awk->prmfns.mmgr.realloc != ASE_NULL) if (run->awk->mmgr->realloc != ASE_NULL)
{ {
tmp = ASE_AWK_REALLOC ( tmp = ASE_AWK_REALLOC (
run->awk, run->inrec.flds, run->awk, run->inrec.flds,

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c 246 2008-07-15 07:06:43Z baconevi $ * $Id: run.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -16,6 +16,8 @@
#define IDXBUFSIZE 64 #define IDXBUFSIZE 64
#define MMGR(run) ((run)->awk->mmgr)
#define STACK_AT(run,n) ((run)->stack[(run)->stack_base+(n)]) #define STACK_AT(run,n) ((run)->stack[(run)->stack_base+(n)])
#define STACK_NARGS(run) (STACK_AT(run,3)) #define STACK_NARGS(run) (STACK_AT(run,3))
#define STACK_ARG(run,n) STACK_AT(run,3+1+(n)) #define STACK_ARG(run,n) STACK_AT(run,3+1+(n))
@ -763,23 +765,20 @@ static int init_run (
run->inrec.maxflds = 0; run->inrec.maxflds = 0;
run->inrec.d0 = ase_awk_val_nil; run->inrec.d0 = ase_awk_val_nil;
if (ase_str_open ( if (ase_str_open (
&run->inrec.line, &run->inrec.line, DEF_BUF_CAPA, MMGR(run)) == ASE_NULL)
DEF_BUF_CAPA, &run->awk->prmfns.mmgr) == ASE_NULL)
{ {
ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
if (ase_str_open ( if (ase_str_open (&run->format.out, 256, MMGR(run)) == ASE_NULL)
&run->format.out, 256, &run->awk->prmfns.mmgr) == ASE_NULL)
{ {
ase_str_close (&run->inrec.line); ase_str_close (&run->inrec.line);
ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1; return -1;
} }
if (ase_str_open ( if (ase_str_open (&run->format.fmt, 256, MMGR(run)) == ASE_NULL)
&run->format.fmt, 256, &run->awk->prmfns.mmgr) == ASE_NULL)
{ {
ase_str_close (&run->format.out); ase_str_close (&run->format.out);
ase_str_close (&run->inrec.line); ase_str_close (&run->inrec.line);
@ -788,8 +787,7 @@ static int init_run (
} }
run->named = ase_map_open ( run->named = ase_map_open (
run, 1024, 70, free_namedval, same_namedval, run, 1024, 70, free_namedval, same_namedval, MMGR(run));
&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);
@ -1314,7 +1312,7 @@ static int run_main (
} }
tmp->type = ASE_AWK_NDE_STR; tmp->type = ASE_AWK_NDE_STR;
tmp->buf = ase_awk_strxdup (run->awk, tmp->buf = ASE_AWK_STRXDUP (run->awk,
runarg[i].ptr, runarg[i].len); runarg[i].ptr, runarg[i].len);
if (tmp->buf == ASE_NULL) if (tmp->buf == ASE_NULL)
{ {
@ -6206,7 +6204,7 @@ static ase_awk_val_t* eval_getline (ase_awk_run_t* run, ase_awk_nde_t* nde)
dst = (in == ASE_NULL)? ASE_T(""): in; dst = (in == ASE_NULL)? ASE_T(""): in;
/* TODO: optimize the line buffer management */ /* TODO: optimize the line buffer management */
if (ase_str_open (&buf, DEF_BUF_CAPA, &run->awk->prmfns.mmgr) == ASE_NULL) if (ase_str_open (&buf, DEF_BUF_CAPA, MMGR(run)) == ASE_NULL)
{ {
if (in != ASE_NULL) ASE_AWK_FREE (run->awk, in); if (in != ASE_NULL) ASE_AWK_FREE (run->awk, in);
ase_awk_setrunerror ( ase_awk_setrunerror (
@ -6280,7 +6278,7 @@ static int __raw_push (ase_awk_run_t* run, void* val)
n = run->stack_limit + STACK_INCREMENT; n = run->stack_limit + STACK_INCREMENT;
if (run->awk->prmfns.mmgr.realloc != ASE_NULL) if (MMGR(run)->realloc != ASE_NULL)
{ {
tmp = (void**) ASE_AWK_REALLOC ( tmp = (void**) ASE_AWK_REALLOC (
run->awk, run->stack, n * ASE_SIZEOF(void*)); run->awk, run->stack, n * ASE_SIZEOF(void*));
@ -6386,8 +6384,7 @@ static int shorten_record (ase_awk_run_t* run, ase_size_t nflds)
} }
if (ase_str_open ( if (ase_str_open (
&tmp, ASE_STR_LEN(&run->inrec.line), &tmp, ASE_STR_LEN(&run->inrec.line), MMGR(run)) == ASE_NULL)
&run->awk->prmfns.mmgr) == ASE_NULL)
{ {
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return -1; return -1;
@ -6487,9 +6484,7 @@ static ase_char_t* idxnde_to_str (
/* multidimensional index */ /* multidimensional index */
ase_str_t idxstr; ase_str_t idxstr;
if (ase_str_open ( if (ase_str_open (&idxstr, DEF_BUF_CAPA, MMGR(run)) == ASE_NULL)
&idxstr, DEF_BUF_CAPA,
&run->awk->prmfns.mmgr) == ASE_NULL)
{ {
ase_awk_setrunerror ( ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: tab.c 197 2008-06-09 06:24:10Z baconevi $ * $Id: tab.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -60,7 +60,7 @@ ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa)
if (capa > 0) if (capa > 0)
{ {
if (tab->awk->prmfns.mmgr.realloc != ASE_NULL) if (tab->awk->mmgr->realloc != ASE_NULL)
{ {
tmp = ASE_AWK_REALLOC (tab->awk, tmp = ASE_AWK_REALLOC (tab->awk,
tab->buf, ASE_SIZEOF(*tab->buf) * capa); tab->buf, ASE_SIZEOF(*tab->buf) * capa);
@ -116,7 +116,7 @@ ase_size_t ase_awk_tab_insert (
ase_size_t i; ase_size_t i;
ase_char_t* dup; ase_char_t* dup;
dup = ase_awk_strxdup (tab->awk, str, len); dup = ASE_AWK_STRXDUP (tab->awk, str, len);
if (dup == ASE_NULL) return (ase_size_t)-1; if (dup == ASE_NULL) return (ase_size_t)-1;
if (index >= tab->capa) if (index >= tab->capa)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.c 237 2008-07-09 13:20:08Z baconevi $ * $Id: val.c 270 2008-07-20 05:53:29Z baconevi $
* *
* {License} * {License}
*/ */
@ -379,7 +379,7 @@ ase_awk_val_t* ase_awk_makerexval (
val->ref = 0; val->ref = 0;
val->len = len; val->len = len;
/* /*
val->buf = ase_awk_strxdup (run->awk, buf, len); val->buf = ASE_AWK_STRXDUP (run->awk, buf, len);
if (val->buf == ASE_NULL) if (val->buf == ASE_NULL)
{ {
ASE_AWK_FREE (run->awk, val); ASE_AWK_FREE (run->awk, val);
@ -441,7 +441,7 @@ 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_map_open ( val->map = ase_map_open (
run, 256, 70, free_mapval, same_mapval, &run->awk->prmfns.mmgr); run, 256, 70, free_mapval, same_mapval, run->awk->mmgr);
if (val->map == ASE_NULL) if (val->map == ASE_NULL)
{ {
ASE_AWK_FREE (run->awk, val); ASE_AWK_FREE (run->awk, val);
@ -732,7 +732,7 @@ static ase_char_t* str_to_str (
if (buf == ASE_NULL) if (buf == ASE_NULL)
{ {
ase_char_t* tmp; ase_char_t* tmp;
tmp = ase_awk_strxdup (run->awk, str, str_len); tmp = ASE_AWK_STRXDUP (run->awk, str, str_len);
if (tmp == ASE_NULL) if (tmp == ASE_NULL)
{ {
ase_awk_setrunerror ( ase_awk_setrunerror (
@ -927,13 +927,13 @@ static ase_char_t* val_real_to_str (
tmp_len = run->global.convfmt.len; tmp_len = run->global.convfmt.len;
} }
if (ase_str_open (&out, 256, &run->awk->prmfns.mmgr) == ASE_NULL) if (ase_str_open (&out, 256, run->awk->mmgr) == ASE_NULL)
{ {
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL; return ASE_NULL;
} }
if (ase_str_open (&fbu, 256, &run->awk->prmfns.mmgr) == ASE_NULL) if (ase_str_open (&fbu, 256, run->awk->mmgr) == ASE_NULL)
{ {
ase_str_close (&out); ase_str_close (&out);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);