This commit is contained in:
2008-08-19 05:21:48 +00:00
parent 63014b5fc8
commit 3cbefaa12c
37 changed files with 465 additions and 544 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 313 2008-08-03 14:06:43Z baconevi $
* $Id: awk.h 332 2008-08-18 11:21:48Z baconevi $
*
* {License}
*/
@ -25,11 +25,11 @@ typedef struct ase_awk_runcbs_t ase_awk_runcbs_t;
typedef struct ase_awk_runarg_t ase_awk_runarg_t;
typedef struct ase_awk_rexfns_t ase_awk_rexfns_t;
typedef ase_real_t (*ase_awk_pow_t) (void* custom, ase_real_t x, ase_real_t y);
typedef ase_real_t (*ase_awk_pow_t) (void* data, ase_real_t x, ase_real_t y);
typedef int (*ase_awk_sprintf_t) (
void* custom, ase_char_t* buf, ase_size_t size,
void* data, ase_char_t* buf, ase_size_t size,
const ase_char_t* fmt, ...);
typedef void (*ase_awk_dprintf_t) (void* custom, const ase_char_t* fmt, ...);
typedef void (*ase_awk_dprintf_t) (void* data, const ase_char_t* fmt, ...);
typedef ase_ssize_t (*ase_awk_io_t) (
int cmd, void* arg, ase_char_t* data, ase_size_t count);
@ -40,7 +40,7 @@ struct ase_awk_extio_t
int type; /* [IN] console, file, coproc, pipe */
int mode; /* [IN] read, write, etc */
ase_char_t* name; /* [IN] */
void* custom_data; /* [IN] */
void* data; /* [IN] */
void* handle; /* [OUT] */
/* input */
@ -70,14 +70,14 @@ struct ase_awk_prmfns_t
ase_awk_dprintf_t dprintf; /* required in the debug mode */
/* user-defined data passed to the functions above */
void* custom_data; /* optional */
void* data; /* optional */
};
struct ase_awk_srcios_t
{
ase_awk_io_t in;
ase_awk_io_t out;
void* custom_data;
void* data;
};
struct ase_awk_runios_t
@ -86,24 +86,24 @@ struct ase_awk_runios_t
ase_awk_io_t coproc;
ase_awk_io_t file;
ase_awk_io_t console;
void* custom_data;
void* data;
};
struct ase_awk_runcbs_t
{
void (*on_start) (
ase_awk_run_t* run, void* custom_data);
ase_awk_run_t* run, void* data);
void (*on_statement) (
ase_awk_run_t* run, ase_size_t line, void* custom_data);
ase_awk_run_t* run, ase_size_t line, void* data);
void (*on_return) (
ase_awk_run_t* run, ase_awk_val_t* ret, void* custom_data);
ase_awk_run_t* run, ase_awk_val_t* ret, void* data);
void (*on_end) (
ase_awk_run_t* run, int errnum, void* custom_data);
ase_awk_run_t* run, int errnum, void* data);
void* custom_data;
void* data;
};
struct ase_awk_runarg_t
@ -562,50 +562,42 @@ struct ase_awk_val_ref_t
extern "C" {
#endif
/** @brief represents the nil value */
/** represents the nil value */
extern ase_awk_val_t* ase_awk_val_nil;
/** @brief represents an empty string */
/** represents an empty string */
extern ase_awk_val_t* ase_awk_val_zls;
/** @brief represents a numeric value -1 */
/** represents a numeric value -1 */
extern ase_awk_val_t* ase_awk_val_negone;
/** @brief represents a numeric value 0 */
/** represents a numeric value 0 */
extern ase_awk_val_t* ase_awk_val_zero;
/** @brief represents a numeric value 1 */
/** represents a numeric value 1 */
extern ase_awk_val_t* ase_awk_val_one;
/*
* create an ase_awk_t instance
* NAME: create an ase_awk_t instance
*
* The ase_awk_open() function is used to create a new ase_awk_t instance.
* The instance created can be passed to other ase_awk_xxx() functions and
* is valid until it is successfully destroyed using the ase_ase_close()
* function.
* DESCRIPTION:
* The ase_awk_open() function creates a new ase_awk_t instance.
* The instance created can be passed to other ase_awk_xxx() functions and
* is valid until it is successfully destroyed using the ase_ase_close()
* function.
*
* The mmgr_fuser() function is called if mmgr_fuser is not ASE_NULL.
* It is passed two parameters; the memory manager pointer as passed
* into the ase_awk_open() function and the pointer to the extension
* area allocated. It should return the pointer to the location of the
* memory manager fused into the extension area.
*
* RETURNS the pointer to an ase_awk_t instance on success, ASE_NULL on failure
* RETURNS:
* the pointer to an ase_awk_t instance on success.
* ASE_NULL on failure.
*/
ase_awk_t* ase_awk_open (
/* memory manager */
ase_mmgr_t* mmgr,
/* size of extension area to allocate in bytes */
ase_size_t extension,
/* memory manager fuser */
ase_fuser_t mmgr_fuser
ase_mmgr_t* mmgr /* memory manager */,
ase_size_t extension /* size of extension area in bytes */,
void (*initializer) (ase_awk_t*) /* extension area initializer */
);
ase_awk_t* ase_awk_openstd (void);
/*
* destroy an ase_awk_instance
* destroy an ase_awk_t instance
*
* An ase_awk_t instance should be destroyed using the ase_awk_close() function
* when finished being used. The instance passed is not valid any more once
@ -784,7 +776,7 @@ int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios);
int ase_awk_run (
ase_awk_t* awk, const ase_char_t* main,
ase_awk_runios_t* runios, ase_awk_runcbs_t* runcbs,
ase_awk_runarg_t* runarg, void* custom_data);
ase_awk_runarg_t* runarg, void* data);
void ase_awk_stop (ase_awk_run_t* run);
void ase_awk_stopall (ase_awk_t* awk);

View File

@ -11,7 +11,7 @@
#include <ase/macros.h>
/*
* Singly Linked List
* Doubly Linked List
*/
typedef struct ase_dll_t ase_dll_t;
typedef struct ase_dll_node_t ase_dll_node_t;
@ -69,21 +69,31 @@ extern "C" {
#endif
/*
* NAME creates a new singly linked list
* RETURNS a pointer to a newly created singly linked list
* NAME: creates a doubly linked list with extension area
*
* DESCRIPTION:
* The ase_dll_open() function creates an empty doubly 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.
* The extension area is allocated when the positive extension size extension
* is specified. It calls the extension initialization function initializer
* after initializing the main area. The extension initializer is passed
* the pointer to the doubly linked list created.
*
* RETURNS:
* the pointer to a newly created doubly linked list on success.
* ASE_NULL on failure.
*
* WARNING:
* 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.
*/
ase_dll_t* ase_dll_open (
ase_mmgr_t* mmgr /* memory manager */
);
/*
* NAME creates a new singly linked list with extension
* RETURNS a pointer to a newly created singly linked list
*/
ase_dll_t* ase_dll_openx (
ase_dll_t* ase_dll_open (
ase_mmgr_t* mmgr /* memory manager */ ,
ase_size_t extension /* size of extension in bytes */,
ase_fuser_t fuser
ase_size_t extension /* size of extension area in bytes */,
void (*initializer) (ase_dll_t*) /* extension initializer */
);
/*
@ -143,6 +153,15 @@ void* ase_dll_getextension (
ase_dll_t* dll /* a singly linked list */
);
/*
* NAME: get the pointer to the memory manager in use
*/
ase_mmgr_t* ase_dll_getmmgr (
ase_dll_t* dll /* a singly linked list */
);
void ase_dll_setmmgr (ase_dll_t* dll, ase_mmgr_t* mmgr);
/*
* NAME Gets the number of elements held in a singly linked list
* RETURN the number of elements the list holds

View File

@ -1,5 +1,5 @@
/*
* $Id: mem.h 331 2008-08-17 14:51:40Z baconevi $
* $Id: mem.h 332 2008-08-18 11:21:48Z baconevi $
*
* {License}
*/
@ -11,22 +11,31 @@
#include <ase/macros.h>
/* gets a pointer to the default memory manager */
#define ASE_MMGR_GETDFLMMGR() (ase_mmgr)
#define ASE_MMGR_GETDFL() (ase_mmgr)
/* sets a pointer to the default memory manager */
#define ASE_MMGR_SETDFLMMGR(m) ((ase_mmgr)=(m))
#define ASE_MMGR_SETDFL(m) ((ase_mmgr)=(m))
/* allocate a memory block */
#define ASE_MMGR_ALLOC(mmgr,size) \
(mmgr)->malloc((mmgr)->custom_data,size)
(mmgr)->malloc((mmgr)->data,size)
/* reallocate a memory block */
#define ASE_MMGR_REALLOC(mmgr,ptr,size) \
(mmgr)->realloc((mmgr)->custom_data,ptr,size)
(mmgr)->realloc((mmgr)->data,ptr,size)
/* free a memory block */
#define ASE_MMGR_FREE(mmgr,ptr) \
(mmgr)->free((mmgr)->custom_data,ptr)
(mmgr)->free((mmgr)->data,ptr)
/* define alias for ASE_MMGR_ALLOC */
#define ASE_MALLOC(mmgr,size) ASE_MMGR_ALLOC(mmgr,size)
/* define alias for ASE_MMGR_REALLOC */
#define ASE_REALLOC(mmgr,ptr,size) ASE_MMGR_REALLOC(mmgr,ptr,size)
/* define alias for ASE_MMGR_FREE */
#define ASE_FREE(mmgr,ptr) ASE_MMGR_FREE(mmgr,ptr)
#ifdef __cplusplus
extern "C" {

View File

@ -68,57 +68,49 @@ extern "C" {
#endif
/*
* NAME: creates a singly linked list
* NAME: creates a singly linked list with extension area
*
* DESCRIPTION:
* The ase_sll_open() functions creates an empty singly linked list with
* the default memory manager.
* 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.
* The extension area is allocated when the positive extension size extension
* is specified. It calls the extension initialization function initializer
* after initializing the main area. The extension initializer is passed
* the pointer to the singly linked list created.
*
* RETURNS: a pointer to a newly created singly linked list
* RETURNS:
* the pointer to a newly created singly linked list on success.
* ASE_NULL on failure.
*
* WARNING:
* 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.
*/
ase_sll_t* ase_sll_open (void);
/*
* NAME: create a singly linked list with a custom memory manager
*/
ase_sll_t* ase_sll_openm (
ase_mmgr_t* mmgr /* memory manager */
);
/*
* NAME: create a singly linked list securing extension area
*/
ase_sll_t* ase_sll_openx (
ase_size_t extension /* size of extension in bytes */,
ase_fuser_t initializer /* extension initializer */
);
/*
* NAME creates a new singly linked list with extension
* RETURNS a pointer to a newly created singly linked list
*/
ase_sll_t* ase_sll_openmx (
ase_sll_t* ase_sll_open (
ase_mmgr_t* mmgr /* memory manager */ ,
ase_size_t extension /* size of extension in bytes */,
ase_fuser_t initializer /* extension initializer */
ase_size_t extension /* size of extension area in bytes */,
void (*initializer) (ase_sll_t*) /* extension initializer */
);
/*
* NAME destroys a singly linked list
* NAME: destroys a singly linked list
*/
void ase_sll_close (
ase_sll_t* sll /* a singly linked list */
);
/*
* NAME deletes all elements of 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
* NAME: specifies how to clone an element
*
* DESCRIPTION
* A special copier ASE_SLL_COPIER_INLINE is provided. This copier enables
@ -138,7 +130,7 @@ ase_sll_copier_t ase_sll_getcopier (
);
/*
* NAME specifies how to destroy an element
* NAME: specifies how to destroy an element
*
* DESCRIPTION
* The freeer is called when a node containing the element is destroyed.
@ -153,39 +145,48 @@ ase_sll_freeer_t ase_sll_getfreeer (
);
/*
* NAME Gets the pointer to the extension area
* RETURN the pointer to the extension area
* NAME: Gets the pointer to the extension area
* RETURN:: the pointer to the extension area
*/
void* ase_sll_getextension (
ase_sll_t* sll /* a singly linked list */
);
/*
* NAME Gets the number of elements held in a singly linked list
* RETURN the number of elements the list holds
* NAME: get the pointer to the memory manager in use
*/
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);
/*
* NAME: Gets the number of elements held in a singly linked list
* RETURN: the number of elements the list holds
*/
ase_size_t ase_sll_getsize (
ase_sll_t* sll /* a singly linked list */
);
/*
* NAME Gets the head(first) node
* RETURN the tail node of a singly linked list
* NAME: Gets the head(first) node
* RETURN: the tail node of a singly linked list
*/
ase_sll_node_t* ase_sll_gethead (
ase_sll_t* sll /* a singly linked list */
);
/*
* NAME Gets the tail(last) node
* RETURN the tail node of a singly linked list
* NAME: Gets the tail(last) node
* RETURN: the tail node of a singly linked list
*/
ase_sll_node_t* ase_sll_gettail (
ase_sll_t* sll /* a singly linked list */
);
/*
* NAME Inserts data before a positional node given
* NAME: Inserts data before a positional node given
*
* DESCRIPTION
* There is performance penalty unless the positional node is neither
@ -226,9 +227,9 @@ void ase_sll_poptail (
);
/*
* NAME Traverses s singly linked list
* NAME: Traverses s singly linked list
*
* DESCRIPTION
* 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

View File

@ -18,11 +18,11 @@ typedef ase_ssize_t (*ase_lsp_io_t) (
int cmd, void* arg, ase_char_t* data, ase_size_t count);
typedef ase_real_t (*ase_lsp_pow_t) (
void* custom, ase_real_t x, ase_real_t y);
void* data, ase_real_t x, ase_real_t y);
typedef int (*ase_lsp_sprintf_t) (
void* custom, ase_char_t* buf, ase_size_t size,
void* data, ase_char_t* buf, ase_size_t size,
const ase_char_t* fmt, ...);
typedef void (*ase_lsp_dprintf_t) (void* custom, const ase_char_t* fmt, ...);
typedef void (*ase_lsp_dprintf_t) (void* data, const ase_char_t* fmt, ...);
struct ase_lsp_prmfns_t
{
@ -34,7 +34,7 @@ struct ase_lsp_prmfns_t
{
ase_lsp_sprintf_t sprintf;
ase_lsp_dprintf_t dprintf;
void* custom_data;
void* data;
} misc;
};

View File

@ -1,5 +1,5 @@
/*
* $Id: macros.h 229 2008-06-26 10:46:39Z baconevi $
* $Id: macros.h 332 2008-08-18 11:21:48Z baconevi $
*
* {License}
*/
@ -130,37 +130,19 @@
(ase_assert_failed (ASE_T(#expr), ASE_T(desc), ASE_T(__FILE__), __LINE__), 0))
#endif
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
#include <stdlib.h>
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define ASE_MALLOC(mmgr,size) malloc (size)
#define ASE_REALLOC(mmgr,ptr,size) realloc (ptr, size)
#define ASE_FREE(mmgr,ptr) free (ptr)
#else
#define ASE_MALLOC(mmgr,size) \
(mmgr)->malloc((mmgr)->custom_data, size)
#define ASE_REALLOC(mmgr,ptr,size) \
(mmgr)->realloc((mmgr)->custom_data, ptr, size)
#define ASE_FREE(mmgr,ptr) \
(mmgr)->free((mmgr)->custom_data, ptr)
#endif
#define ASE_ISUPPER(ccls,c) (ccls)->is_upper((ccls)->custom_data,c)
#define ASE_ISLOWER(ccls,c) (ccls)->is_lower((ccls)->custom_data,c)
#define ASE_ISALPHA(ccls,c) (ccls)->is_alpha((ccls)->custom_data,c)
#define ASE_ISDIGIT(ccls,c) (ccls)->is_digit((ccls)->custom_data,c)
#define ASE_ISXDIGIT(ccls,c) (ccls)->is_xdigit((ccls)->custom_data,c)
#define ASE_ISALNUM(ccls,c) (ccls)->is_alnum((ccls)->custom_data,c)
#define ASE_ISSPACE(ccls,c) (ccls)->is_space((ccls)->custom_data,c)
#define ASE_ISPRINT(ccls,c) (ccls)->is_print((ccls)->custom_data,c)
#define ASE_ISGRAPH(ccls,c) (ccls)->is_graph((ccls)->custom_data,c)
#define ASE_ISCNTRL(ccls,c) (ccls)->is_cntrl((ccls)->custom_data,c)
#define ASE_ISPUNCT(ccls,c) (ccls)->is_punct((ccls)->custom_data,c)
#define ASE_TOUPPER(ccls,c) (ccls)->to_upper((ccls)->custom_data,c)
#define ASE_TOLOWER(ccls,c) (ccls)->to_lower((ccls)->custom_data,c)
#define ASE_ISUPPER(ccls,c) (ccls)->is_upper((ccls)->data,c)
#define ASE_ISLOWER(ccls,c) (ccls)->is_lower((ccls)->data,c)
#define ASE_ISALPHA(ccls,c) (ccls)->is_alpha((ccls)->data,c)
#define ASE_ISDIGIT(ccls,c) (ccls)->is_digit((ccls)->data,c)
#define ASE_ISXDIGIT(ccls,c) (ccls)->is_xdigit((ccls)->data,c)
#define ASE_ISALNUM(ccls,c) (ccls)->is_alnum((ccls)->data,c)
#define ASE_ISSPACE(ccls,c) (ccls)->is_space((ccls)->data,c)
#define ASE_ISPRINT(ccls,c) (ccls)->is_print((ccls)->data,c)
#define ASE_ISGRAPH(ccls,c) (ccls)->is_graph((ccls)->data,c)
#define ASE_ISCNTRL(ccls,c) (ccls)->is_cntrl((ccls)->data,c)
#define ASE_ISPUNCT(ccls,c) (ccls)->is_punct((ccls)->data,c)
#define ASE_TOUPPER(ccls,c) (ccls)->to_upper((ccls)->data,c)
#define ASE_TOLOWER(ccls,c) (ccls)->to_lower((ccls)->data,c)
#ifdef __cplusplus
#define ASE_BEGIN_NAMESPACE(x) namespace x {

View File

@ -1,5 +1,5 @@
/*
* $Id: types.h 281 2008-07-21 14:11:04Z baconevi $
* $Id: types.h 332 2008-08-18 11:21:48Z baconevi $
*
* {License}
*/
@ -347,7 +347,7 @@ struct ase_mmgr_t
ase_malloc_t malloc;
ase_realloc_t realloc;
ase_free_t free;
void* custom_data;
void* data;
};
struct ase_ccls_t
@ -365,7 +365,7 @@ struct ase_ccls_t
ase_isccls_t is_punct;
ase_toccls_t to_upper;
ase_toccls_t to_lower;
void* custom_data;
void* data;
};
#endif