diff options
| author | ruki <[email protected]> | 2016-05-19 15:47:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-05-19 15:47:46 +0800 |
| commit | f3ab20418a0b06f84c6afa22ecfebf7965fd646b (patch) | |
| tree | 91f7d98b3c4a5631897af10eda485f58a430724f /core/pkg | |
| parent | 3f36fc0bee466691f3d0400ae7b4d8259870a15a (diff) | |
impl multi-jobs for builder
Diffstat (limited to 'core/pkg')
28 files changed, 1377 insertions, 339 deletions
diff --git a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h index 32cd51bdc..2b1bad84e 100755 --- a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h +++ b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h @@ -6,95 +6,103 @@ #define TB_CONFIG_VERSION_MAJOR 1 #define TB_CONFIG_VERSION_MINOR 5 #define TB_CONFIG_VERSION_ALTER 1 -#define TB_CONFIG_VERSION_BUILD 201512222155 +#define TB_CONFIG_VERSION_BUILD 201605182101 // defines -#define TB_CONFIG_OS_MACOSX -#define TB_CONFIG_INFO_HAVE_VERSION -#define TB_CONFIG_TYPE_HAVE_FLOAT -#define TB_CONFIG_MODULE_HAVE_XML -#define TB_CONFIG_MODULE_HAVE_ASIO -#define TB_CONFIG_MODULE_HAVE_OBJECT -#define TB_CONFIG_MODULE_HAVE_THREAD -#define TB_CONFIG_MODULE_HAVE_NETWORK -#define TB_CONFIG_MODULE_HAVE_CHARSET -#define TB_CONFIG_LIBC_HAVE_MEMCPY -#define TB_CONFIG_LIBC_HAVE_MEMSET -#define TB_CONFIG_LIBC_HAVE_MEMMOVE -#define TB_CONFIG_LIBC_HAVE_MEMCMP -#define TB_CONFIG_LIBC_HAVE_MEMMEM -#define TB_CONFIG_LIBC_HAVE_STRCAT -#define TB_CONFIG_LIBC_HAVE_STRNCAT -#define TB_CONFIG_LIBC_HAVE_STRCPY -#define TB_CONFIG_LIBC_HAVE_STRNCPY -#define TB_CONFIG_LIBC_HAVE_STRLCPY -#define TB_CONFIG_LIBC_HAVE_STRLEN -#define TB_CONFIG_LIBC_HAVE_STRNLEN -#define TB_CONFIG_LIBC_HAVE_STRSTR -#define TB_CONFIG_LIBC_HAVE_STRCASESTR -#define TB_CONFIG_LIBC_HAVE_STRCMP -#define TB_CONFIG_LIBC_HAVE_STRCASECMP -#define TB_CONFIG_LIBC_HAVE_STRNCMP -#define TB_CONFIG_LIBC_HAVE_STRNCASECMP -#define TB_CONFIG_LIBC_HAVE_WCSCAT -#define TB_CONFIG_LIBC_HAVE_WCSNCAT -#define TB_CONFIG_LIBC_HAVE_WCSCPY -#define TB_CONFIG_LIBC_HAVE_WCSNCPY -#define TB_CONFIG_LIBC_HAVE_WCSLCPY -#define TB_CONFIG_LIBC_HAVE_WCSLEN -#define TB_CONFIG_LIBC_HAVE_WCSNLEN -#define TB_CONFIG_LIBC_HAVE_WCSSTR -#define TB_CONFIG_LIBC_HAVE_WCSCMP -#define TB_CONFIG_LIBC_HAVE_WCSCASECMP -#define TB_CONFIG_LIBC_HAVE_WCSNCMP -#define TB_CONFIG_LIBC_HAVE_WCSNCASECMP -#define TB_CONFIG_LIBC_HAVE_WCSTOMBS -#define TB_CONFIG_LIBC_HAVE_MBSTOWCS -#define TB_CONFIG_LIBC_HAVE_GMTIME -#define TB_CONFIG_LIBC_HAVE_MKTIME -#define TB_CONFIG_LIBC_HAVE_LOCALTIME -#define TB_CONFIG_LIBC_HAVE_GETTIMEOFDAY -#define TB_CONFIG_LIBC_HAVE_SIGNAL -#define TB_CONFIG_LIBC_HAVE_SETJMP -#define TB_CONFIG_LIBC_HAVE_SIGSETJMP -#define TB_CONFIG_LIBC_HAVE_BACKTRACE -#define TB_CONFIG_LIBC_HAVE_SYSTEM -#define TB_CONFIG_LIBM_HAVE_LOG2 -#define TB_CONFIG_LIBM_HAVE_LOG2F -#define TB_CONFIG_LIBM_HAVE_SQRT -#define TB_CONFIG_LIBM_HAVE_SQRTF -#define TB_CONFIG_LIBM_HAVE_ACOS -#define TB_CONFIG_LIBM_HAVE_ACOSF -#define TB_CONFIG_LIBM_HAVE_ASIN -#define TB_CONFIG_LIBM_HAVE_ASINF -#define TB_CONFIG_LIBM_HAVE_POW -#define TB_CONFIG_LIBM_HAVE_POWF -#define TB_CONFIG_LIBM_HAVE_FMOD -#define TB_CONFIG_LIBM_HAVE_FMODF -#define TB_CONFIG_LIBM_HAVE_ATAN -#define TB_CONFIG_LIBM_HAVE_ATANF -#define TB_CONFIG_LIBM_HAVE_ATAN2 -#define TB_CONFIG_LIBM_HAVE_ATAN2F -#define TB_CONFIG_LIBM_HAVE_COS -#define TB_CONFIG_LIBM_HAVE_COSF -#define TB_CONFIG_LIBM_HAVE_SIN -#define TB_CONFIG_LIBM_HAVE_SINF -#define TB_CONFIG_LIBM_HAVE_EXP -#define TB_CONFIG_LIBM_HAVE_EXPF -#define TB_CONFIG_POSIX_HAVE_POLL -#define TB_CONFIG_POSIX_HAVE_PTHREAD_MUTEX_INIT -#define TB_CONFIG_POSIX_HAVE_PTHREAD_CREATE -#define TB_CONFIG_POSIX_HAVE_SOCKET -#define TB_CONFIG_POSIX_HAVE_OPENDIR -#define TB_CONFIG_POSIX_HAVE_DLOPEN -#define TB_CONFIG_POSIX_HAVE_OPEN -#define TB_CONFIG_POSIX_HAVE_GETHOSTNAME -#define TB_CONFIG_POSIX_HAVE_GETIFADDRS -#define TB_CONFIG_POSIX_HAVE_SEM_INIT -#define TB_CONFIG_POSIX_HAVE_GETPAGESIZE -#define TB_CONFIG_POSIX_HAVE_SYSCONF -#define TB_CONFIG_POSIX_HAVE_SCHED_YIELD -#define TB_CONFIG_SYSTEMV_HAVE_SEMGET +#define TB_CONFIG_OS_MACOSX 1 +#define TB_CONFIG_INFO_HAVE_VERSION 1 +#define TB_CONFIG_TYPE_HAVE_FLOAT 1 +#define TB_CONFIG_MODULE_HAVE_REGEX 1 +#define TB_CONFIG_MODULE_HAVE_THREAD 1 +#define TB_CONFIG_MODULE_HAVE_NETWORK 1 +#define TB_CONFIG_LIBC_HAVE_MEMCPY 1 +#define TB_CONFIG_LIBC_HAVE_MEMSET 1 +#define TB_CONFIG_LIBC_HAVE_MEMMOVE 1 +#define TB_CONFIG_LIBC_HAVE_MEMCMP 1 +#define TB_CONFIG_LIBC_HAVE_MEMMEM 1 +#define TB_CONFIG_LIBC_HAVE_STRCAT 1 +#define TB_CONFIG_LIBC_HAVE_STRNCAT 1 +#define TB_CONFIG_LIBC_HAVE_STRCPY 1 +#define TB_CONFIG_LIBC_HAVE_STRNCPY 1 +#define TB_CONFIG_LIBC_HAVE_STRLCPY 1 +#define TB_CONFIG_LIBC_HAVE_STRLEN 1 +#define TB_CONFIG_LIBC_HAVE_STRNLEN 1 +#define TB_CONFIG_LIBC_HAVE_STRSTR 1 +#define TB_CONFIG_LIBC_HAVE_STRCASESTR 1 +#define TB_CONFIG_LIBC_HAVE_STRCMP 1 +#define TB_CONFIG_LIBC_HAVE_STRCASECMP 1 +#define TB_CONFIG_LIBC_HAVE_STRNCMP 1 +#define TB_CONFIG_LIBC_HAVE_STRNCASECMP 1 +#define TB_CONFIG_LIBC_HAVE_WCSCAT 1 +#define TB_CONFIG_LIBC_HAVE_WCSNCAT 1 +#define TB_CONFIG_LIBC_HAVE_WCSCPY 1 +#define TB_CONFIG_LIBC_HAVE_WCSNCPY 1 +#define TB_CONFIG_LIBC_HAVE_WCSLCPY 1 +#define TB_CONFIG_LIBC_HAVE_WCSLEN 1 +#define TB_CONFIG_LIBC_HAVE_WCSNLEN 1 +#define TB_CONFIG_LIBC_HAVE_WCSSTR 1 +#define TB_CONFIG_LIBC_HAVE_WCSCMP 1 +#define TB_CONFIG_LIBC_HAVE_WCSCASECMP 1 +#define TB_CONFIG_LIBC_HAVE_WCSNCMP 1 +#define TB_CONFIG_LIBC_HAVE_WCSNCASECMP 1 +#define TB_CONFIG_LIBC_HAVE_WCSTOMBS 1 +#define TB_CONFIG_LIBC_HAVE_MBSTOWCS 1 +#define TB_CONFIG_LIBC_HAVE_GMTIME 1 +#define TB_CONFIG_LIBC_HAVE_MKTIME 1 +#define TB_CONFIG_LIBC_HAVE_LOCALTIME 1 +#define TB_CONFIG_LIBC_HAVE_GETTIMEOFDAY 1 +#define TB_CONFIG_LIBC_HAVE_SIGNAL 1 +#define TB_CONFIG_LIBC_HAVE_SETJMP 1 +#define TB_CONFIG_LIBC_HAVE_SIGSETJMP 1 +#define TB_CONFIG_LIBC_HAVE_KILL 1 +#define TB_CONFIG_LIBC_HAVE_BACKTRACE 1 +#define TB_CONFIG_LIBM_HAVE_LOG2 1 +#define TB_CONFIG_LIBM_HAVE_LOG2F 1 +#define TB_CONFIG_LIBM_HAVE_SQRT 1 +#define TB_CONFIG_LIBM_HAVE_SQRTF 1 +#define TB_CONFIG_LIBM_HAVE_ACOS 1 +#define TB_CONFIG_LIBM_HAVE_ACOSF 1 +#define TB_CONFIG_LIBM_HAVE_ASIN 1 +#define TB_CONFIG_LIBM_HAVE_ASINF 1 +#define TB_CONFIG_LIBM_HAVE_POW 1 +#define TB_CONFIG_LIBM_HAVE_POWF 1 +#define TB_CONFIG_LIBM_HAVE_FMOD 1 +#define TB_CONFIG_LIBM_HAVE_FMODF 1 +#define TB_CONFIG_LIBM_HAVE_TAN 1 +#define TB_CONFIG_LIBM_HAVE_TANF 1 +#define TB_CONFIG_LIBM_HAVE_ATAN 1 +#define TB_CONFIG_LIBM_HAVE_ATANF 1 +#define TB_CONFIG_LIBM_HAVE_ATAN2 1 +#define TB_CONFIG_LIBM_HAVE_ATAN2F 1 +#define TB_CONFIG_LIBM_HAVE_COS 1 +#define TB_CONFIG_LIBM_HAVE_COSF 1 +#define TB_CONFIG_LIBM_HAVE_SIN 1 +#define TB_CONFIG_LIBM_HAVE_SINF 1 +#define TB_CONFIG_LIBM_HAVE_EXP 1 +#define TB_CONFIG_LIBM_HAVE_EXPF 1 +#define TB_CONFIG_POSIX_HAVE_POLL 1 +#define TB_CONFIG_POSIX_HAVE_PTHREAD_MUTEX_INIT 1 +#define TB_CONFIG_POSIX_HAVE_PTHREAD_CREATE 1 +#define TB_CONFIG_POSIX_HAVE_SOCKET 1 +#define TB_CONFIG_POSIX_HAVE_OPENDIR 1 +#define TB_CONFIG_POSIX_HAVE_DLOPEN 1 +#define TB_CONFIG_POSIX_HAVE_OPEN 1 +#define TB_CONFIG_POSIX_HAVE_GETHOSTNAME 1 +#define TB_CONFIG_POSIX_HAVE_GETIFADDRS 1 +#define TB_CONFIG_POSIX_HAVE_SEM_INIT 1 +#define TB_CONFIG_POSIX_HAVE_GETPAGESIZE 1 +#define TB_CONFIG_POSIX_HAVE_SYSCONF 1 +#define TB_CONFIG_POSIX_HAVE_SCHED_YIELD 1 +#define TB_CONFIG_POSIX_HAVE_REGCOMP 1 +#define TB_CONFIG_POSIX_HAVE_REGEXEC 1 +#define TB_CONFIG_POSIX_HAVE_READV 1 +#define TB_CONFIG_POSIX_HAVE_WRITEV 1 +#define TB_CONFIG_POSIX_HAVE_POSIX_SPAWNP 1 +#define TB_CONFIG_POSIX_HAVE_EXECVP 1 +#define TB_CONFIG_POSIX_HAVE_FORK 1 +#define TB_CONFIG_POSIX_HAVE_VFORK 1 +#define TB_CONFIG_POSIX_HAVE_WAITPID 1 +#define TB_CONFIG_SYSTEMV_HAVE_SEMGET 1 // undefines #undef TB_CONFIG_TRACE_INFO_ONLY diff --git a/core/pkg/tbox.pkg/inc/tbox/asio/aice.h b/core/pkg/tbox.pkg/inc/tbox/asio/aice.h index 5093b6b2f..899caf88c 100644 --- a/core/pkg/tbox.pkg/inc/tbox/asio/aice.h +++ b/core/pkg/tbox.pkg/inc/tbox/asio/aice.h @@ -75,7 +75,7 @@ typedef struct __tb_aice_acpt_t tb_aico_ref_t aico; /// the client addr - tb_ipaddr_t addr; + tb_ipaddr_t addr; /// the private data for using the left space of the union tb_cpointer_t priv[1]; @@ -86,7 +86,7 @@ typedef struct __tb_aice_acpt_t typedef struct __tb_aice_conn_t { /// the addr - tb_ipaddr_t addr; + tb_ipaddr_t addr; }tb_aice_conn_t; @@ -95,7 +95,7 @@ typedef struct __tb_aice_conn_t typedef struct __tb_aice_recv_t { /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the recv data for (tb_iovec_t*)->data tb_byte_t* data; @@ -109,7 +109,7 @@ typedef struct __tb_aice_recv_t typedef struct __tb_aice_send_t { /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the send data for (tb_iovec_t*)->data tb_byte_t const* data; @@ -123,7 +123,7 @@ typedef struct __tb_aice_send_t typedef struct __tb_aice_urecv_t { /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the recv data for (tb_iovec_t*)->data tb_byte_t* data; @@ -132,7 +132,7 @@ typedef struct __tb_aice_urecv_t tb_size_t real; /// the addr - tb_ipaddr_t addr; + tb_ipaddr_t addr; }tb_aice_urecv_t; @@ -140,7 +140,7 @@ typedef struct __tb_aice_urecv_t typedef struct __tb_aice_usend_t { /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the send data for (tb_iovec_t*)->data tb_byte_t const* data; @@ -149,7 +149,7 @@ typedef struct __tb_aice_usend_t tb_size_t real; /// the peer addr - tb_ipaddr_t addr; + tb_ipaddr_t addr; }tb_aice_usend_t; @@ -157,7 +157,7 @@ typedef struct __tb_aice_usend_t typedef struct __tb_aice_read_t { /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the read data for (tb_iovec_t*)->data tb_byte_t* data; @@ -174,7 +174,7 @@ typedef struct __tb_aice_read_t typedef struct __tb_aice_writ_t { /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the writ data for (tb_iovec_t*)->data tb_byte_t const* data; @@ -194,7 +194,7 @@ typedef struct __tb_aice_recv_t tb_byte_t* data; /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the data real tb_size_t real; @@ -208,7 +208,7 @@ typedef struct __tb_aice_send_t tb_byte_t const* data; /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the data real tb_size_t real; @@ -222,13 +222,13 @@ typedef struct __tb_aice_urecv_t tb_byte_t* data; /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the data real tb_size_t real; /// the addr - tb_ipaddr_t addr; + tb_ipaddr_t addr; }tb_aice_urecv_t; @@ -239,13 +239,13 @@ typedef struct __tb_aice_usend_t tb_byte_t const* data; /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the data real tb_size_t real; /// the addr - tb_ipaddr_t addr; + tb_ipaddr_t addr; }tb_aice_usend_t; @@ -256,7 +256,7 @@ typedef struct __tb_aice_read_t tb_byte_t* data; /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the data real tb_size_t real; @@ -273,7 +273,7 @@ typedef struct __tb_aice_writ_t tb_byte_t const* data; /// the data size for (tb_iovec_t*)->size - tb_size_t size; + tb_iovec_size_t size; /// the data real tb_size_t real; @@ -325,7 +325,7 @@ typedef struct __tb_aice_urecvv_t tb_size_t real; /// the peer addr - tb_ipaddr_t addr; + tb_ipaddr_t addr; }tb_aice_urecvv_t; @@ -342,7 +342,7 @@ typedef struct __tb_aice_usendv_t tb_size_t real; /// the addr - tb_ipaddr_t addr; + tb_ipaddr_t addr; }tb_aice_usendv_t; diff --git a/core/pkg/tbox.pkg/inc/tbox/container/vector.h b/core/pkg/tbox.pkg/inc/tbox/container/vector.h index 53b3e111d..9ffae0401 100644 --- a/core/pkg/tbox.pkg/inc/tbox/container/vector.h +++ b/core/pkg/tbox.pkg/inc/tbox/container/vector.h @@ -83,6 +83,32 @@ typedef tb_iterator_ref_t tb_vector_ref_t; */ /*! init vector + * + * @code + * + // init vector + tb_vector_ref_t vector = tb_vector_init(0, tb_element_str(tb_true)); + if (vector) + { + // insert elements into head + tb_vector_insert_head(vector, "hi!"); + + // insert elements into tail + tb_vector_insert_tail(vector, "how"); + tb_vector_insert_tail(vector, "are"); + tb_vector_insert_tail(vector, "you"); + + // dump elements + tb_for_all (tb_char_t const*, cstr, vector) + { + // trace + tb_trace_d("%s", cstr); + } + + // exit vector + tb_vector_exit(vector); + } + * @endcode * * @param grow the item grow * @param element the element diff --git a/core/pkg/tbox.pkg/inc/tbox/database/sql.h b/core/pkg/tbox.pkg/inc/tbox/database/sql.h index 26f66c99a..bdbe4b876 100644 --- a/core/pkg/tbox.pkg/inc/tbox/database/sql.h +++ b/core/pkg/tbox.pkg/inc/tbox/database/sql.h @@ -18,7 +18,7 @@ * * @author ruki * @file sql.h - * @defgroup database + * @ingroup database */ #ifndef TB_DATABASE_SQL_H #define TB_DATABASE_SQL_H diff --git a/core/pkg/tbox.pkg/inc/tbox/math/fixed16.h b/core/pkg/tbox.pkg/inc/tbox/math/fixed16.h index 7894a26b9..138934543 100644 --- a/core/pkg/tbox.pkg/inc/tbox/math/fixed16.h +++ b/core/pkg/tbox.pkg/inc/tbox/math/fixed16.h @@ -337,7 +337,7 @@ static __tb_inline__ tb_fixed16_t tb_long_to_fixed16_check(tb_long_t x) tb_assert(x == (tb_int16_t)x); // ok - return (x << 16); + return (tb_fixed16_t)(x << 16); } static __tb_inline__ tb_long_t tb_fixed16_to_long_check(tb_fixed16_t x) { @@ -400,7 +400,7 @@ static __tb_inline__ tb_fixed16_t tb_fixed16_idiv_check(tb_fixed16_t x, tb_long_ tb_assert(y); // ok - return x / y; + return (tb_fixed16_t)(x / y); } static __tb_inline__ tb_fixed16_t tb_fixed16_imuldiv_check(tb_fixed16_t x, tb_long_t y, tb_long_t z) { diff --git a/core/pkg/tbox.pkg/inc/tbox/math/fixed6.h b/core/pkg/tbox.pkg/inc/tbox/math/fixed6.h index 453e4b6d0..ed384c32c 100644 --- a/core/pkg/tbox.pkg/inc/tbox/math/fixed6.h +++ b/core/pkg/tbox.pkg/inc/tbox/math/fixed6.h @@ -146,7 +146,7 @@ static __tb_inline__ tb_fixed6_t tb_long_to_fixed6_check(tb_long_t x) tb_assert(x >= (TB_MINS32 >> 10) && x <= (TB_MAXS32 >> 10)); // ok - return (x << 6); + return (tb_fixed6_t)(x << 6); } static __tb_inline__ tb_long_t tb_fixed6_to_int_check(tb_fixed6_t x) { @@ -154,7 +154,7 @@ static __tb_inline__ tb_long_t tb_fixed6_to_int_check(tb_fixed6_t x) tb_assert(x >= TB_FIXED6_MIN && x <= TB_FIXED6_MAX); // ok - return (x >> 6); + return (tb_fixed6_t)(x >> 6); } #endif static __tb_inline__ tb_fixed6_t tb_fixed6_mul_inline(tb_fixed6_t x, tb_fixed6_t y) diff --git a/core/pkg/tbox.pkg/inc/tbox/object/dictionary.h b/core/pkg/tbox.pkg/inc/tbox/object/dictionary.h index 46d5a0d0e..a4f9b5dc7 100644 --- a/core/pkg/tbox.pkg/inc/tbox/object/dictionary.h +++ b/core/pkg/tbox.pkg/inc/tbox/object/dictionary.h @@ -62,12 +62,35 @@ typedef struct __tb_object_dictionary_item_t /*! init dictionary * + * @code + // init dictionary + // {"key1": "hello", "key2" :"world", "key3": 12345, "key4": true} + tb_object_ref_t dict = tb_object_dictionary_init(0, tb_false); + if (dict) + { + // key1 => hello + tb_object_dictionary_insert(dict, "key1", tb_object_string_init_from_cstr("hello")); + + // key2 => world + tb_object_dictionary_insert(dict, "key2", tb_object_string_init_from_cstr("world")); + + // key3 => 12345 + tb_object_dictionary_insert(dict, "key3", tb_object_number_init_from_sint32(12345)); + + // key4 => true + tb_object_dictionary_insert(dict, "key4", tb_object_boolean_true()); + + // exit dictionary + tb_object_exit(dict); + } + * @endcode + * * @param size the dictionary size, using the default size if be zero * @param incr is increase refn? * * @return the dictionary object */ -tb_object_ref_t tb_object_dictionary_init(tb_size_t size, tb_size_t incr); +tb_object_ref_t tb_object_dictionary_init(tb_size_t size, tb_bool_t incr); /*! the dictionary size * @@ -91,16 +114,16 @@ tb_void_t tb_object_dictionary_incr(tb_object_ref_t dictionary, tb * @return the dictionary iterator * * @code - * tb_for_all (tb_object_dictionary_item_t*, item, tb_object_dictionary_itor(dictionary)) - * { - * if (item) - * { - * tb_char_t const* key = item->key; - * tb_object_ref_t val = item->val; - * - * // ... - * } - * } + tb_for_all (tb_object_dictionary_item_t*, item, tb_object_dictionary_itor(dictionary)) + { + if (item) + { + tb_char_t const* key = item->key; + tb_object_ref_t val = item->val; + + // ... + } + } * @endcode */ tb_iterator_ref_t tb_object_dictionary_itor(tb_object_ref_t dictionary); diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/environment.h b/core/pkg/tbox.pkg/inc/tbox/platform/environment.h index b5e78bc5c..7140ee3ac 100644 --- a/core/pkg/tbox.pkg/inc/tbox/platform/environment.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/environment.h @@ -143,7 +143,7 @@ tb_bool_t tb_environment_save(tb_environment_ref_t environment, tb // load variable if (tb_environment_load(environment, "PATH")) { - tb_char_t const* value = tb_environment_get(environment, 0); + tb_char_t const* value = tb_environment_at(environment, 0); if (value) { // ... @@ -161,9 +161,9 @@ tb_bool_t tb_environment_save(tb_environment_ref_t environment, tb * * @return the variable value */ -tb_char_t const* tb_environment_get(tb_environment_ref_t environment, tb_size_t index); +tb_char_t const* tb_environment_at(tb_environment_ref_t environment, tb_size_t index); -/*! set the environment variable and will overwrite it +/*! replace the environment variable and will overwrite it * * we will clear environment and overwrite it * @@ -172,7 +172,7 @@ tb_char_t const* tb_environment_get(tb_environment_ref_t environment, tb_ * * @return tb_true or tb_false */ -tb_bool_t tb_environment_set(tb_environment_ref_t environment, tb_char_t const* value); +tb_bool_t tb_environment_replace(tb_environment_ref_t environment, tb_char_t const* value); /*! set the environment variable * @@ -198,7 +198,7 @@ tb_void_t tb_environment_dump(tb_environment_ref_t environment, tb * @code tb_char_t value[TB_PATH_MAXN]; - if (tb_environment_get_one("HOME", value, sizeof(value))) + if (tb_environment_first("HOME", value, sizeof(value))) { // ... } @@ -211,19 +211,56 @@ tb_void_t tb_environment_dump(tb_environment_ref_t environment, tb * * @return the variable value size */ -tb_size_t tb_environment_get_one(tb_char_t const* name, tb_char_t* value, tb_size_t maxn); +tb_size_t tb_environment_first(tb_char_t const* name, tb_char_t* value, tb_size_t maxn); -/*! set the environment variable value +/*! get the environment variable values * - * we will set only one value and overwrite it, - * and remove this environment variable if the value is null + * @code + + tb_char_t value[TB_PATH_MAXN]; + if (tb_environment_get("HOME", value, sizeof(value))) + { + // ... + } + + * @endcode + * + * @param name the variable name + * @param values the variable values, separator: windows(';') or other(';') + * @param maxn the variable values maxn + * + * @return the variable values size + */ +tb_size_t tb_environment_get(tb_char_t const* name, tb_char_t* values, tb_size_t maxn); + +/*! set the environment variable values + * + * we will set all values and overwrite it + * + * @param name the variable name + * @param values the variable values, separator: windows(';') or other(';') + * + * @return tb_true or tb_false + */ +tb_bool_t tb_environment_set(tb_char_t const* name, tb_char_t const* values); + +/*! add the environment variable values and not overwrite it + * + * @param name the variable name + * @param values the variable values, separator: windows(';') or other(';') + * @param to_head add value into the head? + * + * @return tb_true or tb_false + */ +tb_bool_t tb_environment_add(tb_char_t const* name, tb_char_t const* values, tb_bool_t to_head); + +/*! remove the given environment variable * * @param name the variable name - * @param value the variable value * * @return tb_true or tb_false */ -tb_bool_t tb_environment_set_one(tb_char_t const* name, tb_char_t const* value); +tb_bool_t tb_environment_remove(tb_char_t const* name); /* ////////////////////////////////////////////////////////////////////////////////////// * extern diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/ltimer.h b/core/pkg/tbox.pkg/inc/tbox/platform/ltimer.h index 523cd2c0a..93b5e8c3d 100644 --- a/core/pkg/tbox.pkg/inc/tbox/platform/ltimer.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/ltimer.h @@ -80,6 +80,12 @@ tb_ltimer_ref_t tb_ltimer_init(tb_size_t maxn, tb_size_t tick, tb_bool_t */ tb_void_t tb_ltimer_exit(tb_ltimer_ref_t timer); +/*! kill timer for tb_ltimer_loop() + * + * @param timer the timer + */ +tb_void_t tb_ltimer_kill(tb_ltimer_ref_t timer); + /*! clear timer * * @param timer the timer @@ -105,17 +111,17 @@ tb_size_t tb_ltimer_delay(tb_ltimer_ref_t timer); /*! spak timer for the external loop at the single thread * * @code - * tb_void_t tb_ltimer_loop() - * { - * while (1) - * { - * // wait - * wait(tb_ltimer_delay(timer)) - * - * // spak timer - * tb_ltimer_spak(timer); - * } - * } + tb_void_t tb_ltimer_loop() + { + while (1) + { + // wait + wait(tb_ltimer_delay(timer)) + + // spak timer + tb_ltimer_spak(timer); + } + } * @endcode * * @param timer the timer @@ -127,11 +133,10 @@ tb_bool_t tb_ltimer_spak(tb_ltimer_ref_t timer); /*! loop timer for the external thread * * @code - * tb_void_t tb_ltimer_thread(tb_cpointer_t priv) - - * { - * tb_ltimer_loop(timer); - * } + tb_void_t tb_ltimer_thread(tb_cpointer_t priv) + { + tb_ltimer_loop(timer); + } * @endcode * * @param timer the timer diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/prefix.h b/core/pkg/tbox.pkg/inc/tbox/platform/prefix.h index 0795b9f37..c5791eab9 100644 --- a/core/pkg/tbox.pkg/inc/tbox/platform/prefix.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/prefix.h @@ -48,12 +48,23 @@ * types */ +/*! the iovec size type + * + * @note + * we cannot use tb_size_t because sizeof(tb_size_t) != sizeof(u_long) for windows 64bits + */ +#ifdef TB_CONFIG_OS_WINDOWS +typedef unsigned long tb_iovec_size_t; +#else +typedef tb_size_t tb_iovec_size_t; +#endif + #ifdef TB_CONFIG_OS_WINDOWS /// the iovec type for WSASend, WSARecv using WSABUF typedef struct __tb_iovec_t { /// the size - tb_size_t size; + tb_iovec_size_t size; /// the data tb_byte_t* data; @@ -67,7 +78,7 @@ typedef struct __tb_iovec_t tb_byte_t* data; /// the size - tb_size_t size; + tb_iovec_size_t size; }tb_iovec_t; #endif diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/process.h b/core/pkg/tbox.pkg/inc/tbox/platform/process.h index 1bc0d09c7..dab5ac300 100644 --- a/core/pkg/tbox.pkg/inc/tbox/platform/process.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/process.h @@ -35,16 +35,220 @@ __tb_extern_c_enter__ /* ////////////////////////////////////////////////////////////////////////////////////// + * types + */ + +/// the process flag enum +typedef enum __tb_process_flag_e +{ + TB_PROCESS_FLAG_NONE = 0 +, TB_PROCESS_FLAG_SUSPEND = 1 //!< suspend process + +}tb_process_flag_e; + +/// the process attribute type +typedef struct __tb_process_attr_t +{ + /// the flags + tb_size_t flags; + + /// the stdout filename + tb_char_t const* outfile; + + /*! the stdout filemode + * + * default: TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC + * + * support: + * + * - TB_FILE_MODE_WO + * - TB_FILE_MODE_RW + * - TB_FILE_MODE_CREAT + * - TB_FILE_MODE_APPEND + * - TB_FILE_MODE_TRUNC + */ + tb_size_t outmode; + + /// the stderr filename + tb_char_t const* errfile; + + /// the stderr filemode + tb_size_t errmode; + + /*! the environment + * + * @code + + tb_char_t const* envp[] = + { + "path=/usr/bin" + , tb_null + }; + + attr.envp = envp; + + * @endcode + * + * the envp argument is an array of pointers to null-terminated strings + * and must be terminated by a null pointer + * + * if the value of envp is null, then the child process inherits + * the environment of the parent process. + */ + tb_char_t const** envp; + +}tb_process_attr_t, *tb_process_attr_ref_t; + +/// the process ref type +typedef struct{}* tb_process_ref_t; + +/* ////////////////////////////////////////////////////////////////////////////////////// * interfaces */ -/*! done the command line +/*! run a given process + * + * @code + + // init argv + tb_char_t const* argv[] = + { + "echo" + , "hello" + , tb_null + }; + + // init envp + tb_char_t const* envp[] = + { + "path=/usr/bin" + , tb_null + }; + + // init attr + tb_process_attr_t attr = {0}; + attr.envp = envp; + + // run bash + if (tb_process_run("echo", argv, &attr) == 0) + { + // trace + tb_trace_i("ok"); + } + + // run bash + if (tb_process_run("/bin/echo", tb_null, tb_null) == 0) + { + // trace + tb_trace_i("ok"); + } + + * @endcode + * + * @param pathname the process path or name + * @param argv the list of arguments must be terminated by a null pointer + * and must be terminated by a null pointer + * and argv[0] is the self path name + * @param attr the process attributes + * + * @return the status value, failed: -1, ok: 0, other: error code + */ +tb_long_t tb_process_run(tb_char_t const* pathname, tb_char_t const* argv[], tb_process_attr_ref_t attr); + +/*! run a given process from the command line + * + * @param cmd the command line + * @param attr the process attributes + * + * @return the status value, failed: -1, ok: 0, other: error code + */ +tb_long_t tb_process_run_cmd(tb_char_t const* cmd, tb_process_attr_ref_t attr); + +/*! init a given process * - * @param line the command line + * @code + + // init process + tb_process_ref_t process = tb_process_init("/bin/echo", tb_null, tb_null); + if (process) + { + // wait process + tb_long_t status = 0; + if (tb_process_wait(process, &status, 10) > 0) + { + // trace + tb_trace_i("process exited: %ld", status); + } + // kill process + else + { + // kill it + tb_process_kill(process); + + // wait it again + tb_process_wait(process, &status, -1); + } + + // exit process + tb_process_exit(process); + } + + * @endcode + * + * @param pathname the process path or name + * + * @param argv the list of arguments must be terminated by a null pointer + * and must be terminated by a null pointer + * and argv[0] is the self path name + * + * @param attr the process attributes + * + * @return the process + */ +tb_process_ref_t tb_process_init(tb_char_t const* pathname, tb_char_t const* argv[], tb_process_attr_ref_t attr); + +/*! init a given process from the command line + * + * @param cmd the command line + * @param attr the process attributes + * + * @return the process + */ +tb_process_ref_t tb_process_init_cmd(tb_char_t const* cmd, tb_process_attr_ref_t attr); + +/*! exit the process + * + * @param process the process + */ +tb_void_t tb_process_exit(tb_process_ref_t process); + +/*! kill the process + * + * @param process the process + */ +tb_void_t tb_process_kill(tb_process_ref_t process); + +/*! resume the process + * + * @param process the process + */ +tb_void_t tb_process_resume(tb_process_ref_t process); + +/*! suspend the process + * + * @param process the process + */ +tb_void_t tb_process_suspend(tb_process_ref_t process); + +/*! wait the process + * + * @param process the process + * @param pstatus the process exited status pointer, maybe null + * @param timeout the timeout (ms), infinity: -1 * - * @return tb_true or tb_false + * @return wait failed: -1, timeout: 0, ok: 1 */ -tb_bool_t tb_process_done(tb_char_t const* line); +tb_long_t tb_process_wait(tb_process_ref_t process, tb_long_t* pstatus, tb_long_t timeout); /* ////////////////////////////////////////////////////////////////////////////////////// * extern diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/socket.h b/core/pkg/tbox.pkg/inc/tbox/platform/socket.h index 2f05ca48e..2022aa4a1 100644 --- a/core/pkg/tbox.pkg/inc/tbox/platform/socket.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/socket.h @@ -66,6 +66,8 @@ typedef enum __tb_socket_ctrl_e , TB_SOCKET_CTRL_GET_RECV_BUFF_SIZE = 3 , TB_SOCKET_CTRL_SET_SEND_BUFF_SIZE = 4 , TB_SOCKET_CTRL_GET_SEND_BUFF_SIZE = 5 +, TB_SOCKET_CTRL_SET_TCP_NODELAY = 6 +, TB_SOCKET_CTRL_GET_TCP_NODELAY = 7 }tb_socket_ctrl_e; diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/timer.h b/core/pkg/tbox.pkg/inc/tbox/platform/timer.h index 6f598793a..ef9968195 100644 --- a/core/pkg/tbox.pkg/inc/tbox/platform/timer.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/timer.h @@ -76,6 +76,12 @@ tb_timer_ref_t tb_timer_init(tb_size_t maxn, tb_bool_t ctime); */ tb_void_t tb_timer_exit(tb_timer_ref_t timer); +/*! kill timer for tb_timer_loop() + * + * @param timer the timer + */ +tb_void_t tb_timer_kill(tb_timer_ref_t timer); + /*! clear timer * * @param timer the timer diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/windows/atomic.h b/core/pkg/tbox.pkg/inc/tbox/platform/windows/atomic.h index 87f4f161c..2df848185 100644 --- a/core/pkg/tbox.pkg/inc/tbox/platform/windows/atomic.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/windows/atomic.h @@ -27,7 +27,6 @@ * includes */ #include "prefix.h" -#include "interface/interface.h" /* ////////////////////////////////////////////////////////////////////////////////////// * macros @@ -61,10 +60,9 @@ static __tb_inline__ tb_long_t tb_atomic_fetch_and_pset_windows(tb_atomic_t* a, { // check tb_assert_static(sizeof(tb_atomic_t) == sizeof(LONGLONG)); - tb_assert(tb_kernel32()->InterlockedCompareExchange64); // done - return (tb_long_t)tb_kernel32()->InterlockedCompareExchange64((LONGLONG __tb_volatile__*)a, v, p); + return (tb_long_t)InterlockedCompareExchange64((LONGLONG __tb_volatile__*)a, v, p); } #else static __tb_inline__ tb_long_t tb_atomic_fetch_and_set_windows(tb_atomic_t* a, tb_long_t v) diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/kernel32.h b/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/kernel32.h index aafd97c91..b9f3f3773 100644 --- a/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/kernel32.h +++ b/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/kernel32.h @@ -68,6 +68,36 @@ typedef DWORD (WINAPI* tb_kernel32_GetEnvironmentVariableW_t)(LPCWSTR lpName, LP // the SetEnvironmentVariableW func type typedef BOOL (WINAPI* tb_kernel32_SetEnvironmentVariableW_t)(LPCWSTR lpName, LPCWSTR lpValue); +// the CreateProcessW func type +typedef BOOL (WINAPI* tb_kernel32_CreateProcessW_t)(LPCWSTR lpApplicationName, LPCWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFO lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation); + +// the CloseHandle func type +typedef BOOL (WINAPI* tb_kernel32_CloseHandle_t)(HANDLE hObject); + +// the WaitForSingleObject func type +typedef DWORD (WINAPI* tb_kernel32_WaitForSingleObject_t)(HANDLE hHandle, DWORD dwMilliseconds); + +// the GetExitCodeProcess func type +typedef BOOL (WINAPI* tb_kernel32_GetExitCodeProcess_t)(HANDLE hProcess, LPDWORD lpExitCode); + +// the TerminateProcess func type +typedef BOOL (WINAPI* tb_kernel32_TerminateProcess_t)(HANDLE hProcess, UINT uExitCode); + +// the SuspendThread func type +typedef DWORD (WINAPI* tb_kernel32_SuspendThread_t)(HANDLE hThread); + +// the ResumeThread func type +typedef DWORD (WINAPI* tb_kernel32_ResumeThread_t)(HANDLE hThread); + +// the GetEnvironmentStringsW func type +typedef LPWCH (WINAPI* tb_kernel32_GetEnvironmentStringsW_t)(tb_void_t); + +// the FreeEnvironmentStringsW func type +typedef DWORD (WINAPI* tb_kernel32_FreeEnvironmentStringsW_t)(LPWCH lpszEnvironmentBlock); + +// the SetHandleInformation func type +typedef BOOL (WINAPI* tb_kernel32_SetHandleInformation_t)(HANDLE hObject, DWORD dwMask, DWORD dwFlags); + // the kernel32 interfaces type typedef struct __tb_kernel32_t { @@ -92,7 +122,37 @@ typedef struct __tb_kernel32_t // SetEnvironmentVariableW tb_kernel32_SetEnvironmentVariableW_t SetEnvironmentVariableW; -}tb_kernel32_t,*tb_kernel32_ref_t; + // CreateProcessW + tb_kernel32_CreateProcessW_t CreateProcessW; + + // CloseHandle + tb_kernel32_CloseHandle_t CloseHandle; + + // WaitForSingleObject + tb_kernel32_WaitForSingleObject_t WaitForSingleObject; + + // GetExitCodeProcess + tb_kernel32_GetExitCodeProcess_t GetExitCodeProcess; + + // TerminateProcess + tb_kernel32_TerminateProcess_t TerminateProcess; + + // SuspendThread + tb_kernel32_SuspendThread_t SuspendThread; + + // ResumeThread + tb_kernel32_ResumeThread_t ResumeThread; + + // GetEnvironmentStringsW + tb_kernel32_GetEnvironmentStringsW_t GetEnvironmentStringsW; + + // FreeEnvironmentStringsW + tb_kernel32_FreeEnvironmentStringsW_t FreeEnvironmentStringsW; + + // SetHandleInformation + tb_kernel32_SetHandleInformation_t SetHandleInformation; + +}tb_kernel32_t, *tb_kernel32_ref_t; /* ////////////////////////////////////////////////////////////////////////////////////// * interfaces diff --git a/core/pkg/tbox.pkg/inc/tbox/prefix/abort.h b/core/pkg/tbox.pkg/inc/tbox/prefix/abort.h index a882013f9..3b52d631c 100644 --- a/core/pkg/tbox.pkg/inc/tbox/prefix/abort.h +++ b/core/pkg/tbox.pkg/inc/tbox/prefix/abort.h @@ -36,7 +36,7 @@ // abort it, @note ud2 cannot be aborted immediately for multi-thread #if defined(TB_ARCH_x86) || defined(TB_ARCH_x64) -# if defined(TB_ASSEMBLER_IS_MASM) +# if defined(TB_ASSEMBLER_IS_MASM) && !defined(TB_ARCH_x64) //# define tb_abort_done() do { __tb_asm__ { ud2 } } while (0) # define tb_abort_done() do { __tb_asm__ { int 3 } } while (0) # elif defined(TB_ASSEMBLER_IS_GAS) diff --git a/core/pkg/tbox.pkg/inc/tbox/prefix/assert.h b/core/pkg/tbox.pkg/inc/tbox/prefix/assert.h index 5de2fd942..ab5771310 100644 --- a/core/pkg/tbox.pkg/inc/tbox/prefix/assert.h +++ b/core/pkg/tbox.pkg/inc/tbox/prefix/assert.h @@ -70,12 +70,12 @@ __tb_extern_c_enter__ # define tb_assertf_and_check_continue(x, fmt, ...) tb_assertf(x, fmt, __VA_ARGS__) # else # define tb_assertf -# define tb_assertf_and_check_abort tb_abort(); -# define tb_assertf_and_check_return tb_abort(); -# define tb_assertf_and_check_return_val tb_abort(); -# define tb_assertf_and_check_goto tb_abort(); -# define tb_assertf_and_check_break tb_abort(); -# define tb_assertf_and_check_continue tb_abort(); +# define tb_assertf_and_check_abort +# define tb_assertf_and_check_return +# define tb_assertf_and_check_return_val +# define tb_assertf_and_check_goto +# define tb_assertf_and_check_break +# define tb_assertf_and_check_continue # endif #else # if defined(TB_COMPILER_IS_GCC) @@ -95,13 +95,13 @@ __tb_extern_c_enter__ # define tb_assertf_and_check_break(x, fmt, ...) tb_check_break(x) # define tb_assertf_and_check_continue(x, fmt, ...) tb_check_continue(x) # else -# define tb_assertf tb_abort(); -# define tb_assertf_and_check_abort tb_abort(); -# define tb_assertf_and_check_return tb_abort(); -# define tb_assertf_and_check_return_val tb_abort(); -# define tb_assertf_and_check_goto tb_abort(); -# define tb_assertf_and_check_break tb_abort(); -# define tb_assertf_and_check_continue tb_abort(); +# define tb_assertf +# define tb_assertf_and_check_abort +# define tb_assertf_and_check_return +# define tb_assertf_and_check_return_val +# define tb_assertf_and_check_goto +# define tb_assertf_and_check_break +# define tb_assertf_and_check_continue # endif #endif @@ -125,6 +125,120 @@ __tb_extern_c_enter__ # define tb_assert_and_check_break_state(x, s, v) tb_check_break_state(x, s, v) #endif +// assert and pass code, not abort it +#ifdef __tb_debug__ +# if defined(TB_COMPILER_IS_GCC) +# define tb_assertf_pass_return(x, fmt, arg...) do { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, ##arg); tb_assert_backtrace_dump(); tb_trace_sync(); return ; } } while(0) +# define tb_assertf_pass_return_val(x, v, fmt, arg...) do { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, ##arg); tb_assert_backtrace_dump(); tb_trace_sync(); return (v); } } while(0) +# define tb_assertf_pass_goto(x, b, fmt, arg...) do { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, ##arg); tb_assert_backtrace_dump(); tb_trace_sync(); goto b; } } while(0) +# define tb_assertf_pass_break(x, fmt, arg...) { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, ##arg); tb_assert_backtrace_dump(); tb_trace_sync(); break ; } } +# define tb_assertf_pass_continue(x, fmt, arg...) { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, ##arg); tb_assert_backtrace_dump(); tb_trace_sync(); continue ; } } +# define tb_assertf_pass_and_check_abort(x, fmt, arg...) tb_assertf_pass_abort(x, fmt, ##arg) +# define tb_assertf_pass_and_check_return(x, fmt, arg...) tb_assertf_pass_return(x, fmt, ##arg) +# define tb_assertf_pass_and_check_return_val(x, v, fmt, arg...) tb_assertf_pass_return_val(x, v, fmt, ##arg) +# define tb_assertf_pass_and_check_goto(x, b, fmt, arg...) tb_assertf_pass_goto(x, b, fmt, ##arg) +# define tb_assertf_pass_and_check_break(x, fmt, arg...) tb_assertf_pass_break(x, fmt, ##arg) +# define tb_assertf_pass_and_check_continue(x, fmt, arg...) tb_assertf_pass_continue(x, fmt, ##arg) +# elif defined(TB_COMPILER_IS_MSVC) && TB_COMPILER_VERSION_BE(13, 0) +# define tb_assertf_pass_return(x, fmt, ...) do { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, __VA_ARGS__); tb_assert_backtrace_dump(); tb_trace_sync(); return ; } } while(0) +# define tb_assertf_pass_return_val(x, v, fmt, ...) do { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, __VA_ARGS__); tb_assert_backtrace_dump(); tb_trace_sync(); return (v); } } while(0) +# define tb_assertf_pass_goto(x, b, fmt, ...) do { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, __VA_ARGS__); tb_assert_backtrace_dump(); tb_trace_sync(); goto b; } } while(0) +# define tb_assertf_pass_break(x, fmt, ...) { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, __VA_ARGS__); tb_assert_backtrace_dump(); tb_trace_sync(); break ; } } +# define tb_assertf_pass_continue(x, fmt, ...) { if (!(x)) {tb_trace_a("expr[%s]: " fmt, #x, __VA_ARGS__); tb_assert_backtrace_dump(); tb_trace_sync(); continue ; } } +# define tb_assertf_pass_and_check_abort(x, fmt, ...) tb_assertf_pass_abort(x, fmt, __VA_ARGS__) +# define tb_assertf_pass_and_check_return(x, fmt, ...) tb_assertf_pass_return(x, fmt, __VA_ARGS__) +# define tb_assertf_pass_and_check_return_val(x, v, fmt, ...) tb_assertf_pass_return_val(x, v, fmt, __VA_ARGS__) +# define tb_assertf_pass_and_check_goto(x, b, fmt, ...) tb_assertf_pass_goto(x, b, fmt, __VA_ARGS__) +# define tb_assertf_pass_and_check_break(x, fmt, ...) tb_assertf_pass_break(x, fmt, __VA_ARGS__) +# define tb_assertf_pass_and_check_continue(x, fmt, ...) tb_assertf_pass_continue(x, fmt, __VA_ARGS__) +# else +# define tb_assertf_pass_return +# define tb_assertf_pass_return_val +# define tb_assertf_pass_goto +# define tb_assertf_pass_break +# define tb_assertf_pass_continue +# define tb_assertf_pass_and_check_abort +# define tb_assertf_pass_and_check_return +# define tb_assertf_pass_and_check_return_val +# define tb_assertf_pass_and_check_goto +# define tb_assertf_pass_and_check_break +# define tb_assertf_pass_and_check_continue +# endif +#else +# if defined(TB_COMPILER_IS_GCC) +# define tb_assertf_pass_return(x, fmt, arg...) +# define tb_assertf_pass_return_val(x, v, fmt, arg...) +# define tb_assertf_pass_goto(x, b, fmt, arg...) +# define tb_assertf_pass_break(x, fmt, arg...) +# define tb_assertf_pass_continue(x, fmt, arg...) +# define tb_assertf_pass_and_check_abort(x, fmt, arg...) tb_check_abort(x) +# define tb_assertf_pass_and_check_return(x, fmt, arg...) tb_check_return(x) +# define tb_assertf_pass_and_check_return_val(x, v, fmt, arg...) tb_check_return_val(x, v) +# define tb_assertf_pass_and_check_goto(x, b, fmt, arg...) tb_check_goto(x, b) +# define tb_assertf_pass_and_check_break(x, fmt, arg...) tb_check_break(x) +# define tb_assertf_pass_and_check_continue(x, fmt, arg...) tb_check_continue(x) +# elif defined(TB_COMPILER_IS_MSVC) && TB_COMPILER_VERSION_BE(13, 0) +# define tb_assertf_pass_return(x, fmt, ...) +# define tb_assertf_pass_return_val(x, v, fmt, ...) +# define tb_assertf_pass_goto(x, b, fmt, ...) +# define tb_assertf_pass_break(x, fmt, ...) +# define tb_assertf_pass_continue(x, fmt, ...) +# define tb_assertf_pass_and_check_abort(x, fmt, ...) tb_check_abort(x) +# define tb_assertf_pass_and_check_return(x, fmt, ...) tb_check_return(x) +# define tb_assertf_pass_and_check_return_val(x, v, fmt, ...) tb_check_return_val(x, v) +# define tb_assertf_pass_and_check_goto(x, b, fmt, ...) tb_check_goto(x, b) +# define tb_assertf_pass_and_check_break(x, fmt, ...) tb_check_break(x) +# define tb_assertf_pass_and_check_continue(x, fmt, ...) tb_check_continue(x) +# else +# define tb_assertf_pass_return +# define tb_assertf_pass_return_val +# define tb_assertf_pass_goto +# define tb_assertf_pass_break +# define tb_assertf_pass_continue +# define tb_assertf_pass_and_check_abort +# define tb_assertf_pass_and_check_return +# define tb_assertf_pass_and_check_return_val +# define tb_assertf_pass_and_check_goto +# define tb_assertf_pass_and_check_break +# define tb_assertf_pass_and_check_continue +# endif +#endif + +#ifdef __tb_debug__ +# define tb_assert_pass_return(x) do { if (!(x)) {tb_trace_a("expr[%s]", #x); tb_assert_backtrace_dump(); tb_trace_sync(); return ; } } while(0) +# define tb_assert_pass_return_val(x, v) do { if (!(x)) {tb_trace_a("expr[%s]", #x); tb_assert_backtrace_dump(); tb_trace_sync(); return (v); } } while(0) +# define tb_assert_pass_goto(x, b) do { if (!(x)) {tb_trace_a("expr[%s]", #x); tb_assert_backtrace_dump(); tb_trace_sync(); goto b; } } while(0) +# define tb_assert_pass_break(x) { if (!(x)) {tb_trace_a("expr[%s]", #x); tb_assert_backtrace_dump(); tb_trace_sync(); break ; } } +# define tb_assert_pass_continue(x) { if (!(x)) {tb_trace_a("expr[%s]", #x); tb_assert_backtrace_dump(); tb_trace_sync(); continue ; } } +# define tb_assert_pass_break_state(x, s, v) { if (!(x)) { (s) = (v); tb_trace_a("expr[%s]", #x); tb_assert_backtrace_dump(); tb_trace_sync(); break ; } } + +# define tb_assert_pass_and_check_abort(x) tb_assert_pass_abort(x) +# define tb_assert_pass_and_check_return(x) tb_assert_pass_return(x) +# define tb_assert_pass_and_check_return_val(x, v) tb_assert_pass_return_val(x, v) +# define tb_assert_pass_and_check_goto(x, b) tb_assert_pass_goto(x, b) +# define tb_assert_pass_and_check_break(x) tb_assert_pass_break(x) +# define tb_assert_pass_and_check_continue(x) tb_assert_pass_continue(x) +# define tb_assert_pass_and_check_break_state(x, s, v) tb_assert_pass_break_state(x, s, v) +#else +# define tb_assert_pass_return(x) +# define tb_assert_pass_return_val(x, v) +# define tb_assert_pass_goto(x, b) +# define tb_assert_pass_break(x) +# define tb_assert_pass_continue(x) +# define tb_assert_pass_break_state(x, s, v) + +# define tb_assert_pass_and_check_abort(x) tb_check_abort(x) +# define tb_assert_pass_and_check_return(x) tb_check_return(x) +# define tb_assert_pass_and_check_return_val(x, v) tb_check_return_val(x, v) +# define tb_assert_pass_and_check_goto(x, b) tb_check_goto(x, b) +# define tb_assert_pass_and_check_break(x) tb_check_break(x) +# define tb_assert_pass_and_check_continue(x) tb_check_continue(x) +# define tb_assert_pass_and_check_break_state(x, s, v) tb_check_break_state(x, s, v) +#endif + +/// assert: noimpl +#define tb_assert_noimpl() tb_assertf(0, "noimpl") + /*! the static assert * * @code diff --git a/core/pkg/tbox.pkg/inc/tbox/prefix/compiler.h b/core/pkg/tbox.pkg/inc/tbox/prefix/compiler.h index 46ab41c88..4d50eacc2 100644 --- a/core/pkg/tbox.pkg/inc/tbox/prefix/compiler.h +++ b/core/pkg/tbox.pkg/inc/tbox/prefix/compiler.h @@ -306,6 +306,8 @@ # pragma warning(disable:4197) # pragma warning(disable:4141) # pragma warning(disable:4996) +# pragma warning(disable:4359) +# pragma warning(disable:4838) #else # define TB_COMPILER_STRING "unknown compiler" diff --git a/core/pkg/tbox.pkg/inc/tbox/prefix/cpu.h b/core/pkg/tbox.pkg/inc/tbox/prefix/cpu.h index 1ce3717de..fab6bb866 100644 --- a/core/pkg/tbox.pkg/inc/tbox/prefix/cpu.h +++ b/core/pkg/tbox.pkg/inc/tbox/prefix/cpu.h @@ -33,15 +33,22 @@ */ // check 64-bits -#if defined (__LP64__) \ - || defined (__64BIT__) \ - || defined (_LP64) \ - || defined (__x86_64) \ - || defined (__x86_64__) \ - || defined (__amd64) \ - || defined (__amd64__) \ - || defined (__arm64) \ - || defined (__arm64__) \ +#if defined(__LP64__) \ + || defined(__64BIT__) \ + || defined(_LP64) \ + || defined(__x86_64) \ + || defined(__x86_64__) \ + || defined(__amd64) \ + || defined(__amd64__) \ + || defined(__arm64) \ + || defined(__arm64__) \ + || defined(__sparc64__) \ + || defined(__PPC64__) \ + || defined(__ppc64__) \ + || defined(__powerpc64__) \ + || defined(_M_X64) \ + || defined(_M_AMD64) \ + || defined(_M_IA64) \ || (defined(__WORDSIZE) && (__WORDSIZE == 64)) # define TB_CPU_BITSIZE (64) # define TB_CPU_BITBYTE (8) diff --git a/core/pkg/tbox.pkg/inc/tbox/prefix/type.h b/core/pkg/tbox.pkg/inc/tbox/prefix/type.h index d8b08ee95..400ac88bc 100644 --- a/core/pkg/tbox.pkg/inc/tbox/prefix/type.h +++ b/core/pkg/tbox.pkg/inc/tbox/prefix/type.h @@ -118,13 +118,18 @@ typedef unsigned long long tb_uint64_t; #endif typedef tb_int64_t tb_sint64_t; -// hong & hize +// hong and hize typedef tb_sint64_t tb_hong_t; typedef tb_uint64_t tb_hize_t; -// long & size +// long and size +#if defined(TB_CONFIG_OS_WINDOWS) && TB_CPU_BIT64 +typedef tb_int64_t tb_long_t; +typedef tb_uint64_t tb_ulong_t; +#else typedef signed long tb_long_t; typedef unsigned long tb_ulong_t; +#endif typedef tb_ulong_t tb_size_t; // double @@ -140,7 +145,11 @@ typedef tb_int32_t tb_fixed30_t; typedef tb_fixed16_t tb_fixed_t; /// the atomic type +#if TB_CPU_BIT64 +typedef __tb_volatile__ __tb_aligned__(8) tb_long_t tb_atomic_t; +#else typedef __tb_volatile__ __tb_aligned__(4) tb_long_t tb_atomic_t; +#endif /// the atomic64 type, need be aligned for arm, .. typedef __tb_volatile__ __tb_aligned__(8) tb_hong_t tb_atomic64_t; diff --git a/core/pkg/tbox.pkg/inc/tbox/prefix/utils.h b/core/pkg/tbox.pkg/inc/tbox/prefix/utils.h index 51c4e35b5..4bd0e7a46 100644 --- a/core/pkg/tbox.pkg/inc/tbox/prefix/utils.h +++ b/core/pkg/tbox.pkg/inc/tbox/prefix/utils.h @@ -72,7 +72,7 @@ #define tb_align_u64(x, b) (((tb_uint64_t)(x) + ((tb_uint64_t)(b) - 1)) & ~((tb_uint64_t)(b) - 1)) /// align by pow2 -#define tb_align_pow2(x) (((x) > 1)? (tb_ispow2(x)? (x) : (1 << (32 - tb_bits_cl0_u32_be((tb_uint32_t)(x))))) : 1) +#define tb_align_pow2(x) (((x) > 1)? (tb_ispow2(x)? (x) : ((tb_size_t)1 << (32 - tb_bits_cl0_u32_be((tb_uint32_t)(x))))) : 1) /*! @def tb_align_cpu * diff --git a/core/pkg/tbox.pkg/inc/tbox/regex/prefix.h b/core/pkg/tbox.pkg/inc/tbox/regex/prefix.h new file mode 100755 index 000000000..4ca191d5a --- /dev/null +++ b/core/pkg/tbox.pkg/inc/tbox/regex/prefix.h @@ -0,0 +1,35 @@ +/*!The Treasure Box Library + * + * TBox is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * TBox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TBox; + * If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> + * + * Copyright (C) 2009 - 2015, ruki All rights reserved. + * + * @author ruki + * @file prefix.h + * @ingroup regex + * + */ +#ifndef TB_REGEX_PREFIX_H +#define TB_REGEX_PREFIX_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "../prefix.h" +#include "../libc/libc.h" +#include "../container/container.h" + + +#endif diff --git a/core/pkg/tbox.pkg/inc/tbox/regex/regex.h b/core/pkg/tbox.pkg/inc/tbox/regex/regex.h new file mode 100755 index 000000000..f80f0366a --- /dev/null +++ b/core/pkg/tbox.pkg/inc/tbox/regex/regex.h @@ -0,0 +1,410 @@ +/*!The Treasure Box Library + * + * TBox is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * TBox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TBox; + * If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> + * + * Copyright (C) 2009 - 2015, ruki All rights reserved. + * + * @author ruki + * @file regex.h + * @defgroup regex + */ +#ifndef TB_REGEX_H +#define TB_REGEX_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * types + */ + +/// the regex ref type +typedef struct{}* tb_regex_ref_t; + +/// the regex match type +typedef struct _tb_regex_match_t +{ + /// the c-string data + tb_char_t const* cstr; + + /// the c-string size + tb_size_t size; + + /// the matched start position + tb_size_t start; + +}tb_regex_match_t, *tb_regex_match_ref_t; + +/// the regex mode enum +typedef enum __tb_regex_mode_e +{ + TB_REGEX_MODE_NONE = 0 //!< the default mode +, TB_REGEX_MODE_CASELESS = 1 //!< do caseless matching +, TB_REGEX_MODE_MULTILINE = 2 //!< ^ and $ match newlines within data +, TB_REGEX_MODE_GLOBAL = 4 //!< global replace all + +}tb_regex_mode_e; + + +/* ////////////////////////////////////////////////////////////////////////////////////// + * interfaces + */ + +/*! init regex + * + * @param pattern the regex pattern + * @param mode the regex mode, uses the default mode if be zero + * + * @return the regex + */ +tb_regex_ref_t tb_regex_init(tb_char_t const* pattern, tb_size_t mode); + +/*! exit regex + * + * @param regex the regex + */ +tb_void_t tb_regex_exit(tb_regex_ref_t regex); + +/*! match the given c-string and size by regex + * + * @param regex the regex + * @param cstr the c-string data + * @param size the c-string size + * @param start the start position + * @param plength the matched length pointer, do not get it if be null + * @param presults the results pointer, only match it if be null + * + * @return the matched position, not match: -1 + */ +tb_long_t tb_regex_match(tb_regex_ref_t regex, tb_char_t const* cstr, tb_size_t size, tb_size_t start, tb_size_t* plength, tb_vector_ref_t* presults); + +/*! match the given c-string by regex + * + * @code + + // init regex + tb_regex_ref_t regex = tb_regex_init("\\w+", 0); + if (regex) + { + // match single + // + // results: "hello" + // + tb_vector_ref_t results = tb_null; + if (tb_regex_match_cstr(regex, "hello world", 0, tb_null, &results) >= 0 && results) + { + // show results + tb_for_all_if (tb_regex_match_ref_t, entry, results, entry) + { + // trace + tb_trace_i("cstr: %s, size: %lu, start: %lu", entry->cstr, entry->size, entry->start); + } + } + + // match global + // + // results: "hello" + // results: "world" + // + tb_long_t start = 0; + tb_size_t length = 0; + tb_vector_ref_t results = tb_null; + while ((start = tb_regex_match_cstr(regex, "hello world", start + length, &length, &results)) >= 0 && results) + { + // show results + tb_for_all_if (tb_regex_match_ref_t, entry, results, entry) + { + // trace + tb_trace_i("cstr: %s, size: %lu, start: %lu", entry->cstr, entry->size, entry->start); + } + } + + // exit regex + tb_regex_exit(regex); + } + * @endcode + * + * @param regex the regex + * @param cstr the c-string + * @param start the start position + * @param plength the matched length pointer, do not get it if be null + * @param presults the results pointer, only match it if be null + * + * @return the matched position, not match: -1 + */ +tb_long_t tb_regex_match_cstr(tb_regex_ref_t regex, tb_char_t const* cstr, tb_size_t start, tb_size_t* plength, tb_vector_ref_t* presults); + +/*! simply match the given c-string by regex + * + * @note only supports single match + * + * @code + + // init regex + tb_regex_ref_t regex = tb_regex_init("\\w+", 0); + if (regex) + { + // match single + // + // results: "hello" + // + tb_vector_ref_t results = tb_regex_match_simple(regex, "hello world"); + if (results) + { + // show results + tb_for_all_if (tb_regex_match_ref_t, entry, results, entry) + { + // trace + tb_trace_i("cstr: %s, size: %lu, start: %lu", entry->cstr, entry->size, entry->start); + } + } + + // exit regex + tb_regex_exit(regex); + } + * @endcode + * + * @param regex the regex + * @param cstr the c-string + * + * @return the matched results + */ +tb_vector_ref_t tb_regex_match_simple(tb_regex_ref_t regex, tb_char_t const* cstr); + +/*! replace the given c-string and size by regex + * + * @param regex the regex + * @param cstr the c-string data + * @param size the c-string size + * @param start the start position + * @param replace_cstr the replacement c-string data + * @param replace_size the replacement c-string size + * @param plength the result c-string length pointer, do not get it if be null + * + * @return the result c-string + */ +tb_char_t const* tb_regex_replace(tb_regex_ref_t regex, tb_char_t const* cstr, tb_size_t size, tb_size_t start, tb_char_t const* replace_cstr, tb_size_t replace_size, tb_size_t* plength); + +/*! replace the given c-string by regex + * + * @param regex the regex + * @param cstr the c-string data + * @param start the start position + * @param replace_cstr the replacement c-string data + * @param plength the result c-string length pointer, do not get it if be null + * + * @return the result c-string + */ +tb_char_t const* tb_regex_replace_cstr(tb_regex_ref_t regex, tb_char_t const* cstr, tb_size_t start, tb_char_t const* replace_cstr, tb_size_t* plength); + +/*! simply replace the given c-string by regex + * + * @code + + // init regex + tb_regex_ref_t regex = tb_regex_init("\\w+", 0); + if (regex) + { + // match single + // + // results: "hi world" + // + tb_char_t const* results = tb_regex_replace_simple(regex, "hello world", "hi"); + if (results) + { + // trace + tb_trace_i("results: %s", results); + } + + // exit regex + tb_regex_exit(regex); + } + * @endcode + * + * @param regex the regex + * @param cstr the c-string data + * @param replace_cstr the replacement c-string data + * + * @return the result c-string + */ +tb_char_t const* tb_regex_replace_simple(tb_regex_ref_t regex, tb_char_t const* cstr, tb_char_t const* replace_cstr); + +/*! match the given c-string and size by the given regex pattern + * + * @param pattern the regex pattern + * @param mode the regex mode, uses the default mode if be zero + * @param cstr the c-string data + * @param size the c-string size + * @param start the start position + * @param plength the matched length pointer, do not get it if be null + * @param presults the results pointer, only match it if be null + * @note we need exit it manually + * + * @return the matched position, not match: -1 + */ +tb_long_t tb_regex_match_done(tb_char_t const* pattern, tb_size_t mode, tb_char_t const* cstr, tb_size_t size, tb_size_t start, tb_size_t* plength, tb_vector_ref_t* presults); + +/*! match the given c-string by the given regex pattern + * + * @code + + // match single + // + // results: "hello" + // + tb_vector_ref_t results = tb_null; + if (tb_regex_match_done_cstr("\\w+", 0, "hello world", 0, tb_null, &results) >= 0 && results) + { + // show results + tb_for_all_if (tb_regex_match_ref_t, entry, results, entry) + { + // trace + tb_trace_i("cstr: %s, size: %lu, start: %lu", entry->cstr, entry->size, entry->start); + } + + // exit results + tb_vector_exit(results); + } + + // match global + // + // results: "hello" + // results: "world" + // + tb_long_t start = 0; + tb_size_t length = 0; + tb_vector_ref_t results = tb_null; + while ((start = tb_regex_match_done_cstr("\\w+", 0, "hello world", start + length, &length, &results)) >= 0 && results) + { + // show results + tb_for_all_if (tb_regex_match_ref_t, entry, results, entry) + { + // trace + tb_trace_i("cstr: %s, size: %lu, start: %lu", entry->cstr, entry->size, entry->start); + } + + // exit results + tb_vector_exit(results); + } + + * @endcode + * + * @param pattern the regex pattern + * @param mode the regex mode, uses the default mode if be zero + * @param cstr the c-string data + * @param start the start position + * @param plength the matched length pointer, do not get it if be null + * @param presults the results pointer, only match it if be null + * @note we need exit it manually + * + * @return the matched position, not match: -1 + */ +tb_long_t tb_regex_match_done_cstr(tb_char_t const* pattern, tb_size_t mode, tb_char_t const* cstr, tb_size_t start, tb_size_t* plength, tb_vector_ref_t* presults); + +/*! simply match the given c-string by the given regex pattern + * + * @note only supports single match + * + * @code + + // match single + // + // results: "hello" + // + tb_vector_ref_t results = tb_regex_match_done_simple("\\w+", 0, "hello world"); + if (results) + { + // show results + tb_for_all_if (tb_regex_match_ref_t, entry, results, entry) + { + // trace + tb_trace_i("cstr: %s, size: %lu, start: %lu", entry->cstr, entry->size, entry->start); + } + + // exit results + tb_vector_exit(results); + } + + * @endcode + * + * @param pattern the regex pattern + * @param mode the regex mode, uses the default mode if be zero + * @param cstr the c-string data + * + * @return the matched results, we need exit it manually + */ +tb_vector_ref_t tb_regex_match_done_simple(tb_char_t const* pattern, tb_size_t mode, tb_char_t const* cstr); + +/*! replace the given c-string and size by the given regex pattern + * + * @param pattern the regex pattern + * @param mode the regex mode, uses the default mode if be zero + * @param cstr the c-string data + * @param size the c-string size + * @param start the start position + * @param replace_cstr the replacement c-string data + * @param replace_size the replacement c-string size + * @param plength the result c-string length pointer, do not get it if be null + * + * @return the result c-string + */ +tb_char_t const* tb_regex_replace_done(tb_char_t const* pattern, tb_size_t mode, tb_char_t const* cstr, tb_size_t size, tb_size_t start, tb_char_t const* replace_cstr, tb_size_t replace_size, tb_size_t* plength); + +/*! replace the given c-string by the given regex pattern + * + * @param pattern the regex pattern + * @param mode the regex mode, uses the default mode if be zero + * @param cstr the c-string data + * @param start the start position + * @param replace_cstr the replacement c-string data + * @param plength the result c-string length pointer, do not get it if be null + * + * @return the result c-string + */ +tb_char_t const* tb_regex_replace_done_cstr(tb_char_t const* pattern, tb_size_t mode, tb_char_t const* cstr, tb_size_t start, tb_char_t const* replace_cstr, tb_size_t* plength); + +/*! simply replace the given c-string by the given regex pattern + * + * @code + + // replace single + // + // results: "hi world" + // + tb_char_t const* results = tb_regex_replace_done_simple("\\w+", 0, "hello world", "hi"); + if (results) + { + // trace + tb_trace_i("results: %s", results); + + // exit results + tb_free(results); + } + + * @endcode + * + * @param pattern the regex pattern + * @param mode the regex mode, uses the default mode if be zero + * @param cstr the c-string data + * @param replace_cstr the replacement c-string data + * + * @return the result c-string, @note we need free it manually + */ +tb_char_t const* tb_regex_replace_done_simple(tb_char_t const* pattern, tb_size_t mode, tb_char_t const* cstr, tb_char_t const* replace_cstr); + + +#endif diff --git a/core/pkg/tbox.pkg/inc/tbox/stream/async_stream.h b/core/pkg/tbox.pkg/inc/tbox/stream/async_stream.h index 4f7517d66..0d7c5cece 100644 --- a/core/pkg/tbox.pkg/inc/tbox/stream/async_stream.h +++ b/core/pkg/tbox.pkg/inc/tbox/stream/async_stream.h @@ -418,7 +418,7 @@ tb_async_stream_ref_t tb_async_stream_init_filter_from_chunked(tb_async_stream * * @return the stream url */ -tb_url_ref_t tb_async_stream_url(tb_async_stream_ref_t stream); +tb_url_ref_t tb_async_stream_url(tb_async_stream_ref_t stream); /*! the stream type * diff --git a/core/pkg/tbox.pkg/inc/tbox/stream/stream.h b/core/pkg/tbox.pkg/inc/tbox/stream/stream.h index d41d4f7af..10a906c73 100644 --- a/core/pkg/tbox.pkg/inc/tbox/stream/stream.h +++ b/core/pkg/tbox.pkg/inc/tbox/stream/stream.h @@ -106,81 +106,81 @@ __tb_extern_c_enter__ // the stream bitops #ifdef TB_WORDS_BIGENDIAN -# define tb_stream_bread_u16_ne(stream) tb_stream_bread_u16_be(stream) -# define tb_stream_bread_s16_ne(stream) tb_stream_bread_s16_be(stream) -# define tb_stream_bread_u24_ne(stream) tb_stream_bread_u24_be(stream) -# define tb_stream_bread_s24_ne(stream) tb_stream_bread_s24_be(stream) -# define tb_stream_bread_u32_ne(stream) tb_stream_bread_u32_be(stream) -# define tb_stream_bread_s32_ne(stream) tb_stream_bread_s32_be(stream) -# define tb_stream_bread_u64_ne(stream) tb_stream_bread_u64_be(stream) -# define tb_stream_bread_s64_ne(stream) tb_stream_bread_s64_be(stream) +# define tb_stream_bread_u16_ne(stream, pvalue) tb_stream_bread_u16_be(stream, pvalue) +# define tb_stream_bread_s16_ne(stream, pvalue) tb_stream_bread_s16_be(stream, pvalue) +# define tb_stream_bread_u24_ne(stream, pvalue) tb_stream_bread_u24_be(stream, pvalue) +# define tb_stream_bread_s24_ne(stream, pvalue) tb_stream_bread_s24_be(stream, pvalue) +# define tb_stream_bread_u32_ne(stream, pvalue) tb_stream_bread_u32_be(stream, pvalue) +# define tb_stream_bread_s32_ne(stream, pvalue) tb_stream_bread_s32_be(stream, pvalue) +# define tb_stream_bread_u64_ne(stream, pvalue) tb_stream_bread_u64_be(stream, pvalue) +# define tb_stream_bread_s64_ne(stream, pvalue) tb_stream_bread_s64_be(stream, pvalue) -# define tb_stream_bwrit_u16_ne(stream, val) tb_stream_bwrit_u16_be(stream, val) -# define tb_stream_bwrit_s16_ne(stream, val) tb_stream_bwrit_s16_be(stream, val) -# define tb_stream_bwrit_u24_ne(stream, val) tb_stream_bwrit_u24_be(stream, val) -# define tb_stream_bwrit_s24_ne(stream, val) tb_stream_bwrit_s24_be(stream, val) -# define tb_stream_bwrit_u32_ne(stream, val) tb_stream_bwrit_u32_be(stream, val) -# define tb_stream_bwrit_s32_ne(stream, val) tb_stream_bwrit_s32_be(stream, val) -# define tb_stream_bwrit_u64_ne(stream, val) tb_stream_bwrit_u64_be(stream, val) -# define tb_stream_bwrit_s64_ne(stream, val) tb_stream_bwrit_s64_be(stream, val) +# define tb_stream_bwrit_u16_ne(stream, value) tb_stream_bwrit_u16_be(stream, value) +# define tb_stream_bwrit_s16_ne(stream, value) tb_stream_bwrit_s16_be(stream, value) +# define tb_stream_bwrit_u24_ne(stream, value) tb_stream_bwrit_u24_be(stream, value) +# define tb_stream_bwrit_s24_ne(stream, value) tb_stream_bwrit_s24_be(stream, value) +# define tb_stream_bwrit_u32_ne(stream, value) tb_stream_bwrit_u32_be(stream, value) +# define tb_stream_bwrit_s32_ne(stream, value) tb_stream_bwrit_s32_be(stream, value) +# define tb_stream_bwrit_u64_ne(stream, value) tb_stream_bwrit_u64_be(stream, value) +# define tb_stream_bwrit_s64_ne(stream, value) tb_stream_bwrit_s64_be(stream, value) #else -# define tb_stream_bread_u16_ne(stream) tb_stream_bread_u16_le(stream) -# define tb_stream_bread_s16_ne(stream) tb_stream_bread_s16_le(stream) -# define tb_stream_bread_u24_ne(stream) tb_stream_bread_u24_le(stream) -# define tb_stream_bread_s24_ne(stream) tb_stream_bread_s24_le(stream) -# define tb_stream_bread_u32_ne(stream) tb_stream_bread_u32_le(stream) -# define tb_stream_bread_s32_ne(stream) tb_stream_bread_s32_le(stream) -# define tb_stream_bread_u64_ne(stream) tb_stream_bread_u64_le(stream) -# define tb_stream_bread_s64_ne(stream) tb_stream_bread_s64_le(stream) +# define tb_stream_bread_u16_ne(stream, pvalue) tb_stream_bread_u16_le(stream, pvalue) +# define tb_stream_bread_s16_ne(stream, pvalue) tb_stream_bread_s16_le(stream, pvalue) +# define tb_stream_bread_u24_ne(stream, pvalue) tb_stream_bread_u24_le(stream, pvalue) +# define tb_stream_bread_s24_ne(stream, pvalue) tb_stream_bread_s24_le(stream, pvalue) +# define tb_stream_bread_u32_ne(stream, pvalue) tb_stream_bread_u32_le(stream, pvalue) +# define tb_stream_bread_s32_ne(stream, pvalue) tb_stream_bread_s32_le(stream, pvalue) +# define tb_stream_bread_u64_ne(stream, pvalue) tb_stream_bread_u64_le(stream, pvalue) +# define tb_stream_bread_s64_ne(stream, pvalue) tb_stream_bread_s64_le(stream, pvalue) -# define tb_stream_bwrit_u16_ne(stream, val) tb_stream_bwrit_u16_le(stream, val) -# define tb_stream_bwrit_s16_ne(stream, val) tb_stream_bwrit_s16_le(stream, val) -# define tb_stream_bwrit_u24_ne(stream, val) tb_stream_bwrit_u24_le(stream, val) -# define tb_stream_bwrit_s24_ne(stream, val) tb_stream_bwrit_s24_le(stream, val) -# define tb_stream_bwrit_u32_ne(stream, val) tb_stream_bwrit_u32_le(stream, val) -# define tb_stream_bwrit_s32_ne(stream, val) tb_stream_bwrit_s32_le(stream, val) -# define tb_stream_bwrit_u64_ne(stream, val) tb_stream_bwrit_u64_le(stream, val) -# define tb_stream_bwrit_s64_ne(stream, val) tb_stream_bwrit_s64_le(stream, val) +# define tb_stream_bwrit_u16_ne(stream, value) tb_stream_bwrit_u16_le(stream, value) +# define tb_stream_bwrit_s16_ne(stream, value) tb_stream_bwrit_s16_le(stream, value) +# define tb_stream_bwrit_u24_ne(stream, value) tb_stream_bwrit_u24_le(stream, value) +# define tb_stream_bwrit_s24_ne(stream, value) tb_stream_bwrit_s24_le(stream, value) +# define tb_stream_bwrit_u32_ne(stream, value) tb_stream_bwrit_u32_le(stream, value) +# define tb_stream_bwrit_s32_ne(stream, value) tb_stream_bwrit_s32_le(stream, value) +# define tb_stream_bwrit_u64_ne(stream, value) tb_stream_bwrit_u64_le(stream, value) +# define tb_stream_bwrit_s64_ne(stream, value) tb_stream_bwrit_s64_le(stream, value) #endif #ifdef TB_CONFIG_TYPE_HAVE_FLOAT # ifdef TB_FLOAT_BIGENDIAN -# define tb_stream_bread_double_nbe(stream) tb_stream_bread_double_bbe(stream) -# define tb_stream_bread_double_nle(stream) tb_stream_bread_double_ble(stream) +# define tb_stream_bread_double_nbe(stream, pvalue) tb_stream_bread_double_bbe(stream, pvalue) +# define tb_stream_bread_double_nle(stream, pvalue) tb_stream_bread_double_ble(stream, pvalue) -# define tb_stream_bwrit_double_nbe(stream, val) tb_stream_bwrit_double_bbe(stream, val) -# define tb_stream_bwrit_double_nle(stream, val) tb_stream_bwrit_double_ble(stream, val) +# define tb_stream_bwrit_double_nbe(stream, value) tb_stream_bwrit_double_bbe(stream, value) +# define tb_stream_bwrit_double_nle(stream, value) tb_stream_bwrit_double_ble(stream, value) # else -# define tb_stream_bread_double_nbe(stream) tb_stream_bread_double_lbe(stream) -# define tb_stream_bread_double_nle(stream) tb_stream_bread_double_lle(stream) +# define tb_stream_bread_double_nbe(stream, pvalue) tb_stream_bread_double_lbe(stream, pvalue) +# define tb_stream_bread_double_nle(stream, pvalue) tb_stream_bread_double_lle(stream, pvalue) -# define tb_stream_bwrit_double_nbe(stream, val) tb_stream_bwrit_double_lbe(stream, val) -# define tb_stream_bwrit_double_nle(stream, val) tb_stream_bwrit_double_lle(stream, val) +# define tb_stream_bwrit_double_nbe(stream, value) tb_stream_bwrit_double_lbe(stream, value) +# define tb_stream_bwrit_double_nle(stream, value) tb_stream_bwrit_double_lle(stream, value) # endif # ifdef TB_WORDS_BIGENDIAN -# define tb_stream_bread_float_ne(stream) tb_stream_bread_float_be(stream) -# define tb_stream_bwrit_float_ne(stream, val) tb_stream_bwrit_float_be(stream, val) +# define tb_stream_bread_float_ne(stream, pvalue) tb_stream_bread_float_be(stream, pvalue) +# define tb_stream_bwrit_float_ne(stream, value) tb_stream_bwrit_float_be(stream, value) -# define tb_stream_bread_double_nne(stream) tb_stream_bread_double_nbe(stream) -# define tb_stream_bread_double_bne(stream) tb_stream_bread_double_bbe(stream) -# define tb_stream_bread_double_lne(stream) tb_stream_bread_double_lbe(stream) +# define tb_stream_bread_double_nne(stream, pvalue) tb_stream_bread_double_nbe(stream, pvalue) +# define tb_stream_bread_double_bne(stream, pvalue) tb_stream_bread_double_bbe(stream, pvalue) +# define tb_stream_bread_double_lne(stream, pvalue) tb_stream_bread_double_lbe(stream, pvalue) -# define tb_stream_bwrit_double_nne(stream, val) tb_stream_bwrit_double_nbe(stream, val) -# define tb_stream_bwrit_double_bne(stream, val) tb_stream_bwrit_double_bbe(stream, val) -# define tb_stream_bwrit_double_lne(stream, val) tb_stream_bwrit_double_lbe(stream, val) +# define tb_stream_bwrit_double_nne(stream, value) tb_stream_bwrit_double_nbe(stream, value) +# define tb_stream_bwrit_double_bne(stream, value) tb_stream_bwrit_double_bbe(stream, value) +# define tb_stream_bwrit_double_lne(stream, value) tb_stream_bwrit_double_lbe(stream, value) # else -# define tb_stream_bread_float_ne(stream) tb_stream_bread_float_le(stream) -# define tb_stream_bwrit_float_ne(stream, val) tb_stream_bwrit_float_le(stream, val) +# define tb_stream_bread_float_ne(stream, pvalue) tb_stream_bread_float_le(stream, pvalue) +# define tb_stream_bwrit_float_ne(stream, value) tb_stream_bwrit_float_le(stream, value) -# define tb_stream_bread_double_nne(stream) tb_stream_bread_double_nle(stream) -# define tb_stream_bread_double_bne(stream) tb_stream_bread_double_ble(stream) -# define tb_stream_bread_double_lne(stream) tb_stream_bread_double_lle(stream) +# define tb_stream_bread_double_nne(stream, pvalue) tb_stream_bread_double_nle(stream, pvalue) +# define tb_stream_bread_double_bne(stream, pvalue) tb_stream_bread_double_ble(stream, pvalue) +# define tb_stream_bread_double_lne(stream, pvalue) tb_stream_bread_double_lle(stream, pvalue) -# define tb_stream_bwrit_double_nne(stream, val) tb_stream_bwrit_double_nle(stream, val) -# define tb_stream_bwrit_double_bne(stream, val) tb_stream_bwrit_double_ble(stream, val) -# define tb_stream_bwrit_double_lne(stream, val) tb_stream_bwrit_double_lle(stream, val) +# define tb_stream_bwrit_double_nne(stream, value) tb_stream_bwrit_double_nle(stream, value) +# define tb_stream_bwrit_double_bne(stream, value) tb_stream_bwrit_double_ble(stream, value) +# define tb_stream_bwrit_double_lne(stream, value) tb_stream_bwrit_double_lle(stream, value) # endif #endif @@ -794,412 +794,436 @@ tb_byte_t* tb_stream_bread_all(tb_stream_ref_t stream, tb_bool_t is /*! block read uint8 integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the uint8 integer + * @return tb_true or tb_false */ -tb_uint8_t tb_stream_bread_u8(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_u8(tb_stream_ref_t stream, tb_uint8_t* pvalue); /*! block read sint8 integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the sint8 integer + * @return tb_true or tb_false */ -tb_sint8_t tb_stream_bread_s8(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_s8(tb_stream_ref_t stream, tb_sint8_t* pvalue); /*! block read uint16-le integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the uint16-le integer + * @return tb_true or tb_false */ -tb_uint16_t tb_stream_bread_u16_le(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_u16_le(tb_stream_ref_t stream, tb_uint16_t* pvalue); /*! block read sint16-le integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the sint16-le integer + * @return tb_true or tb_false */ -tb_sint16_t tb_stream_bread_s16_le(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_s16_le(tb_stream_ref_t stream, tb_sint16_t* pvalue); /*! block read uint24-le integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the uint24-le integer + * @return tb_true or tb_false */ -tb_uint32_t tb_stream_bread_u24_le(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_u24_le(tb_stream_ref_t stream, tb_uint32_t* pvalue); /*! block read sint24-le integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the sint24-le integer + * @return tb_true or tb_false */ -tb_sint32_t tb_stream_bread_s24_le(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_s24_le(tb_stream_ref_t stream, tb_sint32_t* pvalue); /*! block read uint32-le integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the uint32-le integer + * @return tb_true or tb_false */ -tb_uint32_t tb_stream_bread_u32_le(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_u32_le(tb_stream_ref_t stream, tb_uint32_t* pvalue); /*! block read sint32-le integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the sint32-le integer + * @return tb_true or tb_false */ -tb_sint32_t tb_stream_bread_s32_le(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_s32_le(tb_stream_ref_t stream, tb_sint32_t* pvalue); /*! block read uint64-le integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the uint64-le integer + * @return tb_true or tb_false */ -tb_uint64_t tb_stream_bread_u64_le(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_u64_le(tb_stream_ref_t stream, tb_uint64_t* pvalue); /*! block read sint64-le integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the sint64-le integer + * @return tb_true or tb_false */ -tb_sint64_t tb_stream_bread_s64_le(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_s64_le(tb_stream_ref_t stream, tb_sint64_t* pvalue); /*! block read uint16-be integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the uint16-be integer + * @return tb_true or tb_false */ -tb_uint16_t tb_stream_bread_u16_be(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_u16_be(tb_stream_ref_t stream, tb_uint16_t* pvalue); /*! block read sint16-be integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the sint16-be integer + * @return tb_true or tb_false */ -tb_sint16_t tb_stream_bread_s16_be(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_s16_be(tb_stream_ref_t stream, tb_sint16_t* pvalue); /*! block read uint24-be integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the uint24-be integer + * @return tb_true or tb_false */ -tb_uint32_t tb_stream_bread_u24_be(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_u24_be(tb_stream_ref_t stream, tb_uint32_t* pvalue); /*! block read sint24-be integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the sint24-be integer + * @return tb_true or tb_false */ -tb_sint32_t tb_stream_bread_s24_be(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_s24_be(tb_stream_ref_t stream, tb_sint32_t* pvalue); /*! block read uint32-be integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the uint32-be integer + * @return tb_true or tb_false */ -tb_uint32_t tb_stream_bread_u32_be(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_u32_be(tb_stream_ref_t stream, tb_uint32_t* pvalue); /*! block read sint32-be integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the sint32-be integer + * @return tb_true or tb_false */ -tb_sint32_t tb_stream_bread_s32_be(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_s32_be(tb_stream_ref_t stream, tb_sint32_t* pvalue); /*! block read uint64-be integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the uint64-be integer + * @return tb_true or tb_false */ -tb_uint64_t tb_stream_bread_u64_be(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_u64_be(tb_stream_ref_t stream, tb_uint64_t* pvalue); /*! block read sint64-be integer * * @param stream the stream + * @param pvalue the value pointer * - * @return the sint64-be integer + * @return tb_true or tb_false */ -tb_sint64_t tb_stream_bread_s64_be(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_s64_be(tb_stream_ref_t stream, tb_sint64_t* pvalue); /*! block writ uint8 integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_u8(tb_stream_ref_t stream, tb_uint8_t val); +tb_bool_t tb_stream_bwrit_u8(tb_stream_ref_t stream, tb_uint8_t value); /*! block writ sint8 integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_s8(tb_stream_ref_t stream, tb_sint8_t val); +tb_bool_t tb_stream_bwrit_s8(tb_stream_ref_t stream, tb_sint8_t value); /*! block writ uint16-le integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_u16_le(tb_stream_ref_t stream, tb_uint16_t val); +tb_bool_t tb_stream_bwrit_u16_le(tb_stream_ref_t stream, tb_uint16_t value); /*! block writ sint16-le integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_s16_le(tb_stream_ref_t stream, tb_sint16_t val); +tb_bool_t tb_stream_bwrit_s16_le(tb_stream_ref_t stream, tb_sint16_t value); /*! block writ uint24-le integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_u24_le(tb_stream_ref_t stream, tb_uint32_t val); +tb_bool_t tb_stream_bwrit_u24_le(tb_stream_ref_t stream, tb_uint32_t value); /*! block writ sint24-le integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_s24_le(tb_stream_ref_t stream, tb_sint32_t val); +tb_bool_t tb_stream_bwrit_s24_le(tb_stream_ref_t stream, tb_sint32_t value); /*! block writ uint32-le integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_u32_le(tb_stream_ref_t stream, tb_uint32_t val); +tb_bool_t tb_stream_bwrit_u32_le(tb_stream_ref_t stream, tb_uint32_t value); /*! block writ sint32-le integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_s32_le(tb_stream_ref_t stream, tb_sint32_t val); +tb_bool_t tb_stream_bwrit_s32_le(tb_stream_ref_t stream, tb_sint32_t value); /*! block writ uint64-le integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_u64_le(tb_stream_ref_t stream, tb_uint64_t val); +tb_bool_t tb_stream_bwrit_u64_le(tb_stream_ref_t stream, tb_uint64_t value); /*! block writ sint64-le integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_s64_le(tb_stream_ref_t stream, tb_sint64_t val); +tb_bool_t tb_stream_bwrit_s64_le(tb_stream_ref_t stream, tb_sint64_t value); /*! block writ uint16-be integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_u16_be(tb_stream_ref_t stream, tb_uint16_t val); +tb_bool_t tb_stream_bwrit_u16_be(tb_stream_ref_t stream, tb_uint16_t value); /*! block writ sint16-be integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_s16_be(tb_stream_ref_t stream, tb_sint16_t val); +tb_bool_t tb_stream_bwrit_s16_be(tb_stream_ref_t stream, tb_sint16_t value); /*! block writ uint24-be integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_u24_be(tb_stream_ref_t stream, tb_uint32_t val); +tb_bool_t tb_stream_bwrit_u24_be(tb_stream_ref_t stream, tb_uint32_t value); /*! block writ sint24-be integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_s24_be(tb_stream_ref_t stream, tb_sint32_t val); +tb_bool_t tb_stream_bwrit_s24_be(tb_stream_ref_t stream, tb_sint32_t value); /*! block writ uint32-be integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_u32_be(tb_stream_ref_t stream, tb_uint32_t val); +tb_bool_t tb_stream_bwrit_u32_be(tb_stream_ref_t stream, tb_uint32_t value); /*! block writ sint32-be integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_s32_be(tb_stream_ref_t stream, tb_sint32_t val); +tb_bool_t tb_stream_bwrit_s32_be(tb_stream_ref_t stream, tb_sint32_t value); /*! block writ uint64-be integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_u64_be(tb_stream_ref_t stream, tb_uint64_t val); +tb_bool_t tb_stream_bwrit_u64_be(tb_stream_ref_t stream, tb_uint64_t value); /*! block writ sint64-be integer * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_s64_be(tb_stream_ref_t stream, tb_sint64_t val); +tb_bool_t tb_stream_bwrit_s64_be(tb_stream_ref_t stream, tb_sint64_t value); #ifdef TB_CONFIG_TYPE_HAVE_FLOAT /*! read float-le number * * @param stream the stream + * @param pvalue the value pointer * - * @return the float-le number + * @return tb_true or tb_false */ -tb_float_t tb_stream_bread_float_le(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_float_le(tb_stream_ref_t stream, tb_float_t* pvalue); /*! read float-be number * * @param stream the stream + * @param pvalue the value pointer * - * @return the float-be number + * @return tb_true or tb_false */ -tb_float_t tb_stream_bread_float_be(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_float_be(tb_stream_ref_t stream, tb_float_t* pvalue); /*! read double-ble number * * @param stream the stream + * @param pvalue the value pointer * - * @return the double-ble number + * @return tb_true or tb_false */ -tb_double_t tb_stream_bread_double_ble(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_double_ble(tb_stream_ref_t stream, tb_double_t* pvalue); /*! read double-bbe number * * @param stream the stream + * @param pvalue the value pointer * - * @return the double-bbe number + * @return tb_true or tb_false */ -tb_double_t tb_stream_bread_double_bbe(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_double_bbe(tb_stream_ref_t stream, tb_double_t* pvalue); /*! read double-lle number * * @param stream the stream + * @param pvalue the value pointer * - * @return the double-lle number + * @return tb_true or tb_false */ -tb_double_t tb_stream_bread_double_lle(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_double_lle(tb_stream_ref_t stream, tb_double_t* pvalue); /*! read double-lbe number * * @param stream the stream + * @param pvalue the value pointer * - * @return the double-lbe number + * @return tb_true or tb_false */ -tb_double_t tb_stream_bread_double_lbe(tb_stream_ref_t stream); +tb_bool_t tb_stream_bread_double_lbe(tb_stream_ref_t stream, tb_double_t* pvalue); /*! writ float-le number * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_float_le(tb_stream_ref_t stream, tb_float_t val); +tb_bool_t tb_stream_bwrit_float_le(tb_stream_ref_t stream, tb_float_t value); /*! writ float-be number * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_float_be(tb_stream_ref_t stream, tb_float_t val); +tb_bool_t tb_stream_bwrit_float_be(tb_stream_ref_t stream, tb_float_t value); /*! writ double-ble number * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_double_ble(tb_stream_ref_t stream, tb_double_t val); +tb_bool_t tb_stream_bwrit_double_ble(tb_stream_ref_t stream, tb_double_t value); /*! writ double-bbe number * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_double_bbe(tb_stream_ref_t stream, tb_double_t val); +tb_bool_t tb_stream_bwrit_double_bbe(tb_stream_ref_t stream, tb_double_t value); /*! writ double-lle number * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_double_lle(tb_stream_ref_t stream, tb_double_t val); +tb_bool_t tb_stream_bwrit_double_lle(tb_stream_ref_t stream, tb_double_t value); /*! writ double-lbe number * * @param stream the stream - * @param val the value + * @param value the value * * @return tb_true or tb_false */ -tb_bool_t tb_stream_bwrit_double_lbe(tb_stream_ref_t stream, tb_double_t val); +tb_bool_t tb_stream_bwrit_double_lbe(tb_stream_ref_t stream, tb_double_t value); #endif diff --git a/core/pkg/tbox.pkg/inc/tbox/tbox.h b/core/pkg/tbox.pkg/inc/tbox/tbox.h index c97db64f1..190252505 100644 --- a/core/pkg/tbox.pkg/inc/tbox/tbox.h +++ b/core/pkg/tbox.pkg/inc/tbox/tbox.h @@ -34,6 +34,7 @@ #include "libc/libc.h" #include "math/math.h" #include "utils/utils.h" +#include "regex/regex.h" #include "object/object.h" #include "memory/memory.h" #include "stream/stream.h" diff --git a/core/pkg/tbox.pkg/inc/tbox/utils/fnv32.h b/core/pkg/tbox.pkg/inc/tbox/utils/fnv32.h new file mode 100755 index 000000000..e3fc63f9d --- /dev/null +++ b/core/pkg/tbox.pkg/inc/tbox/utils/fnv32.h @@ -0,0 +1,55 @@ +/*!The Treasure Box Library + * + * TBox is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * TBox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TBox; + * If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> + * + * Copyright (C) 2016, Olexander Yermakov All rights reserved. + * + * @author alexyer + * @file fnv32.h + * @ingroup utils + * + */ +#ifndef TB_UTILS_FNV32_H +#define TB_UTILS_FNV32_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_enter__ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * interfaces + */ + +/*! encode fnv32 + * + * @param data the data + * @param size the size + * + * @return the fnv32 value + */ +tb_uint32_t tb_fnv32_encode(tb_byte_t const* data, tb_size_t size); + +/* ////////////////////////////////////////////////////////////////////////////////////// + * extern + */ +__tb_extern_c_leave__ + +#endif diff --git a/core/pkg/tbox.pkg/inc/tbox/utils/utils.h b/core/pkg/tbox.pkg/inc/tbox/utils/utils.h index 8be786da1..9b3393fdf 100644 --- a/core/pkg/tbox.pkg/inc/tbox/utils/utils.h +++ b/core/pkg/tbox.pkg/inc/tbox/utils/utils.h @@ -42,5 +42,6 @@ #include "adler32.h" #include "singleton.h" #include "lock_profiler.h" +#include "fnv32.h" #endif |
