added qse_getxlirootxtn(), QSE_XLI_ROOTXTNSIZE as well as the rootxtnsize parameter to multiple initialization functions
This commit is contained in:
parent
99d0e04879
commit
72fd080f70
@ -1470,7 +1470,7 @@ static int open_config_file (qse_httpd_t* httpd)
|
|||||||
httpd_xtn = (httpd_xtn_t*) qse_httpd_getxtnstd (httpd);
|
httpd_xtn = (httpd_xtn_t*) qse_httpd_getxtnstd (httpd);
|
||||||
QSE_ASSERT (httpd_xtn->xli == QSE_NULL);
|
QSE_ASSERT (httpd_xtn->xli == QSE_NULL);
|
||||||
|
|
||||||
httpd_xtn->xli = qse_xli_openstd (0);
|
httpd_xtn->xli = qse_xli_openstd (0, 0);
|
||||||
if (httpd_xtn->xli == QSE_NULL)
|
if (httpd_xtn->xli == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_fprintf (QSE_STDERR, QSE_T("Cannot open xli\n"));
|
qse_fprintf (QSE_STDERR, QSE_T("Cannot open xli\n"));
|
||||||
|
@ -354,7 +354,7 @@ static int xli_main (int argc, qse_char_t* argv[])
|
|||||||
mmgr = &xma_mmgr;
|
mmgr = &xma_mmgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
xli = qse_xli_openstdwithmmgr (mmgr, 0);
|
xli = qse_xli_openstdwithmmgr (mmgr, 0, 0);
|
||||||
if (xli == QSE_NULL)
|
if (xli == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open stream editor\n"));
|
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open stream editor\n"));
|
||||||
|
@ -97,7 +97,8 @@ extern "C" {
|
|||||||
* over qse_xli_open() if you don't need finer-grained customization.
|
* over qse_xli_open() if you don't need finer-grained customization.
|
||||||
*/
|
*/
|
||||||
QSE_EXPORT qse_xli_t* qse_xli_openstd (
|
QSE_EXPORT qse_xli_t* qse_xli_openstd (
|
||||||
qse_size_t xtnsize /**< extension size in bytes */
|
qse_size_t xtnsize, /**< extension size in bytes */
|
||||||
|
qse_size_t rootxtnsize /**< extension size in bytes for the root list node */
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +108,8 @@ QSE_EXPORT qse_xli_t* qse_xli_openstd (
|
|||||||
*/
|
*/
|
||||||
QSE_EXPORT qse_xli_t* qse_xli_openstdwithmmgr (
|
QSE_EXPORT qse_xli_t* qse_xli_openstdwithmmgr (
|
||||||
qse_mmgr_t* mmgr, /**< memory manager */
|
qse_mmgr_t* mmgr, /**< memory manager */
|
||||||
qse_size_t xtnsize /**< extension size in bytes */
|
qse_size_t xtnsize, /**< extension size in bytes */
|
||||||
|
qse_size_t rootxtnsize /**< extension size in bytes for the root list node */
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,13 +68,21 @@ typedef enum qse_xli_errnum_t qse_xli_errnum_t;
|
|||||||
*/
|
*/
|
||||||
typedef const qse_char_t* (*qse_xli_errstr_t) (
|
typedef const qse_char_t* (*qse_xli_errstr_t) (
|
||||||
const qse_xli_t* xli, /**< stream editor */
|
const qse_xli_t* xli, /**< stream editor */
|
||||||
qse_xli_errnum_t num /**< an error number */
|
qse_xli_errnum_t num /**< error number */
|
||||||
);
|
);
|
||||||
|
|
||||||
enum qse_xli_opt_t
|
enum qse_xli_opt_t
|
||||||
{
|
{
|
||||||
QSE_XLI_TRAIT,
|
QSE_XLI_TRAIT,
|
||||||
QSE_XLI_PAIRXTNSIZE
|
|
||||||
|
QSE_XLI_PAIRXTNSIZE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the size of extension area associated with the root list node.
|
||||||
|
* you can get the pointer to the extension with qse_getxlirootxtn().
|
||||||
|
* the new size set takes effect after the call to qse_xli_yieldroot().
|
||||||
|
*/
|
||||||
|
QSE_XLI_ROOTXTNSIZE
|
||||||
};
|
};
|
||||||
typedef enum qse_xli_opt_t qse_xli_opt_t;
|
typedef enum qse_xli_opt_t qse_xli_opt_t;
|
||||||
|
|
||||||
@ -325,7 +333,8 @@ extern "C" {
|
|||||||
|
|
||||||
QSE_EXPORT qse_xli_t* qse_xli_open (
|
QSE_EXPORT qse_xli_t* qse_xli_open (
|
||||||
qse_mmgr_t* mmgr,
|
qse_mmgr_t* mmgr,
|
||||||
qse_size_t xtnsize
|
qse_size_t xtnsize,
|
||||||
|
qse_size_t rootxtnsize
|
||||||
);
|
);
|
||||||
|
|
||||||
QSE_EXPORT void qse_xli_close (
|
QSE_EXPORT void qse_xli_close (
|
||||||
@ -644,6 +653,10 @@ QSE_EXPORT void* qse_getxlipairxtn (
|
|||||||
qse_xli_pair_t* pair
|
qse_xli_pair_t* pair
|
||||||
);
|
);
|
||||||
|
|
||||||
|
QSE_EXPORT void* qse_getxlirootxtn (
|
||||||
|
qse_xli_list_t* root
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The qse_freexliroot() function frees the root list acquired with qse_xli_yeildroot().
|
* The qse_freexliroot() function frees the root list acquired with qse_xli_yeildroot().
|
||||||
*/
|
*/
|
||||||
|
@ -65,9 +65,9 @@ typedef struct xtn_t
|
|||||||
qse_xli_ecb_t ecb;
|
qse_xli_ecb_t ecb;
|
||||||
} xtn_t;
|
} xtn_t;
|
||||||
|
|
||||||
qse_xli_t* qse_xli_openstd (qse_size_t xtnsize)
|
qse_xli_t* qse_xli_openstd (qse_size_t xtnsize, qse_size_t rootxtnsize)
|
||||||
{
|
{
|
||||||
return qse_xli_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize);
|
return qse_xli_openstdwithmmgr (QSE_MMGR_GETDFL(), xtnsize, rootxtnsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fini_xtn (qse_xli_t* xli)
|
static void fini_xtn (qse_xli_t* xli)
|
||||||
@ -80,13 +80,13 @@ static void clear_xtn (qse_xli_t* xli)
|
|||||||
/* nothing to do */
|
/* nothing to do */
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_xli_t* qse_xli_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize)
|
qse_xli_t* qse_xli_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_size_t rootxtnsize)
|
||||||
{
|
{
|
||||||
qse_xli_t* xli;
|
qse_xli_t* xli;
|
||||||
xtn_t* xtn;
|
xtn_t* xtn;
|
||||||
|
|
||||||
/* create an object */
|
/* create an object */
|
||||||
xli = qse_xli_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize);
|
xli = qse_xli_open (mmgr, QSE_SIZEOF(xtn_t) + xtnsize, rootxtnsize);
|
||||||
if (xli == QSE_NULL) goto oops;
|
if (xli == QSE_NULL) goto oops;
|
||||||
|
|
||||||
/* initialize extension */
|
/* initialize extension */
|
||||||
|
@ -21,18 +21,19 @@
|
|||||||
#include "xli.h"
|
#include "xli.h"
|
||||||
#include <qse/cmn/chr.h>
|
#include <qse/cmn/chr.h>
|
||||||
|
|
||||||
|
static qse_xli_root_list_t* make_root (qse_xli_t* xli);
|
||||||
static void free_val (qse_xli_root_list_t* xli, qse_xli_val_t* val);
|
static void free_val (qse_xli_root_list_t* xli, qse_xli_val_t* val);
|
||||||
static void free_list (qse_xli_root_list_t* xli, qse_xli_list_t* list);
|
static void free_list (qse_xli_root_list_t* xli, qse_xli_list_t* list);
|
||||||
static void free_atom (qse_xli_root_list_t* xli, qse_xli_atom_t* atom);
|
static void free_atom (qse_xli_root_list_t* xli, qse_xli_atom_t* atom);
|
||||||
|
|
||||||
qse_xli_t* qse_xli_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
|
qse_xli_t* qse_xli_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_size_t rootxtnsize)
|
||||||
{
|
{
|
||||||
qse_xli_t* xli;
|
qse_xli_t* xli;
|
||||||
|
|
||||||
xli = (qse_xli_t*) QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_xli_t) + xtnsize);
|
xli = (qse_xli_t*) QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_xli_t) + xtnsize);
|
||||||
if (xli)
|
if (xli)
|
||||||
{
|
{
|
||||||
if (qse_xli_init (xli, mmgr) <= -1)
|
if (qse_xli_init (xli, mmgr, rootxtnsize) <= -1)
|
||||||
{
|
{
|
||||||
QSE_MMGR_FREE (xli->mmgr, xli);
|
QSE_MMGR_FREE (xli->mmgr, xli);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
@ -54,11 +55,12 @@ void qse_xli_close (qse_xli_t* xli)
|
|||||||
QSE_MMGR_FREE (xli->mmgr, xli);
|
QSE_MMGR_FREE (xli->mmgr, xli);
|
||||||
}
|
}
|
||||||
|
|
||||||
int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr)
|
int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr, qse_size_t rootxtnsize)
|
||||||
{
|
{
|
||||||
QSE_MEMSET (xli, 0, QSE_SIZEOF(*xli));
|
QSE_MEMSET (xli, 0, QSE_SIZEOF(*xli));
|
||||||
xli->mmgr = mmgr;
|
xli->mmgr = mmgr;
|
||||||
xli->errstr = qse_xli_dflerrstr;
|
xli->errstr = qse_xli_dflerrstr;
|
||||||
|
xli->opt.root_xtnsize = rootxtnsize;
|
||||||
|
|
||||||
xli->dotted_curkey = qse_str_open (mmgr, 0, 128);
|
xli->dotted_curkey = qse_str_open (mmgr, 0, 128);
|
||||||
if (xli->dotted_curkey == QSE_NULL) goto oops;
|
if (xli->dotted_curkey == QSE_NULL) goto oops;
|
||||||
@ -70,12 +72,8 @@ int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr)
|
|||||||
if (xli->schema == QSE_NULL) goto oops;
|
if (xli->schema == QSE_NULL) goto oops;
|
||||||
qse_rbt_setstyle (xli->schema, qse_getrbtstyle(QSE_RBT_STYLE_INLINE_COPIERS));
|
qse_rbt_setstyle (xli->schema, qse_getrbtstyle(QSE_RBT_STYLE_INLINE_COPIERS));
|
||||||
|
|
||||||
xli->root = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(*xli->root));
|
xli->root = make_root (xli);
|
||||||
if (xli->root == QSE_NULL) goto oops;
|
if (xli->root == QSE_NULL) goto oops;
|
||||||
QSE_MEMSET (xli->root, 0, QSE_SIZEOF(*xli->root));
|
|
||||||
xli->root->list.type = QSE_XLI_LIST;
|
|
||||||
xli->root->xnil.type = QSE_XLI_NIL;
|
|
||||||
xli->root->mmgr = mmgr;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -119,6 +117,10 @@ int qse_xli_setopt (qse_xli_t* xli, qse_xli_opt_t id, const void* value)
|
|||||||
case QSE_XLI_PAIRXTNSIZE:
|
case QSE_XLI_PAIRXTNSIZE:
|
||||||
xli->opt.pair_xtnsize = *(const qse_size_t*)value;
|
xli->opt.pair_xtnsize = *(const qse_size_t*)value;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case QSE_XLI_ROOTXTNSIZE:
|
||||||
|
xli->opt.root_xtnsize = *(const qse_size_t*)value;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL);
|
qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL);
|
||||||
@ -136,6 +138,10 @@ int qse_xli_getopt (qse_xli_t* xli, qse_xli_opt_t id, void* value)
|
|||||||
case QSE_XLI_PAIRXTNSIZE:
|
case QSE_XLI_PAIRXTNSIZE:
|
||||||
*(qse_size_t*)value = xli->opt.pair_xtnsize;
|
*(qse_size_t*)value = xli->opt.pair_xtnsize;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case QSE_XLI_ROOTXTNSIZE:
|
||||||
|
*(qse_size_t*)value = xli->opt.root_xtnsize;
|
||||||
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL);
|
qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL);
|
||||||
@ -402,6 +408,25 @@ qse_xli_eof_t* qse_xli_inserteof (
|
|||||||
|
|
||||||
/* ------------------------------------------------------ */
|
/* ------------------------------------------------------ */
|
||||||
|
|
||||||
|
static qse_xli_root_list_t* make_root (qse_xli_t* xli)
|
||||||
|
{
|
||||||
|
qse_xli_root_list_t* tmp;
|
||||||
|
|
||||||
|
tmp = QSE_MMGR_ALLOC (xli->mmgr, QSE_SIZEOF(*tmp) + xli->opt.root_xtnsize);
|
||||||
|
if (tmp == QSE_NULL)
|
||||||
|
{
|
||||||
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
||||||
|
return QSE_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSE_MEMSET (tmp, 0, QSE_SIZEOF(*tmp) + xli->opt.root_xtnsize);
|
||||||
|
tmp->list.type = QSE_XLI_LIST;
|
||||||
|
tmp->xnil.type = QSE_XLI_NIL;
|
||||||
|
tmp->mmgr = xli->mmgr;
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
static void free_val (qse_xli_root_list_t* root, qse_xli_val_t* val)
|
static void free_val (qse_xli_root_list_t* root, qse_xli_val_t* val)
|
||||||
{
|
{
|
||||||
if ((qse_xli_nil_t*)val != &root->xnil)
|
if ((qse_xli_nil_t*)val != &root->xnil)
|
||||||
@ -475,17 +500,8 @@ qse_xli_list_t* qse_xli_yieldroot (qse_xli_t* xli)
|
|||||||
{
|
{
|
||||||
qse_xli_root_list_t* tmp, * tmp2;
|
qse_xli_root_list_t* tmp, * tmp2;
|
||||||
|
|
||||||
tmp = QSE_MMGR_ALLOC (xli->mmgr, QSE_SIZEOF(*tmp));
|
tmp = make_root (xli);
|
||||||
if (tmp == QSE_NULL)
|
if (tmp == QSE_NULL) return QSE_NULL;
|
||||||
{
|
|
||||||
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
|
||||||
return QSE_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSE_MEMSET (tmp, 0, QSE_SIZEOF(*tmp));
|
|
||||||
tmp->list.type = QSE_XLI_LIST;
|
|
||||||
tmp->xnil.type = QSE_XLI_NIL;
|
|
||||||
tmp->mmgr = xli->mmgr;
|
|
||||||
|
|
||||||
tmp2 = xli->root;
|
tmp2 = xli->root;
|
||||||
xli->root = tmp;
|
xli->root = tmp;
|
||||||
@ -979,6 +995,12 @@ void* qse_getxlipairxtn (qse_xli_pair_t* pair)
|
|||||||
return (void*)(pair + 1);
|
return (void*)(pair + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* qse_getxlirootxtn (qse_xli_list_t* root)
|
||||||
|
{
|
||||||
|
qse_xli_root_list_t* real_root = (qse_xli_root_list_t*)root;
|
||||||
|
return (void*)(real_root + 1);
|
||||||
|
}
|
||||||
|
|
||||||
void qse_freexliroot (qse_xli_list_t* root)
|
void qse_freexliroot (qse_xli_list_t* root)
|
||||||
{
|
{
|
||||||
qse_xli_root_list_t* real_root = (qse_xli_root_list_t*)root;
|
qse_xli_root_list_t* real_root = (qse_xli_root_list_t*)root;
|
||||||
|
@ -65,6 +65,7 @@ struct qse_xli_t
|
|||||||
{
|
{
|
||||||
int trait;
|
int trait;
|
||||||
qse_size_t pair_xtnsize;
|
qse_size_t pair_xtnsize;
|
||||||
|
qse_size_t root_xtnsize;
|
||||||
} opt;
|
} opt;
|
||||||
|
|
||||||
qse_xli_ecb_t* ecb;
|
qse_xli_ecb_t* ecb;
|
||||||
@ -100,7 +101,7 @@ struct qse_xli_t
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr);
|
int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr, qse_size_t rootxtnsize);
|
||||||
|
|
||||||
void qse_xli_fini (qse_xli_t* xli);
|
void qse_xli_fini (qse_xli_t* xli);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user