initial import
This commit is contained in:
97
qse/include/qse/cmn/chr.h
Normal file
97
qse/include/qse/cmn/chr.h
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* $Id: ctype.h 223 2008-06-26 06:44:41Z baconevi $
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_CHR_H_
|
||||
#define _QSE_CMN_CHR_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/* gets a pointer to the default memory manager */
|
||||
#define QSE_CCLS_GETDFL() (qse_ccls)
|
||||
|
||||
/* sets a pointer to the default memory manager */
|
||||
#define QSE_CCLS_SETDFL(m) ((qse_ccls)=(m))
|
||||
|
||||
#define QSE_CCLS_IS(ccls,c,type) ((ccls)->is((ccls)->data,c,type))
|
||||
#define QSE_CCLS_TO(ccls,c,type) ((ccls)->to((ccls)->data,c,type))
|
||||
|
||||
#define QSE_CCLS_ISUPPER(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_UPPER)
|
||||
#define QSE_CCLS_ISLOWER(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_LOWER)
|
||||
#define QSE_CCLS_ISALPHA(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_ALPHA)
|
||||
#define QSE_CCLS_ISDIGIT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_DIGIT)
|
||||
#define QSE_CCLS_ISXDIGIT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_XDIGIT)
|
||||
#define QSE_CCLS_ISALNUM(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_ALNUM)
|
||||
#define QSE_CCLS_ISSPACE(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_SPACE)
|
||||
#define QSE_CCLS_ISPRINT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_PRINT)
|
||||
#define QSE_CCLS_ISGRAPH(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_GRAPH)
|
||||
#define QSE_CCLS_ISCNTRL(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_CNTRL)
|
||||
#define QSE_CCLS_ISPUNCT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_PUNCT)
|
||||
#define QSE_CCLS_TOUPPER(ccls,c) QSE_CCLS_TO(ccls,c,QSE_CCLS_UPPER)
|
||||
#define QSE_CCLS_TOLOWER(ccls,c) QSE_CCLS_TO(ccls,c,QSE_CCLS_LOWER)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern qse_ccls_t* qse_ccls;
|
||||
|
||||
qse_bool_t qse_ccls_is (
|
||||
qse_cint_t c,
|
||||
qse_ccls_type_t type
|
||||
);
|
||||
|
||||
qse_cint_t qse_ccls_to (
|
||||
qse_cint_t c,
|
||||
qse_ccls_type_t type
|
||||
);
|
||||
|
||||
|
||||
|
||||
qse_size_t qse_mblen (
|
||||
const qse_mchar_t* mb,
|
||||
qse_size_t mblen
|
||||
);
|
||||
|
||||
/****f* qse.cmn.chr/qse_mbtowc
|
||||
* NAME
|
||||
* qse_mbtowc - convert a multibyte sequence to a wide character.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_mbtowc() function returns 0 if an invalid multibyte sequence is
|
||||
* detected, mblen + 1 if the sequence is incomplete. It returns the number
|
||||
* of bytes processed to form a wide character.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_size_t qse_mbtowc (
|
||||
const qse_mchar_t* mb,
|
||||
qse_size_t mblen,
|
||||
qse_wchar_t* wc
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.chr/qse_wctomb
|
||||
* NAME
|
||||
* qse_wctomb - convert a wide character to a multibyte sequence
|
||||
*
|
||||
* RETURN
|
||||
* The qse_wctomb() functions returns 0 if the wide character is illegal,
|
||||
* mblen + 1 if mblen is not large enough to hold the multibyte sequence.
|
||||
* On successful conversion, it returns the number of bytes in the sequence.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_size_t qse_wctomb (
|
||||
qse_wchar_t wc,
|
||||
qse_mchar_t* mb,
|
||||
qse_size_t mblen
|
||||
);
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
260
qse/include/qse/cmn/dll.h
Normal file
260
qse/include/qse/cmn/dll.h
Normal file
@ -0,0 +1,260 @@
|
||||
/*
|
||||
* $Id: map.h 223 2008-06-26 06:44:41Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_DLL_H_
|
||||
#define _QSE_CMN_DLL_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/*
|
||||
* Doubly Linked List
|
||||
*/
|
||||
typedef struct qse_dll_t qse_dll_t;
|
||||
typedef struct qse_dll_node_t qse_dll_node_t;
|
||||
|
||||
/* data copier */
|
||||
typedef void* (*qse_dll_copier_t) (qse_dll_t* dll, void* dptr, qse_size_t dlen);
|
||||
|
||||
/* data freeer */
|
||||
typedef void (*qse_dll_freeer_t) (qse_dll_t* dll, void* dptr, qse_size_t dlen);
|
||||
|
||||
/* node visitor */
|
||||
typedef int (*qse_dll_walker_t) (
|
||||
qse_dll_t* dll, qse_dll_node_t* node, void* arg);
|
||||
|
||||
struct qse_dll_t
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
|
||||
qse_dll_copier_t copier;
|
||||
qse_dll_freeer_t freeer;
|
||||
|
||||
qse_size_t size;
|
||||
qse_dll_node_t* head;
|
||||
qse_dll_node_t* tail;
|
||||
};
|
||||
|
||||
struct qse_dll_node_t
|
||||
{
|
||||
void* dptr; /* pointer to the beginning of data */
|
||||
qse_size_t dlen; /* length of data in bytes */
|
||||
qse_dll_node_t* next; /* pointer to the next node */
|
||||
qse_dll_node_t* prev; /* pointer to the prev node */
|
||||
};
|
||||
|
||||
|
||||
enum qse_dll_walk_t
|
||||
{
|
||||
QSE_DLL_WALK_STOP = 0,
|
||||
QSE_DLL_WALK_FORWARD = 1
|
||||
};
|
||||
|
||||
#define QSE_DLL_COPIER_INLINE qse_dll_copyinline
|
||||
|
||||
#define QSE_DLL_HEAD(dll) ((dll)->head)
|
||||
#define QSE_DLL_TAIL(dll) ((dll)->tail)
|
||||
#define QSE_DLL_SIZE(dll) ((dll)->size)
|
||||
|
||||
#define QSE_DLL_DPTR(n) ((n)->dptr)
|
||||
#define QSE_DLL_DLEN(n) ((n)->dlen)
|
||||
#define QSE_DLL_NEXT(n) ((n)->next)
|
||||
#define QSE_DLL_PREV(n) ((n)->prev)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NAME: creates a doubly linked list with extension area
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_dll_open() function creates an empty doubly linked list.
|
||||
* If the memory manager mmgr is QSE_NULL, the function gets the default
|
||||
* memory manager with QSE_MMGR_GETMMGR() and uses it if it is not QSE_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.
|
||||
* QSE_NULL on failure.
|
||||
*
|
||||
* WARNING:
|
||||
* In the debug build, it fails the assertion if QSE_MMGR_SETMMGR() returns
|
||||
* QSE_NULL when QSE_NULL is passed as the first parameter. In the release
|
||||
* build, it returns QSE_NULL if such a thing happens.
|
||||
*/
|
||||
|
||||
qse_dll_t* qse_dll_open (
|
||||
qse_mmgr_t* mmgr /* memory manager */ ,
|
||||
qse_size_t ext /* size of extension area in bytes */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME destroys a singly linked list
|
||||
*/
|
||||
void qse_dll_close (
|
||||
qse_dll_t* dll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME deletes all elements of a singly linked list
|
||||
*/
|
||||
void qse_dll_clear (
|
||||
qse_dll_t* dll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME specifies how to clone an element
|
||||
*
|
||||
* DESCRIPTION
|
||||
* A special copier QSE_DLL_COPIER_INLINE is provided. This copier enables
|
||||
* you to copy the data inline to the internal node. No freeer is invoked
|
||||
* when the node is freeed.
|
||||
*
|
||||
* You may set the copier to QSE_NULL to perform no special operation
|
||||
* when the data pointer is rememebered.
|
||||
*/
|
||||
void qse_dll_setcopier (
|
||||
qse_dll_t* dll /* a singly linked list */,
|
||||
qse_dll_copier_t copier /* a element copier */
|
||||
);
|
||||
|
||||
qse_dll_copier_t qse_dll_getcopier (
|
||||
qse_dll_t* dll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME specifies how to destroy an element
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The freeer is called when a node containing the element is destroyed.
|
||||
*/
|
||||
void qse_dll_setfreeer (
|
||||
qse_dll_t* dll /* a singly linked list */,
|
||||
qse_dll_freeer_t freeer /* a element freeer */
|
||||
);
|
||||
|
||||
qse_dll_freeer_t qse_dll_getfreeer (
|
||||
qse_dll_t* dll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME Gets the pointer to the extension area
|
||||
* RETURN the pointer to the extension area
|
||||
*/
|
||||
void* qse_dll_getxtn (
|
||||
qse_dll_t* dll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: get the pointer to the memory manager in use
|
||||
*/
|
||||
qse_mmgr_t* qse_dll_getmmgr (
|
||||
qse_dll_t* dll /* a singly linked list */
|
||||
);
|
||||
|
||||
void qse_dll_setmmgr (qse_dll_t* dll, qse_mmgr_t* mmgr);
|
||||
|
||||
/*
|
||||
* NAME Gets the number of elements held in a singly linked list
|
||||
* RETURN the number of elements the list holds
|
||||
*/
|
||||
qse_size_t qse_dll_getsize (
|
||||
qse_dll_t* dll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME Gets the head(first) node
|
||||
* RETURN the tail node of a singly linked list
|
||||
*/
|
||||
qse_dll_node_t* qse_dll_gethead (
|
||||
qse_dll_t* dll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME Gets the tail(last) node
|
||||
* RETURN the tail node of a singly linked list
|
||||
*/
|
||||
qse_dll_node_t* qse_dll_gettail (
|
||||
qse_dll_t* dll /* a singly linked list */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME Inserts data before a positional node given
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Inserts data.
|
||||
*/
|
||||
qse_dll_node_t* qse_dll_insert (
|
||||
qse_dll_t* dll /* a singly linked list */,
|
||||
qse_dll_node_t* pos /* a node before which a new node is inserted */,
|
||||
void* dptr /* the pointer to the data */ ,
|
||||
qse_size_t dlen /* the length of the data in bytes */
|
||||
);
|
||||
|
||||
qse_dll_node_t* qse_dll_pushhead (
|
||||
qse_dll_t* dll /* a singly linked list */,
|
||||
void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
qse_dll_node_t* qse_dll_pushtail (
|
||||
qse_dll_t* dll /* a singly linked list */,
|
||||
void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
void qse_dll_delete (
|
||||
qse_dll_t* dll,
|
||||
qse_dll_node_t* pos
|
||||
);
|
||||
|
||||
void qse_dll_pophead (
|
||||
qse_dll_t* dll
|
||||
);
|
||||
|
||||
void qse_dll_poptail (
|
||||
qse_dll_t* dll
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME Traverses s singly linked list
|
||||
*
|
||||
* DESCRIPTION
|
||||
* A singly linked list allows uni-directional in-order traversal.
|
||||
* The qse_dll_walk() function traverses a singly linkked list from its
|
||||
* head node down to its tail node as long as the walker function returns
|
||||
* QSE_DLL_WALK_FORWARD. A walker can return QSE_DLL_WALK_STOP to cause
|
||||
* immediate stop of traversal.
|
||||
* For each node, the walker function is called and it is passed three
|
||||
* parameters: the singly linked list, the visiting node, and the
|
||||
* user-defined data passed as the third parameter in a call to the
|
||||
* qse_dll_walk() function.
|
||||
*/
|
||||
void qse_dll_walk (
|
||||
qse_dll_t* dll /* a singly linked list */,
|
||||
qse_dll_walker_t walker /* a user-defined walker function */,
|
||||
void* arg /* pointer to user-defined data */
|
||||
);
|
||||
|
||||
/*
|
||||
* Causes a singly linked list to copy in data to a node.
|
||||
* Use QSE_DLL_COPIER_INLINE instead.
|
||||
*/
|
||||
void* qse_dll_copyinline (
|
||||
qse_dll_t* dll /* a singly linked list */,
|
||||
void* data /* pointer to data to copy */ ,
|
||||
qse_size_t len /* length of data in bytes */
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
152
qse/include/qse/cmn/fio.h
Normal file
152
qse/include/qse/cmn/fio.h
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_FIO_H_
|
||||
#define _QSE_CMN_FIO_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
enum qse_fio_open_flag_t
|
||||
{
|
||||
/* treat the file name pointer as a handle pointer */
|
||||
QSE_FIO_HANDLE = (1 << 0),
|
||||
|
||||
QSE_FIO_READ = (1 << 1),
|
||||
QSE_FIO_WRITE = (1 << 2),
|
||||
QSE_FIO_APPEND = (1 << 3),
|
||||
|
||||
QSE_FIO_CREATE = (1 << 4),
|
||||
QSE_FIO_TRUNCATE = (1 << 5),
|
||||
QSE_FIO_EXCLUSIVE = (1 << 6),
|
||||
QSE_FIO_SYNC = (1 << 7),
|
||||
|
||||
/* for ms windows only */
|
||||
QSE_FIO_NOSHRD = (1 << 16),
|
||||
QSE_FIO_NOSHWR = (1 << 17)
|
||||
};
|
||||
|
||||
/* seek origin */
|
||||
enum qse_fio_seek_origin_t
|
||||
{
|
||||
QSE_FIO_BEGIN = 0,
|
||||
QSE_FIO_CURRENT = 1,
|
||||
QSE_FIO_END = 2
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
/* <winnt.h> typedef PVOID HANDLE; */
|
||||
typedef void* qse_fio_hnd_t;
|
||||
#else
|
||||
typedef int qse_fio_hnd_t;
|
||||
#endif
|
||||
|
||||
/* file offset */
|
||||
typedef qse_int64_t qse_fio_off_t;
|
||||
typedef enum qse_fio_seek_origin_t qse_fio_ori_t;
|
||||
|
||||
typedef struct qse_fio_t qse_fio_t;
|
||||
|
||||
struct qse_fio_t
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
qse_fio_hnd_t handle;
|
||||
};
|
||||
|
||||
#define QSE_FIO_MMGR(fio) ((fio)->mmgr)
|
||||
#define QSE_FIO_HANDLE(fio) ((fio)->handle)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****f* qse.fio/qse_fio_open
|
||||
* NAME
|
||||
* qse_fio_open - open a file
|
||||
*
|
||||
* DESCRIPTION
|
||||
* To open a file, you should set the flags with at least one of
|
||||
* QSE_FIO_READ, QSE_FIO_WRITE, QSE_FIO_APPEND.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_fio_t* qse_fio_open (
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t ext,
|
||||
const qse_char_t* path,
|
||||
int flags,
|
||||
int mode
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.fio/qse_fio_close
|
||||
* NAME
|
||||
* qse_fio_close - close a file
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_fio_close (
|
||||
qse_fio_t* fio
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_fio_t* qse_fio_init (
|
||||
qse_fio_t* fio,
|
||||
qse_mmgr_t* mmgr,
|
||||
const qse_char_t* path,
|
||||
int flags,
|
||||
int mode
|
||||
);
|
||||
|
||||
void qse_fio_fini (
|
||||
qse_fio_t* fio
|
||||
);
|
||||
|
||||
qse_fio_hnd_t qse_fio_gethandle (
|
||||
qse_fio_t* fio
|
||||
);
|
||||
|
||||
/****f* qse.cmn.fio/qse_fio_sethandle
|
||||
* SYNOPSIS
|
||||
* qse_fio_sethandle - set the file handle
|
||||
* WARNING
|
||||
* Avoid using this function if you don't know what you are doing.
|
||||
* You may have to retrieve the previous handle using qse_fio_gethandle()
|
||||
* to take relevant actions before resetting it with qse_fio_sethandle().
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_fio_sethandle (
|
||||
qse_fio_t* fio,
|
||||
qse_fio_hnd_t handle
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_fio_off_t qse_fio_seek (
|
||||
qse_fio_t* fio,
|
||||
qse_fio_off_t offset,
|
||||
qse_fio_ori_t origin
|
||||
);
|
||||
|
||||
int qse_fio_truncate (
|
||||
qse_fio_t* fio,
|
||||
qse_fio_off_t size
|
||||
);
|
||||
|
||||
qse_ssize_t qse_fio_read (
|
||||
qse_fio_t* fio,
|
||||
void* buf,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
qse_ssize_t qse_fio_write (
|
||||
qse_fio_t* fio,
|
||||
const void* buf,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
74
qse/include/qse/cmn/io.h
Normal file
74
qse/include/qse/cmn/io.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* $Id: sysapi.h,v 1.56 2006/03/21 16:15:16 bacon Ease $
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_IO_H_
|
||||
#define _QSE_CMN_IO_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/* flags for qse_open */
|
||||
enum
|
||||
{
|
||||
QSE_OPEN_READ = (1 << 0),
|
||||
QSE_OPEN_WRITE = (1 << 1),
|
||||
QSE_OPEN_CREATE = (1 << 2),
|
||||
QSE_OPEN_TRUNCATE = (1 << 3),
|
||||
QSE_OPEN_EXCLUSIVE = (1 << 4),
|
||||
QSE_OPEN_APPEND = (1 << 5),
|
||||
QSE_OPEN_NONBLOCK = (1 << 6)
|
||||
};
|
||||
|
||||
/* origin for qse_seek */
|
||||
enum
|
||||
{
|
||||
QSE_SEEK_BEGIN = 0,
|
||||
QSE_SEEK_CURRENT = 1,
|
||||
QSE_SEEK_END = 2
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
qse_hnd_t qse_open (
|
||||
const qse_char_t* path,
|
||||
int flag,
|
||||
...
|
||||
);
|
||||
|
||||
int qse_close (
|
||||
qse_hnd_t handle
|
||||
);
|
||||
|
||||
qse_ssize_t qse_read (
|
||||
qse_hnd_t handle,
|
||||
void* buf,
|
||||
qse_size_t sz
|
||||
);
|
||||
|
||||
qse_ssize_t qse_write (
|
||||
qse_hnd_t handle,
|
||||
const void* data,
|
||||
qse_size_t sz
|
||||
);
|
||||
|
||||
qse_off_t qse_seek (
|
||||
qse_hnd_t handle,
|
||||
qse_off_t offset,
|
||||
int origin
|
||||
);
|
||||
|
||||
/*
|
||||
int qse_hstat (qse_hnd_t handle, qse_stat_t* buf);
|
||||
int qse_hchmod (qse_hnd_t handle, qse_mode_t mode);
|
||||
*/
|
||||
int qse_htruncate (qse_hnd_t handle, qse_off_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
477
qse/include/qse/cmn/lda.h
Normal file
477
qse/include/qse/cmn/lda.h
Normal file
@ -0,0 +1,477 @@
|
||||
/*
|
||||
* $Id: lda.h 363 2008-09-04 10:58:08Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_LDA_H_
|
||||
#define _QSE_CMN_LDA_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/****o* qse.cmn.lda/linear dynamic array
|
||||
* DESCRIPTION
|
||||
* <qse/cmn/lda.h> provides a linear dynamic array. It grows as more items
|
||||
* are added. T
|
||||
*
|
||||
* #include <qse/cmn/lda.h>
|
||||
******
|
||||
*/
|
||||
|
||||
enum qse_lda_walk_t
|
||||
{
|
||||
QSE_LDA_WALK_STOP = 0,
|
||||
QSE_LDA_WALK_FORWARD = 1,
|
||||
QSE_LDA_WALK_BACKWARD = 2
|
||||
};
|
||||
|
||||
typedef struct qse_lda_t qse_lda_t;
|
||||
typedef struct qse_lda_node_t qse_lda_node_t;
|
||||
typedef enum qse_lda_walk_t qse_lda_walk_t;
|
||||
|
||||
#define QSE_LDA_COPIER_SIMPLE ((qse_lda_copier_t)1)
|
||||
#define QSE_LDA_COPIER_INLINE ((qse_lda_copier_t)2)
|
||||
|
||||
#define QSE_LDA_INVALID ((qse_size_t)-1)
|
||||
|
||||
#define QSE_LDA_SIZE(lda) ((lda)->size)
|
||||
#define QSE_LDA_CAPA(lda) ((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_MMGR(lda) ((lda)->mmgr)
|
||||
#define QSE_LDA_XTN(lda) ((void*)(((qse_lda_t*)lda) + 1))
|
||||
|
||||
#define QSE_LDA_COPIER(lda) ((lda)->copier)
|
||||
#define QSE_LDA_FREEER(lda) ((lda)->freeer)
|
||||
#define QSE_LDA_COMPER(lda) ((lda)->comper)
|
||||
#define QSE_LDA_KEEPER(lda) ((lda)->keeper)
|
||||
#define QSE_LDA_SIZER(lda) ((lda)->sizer)
|
||||
|
||||
|
||||
|
||||
/****b* qse.cmn.lda/qse_lda_copier_t
|
||||
* NAME
|
||||
* qse_lda_copier_t - define a node contruction callback
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_copier_t defines a callback function for node construction.
|
||||
* A node is contructed when a user adds data to a list. The user can
|
||||
* define how the data to add can be maintained in the list. A singly
|
||||
* linked list not specified with any copiers stores the data pointer and
|
||||
* the data length into a node. A special copier QSE_LDA_COPIER_INLINE copies
|
||||
* the contents of the data a user provided into the node. You can use the
|
||||
* qse_lda_setcopier() function to change the copier.
|
||||
*
|
||||
* A copier should return the pointer to the copied data. If it fails to copy
|
||||
* data, it may return QSE_NULL. You need to set a proper freeer to free up
|
||||
* memory allocated for copy.
|
||||
*
|
||||
* SEE ALSO
|
||||
* qse_lda_setcopier, qse_lda_getcopier, QSE_LDA_COPIER
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef void* (*qse_lda_copier_t) (
|
||||
qse_lda_t* lda /* a lda */,
|
||||
void* dptr /* the pointer to data to copy */,
|
||||
qse_size_t dlen /* the length of data to copy */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****b* qse.cmn.lda/qse_lda_freeer_t
|
||||
* NAME
|
||||
* qse_lda_freeer_t - define a node destruction callback
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef void (*qse_lda_freeer_t) (
|
||||
qse_lda_t* lda /* a lda */,
|
||||
void* dptr /* the pointer to data to free */,
|
||||
qse_size_t dlen /* the length of data to free */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* qse.cmn.lda/qse_lda_comper_t
|
||||
* NAME
|
||||
* qse_lda_comper_t - define a data comparator
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_comper_t type defines a key comparator that is called when
|
||||
* the list needs to compare data. A linear dynamic array is created with a
|
||||
* default comparator that performs bitwise comparison.
|
||||
*
|
||||
* The comparator should return 0 if the data are the same and a non-zero
|
||||
* integer otherwise.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef int (*qse_lda_comper_t) (
|
||||
qse_lda_t* lda /* a linear dynamic array */,
|
||||
const void* dptr1 /* a data pointer */,
|
||||
qse_size_t dlen1 /* a data length */,
|
||||
const void* dptr2 /* a data pointer */,
|
||||
qse_size_t dlen2 /* a data length */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* qse.cmn.lda/qse_lda_keeper_t
|
||||
* NAME
|
||||
* qse_lda_keeper_t - define a value keeper
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_keeper_t type defines a value keeper that is called when
|
||||
* a value is retained in the context that it should be destroyed because
|
||||
* it is identical to a new value. Two values are identical if their beginning
|
||||
* pointers and their lengths are equal.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef void (*qse_lda_keeper_t) (
|
||||
qse_lda_t* lda /* a lda */,
|
||||
void* vptr /* the pointer to a value */,
|
||||
qse_size_t vlen /* the length of a value */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* qse.cmn.lda/qse_lda_sizer_t
|
||||
* NAME
|
||||
* qse_lda_sizer_t - define an array size calculator
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_sizer_t type defines an array size claculator that is called
|
||||
* when the array needs to be resized.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef qse_size_t (*qse_lda_sizer_t) (
|
||||
qse_lda_t* lda, /* a linear dynamic array */
|
||||
qse_size_t hint /* a sizing hint */
|
||||
);
|
||||
/******/
|
||||
|
||||
typedef qse_lda_walk_t (*qse_lda_walker_t) (
|
||||
qse_lda_t* lda /* a linear dynamic array */,
|
||||
qse_size_t index /* the index to the visited node */,
|
||||
void* arg /* user-defined data */
|
||||
);
|
||||
|
||||
/****s* qse.cmn.lda/qse_lda_t
|
||||
* NAME
|
||||
* qse_lda_t - define a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
struct qse_lda_t
|
||||
{
|
||||
qse_mmgr_t* mmgr; /* memory manager */
|
||||
|
||||
qse_lda_copier_t copier; /* data copier */
|
||||
qse_lda_freeer_t freeer; /* data freeer */
|
||||
qse_lda_comper_t comper; /* data comparator */
|
||||
qse_lda_keeper_t keeper; /* data keeper */
|
||||
qse_lda_sizer_t sizer; /* size calculator */
|
||||
qse_byte_t scale; /* scale factor */
|
||||
qse_size_t size; /* the number of items */
|
||||
qse_size_t capa; /* capacity */
|
||||
qse_lda_node_t** node;
|
||||
};
|
||||
/******/
|
||||
|
||||
/****s*
|
||||
* NAME
|
||||
* qse_lda_node_t - define a linear dynamic array node
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
struct qse_lda_node_t
|
||||
{
|
||||
void* dptr;
|
||||
qse_size_t dlen;
|
||||
};
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_open
|
||||
* NAME
|
||||
* qse_lda_open - create a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_lda_t* qse_lda_open (
|
||||
qse_mmgr_t* lda,
|
||||
qse_size_t ext,
|
||||
qse_size_t capa
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_close
|
||||
* NAME
|
||||
* qse_lda_close - destroy a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_lda_close (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_init
|
||||
* NAME
|
||||
* qse_lda_init - initialize a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_lda_t* qse_lda_init (
|
||||
qse_lda_t* lda,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t capa
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_fini
|
||||
* NAME
|
||||
* qse_lda_fini - deinitialize a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_lda_fini (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_getxtn
|
||||
* NAME
|
||||
* qse_lda_getxtn - get the pointer to the extension
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_getxtn() function returns the pointer to the extension.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void* qse_lda_getxtn (
|
||||
qse_lda_t* lda /* a linear dynamic array */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_getmmgr
|
||||
* NAME
|
||||
* qse_lda_getmmgr - get the memory manager
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_mmgr_t* qse_lda_getmmgr (
|
||||
qse_lda_t* lda /* a linear dynamic array */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_setmmgr
|
||||
* NAME
|
||||
* qse_lda_setmmgr - set the memory manager
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_lda_setmmgr (
|
||||
qse_lda_t* lda /* a linear dynamic array */,
|
||||
qse_mmgr_t* mmgr /* a memory manager */
|
||||
);
|
||||
/******/
|
||||
|
||||
int qse_lda_getscale (
|
||||
qse_lda_t* lda /* a lda */
|
||||
);
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_setscale
|
||||
* NAME
|
||||
* qse_lda_setscale - set the scale factor
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_setscale() function sets the scale factor of the length
|
||||
* of a key and a value. A scale factor determines the actual length of
|
||||
* a key and a value in bytes. A lda is created with a scale factor of 1.
|
||||
* The scale factor should be larger than 0 and less than 256.
|
||||
*
|
||||
* NOTES
|
||||
* It is a bad idea to change the scale factor when a lda is not empty.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_lda_setscale (
|
||||
qse_lda_t* lda /* a lda */,
|
||||
int scale /* a scale factor */
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_lda_copier_t qse_lda_getcopier (
|
||||
qse_lda_t* lda /* a lda */
|
||||
);
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_setcopier
|
||||
* NAME
|
||||
* qse_lda_setcopier - specify how to clone an element
|
||||
*
|
||||
* DESCRIPTION
|
||||
* A special copier QSE_LDA_COPIER_INLINE is provided. This copier enables
|
||||
* you to copy the data inline to the internal node. No freeer is invoked
|
||||
* when the node is freeed.
|
||||
*
|
||||
* You may set the copier to QSE_NULL to perform no special operation
|
||||
* when the data pointer is rememebered.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_lda_setcopier (
|
||||
qse_lda_t* lda /* a lda */,
|
||||
qse_lda_copier_t copier /* an element copier */
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_lda_freeer_t qse_lda_getfreeer (
|
||||
qse_lda_t* lda /* a lda */
|
||||
);
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_setfreeer
|
||||
* NAME
|
||||
* qse_lda_setfreeer - specify how to destroy an element
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The freeer is called when a node containing the element is destroyed.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_lda_setfreeer (
|
||||
qse_lda_t* lda /* a lda */,
|
||||
qse_lda_freeer_t freeer /* an element freeer */
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_lda_keeper_t qse_lda_getkeeper (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
|
||||
void qse_lda_setkeeper (
|
||||
qse_lda_t* lda,
|
||||
qse_lda_keeper_t keeper
|
||||
);
|
||||
|
||||
qse_lda_sizer_t qse_lda_getsizer (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
|
||||
void qse_lda_setsizer (
|
||||
qse_lda_t* lda,
|
||||
qse_lda_sizer_t sizer
|
||||
);
|
||||
|
||||
qse_size_t qse_lda_getsize (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
|
||||
qse_size_t qse_lda_getcapa (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
|
||||
qse_lda_t* qse_lda_setcapa (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t capa
|
||||
);
|
||||
|
||||
qse_size_t qse_lda_search (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t pos,
|
||||
const void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
qse_size_t qse_lda_rsearch (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t pos,
|
||||
const void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
qse_size_t qse_lda_upsert (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t index,
|
||||
void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
qse_size_t qse_lda_insert (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t index,
|
||||
void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
qse_size_t qse_lda_update (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t pos,
|
||||
void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_delete
|
||||
* NAME
|
||||
* qse_lda_delete - delete data
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_delete() function deletes the as many data as the count
|
||||
* from the index.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_lda_delete() function returns the number of data deleted.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_size_t qse_lda_delete (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t index,
|
||||
qse_size_t count
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.lda/qse_lda_uplete
|
||||
* NAME
|
||||
* qse_lda_uplete - delete data node
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_uplete() function deletes data node without compaction.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_lda_uplete() function returns the number of data affected.
|
||||
*
|
||||
*/
|
||||
qse_size_t qse_lda_uplete (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t index,
|
||||
qse_size_t count
|
||||
);
|
||||
/******/
|
||||
|
||||
void qse_lda_clear (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
|
||||
void qse_lda_walk (
|
||||
qse_lda_t* lda,
|
||||
qse_lda_walker_t walker,
|
||||
void* arg
|
||||
);
|
||||
|
||||
void qse_lda_rwalk (
|
||||
qse_lda_t* lda,
|
||||
qse_lda_walker_t walker,
|
||||
void* arg
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
7
qse/include/qse/cmn/makefile.am
Normal file
7
qse/include/qse/cmn/makefile.am
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
pkginclude_HEADERS = mem.h chr.h str.h lda.h map.h rex.h sll.h dll.h opt.h fio.h tio.h sio.h time.h
|
||||
|
||||
pkgincludedir= $(includedir)/qse/cmn
|
||||
|
||||
CLEANFILES = *dist
|
||||
|
415
qse/include/qse/cmn/makefile.in
Normal file
415
qse/include/qse/cmn/makefile.in
Normal file
@ -0,0 +1,415 @@
|
||||
# makefile.in generated by automake 1.10.1 from makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
subdir = include/qse/cmn
|
||||
DIST_COMMON = $(pkginclude_HEADERS) $(srcdir)/makefile.am \
|
||||
$(srcdir)/makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/include/qse/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
SOURCES =
|
||||
DIST_SOURCES =
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
|
||||
am__installdirs = "$(DESTDIR)$(pkgincludedir)"
|
||||
pkgincludeHEADERS_INSTALL = $(INSTALL_HEADER)
|
||||
HEADERS = $(pkginclude_HEADERS)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
pkgincludedir = $(includedir)/qse/cmn
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
BUILD_CJ = @BUILD_CJ@
|
||||
BUILD_JNI = @BUILD_JNI@
|
||||
BUILD_MODE = @BUILD_MODE@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CFLAGS_JNI = @CFLAGS_JNI@
|
||||
CJ = @CJ@
|
||||
CJFLAGS = @CJFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
ECHO = @ECHO@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
F77 = @F77@
|
||||
FFLAGS = @FFLAGS@
|
||||
GREP = @GREP@
|
||||
HAVE_CXX = @HAVE_CXX@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
JAR = @JAR@
|
||||
JAR_PATH = @JAR_PATH@
|
||||
JAVAC = @JAVAC@
|
||||
JAVAC_PATH = @JAVAC_PATH@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBM = @LIBM@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
RANLIB = @RANLIB@
|
||||
RM = @RM@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_F77 = @ac_ct_F77@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
builddir = @builddir@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
pkginclude_HEADERS = mem.h chr.h str.h lda.h map.h rex.h sll.h dll.h opt.h fio.h tio.h sio.h time.h
|
||||
CLEANFILES = *dist
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
$(srcdir)/makefile.in: $(srcdir)/makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/qse/cmn/makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign include/qse/cmn/makefile
|
||||
.PRECIOUS: makefile
|
||||
makefile: $(srcdir)/makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
install-pkgincludeHEADERS: $(pkginclude_HEADERS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)"
|
||||
@list='$(pkginclude_HEADERS)'; for p in $$list; do \
|
||||
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(pkgincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgincludedir)/$$f'"; \
|
||||
$(pkgincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgincludedir)/$$f"; \
|
||||
done
|
||||
|
||||
uninstall-pkgincludeHEADERS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(pkginclude_HEADERS)'; for p in $$list; do \
|
||||
f=$(am__strip_dir) \
|
||||
echo " rm -f '$(DESTDIR)$(pkgincludedir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(pkgincludedir)/$$f"; \
|
||||
done
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
list='$(DISTFILES)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: makefile $(HEADERS)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(pkgincludedir)"; do \
|
||||
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libtool mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -f makefile
|
||||
distclean-am: clean-am distclean-generic distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am: install-pkgincludeHEADERS
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-exec-am:
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -f makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-pkgincludeHEADERS
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-libtool ctags distclean distclean-generic \
|
||||
distclean-libtool distclean-tags distdir dvi dvi-am html \
|
||||
html-am info info-am install install-am install-data \
|
||||
install-data-am install-dvi install-dvi-am install-exec \
|
||||
install-exec-am install-html install-html-am install-info \
|
||||
install-info-am install-man install-pdf install-pdf-am \
|
||||
install-pkgincludeHEADERS install-ps install-ps-am \
|
||||
install-strip installcheck installcheck-am installdirs \
|
||||
maintainer-clean maintainer-clean-generic mostlyclean \
|
||||
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
|
||||
tags uninstall uninstall-am uninstall-pkgincludeHEADERS
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
566
qse/include/qse/cmn/map.h
Normal file
566
qse/include/qse/cmn/map.h
Normal file
@ -0,0 +1,566 @@
|
||||
/*
|
||||
* $Id: map.h 496 2008-12-15 09:56:48Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_MAP_H_
|
||||
#define _QSE_CMN_MAP_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/****o* qse.cmn.map/hash map
|
||||
* DESCRIPTION
|
||||
* A hash map maintains buckets for key/value pairs with the same key hash
|
||||
* chained under the same bucket.
|
||||
*
|
||||
* #include <qse/cmn/map.h>
|
||||
*
|
||||
* EXAMPLES
|
||||
* void f (void)
|
||||
* {
|
||||
* }
|
||||
******
|
||||
*/
|
||||
|
||||
/* values that can be returned by qse_map_walker_t */
|
||||
enum qse_map_walk_t
|
||||
{
|
||||
QSE_MAP_WALK_STOP = 0,
|
||||
QSE_MAP_WALK_FORWARD = 1
|
||||
};
|
||||
|
||||
enum qse_map_id_t
|
||||
{
|
||||
QSE_MAP_KEY = 0,
|
||||
QSE_MAP_VAL = 1
|
||||
};
|
||||
|
||||
typedef struct qse_map_t qse_map_t;
|
||||
typedef struct qse_map_pair_t qse_map_pair_t;
|
||||
typedef enum qse_map_walk_t qse_map_walk_t;
|
||||
typedef enum qse_map_id_t qse_map_id_t;
|
||||
|
||||
/****b* qse.cmn.map/qse_map_copier_t
|
||||
* NAME
|
||||
* qse_map_copier_t - define a pair contruction callback
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef void* (*qse_map_copier_t) (
|
||||
qse_map_t* map /* a map */,
|
||||
void* dptr /* the pointer to a key or a value */,
|
||||
qse_size_t dlen /* the length of a key or a value */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****b* qse.cmn.map/qse_map_freeer_t
|
||||
* NAME
|
||||
* qse_map_freeer_t - define a key/value destruction callback
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef void (*qse_map_freeer_t) (
|
||||
qse_map_t* map /* a map */,
|
||||
void* dptr /* the pointer to a key or a value */,
|
||||
qse_size_t dlen /* the length of a key or a value */
|
||||
);
|
||||
/******/
|
||||
|
||||
/* key hasher */
|
||||
typedef qse_size_t (*qse_map_hasher_t) (
|
||||
qse_map_t* map /* a map */,
|
||||
const void* kptr /* the pointer to a key */,
|
||||
qse_size_t klen /* the length of a key in bytes */
|
||||
);
|
||||
|
||||
/****t* qse.cmn.map/qse_map_comper_t
|
||||
* NAME
|
||||
* qse_map_comper_t - define a key comparator
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_map_comper_t type defines a key comparator that is called when
|
||||
* the map needs to compare keys. A map is created with a default comparator
|
||||
* which performs bitwise comparison between two keys.
|
||||
*
|
||||
* The comparator should return 0 if the keys are the same and a non-zero
|
||||
* integer otherwise.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef int (*qse_map_comper_t) (
|
||||
qse_map_t* map /* a map */,
|
||||
const void* kptr1 /* the pointer to a key */,
|
||||
qse_size_t klen1 /* the length of a key */,
|
||||
const void* kptr2 /* the pointer to a key */,
|
||||
qse_size_t klen2 /* the length of a key */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* qse.cmn.map/qse_map_keeper_t
|
||||
* NAME
|
||||
* qse_map_keeper_t - define a value keeper
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_map_keeper_t type defines a value keeper that is called when
|
||||
* a value is retained in the context that it should be destroyed because
|
||||
* it is identical to a new value. Two values are identical if their beginning
|
||||
* pointers and their lengths are equal.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef void (*qse_map_keeper_t) (
|
||||
qse_map_t* map /* a map */,
|
||||
void* vptr /* the pointer to a value */,
|
||||
qse_size_t vlen /* the length of a value */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* qse.cmn.map/qse_map_sizer_t
|
||||
* NAME
|
||||
* qse_map_sizer_t - define a bucket size calculator
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_map_sizer_T type defines a bucket size claculator that is called
|
||||
* when a map should resize the bucket. The current bucket size +1 is passed
|
||||
* as the hint.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef qse_size_t (*qse_map_sizer_t) (
|
||||
qse_map_t* map, /* a map */
|
||||
qse_size_t hint /* a sizing hint */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* qse.cmn.map/qse_map_walker_t
|
||||
* NAME
|
||||
* qse_map_walker_t - define a pair visitor
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef qse_map_walk_t (*qse_map_walker_t) (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_map_pair_t* pair /* the pointer to a key/value pair */,
|
||||
void* arg /* the pointer to user-defined data */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****s* qse.cmn.map/qse_map_pair_t
|
||||
* NAME
|
||||
* qse_map_pair_t - define a pair
|
||||
*
|
||||
* DESCRIPTION
|
||||
* A pair is composed of a key and a value. It maintains pointers to the
|
||||
* beginning of a key and a value plus their length. The length is scaled
|
||||
* down with the scale factor specified in an owning map. Use macros defined
|
||||
* in the SEE ALSO section below to access individual fields.
|
||||
*
|
||||
* SEE ALSO
|
||||
* QSE_MAP_KPTR, QSE_MAP_KLEN, QSE_MAP_VPTR, QSE_MAP_VLEN
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
struct qse_map_pair_t
|
||||
{
|
||||
void* kptr; /* the pointer to a key */
|
||||
qse_size_t klen; /* the length of a key */
|
||||
void* vptr; /* the pointer to a value */
|
||||
qse_size_t vlen; /* the length of a value */
|
||||
qse_map_pair_t* next; /* the next pair under the same slot */
|
||||
};
|
||||
/*****/
|
||||
|
||||
/****s* qse.cmn.map/qse_map_t
|
||||
* NAME
|
||||
* qse_map_t - define a hash map
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
struct qse_map_t
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
qse_map_copier_t copier[2];
|
||||
qse_map_freeer_t freeer[2];
|
||||
qse_map_hasher_t hasher; /* key hasher */
|
||||
qse_map_comper_t comper; /* key comparator */
|
||||
qse_map_keeper_t keeper; /* value keeper */
|
||||
qse_map_sizer_t sizer; /* bucket capacity recalculator */
|
||||
qse_byte_t scale[2]; /* length scale */
|
||||
qse_byte_t factor; /* load factor */
|
||||
qse_byte_t filler0;
|
||||
qse_size_t size;
|
||||
qse_size_t capa;
|
||||
qse_size_t threshold;
|
||||
qse_map_pair_t** bucket;
|
||||
};
|
||||
/******/
|
||||
|
||||
#define QSE_MAP_COPIER_SIMPLE ((qse_map_copier_t)1)
|
||||
#define QSE_MAP_COPIER_INLINE ((qse_map_copier_t)2)
|
||||
|
||||
/****d* qse.cmn.map/QSE_MAP_SIZE
|
||||
* NAME
|
||||
* QSE_MAP_SIZE - get the number of pairs
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The QSE_MAP_SIZE() macro returns the number of pairs in a map.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
#define QSE_MAP_SIZE(m) ((m)->size)
|
||||
/*****/
|
||||
|
||||
/****d* qse.cmn.map/QSE_MAP_CAPA
|
||||
* NAME
|
||||
* QSE_MAP_CAPA - get the capacity of a map
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The QSE_MAP_CAPA() macro returns the maximum number of pairs a map can hold.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
#define QSE_MAP_CAPA(m) ((m)->capa)
|
||||
/*****/
|
||||
|
||||
#define QSE_MAP_MMGR(m) ((m)->mmgr)
|
||||
#define QSE_MAP_XTN(m) ((void*)(((qse_map_t*)m) + 1))
|
||||
|
||||
#define QSE_MAP_KCOPIER(m) ((m)->copier[QSE_MAP_KEY])
|
||||
#define QSE_MAP_VCOPIER(m) ((m)->copier[QSE_MAP_VAL])
|
||||
#define QSE_MAP_KFREEER(m) ((m)->freeer[QSE_MAP_KEY])
|
||||
#define QSE_MAP_VFREEER(m) ((m)->freeer[QSE_MAP_VAL])
|
||||
#define QSE_MAP_HASHER(m) ((m)->hasher)
|
||||
#define QSE_MAP_COMPER(m) ((m)->comper)
|
||||
#define QSE_MAP_KEEPER(m) ((m)->keeper)
|
||||
#define QSE_MAP_SIZER(m) ((m)->sizer)
|
||||
|
||||
#define QSE_MAP_FACTOR(m) ((m)->factor)
|
||||
#define QSE_MAP_KSCALE(m) ((m)->scale[QSE_MAP_KEY])
|
||||
#define QSE_MAP_VSCALE(m) ((m)->scale[QSE_MAP_VAL])
|
||||
|
||||
#define QSE_MAP_KPTR(p) ((p)->kptr)
|
||||
#define QSE_MAP_KLEN(p) ((p)->klen)
|
||||
#define QSE_MAP_VPTR(p) ((p)->vptr)
|
||||
#define QSE_MAP_VLEN(p) ((p)->vlen)
|
||||
#define QSE_MAP_NEXT(p) ((p)->next)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****f* qse.cmn.map/qse_map_open
|
||||
* NAME
|
||||
* qse_map_open - creates a hash map
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_map_open() function creates a hash map with a dynamic array
|
||||
* bucket and a list of values chained. The initial capacity should be larger
|
||||
* than 0. The load factor should be between 0 and 100 inclusive and the load
|
||||
* factor of 0 disables bucket resizing. If you need extra space associated
|
||||
* with a map, you may pass a non-zero value as the second parameter.
|
||||
* The QSE_MAP_XTN() macro and the qse_map_getxtn() function
|
||||
* return the pointer to the beginning of the extension.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_map_open() function returns an qse_map_t pointer on success and
|
||||
* QSE_NULL on failure.
|
||||
*
|
||||
* SEE ALSO
|
||||
* QSE_MAP_XTN, qse_map_getxtn
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_map_t* qse_map_open (
|
||||
qse_mmgr_t* mmgr /* a memory manager */,
|
||||
qse_size_t ext /* extension size in bytes */,
|
||||
qse_size_t capa /* initial capacity */,
|
||||
int factor /* load factor */
|
||||
);
|
||||
/******/
|
||||
|
||||
|
||||
/****f* qse.cmn.map/qse_map_close
|
||||
* NAME
|
||||
* qse_map_close - destroy a hash map
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_map_close() function destroys a hash map.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_map_close (
|
||||
qse_map_t* map /* a map */
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_map_t* qse_map_init (
|
||||
qse_map_t* map,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t capa,
|
||||
int factor
|
||||
);
|
||||
|
||||
void qse_map_fini (
|
||||
qse_map_t* map
|
||||
);
|
||||
|
||||
void* qse_map_getxtn (
|
||||
qse_map_t* map
|
||||
);
|
||||
|
||||
qse_mmgr_t* qse_map_getmmgr (
|
||||
qse_map_t* map
|
||||
);
|
||||
|
||||
void qse_map_setmmgr (
|
||||
qse_map_t* map,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
/* get the number of key/value pairs in a map */
|
||||
qse_size_t qse_map_getsize (
|
||||
qse_map_t* map /* a map */
|
||||
);
|
||||
|
||||
qse_size_t qse_map_getcapa (
|
||||
qse_map_t* map /* a map */
|
||||
);
|
||||
|
||||
int qse_map_getscale (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_map_id_t id /* QSE_MAP_KEY or QSE_MAP_VAL */
|
||||
);
|
||||
|
||||
/****f* qse.cmn.map/qse_map_setscale
|
||||
* NAME
|
||||
* qse_map_setscale - set the scale factor
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_map_setscale() function sets the scale factor of the length
|
||||
* of a key and a value. A scale factor determines the actual length of
|
||||
* a key and a value in bytes. A map is created with a scale factor of 1.
|
||||
* The scale factor should be larger than 0 and less than 256.
|
||||
*
|
||||
* NOTES
|
||||
* It is a bad idea to change the scale factor when a map is not empty.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_map_setscale (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_map_id_t id /* QSE_MAP_KEY or QSE_MAP_VAL */,
|
||||
int scale /* a scale factor */
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_map_copier_t qse_map_getcopier (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_map_id_t id /* QSE_MAP_KEY or QSE_MAP_VAL */
|
||||
);
|
||||
|
||||
/****f* qse.cmn.map/qse_map_setcopier
|
||||
* NAME
|
||||
* qse_map_setcopier - specify how to clone an element
|
||||
*
|
||||
* DESCRIPTION
|
||||
* A special copier QSE_MAP_COPIER_INLINE is provided. This copier enables
|
||||
* you to copy the data inline to the internal node. No freeer is invoked
|
||||
* when the node is freeed.
|
||||
*
|
||||
* You may set the copier to QSE_NULL to perform no special operation
|
||||
* when the data pointer is rememebered.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_map_setcopier (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_map_id_t id /* QSE_MAP_KEY or QSE_MAP_VAL */,
|
||||
qse_map_copier_t copier /* an element copier */
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_map_freeer_t qse_map_getfreeer (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_map_id_t id /* QSE_MAP_KEY or QSE_MAP_VAL */
|
||||
);
|
||||
|
||||
/****f* qse.cmn.map/qse_map_setfreeer
|
||||
* NAME
|
||||
* qse_map_setfreeer - specify how to destroy an element
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The freeer is called when a node containing the element is destroyed.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_map_setfreeer (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_map_id_t id /* QSE_MAP_KEY or QSE_MAP_VAL */,
|
||||
qse_map_freeer_t freeer /* an element freeer */
|
||||
);
|
||||
/******/
|
||||
|
||||
|
||||
qse_map_hasher_t qse_map_gethasher (
|
||||
qse_map_t* map
|
||||
);
|
||||
|
||||
void qse_map_sethasher (
|
||||
qse_map_t* map,
|
||||
qse_map_hasher_t hasher
|
||||
);
|
||||
|
||||
qse_map_comper_t qse_map_getcomper (
|
||||
qse_map_t* map
|
||||
);
|
||||
|
||||
void qse_map_setcomper (
|
||||
qse_map_t* map,
|
||||
qse_map_comper_t comper
|
||||
);
|
||||
|
||||
qse_map_keeper_t qse_map_getkeeper (
|
||||
qse_map_t* map
|
||||
);
|
||||
|
||||
void qse_map_setkeeper (
|
||||
qse_map_t* map,
|
||||
qse_map_keeper_t keeper
|
||||
);
|
||||
|
||||
qse_map_sizer_t qse_map_getsizer (
|
||||
qse_map_t* map
|
||||
);
|
||||
|
||||
/* the sizer function is passed a map object and map->capa + 1 */
|
||||
void qse_map_setsizer (
|
||||
qse_map_t* map,
|
||||
qse_map_sizer_t sizer
|
||||
);
|
||||
|
||||
int qse_map_put (
|
||||
qse_map_t* map,
|
||||
void* kptr,
|
||||
qse_size_t klen,
|
||||
void* vptr,
|
||||
qse_size_t vlen,
|
||||
qse_map_pair_t** px
|
||||
);
|
||||
|
||||
/****f* qse.cmn.map/qse_map_search
|
||||
* NAME
|
||||
* qse_map_search - find a pair with a matching key
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_map_search() function searches a map to find a pair with a
|
||||
* matching key. It returns the pointer to the pair found. If it fails
|
||||
* to find one, it returns QSE_NULL.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_map_search() function returns the pointer to the pair with a
|
||||
* maching key, and QSE_NULL if no match is found.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_map_pair_t* qse_map_search (
|
||||
qse_map_t* map /* a map */,
|
||||
const void* kptr /* the pointer to a key */,
|
||||
qse_size_t klen /* the size of the key in bytes */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.map/qse_map_upsert
|
||||
* NAME
|
||||
* qse_map_upsert - update an existing pair or inesrt a new pair
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_map_upsert() function searches a map for the pair with a matching
|
||||
* key. If one is found, it updates the pair. Otherwise, it inserts a new
|
||||
* pair with a key and a value. It returns the pointer to the pair updated
|
||||
* or inserted.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_map_upsert() function returns a pointer to the updated or inserted
|
||||
* pair on success, and QSE_NULL on failure.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_map_pair_t* qse_map_upsert (
|
||||
qse_map_t* map /* a map */,
|
||||
void* kptr /* the pointer to a key */,
|
||||
qse_size_t klen /* the length of the key in bytes */,
|
||||
void* vptr /* the pointer to a value */,
|
||||
qse_size_t vlen /* the length of the value in bytes */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.map/qse_map_insert
|
||||
* NAME
|
||||
* qse_map_insert - insert a new pair with a key and a value
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_map_insert() function inserts a new pair with the key and the value
|
||||
* given. If there exists a pair with the key given, the function returns
|
||||
* QSE_NULL without channging the value.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_map_insert() function returns a pointer to the pair created on
|
||||
* success, and QSE_NULL on failure.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_map_pair_t* qse_map_insert (
|
||||
qse_map_t* map /* a map */,
|
||||
void* kptr /* the pointer to a key */,
|
||||
qse_size_t klen /* the length of the key in bytes */,
|
||||
void* vptr /* the pointer to a value */,
|
||||
qse_size_t vlen /* the length of the value in bytes */
|
||||
);
|
||||
/******/
|
||||
|
||||
/* update the value of a existing pair with a matching key */
|
||||
qse_map_pair_t* qse_map_update (
|
||||
qse_map_t* map /* a map */,
|
||||
void* kptr /* the pointer to a key */,
|
||||
qse_size_t klen /* the length of the key in bytes */,
|
||||
void* vptr /* the pointer to a value */,
|
||||
qse_size_t vlen /* the length of the value in bytes */
|
||||
);
|
||||
|
||||
/* delete a pair with a matching key */
|
||||
int qse_map_delete (
|
||||
qse_map_t* map /* a map */,
|
||||
const void* kptr /* the pointer to a key */,
|
||||
qse_size_t klen /* the size of the key in bytes */
|
||||
);
|
||||
|
||||
/* clear a map */
|
||||
void qse_map_clear (
|
||||
qse_map_t* map /* a map */
|
||||
);
|
||||
|
||||
/* traverse a map */
|
||||
void qse_map_walk (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_map_walker_t walker /* the pointer to the function for each pair */,
|
||||
void* arg /* a pointer to user-specific data */
|
||||
);
|
||||
|
||||
/* get the pointer to the first pair in the map. */
|
||||
qse_map_pair_t* qse_map_getfirstpair (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_size_t* buckno
|
||||
);
|
||||
|
||||
/* get the pointer to the next pair in the map. */
|
||||
qse_map_pair_t* qse_map_getnextpair (
|
||||
qse_map_t* map /* a map */,
|
||||
qse_map_pair_t* pair,
|
||||
qse_size_t* buckno
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
198
qse/include/qse/cmn/mem.h
Normal file
198
qse/include/qse/cmn/mem.h
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* $Id: mem.h 337 2008-08-20 09:17:25Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_MEM_H_
|
||||
#define _QSE_CMN_MEM_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/* gets a pointer to the default memory manager */
|
||||
#define QSE_MMGR_GETDFL() (qse_mmgr)
|
||||
|
||||
/* sets a pointer to the default memory manager */
|
||||
#define QSE_MMGR_SETDFL(m) ((qse_mmgr)=(m))
|
||||
|
||||
/* allocate a memory block */
|
||||
#define QSE_MMGR_ALLOC(mmgr,size) \
|
||||
((mmgr)->alloc((mmgr)->data,size))
|
||||
|
||||
/* reallocate a memory block */
|
||||
#define QSE_MMGR_REALLOC(mmgr,ptr,size) \
|
||||
((mmgr)->realloc((mmgr)->data,ptr,size))
|
||||
|
||||
/* free a memory block */
|
||||
#define QSE_MMGR_FREE(mmgr,ptr) \
|
||||
((mmgr)->free((mmgr)->data,ptr))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NAME: holds a pointer to the default memory manager
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The QSE_MMGR_GETDFL() macro returns the default memory manager.
|
||||
* You may use QSE_MMGR_SETDFL() to change the default memory manager.
|
||||
*/
|
||||
extern qse_mmgr_t* qse_mmgr;
|
||||
|
||||
/*
|
||||
* NAME: copy a memory block
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_memcpy() functions copies n bytes from the source memory block src
|
||||
* to the destinaion memory block dst.
|
||||
*
|
||||
* RETURNS: the destination memory block dst.
|
||||
*
|
||||
* WARNING:
|
||||
* The memory blocks should not overlap. Use the qse_memmove() function if
|
||||
* they overlap.
|
||||
*/
|
||||
|
||||
void* qse_memcpy (
|
||||
void* dst /* a pointer to the destination memory block */ ,
|
||||
const void* src /* a pointer to the source memory block */ ,
|
||||
qse_size_t n /* the number of bytes to copy */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: copy a memory block with more care
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_memmove() functions copies n bytes from the source memory block src
|
||||
* to the destinaion memory block dst without corrupting overlapping zone.
|
||||
*
|
||||
* RETURNS: the destination memory block dst.
|
||||
*/
|
||||
void* qse_memmove (
|
||||
void* dst /* a pointer to the destination memory block */,
|
||||
const void* src /* a pointer to the source memory block */,
|
||||
qse_size_t n /* the number of bytes to copy */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: fill a memory block
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_memset() function fills leading n bytes of the destination
|
||||
* memory block dst with the byte val.
|
||||
*
|
||||
* RETURNS: the destination memory block dst
|
||||
*/
|
||||
void* qse_memset (
|
||||
void* dst /* a pointer to the destination memory block */,
|
||||
int val /* the byte to fill the memory block with */,
|
||||
qse_size_t n /* the number of bytes to fill */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: compare memory blocks
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_memcmp() function compares leading n bytes of two memory blocks
|
||||
* s1 and s2.
|
||||
*
|
||||
* RETURNS:
|
||||
* 0 if two memory ares have the same leadning n bytes.
|
||||
* a positive number if the first different byte of s1 is greater than that
|
||||
* of s2.
|
||||
* a negative number if the first different byte of s1 is less than that of s2.
|
||||
*/
|
||||
int qse_memcmp (
|
||||
const void* s1 /* a pointer to the first memory block to compare */,
|
||||
const void* s2 /* a pointer to the second memory block to compare */,
|
||||
qse_size_t n /* the number of bytes to compare */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: find a byte forward in a memory block
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_membyte() function scans the memory block s from the first byte
|
||||
* up to the nth byte in search of the byte val. If it finds a match,
|
||||
* it aborts scanning the memory block and returns the pointer to the matching
|
||||
* location.
|
||||
*
|
||||
* RETURNS:
|
||||
* QSE_NULL if the byte val is not found.
|
||||
* The pointer to the location in the memory block s matching the byte val
|
||||
* if a match is found.
|
||||
*/
|
||||
void* qse_membyte (
|
||||
const void* s /* a pointer to the memory block to scan */,
|
||||
int val /* a byte to find */,
|
||||
qse_size_t n /* the number of bytes to scan */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: find a byte backward in a memory block
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_memrbyte() function scans the memory block s from the nth byte
|
||||
* backward to the first byte in search of the byte val. If it finds a match,
|
||||
* it aborts scanning the memory block and returns the pointer to the matching
|
||||
* location.
|
||||
*
|
||||
* RETURNS:
|
||||
* QSE_NULL if the byte val is not found.
|
||||
* The pointer to the location in the memory block s matching the byte val
|
||||
* if a match is found.
|
||||
*/
|
||||
void* qse_memrbyte (
|
||||
const void* s /* a pointer to the memory block to scan */,
|
||||
int val /* a byte to find */,
|
||||
qse_size_t n /* the number of bytes to scan */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: find a block of bytes forward in a memory block
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_memmem() functions scans the first hl bytes of the memory block hs
|
||||
* in search of the byte block nd of the length nl bytes.
|
||||
*
|
||||
* RETURNS:
|
||||
* QSE_NULL if the byte val is not found.
|
||||
* The pointer to the location in the memory block s matching the byte val
|
||||
* if a match is found.
|
||||
*
|
||||
* RETURNS:
|
||||
* QSE_NULL if no match is found.
|
||||
* The pointer to the start of the matching location if a match is found.
|
||||
*/
|
||||
void* qse_memmem (
|
||||
const void* hs /* a pointer to the memory block to scan */,
|
||||
qse_size_t hl /* the number of bytes to scan */,
|
||||
const void* nd /* a pointer to the byte block to find */,
|
||||
qse_size_t nl /* the number of bytes in the block */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: find a block of bytes backward in a memory block
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_memrmem() functions scans the first hl bytes of the memory block hs
|
||||
* backward in search of the byte block nd of the length nl bytes.
|
||||
*
|
||||
* RETURNS:
|
||||
* QSE_NULL if no match is found.
|
||||
* The pointer to the start of the matching location if a match is found.
|
||||
*/
|
||||
void* qse_memrmem (
|
||||
const void* hs /* a pointer to the memory block to scan */,
|
||||
qse_size_t hl /* the number of bytes to scan */,
|
||||
const void* nd /* a pointer to the byte block to find */,
|
||||
qse_size_t nl /* the number of bytes in the block */
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
63
qse/include/qse/cmn/opt.h
Normal file
63
qse/include/qse/cmn/opt.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* $Id: getopt.h 290 2008-07-27 06:16:54Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_OPT_H_
|
||||
#define _QSE_CMN_OPT_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
typedef struct qse_opt_t qse_opt_t;
|
||||
typedef struct qse_opt_lng_t qse_opt_lng_t;
|
||||
|
||||
struct qse_opt_lng_t
|
||||
{
|
||||
const qse_char_t* str;
|
||||
qse_cint_t val;
|
||||
};
|
||||
|
||||
struct qse_opt_t
|
||||
{
|
||||
/* input */
|
||||
const qse_char_t* str; /* option string */
|
||||
qse_opt_lng_t* lng; /* long options */
|
||||
|
||||
/* output */
|
||||
qse_cint_t opt; /* character checked for validity */
|
||||
qse_char_t* arg; /* argument associated with an option */
|
||||
|
||||
/* output */
|
||||
const qse_char_t* lngopt;
|
||||
|
||||
/* input + output */
|
||||
int ind; /* index into parent argv vector */
|
||||
|
||||
/* input + output - internal*/
|
||||
qse_char_t* cur;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****f* qse.cmn.opt/qse_getopt
|
||||
* NAME
|
||||
* qse_getopt - parse command line options
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_cint_t qse_getopt (
|
||||
int argc /* argument count */,
|
||||
qse_char_t* const* argv /* argument array */,
|
||||
qse_opt_t* opt /* option configuration */
|
||||
);
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
94
qse/include/qse/cmn/rex.h
Normal file
94
qse/include/qse/cmn/rex.h
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* $Id: rex.h 223 2008-06-26 06:44:41Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_REX_H_
|
||||
#define _QSE_CMN_REX_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/*
|
||||
* Regular Esseression Syntax
|
||||
* A regular expression is zero or more branches, separated by '|'.
|
||||
* ......
|
||||
* ......
|
||||
*
|
||||
* Compiled form of a regular expression:
|
||||
*
|
||||
* | expression |
|
||||
* | header | branch | branch | branch |
|
||||
* | nb | el | na | bl | cmd | arg | cmd | arg | na | bl | cmd | arg | na | bl | cmd |
|
||||
*
|
||||
* nb: the number of branches
|
||||
* el: the length of a expression including the length of nb and el
|
||||
* na: the number of atoms
|
||||
* bl: the length of a branch including the length of na and bl
|
||||
* cmd: The command and repetition info encoded together.
|
||||
* Some commands require an argument to follow them but some other don't.
|
||||
* It is encoded as follows:
|
||||
*
|
||||
* Subexpressions can be nested by having the command "GROUP"
|
||||
* and a subexpression as its argument.
|
||||
*
|
||||
* Examples:
|
||||
* a.c -> |1|6|5|ORD_CHAR(no bound)|a|ANY_CHAR(no bound)|ORD_CHAR(no bound)|c|
|
||||
* ab|xy -> |2|10|4|ORD_CHAR(no bound)|a|ORD_CHAR(no bound)|b|4|ORD_CHAR(no bound)|x|ORD_CHAR(no bound)|y|
|
||||
*/
|
||||
|
||||
#define QSE_REX_NA(code) (*(qse_size_t*)(code))
|
||||
|
||||
#define QSE_REX_LEN(code) \
|
||||
(*(qse_size_t*)((qse_byte_t*)(code)+QSE_SIZEOF(qse_size_t)))
|
||||
|
||||
enum qse_rex_option_t
|
||||
{
|
||||
QSE_REX_IGNORECASE = (1 << 0)
|
||||
};
|
||||
|
||||
enum qse_rex_errnum_t
|
||||
{
|
||||
QSE_REX_ENOERR = 0,
|
||||
QSE_REX_ENOMEM,
|
||||
QSE_REX_ERECUR, /* recursion too deep */
|
||||
QSE_REX_ERPAREN, /* a right parenthesis is expected */
|
||||
QSE_REX_ERBRACKET, /* a right bracket is expected */
|
||||
QSE_REX_ERBRACE, /* a right brace is expected */
|
||||
QSE_REX_EUNBALPAR, /* unbalanced parenthesis */
|
||||
QSE_REX_ECOLON, /* a colon is expected */
|
||||
QSE_REX_ECRANGE, /* invalid character range */
|
||||
QSE_REX_ECCLASS, /* invalid character class */
|
||||
QSE_REX_EBRANGE, /* invalid boundary range */
|
||||
QSE_REX_EEND, /* unexpected end of the pattern */
|
||||
QSE_REX_EGARBAGE /* garbage after the pattern */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void* qse_buildrex (
|
||||
qse_mmgr_t* mmgr, qse_size_t depth,
|
||||
const qse_char_t* ptn, qse_size_t len, int* errnum);
|
||||
|
||||
int qse_matchrex (
|
||||
qse_mmgr_t* mmgr, qse_ccls_t* ccls, qse_size_t depth,
|
||||
void* code, int option,
|
||||
const qse_char_t* str, qse_size_t len,
|
||||
const qse_char_t** match_ptr, qse_size_t* match_len, int* errnum);
|
||||
|
||||
void qse_freerex (qse_mmgr_t* mmgr, void* code);
|
||||
|
||||
qse_bool_t qse_isemptyrex (void* code);
|
||||
|
||||
#if 0
|
||||
void qse_dprintrex (qse_rex_t* rex, void* rex);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
142
qse/include/qse/cmn/sio.h
Normal file
142
qse/include/qse/cmn/sio.h
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* $Id: sio.h,v 1.29 2005/12/26 05:38:24 bacon Ease $
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_SIO_H_
|
||||
#define _QSE_CMN_SIO_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
#include <qse/cmn/fio.h>
|
||||
#include <qse/cmn/tio.h>
|
||||
|
||||
enum qse_sio_open_flag_t
|
||||
{
|
||||
QSE_SIO_HANDLE = QSE_FIO_HANDLE,
|
||||
|
||||
QSE_SIO_READ = QSE_FIO_READ,
|
||||
QSE_SIO_WRITE = QSE_FIO_WRITE,
|
||||
QSE_SIO_APPEND = QSE_FIO_APPEND,
|
||||
|
||||
QSE_SIO_CREATE = QSE_FIO_CREATE,
|
||||
QSE_SIO_TRUNCATE = QSE_FIO_TRUNCATE,
|
||||
QSE_SIO_EXCLUSIVE = QSE_FIO_EXCLUSIVE,
|
||||
QSE_SIO_SYNC = QSE_FIO_SYNC,
|
||||
|
||||
QSE_SIO_NOSHRD = QSE_FIO_NOSHRD,
|
||||
QSE_SIO_NOSHWR = QSE_FIO_NOSHWR
|
||||
};
|
||||
|
||||
typedef qse_fio_off_t qse_sio_off_t;
|
||||
typedef qse_fio_hnd_t qse_sio_hnd_t;
|
||||
|
||||
typedef struct qse_sio_t qse_sio_t;
|
||||
|
||||
struct qse_sio_t
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
qse_fio_t fio;
|
||||
qse_tio_t tio;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern qse_sio_t* qse_sio_in;
|
||||
extern qse_sio_t* qse_sio_out;
|
||||
extern qse_sio_t* qse_sio_err;
|
||||
|
||||
qse_sio_t* qse_sio_open (
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t ext,
|
||||
const qse_char_t* file,
|
||||
int flags
|
||||
);
|
||||
|
||||
void qse_sio_close (
|
||||
qse_sio_t* sio
|
||||
);
|
||||
|
||||
qse_sio_t* qse_sio_init (
|
||||
qse_sio_t* sio,
|
||||
qse_mmgr_t* mmgr,
|
||||
const qse_char_t* file,
|
||||
int flags
|
||||
);
|
||||
|
||||
void qse_sio_fini (
|
||||
qse_sio_t* sio
|
||||
);
|
||||
|
||||
qse_fio_hnd_t qse_sio_gethandle (
|
||||
qse_sio_t* sio
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_flush (
|
||||
qse_sio_t* sio
|
||||
);
|
||||
|
||||
void qse_sio_purge (
|
||||
qse_sio_t* sio
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_getc (
|
||||
qse_sio_t* sio,
|
||||
qse_char_t* c
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_gets (
|
||||
qse_sio_t* sio,
|
||||
qse_char_t* buf,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_getsx (
|
||||
qse_sio_t* sio,
|
||||
qse_char_t* buf,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_getstr (
|
||||
qse_sio_t* sio,
|
||||
qse_str_t* buf
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_putc (
|
||||
qse_sio_t* sio,
|
||||
qse_char_t c
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_puts (
|
||||
qse_sio_t* sio,
|
||||
const qse_char_t* str
|
||||
);
|
||||
|
||||
qse_ssize_t qse_sio_putsx (
|
||||
qse_sio_t* sio,
|
||||
const qse_char_t* str,
|
||||
qse_size_t size
|
||||
);
|
||||
|
||||
#if 0
|
||||
qse_ssize_t qse_sio_putsn (qse_sio_t* sio, ...);
|
||||
qse_ssize_t qse_sio_putsxn (qse_sio_t* sio, ...);
|
||||
qse_ssize_t qse_sio_putsv (qse_sio_t* sio, qse_va_list ap);
|
||||
qse_ssize_t qse_sio_putsxv (qse_sio_t* sio, qse_va_list ap);
|
||||
|
||||
/* WARNING:
|
||||
* getpos may not return the desired postion because of the buffering
|
||||
*/
|
||||
int qse_sio_getpos (qse_sio_t* sio, qse_sio_off_t* pos);
|
||||
int qse_sio_setpos (qse_sio_t* sio, qse_sio_off_t pos);
|
||||
int qse_sio_rewind (qse_sio_t* sio);
|
||||
int qse_sio_movetoend (qse_sio_t* sio);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
582
qse/include/qse/cmn/sll.h
Normal file
582
qse/include/qse/cmn/sll.h
Normal file
@ -0,0 +1,582 @@
|
||||
/*
|
||||
* $Id: sll.h 223 2008-06-26 06:44:41Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_SLL_H_
|
||||
#define _QSE_CMN_SLL_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/****t* qse.cmn.sll/qse_sll_walk_t
|
||||
* NAME
|
||||
* qse_sll_walk_t - define return values for qse_sll_walker_t
|
||||
*
|
||||
* SEE ALSO
|
||||
* qse_sll_walk, qse_sll_walker_t
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
enum qse_sll_walk_t
|
||||
{
|
||||
QSE_SLL_WALK_STOP = 0,
|
||||
QSE_SLL_WALK_FORWARD = 1
|
||||
};
|
||||
/******/
|
||||
|
||||
typedef struct qse_sll_t qse_sll_t;
|
||||
typedef struct qse_sll_node_t qse_sll_node_t;
|
||||
typedef enum qse_sll_walk_t qse_sll_walk_t;
|
||||
|
||||
/****b* qse.cmn.sll/qse_sll_copier_t
|
||||
* NAME
|
||||
* qse_sll_copier_t - define a node contruction callback
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_copier_t defines a callback function for node construction.
|
||||
* A node is contructed when a user adds data to a list. The user can
|
||||
* define how the data to add can be maintained in the list. A singly
|
||||
* linked list not specified with any copiers stores the data pointer and
|
||||
* the data length into a node. A special copier QSE_SLL_COPIER_INLINE copies
|
||||
* the contents of the data a user provided into the node. You can use the
|
||||
* qse_sll_setcopier() function to change the copier.
|
||||
*
|
||||
* A copier should return the pointer to the copied data. If it fails to copy
|
||||
* data, it may return QSE_NULL. You need to set a proper freeer to free up
|
||||
* memory allocated for copy.
|
||||
*
|
||||
* SEE ALSO
|
||||
* qse_sll_setcopier, qse_sll_getcopier, QSE_SLL_COPIER
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef void* (*qse_sll_copier_t) (
|
||||
qse_sll_t* sll /* a map */,
|
||||
void* dptr /* the pointer to data to copy */,
|
||||
qse_size_t dlen /* the length of data to copy */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****b* qse.cmn.sll/qse_sll_freeer_t
|
||||
* NAME
|
||||
* qse_sll_freeer_t - define a node destruction callback
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef void (*qse_sll_freeer_t) (
|
||||
qse_sll_t* sll /* a map */,
|
||||
void* dptr /* the pointer to data to free */,
|
||||
qse_size_t dlen /* the length of data to free */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* qse.cmn.sll/qse_sll_comper_t
|
||||
* NAME
|
||||
* qse_sll_comper_t - define a data comparator
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_comper_t type defines a key comparator that is called when
|
||||
* the list needs to compare data. A singly linked list is created with a
|
||||
* default comparator that performs bitwise comparison.
|
||||
*
|
||||
* The comparator should return 0 if the data are the same and a non-zero
|
||||
* integer otherwise.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef int (*qse_sll_comper_t) (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
const void* dptr1 /* a data pointer */,
|
||||
qse_size_t dlen1 /* a data length */,
|
||||
const void* dptr2 /* a data pointer */,
|
||||
qse_size_t dlen2 /* a data length */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****b* qse.cmn.sll/qse_sll_walker_t
|
||||
* NAME
|
||||
* qse_sll_walker_t - define a list traversal callback for each node
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_walk() calls a callback function of the type qse_sll_walker_t
|
||||
* for each node until it returns QSE_SLL_WALK_STOP. The walker should return
|
||||
* QSE_SLL_WALK_FORWARD to let qse_sll_walk() continue visiting the next node.
|
||||
* The third parameter to qse_sll_walk() is passed to the walker as the third
|
||||
* parameter.
|
||||
*
|
||||
* SEE ALSO
|
||||
* qse_sll_walk, qse_sll_walk_t
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef qse_sll_walk_t (*qse_sll_walker_t) (
|
||||
qse_sll_t* sll /* a map */,
|
||||
qse_sll_node_t* node /* a visited node */,
|
||||
void* arg /* user-defined data */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****s* qse.cmn.sll/qse_sll_t
|
||||
* NAME
|
||||
* qse_sll_t - define a singly linked list
|
||||
*
|
||||
* DESCRPTION
|
||||
* The qse_sll_t type defines a singly lnked list.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
struct qse_sll_t
|
||||
{
|
||||
qse_mmgr_t* mmgr; /* memory manager */
|
||||
|
||||
qse_sll_copier_t copier; /* data copier */
|
||||
qse_sll_freeer_t freeer; /* data freeer */
|
||||
qse_sll_comper_t comper; /* data comparator */
|
||||
qse_byte_t scale; /* scale factor */
|
||||
|
||||
qse_size_t size; /* the number of nodes */
|
||||
qse_sll_node_t* head; /* the head node */
|
||||
qse_sll_node_t* tail; /* the tail node */
|
||||
};
|
||||
/******/
|
||||
|
||||
/****s* qse.cmn.sll/qse_sll_node_t
|
||||
* NAME
|
||||
* qse_sll_node_t - define a list node
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_node_t type defines a list node containing a data pointer and
|
||||
* and data length.
|
||||
*
|
||||
* SEE ALSO
|
||||
* QSE_SLL_DPTR, QSE_SLL_DLEN, QSE_SLL_NEXT
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
struct qse_sll_node_t
|
||||
{
|
||||
void* dptr; /* the pointer to data */
|
||||
qse_size_t dlen; /* the length of data */
|
||||
qse_sll_node_t* next; /* the pointer to the next node */
|
||||
};
|
||||
/******/
|
||||
|
||||
#define QSE_SLL_COPIER_SIMPLE ((qse_sll_copier_t)1)
|
||||
#define QSE_SLL_COPIER_INLINE ((qse_sll_copier_t)2)
|
||||
|
||||
#define QSE_SLL_MMGR(sll) ((sll)->mmgr)
|
||||
#define QSE_SLL_XTN(s) ((void*)(((qse_sll_t*)s) + 1))
|
||||
#define QSE_SLL_COPIER(sll) ((sll)->copier)
|
||||
#define QSE_SLL_FREEER(sll) ((sll)->freeer)
|
||||
#define QSE_SLL_COMPER(sll) ((sll)->comper)
|
||||
|
||||
#define QSE_SLL_HEAD(sll) ((sll)->head)
|
||||
#define QSE_SLL_TAIL(sll) ((sll)->tail)
|
||||
#define QSE_SLL_SIZE(sll) ((sll)->size)
|
||||
#define QSE_SLL_SCALE(sll) ((sll)->scale)
|
||||
|
||||
#define QSE_SLL_DPTR(node) ((node)->dptr)
|
||||
#define QSE_SLL_DLEN(node) ((node)->dlen)
|
||||
#define QSE_SLL_NEXT(node) ((node)->next)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_open
|
||||
* NAME
|
||||
* qse_sll_open - create a singly linked list with extension area
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_open() function creates an empty singly linked list.
|
||||
* If the memory manager mmgr is QSE_NULL, the function gets the default
|
||||
* memory manager with QSE_MMGR_GETMMGR() and uses it if it is not QSE_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.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_sll_open() function returns the pointer to a new singly linked
|
||||
* list on success and QSE_NULL on failure.
|
||||
*
|
||||
* NOTES
|
||||
* In the debug build, it fails an assertion if QSE_MMGR_GETMMGR() returns
|
||||
* QSE_NULL when QSE_NULL is passed as the first parameter. In the release
|
||||
* build, it returns QSE_NULL if such a thing happens.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_sll_t* qse_sll_open (
|
||||
qse_mmgr_t* mmgr /* memory manager */ ,
|
||||
qse_size_t ext /* size of extension area in bytes */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_close
|
||||
* NAME
|
||||
* qse_sll_close - destroy a singly linked list
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_close() function destroys a singly linked list freeing up
|
||||
* the memory.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_close (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_init
|
||||
* NAME
|
||||
* qse_sll_init - initialize a singly linked list
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_init() function initializes a singly linked list. The memory
|
||||
* should be allocated by a caller and be passed to it. The caller may declare
|
||||
* a static variable of the qse_sll_t type and pass its address. A memory
|
||||
* manager still needs to be passed for node manipulation later.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_sll_init() function returns the first parameter on success and
|
||||
* QSE_NULL on failure.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_sll_t* qse_sll_init (
|
||||
qse_sll_t* sll /* an uninitialized singly linked list */,
|
||||
qse_mmgr_t* mmgr /* a memory manager */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_fini
|
||||
* NAME
|
||||
* qse_sll_init - deinitialize a singly linked list
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_fini (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_getxtn
|
||||
* NAME
|
||||
* qse_sll_getxtn - get the pointer to the extension
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_getxtn() function returns the pointer to the extension.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void* qse_sll_getxtn (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_getmmgr
|
||||
* NAME
|
||||
* qse_sll_getmmgr - get the memory manager
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_mmgr_t* qse_sll_getmmgr (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_setmmgr
|
||||
* NAME
|
||||
* qse_sll_setmmgr - set the memory manager
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_setmmgr (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
qse_mmgr_t* mmgr /* a memory manager */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_getsize
|
||||
* NAME
|
||||
* qse_sll_getsize - get the number of nodes
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_getsize() function returns the number of the data nodes held
|
||||
* in a singly linked list.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_size_t qse_sll_getsize (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_getscale
|
||||
* NAME
|
||||
* qse_sll_getscale - get the scale factor
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_sll_getscale (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_setscale
|
||||
* NAME
|
||||
* qse_sll_setscale - set the scale factor
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_setscale() function sets the scale factor of the data length.
|
||||
* A scale factor determines the actual length of data in bytes. A singly
|
||||
* linked list created with a scale factor of 1. The scale factor should be
|
||||
* larger than 0 and less than 256.
|
||||
*
|
||||
* NOTES
|
||||
* It is a bad idea to change the scale factor when a sll is not empty.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_setscale (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
int scale /* a scale factor */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_getcopier
|
||||
* NAME
|
||||
* qse_sll_getfreeer - get the data copier
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_sll_copier_t qse_sll_getcopier (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_setcopier
|
||||
* NAME
|
||||
* qse_sll_setcopier - set a data copier
|
||||
*
|
||||
* DESCRIPTION
|
||||
* A special copier QSE_SLL_COPIER_INLINE is provided. This copier enables
|
||||
* you to copy the data inline to the internal node. No freeer is invoked
|
||||
* when the node is freeed.
|
||||
*
|
||||
* You may set the copier to QSE_NULL to perform no special operation
|
||||
* when the data pointer is rememebered.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_setcopier (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
qse_sll_copier_t copier /* a data copier */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_getfreeer
|
||||
* NAME
|
||||
* qse_sll_getfreeer - get the data freeer
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_sll_freeer_t qse_sll_getfreeer (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_setfreeer
|
||||
* NAME
|
||||
* qse_sll_setfreeer - set a data freeer
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The freeer is called when a node containing the element is destroyed.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_setfreeer (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
qse_sll_freeer_t freeer /* a data freeer */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_getcomper
|
||||
* NAME
|
||||
* qse_sll_getcomper - get the data comparator
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_sll_comper_t qse_sll_getcomper (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_setcomper
|
||||
* NAME
|
||||
* qse_sll_setcomper - set the data comparator
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_setcomper (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
qse_sll_comper_t comper /* a comparator */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_gethead
|
||||
* NAME
|
||||
* qse_sll_gethead - get the head node
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_sll_node_t* qse_sll_gethead (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_gettail
|
||||
* NAME
|
||||
* qse_sll_gettail - get the tail node
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_sll_node_t* qse_sll_gettail (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_search
|
||||
* NAME
|
||||
* qse_sll_search - find a node
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_search() function traverses a list to find a node containing
|
||||
* the same value as the the data pointer and length. The traversal begins
|
||||
* from the next node of the positional node. If the positional node is
|
||||
* QSE_NULL, the traversal begins from the head node.
|
||||
*
|
||||
* RETURN
|
||||
* The pointer to the node found. Otherwise, QSE_NULL.
|
||||
*
|
||||
* NOTES
|
||||
* No reverse search is provided because a reverse traversal can not be
|
||||
* achieved efficiently.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_sll_node_t* qse_sll_search (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
qse_sll_node_t* pos /* a positional node */,
|
||||
const void* dptr /* a data pointer */,
|
||||
qse_size_t dlen /* a data length */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_insert
|
||||
* NAME
|
||||
* qse_sll_insert - insert data to a new node
|
||||
*
|
||||
* DESCRIPTION
|
||||
* There is performance penalty unless the positional node is neither
|
||||
* the head node nor QSE_NULL. You should consider a different data
|
||||
* structure such as a doubly linked list if you need to insert data
|
||||
* into a random position.
|
||||
*
|
||||
* RETURN
|
||||
* The pointer to a new node on success and QSE_NULL on failure:w
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_sll_node_t* qse_sll_insert (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
qse_sll_node_t* pos /* a node before which a new node is inserted */,
|
||||
void* dptr /* the pointer to the data */,
|
||||
qse_size_t dlen /* the length of the data */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_delete
|
||||
* NAME
|
||||
* qse_sll_delete - delete a node
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_delete() function deletes a node.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_delete (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
qse_sll_node_t* pos /* a node to delete */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_clear
|
||||
* NAME
|
||||
* qse_sll_clear - delete all nodes
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_sll_clear() function empties a singly linked list by deletinng
|
||||
* all the nodes.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_clear (
|
||||
qse_sll_t* sll /* a singly linked list */
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_sll_node_t* qse_sll_pushhead (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
qse_sll_node_t* qse_sll_pushtail (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
|
||||
void qse_sll_pophead (
|
||||
qse_sll_t* sll
|
||||
);
|
||||
|
||||
void qse_sll_poptail (
|
||||
qse_sll_t* sll
|
||||
);
|
||||
|
||||
/****f* qse.cmn.sll/qse_sll_walk
|
||||
* NAME
|
||||
* qse_sll_walk - traverse s singly linked list
|
||||
*
|
||||
* DESCRIPTION
|
||||
* A singly linked list allows uni-directional in-order traversal.
|
||||
* The qse_sll_walk() function traverses a singly linkked list from its
|
||||
* head node down to its tail node as long as the walker function returns
|
||||
* QSE_SLL_WALK_FORWARD. A walker can return QSE_SLL_WALK_STOP to cause
|
||||
* immediate stop of traversal.
|
||||
*
|
||||
* For each node, the walker function is called and it is passed three
|
||||
* parameters: the singly linked list, the visiting node, and the
|
||||
* user-defined data passed as the third parameter in a call to the
|
||||
* qse_sll_walk() function.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_sll_walk (
|
||||
qse_sll_t* sll /* a singly linked list */,
|
||||
qse_sll_walker_t walker /* a user-defined walker function */,
|
||||
void* arg /* the pointer to user-defined data */
|
||||
);
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
476
qse/include/qse/cmn/str.h
Normal file
476
qse/include/qse/cmn/str.h
Normal file
@ -0,0 +1,476 @@
|
||||
/*
|
||||
* $Id: str.h 496 2008-12-15 09:56:48Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_STR_H_
|
||||
#define _QSE_CMN_STR_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/****o* qse.cmn.str/string
|
||||
* DESCRIPTION
|
||||
* <qse/cmn/str.h> defines various functions, types, macros to manipulate
|
||||
* strings.
|
||||
*
|
||||
* The qse_cstr_t type and the qse_xstr_t defined in ase/types.h helps you
|
||||
* dealing with a string pointer and length.
|
||||
*
|
||||
* #include <qse/cmn/str.h>
|
||||
*
|
||||
* EXAMPLES
|
||||
* void f (void)
|
||||
* {
|
||||
* }
|
||||
******
|
||||
*/
|
||||
|
||||
|
||||
#define QSE_STR_LEN(s) ((s)->len)
|
||||
#define QSE_STR_PTR(s) ((s)->ptr)
|
||||
#define QSE_STR_CAPA(s) ((s)->capa)
|
||||
#define QSE_STR_CHAR(s,idx) ((s)->ptr[idx])
|
||||
|
||||
#define QSE_STR_MMGR(s) ((s)->mmgr)
|
||||
#define QSE_STR_XTN(s) ((void*)(((qse_str_t*)s) + 1))
|
||||
#define QSE_STR_SIZER(s) ((s)->sizer)
|
||||
|
||||
typedef struct qse_str_t qse_str_t;
|
||||
typedef qse_size_t (*qse_str_sizer_t) (qse_str_t* data, qse_size_t hint);
|
||||
|
||||
struct qse_str_t
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
qse_str_sizer_t sizer;
|
||||
|
||||
qse_char_t* ptr;
|
||||
qse_size_t len;
|
||||
qse_size_t capa;
|
||||
};
|
||||
|
||||
/* int qse_chartonum (qse_char_t c, int base) */
|
||||
#define QSE_CHARTONUM(c,base) \
|
||||
((c>=QSE_T('0') && c<=QSE_T('9'))? ((c-QSE_T('0')<base)? (c-QSE_T('0')): base): \
|
||||
(c>=QSE_T('A') && c<=QSE_T('Z'))? ((c-QSE_T('A')+10<base)? (c-QSE_T('A')+10): base): \
|
||||
(c>=QSE_T('a') && c<=QSE_T('z'))? ((c-QSE_T('a')+10<base)? (c-QSE_T('a')+10): base): base)
|
||||
|
||||
/* qse_strtonum (const qse_char_t* nptr, qse_char_t** endptr, int base) */
|
||||
#define QSE_STRTONUM(value,nptr,endptr,base) \
|
||||
{ \
|
||||
int __ston_f = 0, __ston_v; \
|
||||
const qse_char_t* __ston_ptr = nptr; \
|
||||
for (;;) { \
|
||||
qse_char_t __ston_c = *__ston_ptr; \
|
||||
if (__ston_c == QSE_T(' ') || \
|
||||
__ston_c == QSE_T('\t')) { __ston_ptr++; continue; } \
|
||||
if (__ston_c == QSE_T('-')) { __ston_f++; __ston_ptr++; } \
|
||||
if (__ston_c == QSE_T('+')) { __ston_ptr++; } \
|
||||
break; \
|
||||
} \
|
||||
for (value = 0; (__ston_v = QSE_CHARTONUM(*__ston_ptr, base)) < base; __ston_ptr++) { \
|
||||
value = value * base + __ston_v; \
|
||||
} \
|
||||
if (endptr != QSE_NULL) *((const qse_char_t**)endptr) = __ston_ptr; \
|
||||
if (__ston_f > 0) value *= -1; \
|
||||
}
|
||||
|
||||
/* qse_strxtonum (const qse_char_t* nptr, qse_size_t len, qse_char_char** endptr, int base) */
|
||||
#define QSE_STRXTONUM(value,nptr,len,endptr,base) \
|
||||
{ \
|
||||
int __ston_f = 0, __ston_v; \
|
||||
const qse_char_t* __ston_ptr = nptr; \
|
||||
const qse_char_t* __ston_end = __ston_ptr + len; \
|
||||
value = 0; \
|
||||
while (__ston_ptr < __ston_end) { \
|
||||
qse_char_t __ston_c = *__ston_ptr; \
|
||||
if (__ston_c == QSE_T(' ') || __ston_c == QSE_T('\t')) { \
|
||||
__ston_ptr++; continue; \
|
||||
} \
|
||||
if (__ston_c == QSE_T('-')) { __ston_f++; __ston_ptr++; } \
|
||||
if (__ston_c == QSE_T('+')) { __ston_ptr++; } \
|
||||
break; \
|
||||
} \
|
||||
for (value = 0; __ston_ptr < __ston_end && \
|
||||
(__ston_v = QSE_CHARTONUM(*__ston_ptr, base)) != base; __ston_ptr++) { \
|
||||
value = value * base + __ston_v; \
|
||||
} \
|
||||
if (endptr != QSE_NULL) *((const qse_char_t**)endptr) = __ston_ptr; \
|
||||
if (__ston_f > 0) value *= -1; \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* basic string functions
|
||||
*/
|
||||
qse_size_t qse_strlen (const qse_char_t* str);
|
||||
qse_size_t qse_strbytes (const qse_char_t* str);
|
||||
|
||||
qse_size_t qse_strcpy (
|
||||
qse_char_t* buf, const qse_char_t* str);
|
||||
qse_size_t qse_strxcpy (
|
||||
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str);
|
||||
qse_size_t qse_strncpy (
|
||||
qse_char_t* buf, const qse_char_t* str, qse_size_t len);
|
||||
qse_size_t qse_strxncpy (
|
||||
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str, qse_size_t len);
|
||||
|
||||
qse_size_t qse_strxcat (
|
||||
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str);
|
||||
qse_size_t qse_strxncat (
|
||||
qse_char_t* buf, qse_size_t bsz, const qse_char_t* str, qse_size_t len);
|
||||
|
||||
int qse_strcmp (const qse_char_t* s1, const qse_char_t* s2);
|
||||
int qse_strxcmp (const qse_char_t* s1, qse_size_t len1, const qse_char_t* s2);
|
||||
int qse_strxncmp (
|
||||
const qse_char_t* s1, qse_size_t len1,
|
||||
const qse_char_t* s2, qse_size_t len2);
|
||||
|
||||
int qse_strcasecmp (
|
||||
const qse_char_t* s1, const qse_char_t* s2, qse_ccls_t* ccls);
|
||||
|
||||
/****f* qse.cmn.str/qse_strxncasecmp
|
||||
* NAME
|
||||
* qse_strxncasecmp - compare strings ignoring case
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_strxncasecmp() function compares characters at the same position
|
||||
* in each string after converting them to the same case temporarily.
|
||||
* It accepts two strings and a character class handler. A string is
|
||||
* represented by its beginning pointer and length. You can write your own
|
||||
* character class handler or use QSE_CCLS_GETDFL() to get the default
|
||||
* character class handler.
|
||||
*
|
||||
* For two strings to be equal, they need to have the same length and all
|
||||
* characters in the first string should be equal to their counterpart in the
|
||||
* second string.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_strxncasecmp() returns 0 if two strings are equal, a positive
|
||||
* number if the first string is larger, -1 if the second string is larger.
|
||||
*
|
||||
* EXAMPLES
|
||||
* qse_strxncasecmp (QSE_T("foo"), 3, QSE_T("FoO"), 3, QSE_CCLS_GETDFL());
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_strxncasecmp (
|
||||
const qse_char_t* s1 /* the pointer to the first string */,
|
||||
qse_size_t len1 /* the length of the first string */,
|
||||
const qse_char_t* s2 /* the pointer to the second string */,
|
||||
qse_size_t len2 /* the length of the second string */,
|
||||
qse_ccls_t* ccls /* character class handler */
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_char_t* qse_strdup (const qse_char_t* str, qse_mmgr_t* mmgr);
|
||||
qse_char_t* qse_strxdup (
|
||||
const qse_char_t* str, qse_size_t len, qse_mmgr_t* mmgr);
|
||||
qse_char_t* qse_strxdup2 (
|
||||
const qse_char_t* str1, qse_size_t len1,
|
||||
const qse_char_t* str2, qse_size_t len2, qse_mmgr_t* mmgr);
|
||||
|
||||
qse_char_t* qse_strstr (const qse_char_t* str, const qse_char_t* sub);
|
||||
qse_char_t* qse_strxstr (
|
||||
const qse_char_t* str, qse_size_t size, const qse_char_t* sub);
|
||||
qse_char_t* qse_strxnstr (
|
||||
const qse_char_t* str, qse_size_t strsz,
|
||||
const qse_char_t* sub, qse_size_t subsz);
|
||||
|
||||
qse_char_t* qse_strchr (const qse_char_t* str, qse_cint_t c);
|
||||
qse_char_t* qse_strxchr (const qse_char_t* str, qse_size_t len, qse_cint_t c);
|
||||
qse_char_t* qse_strrchr (const qse_char_t* str, qse_cint_t c);
|
||||
qse_char_t* qse_strxrchr (const qse_char_t* str, qse_size_t len, qse_cint_t c);
|
||||
|
||||
/* Checks if a string begins with a substring */
|
||||
qse_char_t* qse_strbeg (const qse_char_t* str, const qse_char_t* sub);
|
||||
qse_char_t* qse_strxbeg (
|
||||
const qse_char_t* str, qse_size_t len, const qse_char_t* sub);
|
||||
qse_char_t* qse_strnbeg (
|
||||
const qse_char_t* str, const qse_char_t* sub, qse_size_t len);
|
||||
qse_char_t* qse_strxnbeg (
|
||||
const qse_char_t* str, qse_size_t len1,
|
||||
const qse_char_t* sub, qse_size_t len2);
|
||||
|
||||
/* Checks if a string ends with a substring */
|
||||
qse_char_t* qse_strend (const qse_char_t* str, const qse_char_t* sub);
|
||||
qse_char_t* qse_strxend (
|
||||
const qse_char_t* str, qse_size_t len, const qse_char_t* sub);
|
||||
qse_char_t* qse_strnend (
|
||||
const qse_char_t* str, const qse_char_t* sub, qse_size_t len);
|
||||
qse_char_t* qse_strxnend (
|
||||
const qse_char_t* str, qse_size_t len1,
|
||||
const qse_char_t* sub, qse_size_t len2);
|
||||
|
||||
/*
|
||||
* string conversion
|
||||
*/
|
||||
int qse_strtoi (const qse_char_t* str);
|
||||
long qse_strtol (const qse_char_t* str);
|
||||
unsigned int qse_strtoui (const qse_char_t* str);
|
||||
unsigned long qse_strtoul (const qse_char_t* str);
|
||||
|
||||
int qse_strxtoi (const qse_char_t* str, qse_size_t len);
|
||||
long qse_strxtol (const qse_char_t* str, qse_size_t len);
|
||||
unsigned int qse_strxtoui (const qse_char_t* str, qse_size_t len);
|
||||
unsigned long qse_strxtoul (const qse_char_t* str, qse_size_t len);
|
||||
|
||||
qse_int_t qse_strtoint (const qse_char_t* str);
|
||||
qse_long_t qse_strtolong (const qse_char_t* str);
|
||||
qse_uint_t qse_strtouint (const qse_char_t* str);
|
||||
qse_ulong_t qse_strtoulong (const qse_char_t* str);
|
||||
|
||||
qse_int_t qse_strxtoint (const qse_char_t* str, qse_size_t len);
|
||||
qse_long_t qse_strxtolong (const qse_char_t* str, qse_size_t len);
|
||||
qse_uint_t qse_strxtouint (const qse_char_t* str, qse_size_t len);
|
||||
qse_ulong_t qse_strxtoulong (const qse_char_t* str, qse_size_t len);
|
||||
|
||||
qse_str_t* qse_str_open (
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t ext,
|
||||
qse_size_t capa
|
||||
);
|
||||
|
||||
void qse_str_close (
|
||||
qse_str_t* str
|
||||
);
|
||||
|
||||
/*
|
||||
* If capa is 0, it doesn't allocate the buffer in advance.
|
||||
*/
|
||||
qse_str_t* qse_str_init (
|
||||
qse_str_t* str,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t capa
|
||||
);
|
||||
|
||||
void qse_str_fini (
|
||||
qse_str_t* str
|
||||
);
|
||||
|
||||
/****f* qse.cmn.str/qse_str_yield
|
||||
* NAME
|
||||
* qse_str_yield - yield the buffer
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_str_yield() function assigns the buffer to an variable of the
|
||||
* qse_xstr_t type and recreate a new buffer of the new_capa capacity.
|
||||
* The function fails if it fails to allocate a new buffer.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_str_yield() function returns 0 on success, and -1 on failure.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_str_yield (
|
||||
qse_str_t* str /* a dynamic string */,
|
||||
qse_xstr_t* buf /* the pointer to a qse_xstr_t variable */,
|
||||
int new_capa /* new capacity in number of characters */
|
||||
);
|
||||
/******/
|
||||
|
||||
void* qse_str_getxtn (
|
||||
qse_str_t* str
|
||||
);
|
||||
|
||||
qse_mmgr_t* qse_str_getmmgr (
|
||||
qse_str_t* str
|
||||
);
|
||||
|
||||
void qse_str_setmmgr (
|
||||
qse_str_t* str,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: get the sizer
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_str_getsizer() function returns the sizer specified.
|
||||
*
|
||||
* RETURNS: a sizer function set or QSE_NULL if no sizer is set.
|
||||
*/
|
||||
qse_str_sizer_t qse_str_getsizer (
|
||||
qse_str_t* str /* a dynamic string */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: specify a sizer
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_str_setsizer() function specify a new sizer for a dynamic string.
|
||||
* With no sizer specified, the dynamic string doubles the current buffer
|
||||
* when it needs to increase its size. The sizer function is passed a dynamic
|
||||
* string and the minimum capacity required to hold data after resizing.
|
||||
* The string is truncated if the sizer function returns a smaller number
|
||||
* than the hint passed.
|
||||
*/
|
||||
void qse_str_setsizer (
|
||||
qse_str_t* str /* a dynamic string */,
|
||||
qse_str_sizer_t sizer /* a sizer function */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: get capacity
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_str_getcapa() function returns the current capacity.
|
||||
* You may use QSE_STR_CAPA(str) macro for performance sake.
|
||||
*
|
||||
* RETURNS: the current capacity in number of characters.
|
||||
*/
|
||||
qse_size_t qse_str_getcapa (
|
||||
qse_str_t* str /* a dynamic string */
|
||||
);
|
||||
|
||||
/*
|
||||
* NAME: set new capacity
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* The qse_str_setcapa() function set new capacity. If the new capacity
|
||||
* is smaller than the old, the overflowing characters are removed from
|
||||
* from the buffer.
|
||||
*
|
||||
* RETURNS: -1 on failure, a new capacity on success
|
||||
*/
|
||||
qse_size_t qse_str_setcapa (
|
||||
qse_str_t* str /* a dynamic string */,
|
||||
qse_size_t capa /* a new capacity */
|
||||
);
|
||||
|
||||
void qse_str_clear (
|
||||
qse_str_t* str
|
||||
);
|
||||
|
||||
void qse_str_swap (
|
||||
qse_str_t* str,
|
||||
qse_str_t* str2
|
||||
);
|
||||
|
||||
qse_size_t qse_str_cpy (
|
||||
qse_str_t* str,
|
||||
const qse_char_t* s
|
||||
);
|
||||
|
||||
qse_size_t qse_str_ncpy (
|
||||
qse_str_t* str,
|
||||
const qse_char_t* s,
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
qse_size_t qse_str_cat (
|
||||
qse_str_t* str,
|
||||
const qse_char_t* s
|
||||
);
|
||||
|
||||
qse_size_t qse_str_ncat (
|
||||
qse_str_t* str,
|
||||
const qse_char_t* s,
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
qse_size_t qse_str_ccat (
|
||||
qse_str_t* str,
|
||||
qse_char_t c
|
||||
);
|
||||
|
||||
qse_size_t qse_str_nccat (
|
||||
qse_str_t* str,
|
||||
qse_char_t c,
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
|
||||
qse_size_t qse_mbstowcs (
|
||||
const qse_mchar_t* mbs,
|
||||
qse_wchar_t* wcs,
|
||||
qse_size_t* wcslen
|
||||
);
|
||||
|
||||
/****f* qse.cmn.str/qse_mbsntowcsn
|
||||
* NAME
|
||||
* qse_mbsntowcsn - convert a multibyte string to a wide character string
|
||||
*
|
||||
* RETURN
|
||||
* The qse_mbstowcs() function returns the number of bytes handled.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_size_t qse_mbsntowcsn (
|
||||
const qse_mchar_t* mbs,
|
||||
qse_size_t mbslen,
|
||||
qse_wchar_t* wcs,
|
||||
qse_size_t* wcslen
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.str/qse_wcstombs
|
||||
* NAME
|
||||
* qse_wcstombs - convert a wide character string to a multibyte string.
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_wcstombs() function converts a null-terminated wide character
|
||||
* string to a multibyte string and stores it into the buffer pointed to
|
||||
* by mbs. The pointer to a variable holding the buffer length should be
|
||||
* passed to the function as the third parameter. After conversion, it holds
|
||||
* the length of the multibyte string excluding the terminating-null.
|
||||
* It may not null-terminate the resulting multibyte string if the buffer
|
||||
* is not large enough.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_wcstombs() function returns the number of wide characters handled.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_size_t qse_wcstombs (
|
||||
const qse_wchar_t* wcs,
|
||||
qse_mchar_t* mbs,
|
||||
qse_size_t* mbslen
|
||||
);
|
||||
|
||||
/****f* qse.cmn.str/qse_wcsntombsn
|
||||
* NAME
|
||||
* qse_wcstombs - convert a wide character string to a multibyte string
|
||||
*
|
||||
* RETURN
|
||||
* The qse_wcstombs() function returns the number of wide characters handled.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_size_t qse_wcsntombsn (
|
||||
const qse_wchar_t* wcs,
|
||||
qse_size_t wcslen,
|
||||
qse_mchar_t* mbs,
|
||||
qse_size_t* mbslen
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn.str/qse_wcstombs_strict
|
||||
* NAME
|
||||
* qse_wcstombs_strict - convert a wide character string to a multibyte string.
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_wcstombs_strict() function performs the same as the qse_wcsmbs()
|
||||
* function except that it returns an error if it can't fully convert the
|
||||
* input string and/or the buffer is not large enough.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_wcstombs_strict() function returns 0 on success and -1 on failure.
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_wcstombs_strict (
|
||||
const qse_wchar_t* wcs,
|
||||
qse_mchar_t* mbs,
|
||||
qse_size_t mbslen
|
||||
);
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
134
qse/include/qse/cmn/time.h
Normal file
134
qse/include/qse/cmn/time.h
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_TIME_H_
|
||||
#define _QSE_CMN_TIME_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
#define QSE_EPOCH_YEAR ((qse_ntime_t)1970)
|
||||
#define QSE_EPOCH_MON ((qse_ntime_t)1)
|
||||
#define QSE_EPOCH_DAY ((qse_ntime_t)1)
|
||||
#define QSE_EPOCH_WDAY ((qse_ntime_t)4)
|
||||
|
||||
#define QSE_DAY_IN_WEEK ((qse_ntime_t)7)
|
||||
#define QSE_MON_IN_YEAR ((qse_ntime_t)12)
|
||||
#define QSE_HOUR_IN_DAY ((qse_ntime_t)24)
|
||||
#define QSE_MIN_IN_HOUR ((qse_ntime_t)60)
|
||||
#define QSE_MIN_IN_DAY (QSE_MIN_IN_HOUR * QSE_HOUR_IN_DAY)
|
||||
#define QSE_SEC_IN_MIN ((qse_ntime_t)60)
|
||||
#define QSE_SEC_IN_HOUR (QSE_SEC_IN_MIN * QSE_MIN_IN_HOUR)
|
||||
#define QSE_SEC_IN_DAY (QSE_SEC_IN_MIN * QSE_MIN_IN_DAY)
|
||||
#define QSE_MSEC_IN_SEC ((qse_ntime_t)1000)
|
||||
#define QSE_MSEC_IN_MIN (QSE_MSEC_IN_SEC * QSE_SEC_IN_MIN)
|
||||
#define QSE_MSEC_IN_HOUR (QSE_MSEC_IN_SEC * QSE_SEC_IN_HOUR)
|
||||
#define QSE_MSEC_IN_DAY (QSE_MSEC_IN_SEC * QSE_SEC_IN_DAY)
|
||||
|
||||
#define QSE_USEC_IN_MSEC ((qse_ntime_t)1000)
|
||||
#define QSE_NSEC_IN_USEC ((qse_ntime_t)1000)
|
||||
#define QSE_USEC_IN_SEC ((qse_ntime_t)QSE_USEC_IN_MSEC * QSE_MSEC_IN_SEC)
|
||||
|
||||
#define QSE_IS_LEAPYEAR(year) (!((year)%4) && (((year)%100) || !((year)%400)))
|
||||
#define QSE_DAY_IN_YEAR(year) (QSE_IS_LEAPYEAR(year)? 366: 365)
|
||||
|
||||
/* number of milliseconds since the Epoch (00:00:00 UTC, Jan 1, 1970) */
|
||||
typedef qse_long_t qse_ntime_t;
|
||||
typedef struct qse_btime_t qse_btime_t;
|
||||
|
||||
struct qse_btime_t
|
||||
{
|
||||
int sec; /* 0-61 */
|
||||
int min; /* 0-59 */
|
||||
int hour; /* 0-23 */
|
||||
int mday; /* 1-31 */
|
||||
int mon; /* 0(jan)-11(dec) */
|
||||
int year; /* the number of years since 1900 */
|
||||
int wday; /* 0(sun)-6(sat) */
|
||||
int yday; /* 0(jan 1) to 365 */
|
||||
int isdst;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****f* qse.cmn/qse_gettime
|
||||
* NAME
|
||||
* qse_gettime - get the current time
|
||||
*
|
||||
* SYNPOSIS
|
||||
*/
|
||||
int qse_gettime (
|
||||
qse_ntime_t* nt
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn/qse_settime
|
||||
* NAME
|
||||
* qse_settime - set the current time
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_settime (
|
||||
qse_ntime_t nt
|
||||
);
|
||||
/******/
|
||||
|
||||
|
||||
/****f* qse.cmn/qse_gmtime
|
||||
* NAME
|
||||
* qse_gmtime - convert numeric time to broken-down time
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
void qse_gmtime (
|
||||
qse_ntime_t nt,
|
||||
qse_btime_t* bt
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn/qse_localtime
|
||||
* NAME
|
||||
* qse_localtime - convert numeric time to broken-down time
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_localtime (
|
||||
qse_ntime_t nt,
|
||||
qse_btime_t* bt
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn/qse_mktime
|
||||
* NAME
|
||||
* qse_mktime - convert broken-down time to numeric time
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
int qse_mktime (
|
||||
const qse_btime_t* bt,
|
||||
qse_ntime_t* nt
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* qse.cmn/qse_strftime
|
||||
* NAME
|
||||
* qse_strftime - format time
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
qse_size_t qse_strftime (
|
||||
qse_char_t* buf,
|
||||
qse_size_t size,
|
||||
const qse_char_t* fmt,
|
||||
qse_btime_t* bt
|
||||
);
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
299
qse/include/qse/cmn/tio.h
Normal file
299
qse/include/qse/cmn/tio.h
Normal file
@ -0,0 +1,299 @@
|
||||
/*
|
||||
* $Id: tio.h,v 1.19 2006/01/01 13:50:24 bacon Exp $
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CMN_TIO_H_
|
||||
#define _QSE_CMN_TIO_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
#include <qse/cmn/str.h>
|
||||
|
||||
enum
|
||||
{
|
||||
QSE_TIO_ENOERR = 0,
|
||||
QSE_TIO_ENOMEM, /* out of memory */
|
||||
QSE_TIO_ENOSPC, /* no more space */
|
||||
QSE_TIO_EILSEQ, /* illegal sequence */
|
||||
QSE_TIO_EICSEQ, /* incomplete sequence */
|
||||
QSE_TIO_EILCHR, /* illegal character */
|
||||
QSE_TIO_ENOINF, /* no input function attached */
|
||||
QSE_TIO_EINPUT, /* input function returned an error */
|
||||
QSE_TIO_EINPOP, /* input function failed to open */
|
||||
QSE_TIO_EINPCL, /* input function failed to close */
|
||||
QSE_TIO_ENOUTF, /* no output function attached */
|
||||
QSE_TIO_EOUTPT, /* output function returned an error */
|
||||
QSE_TIO_EOUTOP, /* output function failed to open */
|
||||
QSE_TIO_EOUTCL /* output function failed to close */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/* the size of input buffer should be at least equal to or greater
|
||||
* than the maximum sequence length of the qse_mchar_t string.
|
||||
* (i.e. 6 for utf8)
|
||||
*/
|
||||
QSE_TIO_MAX_INBUF_LEN = 4096,
|
||||
QSE_TIO_MAX_OUTBUF_LEN = 4096
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
QSE_TIO_IO_OPEN,
|
||||
QSE_TIO_IO_CLOSE,
|
||||
QSE_TIO_IO_DATA
|
||||
};
|
||||
|
||||
|
||||
#define QSE_TIO_MMGR(tio) ((tio)->mmgr)
|
||||
#define QSE_TIO_XTN(s) ((void*)(((qse_tio_t*)s) + 1))
|
||||
#define QSE_TIO_ERRNUM(tio) ((tio)->errnum)
|
||||
|
||||
/*
|
||||
* TYPE: qse_tio_t
|
||||
* Defines the tio type
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* <qse_tio_t> defines a generic type for text-based IO. When qse_char_t is
|
||||
* qse_mchar_t, it handles any byte streams. When qse_char_t is qse_wchar_t,
|
||||
* it handles utf-8 byte streams.
|
||||
*/
|
||||
typedef struct qse_tio_t qse_tio_t;
|
||||
|
||||
/*
|
||||
* TYPE: qse_tio_io_t
|
||||
* Defines a user-defines IO handler
|
||||
*/
|
||||
typedef qse_ssize_t (*qse_tio_io_t) (
|
||||
int cmd, void* arg, void* data, qse_size_t size);
|
||||
|
||||
struct qse_tio_t
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
int errnum;
|
||||
|
||||
/* io functions */
|
||||
qse_tio_io_t input_func;
|
||||
qse_tio_io_t output_func;
|
||||
void* input_arg;
|
||||
void* output_arg;
|
||||
|
||||
/* for housekeeping */
|
||||
int input_status;
|
||||
qse_size_t inbuf_curp;
|
||||
qse_size_t inbuf_len;
|
||||
qse_size_t outbuf_len;
|
||||
|
||||
qse_mchar_t inbuf[QSE_TIO_MAX_INBUF_LEN];
|
||||
qse_mchar_t outbuf[QSE_TIO_MAX_OUTBUF_LEN];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_open
|
||||
*/
|
||||
qse_tio_t* qse_tio_open (
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t ext
|
||||
);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_close
|
||||
*/
|
||||
int qse_tio_close (
|
||||
qse_tio_t* tio
|
||||
);
|
||||
|
||||
qse_tio_t* qse_tio_init (
|
||||
qse_tio_t* tip,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
int qse_tio_fini (
|
||||
qse_tio_t* tio
|
||||
);
|
||||
|
||||
void* qse_tio_getxtn (
|
||||
qse_tio_t* tio
|
||||
);
|
||||
|
||||
qse_mmgr_t* qse_tio_getmmgr (
|
||||
qse_tio_t* tio
|
||||
);
|
||||
|
||||
void qse_tio_setmmgr (
|
||||
qse_tio_t* tio,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_geterrnum
|
||||
* Returns an error code
|
||||
*
|
||||
* PARAMETERS:
|
||||
* grep - a grep object
|
||||
*
|
||||
* RETURNS:
|
||||
* Error code set by the last tio function called
|
||||
*/
|
||||
int qse_tio_geterrnum (qse_tio_t* tio);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_geterrstr
|
||||
* Translates an error code to a string
|
||||
*
|
||||
* PARAMETERS:
|
||||
* tio - a tio object
|
||||
*
|
||||
* RETURNS:
|
||||
* A pointer to a constant string describing the last error occurred
|
||||
*/
|
||||
const qse_char_t* qse_tio_geterrstr (qse_tio_t* tio);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_attachin
|
||||
* Attaches an input handler function
|
||||
*
|
||||
* PARAMETERS:
|
||||
* tio - a tio object
|
||||
* input - input handler function
|
||||
* arg - user data to be passed to the input handler
|
||||
*
|
||||
* RETURNS:
|
||||
* 0 on success, -1 on failure
|
||||
*/
|
||||
int qse_tio_attachin (
|
||||
qse_tio_t* tio,
|
||||
qse_tio_io_t input,
|
||||
void* arg
|
||||
);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_detachin
|
||||
* Detaches an input handler function
|
||||
*
|
||||
* PARAMETERS:
|
||||
* tio - a tio object
|
||||
*
|
||||
* RETURNS:
|
||||
* 0 on success, -1 on failure
|
||||
*/
|
||||
int qse_tio_detachin (
|
||||
qse_tio_t* tio
|
||||
);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_attachout
|
||||
* Attaches an output handler function
|
||||
*
|
||||
* PARAMETERS:
|
||||
* tio - a tio object
|
||||
* output - output handler function
|
||||
* arg - user data to be passed to the output handler
|
||||
*
|
||||
* RETURNS:
|
||||
* 0 on success, -1 on failure
|
||||
*/
|
||||
int qse_tio_attachout (
|
||||
qse_tio_t* tio,
|
||||
qse_tio_io_t output,
|
||||
void* arg
|
||||
);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_detachout
|
||||
* Detaches an output handler function
|
||||
*
|
||||
* PARAMETERS:
|
||||
* tio - a tio object
|
||||
*
|
||||
* RETURNS:
|
||||
* 0 on success, -1 on failure
|
||||
*/
|
||||
int qse_tio_detachout (
|
||||
qse_tio_t* tio
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_flush
|
||||
* Flushes the output buffer
|
||||
*
|
||||
* PARAMETERS:
|
||||
* tio - a tio object
|
||||
*
|
||||
* RETURNS:
|
||||
* Number of bytes written on success, -1 on failure
|
||||
*/
|
||||
qse_ssize_t qse_tio_flush (qse_tio_t* tio);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_purge
|
||||
* Erases all input and output buffered
|
||||
*
|
||||
* PARAMETERS:
|
||||
* tio - a tio object
|
||||
*
|
||||
*/
|
||||
void qse_tio_purge (qse_tio_t* tio);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_getc
|
||||
* Reads a single character
|
||||
*/
|
||||
qse_ssize_t qse_tio_getc (qse_tio_t* tio, qse_char_t* c);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_gets
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* <qse_tio_gets> inserts a terminating null if there is a room
|
||||
*/
|
||||
qse_ssize_t qse_tio_gets (qse_tio_t* tio, qse_char_t* buf, qse_size_t size);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_getsx
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* <qse_tio_getsx> doesn't insert a terminating null character
|
||||
*/
|
||||
qse_ssize_t qse_tio_getsx (qse_tio_t* tio, qse_char_t* buf, qse_size_t size);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_getstr
|
||||
*/
|
||||
qse_ssize_t qse_tio_getstr (qse_tio_t* tio, qse_str_t* buf);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_putc
|
||||
*/
|
||||
qse_ssize_t qse_tio_putc (qse_tio_t* tio, qse_char_t c);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_puts
|
||||
*/
|
||||
qse_ssize_t qse_tio_puts (qse_tio_t* tio, const qse_char_t* str);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_putsx
|
||||
*/
|
||||
qse_ssize_t qse_tio_putsx (qse_tio_t* tio, const qse_char_t* str, qse_size_t size);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_putsn
|
||||
*/
|
||||
qse_ssize_t qse_tio_putsn (qse_tio_t* tio, ...);
|
||||
|
||||
/*
|
||||
* FUNCTION: qse_tio_putsxn
|
||||
*/
|
||||
qse_ssize_t qse_tio_putsxn (qse_tio_t* tio, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user