added more documentation

This commit is contained in:
2009-02-02 04:12:49 +00:00
parent 6affaf4d37
commit 0836d3e319
26 changed files with 520 additions and 631 deletions

View File

@ -91,7 +91,7 @@ struct qse_fio_t
/* note that qse_fio_t is instantiated statically
* in sio.c. make sure that you update the static instantiation
* when you change the structure of qse_fio_t */
QSE_DEFINE_STD_FIELDS (fio)
QSE_DEFINE_COMMON_FIELDS (fio)
int errnum;
qse_fio_hnd_t handle;
qse_tio_t* tio;
@ -112,9 +112,9 @@ struct qse_fio_lck_t
extern "C" {
#endif
QSE_DEFINE_STD_FUNCTIONS (fio)
QSE_DEFINE_COMMON_FUNCTIONS (fio)
/****f* qse.fio/qse_fio_open
/****f* qse.cmn.fio/qse_fio_open
* NAME
* qse_fio_open - open a file
*
@ -133,7 +133,7 @@ qse_fio_t* qse_fio_open (
);
/******/
/****f* qse.fio/qse_fio_close
/****f* qse.cmn.fio/qse_fio_close
* NAME
* qse_fio_close - close a file
*

View File

@ -25,7 +25,7 @@
/****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
* are added.
*
* #include <qse/cmn/lda.h>
******
@ -54,9 +54,6 @@ typedef enum qse_lda_walk_t qse_lda_walk_t;
#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)
@ -178,7 +175,7 @@ typedef qse_lda_walk_t (*qse_lda_walker_t) (
*/
struct qse_lda_t
{
qse_mmgr_t* mmgr; /* memory manager */
QSE_DEFINE_COMMON_FIELDS (lda)
qse_lda_copier_t copier; /* data copier */
qse_lda_freeer_t freeer; /* data freeer */
@ -209,6 +206,8 @@ struct qse_lda_node_t
extern "C" {
#endif
QSE_DEFINE_COMMON_FUNCTIONS (lda)
/****f* qse.cmn.lda/qse_lda_open
* NAME
* qse_lda_open - create a linear dynamic array
@ -257,43 +256,6 @@ void qse_lda_fini (
);
/******/
/****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 */
);

View File

@ -28,11 +28,6 @@
* chained under the same bucket.
*
* #include <qse/cmn/map.h>
*
* EXAMPLES
* void f (void)
* {
* }
******
*/
@ -190,15 +185,16 @@ struct qse_map_pair_t
*/
struct qse_map_t
{
qse_mmgr_t* mmgr;
QSE_DEFINE_COMMON_FIELDS (map)
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_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;
@ -213,10 +209,8 @@ struct qse_map_t
/****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)
@ -234,9 +228,6 @@ struct qse_map_t
#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])
@ -260,33 +251,31 @@ struct qse_map_t
extern "C" {
#endif
QSE_DEFINE_COMMON_FUNCTIONS (map)
/****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.
*
* 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 */
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 */
);
/******/
@ -294,10 +283,8 @@ qse_map_t* qse_map_open (
/****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 (
@ -306,29 +293,16 @@ void qse_map_close (
/******/
qse_map_t* qse_map_init (
qse_map_t* map,
qse_map_t* map,
qse_mmgr_t* mmgr,
qse_size_t capa,
int factor
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 */
@ -450,58 +424,43 @@ void qse_map_setsizer (
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 */
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 */,
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 */,
void* vptr /* the pointer to a value */,
qse_size_t vlen /* the length of the value in bytes */
);
/******/
@ -509,23 +468,20 @@ qse_map_pair_t* qse_map_upsert (
/****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 */,
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 */,
void* vptr /* the pointer to a value */,
qse_size_t vlen /* the length of the value in bytes */
);
/******/

View File

@ -25,31 +25,43 @@
typedef struct qse_opt_t qse_opt_t;
typedef struct qse_opt_lng_t qse_opt_lng_t;
/****t* qse.cmn.opt/qse_opt_lng_t
* NAME
* qse_opt_lng_t - define a long option
* SYNOPSIS
*/
struct qse_opt_lng_t
{
const qse_char_t* str;
qse_cint_t val;
qse_cint_t val;
};
/*****/
/****t* qse.cmn.opt/qse_opt_t
* NAME
* qse_opt_t - define a command line option table
* SYNOPSIS
*/
struct qse_opt_t
{
/* input */
const qse_char_t* str; /* option string */
qse_opt_lng_t* lng; /* long options */
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 */
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 */
int ind; /* index into parent argv vector */
/* input + output - internal*/
qse_char_t* cur;
qse_char_t* cur;
};
/******/
#ifdef __cplusplus
extern "C" {
@ -57,8 +69,10 @@ extern "C" {
/****f* qse.cmn.opt/qse_getopt
* NAME
* qse_getopt - parse command line options
*
* qse_getopt - process command line options
* DESCRIPTION
* The qse_getopt() function returns QSE_CHAR_EOF when it finishes processing
* command line options. The return values of QSE_T('?') indicates an error.
* SYNOPSIS
*/
qse_cint_t qse_getopt (

View File

@ -101,15 +101,21 @@ struct qse_pio_pin_t
qse_pio_t* self;
};
/****s* cmn/qse_pio_t
* NAME
* qse_pio_t - define an pipe IO type
* SYNOPSIS
*/
struct qse_pio_t
{
QSE_DEFINE_STD_FIELDS(pio)
QSE_DEFINE_COMMON_FIELDS(pio)
int flags;
qse_pio_err_t errnum;
qse_pio_pid_t child;
qse_pio_pin_t pin[3];
};
/*****/
#define QSE_PIO_ERRNUM(pio) ((pio)->errnum)
#define QSE_PIO_FLAGS(pio) ((pio)->flags)
@ -120,9 +126,9 @@ struct qse_pio_t
extern "C" {
#endif
QSE_DEFINE_STD_FUNCTIONS (pio)
QSE_DEFINE_COMMON_FUNCTIONS (pio)
/****f* qse.cmn.pio/qse_pio_open
/****f* cmn/qse_pio_open
* NAME
* qse_pio_open - open pipes to a child process
*
@ -140,7 +146,7 @@ qse_pio_t* qse_pio_open (
);
/******/
/****f* qse.cmn.pio/qse_pio_close
/****f* cmn/qse_pio_close
* NAME
* qse_pio_close - close pipes to a child process
*
@ -151,7 +157,7 @@ void qse_pio_close (
);
/******/
/****f* qse.cmn/pio/qse_pio_init
/****f* cmn/qse_pio_init
* NAME
* qse_pio_init - initialize pipes to a child process
*
@ -165,7 +171,7 @@ qse_pio_t* qse_pio_init (
);
/******/
/****f* qse.cmn/pio/qse_pio_fini
/****f* cmn/qse_pio_fini
* NAME
* qse_pio_fini - finalize pipes to a child process
*
@ -186,7 +192,7 @@ void qse_pio_setflags (
int op
);
/****f* qse.cmn.pio/qse_pio_geterrnum
/****f* cmn/qse_pio_geterrnum
* NAME
* qse_pio_geterrnum - get an error code
*
@ -197,7 +203,7 @@ qse_pio_err_t qse_pio_geterrnum (
);
/******/
/****f* qse.cmn.pio/qse_pio_geterrstr
/****f* cmn/qse_pio_geterrmsg
* NAME
* qse_pio_geterrstr - transllate an error code to a string
*
@ -212,7 +218,7 @@ const qse_char_t* qse_pio_geterrstr (
);
/******/
/****f* qse.cmn.pio/qse_pio_gethandle
/****f* cmn/qse_pio_gethandle
* NAME
* qse_pio_gethandle - get native handle
*
@ -224,7 +230,7 @@ qse_pio_hnd_t qse_pio_gethandle (
);
/******/
/****f* qse.cmn.pio/qse_pio_getchild
/****f* cmn/qse_pio_getchild
* NAME
* qse_pio_getchild - get the PID of a child process
*
@ -235,10 +241,9 @@ qse_pio_pid_t qse_pio_getchild (
);
/******/
/****f* qse.cmn.pio/qse_pio_read
/****f* cmn/qse_pio_read
* NAME
* qse_pio_read - read data
*
* SYNOPSIS
*/
qse_ssize_t qse_pio_read (
@ -249,14 +254,12 @@ qse_ssize_t qse_pio_read (
);
/******/
/****f* qse.cmn.pio/qse_pio_write
/****f* cmn/qse_pio_write
* NAME
* qse_pio_write - write data
*
* DESCRIPTION
* If the parameter 'size' is zero, qse_pio_write() closes the the writing
* stream causing the child process reach the end of the stream.
*
* SYNOPSIS
*/
qse_ssize_t qse_pio_write (
@ -267,7 +270,7 @@ qse_ssize_t qse_pio_write (
);
/******/
/****f* qse.cmn.pio/qse_pio_flush
/****f* cmn/qse_pio_flush
* NAME
* qse_pio_flush - flush data
*
@ -279,7 +282,7 @@ qse_ssize_t qse_pio_flush (
);
/*****/
/****f* qse.cmn.pio/qse_pio_end
/****f* cmn/qse_pio_end
* NAME
* qse_pio_end - close native handle
*
@ -291,10 +294,9 @@ void qse_pio_end (
);
/******/
/****f* qse.cmn.pio/qse_pio_wait
/****f* cmn/qse_pio_wait
* NAME
* qse_pio_wait - wait for a child process
*
* DESCRIPTION
* QSE_PIO_WAIT_NORETRY causes the function to return an error and set the
* errnum field to QSE_PIO_EINTR if the underlying system call is interrupted.
@ -302,12 +304,10 @@ void qse_pio_end (
* When QSE_PIO_WAIT_NOBLOCK is used, the return value of 256 indicates that
* the child process has not terminated. If the flag is not used, 256 is never
* returned.
*
* RETURN
* -1 on error, 256 if the child is alive and QSE_PIO_NOBLOCK is used,
* a number between 0 and 255 inclusive if the child process ends normally,
* 256 + signal number if the child process is terminated by a signal.
*
* SYNOPSIS
*/
int qse_pio_wait (
@ -315,15 +315,13 @@ int qse_pio_wait (
);
/******/
/****f* qse.cmn.pio/qse_pio_kill
/****f* cmn/qse_pio_kill
* NAME
* qse_pio_kill - terminate the child process
*
* NOTES
* You should know the danger of calling this function as the function can
* kill a process that is not your child process if it has terminated but
* there is a new process with the same process handle.
*
* SYNOPSIS
*/
int qse_pio_kill (

View File

@ -22,13 +22,19 @@
#include <qse/types.h>
#include <qse/macros.h>
/****o* qse.cmn.sll/singly linked list
* DESCRIPTION
* <qse/cmn/sll.h> provides a singly linked list
*
* #include <qse/cmn/sll.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
*
* qse_sll_walker_t
* SYNOPSIS
*/
enum qse_sll_walk_t
@ -45,7 +51,6 @@ 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
@ -54,14 +59,12 @@ typedef enum qse_sll_walk_t qse_sll_walk_t;
* 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) (
@ -140,7 +143,7 @@ typedef qse_sll_walk_t (*qse_sll_walker_t) (
*/
struct qse_sll_t
{
qse_mmgr_t* mmgr; /* memory manager */
QSE_DEFINE_COMMON_FIELDS (sll)
qse_sll_copier_t copier; /* data copier */
qse_sll_freeer_t freeer; /* data freeer */
@ -153,17 +156,14 @@ struct qse_sll_t
};
/******/
/****s* qse.cmn.sll/qse_sll_node_t
/****s* cmn/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
@ -177,8 +177,6 @@ struct qse_sll_node_t
#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)
@ -188,14 +186,36 @@ struct qse_sll_node_t
#define QSE_SLL_SIZE(sll) ((sll)->size)
#define QSE_SLL_SCALE(sll) ((sll)->scale)
/****d* cmn/QSE_SLL_DPTR
* NAME
* QSE_SLL_DPTR - get the data pointer in a node
* SYNOPSIS
*/
#define QSE_SLL_DPTR(node) ((node)->dptr)
/******/
/****d* cmn/QSE_SLL_DLEN
* NAME
* QSE_SLL_DLEN - get the length of data in a node
* SYNOPSIS
*/
#define QSE_SLL_DLEN(node) ((node)->dlen)
/******/
/****d* cmn/QSE_SLL_NEXT
* NAME
* QSE_SLL_NEXT - get the next node
* SYNOPSIS
*/
#define QSE_SLL_NEXT(node) ((node)->next)
/******/
#ifdef __cplusplus
extern "C" {
#endif
QSE_DEFINE_COMMON_FUNCTIONS (sll)
/****f* qse.cmn.sll/qse_sll_open
* NAME
* qse_sll_open - create a singly linked list with extension area
@ -274,43 +294,6 @@ void qse_sll_fini (
);
/******/
/****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

View File

@ -22,7 +22,7 @@
#include <qse/types.h>
#include <qse/macros.h>
/****o* qse.cmn.str/string
/****o* cmn/string
* DESCRIPTION
* <qse/cmn/str.h> defines various functions, types, macros to manipulate
* strings.
@ -31,11 +31,6 @@
* dealing with a string pointer and length.
*
* #include <qse/cmn/str.h>
*
* EXAMPLES
* void f (void)
* {
* }
******
*/
@ -44,23 +39,26 @@
#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);
/****s* cmn/qse_str_t
* NAME
* qse_str_t - define a dynamically resizable string
* SYNOPSIS
*/
struct qse_str_t
{
qse_mmgr_t* mmgr;
qse_str_sizer_t sizer;
QSE_DEFINE_COMMON_FIELDS (str)
qse_char_t* ptr;
qse_size_t len;
qse_size_t capa;
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) \
@ -145,10 +143,9 @@ int qse_strxncmp (
int qse_strcasecmp (
const qse_char_t* s1, const qse_char_t* s2, qse_ccls_t* ccls);
/****f* qse.cmn.str/qse_strxncasecmp
/****f* cmn/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.
@ -160,22 +157,19 @@ int qse_strcasecmp (
* 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 */
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 */
);
/******/
@ -241,6 +235,8 @@ 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_DEFINE_COMMON_FUNCTIONS (str)
qse_str_t* qse_str_open (
qse_mmgr_t* mmgr,
qse_size_t ext,
@ -264,7 +260,7 @@ void qse_str_fini (
qse_str_t* str
);
/****f* qse.cmn.str/qse_str_yield
/****f* cmn/qse_str_yield
* NAME
* qse_str_yield - yield the buffer
*
@ -279,52 +275,40 @@ void qse_str_fini (
* 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 */
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.
/****f* cmn/qse_str_getsizer
* NAME
* qse_str_getsizer - get the sizer
* RETURN
* 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 */
qse_str_t* str
);
/******/
/*
* NAME: specify a sizer
*
* DESCRIPTION:
/****f* cmn/qse_str_setsizer
* NAME
* qse_str_setsizer - 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.
* SYNOPSIS
*/
void qse_str_setsizer (
qse_str_t* str /* a dynamic string */,
qse_str_sizer_t sizer /* a sizer function */
qse_str_t* str,
qse_str_sizer_t sizer
);
/******/
/*
* NAME: get capacity
@ -396,10 +380,9 @@ qse_size_t qse_str_nccat (
qse_size_t len
);
/****f* qse.cmn.str/qse_strspl
/****f* cmn/qse_strspl
* NAME
* qse_strspl - split a string
*
* SYNOPSIS
*/
int qse_strspl (
@ -411,10 +394,9 @@ int qse_strspl (
);
/******/
/****f* qse.cmn.str/qse_mbstowcs
/****f* cmn/qse_mbstowcs
* NAME
* qse_mbstowcs - convert a multibyte string to a wide character string
*
* SYNOPSIS
*/
qse_size_t qse_mbstowcs (
@ -424,13 +406,11 @@ qse_size_t qse_mbstowcs (
);
/******/
/****f* qse.cmn.str/qse_mbsntowcsn
/****f* cmn/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 (
@ -441,20 +421,17 @@ qse_size_t qse_mbsntowcsn (
);
/******/
/****f* qse.cmn.str/qse_wcstombslen
/****f* cmn/qse_wcstombslen
* NAME
* qse_wcstombslen - get the length
*
* DESCRIPTION
* The qse_wcstombslen() function scans a null-terminated wide character
* string to get the total number of multibyte characters that it can be
* converted to. The resulting number of characters is stored into memory
* pointed to by mbslen.
*
* RETURN
* The qse_wcstombslen() function returns the number of wide characters
* handled.
*
* SYNOPSIS
*/
qse_size_t qse_wcstombslen (
@ -463,20 +440,17 @@ qse_size_t qse_wcstombslen (
);
/******/
/****f* qse.cmn.str/qse_wcsntombsnlen
/****f* cmn/qse_wcsntombsnlen
* NAME
* qse_wcsntombsnlen - get the length
*
* DESCRIPTION
* The qse_wcsntombsnlen() function scans a wide character wcs as long as
* wcslen characters to get the get the total number of multibyte characters
* that it can be converted to. The resulting number of characters is stored
* into memory pointed to by mbslen.
*
* RETURN
* The qse_wcsntombsnlen() function returns the number of wide characters
* handled.
*
* SYNOPSIS
*/
qse_size_t qse_wcsntombsnlen (
@ -486,10 +460,9 @@ qse_size_t qse_wcsntombsnlen (
);
/******/
/****f* qse.cmn.str/qse_wcstombs
/****f* cmn/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
@ -499,10 +472,8 @@ qse_size_t qse_wcsntombsnlen (
* It may not null-terminate the resulting multibyte string if the buffer
* is not large enough. You can check if the resulting mbslen is equal to
* the input mbslen to know it.
*
* RETURN
* The qse_wcstombs() function returns the number of wide characters handled.
*
* SYNOPSIS
*/
qse_size_t qse_wcstombs (
@ -510,14 +481,13 @@ qse_size_t qse_wcstombs (
qse_mchar_t* mbs,
qse_size_t* mbslen
);
/******/
/****f* qse.cmn.str/qse_wcsntombsn
/****f* cmn/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 (
@ -528,15 +498,13 @@ qse_size_t qse_wcsntombsn (
);
/******/
/****f* qse.cmn.str/qse_wcstombs_strict
/****f* cmn/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

View File

@ -72,10 +72,9 @@ struct qse_btime_t
extern "C" {
#endif
/****f* qse.cmn/qse_gettime
/****f* qse.cmn.time/qse_gettime
* NAME
* qse_gettime - get the current time
*
* SYNPOSIS
*/
int qse_gettime (
@ -83,10 +82,9 @@ int qse_gettime (
);
/******/
/****f* qse.cmn/qse_settime
/****f* qse.cmn.time/qse_settime
* NAME
* qse_settime - set the current time
*
* SYNOPSIS
*/
int qse_settime (
@ -95,10 +93,9 @@ int qse_settime (
/******/
/****f* qse.cmn/qse_gmtime
/****f* qse.cmn.time/qse_gmtime
* NAME
* qse_gmtime - convert numeric time to broken-down time
*
* SYNOPSIS
*/
int qse_gmtime (
@ -107,10 +104,9 @@ int qse_gmtime (
);
/******/
/****f* qse.cmn/qse_localtime
/****f* qse.cmn.time/qse_localtime
* NAME
* qse_localtime - convert numeric time to broken-down time
*
* SYNOPSIS
*/
int qse_localtime (
@ -119,7 +115,7 @@ int qse_localtime (
);
/******/
/****f* qse.cmn/qse_timegm
/****f* qse.cmn.time/qse_timegm
* NAME
* qse_timegm - convert broken-down time to numeric time
*
@ -131,7 +127,7 @@ int qse_timegm (
);
/******/
/****f* qse.cmn/qse_timelocal
/****f* qse.cmn.time/qse_timelocal
* NAME
* qse_timelocal - convert broken-down time to numeric time
*
@ -143,7 +139,7 @@ int qse_timelcoal (
);
/******/
/****f* qse.cmn/qse_strftime
/****f* qse.cmn.time/qse_strftime
* NAME
* qse_strftime - format time
*

View File

@ -60,32 +60,35 @@ enum
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
/****t* cmn/qse_tio_io_t
* NAME
* qse_tio_io_t - define a text IO handler type
* SYNOPSIS
*/
typedef qse_ssize_t (*qse_tio_io_t) (
int cmd, void* arg, void* data, qse_size_t size);
int cmd,
void* arg,
void* data,
qse_size_t size
);
/******/
/****s* cmn/qse_tio_t
* NAME
* qse_tio_t - define a text IO type
* DESCRIPTION
* The qse_tio_t type defines a generic type for text IO. When qse_char_t is
* qse_mchar_t, it handles any byte streams. When qse_char_t is qse_wchar_t,
* it handles a multi-byte stream converted to a wide character stream.
* SYNOPSIS
*/
struct qse_tio_t
{
QSE_DEFINE_STD_FIELDS (tio)
QSE_DEFINE_COMMON_FIELDS (tio)
qse_tio_err_t errnum;
/* io functions */
@ -103,38 +106,57 @@ struct qse_tio_t
qse_mchar_t inbuf[QSE_TIO_MAX_INBUF_LEN];
qse_mchar_t outbuf[QSE_TIO_MAX_OUTBUF_LEN];
};
/******/
#ifdef __cplusplus
extern "C" {
#endif
QSE_DEFINE_STD_FUNCTIONS (tio)
QSE_DEFINE_COMMON_FUNCTIONS (tio)
/*
* FUNCTION: qse_tio_open
/****f* cmn/qse_tio_open
* NAME
* qse_tio_open - create an text IO processor
* SYNOPSIS
*/
qse_tio_t* qse_tio_open (
qse_mmgr_t* mmgr,
qse_size_t ext
);
/******/
/*
* FUNCTION: qse_tio_close
/****f* cmn/qse_tio_close
* NAME
* qse_tio_close - destroy an text IO processor
* SYNOPSIS
*/
int qse_tio_close (
qse_tio_t* tio
);
/******/
/****f* cmn/qse_tio_init
* NAME
* qse_tio_init - initialize an text IO processor
* SYNOPSIS
*/
qse_tio_t* qse_tio_init (
qse_tio_t* tip,
qse_mmgr_t* mmgr
);
/******/
/****f* cmn/qse_tio_fini
* NAME
* qse_tio_fini - finalize an text IO processor
* SYNOPSIS
*/
int qse_tio_fini (
qse_tio_t* tio
);
/******/
/****f* qse.cmn.tio/qse_tio_geterrnum
/****f* cmn/qse_tio_geterrnum
* NAME
* qse_tio_geterrnum - get an error code
*
@ -145,92 +167,75 @@ qse_tio_err_t qse_tio_geterrnum (
);
/******/
/*
* 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
/****f* cmn/qse_tio_geterrmsg
* NAME
* qse_tio_geterrmsg - translate an error code to a string
* RETURN
* A pointer to a constant string describing the last error occurred.
*/
const qse_char_t* qse_tio_geterrstr (
const qse_char_t* qse_tio_geterrmsg (
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:
/****f* cmn/qse_tio_attachin
* NAME
* qse_tio_attachin - attaches an input handler
* RETURN
* 0 on success, -1 on failure
* SYNOPSIS
*/
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:
/****f* cmn/qse_tio_detachin
* NAME
* qse_tio_detachin - detach an input handler
* RETURN
* 0 on success, -1 on failure
* SYNOPSIS
*/
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:
/****f* cmn/qse_tio_attachout
* NAME
* qse_tio_attachout - attaches an output handler
* RETURN
* 0 on success, -1 on failure
* SYNOPSIS
*/
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:
/****f* cmn/qse_tio_detachout
* NAME
* qse_tio_detachout - detaches an output handler
* RETURN
* 0 on success, -1 on failure
* SYNOPSIS
*/
int qse_tio_detachout (
qse_tio_t* tio
);
/******/
/****f* qse.cmn.tio/qse_tio_flush
/****f* cmn/qse_tio_flush
* NAME
* qse_tio_flush - flush the output buffer
*
* RETURNS
* The qse_tio_flush() function return the number of bytes written on
* success, -1 on failure.
*
* SYNOPSIS
*/
qse_ssize_t qse_tio_flush (
@ -238,10 +243,9 @@ qse_ssize_t qse_tio_flush (
);
/******/
/****f* qse.cmn.tio/qse_tio_purge
/****f* cmn/qse_tio_purge
* NAME
* qse_tio_purge - erase input and output buffered
*
* qse_tio_purge - empty input and output buffers
* SYNOPSIS
*/
void qse_tio_purge (
@ -249,10 +253,9 @@ void qse_tio_purge (
);
/******/
/****f* qse.cmn.tio/qse_tio_read
/****f* cmn/qse_tio_read
* NAME
* qse_tio_read - read text
*
* SYNOPSIS
*/
qse_ssize_t qse_tio_read (
@ -262,14 +265,12 @@ qse_ssize_t qse_tio_read (
);
/******/
/****f* qse.cmn.tio/qse_tio_write
/****f* cmn/qse_tio_write
* NAME
* qse_tio_write - write text
*
* DESCRIPTION
* If the size paramenter is (qse_size_t)-1, the function treats the data
* parameter as a pointer to a null-terminated string.
*
* SYNOPSIS
*/
qse_ssize_t qse_tio_write (