fixing code to utilize ase_map_setscale

This commit is contained in:
hyung-hwan 2008-09-27 02:01:24 +00:00
parent 8480da56d1
commit ca18186e94
8 changed files with 135 additions and 91 deletions

View File

@ -3,22 +3,21 @@ items:
SYNOPSIS SYNOPSIS
DESCRIPTION DESCRIPTION
RETURN RETURN
SEE ALSO
BUGS
EXAMPLES EXAMPLES
SOURCE NOTES
BUGS
SEE ALSO
source items: source items:
SYNOPSIS SYNOPSIS
SOURCE
item order: item order:
NAME NAME
SYNOPSIS SYNOPSIS
DESCRIPTION DESCRIPTION
RETURN RETURN
SEE ALSO
BUGS
EXAMPLES EXAMPLES
SOURCE NOTES
BUGS
SEE ALSO
remark begin markers: remark begin markers:
/* /*
remark end markers: remark end markers:

View File

@ -1,5 +1,5 @@
/* /*
* $Id: map.h 388 2008-09-26 07:26:20Z baconevi $ * $Id: map.h 389 2008-09-26 08:01:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -10,7 +10,7 @@
#include <ase/types.h> #include <ase/types.h>
#include <ase/macros.h> #include <ase/macros.h>
/****o* ase.cmn.map/map.h /****o* ase.cmn.map/hash map
* DESCRIPTION * DESCRIPTION
* A hash map maintains buckets for key/value pairs with the same key hash * A hash map maintains buckets for key/value pairs with the same key hash
* chained under the same bucket. * chained under the same bucket.
@ -291,14 +291,17 @@ int ase_map_getscale (
); );
/****f* ase.cmn.map/ase_map_setscale /****f* ase.cmn.map/ase_map_setscale
* NAME
* ase_map_setscale - set the scale factor
* *
* DESCRIPTION * DESCRIPTION
* The ase_map_setscale() function sets the scale factor of the length * The ase_map_setscale() function sets the scale factor of the length
* of a key and a value. A map is created with a scale factor of 1. * of a key and a value. A scale factor determines the actual length of
* a key and a value in bytes. A map is created with a scale factor of 1.
* The scale factor should be larger than 0 and less than 256. * The scale factor should be larger than 0 and less than 256.
* *
* RETURN * NOTES
* ASE_NULL on failure * It is a bad idea to change the scale factor when a map is not empty.
* *
* SYNOPSIS * SYNOPSIS
*/ */
@ -309,6 +312,10 @@ void ase_map_setscale (
); );
/******/ /******/
ase_map_copier_t ase_map_getcopier (
ase_map_t* map /* a map */,
int id /* ASE_MAP_KEY or ASE_MAP_VAL */
);
/****f* ase.cmn.map/ase_map_setcopier /****f* ase.cmn.map/ase_map_setcopier
* NAME * NAME
@ -321,36 +328,39 @@ void ase_map_setscale (
* *
* You may set the copier to ASE_NULL to perform no special operation * You may set the copier to ASE_NULL to perform no special operation
* when the data pointer is rememebered. * when the data pointer is rememebered.
*
* SYNOPSIS
*/ */
void ase_map_setcopier ( void ase_map_setcopier (
ase_map_t* map /* a map */, ase_map_t* map /* a map */,
int id /* ASE_MAP_KEY or ASE_MAP_VAL */, int id /* ASE_MAP_KEY or ASE_MAP_VAL */,
ase_map_copier_t copier /* a element copier */ ase_map_copier_t copier /* an element copier */
); );
/******/ /******/
ase_map_copier_t ase_map_getcopier (
ase_map_t* map /* a map */,
int id /* ASE_MAP_KEY or ASE_MAP_VAL */
);
/*
* NAME: specifies how to destroy an element
*
* DESCRIPTION
* The freeer is called when a node containing the element is destroyed.
*/
void ase_map_setfreeer (
ase_map_t* map /* a map */,
int id /* ASE_MAP_KEY or ASE_MAP_VAL */,
ase_map_freeer_t freeer /* a element freeer */
);
ase_map_freeer_t ase_map_getfreeer ( ase_map_freeer_t ase_map_getfreeer (
ase_map_t* map /* a map */, ase_map_t* map /* a map */,
int id /* ASE_MAP_KEY or ASE_MAP_VAL */ int id /* ASE_MAP_KEY or ASE_MAP_VAL */
); );
/****f* ase.cmn.map/ase_map_setfreeer
* NAME
* ase_map_setfreeer - specify how to destroy an element
*
* DESCRIPTION
* The freeer is called when a node containing the element is destroyed.
*
* SYNOPSIS
*/
void ase_map_setfreeer (
ase_map_t* map /* a map */,
int id /* ASE_MAP_KEY or ASE_MAP_VAL */,
ase_map_freeer_t freeer /* an element freeer */
);
/******/
ase_map_hasher_t ase_map_gethasher ( ase_map_hasher_t ase_map_gethasher (
ase_map_t* map ase_map_t* map
); );
@ -419,36 +429,43 @@ int ase_map_put (
ase_map_pair_t** px ase_map_pair_t** px
); );
/* /****f* ase.cmn.map/ase_map_search
* NAME: find a pair with a matching key * NAME
* ase_map_search - find a pair with a matching key
* *
* DESCRIPTION: * DESCRIPTION
* The ase_map_search() functions searches a map to find a pair with a * The ase_map_search() function searches a map to find a pair with a
* matching key. It returns the pointer to the pair found. If it fails * matching key. It returns the pointer to the pair found. If it fails
* to find one, it returns ASE_NULL. * to find one, it returns ASE_NULL.
* *
* RETURNS: * RETURN
* The pointer to the pair with a maching key. * The ase_map_search() function returns the pointer to the pair with a
* ASE_NULL if no match is found. * maching key, and ASE_NULL if no match is found.
*
* SYNOPSIS
*/ */
ase_map_pair_t* ase_map_search ( ase_map_pair_t* ase_map_search (
ase_map_t* map /* a map */, ase_map_t* map /* a map */,
const void* kptr /* the pointer to a key */, const void* kptr /* the pointer to a key */,
ase_size_t klen /* the size of the key in bytes */ ase_size_t klen /* the size of the key in bytes */
); );
/******/
/* /****f* ase.cmn.map/ase_map_upsert
* NAME: update an existing pair with a matching or inesrt a new pair * NAME
* ase_map_upsert - update an existing pair or inesrt a new pair
* *
* DESCRIPTION: * DESCRIPTION
* The ase_map_upsert() function searches a map for the pair with a matching * The ase_map_upsert() function searches a map for the pair with a matching
* key. If one is found, it updates the pair. Otherwise, it inserts a new * key. If one is found, it updates the pair. Otherwise, it inserts a new
* pair with a key and a value. It returns the pointer to the pair updated * pair with a key and a value. It returns the pointer to the pair updated
* or inserted. * or inserted.
* *
* RETURNS: * RETURN
* a pointer to the updated or inserted pair. * The ase_map_upsert() function returns a pointer to the updated or inserted
* ASE_NULL on failure. * pair on success, and ASE_NULL on failure.
*
* SYNOPSIS
*/ */
ase_map_pair_t* ase_map_upsert ( ase_map_pair_t* ase_map_upsert (
ase_map_t* map /* a map */, ase_map_t* map /* a map */,
@ -457,18 +474,22 @@ ase_map_pair_t* ase_map_upsert (
void* vptr /* the pointer to a value */, void* vptr /* the pointer to a value */,
ase_size_t vlen /* the length of the value in bytes */ ase_size_t vlen /* the length of the value in bytes */
); );
/******/
/* /****f* ase.cmn.map/ase_map_insert
* NAME: insert a new pair with a key and a value * NAME
* ase_map_insert - insert a new pair with a key and a value
* *
* DESCRIPTION: * DESCRIPTION
* The ase_map_insert() function inserts a new pair with the key and the value * The ase_map_insert() function inserts a new pair with the key and the value
* given. If there exists a pair with the key given, the function returns * given. If there exists a pair with the key given, the function returns
* ASE_NULL without channging the value. * ASE_NULL without channging the value.
* *
* RETURNS: * RETURN
* a pointer to the pair successfully created on success. * The ase_map_insert() function returns a pointer to the pair created on
* ASE_NULL on failure. * success, and ASE_NULL on failure.
*
* SYNOPSIS
*/ */
ase_map_pair_t* ase_map_insert ( ase_map_pair_t* ase_map_insert (
ase_map_t* map /* a map */, ase_map_t* map /* a map */,
@ -477,6 +498,7 @@ ase_map_pair_t* ase_map_insert (
void* vptr /* the pointer to a value */, void* vptr /* the pointer to a value */,
ase_size_t vlen /* the length of the value in bytes */ ase_size_t vlen /* the length of the value in bytes */
); );
/******/
/* update the value of a existing pair with a matching key */ /* update the value of a existing pair with a matching key */
ase_map_pair_t* ase_map_update ( ase_map_pair_t* ase_map_update (

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str.h 388 2008-09-26 07:26:20Z baconevi $ * $Id: str.h 389 2008-09-26 08:01:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -10,11 +10,14 @@
#include <ase/types.h> #include <ase/types.h>
#include <ase/macros.h> #include <ase/macros.h>
/****o* ase.cmn.str/str.h /****o* ase.cmn.str/string
* DESCRIPTION * DESCRIPTION
* <ase/cmn/str.h> defines various functions, types, macros to manipulate * <ase/cmn/str.h> defines various functions, types, macros to manipulate
* strings. * strings.
* *
* The ase_cstr_t type and the ase_xstr_t defined in ase/types.h helps you
* dealing with a string pointer and length.
*
* #include <ase/cmn/str.h> * #include <ase/cmn/str.h>
* *
* EXAMPLES * EXAMPLES

View File

@ -1,5 +1,5 @@
/* /*
* $Id: types.h 375 2008-09-23 14:47:23Z baconevi $ * $Id: types.h 389 2008-09-26 08:01:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -332,17 +332,31 @@ typedef void (*ase_free_t) (void* data, void* ptr);
typedef ase_bool_t (*ase_isccls_t) (void* data, ase_cint_t c); typedef ase_bool_t (*ase_isccls_t) (void* data, ase_cint_t c);
typedef ase_cint_t (*ase_toccls_t) (void* data, ase_cint_t c); typedef ase_cint_t (*ase_toccls_t) (void* data, ase_cint_t c);
/****t* ase/ase_xstr_t
* NAME
* ase_xstr_t - combile a pointer and length
*
* SYNOPSIS
*/
struct ase_xstr_t struct ase_xstr_t
{ {
ase_char_t* ptr; /* this is not a const pointer */ ase_char_t* ptr; /* this is not a const pointer */
ase_size_t len; ase_size_t len;
}; };
/******/
/****t* ase/ase_cstr_t
* NAME
* ase_cstr_t - combine a constant pointer and length
*
* SYNOPSIS
*/
struct ase_cstr_t struct ase_cstr_t
{ {
const ase_char_t* ptr; /* this is a const pointer */ const ase_char_t* ptr; /* this is a const pointer */
ase_size_t len; ase_size_t len;
}; };
/******/
struct ase_mmgr_t struct ase_mmgr_t
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c 385 2008-09-25 11:06:33Z baconevi $ * $Id: awk.c 389 2008-09-26 08:01:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -77,6 +77,8 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
*(ase_awk_t**)ASE_MAP_EXTENSION(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_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->wtab, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE); ase_map_setcopier (awk->wtab, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
ase_map_setscale (awk->wtab, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
ase_map_setscale (awk->wtab, ASE_MAP_VAL, ASE_SIZEOF(ase_char_t));
awk->rwtab = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70); awk->rwtab = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70);
if (awk->rwtab == ASE_NULL) if (awk->rwtab == ASE_NULL)
@ -89,9 +91,10 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
*(ase_awk_t**)ASE_MAP_EXTENSION(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_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->rwtab, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE); ase_map_setcopier (awk->rwtab, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
ase_map_setscale (awk->rwtab, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
ase_map_setscale (awk->rwtab, ASE_MAP_VAL, ASE_SIZEOF(ase_char_t));
/* TODO: initial map size?? */ /* TODO: initial map size?? */
/*awk->tree.afns = ase_map_open (awk, 512, 70, free_afn, ASE_NULL, mmgr);*/
awk->tree.afns = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70); awk->tree.afns = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70);
if (awk->tree.afns == ASE_NULL) if (awk->tree.afns == ASE_NULL)
{ {
@ -102,9 +105,10 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
return ASE_NULL; return ASE_NULL;
} }
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->tree.afns) = awk; *(ase_awk_t**)ASE_MAP_EXTENSION(awk->tree.afns) = awk;
ase_map_setcopier (awk->tree.afns, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setfreeer (awk->tree.afns, ASE_MAP_VAL, free_afn); ase_map_setfreeer (awk->tree.afns, ASE_MAP_VAL, free_afn);
ase_map_setcale (awk->tree.afns, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
/*awk->parse.afns = ase_map_open (awk, 256, 70, ASE_NULL, ASE_NULL, mmgr);*/
awk->parse.afns = ase_map_open (mmgr, ASE_SIZEOF(awk), 256, 70); awk->parse.afns = ase_map_open (mmgr, ASE_SIZEOF(awk), 256, 70);
if (awk->parse.afns == ASE_NULL) if (awk->parse.afns == ASE_NULL)
{ {
@ -116,9 +120,10 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
return ASE_NULL; return ASE_NULL;
} }
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.afns) = awk; *(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.afns) = awk;
ase_map_setcopier (awk->parse.afns, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->parse.afns, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE); ase_map_setcopier (awk->parse.afns, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
ase_map_setscale (awk->parse.afns, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
/*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); awk->parse.named = ase_map_open (mmgr, ASE_SIZEOF(awk), 256, 70);
if (awk->parse.named == ASE_NULL) if (awk->parse.named == ASE_NULL)
{ {
@ -131,7 +136,9 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
return ASE_NULL; return ASE_NULL;
} }
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.named) = awk; *(ase_awk_t**)ASE_MAP_EXTENSION(awk->parse.named) = awk;
ase_map_setcopier (awk->parse.named, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setcopier (awk->parse.named, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE); ase_map_setcopier (awk->parse.named, ASE_MAP_VAL, ASE_MAP_COPIER_INLINE);
ase_map_setscale (awk->parse.named, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL) if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
{ {
@ -205,7 +212,6 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
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, 512, 70, free_bfn, ASE_NULL, mmgr);*/
awk->bfn.user = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70); awk->bfn.user = ase_map_open (mmgr, ASE_SIZEOF(awk), 512, 70);
if (awk->bfn.user == ASE_NULL) if (awk->bfn.user == ASE_NULL)
{ {
@ -224,6 +230,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
*(ase_awk_t**)ASE_MAP_EXTENSION(awk->bfn.user) = awk; *(ase_awk_t**)ASE_MAP_EXTENSION(awk->bfn.user) = awk;
ase_map_setcopier (awk->bfn.user, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE); ase_map_setcopier (awk->bfn.user, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setfreeer (awk->bfn.user, ASE_MAP_VAL, free_bfn); ase_map_setfreeer (awk->bfn.user, ASE_MAP_VAL, free_bfn);
ase_map_setscale (awk->bfn.user, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
awk->parse.depth.cur.block = 0; awk->parse.depth.cur.block = 0;
awk->parse.depth.cur.loop = 0; awk->parse.depth.cur.loop = 0;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: func.c 382 2008-09-24 11:36:45Z baconevi $ * $Id: func.c 389 2008-09-26 08:01:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -99,7 +99,7 @@ void* ase_awk_addfunc (
bfn->handler = handler; bfn->handler = handler;
if (ase_map_insert (awk->bfn.user, if (ase_map_insert (awk->bfn.user,
(ase_char_t*)name, ASE_NCTONB(name_len), bfn, 0) == ASE_NULL) (ase_char_t*)name, name_len, bfn, 0) == 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);
@ -112,7 +112,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_map_remove (awk->bfn.user, name, ASE_NCTONB(name_len)) == -1) if (ase_map_remove (awk->bfn.user, name, name_len) == -1)
{ {
ase_cstr_t errarg; ase_cstr_t errarg;
@ -146,12 +146,12 @@ ase_awk_bfn_t* ase_awk_getbfn (
(awk->option & bfn->valid) != bfn->valid) continue; (awk->option & bfn->valid) != bfn->valid) continue;
pair = ase_map_search ( pair = ase_map_search (
awk->wtab, bfn->name.ptr, ASE_NCTONB(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 */
k = ASE_MAP_VPTR(pair); k = ASE_MAP_VPTR(pair);
l = ASE_MAP_VCLEN(pair); l = ASE_MAP_VLEN(pair);
} }
else else
{ {
@ -166,21 +166,21 @@ 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_map_search (awk->rwtab, name, ASE_NCTONB(len)); pair = ase_map_search (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
* one of the original word. */ * one of the original word. */
k = ASE_MAP_VPTR(pair); k = ASE_MAP_VPTR(pair);
l = ASE_MAP_VCLEN(pair); l = ASE_MAP_VLEN(pair);
} }
else else
{ {
pair = ase_map_search (awk->wtab, name, ASE_NCTONB(len)); pair = ase_map_search (awk->wtab, name, len);
if (pair != ASE_NULL) if (pair != ASE_NULL)
{ {
k = ASE_MAP_VPTR(pair); k = ASE_MAP_VPTR(pair);
l = ASE_MAP_VCLEN(pair); l = ASE_MAP_VLEN(pair);
if (ase_strxncmp (name, len, k, l) != 0) if (ase_strxncmp (name, len, k, l) != 0)
{ {
@ -204,7 +204,7 @@ ase_awk_bfn_t* ase_awk_getbfn (
} }
/* END NOTE */ /* END NOTE */
pair = ase_map_search (awk->bfn.user, k, ASE_NCTONB(l)); pair = ase_map_search (awk->bfn.user, k, l);
if (pair == ASE_NULL) return ASE_NULL; if (pair == ASE_NULL) return ASE_NULL;
bfn = (ase_awk_bfn_t*)ASE_MAP_VPTR(pair); bfn = (ase_awk_bfn_t*)ASE_MAP_VPTR(pair);
@ -800,7 +800,7 @@ static int bfn_split (
if (ase_map_insert ( if (ase_map_insert (
((ase_awk_val_map_t*)t1)->map, ((ase_awk_val_map_t*)t1)->map,
key, ASE_NCTONB(key_len), t2, 0) == ASE_NULL) key, key_len, t2, 0) == ASE_NULL)
{ {
ase_awk_refdownval (run, t2); ase_awk_refdownval (run, t2);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c 381 2008-09-24 11:07:24Z baconevi $ * $Id: parse.c 389 2008-09-26 08:01:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -464,11 +464,11 @@ ase_cstr_t* ase_awk_getkw (ase_awk_t* awk, int id, ase_cstr_t* s)
s->ptr = kwtab[id].name; s->ptr = kwtab[id].name;
s->len = kwtab[id].name_len; s->len = kwtab[id].name_len;
p = ase_map_search (awk->wtab, s->ptr, ASE_NCTONB(s->len)); p = ase_map_search (awk->wtab, s->ptr, s->len);
if (p != ASE_NULL) if (p != ASE_NULL)
{ {
s->ptr = ASE_MAP_VPTR(p); s->ptr = ASE_MAP_VPTR(p);
s->len = ASE_MAP_VCLEN(p); s->len = ASE_MAP_VLEN(p);
} }
return s; return s;
@ -558,7 +558,7 @@ static int parse (ase_awk_t* awk)
SETERRARG (awk, ASE_AWK_EFNNONE, SETERRARG (awk, ASE_AWK_EFNNONE,
*(ase_size_t*)ASE_MAP_VPTR(p), *(ase_size_t*)ASE_MAP_VPTR(p),
ASE_MAP_KPTR(p), ASE_MAP_KPTR(p),
ASE_MAP_KCLEN(p)); ASE_MAP_KLEN(p));
EXIT_PARSE(-1); EXIT_PARSE(-1);
} }
@ -1097,11 +1097,11 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
/* do some trick to save a string. make it back-point at the key part /* do some trick to save a string. make it back-point at the key part
* of the pair */ * of the pair */
afn->name.ptr = ASE_MAP_KPTR(pair); afn->name.ptr = ASE_MAP_KPTR(pair);
afn->name.len = ASE_MAP_KCLEN(pair); afn->name.len = ASE_MAP_KLEN(pair);
ASE_AWK_FREE (awk, name_dup); ASE_AWK_FREE (awk, name_dup);
/* remove an undefined function call entry from the parse.afn table */ /* remove an undefined function call entry from the parse.afn table */
ase_map_remove (awk->parse.afns, afn->name.ptr, ASE_NCTONB(name_len)); ase_map_remove (awk->parse.afns, afn->name.ptr, name_len);
return body; return body;
} }
@ -1487,7 +1487,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_map_search (awk->parse.afns, name, ASE_NCTONB(len)) != ASE_NULL) if (ase_map_search (awk->parse.afns, name, len) != ASE_NULL)
{ {
SETERRARG ( SETERRARG (
awk, ASE_AWK_EAFNRED, line, awk, ASE_AWK_EAFNRED, line,
@ -1677,7 +1677,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_map_search (awk->parse.afns, if (ase_map_search (awk->parse.afns,
local.ptr, ASE_NCTONB(local.len)) != ASE_NULL) local.ptr, local.len) != ASE_NULL)
{ {
SETERRARG ( SETERRARG (
awk, ASE_AWK_EAFNRED, awk->token.line, awk, ASE_AWK_EAFNRED, awk->token.line,
@ -3265,7 +3265,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_map_search (awk->parse.named, if (ase_map_search (awk->parse.named,
name_dup, ASE_NCTONB(name_len)) != ASE_NULL) 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);
@ -3324,7 +3324,7 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
} }
if (ase_map_search (awk->parse.afns, if (ase_map_search (awk->parse.afns,
name_dup, ASE_NCTONB(name_len)) != ASE_NULL) 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);
@ -3344,7 +3344,7 @@ static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line)
/* collect unique instances of a named variables for reference */ /* collect unique instances of a named variables for reference */
if (ase_map_upsert (awk->parse.named, if (ase_map_upsert (awk->parse.named,
name_dup, ASE_NCTONB(name_len), name_dup, name_len,
&line, ASE_SIZEOF(line)) == ASE_NULL) &line, ASE_SIZEOF(line)) == ASE_NULL)
{ {
SETERRLIN (awk, ASE_AWK_ENOMEM, line); SETERRLIN (awk, ASE_AWK_ENOMEM, line);
@ -3507,8 +3507,7 @@ static ase_awk_nde_t* parse_hashidx (
} }
if (ase_map_search ( if (ase_map_search (
awk->parse.afns, awk->parse.afns, name, name_len) != ASE_NULL)
name, ASE_NCTONB(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);
@ -3660,8 +3659,7 @@ static ase_awk_nde_t* parse_fncall (
/* store a non-builtin function call into the parse.afns table */ /* store a non-builtin function call into the parse.afns table */
if (ase_map_upsert ( if (ase_map_upsert (
awk->parse.afns, awk->parse.afns, name, name_len,
name, ASE_NCTONB(name_len),
&line, ASE_SIZEOF(line)) == ASE_NULL) &line, ASE_SIZEOF(line)) == ASE_NULL)
{ {
ASE_AWK_FREE (awk, call); ASE_AWK_FREE (awk, call);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.c 381 2008-09-24 11:07:24Z baconevi $ * $Id: val.c 389 2008-09-26 08:01:24Z baconevi $
* *
* {License} * {License}
*/ */
@ -506,6 +506,7 @@ ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run)
/* the key is copied inline into a pair and is freed when the pair /* the key is copied inline into a pair and is freed when the pair
* is destroyed */ * is destroyed */
ase_map_setcopier (val->map, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE); ase_map_setcopier (val->map, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
ase_map_setscale (val->map, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
/* not setting copier for a value means that the pointer to the data /* not setting copier for a value means that the pointer to the data
* allocated somewhere else is remembered in a pair. but the freeing * allocated somewhere else is remembered in a pair. but the freeing
@ -1141,7 +1142,7 @@ static ase_map_walk_t print_pair (
ASE_ASSERT (run == *(ase_awk_run_t**)ASE_MAP_EXTENSION(map)); ASE_ASSERT (run == *(ase_awk_run_t**)ASE_MAP_EXTENSION(map));
DPRINTF (DCUSTOM, ASE_T(" %.*s=>"), DPRINTF (DCUSTOM, ASE_T(" %.*s=>"),
(int)ASE_MAP_KCLEN(pair), ASE_MAP_KPTR(pair)); (int)ASE_MAP_KLEN(pair), ASE_MAP_KPTR(pair));
ase_awk_dprintval ((ase_awk_run_t*)arg, ASE_MAP_VPTR(pair)); ase_awk_dprintval ((ase_awk_run_t*)arg, ASE_MAP_VPTR(pair));
DPRINTF (DCUSTOM, ASE_T(" ")); DPRINTF (DCUSTOM, ASE_T(" "));