* added qse_cptl_t/qse_xptl_t
* deleted word substitution functions from awk
This commit is contained in:
parent
40711d3320
commit
7e6a4dc0d5
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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" {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp 462 2011-05-18 14:36:40Z hyunghwan.chung $
|
||||
* $Id: Awk.cpp 474 2011-05-23 16:52:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -806,8 +806,8 @@ Awk::Value::IndexIterator Awk::Value::getFirstIndex (Index* idx) const
|
||||
iptr = qse_awk_rtx_getfirstmapvalitr (this->run->rtx, this->val, &itr);
|
||||
if (iptr == QSE_NULL) return IndexIterator::END; // no more key
|
||||
|
||||
idx->ptr = (const char_t*)QSE_AWK_VAL_MAP_ITR_KPTR(iptr);
|
||||
idx->len = QSE_AWK_VAL_MAP_ITR_KLEN(iptr);
|
||||
idx->ptr = QSE_AWK_VAL_MAP_ITR_KEY_PTR(iptr);
|
||||
idx->len = QSE_AWK_VAL_MAP_ITR_KEY_LEN(iptr);
|
||||
|
||||
return itr;
|
||||
}
|
||||
@ -827,8 +827,8 @@ Awk::Value::IndexIterator Awk::Value::getNextIndex (
|
||||
iptr = qse_awk_rtx_getnextmapvalitr (this->run->rtx, this->val, &itr);
|
||||
if (iptr == QSE_NULL) return IndexIterator::END; // no more key
|
||||
|
||||
idx->ptr = (const char_t*)QSE_AWK_VAL_MAP_ITR_KPTR(iptr);
|
||||
idx->len = QSE_AWK_VAL_MAP_ITR_KLEN(iptr);
|
||||
idx->ptr = QSE_AWK_VAL_MAP_ITR_KEY_PTR(iptr);
|
||||
idx->len = QSE_AWK_VAL_MAP_ITR_KEY_LEN(iptr);
|
||||
|
||||
return itr;
|
||||
}
|
||||
@ -1567,30 +1567,6 @@ int Awk::deleteFunction (const char_t* name)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Awk::getWord (const cstr_t* ow, cstr_t* nw)
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_getword (awk, ow, nw);
|
||||
}
|
||||
|
||||
int Awk::setWord (const cstr_t* ow, const cstr_t* nw)
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_setword (awk, ow, nw);
|
||||
}
|
||||
|
||||
int Awk::unsetWord (const cstr_t* w)
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
return qse_awk_unsetword (awk, w);
|
||||
}
|
||||
|
||||
void Awk::unsetAllWords ()
|
||||
{
|
||||
QSE_ASSERT (awk != QSE_NULL);
|
||||
qse_awk_unsetallwords (awk);
|
||||
}
|
||||
|
||||
Awk::ssize_t Awk::readSource (
|
||||
awk_t* awk, sio_cmd_t cmd, sio_arg_t* arg,
|
||||
char_t* data, size_t count)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c 459 2011-05-17 14:37:51Z hyunghwan.chung $
|
||||
* $Id: awk.c 474 2011-05-23 16:52:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -161,26 +161,6 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
|
||||
if (init_token (mmgr, &awk->tok) == -1) goto oops;
|
||||
if (init_token (mmgr, &awk->ntok) == -1) goto oops;
|
||||
|
||||
awk->wtab = qse_htb_open (
|
||||
mmgr, QSE_SIZEOF(awk),
|
||||
512, 70, QSE_SIZEOF(qse_char_t), QSE_SIZEOF(qse_char_t)
|
||||
);
|
||||
if (awk->wtab == QSE_NULL) goto oops;
|
||||
*(qse_awk_t**)QSE_XTN(awk->wtab) = awk;
|
||||
qse_htb_setmancbs (awk->wtab,
|
||||
qse_htb_mancbs(QSE_HTB_MANCBS_INLINE_COPIERS)
|
||||
);
|
||||
|
||||
awk->rwtab = qse_htb_open (
|
||||
mmgr, QSE_SIZEOF(awk),
|
||||
512, 70, QSE_SIZEOF(qse_char_t), QSE_SIZEOF(qse_char_t)
|
||||
);
|
||||
if (awk->rwtab == QSE_NULL) goto oops;
|
||||
*(qse_awk_t**)QSE_XTN(awk->rwtab) = awk;
|
||||
qse_htb_setmancbs (awk->rwtab,
|
||||
qse_htb_mancbs(QSE_HTB_MANCBS_INLINE_COPIERS)
|
||||
);
|
||||
|
||||
awk->sio.names = qse_htb_open (
|
||||
mmgr, QSE_SIZEOF(awk), 128, 70, QSE_SIZEOF(qse_char_t), 1
|
||||
);
|
||||
@ -280,8 +260,6 @@ oops:
|
||||
if (awk->parse.funs) qse_htb_close (awk->parse.funs);
|
||||
if (awk->tree.funs) qse_htb_close (awk->tree.funs);
|
||||
if (awk->sio.names) qse_htb_close (awk->sio.names);
|
||||
if (awk->rwtab) qse_htb_close (awk->rwtab);
|
||||
if (awk->wtab) qse_htb_close (awk->wtab);
|
||||
fini_token (&awk->ntok);
|
||||
fini_token (&awk->tok);
|
||||
fini_token (&awk->ptok);
|
||||
@ -305,9 +283,6 @@ int qse_awk_close (qse_awk_t* awk)
|
||||
qse_htb_close (awk->tree.funs);
|
||||
qse_htb_close (awk->sio.names);
|
||||
|
||||
qse_htb_close (awk->rwtab);
|
||||
qse_htb_close (awk->wtab);
|
||||
|
||||
fini_token (&awk->ntok);
|
||||
fini_token (&awk->tok);
|
||||
fini_token (&awk->ptok);
|
||||
@ -424,89 +399,6 @@ void qse_awk_stopall (qse_awk_t* awk)
|
||||
awk->stopall = QSE_TRUE;
|
||||
}
|
||||
|
||||
int qse_awk_getword (qse_awk_t* awk, const qse_cstr_t* okw, qse_cstr_t* nkw)
|
||||
{
|
||||
qse_htb_pair_t* p;
|
||||
|
||||
p = qse_htb_search (awk->wtab, okw->ptr, okw->len);
|
||||
if (p == QSE_NULL) return -1;
|
||||
|
||||
nkw->ptr = ((qse_cstr_t*)p->vptr)->ptr;
|
||||
nkw->len = ((qse_cstr_t*)p->vptr)->len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qse_awk_unsetword (qse_awk_t* awk, const qse_cstr_t* kw)
|
||||
{
|
||||
qse_htb_pair_t* p;
|
||||
|
||||
QSE_ASSERT (kw->ptr != QSE_NULL);
|
||||
|
||||
p = qse_htb_search (awk->wtab, kw->ptr, kw->len);
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOENT, kw);
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_htb_delete (awk->rwtab, QSE_HTB_VPTR(p), QSE_HTB_VLEN(p));
|
||||
qse_htb_delete (awk->wtab, kw->ptr, kw->len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qse_awk_unsetallwords (qse_awk_t* awk)
|
||||
{
|
||||
qse_htb_clear (awk->wtab);
|
||||
qse_htb_clear (awk->rwtab);
|
||||
}
|
||||
|
||||
int qse_awk_setword (
|
||||
qse_awk_t* awk, const qse_cstr_t* okw, const qse_cstr_t* nkw)
|
||||
{
|
||||
if (nkw == QSE_NULL)
|
||||
{
|
||||
if (okw == QSE_NULL)
|
||||
{
|
||||
/* clear the entire table */
|
||||
qse_awk_unsetallwords (awk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return qse_awk_unsetword (awk, okw);
|
||||
}
|
||||
else if (okw == QSE_NULL)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_EINVAL, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
QSE_ASSERT (okw->ptr != QSE_NULL);
|
||||
QSE_ASSERT (nkw->ptr != QSE_NULL);
|
||||
|
||||
/* set the word */
|
||||
if (qse_htb_upsert (
|
||||
awk->wtab,
|
||||
(qse_char_t*)okw->ptr, okw->len,
|
||||
(qse_char_t*)nkw->ptr, nkw->len) == QSE_NULL)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qse_htb_upsert (
|
||||
awk->rwtab,
|
||||
(qse_char_t*)nkw->ptr, nkw->len,
|
||||
(qse_char_t*)okw->ptr, okw->len) == QSE_NULL)
|
||||
{
|
||||
qse_htb_delete (awk->wtab, okw->ptr, okw->len);
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
qse_size_t qse_awk_getmaxdepth (qse_awk_t* awk, qse_awk_depth_t type)
|
||||
{
|
||||
return (type == QSE_AWK_DEPTH_BLOCK_PARSE)? awk->parse.depth.max.block:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: fnc.c 463 2011-05-19 02:50:51Z hyunghwan.chung $
|
||||
* $Id: fnc.c 474 2011-05-23 16:52:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -186,8 +186,6 @@ qse_awk_fnc_t* qse_awk_getfnc (
|
||||
{
|
||||
qse_awk_fnc_t* fnc;
|
||||
qse_htb_pair_t* pair;
|
||||
const qse_char_t* k;
|
||||
qse_size_t l;
|
||||
|
||||
/* search the system function table */
|
||||
/* TODO: some speed up? binary search by ordering the table? */
|
||||
@ -196,66 +194,12 @@ qse_awk_fnc_t* qse_awk_getfnc (
|
||||
if (fnc->valid != 0 &&
|
||||
(awk->option & fnc->valid) != fnc->valid) continue;
|
||||
|
||||
pair = qse_htb_search (
|
||||
awk->wtab, fnc->name.ptr, fnc->name.len);
|
||||
if (pair != QSE_NULL)
|
||||
{
|
||||
/* found in the customized word table */
|
||||
k = QSE_HTB_VPTR(pair);
|
||||
l = QSE_HTB_VLEN(pair);
|
||||
}
|
||||
else
|
||||
{
|
||||
k = fnc->name.ptr;
|
||||
l = fnc->name.len;
|
||||
if (qse_strxncmp (
|
||||
fnc->name.ptr, fnc->name.len,
|
||||
name, len) == 0) return fnc;
|
||||
}
|
||||
|
||||
if (qse_strxncmp (k, l, name, len) == 0) return fnc;
|
||||
}
|
||||
|
||||
/* NOTE: I suspect this block of code might be very fragile.
|
||||
* because I'm trying to support qse_awk_setword in
|
||||
* a very flimsy way here. Would it be better to drop
|
||||
* qse_awk_setword totally? */
|
||||
pair = qse_htb_search (awk->rwtab, name, len);
|
||||
if (pair != QSE_NULL)
|
||||
{
|
||||
/* the current name is a target name for
|
||||
* one of the original word. */
|
||||
k = QSE_HTB_VPTR(pair);
|
||||
l = QSE_HTB_VLEN(pair);
|
||||
}
|
||||
else
|
||||
{
|
||||
pair = qse_htb_search (awk->wtab, name, len);
|
||||
if (pair != QSE_NULL)
|
||||
{
|
||||
k = QSE_HTB_VPTR(pair);
|
||||
l = QSE_HTB_VLEN(pair);
|
||||
|
||||
if (qse_strxncmp (name, len, k, l) != 0)
|
||||
{
|
||||
/* it name is not a target name but has
|
||||
* a target name different from itself,
|
||||
* it cannot be a intrinsic function name.
|
||||
*
|
||||
* For instance, name is "sin" here after
|
||||
* qse_awk_setword ("sin", "cain") is called.
|
||||
* If name were "cain", it would be handled
|
||||
* in the outmost if block */
|
||||
|
||||
return QSE_NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
k = name;
|
||||
l = len;
|
||||
}
|
||||
}
|
||||
/* END NOTE */
|
||||
|
||||
pair = qse_htb_search (awk->fnc.user, k, l);
|
||||
pair = qse_htb_search (awk->fnc.user, name, len);
|
||||
if (pair == QSE_NULL) return QSE_NULL;
|
||||
|
||||
fnc = (qse_awk_fnc_t*)QSE_HTB_VPTR(pair);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c 462 2011-05-18 14:36:40Z hyunghwan.chung $
|
||||
* $Id: parse.c 474 2011-05-23 16:52:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -237,8 +237,7 @@ typedef struct kwent_t kwent_t;
|
||||
|
||||
struct kwent_t
|
||||
{
|
||||
const qse_char_t* name;
|
||||
qse_size_t namelen;
|
||||
qse_cstr_t name;
|
||||
int type;
|
||||
int valid; /* the entry is valid when this option is set */
|
||||
};
|
||||
@ -247,30 +246,30 @@ static kwent_t kwtab[] =
|
||||
{
|
||||
/* keep this table in sync with the kw_t enums in <parse.h>.
|
||||
* also keep it sorted by the first field for binary search */
|
||||
{ QSE_T("BEGIN"), 5, TOK_BEGIN, QSE_AWK_PABLOCK },
|
||||
{ QSE_T("END"), 3, TOK_END, QSE_AWK_PABLOCK },
|
||||
{ QSE_T("break"), 5, TOK_BREAK, 0 },
|
||||
{ QSE_T("continue"), 8, TOK_CONTINUE, 0 },
|
||||
{ QSE_T("delete"), 6, TOK_DELETE, 0 },
|
||||
{ QSE_T("do"), 2, TOK_DO, 0 },
|
||||
{ QSE_T("else"), 4, TOK_ELSE, 0 },
|
||||
{ QSE_T("exit"), 4, TOK_EXIT, 0 },
|
||||
{ QSE_T("for"), 3, TOK_FOR, 0 },
|
||||
{ QSE_T("function"), 8, TOK_FUNCTION, 0 },
|
||||
{ QSE_T("getline"), 7, TOK_GETLINE, QSE_AWK_RIO },
|
||||
{ QSE_T("global"), 6, TOK_GLOBAL, QSE_AWK_EXPLICIT },
|
||||
{ QSE_T("if"), 2, TOK_IF, 0 },
|
||||
{ QSE_T("in"), 2, TOK_IN, 0 },
|
||||
{ QSE_T("include"), 7, TOK_INCLUDE, QSE_AWK_INCLUDE },
|
||||
{ QSE_T("local"), 5, TOK_LOCAL, QSE_AWK_EXPLICIT },
|
||||
{ QSE_T("next"), 4, TOK_NEXT, QSE_AWK_PABLOCK },
|
||||
{ QSE_T("nextfile"), 8, TOK_NEXTFILE, QSE_AWK_PABLOCK },
|
||||
{ QSE_T("nextofile"), 9, TOK_NEXTOFILE, QSE_AWK_PABLOCK | QSE_AWK_NEXTOFILE },
|
||||
{ QSE_T("print"), 5, TOK_PRINT, QSE_AWK_RIO },
|
||||
{ QSE_T("printf"), 6, TOK_PRINTF, QSE_AWK_RIO },
|
||||
{ QSE_T("reset"), 5, TOK_RESET, QSE_AWK_RESET },
|
||||
{ QSE_T("return"), 6, TOK_RETURN, 0 },
|
||||
{ QSE_T("while"), 5, TOK_WHILE, 0 }
|
||||
{ { QSE_T("BEGIN"), 5 }, TOK_BEGIN, QSE_AWK_PABLOCK },
|
||||
{ { QSE_T("END"), 3 }, TOK_END, QSE_AWK_PABLOCK },
|
||||
{ { QSE_T("break"), 5 }, TOK_BREAK, 0 },
|
||||
{ { QSE_T("continue"), 8 }, TOK_CONTINUE, 0 },
|
||||
{ { QSE_T("delete"), 6 }, TOK_DELETE, 0 },
|
||||
{ { QSE_T("do"), 2 }, TOK_DO, 0 },
|
||||
{ { QSE_T("else"), 4 }, TOK_ELSE, 0 },
|
||||
{ { QSE_T("exit"), 4 }, TOK_EXIT, 0 },
|
||||
{ { QSE_T("for"), 3 }, TOK_FOR, 0 },
|
||||
{ { QSE_T("function"), 8 }, TOK_FUNCTION, 0 },
|
||||
{ { QSE_T("getline"), 7 }, TOK_GETLINE, QSE_AWK_RIO },
|
||||
{ { QSE_T("global"), 6 }, TOK_GLOBAL, QSE_AWK_EXPLICIT },
|
||||
{ { QSE_T("if"), 2 }, TOK_IF, 0 },
|
||||
{ { QSE_T("in"), 2 }, TOK_IN, 0 },
|
||||
{ { QSE_T("include"), 7 }, TOK_INCLUDE, QSE_AWK_INCLUDE },
|
||||
{ { QSE_T("local"), 5 }, TOK_LOCAL, QSE_AWK_EXPLICIT },
|
||||
{ { QSE_T("next"), 4 }, TOK_NEXT, QSE_AWK_PABLOCK },
|
||||
{ { QSE_T("nextfile"), 8 }, TOK_NEXTFILE, QSE_AWK_PABLOCK },
|
||||
{ { QSE_T("nextofile"), 9 }, TOK_NEXTOFILE, QSE_AWK_PABLOCK | QSE_AWK_NEXTOFILE },
|
||||
{ { QSE_T("print"), 5 }, TOK_PRINT, QSE_AWK_RIO },
|
||||
{ { QSE_T("printf"), 6 }, TOK_PRINTF, QSE_AWK_RIO },
|
||||
{ { QSE_T("reset"), 5 }, TOK_RESET, QSE_AWK_RESET },
|
||||
{ { QSE_T("return"), 6 }, TOK_RETURN, 0 },
|
||||
{ { QSE_T("while"), 5 }, TOK_WHILE, 0 }
|
||||
};
|
||||
|
||||
typedef struct global_t global_t;
|
||||
@ -493,21 +492,9 @@ const qse_char_t* qse_awk_getgblname (
|
||||
return QSE_LDA_DPTR(awk->parse.gbls,idx);
|
||||
}
|
||||
|
||||
qse_cstr_t* qse_awk_getkw (qse_awk_t* awk, int id, qse_cstr_t* s)
|
||||
void qse_awk_getkwname (qse_awk_t* awk, qse_awk_kwid_t id, qse_cstr_t* s)
|
||||
{
|
||||
qse_htb_pair_t* p;
|
||||
|
||||
s->ptr = kwtab[id].name;
|
||||
s->len = kwtab[id].namelen;
|
||||
|
||||
p = qse_htb_search (awk->wtab, s->ptr, s->len);
|
||||
if (p != QSE_NULL)
|
||||
{
|
||||
s->ptr = QSE_HTB_VPTR(p);
|
||||
s->len = QSE_HTB_VLEN(p);
|
||||
}
|
||||
|
||||
return s;
|
||||
*s = kwtab[id].name;
|
||||
}
|
||||
|
||||
static int parse (qse_awk_t* awk)
|
||||
@ -1679,24 +1666,10 @@ struct check_global_t
|
||||
static qse_lda_walk_t check_global (qse_lda_t* lda, qse_size_t index, void* arg)
|
||||
{
|
||||
qse_cstr_t tmp;
|
||||
qse_awk_t* awk = *(qse_awk_t**)QSE_XTN(lda);
|
||||
/*qse_awk_t* awk = *(qse_awk_t**)QSE_XTN(lda);*/
|
||||
check_global_t* cg = (check_global_t*)arg;
|
||||
|
||||
tmp.ptr = QSE_LDA_DPTR(lda,index);
|
||||
tmp.len = QSE_LDA_DLEN(lda,index);
|
||||
|
||||
if (index < awk->tree.ngbls_base)
|
||||
{
|
||||
qse_htb_pair_t* pair;
|
||||
|
||||
pair = qse_htb_search (awk->wtab, tmp.ptr, tmp.len);
|
||||
if (pair != QSE_NULL)
|
||||
{
|
||||
tmp.ptr = ((qse_cstr_t*)(pair->vptr))->ptr;
|
||||
tmp.len = ((qse_cstr_t*)(pair->vptr))->len;
|
||||
}
|
||||
}
|
||||
|
||||
tmp = *(qse_cstr_t*)QSE_LDA_DATA(lda,index);
|
||||
if (qse_strxncmp (tmp.ptr, tmp.len, cg->name.ptr, cg->name.len) == 0)
|
||||
{
|
||||
cg->index = index;
|
||||
@ -1976,8 +1949,7 @@ static qse_awk_t* collect_locals (
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
lcl.ptr = QSE_STR_PTR(awk->tok.name);
|
||||
lcl.len = QSE_STR_LEN(awk->tok.name);
|
||||
lcl = *QSE_STR_XSTR(awk->tok.name);
|
||||
|
||||
/* check if it conflicts with a builtin function name
|
||||
* function f() { local length; } */
|
||||
@ -5726,9 +5698,7 @@ static int preget_token (qse_awk_t* awk)
|
||||
static int classify_ident (
|
||||
qse_awk_t* awk, const qse_char_t* name, qse_size_t len)
|
||||
{
|
||||
if (QSE_HTB_SIZE(awk->wtab) <= 0)
|
||||
{
|
||||
/* perform binary search if no custom words are specified */
|
||||
/* perform binary search */
|
||||
|
||||
/* declaring left, right, mid to be of int is ok
|
||||
* because we know kwtab is small enough. */
|
||||
@ -5741,7 +5711,8 @@ static int classify_ident (
|
||||
|
||||
mid = (left + right) / 2;
|
||||
kwp = &kwtab[mid];
|
||||
n = qse_strxncmp (kwp->name, kwp->namelen, name, len);
|
||||
|
||||
n = qse_strxncmp (kwp->name.ptr, kwp->name.len, name, len);
|
||||
if (n > 0)
|
||||
{
|
||||
/* if left, right, mid were of qse_size_t,
|
||||
@ -5760,41 +5731,6 @@ static int classify_ident (
|
||||
return kwp->type;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* perform linear search if there are any custom words set */
|
||||
kwent_t* kwp, * end;
|
||||
qse_htb_pair_t* pair;
|
||||
|
||||
end = kwtab + QSE_COUNTOF(kwtab);
|
||||
for (kwp = kwtab; kwp < end; kwp++)
|
||||
{
|
||||
const qse_char_t* k;
|
||||
qse_size_t l;
|
||||
|
||||
if (kwp->valid != 0 &&
|
||||
(awk->option & kwp->valid) != kwp->valid) continue;
|
||||
|
||||
pair = qse_htb_search (awk->wtab, kwp->name, kwp->namelen);
|
||||
if (pair != QSE_NULL)
|
||||
{
|
||||
k = ((qse_cstr_t*)(pair->vptr))->ptr;
|
||||
l = ((qse_cstr_t*)(pair->vptr))->len;
|
||||
}
|
||||
else
|
||||
{
|
||||
k = kwp->name;
|
||||
l = kwp->namelen;
|
||||
}
|
||||
|
||||
if (qse_strxncmp (k, l, name, len) == 0)
|
||||
{
|
||||
return kwp->type;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return TOK_IDENT;
|
||||
}
|
||||
@ -5859,7 +5795,7 @@ static int deparse (qse_awk_t* awk)
|
||||
|
||||
QSE_ASSERT (awk->tree.ngbls > 0);
|
||||
|
||||
qse_awk_getkw (awk, KW_GLOBAL, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_GLOBAL, &kw);
|
||||
if (qse_awk_putsrcstrx(awk,kw.ptr,kw.len) <= -1)
|
||||
{
|
||||
EXIT_DEPARSE ();
|
||||
@ -5952,7 +5888,7 @@ static int deparse (qse_awk_t* awk)
|
||||
{
|
||||
qse_cstr_t kw;
|
||||
|
||||
qse_awk_getkw (awk, KW_BEGIN, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_BEGIN, &kw);
|
||||
|
||||
if (qse_awk_putsrcstrx (awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE ();
|
||||
if (qse_awk_putsrcstr (awk, QSE_T(" ")) <= -1) EXIT_DEPARSE ();
|
||||
@ -6014,7 +5950,7 @@ static int deparse (qse_awk_t* awk)
|
||||
{
|
||||
qse_cstr_t kw;
|
||||
|
||||
qse_awk_getkw (awk, KW_END, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_END, &kw);
|
||||
|
||||
if (qse_awk_putsrcstrx (awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE ();
|
||||
if (qse_awk_putsrcstr (awk, QSE_T(" ")) <= -1) EXIT_DEPARSE ();
|
||||
@ -6073,7 +6009,7 @@ static qse_htb_walk_t deparse_func (
|
||||
x->ret = -1; return QSE_HTB_WALK_STOP; \
|
||||
}
|
||||
|
||||
qse_awk_getkw (df->awk, KW_FUNCTION, &kw);
|
||||
qse_awk_getkwname (df->awk, QSE_AWK_KWID_FUNCTION, &kw);
|
||||
PUT_SX (df, kw.ptr, kw.len);
|
||||
|
||||
PUT_C (df, QSE_T(' '));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.h 441 2011-04-22 14:28:43Z hyunghwan.chung $
|
||||
* $Id: parse.h 474 2011-05-23 16:52:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -22,47 +22,66 @@
|
||||
#define _QSE_LIB_AWK_PARSE_H_
|
||||
|
||||
/* these enums should match kwtab in parse.c */
|
||||
enum kw_t
|
||||
enum qse_awk_kwid_t
|
||||
{
|
||||
KW_BEGIN,
|
||||
KW_END,
|
||||
KW_BREAK,
|
||||
KW_CONTINUE,
|
||||
KW_DELETE,
|
||||
KW_DO,
|
||||
KW_ELSE,
|
||||
KW_EXIT,
|
||||
KW_FOR,
|
||||
KW_FUNCTION,
|
||||
KW_GETLINE,
|
||||
KW_GLOBAL,
|
||||
KW_IF,
|
||||
KW_IN,
|
||||
KW_INCLUDE,
|
||||
KW_LOCAL,
|
||||
KW_NEXT,
|
||||
KW_NEXTFILE,
|
||||
KW_NEXTOFILE,
|
||||
KW_PRINT,
|
||||
KW_PRINTF,
|
||||
KW_RESET,
|
||||
KW_RETURN,
|
||||
KW_WHILE
|
||||
QSE_AWK_KWID_BEGIN,
|
||||
QSE_AWK_KWID_END,
|
||||
QSE_AWK_KWID_BREAK,
|
||||
QSE_AWK_KWID_CONTINUE,
|
||||
QSE_AWK_KWID_DELETE,
|
||||
QSE_AWK_KWID_DO,
|
||||
QSE_AWK_KWID_ELSE,
|
||||
QSE_AWK_KWID_EXIT,
|
||||
QSE_AWK_KWID_FOR,
|
||||
QSE_AWK_KWID_FUNCTION,
|
||||
QSE_AWK_KWID_GETLINE,
|
||||
QSE_AWK_KWID_GLOBAL,
|
||||
QSE_AWK_KWID_IF,
|
||||
QSE_AWK_KWID_IN,
|
||||
QSE_AWK_KWID_INCLUDE,
|
||||
QSE_AWK_KWID_LOCAL,
|
||||
QSE_AWK_KWID_NEXT,
|
||||
QSE_AWK_KWID_NEXTFILE,
|
||||
QSE_AWK_KWID_NEXTOFILE,
|
||||
QSE_AWK_KWID_PRINT,
|
||||
QSE_AWK_KWID_PRINTF,
|
||||
QSE_AWK_KWID_RESET,
|
||||
QSE_AWK_KWID_RETURN,
|
||||
QSE_AWK_KWID_WHILE
|
||||
};
|
||||
|
||||
typedef enum qse_awk_kwid_t qse_awk_kwid_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int qse_awk_putsrcstr (qse_awk_t* awk, const qse_char_t* str);
|
||||
int qse_awk_putsrcstr (
|
||||
qse_awk_t* awk,
|
||||
const qse_char_t* str
|
||||
);
|
||||
|
||||
int qse_awk_putsrcstrx (
|
||||
qse_awk_t* awk, const qse_char_t* str, qse_size_t len);
|
||||
qse_awk_t* awk,
|
||||
const qse_char_t* str,
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
const qse_char_t* qse_awk_getgblname (
|
||||
qse_awk_t* awk, qse_size_t idx, qse_size_t* len);
|
||||
qse_cstr_t* qse_awk_getkw (qse_awk_t* awk, int id, qse_cstr_t* s);
|
||||
qse_awk_t* awk,
|
||||
qse_size_t idx,
|
||||
qse_size_t* len
|
||||
);
|
||||
|
||||
int qse_awk_initgbls (qse_awk_t* awk);
|
||||
void qse_awk_getkwname (
|
||||
qse_awk_t* awk,
|
||||
qse_awk_kwid_t id,
|
||||
qse_cstr_t* s
|
||||
);
|
||||
|
||||
int qse_awk_initgbls (
|
||||
qse_awk_t* awk
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: tree.c 447 2011-05-01 13:28:51Z hyunghwan.chung $
|
||||
* $Id: tree.c 474 2011-05-23 16:52:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -576,7 +576,7 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
|
||||
PUT_SRCSTR (awk, QSE_T(" "));
|
||||
}
|
||||
|
||||
qse_awk_getkw (awk, KW_GETLINE, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_GETLINE, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
if (px->var != QSE_NULL)
|
||||
{
|
||||
@ -647,7 +647,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
if (px->nlcls > 0)
|
||||
{
|
||||
PRINT_TABS (awk, depth + 1);
|
||||
qse_awk_getkw (awk, KW_LOCAL, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_LOCAL, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" "));
|
||||
|
||||
@ -692,7 +692,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
qse_awk_nde_if_t* px = (qse_awk_nde_if_t*)p;
|
||||
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_IF, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_IF, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" ("));
|
||||
PRINT_EXPR (awk, px->test);
|
||||
@ -708,7 +708,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
if (px->else_part != QSE_NULL)
|
||||
{
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_ELSE, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_ELSE, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_NL (awk);
|
||||
if (px->else_part->type == QSE_AWK_NDE_BLK)
|
||||
@ -724,7 +724,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
qse_awk_nde_while_t* px = (qse_awk_nde_while_t*)p;
|
||||
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_WHILE, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_WHILE, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" ("));
|
||||
PRINT_EXPR (awk, px->test);
|
||||
@ -746,7 +746,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
qse_awk_nde_while_t* px = (qse_awk_nde_while_t*)p;
|
||||
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_DO, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_DO, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_NL (awk);
|
||||
if (px->body->type == QSE_AWK_NDE_BLK)
|
||||
@ -759,7 +759,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
}
|
||||
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_WHILE, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_WHILE, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" ("));
|
||||
PRINT_EXPR (awk, px->test);
|
||||
@ -773,7 +773,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
qse_awk_nde_for_t* px = (qse_awk_nde_for_t*)p;
|
||||
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_FOR, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_FOR, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" ("));
|
||||
if (px->init != QSE_NULL)
|
||||
@ -809,7 +809,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
qse_awk_nde_foreach_t* px = (qse_awk_nde_foreach_t*)p;
|
||||
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_FOR, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_FOR, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" "));
|
||||
PRINT_EXPR (awk, px->test);
|
||||
@ -828,7 +828,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
case QSE_AWK_NDE_BREAK:
|
||||
{
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_BREAK, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_BREAK, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(";"));
|
||||
PUT_NL (awk);
|
||||
@ -838,7 +838,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
case QSE_AWK_NDE_CONTINUE:
|
||||
{
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_CONTINUE, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_CONTINUE, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(";"));
|
||||
PUT_NL (awk);
|
||||
@ -850,14 +850,14 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
PRINT_TABS (awk, depth);
|
||||
if (((qse_awk_nde_return_t*)p)->val == QSE_NULL)
|
||||
{
|
||||
qse_awk_getkw (awk, KW_RETURN, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_RETURN, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(";"));
|
||||
PUT_NL (awk);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_awk_getkw (awk, KW_RETURN, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_RETURN, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" "));
|
||||
QSE_ASSERT (((qse_awk_nde_return_t*)p)->val->next == QSE_NULL);
|
||||
@ -876,14 +876,14 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
|
||||
if (px->val == QSE_NULL)
|
||||
{
|
||||
qse_awk_getkw (awk, KW_EXIT, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_EXIT, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(";"));
|
||||
PUT_NL (awk);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_awk_getkw (awk, KW_EXIT, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_EXIT, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" "));
|
||||
QSE_ASSERT (px->val->next == QSE_NULL);
|
||||
@ -897,7 +897,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
case QSE_AWK_NDE_NEXT:
|
||||
{
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_NEXT, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_NEXT, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(";"));
|
||||
PUT_NL (awk);
|
||||
@ -909,12 +909,12 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
PRINT_TABS (awk, depth);
|
||||
if (((qse_awk_nde_nextfile_t*)p)->out)
|
||||
{
|
||||
qse_awk_getkw (awk, KW_NEXTOFILE, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_NEXTOFILE, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_awk_getkw (awk, KW_NEXTFILE, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_NEXTFILE, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
}
|
||||
PUT_SRCSTR (awk, QSE_T(";"));
|
||||
@ -925,7 +925,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
case QSE_AWK_NDE_DELETE:
|
||||
{
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_DELETE, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_DELETE, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" "));
|
||||
qse_awk_prnpt (awk, ((qse_awk_nde_delete_t*)p)->var);
|
||||
@ -935,7 +935,7 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
case QSE_AWK_NDE_RESET:
|
||||
{
|
||||
PRINT_TABS (awk, depth);
|
||||
qse_awk_getkw (awk, KW_RESET, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_RESET, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
PUT_SRCSTR (awk, QSE_T(" "));
|
||||
qse_awk_prnpt (awk, ((qse_awk_nde_reset_t*)p)->var);
|
||||
@ -951,12 +951,12 @@ static int print_stmt (qse_awk_t* awk, qse_awk_nde_t* p, int depth)
|
||||
|
||||
if (p->type == QSE_AWK_NDE_PRINT)
|
||||
{
|
||||
qse_awk_getkw (awk, KW_PRINT, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_PRINT, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_awk_getkw (awk, KW_PRINTF, &kw);
|
||||
qse_awk_getkwname (awk, QSE_AWK_KWID_PRINTF, &kw);
|
||||
PUT_SRCSTRX (awk, kw.ptr, kw.len);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: dll.c 441 2011-04-22 14:28:43Z hyunghwan.chung $
|
||||
* $Id: dll.c 474 2011-05-23 16:52:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -24,6 +24,8 @@
|
||||
QSE_IMPLEMENT_COMMON_FUNCTIONS (dll)
|
||||
|
||||
#define TOB(dll,len) ((len)*(dll)->scale)
|
||||
#define DPTR(node) QSE_DLL_DPTR(node)
|
||||
#define DLEN(node) QSE_DLL_DLEN(node)
|
||||
|
||||
static int default_comper (
|
||||
qse_dll_t* dll,
|
||||
@ -171,7 +173,7 @@ static qse_dll_node_t* alloc_node (qse_dll_t* dll, void* dptr, qse_size_t dlen)
|
||||
{
|
||||
n = QSE_MMGR_ALLOC (dll->mmgr, QSE_SIZEOF(qse_dll_node_t));
|
||||
if (n == QSE_NULL) return QSE_NULL;
|
||||
n->dptr = dptr;
|
||||
DPTR(n) = dptr;
|
||||
}
|
||||
else if (dll->copier == QSE_DLL_COPIER_INLINE)
|
||||
{
|
||||
@ -180,21 +182,21 @@ static qse_dll_node_t* alloc_node (qse_dll_t* dll, void* dptr, qse_size_t dlen)
|
||||
if (n == QSE_NULL) return QSE_NULL;
|
||||
|
||||
QSE_MEMCPY (n + 1, dptr, TOB(dll,dlen));
|
||||
n->dptr = n + 1;
|
||||
DPTR(n) = n + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
n = QSE_MMGR_ALLOC (dll->mmgr, QSE_SIZEOF(qse_dll_node_t));
|
||||
if (n == QSE_NULL) return QSE_NULL;
|
||||
n->dptr = dll->copier (dll, dptr, dlen);
|
||||
if (n->dptr == QSE_NULL)
|
||||
DPTR(n) = dll->copier (dll, dptr, dlen);
|
||||
if (DPTR(n) == QSE_NULL)
|
||||
{
|
||||
QSE_MMGR_FREE (dll->mmgr, n);
|
||||
return QSE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
n->dlen = dlen;
|
||||
DLEN(n) = dlen;
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -203,7 +205,7 @@ static QSE_INLINE void free_node (qse_dll_t* dll, qse_dll_node_t* node)
|
||||
if (dll->freeer != QSE_NULL)
|
||||
{
|
||||
/* free the actual data */
|
||||
dll->freeer (dll, node->dptr, node->dlen);
|
||||
dll->freeer (dll, DPTR(node), DLEN(node));
|
||||
}
|
||||
|
||||
/* free the node */
|
||||
@ -217,7 +219,7 @@ qse_dll_node_t* qse_dll_search (
|
||||
|
||||
while (QSE_DLL_ISMEMBER(dll,pos))
|
||||
{
|
||||
if (dll->comper (dll, pos->dptr, pos->dlen, dptr, dlen) == 0)
|
||||
if (dll->comper (dll, DPTR(pos), DLEN(pos), dptr, dlen) == 0)
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
@ -235,7 +237,7 @@ qse_dll_node_t* qse_dll_rsearch (
|
||||
|
||||
while (QSE_DLL_ISMEMBER(dll,pos))
|
||||
{
|
||||
if (dll->comper (dll, pos->dptr, pos->dlen, dptr, dlen) == 0)
|
||||
if (dll->comper (dll, DPTR(pos), DLEN(pos), dptr, dlen) == 0)
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: htb.c 441 2011-04-22 14:28:43Z hyunghwan.chung $
|
||||
* $Id: htb.c 474 2011-05-23 16:52:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -256,7 +256,8 @@ const mancbs_t* qse_htb_mancbs (mancbs_kind_t kind)
|
||||
};
|
||||
|
||||
htb_t* qse_htb_open (
|
||||
mmgr_t* mmgr, size_t xtnsize, size_t capa, int factor, int kscale, int vscale)
|
||||
mmgr_t* mmgr, size_t xtnsize, size_t capa,
|
||||
int factor, int kscale, int vscale)
|
||||
{
|
||||
htb_t* htb;
|
||||
|
||||
@ -289,7 +290,8 @@ void qse_htb_close (htb_t* htb)
|
||||
}
|
||||
|
||||
htb_t* qse_htb_init (
|
||||
htb_t* htb, mmgr_t* mmgr, size_t capa, int factor, int kscale, int vscale)
|
||||
htb_t* htb, mmgr_t* mmgr, size_t capa,
|
||||
int factor, int kscale, int vscale)
|
||||
{
|
||||
if (mmgr == QSE_NULL) mmgr = QSE_MMGR_GETDFL();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: lda.c 441 2011-04-22 14:28:43Z hyunghwan.chung $
|
||||
* $Id: lda.c 474 2011-05-23 16:52:37Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -24,7 +24,7 @@
|
||||
QSE_IMPLEMENT_COMMON_FUNCTIONS (lda)
|
||||
|
||||
#define lda_t qse_lda_t
|
||||
#define node_t qse_lda_node_t
|
||||
#define slot_t qse_lda_slot_t
|
||||
#define copier_t qse_lda_copier_t
|
||||
#define freeer_t qse_lda_freeer_t
|
||||
#define comper_t qse_lda_comper_t
|
||||
@ -36,8 +36,8 @@ QSE_IMPLEMENT_COMMON_FUNCTIONS (lda)
|
||||
#define size_t qse_size_t
|
||||
|
||||
#define TOB(lda,len) ((len)*(lda)->scale)
|
||||
#define DPTR(node) ((node)->dptr)
|
||||
#define DLEN(node) ((node)->dlen)
|
||||
#define DPTR(node) ((node)->val.ptr)
|
||||
#define DLEN(node) ((node)->val.len)
|
||||
|
||||
static int default_comparator (lda_t* lda,
|
||||
const void* dptr1, size_t dlen1,
|
||||
@ -58,20 +58,20 @@ static int default_comparator (lda_t* lda,
|
||||
return n;
|
||||
}
|
||||
|
||||
static QSE_INLINE node_t* alloc_node (lda_t* lda, void* dptr, size_t dlen)
|
||||
static QSE_INLINE slot_t* alloc_node (lda_t* lda, void* dptr, size_t dlen)
|
||||
{
|
||||
node_t* n;
|
||||
slot_t* n;
|
||||
|
||||
if (lda->copier == QSE_LDA_COPIER_SIMPLE)
|
||||
{
|
||||
n = QSE_MMGR_ALLOC (lda->mmgr, QSE_SIZEOF(node_t));
|
||||
n = QSE_MMGR_ALLOC (lda->mmgr, QSE_SIZEOF(slot_t));
|
||||
if (n == QSE_NULL) return QSE_NULL;
|
||||
DPTR(n) = dptr;
|
||||
}
|
||||
else if (lda->copier == QSE_LDA_COPIER_INLINE)
|
||||
{
|
||||
n = QSE_MMGR_ALLOC (lda->mmgr,
|
||||
QSE_SIZEOF(node_t) + TOB(lda,dlen));
|
||||
QSE_SIZEOF(slot_t) + TOB(lda,dlen));
|
||||
if (n == QSE_NULL) return QSE_NULL;
|
||||
|
||||
QSE_MEMCPY (n + 1, dptr, TOB(lda,dlen));
|
||||
@ -79,7 +79,7 @@ static QSE_INLINE node_t* alloc_node (lda_t* lda, void* dptr, size_t dlen)
|
||||
}
|
||||
else
|
||||
{
|
||||
n = QSE_MMGR_ALLOC (lda->mmgr, QSE_SIZEOF(node_t));
|
||||
n = QSE_MMGR_ALLOC (lda->mmgr, QSE_SIZEOF(slot_t));
|
||||
if (n == QSE_NULL) return QSE_NULL;
|
||||
DPTR(n) = lda->copier (lda, dptr, dlen);
|
||||
if (DPTR(n) == QSE_NULL)
|
||||
@ -252,14 +252,14 @@ lda_t* qse_lda_setcapa (lda_t* lda, size_t capa)
|
||||
{
|
||||
if (lda->mmgr->realloc != QSE_NULL && lda->node != QSE_NULL)
|
||||
{
|
||||
tmp = (node_t**) QSE_MMGR_REALLOC (
|
||||
tmp = (slot_t**) QSE_MMGR_REALLOC (
|
||||
lda->mmgr, lda->node,
|
||||
QSE_SIZEOF(*lda->node)*capa);
|
||||
if (tmp == QSE_NULL) return QSE_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (node_t**) QSE_MMGR_ALLOC (
|
||||
tmp = (slot_t**) QSE_MMGR_ALLOC (
|
||||
lda->mmgr, QSE_SIZEOF(*lda->node)*capa);
|
||||
if (tmp == QSE_NULL) return QSE_NULL;
|
||||
|
||||
@ -336,7 +336,7 @@ size_t qse_lda_upsert (lda_t* lda, size_t pos, void* dptr, size_t dlen)
|
||||
size_t qse_lda_insert (lda_t* lda, size_t pos, void* dptr, size_t dlen)
|
||||
{
|
||||
size_t i;
|
||||
node_t* node;
|
||||
slot_t* node;
|
||||
|
||||
/* allocate the node first */
|
||||
node = alloc_node (lda, dptr, dlen);
|
||||
@ -413,7 +413,7 @@ size_t qse_lda_insert (lda_t* lda, size_t pos, void* dptr, size_t dlen)
|
||||
|
||||
size_t qse_lda_update (lda_t* lda, size_t pos, void* dptr, size_t dlen)
|
||||
{
|
||||
node_t* c;
|
||||
slot_t* c;
|
||||
|
||||
if (pos >= lda->size) return QSE_LDA_NIL;
|
||||
|
||||
@ -434,7 +434,7 @@ size_t qse_lda_update (lda_t* lda, size_t pos, void* dptr, size_t dlen)
|
||||
else
|
||||
{
|
||||
/* updated to different data */
|
||||
node_t* node = alloc_node (lda, dptr, dlen);
|
||||
slot_t* node = alloc_node (lda, dptr, dlen);
|
||||
if (node == QSE_NULL) return QSE_LDA_NIL;
|
||||
|
||||
if (lda->freeer != QSE_NULL)
|
||||
@ -459,7 +459,7 @@ size_t qse_lda_delete (lda_t* lda, size_t index, size_t count)
|
||||
|
||||
for (i = index; i < index + count; i++)
|
||||
{
|
||||
node_t* c = lda->node[i];
|
||||
slot_t* c = lda->node[i];
|
||||
|
||||
if (c != QSE_NULL)
|
||||
{
|
||||
@ -492,7 +492,7 @@ size_t qse_lda_uplete (lda_t* lda, size_t index, size_t count)
|
||||
|
||||
for (i = index; i < index + count; i++)
|
||||
{
|
||||
node_t* c = lda->node[i];
|
||||
slot_t* c = lda->node[i];
|
||||
|
||||
if (c != QSE_NULL)
|
||||
{
|
||||
@ -513,7 +513,7 @@ void qse_lda_clear (lda_t* lda)
|
||||
|
||||
for (i = 0; i < lda->size; i++)
|
||||
{
|
||||
node_t* c = lda->node[i];
|
||||
slot_t* c = lda->node[i];
|
||||
if (c != QSE_NULL)
|
||||
{
|
||||
if (lda->freeer)
|
||||
@ -618,7 +618,7 @@ size_t qse_lda_pushheap (lda_t* lda, void* dptr, size_t dlen)
|
||||
|
||||
while (cur != 0)
|
||||
{
|
||||
node_t* tmp;
|
||||
slot_t* tmp;
|
||||
|
||||
/* compare with the parent */
|
||||
par = HEAP_PARENT(cur);
|
||||
@ -641,7 +641,7 @@ size_t qse_lda_pushheap (lda_t* lda, void* dptr, size_t dlen)
|
||||
void qse_lda_popheap (lda_t* lda)
|
||||
{
|
||||
size_t cur, child;
|
||||
node_t* tmp;
|
||||
slot_t* tmp;
|
||||
|
||||
QSE_ASSERT (lda->size > 0);
|
||||
|
||||
|
@ -282,7 +282,7 @@ pair_t* qse_rbt_search (rbt_t* rbt, const void* kptr, size_t klen)
|
||||
|
||||
while (!IS_NIL(rbt,pair))
|
||||
{
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, pair->kptr, pair->klen);
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(pair), KLEN(pair));
|
||||
if (n == 0) return pair;
|
||||
|
||||
if (n > 0) pair = pair->right;
|
||||
@ -516,7 +516,7 @@ static pair_t* insert (
|
||||
|
||||
while (!IS_NIL(rbt,xcur))
|
||||
{
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, xcur->kptr, xcur->klen);
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(xcur), KLEN(xcur));
|
||||
if (n == 0)
|
||||
{
|
||||
switch (opt)
|
||||
@ -555,7 +555,7 @@ static pair_t* insert (
|
||||
else
|
||||
{
|
||||
/* perform normal binary insert */
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, xpar->kptr, xpar->klen);
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(xpar), KLEN(xpar));
|
||||
if (n > 0)
|
||||
{
|
||||
QSE_ASSERT (xpar->right == &rbt->nil);
|
||||
@ -609,7 +609,7 @@ pair_t* qse_rbt_cbsert (
|
||||
|
||||
while (!IS_NIL(rbt,xcur))
|
||||
{
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, xcur->kptr, xcur->klen);
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(xcur), KLEN(xcur));
|
||||
if (n == 0)
|
||||
{
|
||||
/* back up the contents of the current pair
|
||||
@ -674,7 +674,7 @@ pair_t* qse_rbt_cbsert (
|
||||
else
|
||||
{
|
||||
/* perform normal binary insert */
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, xpar->kptr, xpar->klen);
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(xpar), KLEN(xpar));
|
||||
if (n > 0)
|
||||
{
|
||||
QSE_ASSERT (xpar->right == &rbt->nil);
|
||||
|
@ -449,7 +449,7 @@ static QSE_INLINE int capture_connection (
|
||||
{
|
||||
int n;
|
||||
|
||||
n = compare_octets (pair->vptr, pair->vlen, "close", 5);
|
||||
n = compare_octets (QSE_HTB_VPTR(pair), QSE_HTB_VLEN(pair), "close", 5);
|
||||
if (n == 0)
|
||||
{
|
||||
http->req.attr.connection_close = 1;
|
||||
@ -464,9 +464,9 @@ static QSE_INLINE int capture_content_length (
|
||||
qse_http_t* http, qse_htb_pair_t* pair)
|
||||
{
|
||||
qse_size_t len = 0, off = 0, tmp;
|
||||
const qse_byte_t* ptr = pair->vptr;
|
||||
const qse_byte_t* ptr = QSE_HTB_VPTR(pair);
|
||||
|
||||
while (off < pair->vlen)
|
||||
while (off < QSE_HTB_VLEN(pair))
|
||||
{
|
||||
int num = digit_to_num (ptr[off]);
|
||||
if (num <= -1)
|
||||
@ -510,14 +510,14 @@ static QSE_INLINE int capture_content_length (
|
||||
static QSE_INLINE int capture_content_type (
|
||||
qse_http_t* http, qse_htb_pair_t* pair)
|
||||
{
|
||||
qse_printf (QSE_T("content type capture => %.*S\n"), (int)pair->vlen, pair->vptr);
|
||||
qse_printf (QSE_T("content type capture => %.*S\n"), (int)QSE_HTB_VLEN(pair), QSE_HTB_VPTR(pair));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QSE_INLINE int capture_host (
|
||||
qse_http_t* http, qse_htb_pair_t* pair)
|
||||
{
|
||||
qse_printf (QSE_T("host capture => %.*S\n"), (int)pair->vlen, pair->vptr);
|
||||
qse_printf (QSE_T("host capture => %.*S\n"), (int)QSE_HTB_VLEN(pair), QSE_HTB_VPTR(pair));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -526,7 +526,7 @@ static QSE_INLINE int capture_transfer_encoding (
|
||||
{
|
||||
int n;
|
||||
|
||||
n = compare_octets (pair->vptr, pair->vlen, "chunked", 7);
|
||||
n = compare_octets (QSE_HTB_VPTR(pair), QSE_HTB_VLEN(pair), "chunked", 7);
|
||||
if (n == 0)
|
||||
{
|
||||
if (http->req.attr.content_length > 0)
|
||||
@ -572,7 +572,7 @@ static QSE_INLINE int capture_key_header (
|
||||
mid = base + count / 2;
|
||||
|
||||
n = compare_octets (
|
||||
pair->kptr, pair->klen,
|
||||
QSE_HTB_VPTR(pair), QSE_HTB_VLEN(pair),
|
||||
hdrtab[mid].ptr, hdrtab[mid].len
|
||||
);
|
||||
|
||||
@ -646,7 +646,7 @@ static qse_htb_pair_t* hdr_cbserter (
|
||||
cmb = (struct hdr_cmb_t*) QSE_MMGR_ALLOC (
|
||||
tx->http->mmgr,
|
||||
QSE_SIZEOF(*cmb) +
|
||||
QSE_SIZEOF(qse_byte_t) * (pair->vlen + 1 + tx->vlen + 1)
|
||||
QSE_SIZEOF(qse_byte_t) * (QSE_HTB_VLEN(pair) + 1 + tx->vlen + 1)
|
||||
);
|
||||
if (cmb == QSE_NULL)
|
||||
{
|
||||
@ -659,8 +659,8 @@ static qse_htb_pair_t* hdr_cbserter (
|
||||
len = 0;
|
||||
|
||||
/* fill the space with the value */
|
||||
QSE_MEMCPY (&ptr[len], pair->vptr, pair->vlen);
|
||||
len += pair->vlen;
|
||||
QSE_MEMCPY (&ptr[len], QSE_HTB_VPTR(pair), QSE_HTB_VLEN(pair));
|
||||
len += QSE_HTB_VLEN(pair);
|
||||
ptr[len++] = ',';
|
||||
QSE_MEMCPY (&ptr[len], tx->vptr, tx->vlen);
|
||||
len += tx->vlen;
|
||||
@ -680,14 +680,14 @@ Change it to doubly linked for this?
|
||||
|
||||
QSE_MMGR_FREE (
|
||||
tx->http->mmgr,
|
||||
((struct hdr_cmb_t*)pair->vptr) - 1
|
||||
((struct hdr_cmb_t*)QSE_HTB_VPTR(pair)) - 1
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* update the value pointer and length */
|
||||
pair->vptr = ptr;
|
||||
pair->vlen = len;
|
||||
QSE_HTB_VPTR(pair) = ptr;
|
||||
QSE_HTB_VLEN(pair) = len;
|
||||
|
||||
/* link the new combined value block */
|
||||
cmb->next = tx->http->reqx.chl;
|
||||
@ -794,7 +794,7 @@ qse_printf (QSE_T("BADHDR\n"), name.ptr, value.ptr);
|
||||
|
||||
static qse_htb_walk_t walk (qse_htb_t* htb, qse_htb_pair_t* pair, void* ctx)
|
||||
{
|
||||
qse_printf (QSE_T("HEADER OK %d[%S] %d[%S]\n"), (int)pair->klen, pair->kptr, (int)pair->vlen, pair->vptr);
|
||||
qse_printf (QSE_T("HEADER OK %d[%S] %d[%S]\n"), (int)QSE_HTB_KLEN(pair), QSE_HTB_KPTR(pair), (int)QSE_HTB_VLEN(pair), QSE_HTB_VPTR(pair));
|
||||
return QSE_HTB_WALK_FORWARD;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
static const qse_char_t* src = QSE_T(
|
||||
"function dump(x) { for (k in x) print k \"=\" x[k]; x[\"f99\"]=\"os2\"; return x; }"
|
||||
"function dump(x) { OFS=\"=\"; for (k in x) print k, x[k]; x[\"f99\"]=\"os2\"; return x; }"
|
||||
);
|
||||
|
||||
int main ()
|
||||
@ -145,7 +145,7 @@ int main ()
|
||||
qse_xstr_t str;
|
||||
|
||||
str.ptr = qse_awk_rtx_valtocpldup (
|
||||
rtx, QSE_AWK_VAL_MAP_ITR_VPTR(iptr), &str.len);
|
||||
rtx, QSE_AWK_VAL_MAP_ITR_VAL(iptr), &str.len);
|
||||
if (str.ptr == QSE_NULL)
|
||||
{
|
||||
qse_fprintf (QSE_STDERR, QSE_T("error: %s\n"),
|
||||
@ -154,8 +154,8 @@ int main ()
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("ret [%.*s]=[%.*s]\n"),
|
||||
(int)QSE_AWK_VAL_MAP_ITR_KLEN(iptr),
|
||||
QSE_AWK_VAL_MAP_ITR_KPTR(iptr),
|
||||
(int)QSE_AWK_VAL_MAP_ITR_KEY_LEN(iptr),
|
||||
QSE_AWK_VAL_MAP_ITR_KEY_PTR(iptr),
|
||||
(int)str.len, str.ptr
|
||||
);
|
||||
qse_awk_rtx_free (rtx, str.ptr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user