added useful macros to ase_str_t and ase_map_t

This commit is contained in:
hyung-hwan 2008-09-25 02:16:41 +00:00
parent dfc1e83f7c
commit 327fd11974
5 changed files with 36 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: map.h 376 2008-09-24 07:18:50Z baconevi $
* $Id: map.h 380 2008-09-24 08:16:41Z baconevi $
*
* {License}
*/
@ -115,6 +115,17 @@ enum ase_map_walk_t
#define ASE_MAP_SIZE(m) ((m)->size)
#define ASE_MAP_CAPA(m) ((m)->capa)
#define ASE_MAP_MMGR(m) ((m)->mmgr)
#define ASE_MAP_KCOPIER(m) ((m)->copier[ASE_MAP_KEY])
#define ASE_MAP_VCOPIER(m) ((m)->copier[ASE_MAP_VAL])
#define ASE_MAP_KFREEER(m) ((m)->freeer[ASE_MAP_KEY])
#define ASE_MAP_VFREEER(m) ((m)->freeer[ASE_MAP_VAL])
#define ASE_MAP_HASHER(m) ((m)->hasher)
#define ASE_MAP_COMPER(m) ((m)->comper)
#define ASE_MAP_KEEPER(m) ((m)->keeper)
#define ASE_MAP_SIZER(m) ((m)->sizer)
#define ASE_MAP_EXTENSION(m) ((void*)(((ase_map_t*)m) + 1))
#define ASE_MAP_KPTR(p) ((p)->kptr)
#define ASE_MAP_KLEN(p) ((p)->klen)
#define ASE_MAP_VPTR(p) ((p)->vptr)

View File

@ -1,5 +1,5 @@
/*
* $Id: str.h 379 2008-09-24 08:06:56Z baconevi $
* $Id: str.h 380 2008-09-24 08:16:41Z baconevi $
*
* {License}
*/
@ -10,10 +10,14 @@
#include <ase/types.h>
#include <ase/macros.h>
#define ASE_STR_LEN(x) ((x)->len)
#define ASE_STR_PTR(x) ((x)->ptr)
#define ASE_STR_CAPA(x) ((x)->capa)
#define ASE_STR_CHAR(x,idx) ((x)->ptr[idx])
#define ASE_STR_LEN(s) ((s)->len)
#define ASE_STR_PTR(s) ((s)->ptr)
#define ASE_STR_CAPA(s) ((s)->capa)
#define ASE_STR_CHAR(s,idx) ((s)->ptr[idx])
#define ASE_STR_MMGR(s) ((s)->mmgr)
#define ASE_STR_SIZER(s) ((s)->sizer)
#define ASE_STR_EXTENSION(s) ((void*)(((ase_str_t*)s) + 1))
typedef struct ase_str_t ase_str_t;
typedef ase_size_t (*ase_str_sizer_t) (ase_str_t* data, ase_size_t hint);

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 379 2008-09-24 08:06:56Z baconevi $
* $Id: awk.c 380 2008-09-24 08:16:41Z baconevi $
*
* {License}
*/
@ -23,7 +23,7 @@
static void free_afn (ase_map_t* map, void* vptr, ase_size_t vlen)
{
ase_awk_t* awk = *(ase_awk_t**)ase_map_getextension(map);
ase_awk_t* awk = *(ase_awk_t**)ASE_MAP_EXTENSION(map);
ase_awk_afn_t* f = (ase_awk_afn_t*)vptr;
/* f->name doesn't have to be freed */
@ -35,7 +35,7 @@ static void free_afn (ase_map_t* map, void* vptr, ase_size_t vlen)
static void free_bfn (ase_map_t* map, void* vptr, ase_size_t vlen)
{
ase_awk_t* awk = *(ase_awk_t**)ase_map_getextension(map);
ase_awk_t* awk = *(ase_awk_t**)ASE_MAP_EXTENSION(map);
ase_awk_bfn_t* f = (ase_awk_bfn_t*)vptr;
ASE_AWK_FREE (awk, f);
@ -74,7 +74,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
*(ase_awk_t**)ase_map_getextension(awk->wtab) = awk;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->wtab) = awk;
ase_map_setcopier (awk->wtab, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->wtab, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
@ -86,7 +86,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
*(ase_awk_t**)ase_map_getextension(awk->rwtab) = awk;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->rwtab) = awk;
ase_map_setcopier (awk->rwtab, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->rwtab, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
@ -101,7 +101,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
*(ase_awk_t**)ase_map_getextension(awk->tree.afns) = awk;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->tree.afns) = awk;
ase_map_setfreeer (awk->tree.afns, ASE_MAP_VAL, free_afn);
/*awk->parse.afns = ase_map_open (awk, 256, 70, ASE_NULL, ASE_NULL, mmgr);*/
@ -115,7 +115,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
*(ase_awk_t**)ase_map_getextension(awk->parse.afns) = awk;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.afns) = awk;
/*awk->parse.named = ase_map_open (awk, 256, 70, ASE_NULL, ASE_NULL, mmgr);*/
awk->parse.named = ase_map_open (mmgr, ASE_SIZEOF(awk), 256, 70);
@ -129,7 +129,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
*(ase_awk_t**)ase_map_getextension(awk->parse.named) = awk;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.named) = awk;
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
{
@ -219,7 +219,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
*(ase_awk_t**)ase_map_getextension(awk->bfn.user) = awk;
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->bfn.user) = awk;
ase_map_setfreeer (awk->bfn.user, ASE_MAP_VAL, free_bfn);
awk->parse.depth.cur.block = 0;

View File

@ -47,7 +47,7 @@ ase_awk_t* ase_awk_openstd (void)
awk = ase_awk_open (ASE_NULL, ASE_SIZEOF(ext_t), ASE_NULL);
ase_awk_setccls (awk, ASE_CCLS_GETDFL());
ext = (ext_t*) ase_awk_getextension (awk);
ext = (ext_t*)ASE_AWK_EXTENSION(awk);
ext->prmfns.pow = custom_awk_pow;
ext->prmfns.sprintf = custom_awk_sprintf;
ext->prmfns.dprintf = custom_awk_dprintf;

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c 378 2008-09-24 08:00:50Z baconevi $
* $Id: val.c 380 2008-09-24 08:16:41Z baconevi $
*
* {License}
*/
@ -430,7 +430,7 @@ static void same_mapval (void* run, void* v)
*/
static void free_mapval (ase_map_t* map, void* dptr, ase_size_t dlen)
{
ase_awk_run_t* run = *(ase_awk_run_t**)ase_map_getextension(map);
ase_awk_run_t* run = *(ase_awk_run_t**)ASE_MAP_EXTENSION(map);
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("refdown in map free..."));
@ -443,7 +443,7 @@ static void free_mapval (ase_map_t* map, void* dptr, ase_size_t dlen)
static void same_mapval (ase_map_t* map, void* dptr, ase_size_t dlen)
{
ase_awk_run_t* run = *(ase_awk_run_t**)ase_map_getextension(map);
ase_awk_run_t* run = *(ase_awk_run_t**)ASE_MAP_EXTENSION(map);
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("refdown nofree in map free..."));
ase_awk_dprintval (run, dptr);
@ -485,7 +485,7 @@ ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run)
ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM);
return ASE_NULL;
}
*(ase_awk_run_t**)ase_map_getextension(val->map) = run;
*(ase_awk_run_t**)ASE_MAP_EXTENSION(val->map) = run;
/* the key is copied inline into a pair and is freed when the pair
* is destroyed */
@ -1119,7 +1119,7 @@ static ase_map_walk_t print_pair (
{
ase_awk_run_t* run = (ase_awk_run_t*)arg;
ASE_ASSERT (run == *(ase_awk_run_t**)ase_map_getextension(map));
ASE_ASSERT (run == *(ase_awk_run_t**)ASE_MAP_EXTENSION(map));
DPRINTF (DCUSTOM, ASE_T(" %.*s=>"),
(int)ASE_MAP_KCLEN(pair), ASE_MAP_KPTR(pair));