* added qse_cptl_t/qse_xptl_t

* deleted word substitution functions from awk
This commit is contained in:
2011-05-24 10:52:37 +00:00
parent 40711d3320
commit 7e6a4dc0d5
20 changed files with 289 additions and 550 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 460 2011-05-17 14:56:54Z hyunghwan.chung $
* $Id: Awk.hpp 474 2011-05-23 16:52:37Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -1003,27 +1003,6 @@ public:
);
/// @}
///
/// @name Word Substitution
/// @{
///
int getWord (
const cstr_t* ow,
cstr_t* nw
);
int setWord (
const cstr_t* ow,
const cstr_t* nw
);
int unsetWord (
const cstr_t* ow
);
void unsetAllWords ();
/// @}
protected:
///
/// @name Pipe I/O handlers

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 473 2011-05-23 03:38:03Z hyunghwan.chung $
* $Id: awk.h 474 2011-05-23 16:52:37Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -274,10 +274,12 @@ struct qse_awk_val_map_itr_t
};
typedef struct qse_awk_val_map_itr_t qse_awk_val_map_itr_t;
#define QSE_AWK_VAL_MAP_ITR_KPTR(itr) QSE_HTB_KPTR((itr)->pair)
#define QSE_AWK_VAL_MAP_ITR_KLEN(itr) QSE_HTB_KLEN((itr)->pair)
#define QSE_AWK_VAL_MAP_ITR_VPTR(itr) QSE_HTB_VPTR((itr)->pair)
#define QSE_AWK_VAL_MAP_ITR_KEY_PTR(itr) \
((const qse_char_t*)QSE_HTB_KPTR((itr)->pair))
#define QSE_AWK_VAL_MAP_ITR_KEY_LEN(itr) \
(*(const qse_size_t*)&QSE_HTB_KLEN((itr)->pair))
#define QSE_AWK_VAL_MAP_ITR_VAL(itr) \
((const qse_awk_val_t*)QSE_HTB_VPTR((itr)->pair))
/**
* The qse_awk_nde_type_t defines the node types.
@ -366,6 +368,11 @@ struct qse_awk_fun_t
};
typedef struct qse_awk_fun_t qse_awk_fun_t;
#define QSE_AWK_FUN_NAME(fun) ((const qse_xstr_t*)&(fun)->name)
#define QSE_AWK_FUN_NAME_PTR(fun) ((const qse_char_t*)(fun)->name.ptr)
#define QSE_AWK_FUN_NAME_LEN(fun) (*(const qse_size_t*)&(fun)->name.len)
#define QSE_AWK_FUN_NARGS(fun) (*(const qse_size_t*)&(fun)->nargs)
typedef int (*qse_awk_sprintf_t) (
qse_awk_t* awk,
qse_char_t* buf,
@ -1323,39 +1330,6 @@ void qse_awk_setmaxdepth (
qse_size_t depth /**< maximum depth */
);
int qse_awk_getword (
qse_awk_t* awk,
const qse_cstr_t* okw,
qse_cstr_t* nkw
);
int qse_awk_unsetword (
qse_awk_t* awk,
const qse_cstr_t* kw
);
void qse_awk_unsetallwords (
qse_awk_t* awk
);
/**
* The qse_awk_setword() function enables replacement of a name of a keyword,
* intrinsic global variables, and intrinsic functions.
*
* If @a nkw is #QSE_NULL or @a nlen is zero and @a okw is #QSE_NULL or
* @a olen is zero, it unsets all word replacements; If @a nkw is #QSE_NULL or
* @a nlen is zero, it unsets the replacement for @a okw and @a olen; If
* all of them are valid, it sets the word replace for @a okw and @a olen
* to @a nkw and @a nlen.
*
* @return 0 on success, -1 on failure
*/
int qse_awk_setword (
qse_awk_t* awk, /**< awk */
const qse_cstr_t* okw, /**< old keyword */
const qse_cstr_t* nkw /**< new keyword */
);
/**
* The qse_awk_addgbl() function adds an intrinsic global variable.
* @return the ID of the global variable added on success, -1 on failure.

View File

@ -1,5 +1,5 @@
/*
* $Id: dll.h 441 2011-04-22 14:28:43Z hyunghwan.chung $
* $Id: dll.h 474 2011-05-23 16:52:37Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -195,9 +195,8 @@ struct qse_dll_node_t
/* the first two fields in sync with qse_gdl_t */
qse_dll_node_t* prev;
qse_dll_node_t* next;
void* dptr; /**< data pointer */
qse_size_t dlen; /**< data length */
/* data */
qse_xptl_t val;
};
/**
@ -220,8 +219,9 @@ struct qse_dll_t
#define QSE_DLL_COPIER_INLINE ((qse_dll_copier_t)2)
#define QSE_DLL_SCALE(dll) ((const int)(dll)->scale)
#define QSE_DLL_DPTR(node) ((node)->dptr)
#define QSE_DLL_DLEN(node) ((node)->dlen)
#define QSE_DLL_DPTR(node) ((node)->val.ptr)
#define QSE_DLL_DLEN(node) ((node)->val.len)
#ifdef __cplusplus
extern "C" {

View File

@ -1,5 +1,5 @@
/*
* $Id: htb.h 441 2011-04-22 14:28:43Z hyunghwan.chung $
* $Id: htb.h 474 2011-05-23 16:52:37Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -195,10 +195,8 @@ typedef qse_htb_pair_t* (*qse_htb_cbserter_t) (
*/
struct qse_htb_pair_t
{
void* kptr; /**< key pointer */
qse_size_t klen; /**< key length */
void* vptr; /**< value pointer */
qse_size_t vlen; /**< value length */
qse_xptl_t key;
qse_xptl_t val;
/* management information below */
qse_htb_pair_t* next;
@ -253,7 +251,6 @@ struct qse_htb_t
qse_htb_pair_t** bucket;
};
/**
* The QSE_HTB_COPIER_SIMPLE macros defines a copier that remembers the
* pointer and length of data in a pair.
@ -276,22 +273,23 @@ struct qse_htb_t
/**
* The QSE_HTB_SIZE() macro returns the number of pairs in a hash table.
*/
#define QSE_HTB_SIZE(m) ((const qse_size_t)(m)->size)
#define QSE_HTB_SIZE(m) (*(const qse_size_t*)&(m)->size)
/**
* The QSE_HTB_CAPA() macro returns the maximum number of pairs that can be
* stored in a hash table without further reorganization.
*/
#define QSE_HTB_CAPA(m) ((const qse_size_t)(m)->capa)
#define QSE_HTB_CAPA(m) (*(const qse_size_t*)&(m)->capa)
#define QSE_HTB_FACTOR(m) ((const int)(m)->factor)
#define QSE_HTB_KSCALE(m) ((const int)(m)->scale[QSE_HTB_KEY])
#define QSE_HTB_VSCALE(m) ((const int)(m)->scale[QSE_HTB_VAL])
#define QSE_HTB_FACTOR(m) (*(const int*)&(m)->factor)
#define QSE_HTB_KSCALE(m) (*(const int*)&(m)->scale[QSE_HTB_KEY])
#define QSE_HTB_VSCALE(m) (*(const int*)&(m)->scale[QSE_HTB_VAL])
#define QSE_HTB_KPTR(p) ((p)->key.ptr)
#define QSE_HTB_KLEN(p) ((p)->key.len)
#define QSE_HTB_VPTR(p) ((p)->val.ptr)
#define QSE_HTB_VLEN(p) ((p)->val.len)
#define QSE_HTB_KPTR(p) ((p)->kptr)
#define QSE_HTB_KLEN(p) ((p)->klen)
#define QSE_HTB_VPTR(p) ((p)->vptr)
#define QSE_HTB_VLEN(p) ((p)->vlen)
#define QSE_HTB_NEXT(p) ((p)->next)
#ifdef __cplusplus
@ -641,9 +639,9 @@ qse_size_t qse_htb_dflhash (
*/
int qse_htb_dflcomp (
qse_htb_t* htb,
const void* kptr1,
const void* kptr1,
qse_size_t klen1,
const void* kptr2,
const void* kptr2,
qse_size_t klen2
);

View File

@ -1,5 +1,5 @@
/*
* $Id: lda.h 441 2011-04-22 14:28:43Z hyunghwan.chung $
* $Id: lda.h 474 2011-05-23 16:52:37Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -37,7 +37,7 @@ enum qse_lda_walk_t
};
typedef struct qse_lda_t qse_lda_t;
typedef struct qse_lda_node_t qse_lda_node_t;
typedef struct qse_lda_slot_t qse_lda_slot_t;
typedef enum qse_lda_walk_t qse_lda_walk_t;
#define QSE_LDA_COPIER_SIMPLE ((qse_lda_copier_t)1)
@ -45,12 +45,12 @@ typedef enum qse_lda_walk_t qse_lda_walk_t;
#define QSE_LDA_NIL ((qse_size_t)-1)
#define QSE_LDA_SIZE(lda) ((const qse_size_t)(lda)->size)
#define QSE_LDA_CAPA(lda) ((const qse_size_t)(lda)->capa)
#define QSE_LDA_SIZE(lda) (*(const qse_size_t*)&(lda)->size)
#define QSE_LDA_CAPA(lda) (*(const qse_size_t*)&(lda)->capa)
#define QSE_LDA_NODE(lda,index) ((lda)->node[index])
#define QSE_LDA_DPTR(lda,index) ((lda)->node[index]->dptr)
#define QSE_LDA_DLEN(lda,index) ((lda)->node[index]->dlen)
#define QSE_LDA_DATA(lda,index) ((const qse_xptl_t*)&(lda)->node[index]->val)
#define QSE_LDA_DPTR(lda,index) ((lda)->node[index]->val.ptr)
#define QSE_LDA_DLEN(lda,index) ((lda)->node[index]->val.len)
/**
* The qse_lda_copier_t type defines a callback function for node construction.
@ -139,16 +139,15 @@ struct qse_lda_t
qse_byte_t scale; /* scale factor */
qse_size_t size; /* number of items */
qse_size_t capa; /* capacity */
qse_lda_node_t** node;
qse_lda_slot_t** node;
};
/**
* The qse_lda_node_t type defines a linear dynamic array node
* The qse_lda_slot_t type defines a linear dynamic array node
*/
struct qse_lda_node_t
struct qse_lda_slot_t
{
void* dptr;
qse_size_t dlen;
qse_xptl_t val;
};
#ifdef __cplusplus
@ -286,17 +285,17 @@ qse_lda_t* qse_lda_setcapa (
);
qse_size_t qse_lda_search (
qse_lda_t* lda,
qse_size_t pos,
qse_lda_t* lda,
qse_size_t pos,
const void* dptr,
qse_size_t dlen
qse_size_t dlen
);
qse_size_t qse_lda_rsearch (
qse_lda_t* lda,
qse_size_t pos,
qse_lda_t* lda,
qse_size_t pos,
const void* dptr,
qse_size_t dlen
qse_size_t dlen
);
qse_size_t qse_lda_upsert (

View File

@ -170,10 +170,8 @@ typedef qse_rbt_pair_t* (*qse_rbt_cbserter_t) (
*/
struct qse_rbt_pair_t
{
void* kptr; /**< key pointer */
qse_size_t klen; /**< key length */
void* vptr; /**< value pointer */
qse_size_t vlen; /**< value length */
qse_xptl_t key;
qse_xptl_t val;
/* management information below */
enum
@ -258,10 +256,11 @@ struct qse_rbt_t
#define QSE_RBT_KSCALE(m) ((const int)(m)->scale[QSE_RBT_KEY])
#define QSE_RBT_VSCALE(m) ((const int)(m)->scale[QSE_RBT_VAL])
#define QSE_RBT_KPTR(p) ((p)->kptr)
#define QSE_RBT_KLEN(p) ((p)->klen)
#define QSE_RBT_VPTR(p) ((p)->vptr)
#define QSE_RBT_VLEN(p) ((p)->vlen)
#define QSE_RBT_KPTR(p) ((p)->key.ptr)
#define QSE_RBT_KLEN(p) ((p)->key.len)
#define QSE_RBT_VPTR(p) ((p)->val.ptr)
#define QSE_RBT_VLEN(p) ((p)->val.len)
#define QSE_RBT_NEXT(p) ((p)->next)
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* $Id: sll.h 441 2011-04-22 14:28:43Z hyunghwan.chung $
* $Id: sll.h 474 2011-05-23 16:52:37Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -124,8 +124,7 @@ struct qse_sll_t
struct qse_sll_node_t
{
qse_sll_node_t* next; /* point to the next node */
void* dptr; /* data pointer */
qse_size_t dlen; /* data length */
qse_xptl_t val;
};
#define QSE_SLL_COPIER_SIMPLE ((qse_sll_copier_t)1)
@ -139,12 +138,12 @@ struct qse_sll_node_t
/**
* The QSE_SLL_DPTR macro gets the data pointer in a node.
*/
#define QSE_SLL_DPTR(node) ((node)->dptr)
#define QSE_SLL_DPTR(node) ((node)->val.ptr)
/**
* The QSE_SLL_DLEN macro gets the length of data in a node.
*/
#define QSE_SLL_DLEN(node) ((node)->dlen)
#define QSE_SLL_DLEN(node) ((node)->val.len)
/**
* The QSE_SLL_NEXT macro gets the next node.

View File

@ -1,5 +1,5 @@
/*
* $Id: types.h 451 2011-05-03 14:00:38Z hyunghwan.chung $
* $Id: types.h 474 2011-05-23 16:52:37Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -490,6 +490,26 @@ typedef struct qse_wcstr_t qse_wcstr_t;
typedef qse_wcstr_t qse_cstr_t;
#endif
/**
* The qse_cptl_t type defines a pair type of a constant pointer and a length.
*/
struct qse_cptl_t
{
const void* ptr;
qse_size_t len;
};
typedef struct qse_cptl_t qse_cptl_t;
/**
* The qse_xptl_t type defines a pair type of a pointer and a length.
*/
struct qse_xptl_t
{
void* ptr;
qse_size_t len;
};
typedef struct qse_xptl_t qse_xptl_t;
/**
* allocate a memory chunk of the size @a n.
* @return a pointer to a memory chunk on success, QSE_NULL on failure.