addming a dynamic array

This commit is contained in:
2008-10-01 05:14:20 +00:00
parent 5fd42fbb99
commit c2a6db9ec3
7 changed files with 731 additions and 41 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 354 2008-08-31 10:57:24Z baconevi $
* $Id: awk.h 404 2008-09-30 11:14:20Z baconevi $
*
* {License}
*/
@ -7,12 +7,20 @@
#ifndef _ASE_AWK_AWK_H_
#define _ASE_AWK_AWK_H_
#include <ase/types.h>
#include <ase/macros.h>
#include <ase/cmn/map.h>
#include <ase/cmn/str.h>
/****o* ase.awk/awk interpreter
* DESCRIPTION
* The library includes an AWK interpreter that can be embedded into other
* applications or can run stand-alone.
*
* #include <ase/awk/awk.h>
******
*/
typedef struct ase_awk_t ase_awk_t;
typedef struct ase_awk_run_t ase_awk_run_t;
typedef struct ase_awk_val_t ase_awk_val_t;
@ -577,50 +585,63 @@ extern ase_awk_val_t* ase_awk_val_zero;
/** represents a numeric value 1 */
extern ase_awk_val_t* ase_awk_val_one;
/*
* NAME: create an ase_awk_t instance
/****f* ase.awk/ase_awk_open
* NAME
* ase_awk_open - create an awk object
*
* DESCRIPTION:
* 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.
*
* RETURNS:
* the pointer to an ase_awk_t instance on success.
* ASE_NULL on failure.
* RETURN
* The ase_awk_open() function returns the pointer to an ase_awk_t instance
* on success and ASE_NULL on failure.
*
* SYNOPSIS
*/
ase_awk_t* ase_awk_open (
ase_mmgr_t* mmgr /* memory manager */,
ase_size_t ext /* size of extension area in bytes */
ase_mmgr_t* mmgr /* a memory manager */,
ase_size_t ext /* size of extension area in bytes */
);
/******/
/*
* destroy an ase_awk_t instance
/****f* ase.awk/ase_awk_close
* NAME
* ase_awk_close - destroy an awk object
*
* 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
* the function returns success.
*
* RETURNS 0 on success, -1 on failure
* RETURN
* 0 on success, -1 on failure
*
* SYNOPSIS
*/
int ase_awk_close (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk
ase_awk_t* awk /* an awk object */
);
/******/
/*
* get the pointer to the memory manager in use
* RETURNS the pointer to the memory manager set through ase_awk_open()
/****f* ase.awk/ase_awk_getmmgr
* NAME
* ase_awk_getmmgr - get the memory manager
*
* DESCRIPTION
* The ase_awk_getmmgr() function returns the pointer to the memory manager.
*
* SYNOPSIS
*/
ase_mmgr_t* ase_awk_getmmgr (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk
ase_awk_t* awk /* an awk object */
);
/******/
/*
/****f* ase.awk/ase_awk_getextension
* NAME
* get the pointer to extension area requested upon a call to ase_awk_open()
* ase_awk_getextension - get the extension
*
* DESCRIPTION
* The extension area is allocated in the ase_awk_open() function when it is
@ -628,12 +649,12 @@ ase_mmgr_t* ase_awk_getmmgr (
* can be acquired using the ase_awk_getextension() function and be utilized
* for various purposes.
*
* RETURNS the pointer to the extension area
* SYNOPSIS
*/
void* ase_awk_getextension (
/* the pointer to an ase_awk_t instance */
ase_awk_t* awk
ase_awk_t* awk /* an awk object */
);
/******/
/*
* set the character classfier
@ -772,6 +793,9 @@ int ase_awk_delglobal (ase_awk_t* awk, const ase_char_t* name, ase_size_t len);
*/
int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios);
int ase_awk_parsefiles (ase_awk_t* awk, const ase_char_t* files[], ase_size_t count);
/**
* Executes a parsed program.
*

152
ase/include/ase/cmn/dar.h Normal file
View File

@ -0,0 +1,152 @@
/*
* $Id: dar.h 363 2008-09-04 10:58:08Z baconevi $
*
* {License}
*/
#ifndef _ASE_CMN_DAR_H_
#define _ASE_CMN_DAR_H_
#include <ase/types.h>
#include <ase/macros.h>
/****o* ase.cmn.dar/dynamic array
* DESCRIPTION
* A dynamic array grows as more items are added.
*
* #include <ase/cmn/dar.h>
******
*/
typedef struct ase_dar_t ase_dar_t;
/****s* ase.cmn.dar/ase_dar_t
* NAME
* ase_dar_t - define a dynamic array
*
* SYNOPSIS
*/
struct ase_dar_t
{
ase_mmgr_t* mmgr; /* memory manager */
ase_sll_copier_t copier; /* data copier */
ase_sll_freeer_t freeer; /* data freeer */
ase_sll_comper_t comper; /* data comparator */
ase_byte_t scale; /* scale factor */
ase_size_t size; /* the number of items */
ase_size_t capa; /* capacity */
struct
{
void* dptr;
ase_size_t dlen;
}* buf;
};
/******/
#ifdef __cplusplus
extern "C" {
#endif
/****f* ase.cmn.dar/ase_dar_open
* NAME
* ase_dar_open - create a dynamic array
*
* SYNOPSIS
*/
ase_dar_t* ase_dar_open (
ase_mmgr_t* dar,
ase_size_t ext,
ase_size_t capa
);
/******/
/****f* ase.cmn.dar/ase_dar_close
* NAME
* ase_dar_close - destroy a dynamic array
*
* SYNOPSIS
*/
void ase_dar_close (
ase_dar_t* dar
);
/******/
/****f* ase.cmn.dar/ase_dar_init
* NAME
* ase_dar_init - initialize a dynamic array
*
* SYNOPSIS
*/
ase_dar_t* ase_dar_init (
ase_dar_t* dar,
ase_mmgr_t* mmgr,
ase_size_t capa
);
/******/
/****f* ase.cmn.dar/ase_dar_fini
* NAME
* ase_dar_fini - deinitialize a dynamic array
*
* SYNOPSIS
*/
void ase_dar_fini (
ase_dar_t* dar
);
/******/
ase_size_t ase_dar_getsize (ase_dar_t* dar);
ase_size_t ase_dar_getcapa (ase_dar_t* dar);
ase_dar_t* ase_dar_setcapa (ase_dar_t* dar, ase_size_t capa);
ase_size_t ase_dar_insert (
ase_dar_t* dar,
ase_size_t index,
const ase_char_t* str,
ase_size_t len
);
ase_size_t ase_dar_delete (
ase_dar_t* dar,
ase_size_t index,
ase_size_t count
);
ase_size_t ase_dar_add (
ase_dar_t* dar, const ase_char_t* str, ase_size_t len);
ase_size_t ase_dar_adduniq (
ase_dar_t* dar, const ase_char_t* str, ase_size_t len);
ase_size_t ase_dar_find (
ase_dar_t* dar, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_dar_rfind (
ase_dar_t* dar, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_dar_rrfind (
ase_dar_t* dar, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_dar_findx (
ase_dar_t* dar, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
ase_size_t ase_dar_rfindx (
ase_dar_t* dar, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
ase_size_t ase_dar_rrfindx (
ase_dar_t* dar, ase_size_t index,
const ase_char_t* str, ase_size_t len,
void(*transform)(ase_size_t, ase_cstr_t*,void*), void* arg);
void ase_dar_clear (ase_dar_t* dar);
#ifdef __cplusplus
}
#endif
#endif