initially finished code change for the various changes in common routines
This commit is contained in:
parent
7f9f5b1fc0
commit
b2ad40e12a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c 343 2008-08-22 08:13:47Z baconevi $
|
||||
* $Id: awk.c 391 2008-09-27 09:51:23Z baconevi $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk.h>
|
||||
@ -797,13 +797,15 @@ static void on_run_start (ase_awk_run_t* run, void* custom)
|
||||
local_dprintf (ASE_T("[AWK ABOUT TO START]\n"));
|
||||
}
|
||||
|
||||
static int print_awk_value (ase_pair_t* pair, void* arg)
|
||||
static ase_map_walk_t print_awk_value (
|
||||
ase_map_t* map, ase_map_pair_t* pair, void* arg)
|
||||
{
|
||||
ase_awk_run_t* run = (ase_awk_run_t*)arg;
|
||||
local_dprintf (ASE_T("%.*s = "), (int)pair->key.len, pair->key.ptr);
|
||||
ase_awk_dprintval (run, (ase_awk_val_t*)pair->val);
|
||||
local_dprintf (ASE_T("%.*s = "),
|
||||
(int)ASE_MAP_KLEN(pair), ASE_MAP_KPTR(pair));
|
||||
ase_awk_dprintval (run, (ase_awk_val_t*)ASE_MAP_VPTR(pair));
|
||||
local_dprintf (ASE_T("\n"));
|
||||
return 0;
|
||||
return ASE_MAP_WALK_FORWARD;
|
||||
}
|
||||
|
||||
static void on_run_statement (
|
||||
@ -1006,7 +1008,7 @@ static int handle_args (int argc, ase_char_t* argv[], srcio_data_t* siod)
|
||||
|
||||
if (sf == ASE_NULL)
|
||||
{
|
||||
sf = ase_sll_open (ASE_NULL, 0, ASE_NULL);
|
||||
sf = ase_sll_open (ASE_NULL, 0);
|
||||
if (sf == ASE_NULL)
|
||||
{
|
||||
out_of_memory ();
|
||||
@ -1060,7 +1062,7 @@ static int handle_args (int argc, ase_char_t* argv[], srcio_data_t* siod)
|
||||
}
|
||||
|
||||
|
||||
if (ase_sll_getsize(sf) == 0)
|
||||
if (sf == ASE_NULL || ASE_SLL_SIZE(sf) == 0)
|
||||
{
|
||||
if (opt.ind >= argc)
|
||||
{
|
||||
@ -1093,7 +1095,7 @@ typedef struct extension_t
|
||||
}
|
||||
extension_t;
|
||||
|
||||
static void init_extension (ase_awk_t* awk)
|
||||
static void init_awk_extension (ase_awk_t* awk)
|
||||
{
|
||||
extension_t* ext = ase_awk_getextension(awk);
|
||||
|
||||
@ -1129,7 +1131,7 @@ static ase_awk_t* open_awk (void)
|
||||
mmgr.data = ASE_NULL;
|
||||
#endif
|
||||
|
||||
awk = ase_awk_open (&mmgr, ASE_SIZEOF(extension_t), init_extension);
|
||||
awk = ase_awk_open (&mmgr, ASE_SIZEOF(extension_t));
|
||||
if (awk == ASE_NULL)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@ -1138,6 +1140,8 @@ static ase_awk_t* open_awk (void)
|
||||
ase_printf (ASE_T("ERROR: cannot open awk\n"));
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
init_awk_extension (awk);
|
||||
|
||||
ase_awk_setoption (awk,
|
||||
ASE_AWK_IMPLICIT | ASE_AWK_EXTIO | ASE_AWK_NEWLINE |
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp 390 2008-09-26 15:30:49Z baconevi $
|
||||
* $Id: Awk.hpp 391 2008-09-27 09:51:23Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -1061,7 +1061,7 @@ protected:
|
||||
|
||||
static int functionHandler (
|
||||
run_t* run, const char_t* name, size_t len);
|
||||
static void freeFunctionMapValue (void* owner, void* value);
|
||||
static void freeFunctionMapValue (map_t* map, void* dptr, size_t dlen);
|
||||
|
||||
static void onRunStart (run_t* run, void* data);
|
||||
static void onRunEnd (run_t* run, int errnum, void* data);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: map.h 390 2008-09-26 15:30:49Z baconevi $
|
||||
* $Id: map.h 391 2008-09-27 09:51:23Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -127,14 +127,13 @@ typedef ase_map_walk_t (*ase_map_walker_t) (
|
||||
*/
|
||||
struct ase_map_pair_t
|
||||
{
|
||||
void* kptr; /* the pointer to a key */
|
||||
ase_size_t klen; /* the length of a key */
|
||||
void* kptr; /* the pointer to a key */
|
||||
ase_size_t klen; /* the length of a key */
|
||||
|
||||
void* vptr; /* the pointer to a value */
|
||||
ase_size_t vlen; /* the length of a value */
|
||||
void* vptr; /* the pointer to a value */
|
||||
ase_size_t vlen; /* the length of a value */
|
||||
|
||||
/* an internal pointer to the next pair chained */
|
||||
ase_map_pair_t* next;
|
||||
ase_map_pair_t* next; /* the next pair under the same slot */
|
||||
};
|
||||
/*****/
|
||||
|
||||
@ -281,8 +280,25 @@ void ase_map_fini (
|
||||
ase_map_t* map
|
||||
);
|
||||
|
||||
/* clear a map */
|
||||
void ase_map_clear (
|
||||
void* ase_map_getextension (
|
||||
ase_map_t* map
|
||||
);
|
||||
|
||||
ase_mmgr_t* ase_map_getmmgr (
|
||||
ase_map_t* map
|
||||
);
|
||||
|
||||
void ase_map_setmmgr (
|
||||
ase_map_t* map,
|
||||
ase_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
/* get the number of key/value pairs in a map */
|
||||
ase_size_t ase_map_getsize (
|
||||
ase_map_t* map /* a map */
|
||||
);
|
||||
|
||||
ase_size_t ase_map_getcapa (
|
||||
ase_map_t* map /* a map */
|
||||
);
|
||||
|
||||
@ -399,28 +415,6 @@ void ase_map_setsizer (
|
||||
ase_map_sizer_t sizer
|
||||
);
|
||||
|
||||
void* ase_map_getextension (
|
||||
ase_map_t* map
|
||||
);
|
||||
|
||||
ase_mmgr_t* ase_map_getmmgr (
|
||||
ase_map_t* map
|
||||
);
|
||||
|
||||
void ase_map_setmmgr (
|
||||
ase_map_t* map,
|
||||
ase_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
/* get the number of key/value pairs in a map */
|
||||
ase_size_t ase_map_getsize (
|
||||
ase_map_t* map /* a map */
|
||||
);
|
||||
|
||||
ase_size_t ase_map_getcapa (
|
||||
ase_map_t* map /* a map */
|
||||
);
|
||||
|
||||
int ase_map_put (
|
||||
ase_map_t* map,
|
||||
void* kptr,
|
||||
@ -517,6 +511,11 @@ int ase_map_delete (
|
||||
ase_size_t klen /* the size of the key in bytes */
|
||||
);
|
||||
|
||||
/* clear a map */
|
||||
void ase_map_clear (
|
||||
ase_map_t* map /* a map */
|
||||
);
|
||||
|
||||
/* traverse a map */
|
||||
void ase_map_walk (
|
||||
ase_map_t* map /* a map */,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: map.h 223 2008-06-26 06:44:41Z baconevi $
|
||||
* $Id: sll.h 223 2008-06-26 06:44:41Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -10,11 +10,16 @@
|
||||
#include <ase/types.h>
|
||||
#include <ase/macros.h>
|
||||
|
||||
/*
|
||||
* Singly Linked List
|
||||
*/
|
||||
/* values to be returned by ase_sll_walker_t */
|
||||
enum ase_sll_walk_t
|
||||
{
|
||||
ASE_SLL_WALK_STOP = 0,
|
||||
ASE_SLL_WALK_FORWARD = 1
|
||||
};
|
||||
|
||||
typedef struct ase_sll_t ase_sll_t;
|
||||
typedef struct ase_sll_node_t ase_sll_node_t;
|
||||
typedef enum ase_sll_walk_t ase_sll_walk_t;
|
||||
|
||||
/* data copier */
|
||||
typedef void* (*ase_sll_copier_t) (ase_sll_t* sll, void* dptr, ase_size_t dlen);
|
||||
@ -23,41 +28,60 @@ typedef void* (*ase_sll_copier_t) (ase_sll_t* sll, void* dptr, ase_size_t dlen);
|
||||
typedef void (*ase_sll_freeer_t) (ase_sll_t* sll, void* dptr, ase_size_t dlen);
|
||||
|
||||
/* node visitor */
|
||||
typedef int (*ase_sll_walker_t) (
|
||||
typedef ase_sll_walk_t (*ase_sll_walker_t) (
|
||||
ase_sll_t* sll, ase_sll_node_t* node, void* arg);
|
||||
|
||||
/****s* ase.cmn.sll/ase_sll_t
|
||||
* NAME
|
||||
* ase_sll_t - define a singly linked list
|
||||
*
|
||||
* DESCRPTION
|
||||
* The ase_sll_t type defines a singly lnked list.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
struct ase_sll_t
|
||||
{
|
||||
ase_mmgr_t* mmgr;
|
||||
|
||||
ase_sll_copier_t copier;
|
||||
ase_sll_freeer_t freeer;
|
||||
ase_byte_t scale;
|
||||
|
||||
ase_size_t size;
|
||||
ase_sll_node_t* head;
|
||||
ase_sll_node_t* tail;
|
||||
};
|
||||
/******/
|
||||
|
||||
/****s* ase.cmn.sll/ase_sll_node_t
|
||||
* NAME
|
||||
* ase_sll_node_t - define a list node
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The ase_sll_node_t type defines a list node containing a data pointer and
|
||||
* and data length.
|
||||
*
|
||||
* SEE ALSO
|
||||
* ASE_SLL_DPTR, ASE_SLL_DLEN, ASE_SLL_NEXT
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
struct ase_sll_node_t
|
||||
{
|
||||
void* dptr; /* pointer to the beginning of data */
|
||||
ase_size_t dlen; /* length of data in bytes */
|
||||
void* dptr; /* pointer to the beginning of data */
|
||||
ase_size_t dlen; /* length of data in bytes */
|
||||
ase_sll_node_t* next; /* pointer to the next node */
|
||||
};
|
||||
/******/
|
||||
|
||||
|
||||
/* values to be returned by ase_sll_walker_t */
|
||||
enum ase_sll_walk_t
|
||||
{
|
||||
ASE_SLL_WALK_STOP = 0,
|
||||
ASE_SLL_WALK_FORWARD = 1
|
||||
};
|
||||
|
||||
#define ASE_SLL_COPIER_INLINE ase_sll_copyinline
|
||||
|
||||
#define ASE_SLL_HEAD(sll) ((sll)->head)
|
||||
#define ASE_SLL_TAIL(sll) ((sll)->tail)
|
||||
#define ASE_SLL_SIZE(sll) ((sll)->size)
|
||||
#define ASE_SLL_HEAD(sll) ((sll)->head)
|
||||
#define ASE_SLL_TAIL(sll) ((sll)->tail)
|
||||
#define ASE_SLL_SIZE(sll) ((sll)->size)
|
||||
#define ASE_SLL_SCALE(sll) ((sll)->scale)
|
||||
|
||||
#define ASE_SLL_DPTR(n) ((n)->dptr)
|
||||
#define ASE_SLL_DLEN(n) ((n)->dlen)
|
||||
@ -67,10 +91,11 @@ enum ase_sll_walk_t
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NAME: creates a singly linked list with extension area
|
||||
/****f* ase.cmn.sll/ase_sll_open
|
||||
* NAME
|
||||
* ase_sll_open - create a singly linked list with extension area
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* DESCRIPTION
|
||||
* The ase_sll_open() function creates an empty singly linked list.
|
||||
* If the memory manager mmgr is ASE_NULL, the function gets the default
|
||||
* memory manager with ASE_MMGR_GETMMGR() and uses it if it is not ASE_NULL.
|
||||
@ -79,27 +104,36 @@ extern "C" {
|
||||
* after initializing the main area. The extension initializer is passed
|
||||
* the pointer to the singly linked list created.
|
||||
*
|
||||
* RETURNS:
|
||||
* RETURN
|
||||
* the pointer to a newly created singly linked list on success.
|
||||
* ASE_NULL on failure.
|
||||
*
|
||||
* WARNING:
|
||||
* NOTES
|
||||
* In the debug build, it fails the assertion if ASE_MMGR_SETMMGR() returns
|
||||
* ASE_NULL when ASE_NULL is passed as the first parameter. In the release
|
||||
* build, it returns ASE_NULL if such a thing happens.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
|
||||
ase_sll_t* ase_sll_open (
|
||||
ase_mmgr_t* mmgr /* memory manager */ ,
|
||||
ase_size_t ext /* size of extension area in bytes */
|
||||
ase_size_t ext /* size of extension area in bytes */
|
||||
);
|
||||
/******/
|
||||
|
||||
/*
|
||||
* NAME: destroys a singly linked list
|
||||
/****f* ase.cmn.sll/ase_sll_close
|
||||
* NAME
|
||||
* ase_sll_close - destroy a singly linked list
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The ase_sll_close() function destroys a singly linked list
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void ase_sll_close (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
ase_sll_t* ase_sll_init (
|
||||
ase_sll_t* sll /* an uninitialized singly linked list */,
|
||||
@ -110,48 +144,6 @@ void ase_sll_fini (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: deletes all elements of a singly linked list
|
||||
*/
|
||||
void ase_sll_clear (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: specifies how to clone an element
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* A special copier ASE_SLL_COPIER_INLINE is provided. This copier enables
|
||||
* you to copy the data inline to the internal node. No freeer is invoked
|
||||
* when the node is freeed.
|
||||
*
|
||||
* You may set the copier to ASE_NULL to perform no special operation
|
||||
* when the data pointer is rememebered.
|
||||
*/
|
||||
void ase_sll_setcopier (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_copier_t copier /* a element copier */
|
||||
);
|
||||
|
||||
ase_sll_copier_t ase_sll_getcopier (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: specifies how to destroy an element
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The freeer is called when a node containing the element is destroyed.
|
||||
*/
|
||||
void ase_sll_setfreeer (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_freeer_t freeer /* a element freeer */
|
||||
);
|
||||
|
||||
ase_sll_freeer_t ase_sll_getfreeer (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: Gets the pointer to the extension area
|
||||
* RETURN:: the pointer to the extension area
|
||||
@ -167,7 +159,10 @@ ase_mmgr_t* ase_sll_getmmgr (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
void ase_sll_setmmgr (ase_sll_t* sll, ase_mmgr_t* mmgr);
|
||||
void ase_sll_setmmgr (
|
||||
ase_sll_t* sll,
|
||||
ase_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: Gets the number of elements held in a singly linked list
|
||||
@ -177,6 +172,75 @@ ase_size_t ase_sll_getsize (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
|
||||
int ase_sll_getscale (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
/****f* ase.cmn.sll/ase_sll_setscale
|
||||
* NAME
|
||||
* ase_sll_setscale - set the scale factor
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The ase_sll_setscale() function sets the scale factor of the data length.
|
||||
* A scale factor determines the actual length of data in bytes. A singly
|
||||
* linked list created with a scale factor of 1. The scale factor should be
|
||||
* larger than 0 and less than 256.
|
||||
*
|
||||
* NOTES
|
||||
* It is a bad idea to change the scale factor when a sll is not empty.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void ase_sll_setscale (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
int scale /* a scale factor */
|
||||
);
|
||||
/******/
|
||||
|
||||
ase_sll_copier_t ase_sll_getcopier (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
/****f* ase.cmn.sll/ase_sll_setcopier
|
||||
* NAME
|
||||
* ase_sll_setcopier - specify how to clone an element
|
||||
*
|
||||
* DESCRIPTION
|
||||
* A special copier ASE_SLL_COPIER_INLINE is provided. This copier enables
|
||||
* you to copy the data inline to the internal node. No freeer is invoked
|
||||
* when the node is freeed.
|
||||
*
|
||||
* You may set the copier to ASE_NULL to perform no special operation
|
||||
* when the data pointer is rememebered.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void ase_sll_setcopier (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_copier_t copier /* a element copier */
|
||||
);
|
||||
/******/
|
||||
|
||||
ase_sll_freeer_t ase_sll_getfreeer (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
/****f* ase.cmn.sll/ase_sll_setfreeer
|
||||
* NAME
|
||||
* ase_sll_setfreeer - specify how to destroy an element
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The freeer is called when a node containing the element is destroyed.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void ase_sll_setfreeer (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_freeer_t freeer /* a element freeer */
|
||||
);
|
||||
/******/
|
||||
|
||||
/*
|
||||
* NAME: Gets the head(first) node
|
||||
* RETURN: the tail node of a singly linked list
|
||||
@ -193,21 +257,45 @@ ase_sll_node_t* ase_sll_gettail (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: Inserts data before a positional node given
|
||||
/****f* ase.cmn.sll/ase_sll_insert
|
||||
* NAME
|
||||
* ase_sll_insert - insert data before a positional node given
|
||||
*
|
||||
* DESCRIPTION
|
||||
* There is performance penalty unless the positional node is neither
|
||||
* the head node nor ASE_NULL. You should consider a different data
|
||||
* structure such as a doubly linked list if you need to insert data
|
||||
* into a random position.
|
||||
* There is performance penalty unless the positional node is neither
|
||||
* the head node nor ASE_NULL. You should consider a different data
|
||||
* structure such as a doubly linked list if you need to insert data
|
||||
* into a random position.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
ase_sll_node_t* ase_sll_insert (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_node_t* pos /* a node before which a new node is inserted */,
|
||||
void* dptr /* the pointer to the data */ ,
|
||||
ase_size_t dlen /* the length of the data in bytes */
|
||||
void* dptr /* the pointer to the data */,
|
||||
ase_size_t dlen /* the length of the data */
|
||||
);
|
||||
/******/
|
||||
|
||||
void ase_sll_delete (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_node_t* pos /* a node to delete */
|
||||
);
|
||||
|
||||
/****f* ase.cmn.sll/ase_sll_clear
|
||||
* NAME
|
||||
* ase_sll_clear - delete all nodes
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The ase_sll_clear() function empties a singly linked list by deletinng
|
||||
* all data nodes.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void ase_sll_clear (
|
||||
ase_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
ase_sll_node_t* ase_sll_pushhead (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
@ -221,10 +309,6 @@ ase_sll_node_t* ase_sll_pushtail (
|
||||
ase_size_t dlen
|
||||
);
|
||||
|
||||
void ase_sll_delete (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_node_t* pos /* a node to delete */
|
||||
);
|
||||
|
||||
void ase_sll_pophead (
|
||||
ase_sll_t* sll
|
||||
@ -234,25 +318,29 @@ void ase_sll_poptail (
|
||||
ase_sll_t* sll
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: Traverses s singly linked list
|
||||
/****f* ase.cmn.sll/ase_sll_walk
|
||||
* NAME
|
||||
* ase_sll_walk - traverse s singly linked list
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* A singly linked list allows uni-directional in-order traversal.
|
||||
* The ase_sll_walk() function traverses a singly linkked list from its
|
||||
* head node down to its tail node as long as the walker function returns
|
||||
* ASE_SLL_WALK_FORWARD. A walker can return ASE_SLL_WALK_STOP to cause
|
||||
* immediate stop of traversal.
|
||||
* For each node, the walker function is called and it is passed three
|
||||
* parameters: the singly linked list, the visiting node, and the
|
||||
* user-defined data passed as the third parameter in a call to the
|
||||
* ase_sll_walk() function.
|
||||
* DESCRIPTION
|
||||
* A singly linked list allows uni-directional in-order traversal.
|
||||
* The ase_sll_walk() function traverses a singly linkked list from its
|
||||
* head node down to its tail node as long as the walker function returns
|
||||
* ASE_SLL_WALK_FORWARD. A walker can return ASE_SLL_WALK_STOP to cause
|
||||
* immediate stop of traversal.
|
||||
* For each node, the walker function is called and it is passed three
|
||||
* parameters: the singly linked list, the visiting node, and the
|
||||
* user-defined data passed as the third parameter in a call to the
|
||||
* ase_sll_walk() function.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void ase_sll_walk (
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_t* sll /* a singly linked list */,
|
||||
ase_sll_walker_t walker /* a user-defined walker function */,
|
||||
void* arg /* pointer to user-defined data */
|
||||
void* arg /* pointer to user-defined data */
|
||||
);
|
||||
/******/
|
||||
|
||||
/*
|
||||
* Causes a singly linked list to copy in data to a node.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp 390 2008-09-26 15:30:49Z baconevi $
|
||||
* $Id: Awk.cpp 391 2008-09-27 09:51:23Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -423,7 +423,7 @@ int Awk::Argument::getIndexed (
|
||||
if (pair == ASE_NULL) return 0;
|
||||
|
||||
// if val.init fails, it should return an error
|
||||
return val.init ((val_t*)pair->val);
|
||||
return val.init ((val_t*)ASE_MAP_VPTR(pair));
|
||||
}
|
||||
|
||||
int Awk::Argument::getIndexed (long_t idx, Argument& val) const
|
||||
@ -467,7 +467,7 @@ int Awk::Argument::getIndexed (long_t idx, Argument& val) const
|
||||
if (pair == ASE_NULL) return 0;
|
||||
|
||||
// if val.init fails, it should return an error
|
||||
return val.init ((val_t*)pair->val);
|
||||
return val.init ((val_t*)ASE_MAP_VPTR(pair));
|
||||
}
|
||||
|
||||
int Awk::Argument::getFirstIndex (Awk::Argument& val) const
|
||||
@ -482,7 +482,9 @@ int Awk::Argument::getFirstIndex (Awk::Argument& val) const
|
||||
pair_t* pair = ase_map_getfirstpair (m->map, &buckno);
|
||||
if (pair == ASE_NULL) return 0; // no more key
|
||||
|
||||
if (val.init (pair->key.ptr, pair->key.len) == -1) return -1;
|
||||
if (val.init (
|
||||
(ase_char_t*)ASE_MAP_KPTR(pair),
|
||||
ASE_MAP_KLEN(pair)) == -1) return -1;
|
||||
|
||||
// reuse the string field as an interator.
|
||||
this->str.ptr = (char_t*)pair;
|
||||
@ -506,7 +508,9 @@ int Awk::Argument::getNextIndex (Awk::Argument& val) const
|
||||
pair = ase_map_getnextpair (m->map, pair, &buckno);
|
||||
if (pair == ASE_NULL) return 0;
|
||||
|
||||
if (val.init (pair->key.ptr, pair->key.len) == -1) return -1;
|
||||
if (val.init (
|
||||
(ase_char_t*)ASE_MAP_KPTR(pair),
|
||||
ASE_MAP_KLEN(pair)) == -1) return -1;
|
||||
|
||||
// reuse the string field as an interator.
|
||||
this->str.ptr = (char_t*)pair;
|
||||
@ -617,7 +621,8 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, long_t v)
|
||||
ase_awk_refupval (this->run->run, x2);
|
||||
|
||||
pair_t* pair = ase_map_upsert (
|
||||
((ase_awk_val_map_t*)x)->map, idx, iln, x2);
|
||||
((ase_awk_val_map_t*)x)->map,
|
||||
(char_t*)idx, iln, x2, 0);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
ase_awk_refdownval (this->run->run, x2);
|
||||
@ -637,7 +642,8 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, long_t v)
|
||||
ase_awk_refupval (this->run->run, x2);
|
||||
|
||||
pair_t* pair = ase_map_upsert (
|
||||
((ase_awk_val_map_t*)this->val)->map, idx, iln, x2);
|
||||
((ase_awk_val_map_t*)this->val)->map,
|
||||
(char_t*)idx, iln, x2, 0);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
ase_awk_refdownval (this->run->run, x2);
|
||||
@ -678,7 +684,8 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, real_t v)
|
||||
ase_awk_refupval (this->run->run, x2);
|
||||
|
||||
pair_t* pair = ase_map_upsert (
|
||||
((ase_awk_val_map_t*)x)->map, idx, iln, x2);
|
||||
((ase_awk_val_map_t*)x)->map,
|
||||
(char_t*)idx, iln, x2, 0);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
ase_awk_refdownval (this->run->run, x2);
|
||||
@ -698,7 +705,8 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, real_t v)
|
||||
ase_awk_refupval (this->run->run, x2);
|
||||
|
||||
pair_t* pair = ase_map_upsert (
|
||||
((ase_awk_val_map_t*)this->val)->map, idx, iln, x2);
|
||||
((ase_awk_val_map_t*)this->val)->map,
|
||||
(char_t*)idx, iln, x2, 0);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
ase_awk_refdownval (this->run->run, x2);
|
||||
@ -739,7 +747,8 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, const char_t* str, s
|
||||
ase_awk_refupval (this->run->run, x2);
|
||||
|
||||
pair_t* pair = ase_map_upsert (
|
||||
((ase_awk_val_map_t*)x)->map, idx, iln, x2);
|
||||
((ase_awk_val_map_t*)x)->map,
|
||||
(char_t*)idx, iln, x2, 0);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
ase_awk_refdownval (this->run->run, x2);
|
||||
@ -759,7 +768,8 @@ int Awk::Return::setIndexed (const char_t* idx, size_t iln, const char_t* str, s
|
||||
ase_awk_refupval (this->run->run, x2);
|
||||
|
||||
pair_t* pair = ase_map_upsert (
|
||||
((ase_awk_val_map_t*)this->val)->map, idx, iln, x2);
|
||||
((ase_awk_val_map_t*)this->val)->map,
|
||||
(char_t*)idx, iln, x2, 0);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
ase_awk_refdownval (this->run->run, x2);
|
||||
@ -1154,9 +1164,12 @@ int Awk::open ()
|
||||
ase_awk_setccls (awk, &ccls);
|
||||
ase_awk_setprmfns (awk, &prmfns);
|
||||
|
||||
|
||||
//functionMap = ase_map_open (
|
||||
// this, 512, 70, freeFunctionMapValue, ASE_NULL,
|
||||
// ase_awk_getmmgr(awk));
|
||||
functionMap = ase_map_open (
|
||||
this, 512, 70, freeFunctionMapValue, ASE_NULL,
|
||||
ase_awk_getmmgr(awk));
|
||||
ase_awk_getmmgr(awk), ASE_SIZEOF(this), 512, 70);
|
||||
if (functionMap == ASE_NULL)
|
||||
{
|
||||
ase_awk_close (awk);
|
||||
@ -1166,6 +1179,11 @@ int Awk::open ()
|
||||
return -1;
|
||||
}
|
||||
|
||||
*(Awk**)ase_map_getextension(functionMap) = this;
|
||||
ase_map_setcopier (functionMap, ASE_MAP_KEY, ASE_MAP_COPIER_INLINE);
|
||||
ase_map_setfreeer (functionMap, ASE_MAP_VAL, freeFunctionMapValue);
|
||||
ase_map_setscale (functionMap, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
|
||||
|
||||
int opt =
|
||||
OPT_IMPLICIT |
|
||||
OPT_EXTIO |
|
||||
@ -1366,7 +1384,7 @@ int Awk::dispatchFunction (Run* run, const char_t* name, size_t len)
|
||||
|
||||
//awk = ase_awk_getrunawk (run);
|
||||
|
||||
pair = ase_map_get (functionMap, name, len);
|
||||
pair = ase_map_search (functionMap, name, len);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
run->setError (ERR_FNNONE, 0, name, len);
|
||||
@ -1374,7 +1392,7 @@ int Awk::dispatchFunction (Run* run, const char_t* name, size_t len)
|
||||
}
|
||||
|
||||
FunctionHandler handler;
|
||||
handler = *(FunctionHandler*)ASE_PAIR_VAL(pair);
|
||||
handler = *(FunctionHandler*)ASE_MAP_VPTR(pair);
|
||||
|
||||
size_t i, nargs = ase_awk_getnargs(run->run);
|
||||
|
||||
@ -1464,7 +1482,8 @@ int Awk::addFunction (
|
||||
return -1;
|
||||
}
|
||||
|
||||
pair_t* pair = ase_map_upsert (functionMap, name, nameLen, tmp);
|
||||
pair_t* pair = ase_map_upsert (
|
||||
functionMap, (char_t*)name, nameLen, tmp, 0);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
ase_awk_delfunc (awk, name, nameLen);
|
||||
@ -1484,7 +1503,7 @@ int Awk::deleteFunction (const char_t* name)
|
||||
size_t nameLen = ase_strlen(name);
|
||||
|
||||
int n = ase_awk_delfunc (awk, name, nameLen);
|
||||
if (n == 0) ase_map_remove (functionMap, name, nameLen);
|
||||
if (n == 0) ase_map_delete (functionMap, name, nameLen);
|
||||
else retrieveError ();
|
||||
|
||||
return n;
|
||||
@ -1660,10 +1679,11 @@ int Awk::functionHandler (
|
||||
return awk->dispatchFunction (ctx, name, len);
|
||||
}
|
||||
|
||||
void Awk::freeFunctionMapValue (void* owner, void* value)
|
||||
void Awk::freeFunctionMapValue (map_t* map, void* dptr, size_t dlen)
|
||||
{
|
||||
Awk* awk = (Awk*)owner;
|
||||
ase_awk_free (awk->awk, value);
|
||||
//Awk* awk = (Awk*)owner;
|
||||
Awk* awk = *(Awk**)ase_map_getextension(map);
|
||||
ase_awk_free (awk->awk, dptr);
|
||||
}
|
||||
|
||||
void Awk::onRunStart (run_t* run, void* data)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c 389 2008-09-26 08:01:24Z baconevi $
|
||||
* $Id: awk.c 391 2008-09-27 09:51:23Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -107,7 +107,7 @@ ase_awk_t* ase_awk_open (ase_mmgr_t* mmgr, ase_size_t ext)
|
||||
*(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_setcale (awk->tree.afns, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
|
||||
ase_map_setscale (awk->tree.afns, ASE_MAP_KEY, ASE_SIZEOF(ase_char_t));
|
||||
|
||||
awk->parse.afns = ase_map_open (mmgr, ASE_SIZEOF(awk), 256, 70);
|
||||
if (awk->parse.afns == ASE_NULL)
|
||||
@ -456,7 +456,7 @@ int ase_awk_unsetword (ase_awk_t* awk, const ase_char_t* kw, ase_size_t len)
|
||||
{
|
||||
ase_map_pair_t* p;
|
||||
|
||||
p = ase_map_search (awk->wtab, kw, ASE_NCHARS_TO_NBYTES(len));
|
||||
p = ase_map_search (awk->wtab, kw, len);
|
||||
if (p == ASE_NULL)
|
||||
{
|
||||
SETERRARG (awk, ASE_AWK_ENOENT, 0, kw, len);
|
||||
@ -464,7 +464,7 @@ int ase_awk_unsetword (ase_awk_t* awk, const ase_char_t* kw, ase_size_t len)
|
||||
}
|
||||
|
||||
ase_map_delete (awk->rwtab, ASE_MAP_VPTR(p), ASE_MAP_VLEN(p));
|
||||
ase_map_delete (awk->wtab, kw, ASE_NCHARS_TO_NBYTES(len));
|
||||
ase_map_delete (awk->wtab, kw, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -501,18 +501,16 @@ int ase_awk_setword (ase_awk_t* awk,
|
||||
|
||||
/* set the word */
|
||||
if (ase_map_upsert (awk->wtab,
|
||||
(ase_char_t*)okw, ASE_NCHARS_TO_NBYTES(olen),
|
||||
(ase_char_t*)nkw, ASE_NCHARS_TO_NBYTES(nlen)) == ASE_NULL)
|
||||
(ase_char_t*)okw, olen, (ase_char_t*)nkw, nlen) == ASE_NULL)
|
||||
{
|
||||
SETERR (awk, ASE_AWK_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ase_map_upsert (awk->rwtab,
|
||||
(ase_char_t*)nkw, ASE_NCHARS_TO_NBYTES(nlen),
|
||||
(ase_char_t*)okw, ASE_NCHARS_TO_NBYTES(olen)) == ASE_NULL)
|
||||
(ase_char_t*)nkw, nlen, (ase_char_t*)okw, olen) == ASE_NULL)
|
||||
{
|
||||
ase_map_delete (awk->wtab, okw, ASE_NCHARS_TO_NBYTES(olen));
|
||||
ase_map_delete (awk->wtab, okw, olen);
|
||||
SETERR (awk, ASE_AWK_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: func.c 389 2008-09-26 08:01:24Z baconevi $
|
||||
* $Id: func.c 391 2008-09-27 09:51:23Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -112,7 +112,7 @@ void* ase_awk_addfunc (
|
||||
int ase_awk_delfunc (
|
||||
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len)
|
||||
{
|
||||
if (ase_map_remove (awk->bfn.user, name, name_len) == -1)
|
||||
if (ase_map_delete (awk->bfn.user, name, name_len) == -1)
|
||||
{
|
||||
ase_cstr_t errarg;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c 389 2008-09-26 08:01:24Z baconevi $
|
||||
* $Id: parse.c 391 2008-09-27 09:51:23Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -825,7 +825,6 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
||||
ase_awk_afn_t* afn;
|
||||
ase_size_t nargs, g;
|
||||
ase_map_pair_t* pair;
|
||||
int n;
|
||||
|
||||
/* eat up the keyword 'function' and get the next token */
|
||||
ASE_ASSERT (MATCH(awk,TOKEN_FUNCTION));
|
||||
@ -1080,9 +1079,12 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
||||
afn->nargs = nargs;
|
||||
afn->body = body;
|
||||
|
||||
n = ase_map_upsertx (awk->tree.afns, name_dup, name_len, afn, &pair);
|
||||
if (n < 0)
|
||||
pair = ase_map_insert (awk->tree.afns, name_dup, name_len, afn, 0);
|
||||
if (pair == ASE_NULL)
|
||||
{
|
||||
/* if ase_map_insert() fails for other reasons than memory
|
||||
* shortage, there should be implementaion errors as duplicate
|
||||
* functions are detected earlier in this function */
|
||||
ASE_AWK_FREE (awk, name_dup);
|
||||
ase_awk_clrpt (awk, body);
|
||||
ASE_AWK_FREE (awk, afn);
|
||||
@ -1091,9 +1093,6 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
/* duplicate functions should have been detected previously */
|
||||
ASE_ASSERT (n != 0);
|
||||
|
||||
/* do some trick to save a string. make it back-point at the key part
|
||||
* of the pair */
|
||||
afn->name.ptr = ASE_MAP_KPTR(pair);
|
||||
@ -1101,7 +1100,7 @@ static ase_awk_nde_t* parse_function (ase_awk_t* awk)
|
||||
ASE_AWK_FREE (awk, name_dup);
|
||||
|
||||
/* remove an undefined function call entry from the parse.afn table */
|
||||
ase_map_remove (awk->parse.afns, afn->name.ptr, name_len);
|
||||
ase_map_delete (awk->parse.afns, afn->name.ptr, name_len);
|
||||
return body;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c 390 2008-09-26 15:30:49Z baconevi $
|
||||
* $Id: run.c 391 2008-09-27 09:51:23Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -2552,7 +2552,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_map_remove (map, key, keylen);
|
||||
ase_map_delete (map, key, keylen);
|
||||
if (key != buf) ASE_AWK_FREE (run->awk, key);
|
||||
}
|
||||
else
|
||||
@ -2676,7 +2676,7 @@ static int run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
||||
run->errlin = var->line;
|
||||
return -1;
|
||||
}
|
||||
ase_map_remove (map, key, keylen);
|
||||
ase_map_delete (map, key, keylen);
|
||||
if (key != buf) ASE_AWK_FREE (run->awk, key);
|
||||
}
|
||||
else
|
||||
@ -2713,7 +2713,7 @@ static int run_reset (ase_awk_run_t* run, ase_awk_nde_reset_t* nde)
|
||||
|
||||
/* a named variable can be reset if removed from a internal map
|
||||
to manage it */
|
||||
ase_map_remove (run->named, var->id.name.ptr, var->id.name.len);
|
||||
ase_map_delete (run->named, var->id.name.ptr, var->id.name.len);
|
||||
}
|
||||
else if (var->type == ASE_AWK_NDE_GLOBAL ||
|
||||
var->type == ASE_AWK_NDE_LOCAL ||
|
||||
|
@ -47,7 +47,7 @@ ase_awk_t* ase_awk_openstd (void)
|
||||
awk = ase_awk_open (ASE_MMGR_GETDFL(), ASE_SIZEOF(ext_t));
|
||||
ase_awk_setccls (awk, ASE_CCLS_GETDFL());
|
||||
|
||||
ext = (ext_t*)ASE_AWK_EXTENSION(awk);
|
||||
ext = (ext_t*)ase_awk_getextension(awk);
|
||||
ext->prmfns.pow = custom_awk_pow;
|
||||
ext->prmfns.sprintf = custom_awk_sprintf;
|
||||
ext->prmfns.dprintf = custom_awk_dprintf;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: map.c 388 2008-09-26 07:26:20Z baconevi $
|
||||
* $Id: map.c 391 2008-09-27 09:51:23Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -24,10 +24,10 @@
|
||||
#define NEXT(p) ASE_MAP_NEXT(p)
|
||||
|
||||
#define SIZEOF(x) ASE_SIZEOF(x)
|
||||
#define size_t ase_size_t
|
||||
#define byte_t ase_byte_t
|
||||
#define uint_t ase_uint_t
|
||||
#define mmgr_t ase_mmgr_t
|
||||
#define size_t ase_size_t
|
||||
#define byte_t ase_byte_t
|
||||
#define uint_t ase_uint_t
|
||||
#define mmgr_t ase_mmgr_t
|
||||
|
||||
#define KTOB(map,len) ((len)*(map)->scale[ASE_MAP_KEY])
|
||||
#define VTOB(map,len) ((len)*(map)->scale[ASE_MAP_VAL])
|
||||
@ -108,11 +108,11 @@ static pair_t* alloc_pair (map_t* map,
|
||||
}
|
||||
else
|
||||
{
|
||||
n->vptr = vcop (map, vptr, vlen);
|
||||
if (n->vptr != ASE_NULL)
|
||||
VPTR(n) = vcop (map, vptr, vlen);
|
||||
if (VPTR(n) != ASE_NULL)
|
||||
{
|
||||
if (map->freeer[ASE_MAP_KEY] != ASE_NULL)
|
||||
map->freeer[ASE_MAP_KEY] (map, n->kptr, n->klen);
|
||||
map->freeer[ASE_MAP_KEY] (map, KPTR(n), KLEN(n));
|
||||
ASE_MMGR_FREE (map->mmgr, n);
|
||||
return ASE_NULL;
|
||||
}
|
||||
@ -274,25 +274,29 @@ void ase_map_fini (map_t* map)
|
||||
ASE_MMGR_FREE (map->mmgr, map->bucket);
|
||||
}
|
||||
|
||||
void ase_map_clear (map_t* map)
|
||||
void* ase_map_getextension (map_t* map)
|
||||
{
|
||||
size_t i;
|
||||
pair_t* pair, * next;
|
||||
return map + 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < map->capa; i++)
|
||||
{
|
||||
pair = map->bucket[i];
|
||||
mmgr_t* ase_map_getmmgr (map_t* map)
|
||||
{
|
||||
return map->mmgr;
|
||||
}
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
next = NEXT(pair);
|
||||
free_pair (map, pair);
|
||||
map->size--;
|
||||
pair = next;
|
||||
}
|
||||
void ase_map_setmmgr (map_t* map, mmgr_t* mmgr)
|
||||
{
|
||||
map->mmgr = mmgr;
|
||||
}
|
||||
|
||||
map->bucket[i] = ASE_NULL;
|
||||
}
|
||||
size_t ase_map_getsize (map_t* map)
|
||||
{
|
||||
return map->size;
|
||||
}
|
||||
|
||||
size_t ase_map_getcapa (map_t* map)
|
||||
{
|
||||
return map->capa;
|
||||
}
|
||||
|
||||
int ase_map_getscale (map_t* map, int id)
|
||||
@ -386,31 +390,6 @@ void ase_map_setsizer (map_t* map, sizer_t sizer)
|
||||
map->sizer = sizer;
|
||||
}
|
||||
|
||||
void* ase_map_getextension (map_t* map)
|
||||
{
|
||||
return map + 1;
|
||||
}
|
||||
|
||||
mmgr_t* ase_map_getmmgr (map_t* map)
|
||||
{
|
||||
return map->mmgr;
|
||||
}
|
||||
|
||||
void ase_map_setmmgr (map_t* map, mmgr_t* mmgr)
|
||||
{
|
||||
map->mmgr = mmgr;
|
||||
}
|
||||
|
||||
size_t ase_map_getsize (map_t* map)
|
||||
{
|
||||
return map->size;
|
||||
}
|
||||
|
||||
size_t ase_map_getcapa (map_t* map)
|
||||
{
|
||||
return map->capa;
|
||||
}
|
||||
|
||||
pair_t* ase_map_search (map_t* map, const void* kptr, size_t klen)
|
||||
{
|
||||
pair_t* pair;
|
||||
@ -605,6 +584,28 @@ int ase_map_delete (map_t* map, const void* kptr, size_t klen)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ase_map_clear (map_t* map)
|
||||
{
|
||||
size_t i;
|
||||
pair_t* pair, * next;
|
||||
|
||||
for (i = 0; i < map->capa; i++)
|
||||
{
|
||||
pair = map->bucket[i];
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
next = NEXT(pair);
|
||||
free_pair (map, pair);
|
||||
map->size--;
|
||||
pair = next;
|
||||
}
|
||||
|
||||
map->bucket[i] = ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ase_map_walk (map_t* map, walker_t walker, void* arg)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -21,6 +21,8 @@
|
||||
#define DLEN(n) ASE_SLL_DLEN(n)
|
||||
#define NEXT(n) ASE_SLL_NEXT(n)
|
||||
|
||||
#define TOB(sll,len) ((len)*(sll)->scale)
|
||||
|
||||
#define size_t ase_size_t
|
||||
#define mmgr_t ase_mmgr_t
|
||||
|
||||
@ -55,6 +57,8 @@ sll_t* ase_sll_init (sll_t* sll, mmgr_t* mmgr)
|
||||
/* do not zero out the extension */
|
||||
ASE_MEMSET (sll, 0, ASE_SIZEOF(sll_t));
|
||||
sll->mmgr = mmgr;
|
||||
sll->size = 0;
|
||||
sll->scale = 1;
|
||||
return sll;
|
||||
}
|
||||
|
||||
@ -63,12 +67,6 @@ void ase_sll_fini (sll_t* sll)
|
||||
ase_sll_clear (sll);
|
||||
}
|
||||
|
||||
void ase_sll_clear (sll_t* sll)
|
||||
{
|
||||
while (HEAD(sll) != ASE_NULL) ase_sll_delete (sll, HEAD(sll));
|
||||
ASE_ASSERT (TAIL(sll) == ASE_NULL);
|
||||
}
|
||||
|
||||
void* ase_sll_getextension (sll_t* sll)
|
||||
{
|
||||
return sll + 1;
|
||||
@ -99,6 +97,22 @@ node_t* ase_sll_gettail (sll_t* sll)
|
||||
return TAIL(sll);
|
||||
}
|
||||
|
||||
int ase_sll_getscale (sll_t* sll)
|
||||
{
|
||||
return sll->scale;
|
||||
}
|
||||
|
||||
void ase_sll_setscale (sll_t* sll, int scale)
|
||||
{
|
||||
ASE_ASSERTX (scale > 0 && scale <= ASE_TYPE_MAX(ase_byte_t),
|
||||
"The scale should be larger than 0 and less than or equal to the maximum value that the ase_byte_t type can hold");
|
||||
|
||||
if (scale <= 0) scale = 1;
|
||||
if (scale > ASE_TYPE_MAX(ase_byte_t)) scale = ASE_TYPE_MAX(ase_byte_t);
|
||||
|
||||
sll->scale = scale;
|
||||
}
|
||||
|
||||
copier_t ase_sll_getcopier (sll_t* sll)
|
||||
{
|
||||
return sll->copier;
|
||||
@ -131,10 +145,11 @@ static node_t* alloc_node (sll_t* sll, void* dptr, size_t dlen)
|
||||
}
|
||||
else if (sll->copier == ASE_SLL_COPIER_INLINE)
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (sll->mmgr, ASE_SIZEOF(node_t) + dlen);
|
||||
n = ASE_MMGR_ALLOC (sll->mmgr,
|
||||
ASE_SIZEOF(node_t) + TOB(sll,dlen));
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
|
||||
ASE_MEMCPY (n + 1, dptr, dlen);
|
||||
ASE_MEMCPY (n + 1, dptr, TOB(sll,dlen));
|
||||
DPTR(n) = n + 1;
|
||||
}
|
||||
else
|
||||
@ -191,16 +206,6 @@ node_t* ase_sll_insert (
|
||||
return n;
|
||||
}
|
||||
|
||||
node_t* ase_sll_pushhead (sll_t* sll, void* data, size_t size)
|
||||
{
|
||||
return ase_sll_insert (sll, HEAD(sll), data, size);
|
||||
}
|
||||
|
||||
node_t* ase_sll_pushtail (sll_t* sll, void* data, size_t size)
|
||||
{
|
||||
return ase_sll_insert (sll, ASE_NULL, data, size);
|
||||
}
|
||||
|
||||
void ase_sll_delete (sll_t* sll, node_t* pos)
|
||||
{
|
||||
if (pos == ASE_NULL) return; /* not a valid node */
|
||||
@ -238,6 +243,22 @@ void ase_sll_delete (sll_t* sll, node_t* pos)
|
||||
SIZE(sll)--;
|
||||
}
|
||||
|
||||
void ase_sll_clear (sll_t* sll)
|
||||
{
|
||||
while (HEAD(sll) != ASE_NULL) ase_sll_delete (sll, HEAD(sll));
|
||||
ASE_ASSERT (TAIL(sll) == ASE_NULL);
|
||||
}
|
||||
|
||||
node_t* ase_sll_pushhead (sll_t* sll, void* data, size_t size)
|
||||
{
|
||||
return ase_sll_insert (sll, HEAD(sll), data, size);
|
||||
}
|
||||
|
||||
node_t* ase_sll_pushtail (sll_t* sll, void* data, size_t size)
|
||||
{
|
||||
return ase_sll_insert (sll, ASE_NULL, data, size);
|
||||
}
|
||||
|
||||
void ase_sll_pophead (sll_t* sll)
|
||||
{
|
||||
ase_sll_delete (sll, HEAD(sll));
|
||||
|
Loading…
x
Reference in New Issue
Block a user