From c89c94bf89e98c8e42e786aacc0b334a57474179 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 19:11:32 +0800 Subject: format code --- core/src/xmake/base64/decode.c | 19 +- core/src/xmake/base64/encode.c | 24 +- core/src/xmake/base64/prefix.h | 3 - core/src/xmake/bloom_filter/bloom_filter_clear.c | 8 +- core/src/xmake/bloom_filter/bloom_filter_close.c | 8 +- core/src/xmake/bloom_filter/bloom_filter_data.c | 14 +- .../src/xmake/bloom_filter/bloom_filter_data_set.c | 19 +- core/src/xmake/bloom_filter/bloom_filter_get.c | 11 +- core/src/xmake/bloom_filter/bloom_filter_open.c | 21 +- core/src/xmake/bloom_filter/bloom_filter_set.c | 10 +- core/src/xmake/bloom_filter/bloom_filter_size.c | 9 +- core/src/xmake/bloom_filter/prefix.h | 2 - core/src/xmake/config.h | 2 - core/src/xmake/curses/curses.c | 506 +++---- core/src/xmake/engine.c | 1554 ++++++++++---------- core/src/xmake/engine.h | 28 +- core/src/xmake/engine_pool.c | 48 +- core/src/xmake/engine_pool.h | 10 +- core/src/xmake/fwatcher/add.c | 9 +- core/src/xmake/fwatcher/close.c | 7 +- core/src/xmake/fwatcher/open.c | 13 +- core/src/xmake/fwatcher/prefix.h | 2 - core/src/xmake/fwatcher/remove.c | 10 +- core/src/xmake/fwatcher/wait.c | 12 +- core/src/xmake/hash/md5.c | 44 +- core/src/xmake/hash/prefix.h | 30 +- core/src/xmake/hash/rand128.c | 15 +- core/src/xmake/hash/rand32.c | 11 +- core/src/xmake/hash/rand64.c | 12 +- core/src/xmake/hash/sha.c | 50 +- core/src/xmake/hash/uuid4.c | 11 +- core/src/xmake/hash/xxhash.c | 121 +- core/src/xmake/io/file_close.c | 36 +- core/src/xmake/io/file_flush.c | 34 +- core/src/xmake/io/file_isatty.c | 9 +- core/src/xmake/io/file_open.c | 151 +- core/src/xmake/io/file_rawfd.c | 19 +- core/src/xmake/io/file_read.c | 353 +++-- core/src/xmake/io/file_readable.c | 15 +- core/src/xmake/io/file_seek.c | 44 +- core/src/xmake/io/file_size.c | 16 +- core/src/xmake/io/file_write.c | 119 +- core/src/xmake/io/filelock_close.c | 8 +- core/src/xmake/io/filelock_lock.c | 12 +- core/src/xmake/io/filelock_open.c | 21 +- core/src/xmake/io/filelock_trylock.c | 12 +- core/src/xmake/io/filelock_unlock.c | 7 +- core/src/xmake/io/iscygpty.c | 90 +- core/src/xmake/io/pipe_close.c | 8 +- core/src/xmake/io/pipe_connect.c | 11 +- core/src/xmake/io/pipe_open.c | 23 +- core/src/xmake/io/pipe_openpair.c | 24 +- core/src/xmake/io/pipe_read.c | 23 +- core/src/xmake/io/pipe_wait.c | 8 +- core/src/xmake/io/pipe_write.c | 21 +- core/src/xmake/io/poller.c | 11 +- core/src/xmake/io/poller.h | 14 +- core/src/xmake/io/poller_insert.c | 15 +- core/src/xmake/io/poller_modify.c | 15 +- core/src/xmake/io/poller_remove.c | 11 +- core/src/xmake/io/poller_spank.c | 8 +- core/src/xmake/io/poller_support.c | 8 +- core/src/xmake/io/poller_wait.c | 47 +- core/src/xmake/io/prefix.h | 88 +- core/src/xmake/io/socket_accept.c | 14 +- core/src/xmake/io/socket_bind.c | 20 +- core/src/xmake/io/socket_close.c | 8 +- core/src/xmake/io/socket_connect.c | 20 +- core/src/xmake/io/socket_ctrl.c | 11 +- core/src/xmake/io/socket_kill.c | 8 +- core/src/xmake/io/socket_listen.c | 8 +- core/src/xmake/io/socket_open.c | 16 +- core/src/xmake/io/socket_peeraddr.c | 18 +- core/src/xmake/io/socket_rawfd.c | 9 +- core/src/xmake/io/socket_recv.c | 23 +- core/src/xmake/io/socket_recvfrom.c | 40 +- core/src/xmake/io/socket_send.c | 21 +- core/src/xmake/io/socket_sendfile.c | 36 +- core/src/xmake/io/socket_sendto.c | 26 +- core/src/xmake/io/socket_wait.c | 8 +- core/src/xmake/io/stdfile.c | 94 +- core/src/xmake/libc/byteof.c | 17 +- core/src/xmake/libc/dataptr.c | 11 +- core/src/xmake/libc/free.c | 11 +- core/src/xmake/libc/malloc.c | 13 +- core/src/xmake/libc/memcpy.c | 14 +- core/src/xmake/libc/memmov.c | 14 +- core/src/xmake/libc/memset.c | 12 +- core/src/xmake/libc/prefix.h | 13 +- core/src/xmake/libc/setbyte.c | 20 +- core/src/xmake/libc/strndup.c | 18 +- core/src/xmake/lz4/block_compress.c | 39 +- core/src/xmake/lz4/block_decompress.c | 43 +- core/src/xmake/lz4/compress.c | 44 +- core/src/xmake/lz4/compress_file.c | 45 +- core/src/xmake/lz4/compress_stream_close.c | 10 +- core/src/xmake/lz4/compress_stream_open.c | 16 +- core/src/xmake/lz4/compress_stream_read.c | 25 +- core/src/xmake/lz4/compress_stream_write.c | 26 +- core/src/xmake/lz4/decompress.c | 56 +- core/src/xmake/lz4/decompress_file.c | 46 +- core/src/xmake/lz4/decompress_stream_close.c | 10 +- core/src/xmake/lz4/decompress_stream_open.c | 16 +- core/src/xmake/lz4/decompress_stream_read.c | 25 +- core/src/xmake/lz4/decompress_stream_write.c | 23 +- core/src/xmake/lz4/prefix.h | 181 ++- core/src/xmake/os/args.c | 76 +- core/src/xmake/os/argv.c | 69 +- core/src/xmake/os/chdir.c | 9 +- core/src/xmake/os/cpdir.c | 13 +- core/src/xmake/os/cpfile.c | 13 +- core/src/xmake/os/cpuinfo.c | 192 +-- core/src/xmake/os/curdir.c | 13 +- core/src/xmake/os/emptydir.c | 17 +- core/src/xmake/os/exists.c | 9 +- core/src/xmake/os/filesize.c | 14 +- core/src/xmake/os/find.c | 86 +- core/src/xmake/os/fscase.c | 9 +- core/src/xmake/os/getenv.c | 37 +- core/src/xmake/os/getenvs.c | 96 +- core/src/xmake/os/getown.c | 13 +- core/src/xmake/os/getpid.c | 14 +- core/src/xmake/os/getwinsize.c | 21 +- core/src/xmake/os/gid.c | 62 +- core/src/xmake/os/isdir.c | 11 +- core/src/xmake/os/isfile.c | 11 +- core/src/xmake/os/islink.c | 11 +- core/src/xmake/os/link.c | 11 +- core/src/xmake/os/mclock.c | 7 +- core/src/xmake/os/meminfo.c | 95 +- core/src/xmake/os/mkdir.c | 14 +- core/src/xmake/os/mtime.c | 14 +- core/src/xmake/os/prefix.h | 3 - core/src/xmake/os/readlink.c | 34 +- core/src/xmake/os/rename.c | 11 +- core/src/xmake/os/rmdir.c | 36 +- core/src/xmake/os/rmfile.c | 9 +- core/src/xmake/os/setenv.c | 15 +- core/src/xmake/os/signal.c | 111 +- core/src/xmake/os/sleep.c | 10 +- core/src/xmake/os/strerror.c | 27 +- core/src/xmake/os/syserror.c | 28 +- core/src/xmake/os/tmpdir.c | 13 +- core/src/xmake/os/touch.c | 9 +- core/src/xmake/os/uid.c | 62 +- core/src/xmake/package/loadxmi.c | 209 ++- core/src/xmake/package/prefix.h | 3 - core/src/xmake/path/absolute.c | 11 +- core/src/xmake/path/directory.c | 19 +- core/src/xmake/path/is_absolute.c | 9 +- core/src/xmake/path/prefix.h | 3 - core/src/xmake/path/relative.c | 11 +- core/src/xmake/path/translate.c | 18 +- core/src/xmake/prefix.h | 55 +- core/src/xmake/prefix/config.h | 8 +- core/src/xmake/prefix/prefix.h | 3 - core/src/xmake/prefix/version.h | 28 +- core/src/xmake/process/close.c | 7 +- core/src/xmake/process/kill.c | 7 +- core/src/xmake/process/open.c | 140 +- core/src/xmake/process/openv.c | 173 +-- core/src/xmake/process/prefix.h | 2 - core/src/xmake/process/wait.c | 12 +- core/src/xmake/readline/add_history.c | 9 +- core/src/xmake/readline/clear_history.c | 7 +- core/src/xmake/readline/history_list.c | 13 +- core/src/xmake/readline/prefix.h | 9 +- core/src/xmake/readline/readline.c | 18 +- core/src/xmake/sandbox/interactive.c | 113 +- core/src/xmake/sandbox/prefix.h | 3 - core/src/xmake/semver/compare.c | 22 +- core/src/xmake/semver/parse.c | 14 +- core/src/xmake/semver/prefix.h | 3 +- core/src/xmake/semver/satisfies.c | 42 +- core/src/xmake/semver/select.c | 125 +- core/src/xmake/semver/semver.c | 29 +- core/src/xmake/string/convert.c | 94 +- core/src/xmake/string/endswith.c | 15 +- core/src/xmake/string/lastof.c | 48 +- core/src/xmake/string/prefix.h | 3 - core/src/xmake/string/split.c | 76 +- core/src/xmake/string/startswith.c | 13 +- core/src/xmake/string/trim.c | 55 +- core/src/xmake/thread/event_exit.c | 16 +- core/src/xmake/thread/event_incref.c | 10 +- core/src/xmake/thread/event_init.c | 25 +- core/src/xmake/thread/event_post.c | 10 +- core/src/xmake/thread/event_wait.c | 10 +- core/src/xmake/thread/mutex_exit.c | 16 +- core/src/xmake/thread/mutex_incref.c | 10 +- core/src/xmake/thread/mutex_init.c | 25 +- core/src/xmake/thread/mutex_lock.c | 10 +- core/src/xmake/thread/mutex_trylock.c | 10 +- core/src/xmake/thread/mutex_unlock.c | 10 +- core/src/xmake/thread/prefix.h | 126 +- core/src/xmake/thread/queue_clear.c | 10 +- core/src/xmake/thread/queue_exit.c | 16 +- core/src/xmake/thread/queue_incref.c | 10 +- core/src/xmake/thread/queue_init.c | 42 +- core/src/xmake/thread/queue_pop.c | 24 +- core/src/xmake/thread/queue_push.c | 49 +- core/src/xmake/thread/queue_size.c | 10 +- core/src/xmake/thread/semaphore_exit.c | 16 +- core/src/xmake/thread/semaphore_incref.c | 10 +- core/src/xmake/thread/semaphore_init.c | 25 +- core/src/xmake/thread/semaphore_post.c | 10 +- core/src/xmake/thread/semaphore_wait.c | 10 +- core/src/xmake/thread/sharedata_clear.c | 10 +- core/src/xmake/thread/sharedata_exit.c | 13 +- core/src/xmake/thread/sharedata_get.c | 24 +- core/src/xmake/thread/sharedata_incref.c | 10 +- core/src/xmake/thread/sharedata_init.c | 22 +- core/src/xmake/thread/sharedata_set.c | 49 +- core/src/xmake/thread/thread_exit.c | 16 +- core/src/xmake/thread/thread_init.c | 60 +- core/src/xmake/thread/thread_resume.c | 10 +- core/src/xmake/thread/thread_suspend.c | 10 +- core/src/xmake/thread/thread_wait.c | 10 +- core/src/xmake/tty/prefix.h | 3 - core/src/xmake/tty/term_mode.c | 29 +- core/src/xmake/utils/bin2c.c | 88 +- core/src/xmake/utils/prefix.h | 2 - core/src/xmake/winos/ansi.c | 50 +- core/src/xmake/winos/logical_drives.c | 24 +- core/src/xmake/winos/prefix.h | 5 +- core/src/xmake/winos/registry_keys.c | 161 +- core/src/xmake/winos/registry_query.c | 132 +- core/src/xmake/winos/registry_values.c | 100 +- core/src/xmake/winos/short_path.c | 20 +- core/src/xmake/xmake.c | 52 +- core/src/xmake/xmake.h | 17 +- 231 files changed, 4227 insertions(+), 4986 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/base64/decode.c b/core/src/xmake/base64/decode.c index abb9abcbd..41555f5cc 100644 --- a/core/src/xmake/base64/decode.c +++ b/core/src/xmake/base64/decode.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "base64" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "base64" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,24 +33,21 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_base64_decode(lua_State* lua) -{ +tb_int_t xm_base64_decode(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the string - size_t size = 0; - tb_char_t const* cstr = luaL_checklstring(lua, 1, &size); + size_t size = 0; + tb_char_t const *cstr = luaL_checklstring(lua, 1, &size); tb_check_return_val(cstr && size, 0); // decode it tb_byte_t buff[8192]; - if (size < sizeof(buff)) - { + if (size < sizeof(buff)) { tb_size_t real = tb_base64_decode(cstr, size, buff, sizeof(buff)); - if (real > 0) - { - lua_pushlstring(lua, (tb_char_t const*)buff, (tb_int_t)real); + if (real > 0) { + lua_pushlstring(lua, (tb_char_t const *)buff, (tb_int_t)real); return 1; } } diff --git a/core/src/xmake/base64/encode.c b/core/src/xmake/base64/encode.c index b99ee3922..cf2135e56 100644 --- a/core/src/xmake/base64/encode.c +++ b/core/src/xmake/base64/encode.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "base64" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "base64" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,18 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_base64_encode(lua_State* lua) -{ +tb_int_t xm_base64_encode(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 1)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_lua_isinteger(lua, 2)) + size = (tb_size_t)lua_tointeger(lua, 2); + if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -53,11 +53,9 @@ tb_int_t xm_base64_encode(lua_State* lua) // encode it tb_char_t buff[8192]; - if (size * 3 / 2 < sizeof(buff)) - { + if (size * 3 / 2 < sizeof(buff)) { tb_size_t real = tb_base64_encode(data, size, buff, sizeof(buff)); - if (real > 0) - { + if (real > 0) { lua_pushlstring(lua, buff, (tb_int_t)real); return 1; } diff --git a/core/src/xmake/base64/prefix.h b/core/src/xmake/base64/prefix.h index a22be8e7c..4e7ba2bf3 100644 --- a/core/src/xmake/base64/prefix.h +++ b/core/src/xmake/base64/prefix.h @@ -26,7 +26,4 @@ */ #include "../prefix.h" - #endif - - diff --git a/core/src/xmake/bloom_filter/bloom_filter_clear.c b/core/src/xmake/bloom_filter/bloom_filter_clear.c index c68419e7d..3f6e36bd0 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_clear.c +++ b/core/src/xmake/bloom_filter/bloom_filter_clear.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "bloom_filter_clear" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "bloom_filter_clear" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_bloom_filter_clear(lua_State* lua) -{ +tb_int_t xm_bloom_filter_clear(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -51,4 +50,3 @@ tb_int_t xm_bloom_filter_clear(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/bloom_filter/bloom_filter_close.c b/core/src/xmake/bloom_filter/bloom_filter_close.c index fd1d3e206..5c916b460 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_close.c +++ b/core/src/xmake/bloom_filter/bloom_filter_close.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "bloom_filter_close" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "bloom_filter_close" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_bloom_filter_close(lua_State* lua) -{ +tb_int_t xm_bloom_filter_close(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -53,4 +52,3 @@ tb_int_t xm_bloom_filter_close(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/bloom_filter/bloom_filter_data.c b/core/src/xmake/bloom_filter/bloom_filter_data.c index 3911d5e08..e37aea966 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "bloom_filter_data" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "bloom_filter_data" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_bloom_filter_data(lua_State* lua) -{ +tb_int_t xm_bloom_filter_data(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -48,8 +47,9 @@ tb_int_t xm_bloom_filter_data(lua_State* lua) // get data tb_pointer_t data = (tb_pointer_t)tb_bloom_filter_data(filter); - if (data) xm_lua_pushpointer(lua, data); - else lua_pushnil(lua); + if (data) + xm_lua_pushpointer(lua, data); + else + lua_pushnil(lua); return 1; } - diff --git a/core/src/xmake/bloom_filter/bloom_filter_data_set.c b/core/src/xmake/bloom_filter/bloom_filter_data_set.c index d7b036289..a6949d730 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data_set.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data_set.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "bloom_filter_data_set" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "bloom_filter_data_set" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_bloom_filter_data_set(lua_State* lua) -{ +tb_int_t xm_bloom_filter_data_set(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -48,11 +47,12 @@ tb_int_t xm_bloom_filter_data_set(lua_State* lua) // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 2)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_lua_isinteger(lua, 3)) + size = (tb_size_t)lua_tointeger(lua, 3); + if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -64,4 +64,3 @@ tb_int_t xm_bloom_filter_data_set(lua_State* lua) lua_pushboolean(lua, ok); return 1; } - diff --git a/core/src/xmake/bloom_filter/bloom_filter_get.c b/core/src/xmake/bloom_filter/bloom_filter_get.c index 8ad695515..755446a09 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_get.c +++ b/core/src/xmake/bloom_filter/bloom_filter_get.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "bloom_filter_get" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "bloom_filter_get" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_bloom_filter_get(lua_State* lua) -{ +tb_int_t xm_bloom_filter_get(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -47,7 +46,7 @@ tb_int_t xm_bloom_filter_get(lua_State* lua) tb_check_return_val(filter, 0); // get item - tb_char_t const* item = luaL_checkstring(lua, 2); + tb_char_t const *item = luaL_checkstring(lua, 2); tb_assert_and_check_return_val(item, 0); // get item @@ -55,5 +54,3 @@ tb_int_t xm_bloom_filter_get(lua_State* lua) lua_pushboolean(lua, ok); return 1; } - - diff --git a/core/src/xmake/bloom_filter/bloom_filter_open.c b/core/src/xmake/bloom_filter/bloom_filter_open.c index 65d8d4951..68af8ae92 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_open.c +++ b/core/src/xmake/bloom_filter/bloom_filter_open.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "bloom_filter_open" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "bloom_filter_open" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_bloom_filter_open(lua_State* lua) -{ +tb_int_t xm_bloom_filter_open(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get arguments tb_int_t probability = (tb_int_t)lua_tointeger(lua, 1); - tb_int_t hash_count = (tb_int_t)lua_tointeger(lua, 2); - tb_int_t item_maxn = (tb_int_t)lua_tointeger(lua, 3); - if (hash_count > 16 || item_maxn < 0) - { + tb_int_t hash_count = (tb_int_t)lua_tointeger(lua, 2); + tb_int_t item_maxn = (tb_int_t)lua_tointeger(lua, 3); + if (hash_count > 16 || item_maxn < 0) { lua_pushnil(lua); lua_pushfstring(lua, "invalid hash count(%p) and item maxn(%d)!", hash_count, item_maxn); return 2; @@ -51,8 +49,9 @@ tb_int_t xm_bloom_filter_open(lua_State* lua) // init the bloom filter tb_bloom_filter_ref_t filter = tb_bloom_filter_init(probability, hash_count, item_maxn, tb_element_str(tb_true)); - if (filter) xm_lua_pushpointer(lua, (tb_pointer_t)filter); - else lua_pushnil(lua); + if (filter) + xm_lua_pushpointer(lua, (tb_pointer_t)filter); + else + lua_pushnil(lua); return 1; } - diff --git a/core/src/xmake/bloom_filter/bloom_filter_set.c b/core/src/xmake/bloom_filter/bloom_filter_set.c index ceaaeef66..9387d5354 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_set.c +++ b/core/src/xmake/bloom_filter/bloom_filter_set.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "bloom_filter_set" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "bloom_filter_set" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_bloom_filter_set(lua_State* lua) -{ +tb_int_t xm_bloom_filter_set(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -47,7 +46,7 @@ tb_int_t xm_bloom_filter_set(lua_State* lua) tb_check_return_val(filter, 0); // get item - tb_char_t const* item = luaL_checkstring(lua, 2); + tb_char_t const *item = luaL_checkstring(lua, 2); tb_assert_and_check_return_val(item, 0); // set item @@ -55,4 +54,3 @@ tb_int_t xm_bloom_filter_set(lua_State* lua) lua_pushboolean(lua, ok); return 1; } - diff --git a/core/src/xmake/bloom_filter/bloom_filter_size.c b/core/src/xmake/bloom_filter/bloom_filter_size.c index ee8de73b9..219035fe7 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_size.c +++ b/core/src/xmake/bloom_filter/bloom_filter_size.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "bloom_filter_size" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "bloom_filter_size" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_bloom_filter_size(lua_State* lua) -{ +tb_int_t xm_bloom_filter_size(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -51,5 +50,3 @@ tb_int_t xm_bloom_filter_size(lua_State* lua) lua_pushinteger(lua, (tb_int_t)size); return 1; } - - diff --git a/core/src/xmake/bloom_filter/prefix.h b/core/src/xmake/bloom_filter/prefix.h index 8419d3ae1..ef70c7aaa 100644 --- a/core/src/xmake/bloom_filter/prefix.h +++ b/core/src/xmake/bloom_filter/prefix.h @@ -27,5 +27,3 @@ #include "../prefix.h" #endif - - diff --git a/core/src/xmake/config.h b/core/src/xmake/config.h index 65f1d7808..b0d39830c 100644 --- a/core/src/xmake/config.h +++ b/core/src/xmake/config.h @@ -27,5 +27,3 @@ #include "xmake.config.h" #endif - - diff --git a/core/src/xmake/curses/curses.c b/core/src/xmake/curses/curses.c index 3321090f1..988e6840c 100644 --- a/core/src/xmake/curses/curses.c +++ b/core/src/xmake/curses/curses.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "curses" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "curses" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,71 +33,66 @@ #include #if defined(PDCURSES) // fix macro redefinition -# undef MOUSE_MOVED +#undef MOUSE_MOVED #endif #define NCURSES_MOUSE_VERSION 2 #ifdef TB_COMPILER_IS_MINGW -# include +#include #else -# include +#include #endif #if defined(NCURSES_VERSION) -# include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// * macros */ -#define XM_CURSES_STDSCR "curses.stdscr" -#define XM_CURSES_WINDOW "curses.window" -#define XM_CURSES_OK(v) (((v) == ERR) ? 0 : 1) +#define XM_CURSES_STDSCR "curses.stdscr" +#define XM_CURSES_WINDOW "curses.window" +#define XM_CURSES_OK(v) (((v) == ERR) ? 0 : 1) // define functions -#define XM_CURSES_NUMBER(n) \ - static int xm_curses_ ## n(lua_State* lua) \ - { \ - lua_pushnumber(lua, n()); \ - return 1; \ +#define XM_CURSES_NUMBER(n) \ + static int xm_curses_##n(lua_State *lua) { \ + lua_pushnumber(lua, n()); \ + return 1; \ } -#define XM_CURSES_NUMBER2(n, v) \ - static int xm_curses_ ## n(lua_State* lua) \ - { \ - lua_pushnumber(lua, v); \ - return 1; \ +#define XM_CURSES_NUMBER2(n, v) \ + static int xm_curses_##n(lua_State *lua) { \ + lua_pushnumber(lua, v); \ + return 1; \ } -#define XM_CURSES_BOOL(n) \ - static int xm_curses_ ## n(lua_State* lua) \ - { \ - lua_pushboolean(lua, n()); \ - return 1; \ +#define XM_CURSES_BOOL(n) \ + static int xm_curses_##n(lua_State *lua) { \ + lua_pushboolean(lua, n()); \ + return 1; \ } -#define XM_CURSES_BOOLOK(n) \ - static int xm_curses_ ## n(lua_State* lua) \ - { \ - lua_pushboolean(lua, XM_CURSES_OK(n())); \ - return 1; \ +#define XM_CURSES_BOOLOK(n) \ + static int xm_curses_##n(lua_State *lua) { \ + lua_pushboolean(lua, XM_CURSES_OK(n())); \ + return 1; \ } -#define XM_CURSES_WINDOW_BOOLOK(n) \ - static int xm_curses_window_ ## n(lua_State* lua) \ - { \ - WINDOW* w = xm_curses_window_check(lua, 1); \ - lua_pushboolean(lua, XM_CURSES_OK(n(w))); \ - return 1; \ +#define XM_CURSES_WINDOW_BOOLOK(n) \ + static int xm_curses_window_##n(lua_State *lua) { \ + WINDOW *w = xm_curses_window_check(lua, 1); \ + lua_pushboolean(lua, XM_CURSES_OK(n(w))); \ + return 1; \ } // define constants -#define XM_CURSES_CONST_(n, v) \ - lua_pushstring(lua, n); \ - lua_pushnumber(lua, v); \ +#define XM_CURSES_CONST_(n, v) \ + lua_pushstring(lua, n); \ + lua_pushnumber(lua, v); \ lua_settable(lua, lua_upvalueindex(1)); -#define XM_CURSES_CONST(s) XM_CURSES_CONST_(#s, s) -#define XM_CURSES_CONST2(s, v) XM_CURSES_CONST_(#s, v) +#define XM_CURSES_CONST(s) XM_CURSES_CONST_(#s, s) +#define XM_CURSES_CONST2(s, v) XM_CURSES_CONST_(#s, v) /* ////////////////////////////////////////////////////////////////////////////////////// * globals @@ -109,8 +104,7 @@ static int g_mapkey = 0; /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static chtype xm_curses_checkch(lua_State* lua, int index) -{ +static chtype xm_curses_checkch(lua_State *lua, int index) { if (lua_type(lua, index) == LUA_TNUMBER) return (chtype)luaL_checknumber(lua, index); if (lua_type(lua, index) == LUA_TSTRING) @@ -122,48 +116,65 @@ static chtype xm_curses_checkch(lua_State* lua, int index) } // get character and map key -static int xm_curses_window_getch_impl(WINDOW* w) -{ +static int xm_curses_window_getch_impl(WINDOW *w) { #ifdef PDCURSES - static int has_key = 0; + static int has_key = 0; static int temp_key = 0; int key; - if (g_mapkey && has_key) - { + if (g_mapkey && has_key) { has_key = 0; return temp_key; } key = wgetch(w); - if (key == KEY_RESIZE) resize_term(0, 0); - if (key == ERR || !g_mapkey) return key; - if (key >= ALT_A && key <= ALT_Z) - { - has_key = 1; + if (key == KEY_RESIZE) + resize_term(0, 0); + if (key == ERR || !g_mapkey) + return key; + if (key >= ALT_A && key <= ALT_Z) { + has_key = 1; temp_key = key - ALT_A + 'A'; - } - else if (key >= ALT_0 && key <= ALT_9) - { - has_key = 1; + } else if (key >= ALT_0 && key <= ALT_9) { + has_key = 1; temp_key = key - ALT_0 + '0'; - } - else - { - switch (key) - { - case ALT_DEL: temp_key = KEY_DC; break; - case ALT_INS: temp_key = KEY_IC; break; - case ALT_HOME: temp_key = KEY_HOME; break; - case ALT_END: temp_key = KEY_END; break; - case ALT_PGUP: temp_key = KEY_PPAGE; break; - case ALT_PGDN: temp_key = KEY_NPAGE; break; - case ALT_UP: temp_key = KEY_UP; break; - case ALT_DOWN: temp_key = KEY_DOWN; break; - case ALT_RIGHT: temp_key = KEY_RIGHT; break; - case ALT_LEFT: temp_key = KEY_LEFT; break; - case ALT_BKSP: temp_key = KEY_BACKSPACE; break; - default: return key; + } else { + switch (key) { + case ALT_DEL: + temp_key = KEY_DC; + break; + case ALT_INS: + temp_key = KEY_IC; + break; + case ALT_HOME: + temp_key = KEY_HOME; + break; + case ALT_END: + temp_key = KEY_END; + break; + case ALT_PGUP: + temp_key = KEY_PPAGE; + break; + case ALT_PGDN: + temp_key = KEY_NPAGE; + break; + case ALT_UP: + temp_key = KEY_UP; + break; + case ALT_DOWN: + temp_key = KEY_DOWN; + break; + case ALT_RIGHT: + temp_key = KEY_RIGHT; + break; + case ALT_LEFT: + temp_key = KEY_LEFT; + break; + case ALT_BKSP: + temp_key = KEY_BACKSPACE; + break; + default: + return key; } } has_key = 1; @@ -174,63 +185,57 @@ static int xm_curses_window_getch_impl(WINDOW* w) } // new a window object -static void xm_curses_window_new(lua_State* lua, WINDOW* nw) -{ - if (nw) - { - WINDOW** w = (WINDOW**)lua_newuserdata(lua, sizeof(WINDOW*)); +static void xm_curses_window_new(lua_State *lua, WINDOW *nw) { + if (nw) { + WINDOW **w = (WINDOW **)lua_newuserdata(lua, sizeof(WINDOW *)); luaL_getmetatable(lua, XM_CURSES_WINDOW); lua_setmetatable(lua, -2); *w = nw; - } - else - { + } else { lua_pushliteral(lua, "failed to create window"); lua_error(lua); } } // get window -static WINDOW** xm_curses_window_get(lua_State* lua, int index) -{ - WINDOW** w = (WINDOW**)luaL_checkudata(lua, index, XM_CURSES_WINDOW); - if (w == NULL) luaL_argerror(lua, index, "bad curses window"); +static WINDOW **xm_curses_window_get(lua_State *lua, int index) { + WINDOW **w = (WINDOW **)luaL_checkudata(lua, index, XM_CURSES_WINDOW); + if (w == NULL) + luaL_argerror(lua, index, "bad curses window"); return w; } // get and check window -static WINDOW* xm_curses_window_check(lua_State* lua, int index) -{ - WINDOW** w = xm_curses_window_get(lua, index); - if (*w == NULL) luaL_argerror(lua, index, "attempt to use closed curses window"); +static WINDOW *xm_curses_window_check(lua_State *lua, int index) { + WINDOW **w = xm_curses_window_get(lua, index); + if (*w == NULL) + luaL_argerror(lua, index, "attempt to use closed curses window"); return *w; } // tostring(window) -static int xm_curses_window_tostring(lua_State* lua) -{ - WINDOW** w = xm_curses_window_get(lua, 1); - char const* s = NULL; - if (*w) s = (char const*)lua_touserdata(lua, 1); - lua_pushfstring(lua, "curses window (%s)", s? s : "closed"); +static int xm_curses_window_tostring(lua_State *lua) { + WINDOW **w = xm_curses_window_get(lua, 1); + char const *s = NULL; + if (*w) + s = (char const *)lua_touserdata(lua, 1); + lua_pushfstring(lua, "curses window (%s)", s ? s : "closed"); return 1; } // window:move(y, x) -static int xm_curses_window_move(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int y = luaL_checkint(lua, 2); - int x = luaL_checkint(lua, 3); +static int xm_curses_window_move(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int y = luaL_checkint(lua, 2); + int x = luaL_checkint(lua, 3); lua_pushboolean(lua, XM_CURSES_OK(wmove(w, y, x))); return 1; } // window:getyx(y, x) -static int xm_curses_window_getyx(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int y, x; +static int xm_curses_window_getyx(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int y, x; getyx(w, y, x); lua_pushnumber(lua, y); lua_pushnumber(lua, x); @@ -238,10 +243,9 @@ static int xm_curses_window_getyx(lua_State* lua) } // window:getmaxyx(y, x) -static int xm_curses_window_getmaxyx(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int y, x; +static int xm_curses_window_getmaxyx(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int y, x; getmaxyx(w, y, x); lua_pushnumber(lua, y); lua_pushnumber(lua, x); @@ -249,11 +253,9 @@ static int xm_curses_window_getmaxyx(lua_State* lua) } // window:delwin() -static int xm_curses_window_delwin(lua_State* lua) -{ - WINDOW** w = xm_curses_window_get(lua, 1); - if (*w && *w != stdscr) - { +static int xm_curses_window_delwin(lua_State *lua) { + WINDOW **w = xm_curses_window_get(lua, 1); + if (*w && *w != stdscr) { delwin(*w); *w = NULL; } @@ -261,32 +263,29 @@ static int xm_curses_window_delwin(lua_State* lua) } // window:addch(ch) -static int xm_curses_window_addch(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - chtype ch = xm_curses_checkch(lua, 2); +static int xm_curses_window_addch(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + chtype ch = xm_curses_checkch(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(waddch(w, ch))); return 1; } // window:addnstr(str) -static int xm_curses_window_addnstr(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - const char* str = luaL_checkstring(lua, 2); - int n = luaL_optint(lua, 3, -1); - if (n < 0) n = (int)lua_strlen(lua, 2); +static int xm_curses_window_addnstr(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + const char *str = luaL_checkstring(lua, 2); + int n = luaL_optint(lua, 3, -1); + if (n < 0) + n = (int)lua_strlen(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(waddnstr(w, str, n))); return 1; } // window:keypad(true) -static int xm_curses_window_keypad(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int enabled = lua_isnoneornil(lua, 2) ? 1 : lua_toboolean(lua, 2); - if (enabled) - { +static int xm_curses_window_keypad(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int enabled = lua_isnoneornil(lua, 2) ? 1 : lua_toboolean(lua, 2); + if (enabled) { // on WIN32 ALT keys need to be mapped, so to make sure you get the wanted keys, // only makes sense when using keypad(true) and echo(false) g_mapkey = 1; @@ -296,91 +295,83 @@ static int xm_curses_window_keypad(lua_State* lua) } // window:meta(true) -static int xm_curses_window_meta(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int enabled = lua_toboolean(lua, 2); +static int xm_curses_window_meta(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int enabled = lua_toboolean(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(meta(w, enabled))); return 1; } // window:nodelay(true) -static int xm_curses_window_nodelay(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int enabled = lua_toboolean(lua, 2); +static int xm_curses_window_nodelay(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int enabled = lua_toboolean(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(nodelay(w, enabled))); return 1; } // window:leaveok(true) -static int xm_curses_window_leaveok(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int enabled = lua_toboolean(lua, 2); +static int xm_curses_window_leaveok(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int enabled = lua_toboolean(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(leaveok(w, enabled))); return 1; } // window:getch() -static int xm_curses_window_getch(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int c = xm_curses_window_getch_impl(w); - if (c == ERR) return 0; +static int xm_curses_window_getch(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int c = xm_curses_window_getch_impl(w); + if (c == ERR) + return 0; lua_pushnumber(lua, c); return 1; } // window:attroff(attrs) -static int xm_curses_window_attroff(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int attrs = luaL_checkint(lua, 2); +static int xm_curses_window_attroff(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int attrs = luaL_checkint(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(wattroff(w, attrs))); return 1; } // window:attron(attrs) -static int xm_curses_window_attron(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int attrs = luaL_checkint(lua, 2); +static int xm_curses_window_attron(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int attrs = luaL_checkint(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(wattron(w, attrs))); return 1; } // window:attrset(attrs) -static int xm_curses_window_attrset(lua_State* lua) -{ - WINDOW* w = xm_curses_window_check(lua, 1); - int attrs = luaL_checkint(lua, 2); +static int xm_curses_window_attrset(lua_State *lua) { + WINDOW *w = xm_curses_window_check(lua, 1); + int attrs = luaL_checkint(lua, 2); lua_pushboolean(lua, XM_CURSES_OK(wattrset(w, attrs))); return 1; } // window:copywin(...) -static int xm_curses_window_copywin(lua_State* lua) -{ - WINDOW* srcwin = xm_curses_window_check(lua, 1); - WINDOW* dstwin = xm_curses_window_check(lua, 2); - int sminrow = luaL_checkint(lua, 3); - int smincol = luaL_checkint(lua, 4); - int dminrow = luaL_checkint(lua, 5); - int dmincol = luaL_checkint(lua, 6); - int dmaxrow = luaL_checkint(lua, 7); - int dmaxcol = luaL_checkint(lua, 8); - int overlay = lua_toboolean(lua, 9); - lua_pushboolean(lua, XM_CURSES_OK(copywin(srcwin, dstwin, sminrow, - smincol, dminrow, dmincol, dmaxrow, dmaxcol, overlay))); +static int xm_curses_window_copywin(lua_State *lua) { + WINDOW *srcwin = xm_curses_window_check(lua, 1); + WINDOW *dstwin = xm_curses_window_check(lua, 2); + int sminrow = luaL_checkint(lua, 3); + int smincol = luaL_checkint(lua, 4); + int dminrow = luaL_checkint(lua, 5); + int dmincol = luaL_checkint(lua, 6); + int dmaxrow = luaL_checkint(lua, 7); + int dmaxcol = luaL_checkint(lua, 8); + int overlay = lua_toboolean(lua, 9); + lua_pushboolean(lua, + XM_CURSES_OK( + copywin(srcwin, dstwin, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, overlay))); return 1; } // clean window after exiting program -static void xm_curses_cleanup() -{ - if (!isendwin()) - { +static void xm_curses_cleanup() { + if (!isendwin()) { wclear(stdscr); wrefresh(stdscr); endwin(); @@ -388,8 +379,7 @@ static void xm_curses_cleanup() } // register constants -static void xm_curses_register_constants(lua_State* lua) -{ +static void xm_curses_register_constants(lua_State *lua) { // colors XM_CURSES_CONST(COLOR_BLACK) XM_CURSES_CONST(COLOR_RED) @@ -495,9 +485,9 @@ static void xm_curses_register_constants(lua_State* lua) XM_CURSES_CONST(KEY_B3) #endif #if !defined(XCURSES) -# ifndef NOMOUSE +#ifndef NOMOUSE XM_CURSES_CONST(KEY_MOUSE) -# endif +#endif #endif XM_CURSES_CONST(KEY_MOVE) XM_CURSES_CONST(KEY_NEXT) @@ -560,7 +550,7 @@ static void xm_curses_register_constants(lua_State* lua) XM_CURSES_CONST2(KEY_F12, KEY_F(12)) #if !defined(XCURSES) -# ifndef NOMOUSE +#ifndef NOMOUSE // mouse constants XM_CURSES_CONST(BUTTON1_RELEASED) XM_CURSES_CONST(BUTTON1_PRESSED) @@ -587,26 +577,26 @@ static void xm_curses_register_constants(lua_State* lua) XM_CURSES_CONST(BUTTON_ALT) XM_CURSES_CONST(REPORT_MOUSE_POSITION) XM_CURSES_CONST(ALL_MOUSE_EVENTS) -# if NCURSES_MOUSE_VERSION > 1 +#if NCURSES_MOUSE_VERSION > 1 XM_CURSES_CONST(BUTTON5_RELEASED) XM_CURSES_CONST(BUTTON5_PRESSED) XM_CURSES_CONST(BUTTON5_CLICKED) XM_CURSES_CONST(BUTTON5_DOUBLE_CLICKED) XM_CURSES_CONST(BUTTON5_TRIPLE_CLICKED) -# endif -# endif +#endif +#endif #endif } // init curses -static int xm_curses_initscr(lua_State* lua) -{ - WINDOW* w = initscr(); - if (!w) return 0; +static int xm_curses_initscr(lua_State *lua) { + WINDOW *w = initscr(); + if (!w) + return 0; xm_curses_window_new(lua, w); #if defined(NCURSES_VERSION) -// ESCDELAY = 0; + // ESCDELAY = 0; set_escdelay(0); #endif @@ -622,8 +612,7 @@ static int xm_curses_initscr(lua_State* lua) return 1; } -static int xm_curses_endwin(lua_State* lua) -{ +static int xm_curses_endwin(lua_State *lua) { endwin(); #ifdef XCURSES XCursesExit(); @@ -632,19 +621,16 @@ static int xm_curses_endwin(lua_State* lua) return 0; } -static int xm_curses_stdscr(lua_State* lua) -{ +static int xm_curses_stdscr(lua_State *lua) { lua_pushstring(lua, XM_CURSES_STDSCR); lua_rawget(lua, LUA_REGISTRYINDEX); return 1; } #if !defined(XCURSES) && !defined(NOMOUSE) -static int xm_curses_getmouse(lua_State* lua) -{ +static int xm_curses_getmouse(lua_State *lua) { MEVENT e; - if (getmouse(&e) == OK) - { + if (getmouse(&e) == OK) { lua_pushinteger(lua, e.bstate); lua_pushinteger(lua, e.x); lua_pushinteger(lua, e.y); @@ -657,8 +643,7 @@ static int xm_curses_getmouse(lua_State* lua) return 1; } -static int xm_curses_mousemask(lua_State* lua) -{ +static int xm_curses_mousemask(lua_State *lua) { mmask_t m = luaL_checkint(lua, 1); mmask_t om; m = mousemask(m, &om); @@ -668,26 +653,23 @@ static int xm_curses_mousemask(lua_State* lua) } #endif -static int xm_curses_init_pair(lua_State* lua) -{ +static int xm_curses_init_pair(lua_State *lua) { short pair = luaL_checkint(lua, 1); - short f = luaL_checkint(lua, 2); - short b = luaL_checkint(lua, 3); + short f = luaL_checkint(lua, 2); + short b = luaL_checkint(lua, 3); lua_pushboolean(lua, XM_CURSES_OK(init_pair(pair, f, b))); return 1; } -static int xm_curses_COLOR_PAIR(lua_State* lua) -{ +static int xm_curses_COLOR_PAIR(lua_State *lua) { int n = luaL_checkint(lua, 1); lua_pushnumber(lua, COLOR_PAIR(n)); return 1; } -static int xm_curses_curs_set(lua_State* lua) -{ - int vis = luaL_checkint(lua, 1); +static int xm_curses_curs_set(lua_State *lua) { + int vis = luaL_checkint(lua, 1); int state = curs_set(vis); if (state == ERR) return 0; @@ -696,15 +678,13 @@ static int xm_curses_curs_set(lua_State* lua) return 1; } -static int xm_curses_napms(lua_State* lua) -{ +static int xm_curses_napms(lua_State *lua) { int ms = luaL_checkint(lua, 1); lua_pushboolean(lua, XM_CURSES_OK(napms(ms))); return 1; } -static int xm_curses_cbreak(lua_State* lua) -{ +static int xm_curses_cbreak(lua_State *lua) { if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) lua_pushboolean(lua, XM_CURSES_OK(cbreak())); else @@ -712,8 +692,7 @@ static int xm_curses_cbreak(lua_State* lua) return 1; } -static int xm_curses_echo(lua_State* lua) -{ +static int xm_curses_echo(lua_State *lua) { if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) lua_pushboolean(lua, XM_CURSES_OK(echo())); else @@ -721,8 +700,7 @@ static int xm_curses_echo(lua_State* lua) return 1; } -static int xm_curses_nl(lua_State* lua) -{ +static int xm_curses_nl(lua_State *lua) { if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) lua_pushboolean(lua, XM_CURSES_OK(nl())); else @@ -730,10 +708,9 @@ static int xm_curses_nl(lua_State* lua) return 1; } -static int xm_curses_newpad(lua_State* lua) -{ +static int xm_curses_newpad(lua_State *lua) { int nlines = luaL_checkint(lua, 1); - int ncols = luaL_checkint(lua, 2); + int ncols = luaL_checkint(lua, 2); xm_curses_window_new(lua, newpad(nlines, ncols)); return 1; } @@ -751,69 +728,66 @@ XM_CURSES_WINDOW_BOOLOK(wnoutrefresh) * globals */ -static const luaL_Reg g_window_functions[] = -{ - { "close", xm_curses_window_delwin }, - { "keypad", xm_curses_window_keypad }, - { "meta", xm_curses_window_meta }, - { "nodelay", xm_curses_window_nodelay }, - { "leaveok", xm_curses_window_leaveok }, - { "move", xm_curses_window_move }, - { "clear", xm_curses_window_wclear }, - { "noutrefresh",xm_curses_window_wnoutrefresh }, - { "attroff", xm_curses_window_attroff }, - { "attron", xm_curses_window_attron }, - { "attrset", xm_curses_window_attrset }, - { "getch", xm_curses_window_getch }, - { "getyx", xm_curses_window_getyx }, - { "getmaxyx", xm_curses_window_getmaxyx }, - { "addch", xm_curses_window_addch }, - { "addstr", xm_curses_window_addnstr }, - { "copy", xm_curses_window_copywin }, - {"__gc", xm_curses_window_delwin }, - {"__tostring", xm_curses_window_tostring }, - {NULL, NULL } +static const luaL_Reg g_window_functions[] = { + { "close", xm_curses_window_delwin }, + { "keypad", xm_curses_window_keypad }, + { "meta", xm_curses_window_meta }, + { "nodelay", xm_curses_window_nodelay }, + { "leaveok", xm_curses_window_leaveok }, + { "move", xm_curses_window_move }, + { "clear", xm_curses_window_wclear }, + { "noutrefresh", xm_curses_window_wnoutrefresh }, + { "attroff", xm_curses_window_attroff }, + { "attron", xm_curses_window_attron }, + { "attrset", xm_curses_window_attrset }, + { "getch", xm_curses_window_getch }, + { "getyx", xm_curses_window_getyx }, + { "getmaxyx", xm_curses_window_getmaxyx }, + { "addch", xm_curses_window_addch }, + { "addstr", xm_curses_window_addnstr }, + { "copy", xm_curses_window_copywin }, + { "__gc", xm_curses_window_delwin }, + { "__tostring", xm_curses_window_tostring }, + { NULL, NULL }, }; -static const luaL_Reg g_curses_functions[] = -{ - { "done", xm_curses_endwin }, - { "isdone", xm_curses_isendwin }, - { "main_window", xm_curses_stdscr }, - { "columns", xm_curses_COLS }, - { "lines", xm_curses_LINES }, - { "start_color", xm_curses_start_color }, - { "has_colors", xm_curses_has_colors }, - { "init_pair", xm_curses_init_pair }, - { "color_pair", xm_curses_COLOR_PAIR }, - { "napms", xm_curses_napms }, - { "cursor_set", xm_curses_curs_set }, - { "new_pad", xm_curses_newpad }, - { "doupdate", xm_curses_doupdate }, - { "cbreak", xm_curses_cbreak }, - { "echo", xm_curses_echo }, - { "nl", xm_curses_nl }, +static const luaL_Reg g_curses_functions[] = { + { "done", xm_curses_endwin }, + { "isdone", xm_curses_isendwin }, + { "main_window", xm_curses_stdscr }, + { "columns", xm_curses_COLS }, + { "lines", xm_curses_LINES }, + { "start_color", xm_curses_start_color }, + { "has_colors", xm_curses_has_colors }, + { "init_pair", xm_curses_init_pair }, + { "color_pair", xm_curses_COLOR_PAIR }, + { "napms", xm_curses_napms }, + { "cursor_set", xm_curses_curs_set }, + { "new_pad", xm_curses_newpad }, + { "doupdate", xm_curses_doupdate }, + { "cbreak", xm_curses_cbreak }, + { "echo", xm_curses_echo }, + { "nl", xm_curses_nl }, #if !defined(XCURSES) #ifndef NOMOUSE - { "mousemask", xm_curses_mousemask }, - { "getmouse", xm_curses_getmouse }, + { "mousemask", xm_curses_mousemask }, + { "getmouse", xm_curses_getmouse }, #endif #endif - {NULL, NULL} + { NULL, NULL }, }; /* ////////////////////////////////////////////////////////////////////////////////////// * implementations */ -int xm_lua_curses_register(lua_State* lua, const char* module) -{ +int xm_lua_curses_register(lua_State *lua, const char *module) { // create new metatable for window objects luaL_newmetatable(lua, XM_CURSES_WINDOW); lua_pushliteral(lua, "__index"); - lua_pushvalue(lua, -2); /* push metatable */ - lua_rawset(lua, -3); /* metatable.__index = metatable */ + lua_pushvalue(lua, -2); /* push metatable */ + lua_rawset(lua, -3); /* metatable.__index = metatable */ luaL_setfuncs(lua, g_window_functions, 0); - lua_pop(lua, 1); /* remove metatable from stack */ + lua_pop(lua, 1); /* remove metatable from stack */ // create global table with curses methods/variables/constants lua_newtable(lua); diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 61ba79af1..a65395423 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "engine" -#define TB_TRACE_MODULE_DEBUG (1) +#define TB_TRACE_MODULE_NAME "engine" +#define TB_TRACE_MODULE_DEBUG (1) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -31,38 +31,39 @@ #include "xmake.h" #include "io/poller.h" #if defined(TB_CONFIG_OS_WINDOWS) -# include -# include -# include +#include +#include +#include #elif defined(TB_CONFIG_OS_MACOSX) || defined(TB_CONFIG_OS_IOS) -# include -# include -# include -#elif defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD) || defined(TB_CONFIG_OS_ANDROID) || defined(TB_CONFIG_OS_HAIKU) -# include -# include +#include +#include +#include +#elif defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD) || defined(TB_CONFIG_OS_ANDROID) || \ + defined(TB_CONFIG_OS_HAIKU) +#include +#include #endif #ifdef TB_CONFIG_OS_BSD -# include -# include -# include +#include +#include +#include #endif #ifdef TB_CONFIG_OS_HAIKU -# include +#include #endif #ifdef __COSMOPOLITAN__ -# include +#include #endif // for uid #ifndef TB_CONFIG_OS_WINDOWS -# include -# include +#include +#include #endif // for embed files #ifdef XM_EMBED_ENABLE -# include "lz4/prefix.h" +#include "lz4/prefix.h" #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -71,321 +72,318 @@ // proc/self #if defined(TB_CONFIG_OS_LINUX) -# define XM_PROC_SELF_FILE "/proc/self/exe" +#define XM_PROC_SELF_FILE "/proc/self/exe" #elif defined(TB_CONFIG_OS_BSD) && !defined(__OpenBSD__) && !defined(__FreeBSD__) -# if defined(__NetBSD__) -# define XM_PROC_SELF_FILE "/proc/curproc/exe" -# else -# define XM_PROC_SELF_FILE "/proc/curproc/file" -# endif +#if defined(__NetBSD__) +#define XM_PROC_SELF_FILE "/proc/curproc/exe" +#else +#define XM_PROC_SELF_FILE "/proc/curproc/file" +#endif #endif // hook lua memory allocator -#define XM_HOOK_LUA_MEMALLOC (0) +#define XM_HOOK_LUA_MEMALLOC (0) /* ////////////////////////////////////////////////////////////////////////////////////// * types */ // the engine type -typedef struct __xm_engine_t -{ +typedef struct __xm_engine_t { // the lua - lua_State* lua; + lua_State *lua; // the engine name - tb_char_t name[64]; + tb_char_t name[64]; // the io poller - tb_poller_ref_t poller; - xm_poller_state_t poller_state; + tb_poller_ref_t poller; + xm_poller_state_t poller_state; #ifdef XM_EMBED_ENABLE // the temporary directory - tb_char_t tmpdir[TB_PATH_MAXN]; + tb_char_t tmpdir[TB_PATH_MAXN]; // the embed files - tb_byte_t const* embeddata[32]; - tb_size_t embedsize[32]; - tb_size_t embedcount; + tb_byte_t const *embeddata[32]; + tb_size_t embedsize[32]; + tb_size_t embedcount; #endif - -}xm_engine_t; +} xm_engine_t; /* ////////////////////////////////////////////////////////////////////////////////////// * declaration */ // the os functions -tb_int_t xm_os_argv(lua_State* lua); -tb_int_t xm_os_args(lua_State* lua); -tb_int_t xm_os_find(lua_State* lua); -tb_int_t xm_os_link(lua_State* lua); -tb_int_t xm_os_isdir(lua_State* lua); -tb_int_t xm_os_rmdir(lua_State* lua); -tb_int_t xm_os_mkdir(lua_State* lua); -tb_int_t xm_os_cpdir(lua_State* lua); -tb_int_t xm_os_chdir(lua_State* lua); -tb_int_t xm_os_mtime(lua_State* lua); -tb_int_t xm_os_sleep(lua_State* lua); -tb_int_t xm_os_mclock(lua_State* lua); -tb_int_t xm_os_curdir(lua_State* lua); -tb_int_t xm_os_tmpdir(lua_State* lua); -tb_int_t xm_os_islink(lua_State* lua); -tb_int_t xm_os_isfile(lua_State* lua); -tb_int_t xm_os_touch(lua_State* lua); -tb_int_t xm_os_rmfile(lua_State* lua); -tb_int_t xm_os_cpfile(lua_State* lua); -tb_int_t xm_os_fscase(lua_State* lua); -tb_int_t xm_os_rename(lua_State* lua); -tb_int_t xm_os_exists(lua_State* lua); -tb_int_t xm_os_setenv(lua_State* lua); -tb_int_t xm_os_getenv(lua_State* lua); -tb_int_t xm_os_getenvs(lua_State* lua); -tb_int_t xm_os_cpuinfo(lua_State* lua); -tb_int_t xm_os_meminfo(lua_State* lua); -tb_int_t xm_os_readlink(lua_State* lua); -tb_int_t xm_os_filesize(lua_State* lua); -tb_int_t xm_os_emptydir(lua_State* lua); -tb_int_t xm_os_syserror(lua_State* lua); -tb_int_t xm_os_strerror(lua_State* lua); -tb_int_t xm_os_getwinsize(lua_State* lua); -tb_int_t xm_os_getpid(lua_State* lua); -tb_int_t xm_os_signal(lua_State* lua); +tb_int_t xm_os_argv(lua_State *lua); +tb_int_t xm_os_args(lua_State *lua); +tb_int_t xm_os_find(lua_State *lua); +tb_int_t xm_os_link(lua_State *lua); +tb_int_t xm_os_isdir(lua_State *lua); +tb_int_t xm_os_rmdir(lua_State *lua); +tb_int_t xm_os_mkdir(lua_State *lua); +tb_int_t xm_os_cpdir(lua_State *lua); +tb_int_t xm_os_chdir(lua_State *lua); +tb_int_t xm_os_mtime(lua_State *lua); +tb_int_t xm_os_sleep(lua_State *lua); +tb_int_t xm_os_mclock(lua_State *lua); +tb_int_t xm_os_curdir(lua_State *lua); +tb_int_t xm_os_tmpdir(lua_State *lua); +tb_int_t xm_os_islink(lua_State *lua); +tb_int_t xm_os_isfile(lua_State *lua); +tb_int_t xm_os_touch(lua_State *lua); +tb_int_t xm_os_rmfile(lua_State *lua); +tb_int_t xm_os_cpfile(lua_State *lua); +tb_int_t xm_os_fscase(lua_State *lua); +tb_int_t xm_os_rename(lua_State *lua); +tb_int_t xm_os_exists(lua_State *lua); +tb_int_t xm_os_setenv(lua_State *lua); +tb_int_t xm_os_getenv(lua_State *lua); +tb_int_t xm_os_getenvs(lua_State *lua); +tb_int_t xm_os_cpuinfo(lua_State *lua); +tb_int_t xm_os_meminfo(lua_State *lua); +tb_int_t xm_os_readlink(lua_State *lua); +tb_int_t xm_os_filesize(lua_State *lua); +tb_int_t xm_os_emptydir(lua_State *lua); +tb_int_t xm_os_syserror(lua_State *lua); +tb_int_t xm_os_strerror(lua_State *lua); +tb_int_t xm_os_getwinsize(lua_State *lua); +tb_int_t xm_os_getpid(lua_State *lua); +tb_int_t xm_os_signal(lua_State *lua); #ifndef TB_CONFIG_OS_WINDOWS -tb_int_t xm_os_uid(lua_State* lua); -tb_int_t xm_os_gid(lua_State* lua); -tb_int_t xm_os_getown(lua_State* lua); +tb_int_t xm_os_uid(lua_State *lua); +tb_int_t xm_os_gid(lua_State *lua); +tb_int_t xm_os_getown(lua_State *lua); #endif // the io/file functions -tb_int_t xm_io_stdfile(lua_State* lua); -tb_int_t xm_io_file_open(lua_State* lua); -tb_int_t xm_io_file_read(lua_State* lua); -tb_int_t xm_io_file_readable(lua_State* lua); -tb_int_t xm_io_file_seek(lua_State* lua); -tb_int_t xm_io_file_size(lua_State* lua); -tb_int_t xm_io_file_rawfd(lua_State* lua); -tb_int_t xm_io_file_write(lua_State* lua); -tb_int_t xm_io_file_flush(lua_State* lua); -tb_int_t xm_io_file_close(lua_State* lua); -tb_int_t xm_io_file_isatty(lua_State* lua); +tb_int_t xm_io_stdfile(lua_State *lua); +tb_int_t xm_io_file_open(lua_State *lua); +tb_int_t xm_io_file_read(lua_State *lua); +tb_int_t xm_io_file_readable(lua_State *lua); +tb_int_t xm_io_file_seek(lua_State *lua); +tb_int_t xm_io_file_size(lua_State *lua); +tb_int_t xm_io_file_rawfd(lua_State *lua); +tb_int_t xm_io_file_write(lua_State *lua); +tb_int_t xm_io_file_flush(lua_State *lua); +tb_int_t xm_io_file_close(lua_State *lua); +tb_int_t xm_io_file_isatty(lua_State *lua); // the io/filelock functions -tb_int_t xm_io_filelock_open(lua_State* lua); -tb_int_t xm_io_filelock_lock(lua_State* lua); -tb_int_t xm_io_filelock_unlock(lua_State* lua); -tb_int_t xm_io_filelock_trylock(lua_State* lua); -tb_int_t xm_io_filelock_close(lua_State* lua); +tb_int_t xm_io_filelock_open(lua_State *lua); +tb_int_t xm_io_filelock_lock(lua_State *lua); +tb_int_t xm_io_filelock_unlock(lua_State *lua); +tb_int_t xm_io_filelock_trylock(lua_State *lua); +tb_int_t xm_io_filelock_close(lua_State *lua); // the io/socket functions -tb_int_t xm_io_socket_open(lua_State* lua); -tb_int_t xm_io_socket_rawfd(lua_State* lua); -tb_int_t xm_io_socket_peeraddr(lua_State* lua); -tb_int_t xm_io_socket_wait(lua_State* lua); -tb_int_t xm_io_socket_bind(lua_State* lua); -tb_int_t xm_io_socket_ctrl(lua_State* lua); -tb_int_t xm_io_socket_listen(lua_State* lua); -tb_int_t xm_io_socket_accept(lua_State* lua); -tb_int_t xm_io_socket_connect(lua_State* lua); -tb_int_t xm_io_socket_send(lua_State* lua); -tb_int_t xm_io_socket_sendto(lua_State* lua); -tb_int_t xm_io_socket_sendfile(lua_State* lua); -tb_int_t xm_io_socket_recv(lua_State* lua); -tb_int_t xm_io_socket_recvfrom(lua_State* lua); -tb_int_t xm_io_socket_kill(lua_State* lua); -tb_int_t xm_io_socket_close(lua_State* lua); +tb_int_t xm_io_socket_open(lua_State *lua); +tb_int_t xm_io_socket_rawfd(lua_State *lua); +tb_int_t xm_io_socket_peeraddr(lua_State *lua); +tb_int_t xm_io_socket_wait(lua_State *lua); +tb_int_t xm_io_socket_bind(lua_State *lua); +tb_int_t xm_io_socket_ctrl(lua_State *lua); +tb_int_t xm_io_socket_listen(lua_State *lua); +tb_int_t xm_io_socket_accept(lua_State *lua); +tb_int_t xm_io_socket_connect(lua_State *lua); +tb_int_t xm_io_socket_send(lua_State *lua); +tb_int_t xm_io_socket_sendto(lua_State *lua); +tb_int_t xm_io_socket_sendfile(lua_State *lua); +tb_int_t xm_io_socket_recv(lua_State *lua); +tb_int_t xm_io_socket_recvfrom(lua_State *lua); +tb_int_t xm_io_socket_kill(lua_State *lua); +tb_int_t xm_io_socket_close(lua_State *lua); // the io/pipe functions -tb_int_t xm_io_pipe_open(lua_State* lua); -tb_int_t xm_io_pipe_openpair(lua_State* lua); -tb_int_t xm_io_pipe_close(lua_State* lua); -tb_int_t xm_io_pipe_read(lua_State* lua); -tb_int_t xm_io_pipe_write(lua_State* lua); -tb_int_t xm_io_pipe_wait(lua_State* lua); -tb_int_t xm_io_pipe_connect(lua_State* lua); +tb_int_t xm_io_pipe_open(lua_State *lua); +tb_int_t xm_io_pipe_openpair(lua_State *lua); +tb_int_t xm_io_pipe_close(lua_State *lua); +tb_int_t xm_io_pipe_read(lua_State *lua); +tb_int_t xm_io_pipe_write(lua_State *lua); +tb_int_t xm_io_pipe_wait(lua_State *lua); +tb_int_t xm_io_pipe_connect(lua_State *lua); // the io/poller functions -tb_int_t xm_io_poller_insert(lua_State* lua); -tb_int_t xm_io_poller_modify(lua_State* lua); -tb_int_t xm_io_poller_remove(lua_State* lua); -tb_int_t xm_io_poller_spank(lua_State* lua); -tb_int_t xm_io_poller_support(lua_State* lua); -tb_int_t xm_io_poller_wait(lua_State* lua); +tb_int_t xm_io_poller_insert(lua_State *lua); +tb_int_t xm_io_poller_modify(lua_State *lua); +tb_int_t xm_io_poller_remove(lua_State *lua); +tb_int_t xm_io_poller_spank(lua_State *lua); +tb_int_t xm_io_poller_support(lua_State *lua); +tb_int_t xm_io_poller_wait(lua_State *lua); // the path functions -tb_int_t xm_path_relative(lua_State* lua); -tb_int_t xm_path_absolute(lua_State* lua); -tb_int_t xm_path_translate(lua_State* lua); -tb_int_t xm_path_directory(lua_State* lua); -tb_int_t xm_path_is_absolute(lua_State* lua); +tb_int_t xm_path_relative(lua_State *lua); +tb_int_t xm_path_absolute(lua_State *lua); +tb_int_t xm_path_translate(lua_State *lua); +tb_int_t xm_path_directory(lua_State *lua); +tb_int_t xm_path_is_absolute(lua_State *lua); // the hash functions -tb_int_t xm_hash_uuid4(lua_State* lua); -tb_int_t xm_hash_sha(lua_State* lua); -tb_int_t xm_hash_md5(lua_State* lua); -tb_int_t xm_hash_xxhash(lua_State* lua); -tb_int_t xm_hash_rand32(lua_State* lua); -tb_int_t xm_hash_rand64(lua_State* lua); -tb_int_t xm_hash_rand128(lua_State* lua); +tb_int_t xm_hash_uuid4(lua_State *lua); +tb_int_t xm_hash_sha(lua_State *lua); +tb_int_t xm_hash_md5(lua_State *lua); +tb_int_t xm_hash_xxhash(lua_State *lua); +tb_int_t xm_hash_rand32(lua_State *lua); +tb_int_t xm_hash_rand64(lua_State *lua); +tb_int_t xm_hash_rand128(lua_State *lua); // the base64 functions -tb_int_t xm_base64_encode(lua_State* lua); -tb_int_t xm_base64_decode(lua_State* lua); +tb_int_t xm_base64_encode(lua_State *lua); +tb_int_t xm_base64_decode(lua_State *lua); // the lz4 functions -tb_int_t xm_lz4_compress(lua_State* lua); -tb_int_t xm_lz4_decompress(lua_State* lua); -tb_int_t xm_lz4_block_compress(lua_State* lua); -tb_int_t xm_lz4_block_decompress(lua_State* lua); -tb_int_t xm_lz4_compress_file(lua_State* lua); -tb_int_t xm_lz4_decompress_file(lua_State* lua); -tb_int_t xm_lz4_compress_stream_open(lua_State* lua); -tb_int_t xm_lz4_compress_stream_read(lua_State* lua); -tb_int_t xm_lz4_compress_stream_write(lua_State* lua); -tb_int_t xm_lz4_compress_stream_close(lua_State* lua); -tb_int_t xm_lz4_decompress_stream_open(lua_State* lua); -tb_int_t xm_lz4_decompress_stream_read(lua_State* lua); -tb_int_t xm_lz4_decompress_stream_write(lua_State* lua); -tb_int_t xm_lz4_decompress_stream_close(lua_State* lua); +tb_int_t xm_lz4_compress(lua_State *lua); +tb_int_t xm_lz4_decompress(lua_State *lua); +tb_int_t xm_lz4_block_compress(lua_State *lua); +tb_int_t xm_lz4_block_decompress(lua_State *lua); +tb_int_t xm_lz4_compress_file(lua_State *lua); +tb_int_t xm_lz4_decompress_file(lua_State *lua); +tb_int_t xm_lz4_compress_stream_open(lua_State *lua); +tb_int_t xm_lz4_compress_stream_read(lua_State *lua); +tb_int_t xm_lz4_compress_stream_write(lua_State *lua); +tb_int_t xm_lz4_compress_stream_close(lua_State *lua); +tb_int_t xm_lz4_decompress_stream_open(lua_State *lua); +tb_int_t xm_lz4_decompress_stream_read(lua_State *lua); +tb_int_t xm_lz4_decompress_stream_write(lua_State *lua); +tb_int_t xm_lz4_decompress_stream_close(lua_State *lua); // the bloom filter functions -tb_int_t xm_bloom_filter_open(lua_State* lua); -tb_int_t xm_bloom_filter_close(lua_State* lua); -tb_int_t xm_bloom_filter_clear(lua_State* lua); -tb_int_t xm_bloom_filter_data(lua_State* lua); -tb_int_t xm_bloom_filter_size(lua_State* lua); -tb_int_t xm_bloom_filter_get(lua_State* lua); -tb_int_t xm_bloom_filter_set(lua_State* lua); -tb_int_t xm_bloom_filter_data_set(lua_State* lua); +tb_int_t xm_bloom_filter_open(lua_State *lua); +tb_int_t xm_bloom_filter_close(lua_State *lua); +tb_int_t xm_bloom_filter_clear(lua_State *lua); +tb_int_t xm_bloom_filter_data(lua_State *lua); +tb_int_t xm_bloom_filter_size(lua_State *lua); +tb_int_t xm_bloom_filter_get(lua_State *lua); +tb_int_t xm_bloom_filter_set(lua_State *lua); +tb_int_t xm_bloom_filter_data_set(lua_State *lua); // the windows functions #ifdef TB_CONFIG_OS_WINDOWS -tb_int_t xm_winos_cp_info(lua_State* lua); -tb_int_t xm_winos_console_cp(lua_State* lua); -tb_int_t xm_winos_console_output_cp(lua_State* lua); -tb_int_t xm_winos_ansi_cp(lua_State* lua); -tb_int_t xm_winos_oem_cp(lua_State* lua); -tb_int_t xm_winos_logical_drives(lua_State* lua); -tb_int_t xm_winos_registry_query(lua_State* lua); -tb_int_t xm_winos_registry_keys(lua_State* lua); -tb_int_t xm_winos_registry_values(lua_State* lua); -tb_int_t xm_winos_short_path(lua_State* lua); +tb_int_t xm_winos_cp_info(lua_State *lua); +tb_int_t xm_winos_console_cp(lua_State *lua); +tb_int_t xm_winos_console_output_cp(lua_State *lua); +tb_int_t xm_winos_ansi_cp(lua_State *lua); +tb_int_t xm_winos_oem_cp(lua_State *lua); +tb_int_t xm_winos_logical_drives(lua_State *lua); +tb_int_t xm_winos_registry_query(lua_State *lua); +tb_int_t xm_winos_registry_keys(lua_State *lua); +tb_int_t xm_winos_registry_values(lua_State *lua); +tb_int_t xm_winos_short_path(lua_State *lua); #endif // the string functions -tb_int_t xm_string_trim(lua_State* lua); -tb_int_t xm_string_split(lua_State* lua); -tb_int_t xm_string_lastof(lua_State* lua); -tb_int_t xm_string_convert(lua_State* lua); -tb_int_t xm_string_endswith(lua_State* lua); -tb_int_t xm_string_startswith(lua_State* lua); +tb_int_t xm_string_trim(lua_State *lua); +tb_int_t xm_string_split(lua_State *lua); +tb_int_t xm_string_lastof(lua_State *lua); +tb_int_t xm_string_convert(lua_State *lua); +tb_int_t xm_string_endswith(lua_State *lua); +tb_int_t xm_string_startswith(lua_State *lua); // the process functions -tb_int_t xm_process_open(lua_State* lua); -tb_int_t xm_process_openv(lua_State* lua); -tb_int_t xm_process_wait(lua_State* lua); -tb_int_t xm_process_kill(lua_State* lua); -tb_int_t xm_process_close(lua_State* lua); +tb_int_t xm_process_open(lua_State *lua); +tb_int_t xm_process_openv(lua_State *lua); +tb_int_t xm_process_wait(lua_State *lua); +tb_int_t xm_process_kill(lua_State *lua); +tb_int_t xm_process_close(lua_State *lua); // the fwatcher functions -tb_int_t xm_fwatcher_open(lua_State* lua); -tb_int_t xm_fwatcher_add(lua_State* lua); -tb_int_t xm_fwatcher_remove(lua_State* lua); -tb_int_t xm_fwatcher_wait(lua_State* lua); -tb_int_t xm_fwatcher_close(lua_State* lua); +tb_int_t xm_fwatcher_open(lua_State *lua); +tb_int_t xm_fwatcher_add(lua_State *lua); +tb_int_t xm_fwatcher_remove(lua_State *lua); +tb_int_t xm_fwatcher_wait(lua_State *lua); +tb_int_t xm_fwatcher_close(lua_State *lua); // the sandbox functions -tb_int_t xm_sandbox_interactive(lua_State* lua); +tb_int_t xm_sandbox_interactive(lua_State *lua); #ifdef XM_CONFIG_API_HAVE_READLINE // the readline functions -tb_int_t xm_readline_readline(lua_State* lua); -tb_int_t xm_readline_history_list(lua_State* lua); -tb_int_t xm_readline_add_history(lua_State* lua); -tb_int_t xm_readline_clear_history(lua_State* lua); +tb_int_t xm_readline_readline(lua_State *lua); +tb_int_t xm_readline_history_list(lua_State *lua); +tb_int_t xm_readline_add_history(lua_State *lua); +tb_int_t xm_readline_clear_history(lua_State *lua); #endif // the semver functions -tb_int_t xm_semver_parse(lua_State* lua); -tb_int_t xm_semver_compare(lua_State* lua); -tb_int_t xm_semver_satisfies(lua_State* lua); -tb_int_t xm_semver_select(lua_State* lua); +tb_int_t xm_semver_parse(lua_State *lua); +tb_int_t xm_semver_compare(lua_State *lua); +tb_int_t xm_semver_satisfies(lua_State *lua); +tb_int_t xm_semver_select(lua_State *lua); // the libc functions -tb_int_t xm_libc_malloc(lua_State* lua); -tb_int_t xm_libc_free(lua_State* lua); -tb_int_t xm_libc_memcpy(lua_State* lua); -tb_int_t xm_libc_memmov(lua_State* lua); -tb_int_t xm_libc_memset(lua_State* lua); -tb_int_t xm_libc_strndup(lua_State* lua); -tb_int_t xm_libc_dataptr(lua_State* lua); -tb_int_t xm_libc_byteof(lua_State* lua); -tb_int_t xm_libc_setbyte(lua_State* lua); +tb_int_t xm_libc_malloc(lua_State *lua); +tb_int_t xm_libc_free(lua_State *lua); +tb_int_t xm_libc_memcpy(lua_State *lua); +tb_int_t xm_libc_memmov(lua_State *lua); +tb_int_t xm_libc_memset(lua_State *lua); +tb_int_t xm_libc_strndup(lua_State *lua); +tb_int_t xm_libc_dataptr(lua_State *lua); +tb_int_t xm_libc_byteof(lua_State *lua); +tb_int_t xm_libc_setbyte(lua_State *lua); // the tty functions -tb_int_t xm_tty_term_mode(lua_State* lua); +tb_int_t xm_tty_term_mode(lua_State *lua); // the package functions -tb_int_t xm_package_loadxmi(lua_State* lua); +tb_int_t xm_package_loadxmi(lua_State *lua); // the utils functions -tb_int_t xm_utils_bin2c(lua_State* lua); +tb_int_t xm_utils_bin2c(lua_State *lua); #ifdef XM_CONFIG_API_HAVE_CURSES // register curses functions -tb_int_t xm_lua_curses_register(lua_State* lua, tb_char_t const* module); +tb_int_t xm_lua_curses_register(lua_State *lua, tb_char_t const *module); #endif // the thread functions -tb_int_t xm_thread_init(lua_State* lua); -tb_int_t xm_thread_exit(lua_State* lua); -tb_int_t xm_thread_wait(lua_State* lua); -tb_int_t xm_thread_suspend(lua_State* lua); -tb_int_t xm_thread_resume(lua_State* lua); +tb_int_t xm_thread_init(lua_State *lua); +tb_int_t xm_thread_exit(lua_State *lua); +tb_int_t xm_thread_wait(lua_State *lua); +tb_int_t xm_thread_suspend(lua_State *lua); +tb_int_t xm_thread_resume(lua_State *lua); // the thread/mutex functions -tb_int_t xm_thread_mutex_init(lua_State* lua); -tb_int_t xm_thread_mutex_exit(lua_State* lua); -tb_int_t xm_thread_mutex_lock(lua_State* lua); -tb_int_t xm_thread_mutex_trylock(lua_State* lua); -tb_int_t xm_thread_mutex_unlock(lua_State* lua); -tb_int_t xm_thread_mutex_incref(lua_State* lua); +tb_int_t xm_thread_mutex_init(lua_State *lua); +tb_int_t xm_thread_mutex_exit(lua_State *lua); +tb_int_t xm_thread_mutex_lock(lua_State *lua); +tb_int_t xm_thread_mutex_trylock(lua_State *lua); +tb_int_t xm_thread_mutex_unlock(lua_State *lua); +tb_int_t xm_thread_mutex_incref(lua_State *lua); // the thread/event functions -tb_int_t xm_thread_event_init(lua_State* lua); -tb_int_t xm_thread_event_exit(lua_State* lua); -tb_int_t xm_thread_event_post(lua_State* lua); -tb_int_t xm_thread_event_wait(lua_State* lua); -tb_int_t xm_thread_event_incref(lua_State* lua); +tb_int_t xm_thread_event_init(lua_State *lua); +tb_int_t xm_thread_event_exit(lua_State *lua); +tb_int_t xm_thread_event_post(lua_State *lua); +tb_int_t xm_thread_event_wait(lua_State *lua); +tb_int_t xm_thread_event_incref(lua_State *lua); // the thread/semaphore functions -tb_int_t xm_thread_semaphore_init(lua_State* lua); -tb_int_t xm_thread_semaphore_exit(lua_State* lua); -tb_int_t xm_thread_semaphore_post(lua_State* lua); -tb_int_t xm_thread_semaphore_wait(lua_State* lua); -tb_int_t xm_thread_semaphore_incref(lua_State* lua); +tb_int_t xm_thread_semaphore_init(lua_State *lua); +tb_int_t xm_thread_semaphore_exit(lua_State *lua); +tb_int_t xm_thread_semaphore_post(lua_State *lua); +tb_int_t xm_thread_semaphore_wait(lua_State *lua); +tb_int_t xm_thread_semaphore_incref(lua_State *lua); // the thread/queue functions -tb_int_t xm_thread_queue_init(lua_State* lua); -tb_int_t xm_thread_queue_exit(lua_State* lua); -tb_int_t xm_thread_queue_size(lua_State* lua); -tb_int_t xm_thread_queue_clear(lua_State* lua); -tb_int_t xm_thread_queue_incref(lua_State* lua); -tb_int_t xm_thread_queue_push(lua_State* lua); -tb_int_t xm_thread_queue_pop(lua_State* lua); +tb_int_t xm_thread_queue_init(lua_State *lua); +tb_int_t xm_thread_queue_exit(lua_State *lua); +tb_int_t xm_thread_queue_size(lua_State *lua); +tb_int_t xm_thread_queue_clear(lua_State *lua); +tb_int_t xm_thread_queue_incref(lua_State *lua); +tb_int_t xm_thread_queue_push(lua_State *lua); +tb_int_t xm_thread_queue_pop(lua_State *lua); // the thread/sharedata functions -tb_int_t xm_thread_sharedata_init(lua_State* lua); -tb_int_t xm_thread_sharedata_exit(lua_State* lua); -tb_int_t xm_thread_sharedata_clear(lua_State* lua); -tb_int_t xm_thread_sharedata_incref(lua_State* lua); -tb_int_t xm_thread_sharedata_set(lua_State* lua); -tb_int_t xm_thread_sharedata_get_(lua_State* lua); +tb_int_t xm_thread_sharedata_init(lua_State *lua); +tb_int_t xm_thread_sharedata_exit(lua_State *lua); +tb_int_t xm_thread_sharedata_clear(lua_State *lua); +tb_int_t xm_thread_sharedata_incref(lua_State *lua); +tb_int_t xm_thread_sharedata_set(lua_State *lua); +tb_int_t xm_thread_sharedata_get_(lua_State *lua); // open cjson -__tb_extern_c_enter__ -tb_int_t luaopen_cjson(lua_State *l); +__tb_extern_c_enter__ tb_int_t luaopen_cjson(lua_State *l); __tb_extern_c_leave__ /* ////////////////////////////////////////////////////////////////////////////////////// @@ -393,340 +391,320 @@ __tb_extern_c_leave__ */ // the os functions -static luaL_Reg const g_os_functions[] = -{ - { "argv", xm_os_argv } -, { "args", xm_os_args } -, { "find", xm_os_find } -, { "link", xm_os_link } -, { "isdir", xm_os_isdir } -, { "rmdir", xm_os_rmdir } -, { "mkdir", xm_os_mkdir } -, { "cpdir", xm_os_cpdir } -, { "chdir", xm_os_chdir } -, { "mtime", xm_os_mtime } -, { "sleep", xm_os_sleep } -, { "mclock", xm_os_mclock } -, { "curdir", xm_os_curdir } -, { "tmpdir", xm_os_tmpdir } -, { "islink", xm_os_islink } -, { "isfile", xm_os_isfile } -, { "touch", xm_os_touch } -, { "rmfile", xm_os_rmfile } -, { "cpfile", xm_os_cpfile } -, { "fscase", xm_os_fscase } -, { "rename", xm_os_rename } -, { "exists", xm_os_exists } -, { "setenv", xm_os_setenv } -, { "getenv", xm_os_getenv } -, { "getenvs", xm_os_getenvs } -, { "cpuinfo", xm_os_cpuinfo } -, { "meminfo", xm_os_meminfo } -, { "readlink", xm_os_readlink } -, { "emptydir", xm_os_emptydir } -, { "strerror", xm_os_strerror } -, { "syserror", xm_os_syserror } -, { "filesize", xm_os_filesize } -, { "getwinsize", xm_os_getwinsize} -, { "getpid", xm_os_getpid } -, { "signal", xm_os_signal } +static luaL_Reg const g_os_functions[] = { + { "argv", xm_os_argv }, + { "args", xm_os_args }, + { "find", xm_os_find }, + { "link", xm_os_link }, + { "isdir", xm_os_isdir }, + { "rmdir", xm_os_rmdir }, + { "mkdir", xm_os_mkdir }, + { "cpdir", xm_os_cpdir }, + { "chdir", xm_os_chdir }, + { "mtime", xm_os_mtime }, + { "sleep", xm_os_sleep }, + { "mclock", xm_os_mclock }, + { "curdir", xm_os_curdir }, + { "tmpdir", xm_os_tmpdir }, + { "islink", xm_os_islink }, + { "isfile", xm_os_isfile }, + { "touch", xm_os_touch }, + { "rmfile", xm_os_rmfile }, + { "cpfile", xm_os_cpfile }, + { "fscase", xm_os_fscase }, + { "rename", xm_os_rename }, + { "exists", xm_os_exists }, + { "setenv", xm_os_setenv }, + { "getenv", xm_os_getenv }, + { "getenvs", xm_os_getenvs }, + { "cpuinfo", xm_os_cpuinfo }, + { "meminfo", xm_os_meminfo }, + { "readlink", xm_os_readlink }, + { "emptydir", xm_os_emptydir }, + { "strerror", xm_os_strerror }, + { "syserror", xm_os_syserror }, + { "filesize", xm_os_filesize }, + { "getwinsize", xm_os_getwinsize }, + { "getpid", xm_os_getpid }, + { "signal", xm_os_signal }, #ifndef TB_CONFIG_OS_WINDOWS -, { "uid", xm_os_uid } -, { "gid", xm_os_gid } -, { "getown", xm_os_getown } + { "uid", xm_os_uid }, + { "gid", xm_os_gid }, + { "getown", xm_os_getown }, #endif -, { tb_null, tb_null } + { tb_null, tb_null }, }; // the windows functions #ifdef TB_CONFIG_OS_WINDOWS -static luaL_Reg const g_winos_functions[] = -{ - { "cp_info", xm_winos_cp_info } -, { "console_cp", xm_winos_console_cp } -, { "console_output_cp", xm_winos_console_output_cp } -, { "oem_cp", xm_winos_oem_cp } -, { "ansi_cp", xm_winos_ansi_cp } -, { "logical_drives", xm_winos_logical_drives } -, { "registry_query", xm_winos_registry_query } -, { "registry_keys", xm_winos_registry_keys } -, { "registry_values", xm_winos_registry_values } -, { "short_path", xm_winos_short_path } -, { tb_null, tb_null } +static luaL_Reg const g_winos_functions[] = { + { "cp_info", xm_winos_cp_info }, + { "console_cp", xm_winos_console_cp }, + { "console_output_cp", xm_winos_console_output_cp }, + { "oem_cp", xm_winos_oem_cp }, + { "ansi_cp", xm_winos_ansi_cp }, + { "logical_drives", xm_winos_logical_drives }, + { "registry_query", xm_winos_registry_query }, + { "registry_keys", xm_winos_registry_keys }, + { "registry_values", xm_winos_registry_values }, + { "short_path", xm_winos_short_path }, + { tb_null, tb_null }, }; #endif // the io functions -static luaL_Reg const g_io_functions[] = -{ - { "stdfile", xm_io_stdfile } -, { "file_open", xm_io_file_open } -, { "file_read", xm_io_file_read } -, { "file_readable", xm_io_file_readable } -, { "file_seek", xm_io_file_seek } -, { "file_size", xm_io_file_size } -, { "file_write", xm_io_file_write } -, { "file_flush", xm_io_file_flush } -, { "file_isatty", xm_io_file_isatty } -, { "file_close", xm_io_file_close } -, { "file_rawfd", xm_io_file_rawfd } -, { "filelock_open", xm_io_filelock_open } -, { "filelock_lock", xm_io_filelock_lock } -, { "filelock_trylock", xm_io_filelock_trylock } -, { "filelock_unlock", xm_io_filelock_unlock } -, { "filelock_close", xm_io_filelock_close } -, { "socket_open", xm_io_socket_open } -, { "socket_rawfd", xm_io_socket_rawfd } -, { "socket_peeraddr", xm_io_socket_peeraddr } -, { "socket_wait", xm_io_socket_wait } -, { "socket_bind", xm_io_socket_bind } -, { "socket_ctrl", xm_io_socket_ctrl } -, { "socket_listen", xm_io_socket_listen } -, { "socket_accept", xm_io_socket_accept } -, { "socket_connect", xm_io_socket_connect } -, { "socket_send", xm_io_socket_send } -, { "socket_sendto", xm_io_socket_sendto } -, { "socket_sendfile", xm_io_socket_sendfile } -, { "socket_recv", xm_io_socket_recv } -, { "socket_recvfrom", xm_io_socket_recvfrom } -, { "socket_kill" , xm_io_socket_kill } -, { "socket_close", xm_io_socket_close } -, { "pipe_open", xm_io_pipe_open } -, { "pipe_openpair", xm_io_pipe_openpair } -, { "pipe_close", xm_io_pipe_close } -, { "pipe_read", xm_io_pipe_read } -, { "pipe_write", xm_io_pipe_write } -, { "pipe_wait", xm_io_pipe_wait } -, { "pipe_connect", xm_io_pipe_connect } -, { "poller_insert", xm_io_poller_insert } -, { "poller_modify", xm_io_poller_modify } -, { "poller_remove", xm_io_poller_remove } -, { "poller_spank", xm_io_poller_spank } -, { "poller_support", xm_io_poller_support } -, { "poller_wait", xm_io_poller_wait } -, { tb_null, tb_null } +static luaL_Reg const g_io_functions[] = { + { "stdfile", xm_io_stdfile }, + { "file_open", xm_io_file_open }, + { "file_read", xm_io_file_read }, + { "file_readable", xm_io_file_readable }, + { "file_seek", xm_io_file_seek }, + { "file_size", xm_io_file_size }, + { "file_write", xm_io_file_write }, + { "file_flush", xm_io_file_flush }, + { "file_isatty", xm_io_file_isatty }, + { "file_close", xm_io_file_close }, + { "file_rawfd", xm_io_file_rawfd }, + { "filelock_open", xm_io_filelock_open }, + { "filelock_lock", xm_io_filelock_lock }, + { "filelock_trylock", xm_io_filelock_trylock }, + { "filelock_unlock", xm_io_filelock_unlock }, + { "filelock_close", xm_io_filelock_close }, + { "socket_open", xm_io_socket_open }, + { "socket_rawfd", xm_io_socket_rawfd }, + { "socket_peeraddr", xm_io_socket_peeraddr }, + { "socket_wait", xm_io_socket_wait }, + { "socket_bind", xm_io_socket_bind }, + { "socket_ctrl", xm_io_socket_ctrl }, + { "socket_listen", xm_io_socket_listen }, + { "socket_accept", xm_io_socket_accept }, + { "socket_connect", xm_io_socket_connect }, + { "socket_send", xm_io_socket_send }, + { "socket_sendto", xm_io_socket_sendto }, + { "socket_sendfile", xm_io_socket_sendfile }, + { "socket_recv", xm_io_socket_recv }, + { "socket_recvfrom", xm_io_socket_recvfrom }, + { "socket_kill", xm_io_socket_kill }, + { "socket_close", xm_io_socket_close }, + { "pipe_open", xm_io_pipe_open }, + { "pipe_openpair", xm_io_pipe_openpair }, + { "pipe_close", xm_io_pipe_close }, + { "pipe_read", xm_io_pipe_read }, + { "pipe_write", xm_io_pipe_write }, + { "pipe_wait", xm_io_pipe_wait }, + { "pipe_connect", xm_io_pipe_connect }, + { "poller_insert", xm_io_poller_insert }, + { "poller_modify", xm_io_poller_modify }, + { "poller_remove", xm_io_poller_remove }, + { "poller_spank", xm_io_poller_spank }, + { "poller_support", xm_io_poller_support }, + { "poller_wait", xm_io_poller_wait }, + { tb_null, tb_null }, }; // the path functions -static luaL_Reg const g_path_functions[] = -{ - { "relative", xm_path_relative } -, { "absolute", xm_path_absolute } -, { "translate", xm_path_translate } -, { "directory", xm_path_directory } -, { "is_absolute", xm_path_is_absolute } -, { tb_null, tb_null } +static luaL_Reg const g_path_functions[] = { + { "relative", xm_path_relative }, + { "absolute", xm_path_absolute }, + { "translate", xm_path_translate }, + { "directory", xm_path_directory }, + { "is_absolute", xm_path_is_absolute }, + { tb_null, tb_null }, }; // the hash functions -static luaL_Reg const g_hash_functions[] = -{ - { "uuid4", xm_hash_uuid4 } -, { "sha", xm_hash_sha } -, { "md5", xm_hash_md5 } -, { "xxhash", xm_hash_xxhash } -, { "rand32", xm_hash_rand32 } -, { "rand64", xm_hash_rand64 } -, { "rand128", xm_hash_rand128 } -, { tb_null, tb_null } +static luaL_Reg const g_hash_functions[] = { + { "uuid4", xm_hash_uuid4 }, + { "sha", xm_hash_sha }, + { "md5", xm_hash_md5 }, + { "xxhash", xm_hash_xxhash }, + { "rand32", xm_hash_rand32 }, + { "rand64", xm_hash_rand64 }, + { "rand128", xm_hash_rand128 }, + { tb_null, tb_null }, }; // the base64 functions -static luaL_Reg const g_base64_functions[] = -{ - { "encode", xm_base64_encode } -, { "decode", xm_base64_decode } -, { tb_null, tb_null } +static luaL_Reg const g_base64_functions[] = { + { "encode", xm_base64_encode }, + { "decode", xm_base64_decode }, + { tb_null, tb_null }, }; // the lz4 functions -static luaL_Reg const g_lz4_functions[] = -{ - { "compress", xm_lz4_compress } -, { "decompress", xm_lz4_decompress } -, { "block_compress", xm_lz4_block_compress } -, { "block_decompress", xm_lz4_block_decompress } -, { "compress_file", xm_lz4_compress_file } -, { "decompress_file", xm_lz4_decompress_file } -, { "compress_stream_open", xm_lz4_compress_stream_open } -, { "compress_stream_read", xm_lz4_compress_stream_read } -, { "compress_stream_write", xm_lz4_compress_stream_write } -, { "compress_stream_close", xm_lz4_compress_stream_close } -, { "decompress_stream_open", xm_lz4_decompress_stream_open } -, { "decompress_stream_read", xm_lz4_decompress_stream_read } -, { "decompress_stream_write",xm_lz4_decompress_stream_write } -, { "decompress_stream_close",xm_lz4_decompress_stream_close } -, { tb_null, tb_null } +static luaL_Reg const g_lz4_functions[] = { + { "compress", xm_lz4_compress }, + { "decompress", xm_lz4_decompress }, + { "block_compress", xm_lz4_block_compress }, + { "block_decompress", xm_lz4_block_decompress }, + { "compress_file", xm_lz4_compress_file }, + { "decompress_file", xm_lz4_decompress_file }, + { "compress_stream_open", xm_lz4_compress_stream_open }, + { "compress_stream_read", xm_lz4_compress_stream_read }, + { "compress_stream_write", xm_lz4_compress_stream_write }, + { "compress_stream_close", xm_lz4_compress_stream_close }, + { "decompress_stream_open", xm_lz4_decompress_stream_open }, + { "decompress_stream_read", xm_lz4_decompress_stream_read }, + { "decompress_stream_write", xm_lz4_decompress_stream_write }, + { "decompress_stream_close", xm_lz4_decompress_stream_close }, + { tb_null, tb_null }, }; // the bloom filter functions -static luaL_Reg const g_bloom_filter_functions[] = -{ - { "open", xm_bloom_filter_open } -, { "close", xm_bloom_filter_close } -, { "clear", xm_bloom_filter_clear } -, { "data", xm_bloom_filter_data } -, { "size", xm_bloom_filter_size } -, { "get", xm_bloom_filter_get } -, { "set", xm_bloom_filter_set } -, { "data_set", xm_bloom_filter_data_set } -, { tb_null, tb_null } +static luaL_Reg const g_bloom_filter_functions[] = { + { "open", xm_bloom_filter_open }, + { "close", xm_bloom_filter_close }, + { "clear", xm_bloom_filter_clear }, + { "data", xm_bloom_filter_data }, + { "size", xm_bloom_filter_size }, + { "get", xm_bloom_filter_get }, + { "set", xm_bloom_filter_set }, + { "data_set", xm_bloom_filter_data_set }, + { tb_null, tb_null }, }; // the string functions -static luaL_Reg const g_string_functions[] = -{ - { "trim", xm_string_trim } -, { "split", xm_string_split } -, { "lastof", xm_string_lastof } -, { "convert", xm_string_convert } -, { "endswith", xm_string_endswith } -, { "startswith", xm_string_startswith } -, { tb_null, tb_null } +static luaL_Reg const g_string_functions[] = { + { "trim", xm_string_trim }, + { "split", xm_string_split }, + { "lastof", xm_string_lastof }, + { "convert", xm_string_convert }, + { "endswith", xm_string_endswith }, + { "startswith", xm_string_startswith }, + { tb_null, tb_null }, }; // the process functions -static luaL_Reg const g_process_functions[] = -{ - { "open", xm_process_open } -, { "openv", xm_process_openv } -, { "wait", xm_process_wait } -, { "kill", xm_process_kill } -, { "close", xm_process_close } -, { tb_null, tb_null } +static luaL_Reg const g_process_functions[] = { + { "open", xm_process_open }, + { "openv", xm_process_openv }, + { "wait", xm_process_wait }, + { "kill", xm_process_kill }, + { "close", xm_process_close }, + { tb_null, tb_null }, }; // the fwatcher functions -static luaL_Reg const g_fwatcher_functions[] = -{ - { "open", xm_fwatcher_open } -, { "add", xm_fwatcher_add } -, { "remove", xm_fwatcher_remove } -, { "wait", xm_fwatcher_wait } -, { "close", xm_fwatcher_close } -, { tb_null, tb_null } +static luaL_Reg const g_fwatcher_functions[] = { + { "open", xm_fwatcher_open }, + { "add", xm_fwatcher_add }, + { "remove", xm_fwatcher_remove }, + { "wait", xm_fwatcher_wait }, + { "close", xm_fwatcher_close }, + { tb_null, tb_null }, }; // the sandbox functions -static luaL_Reg const g_sandbox_functions[] = -{ - { "interactive", xm_sandbox_interactive } -, { tb_null, tb_null } +static luaL_Reg const g_sandbox_functions[] = { + { "interactive", xm_sandbox_interactive }, + { tb_null, tb_null }, }; #ifdef XM_CONFIG_API_HAVE_READLINE // the readline functions -static luaL_Reg const g_readline_functions[] = -{ - { "readline", xm_readline_readline } -, { "history_list", xm_readline_history_list } -, { "add_history", xm_readline_add_history } -, { "clear_history", xm_readline_clear_history} -, { tb_null, tb_null } +static luaL_Reg const g_readline_functions[] = { + { "readline", xm_readline_readline }, + { "history_list", xm_readline_history_list }, + { "add_history", xm_readline_add_history }, + { "clear_history", xm_readline_clear_history }, + { tb_null, tb_null }, }; #endif // the semver functions -static luaL_Reg const g_semver_functions[] = -{ - { "parse", xm_semver_parse } -, { "compare", xm_semver_compare } -, { "satisfies", xm_semver_satisfies } -, { "select", xm_semver_select } -, { tb_null, tb_null } +static luaL_Reg const g_semver_functions[] = { + { "parse", xm_semver_parse }, + { "compare", xm_semver_compare }, + { "satisfies", xm_semver_satisfies }, + { "select", xm_semver_select }, + { tb_null, tb_null }, }; // the libc functions -static luaL_Reg const g_libc_functions[] = -{ - { "malloc", xm_libc_malloc } -, { "free", xm_libc_free } -, { "memcpy", xm_libc_memcpy } -, { "memset", xm_libc_memset } -, { "memmov", xm_libc_memmov } -, { "strndup", xm_libc_strndup } -, { "dataptr", xm_libc_dataptr } -, { "byteof", xm_libc_byteof } -, { "setbyte", xm_libc_setbyte } -, { tb_null, tb_null } +static luaL_Reg const g_libc_functions[] = { + { "malloc", xm_libc_malloc }, + { "free", xm_libc_free }, + { "memcpy", xm_libc_memcpy }, + { "memset", xm_libc_memset }, + { "memmov", xm_libc_memmov }, + { "strndup", xm_libc_strndup }, + { "dataptr", xm_libc_dataptr }, + { "byteof", xm_libc_byteof }, + { "setbyte", xm_libc_setbyte }, + { tb_null, tb_null }, }; // the tty functions -static luaL_Reg const g_tty_functions[] = -{ - { "term_mode", xm_tty_term_mode } -, { tb_null, tb_null } +static luaL_Reg const g_tty_functions[] = { + { "term_mode", xm_tty_term_mode }, + { tb_null, tb_null }, }; // the package functions -static luaL_Reg const g_package_functions[] = -{ - { "loadxmi", xm_package_loadxmi } -, { tb_null, tb_null } +static luaL_Reg const g_package_functions[] = { + { "loadxmi", xm_package_loadxmi }, + { tb_null, tb_null }, }; // the utils functions -static luaL_Reg const g_utils_functions[] = -{ - { "bin2c", xm_utils_bin2c } -, { tb_null, tb_null } +static luaL_Reg const g_utils_functions[] = { + { "bin2c", xm_utils_bin2c }, + { tb_null, tb_null }, }; // the thread functions -static luaL_Reg const g_thread_functions[] = -{ - { "thread_init", xm_thread_init } -, { "thread_exit", xm_thread_exit } -, { "thread_wait", xm_thread_wait } -, { "thread_resume", xm_thread_resume } -, { "thread_suspend", xm_thread_suspend } -, { "mutex_init", xm_thread_mutex_init } -, { "mutex_exit", xm_thread_mutex_exit } -, { "mutex_lock", xm_thread_mutex_lock } -, { "mutex_trylock", xm_thread_mutex_trylock } -, { "mutex_unlock", xm_thread_mutex_unlock } -, { "mutex_incref", xm_thread_mutex_incref } -, { "event_init", xm_thread_event_init } -, { "event_exit", xm_thread_event_exit } -, { "event_post", xm_thread_event_post } -, { "event_wait", xm_thread_event_wait } -, { "event_incref", xm_thread_event_incref } -, { "semaphore_init", xm_thread_semaphore_init } -, { "semaphore_exit", xm_thread_semaphore_exit } -, { "semaphore_post", xm_thread_semaphore_post } -, { "semaphore_wait", xm_thread_semaphore_wait } -, { "semaphore_incref", xm_thread_semaphore_incref } -, { "queue_init", xm_thread_queue_init } -, { "queue_exit", xm_thread_queue_exit } -, { "queue_size", xm_thread_queue_size } -, { "queue_clear", xm_thread_queue_clear } -, { "queue_incref", xm_thread_queue_incref } -, { "queue_push", xm_thread_queue_push } -, { "queue_pop", xm_thread_queue_pop } -, { "sharedata_init", xm_thread_sharedata_init } -, { "sharedata_exit", xm_thread_sharedata_exit } -, { "sharedata_clear", xm_thread_sharedata_clear } -, { "sharedata_incref", xm_thread_sharedata_incref } -, { "sharedata_set", xm_thread_sharedata_set } -, { "sharedata_get", xm_thread_sharedata_get_ } -, { tb_null, tb_null } +static luaL_Reg const g_thread_functions[] = { + { "thread_init", xm_thread_init }, + { "thread_exit", xm_thread_exit }, + { "thread_wait", xm_thread_wait }, + { "thread_resume", xm_thread_resume }, + { "thread_suspend", xm_thread_suspend }, + { "mutex_init", xm_thread_mutex_init }, + { "mutex_exit", xm_thread_mutex_exit }, + { "mutex_lock", xm_thread_mutex_lock }, + { "mutex_trylock", xm_thread_mutex_trylock }, + { "mutex_unlock", xm_thread_mutex_unlock }, + { "mutex_incref", xm_thread_mutex_incref }, + { "event_init", xm_thread_event_init }, + { "event_exit", xm_thread_event_exit }, + { "event_post", xm_thread_event_post }, + { "event_wait", xm_thread_event_wait }, + { "event_incref", xm_thread_event_incref }, + { "semaphore_init", xm_thread_semaphore_init }, + { "semaphore_exit", xm_thread_semaphore_exit }, + { "semaphore_post", xm_thread_semaphore_post }, + { "semaphore_wait", xm_thread_semaphore_wait }, + { "semaphore_incref", xm_thread_semaphore_incref }, + { "queue_init", xm_thread_queue_init }, + { "queue_exit", xm_thread_queue_exit }, + { "queue_size", xm_thread_queue_size }, + { "queue_clear", xm_thread_queue_clear }, + { "queue_incref", xm_thread_queue_incref }, + { "queue_push", xm_thread_queue_push }, + { "queue_pop", xm_thread_queue_pop }, + { "sharedata_init", xm_thread_sharedata_init }, + { "sharedata_exit", xm_thread_sharedata_exit }, + { "sharedata_clear", xm_thread_sharedata_clear }, + { "sharedata_incref", xm_thread_sharedata_incref }, + { "sharedata_set", xm_thread_sharedata_set }, + { "sharedata_get", xm_thread_sharedata_get_ }, + { tb_null, tb_null }, }; // the lua global instance for signal handler -static lua_State* g_lua = tb_null; +static lua_State *g_lua = tb_null; // the xmake script files data #ifdef XM_EMBED_ENABLE static tb_byte_t g_xmake_xmz_data[] = { - #include "xmake.xmz.h" +#include "xmake.xmz.h" }; #endif /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_bool_t xm_engine_save_arguments(xm_engine_t* engine, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv) -{ +static tb_bool_t xm_engine_save_arguments(xm_engine_t *engine, tb_int_t argc, tb_char_t **argv, tb_char_t **taskargv) { // check tb_assert_and_check_return_val(engine && engine->lua && argc >= 1 && argv, tb_false); @@ -738,11 +716,9 @@ static tb_bool_t xm_engine_save_arguments(xm_engine_t* engine, tb_int_t argc, tb lua_newtable(engine->lua); // patch the task arguments list - if (taskargv) - { - tb_char_t** taskarg = taskargv; - while (*taskarg) - { + if (taskargv) { + tb_char_t **taskarg = taskargv; + while (*taskarg) { lua_pushstring(engine->lua, *taskarg); lua_rawseti(engine->lua, -2, (int)lua_objlen(engine->lua, -2) + 1); taskarg++; @@ -751,10 +727,9 @@ static tb_bool_t xm_engine_save_arguments(xm_engine_t* engine, tb_int_t argc, tb // save all arguments to the new table tb_int_t i = 0; - for (i = 1; i < argc; i++) - { + for (i = 1; i < argc; i++) { #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) - tb_char_t argvbuf[4096] = {0}; + tb_char_t argvbuf[4096] = { 0 }; tb_wcstombs(argvbuf, argvw[i], tb_arrayn(argvbuf)); // table_new[table.getn(table_new) + 1] = argv[i] lua_pushstring(engine->lua, argvbuf); @@ -769,8 +744,7 @@ static tb_bool_t xm_engine_save_arguments(xm_engine_t* engine, tb_int_t argc, tb return tb_true; } -static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** argv, tb_char_t* path, tb_size_t maxn) -{ +static tb_bool_t xm_engine_get_program_file(xm_engine_t *engine, tb_char_t **argv, tb_char_t *path, tb_size_t maxn) { // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); @@ -779,9 +753,8 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg * The executable file compiled using cosmocc on macOS might retrieve a relative path to the programfile. * If the root directory has been changed, the retrieved programfile will be a non-existent path. */ - static tb_char_t s_program_filepath[TB_PATH_MAXN] = {0}; - if (s_program_filepath[0]) - { + static tb_char_t s_program_filepath[TB_PATH_MAXN] = { 0 }; + if (s_program_filepath[0]) { tb_strlcpy(path, s_program_filepath, maxn); lua_pushstring(engine->lua, s_program_filepath); lua_setglobal(engine->lua, "_PROGRAM_FILE"); @@ -789,23 +762,21 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg } tb_bool_t ok = tb_false; - do - { + do { // get it from the environment variable first - if (tb_environment_first("XMAKE_PROGRAM_FILE", path, maxn) && tb_file_info(path, tb_null)) - { + if (tb_environment_first("XMAKE_PROGRAM_FILE", path, maxn) && tb_file_info(path, tb_null)) { ok = tb_true; break; } #if defined(TB_CONFIG_OS_WINDOWS) // get the executale file path as program directory - tb_wchar_t buf[TB_PATH_MAXN] = {0}; + tb_wchar_t buf[TB_PATH_MAXN] = { 0 }; tb_size_t size = (tb_size_t)GetModuleFileNameW(tb_null, buf, (DWORD)TB_PATH_MAXN); tb_assert_and_check_break(size < TB_PATH_MAXN); // end - buf[size] = L'\0'; - size = tb_wcstombs(path, buf, maxn); + buf[size] = L'\0'; + size = tb_wcstombs(path, buf, maxn); tb_assert_and_check_break(size < maxn); path[size] = '\0'; @@ -832,44 +803,41 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg * @see it may be a relative path */ ssize_t size = readlink(XM_PROC_SELF_FILE, path, (size_t)maxn); - if (size > 0 && size < maxn) - { + if (size > 0 && size < maxn) { path[size] = '\0'; - ok = tb_true; + ok = tb_true; } #elif defined(TB_CONFIG_OS_BSD) && defined(KERN_PROC_PATHNAME) // only for FreeBSD and OpenBSD, https://github.com/xmake-io/xmake/issues/2948 - tb_int_t mib[4]; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; + tb_int_t mib[4]; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; size_t size = maxn; - if (sysctl(mib, 4, path, &size, tb_null, 0) == 0 && size < maxn) - { + if (sysctl(mib, 4, path, &size, tb_null, 0) == 0 && size < maxn) { path[size] = '\0'; - ok = tb_true; + ok = tb_true; } #elif defined(TB_CONFIG_OS_HAIKU) - int32 cookie = 0; + int32 cookie = 0; image_info info; - while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) - { - if (info.type == B_APP_IMAGE) - { + while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { + if (info.type == B_APP_IMAGE) { tb_strlcpy(path, info.name, maxn); ok = tb_true; break; } } #else - static tb_char_t const* s_paths[] = - { + static tb_char_t const *s_paths[] = { "~/.local/bin/xmake", "/usr/local/bin/xmake", - "/usr/bin/xmake" + "/usr/bin/xmake", }; - for (tb_size_t i = 0; i < tb_arrayn(s_paths); i++) - { - tb_char_t const* p = s_paths[i]; - if (tb_file_info(p, tb_null)) - { + for (tb_size_t i = 0; i < tb_arrayn(s_paths); i++) { + tb_char_t const *p = s_paths[i]; + if (tb_file_info(p, tb_null)) { tb_strlcpy(path, p, maxn); ok = tb_true; break; @@ -877,11 +845,9 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg } #endif - if (!ok && argv) - { - tb_char_t const* p = argv[0]; - if (p && tb_file_info(p, tb_null)) - { + if (!ok && argv) { + tb_char_t const *p = argv[0]; + if (p && tb_file_info(p, tb_null)) { tb_strlcpy(path, p, maxn); ok = tb_true; } @@ -890,8 +856,7 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg } while (0); // ok? - if (ok) - { + if (ok) { // trace tb_trace_d("programfile: %s", path); @@ -906,11 +871,12 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg } #ifdef XM_EMBED_ENABLE -static tb_bool_t xm_engine_get_temporary_directory(tb_char_t* path, tb_size_t maxn, tb_char_t const* name, tb_char_t const* version_cstr) -{ - tb_char_t data[TB_PATH_MAXN] = {0}; - if (tb_directory_temporary(data, sizeof(data))) - { +static tb_bool_t xm_engine_get_temporary_directory(tb_char_t *path, + tb_size_t maxn, + tb_char_t const *name, + tb_char_t const *version_cstr) { + tb_char_t data[TB_PATH_MAXN] = { 0 }; + if (tb_directory_temporary(data, sizeof(data))) { // get euid tb_int_t euid = 0; #ifndef TB_CONFIG_OS_WINDOWS @@ -924,73 +890,69 @@ static tb_bool_t xm_engine_get_temporary_directory(tb_char_t* path, tb_size_t ma } #endif -static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t* path, tb_size_t maxn, tb_char_t const* programfile) -{ +static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, + tb_char_t *path, + tb_size_t maxn, + tb_char_t const *programfile) { // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); - static tb_char_t s_program_directory[TB_PATH_MAXN] = {0}; - if (s_program_directory[0]) - { + static tb_char_t s_program_directory[TB_PATH_MAXN] = { 0 }; + if (s_program_directory[0]) { tb_strlcpy(path, s_program_directory, maxn); lua_pushstring(engine->lua, s_program_directory); lua_setglobal(engine->lua, "_PROGRAM_DIR"); return tb_true; } - tb_bool_t ok = tb_false; - tb_char_t data[TB_PATH_MAXN] = {0}; - do - { + tb_bool_t ok = tb_false; + tb_char_t data[TB_PATH_MAXN] = { 0 }; + do { #ifdef XM_EMBED_ENABLE tb_size_t embedcount = engine->embedcount; - if (embedcount) - { + if (embedcount) { tb_uint32_t crc32 = 0; for (tb_size_t i = 0; i < embedcount; i++) crc32 += tb_crc32_make(engine->embeddata[i], engine->embedsize[i], 0); tb_snprintf(path, maxn, "%s/%x", engine->tmpdir, crc32); - } - else tb_strlcpy(path, engine->tmpdir, maxn); + } else + tb_strlcpy(path, engine->tmpdir, maxn); ok = tb_true; break; #endif // get it from the environment variable first - if (tb_environment_first("XMAKE_PROGRAM_DIR", data, sizeof(data)) && tb_path_absolute(data, path, maxn)) - { + if (tb_environment_first("XMAKE_PROGRAM_DIR", data, sizeof(data)) && tb_path_absolute(data, path, maxn)) { ok = tb_true; break; } // get it from program file path - if (programfile) - { + if (programfile) { // get real program file path from the symbol link #if !defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_CONFIG_OS_IOS) tb_char_t programpath[TB_PATH_MAXN]; tb_long_t size = readlink(programfile, programpath, sizeof(programpath)); - if (size >= 0 && size < sizeof(programpath)) - { + if (size >= 0 && size < sizeof(programpath)) { programpath[size] = '\0'; // soft link to relative path? fix it - if (!tb_path_is_absolute(programpath)) - { - tb_char_t buff[TB_PATH_MAXN]; - tb_char_t const* rootdir = tb_path_directory(programfile, buff, sizeof(buff)); - if (rootdir && tb_path_absolute_to(rootdir, programpath, path, maxn)) // @note path and programfile are same buffer + if (!tb_path_is_absolute(programpath)) { + tb_char_t buff[TB_PATH_MAXN]; + tb_char_t const *rootdir = tb_path_directory(programfile, buff, sizeof(buff)); + if (rootdir && tb_path_absolute_to( + rootdir, programpath, path, maxn)) // @note path and programfile are same buffer tb_strlcpy(programpath, path, maxn); } - } - else tb_strlcpy(programpath, programfile, sizeof(programpath)); + } else + tb_strlcpy(programpath, programfile, sizeof(programpath)); #else - tb_char_t const* programpath = programfile; + tb_char_t const *programpath = programfile; #endif // get the root directory - tb_char_t data[TB_PATH_MAXN]; - tb_char_t const* rootdir = tb_path_directory(programpath, data, sizeof(data)); + tb_char_t data[TB_PATH_MAXN]; + tb_char_t const *rootdir = tb_path_directory(programpath, data, sizeof(data)); tb_assert_and_check_break(rootdir); // init share/name sub-directory @@ -998,17 +960,18 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t* tb_snprintf(sharedir, sizeof(sharedir), "../share/%s", engine->name); // find the program (lua) directory - tb_size_t i; - tb_file_info_t info; - tb_char_t scriptpath[TB_PATH_MAXN]; - tb_char_t const* subdirs[] = {".", sharedir}; - for (i = 0; i < tb_arrayn(subdirs); i++) - { + tb_size_t i; + tb_file_info_t info; + tb_char_t scriptpath[TB_PATH_MAXN]; + tb_char_t const *subdirs[] = { + ".", + sharedir, + }; + for (i = 0; i < tb_arrayn(subdirs); i++) { // get program directory if (tb_path_absolute_to(rootdir, subdirs[i], path, maxn) && tb_path_absolute_to(path, "core/_xmake_main.lua", scriptpath, sizeof(scriptpath)) && - tb_file_info(scriptpath, &info) && info.type == TB_FILE_TYPE_FILE) - { + tb_file_info(scriptpath, &info) && info.type == TB_FILE_TYPE_FILE) { ok = tb_true; break; } @@ -1018,8 +981,7 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t* } while (0); // ok? - if (ok) - { + if (ok) { // trace tb_trace_d("programdir: %s", path); @@ -1035,21 +997,18 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t* return ok; } -static tb_bool_t xm_engine_get_project_directory(xm_engine_t* engine, tb_char_t* path, tb_size_t maxn) -{ +static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t *path, tb_size_t maxn) { // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); tb_bool_t ok = tb_false; - do - { + do { // attempt to get it from the environment variable first - tb_char_t data[TB_PATH_MAXN] = {0}; - if ( !tb_environment_first("XMAKE_PROJECT_DIR", data, sizeof(data)) - || !tb_path_absolute(data, path, maxn)) - { + tb_char_t data[TB_PATH_MAXN] = { 0 }; + if (!tb_environment_first("XMAKE_PROJECT_DIR", data, sizeof(data)) || !tb_path_absolute(data, path, maxn)) { // get it from the current directory - if (!tb_directory_current(path, maxn)) break; + if (!tb_directory_current(path, maxn)) + break; } // trace @@ -1065,15 +1024,15 @@ static tb_bool_t xm_engine_get_project_directory(xm_engine_t* engine, tb_char_t* } while (0); // failed? - if (!ok) tb_printf("error: not found the project directory!\n"); + if (!ok) + tb_printf("error: not found the project directory!\n"); // ok? return ok; } #if defined(TB_CONFIG_OS_WINDOWS) || defined(SIGINT) -static tb_void_t xm_engine_dump_traceback(lua_State* lua) -{ +static tb_void_t xm_engine_dump_traceback(lua_State *lua) { // @note it's not safe, but it doesn't matter, we're just trying to get the stack backtrace for debugging lua_getglobal(lua, "debug"); lua_getfield(lua, -1, "traceback"); @@ -1085,37 +1044,31 @@ static tb_void_t xm_engine_dump_traceback(lua_State* lua) #endif #if defined(TB_CONFIG_OS_WINDOWS) -static BOOL WINAPI xm_engine_signal_handler(DWORD signo) -{ - if (signo == CTRL_C_EVENT && g_lua) - { +static BOOL WINAPI xm_engine_signal_handler(DWORD signo) { + if (signo == CTRL_C_EVENT && g_lua) { xm_engine_dump_traceback(g_lua); tb_abort(); } return TRUE; } #elif defined(SIGINT) -static tb_void_t xm_engine_signal_handler(tb_int_t signo) -{ - if (signo == SIGINT && g_lua) - { +static tb_void_t xm_engine_signal_handler(tb_int_t signo) { + if (signo == SIGINT && g_lua) { xm_engine_dump_traceback(g_lua); tb_abort(); } } #endif -static tb_void_t xm_engine_init_host(xm_engine_t* engine) -{ +static tb_void_t xm_engine_init_host(xm_engine_t *engine) { // check tb_assert_and_check_return(engine && engine->lua); // init system host - tb_char_t const* syshost = tb_null; + tb_char_t const *syshost = tb_null; #if defined(__COSMOPOLITAN__) struct utsname buffer; - if (uname(&buffer) == 0) - { + if (uname(&buffer) == 0) { if (tb_strstr(buffer.sysname, "Darwin")) syshost = "macosx"; else if (tb_strstr(buffer.sysname, "Linux")) @@ -1138,48 +1091,48 @@ static tb_void_t xm_engine_init_host(xm_engine_t* engine) #elif defined(TB_CONFIG_OS_HAIKU) syshost = "haiku"; #endif - lua_pushstring(engine->lua, syshost? syshost : "unknown"); + lua_pushstring(engine->lua, syshost ? syshost : "unknown"); lua_setglobal(engine->lua, "_HOST"); // init subsystem host - tb_char_t const* subhost = syshost; + tb_char_t const *subhost = syshost; #if defined(TB_CONFIG_OS_WINDOWS) -# if defined(TB_COMPILER_ON_MSYS) +#if defined(TB_COMPILER_ON_MSYS) subhost = "msys"; -# elif defined(TB_COMPILER_ON_CYGWIN) +#elif defined(TB_COMPILER_ON_CYGWIN) subhost = "cygwin"; -# else +#else { - tb_char_t data[64] = {0}; - if (tb_environment_first("MSYSTEM", data, sizeof(data))) - { + tb_char_t data[64] = { 0 }; + if (tb_environment_first("MSYSTEM", data, sizeof(data))) { // on msys? if (!tb_strnicmp(data, "mingw", 5) // mingw32/64 on msys2 - || !tb_strnicmp(data, "clang", 5) // clang32/64 on msys2, @see https://github.com/xmake-io/xmake/issues/3060 - || !tb_stricmp(data, "ucrt64") // ucrt64 https://www.msys2.org/docs/environments/ + || !tb_strnicmp(data, + "clang", + 5) // clang32/64 on msys2, @see https://github.com/xmake-io/xmake/issues/3060 + || !tb_stricmp(data, "ucrt64") // ucrt64 https://www.msys2.org/docs/environments/ || !tb_stricmp(data, "msys")) // on msys2 subhost = "msys"; } } -# endif #endif - lua_pushstring(engine->lua, subhost? subhost : "unknown"); +#endif + lua_pushstring(engine->lua, subhost ? subhost : "unknown"); lua_setglobal(engine->lua, "_SUBHOST"); } -static __tb_inline__ tb_char_t const* xm_engine_xmake_arch() -{ - tb_char_t const* arch = tb_null; +static __tb_inline__ tb_char_t const *xm_engine_xmake_arch() { + tb_char_t const *arch = tb_null; #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) -# if defined(TB_ARCH_x64) +#if defined(TB_ARCH_x64) arch = "x64"; -# elif defined(TB_ARCH_ARM64) +#elif defined(TB_ARCH_ARM64) arch = "arm64"; -# elif defined(TB_ARCH_ARM) +#elif defined(TB_ARCH_ARM) arch = "arm"; -# else +#else arch = "x86"; -# endif +#endif #elif defined(TB_ARCH_x64) arch = "x86_64"; #elif defined(TB_ARCH_x86) @@ -1192,48 +1145,46 @@ static __tb_inline__ tb_char_t const* xm_engine_xmake_arch() return arch; } -static tb_void_t xm_engine_init_arch(xm_engine_t* engine) -{ +static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { // check tb_assert_and_check_return(engine && engine->lua); // init xmake arch - tb_char_t const* xmakearch = xm_engine_xmake_arch(); + tb_char_t const *xmakearch = xm_engine_xmake_arch(); lua_pushstring(engine->lua, xmakearch); lua_setglobal(engine->lua, "_XMAKE_ARCH"); // init system architecture - tb_char_t const* sysarch = tb_null; + tb_char_t const *sysarch = tb_null; #if defined(__COSMOPOLITAN__) struct utsname buffer; - if (uname(&buffer) == 0) - { + if (uname(&buffer) == 0) { sysarch = buffer.machine; - if (tb_strstr(buffer.sysname, "Windows")) - { + if (tb_strstr(buffer.sysname, "Windows")) { if (!tb_strcmp(buffer.machine, "x86_64")) sysarch = "x64"; else if (!tb_strcmp(buffer.machine, "i686") || !tb_strcmp(buffer.machine, "i386")) sysarch = "x86"; - } - else if (!tb_strcmp(buffer.machine, "aarch64")) + } else if (!tb_strcmp(buffer.machine, "aarch64")) sysarch = "arm64"; } #elif defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) // the GetNativeSystemInfo function type - typedef void (WINAPI *GetNativeSystemInfo_t)(LPSYSTEM_INFO); + typedef void(WINAPI * GetNativeSystemInfo_t)(LPSYSTEM_INFO); // get system info - SYSTEM_INFO systeminfo = {0}; + SYSTEM_INFO systeminfo = { 0 }; GetNativeSystemInfo_t pGetNativeSystemInfo = tb_null; - tb_dynamic_ref_t kernel32 = tb_dynamic_init("kernel32.dll"); - if (kernel32) pGetNativeSystemInfo = (GetNativeSystemInfo_t)tb_dynamic_func(kernel32, "GetNativeSystemInfo"); - if (pGetNativeSystemInfo) pGetNativeSystemInfo(&systeminfo); - else GetSystemInfo(&systeminfo); + tb_dynamic_ref_t kernel32 = tb_dynamic_init("kernel32.dll"); + if (kernel32) + pGetNativeSystemInfo = (GetNativeSystemInfo_t)tb_dynamic_func(kernel32, "GetNativeSystemInfo"); + if (pGetNativeSystemInfo) + pGetNativeSystemInfo(&systeminfo); + else + GetSystemInfo(&systeminfo); // init architecture - switch (systeminfo.wProcessorArchitecture) - { + switch (systeminfo.wProcessorArchitecture) { case PROCESSOR_ARCHITECTURE_AMD64: sysarch = "x64"; break; @@ -1252,17 +1203,17 @@ static tb_void_t xm_engine_init_arch(xm_engine_t* engine) break; } #endif - if (!sysarch) sysarch = xmakearch; + if (!sysarch) + sysarch = xmakearch; lua_pushstring(engine->lua, sysarch); lua_setglobal(engine->lua, "_ARCH"); // init subsystem architecture - tb_char_t const* subarch = sysarch; + tb_char_t const *subarch = sysarch; #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) // get architecture from msys environment - tb_char_t data[64] = {0}; - if (tb_environment_first("MSYSTEM_CARCH", data, sizeof(data))) - { + tb_char_t data[64] = { 0 }; + if (tb_environment_first("MSYSTEM_CARCH", data, sizeof(data))) { if (!tb_strcmp(data, "i686")) subarch = "i386"; else @@ -1273,8 +1224,7 @@ static tb_void_t xm_engine_init_arch(xm_engine_t* engine) lua_setglobal(engine->lua, "_SUBARCH"); } -static tb_void_t xm_engine_init_features(xm_engine_t* engine) -{ +static tb_void_t xm_engine_init_features(xm_engine_t *engine) { // check tb_assert_and_check_return(engine && engine->lua); @@ -1302,12 +1252,11 @@ static tb_void_t xm_engine_init_features(xm_engine_t* engine) lua_setglobal(engine->lua, "_FEATURES"); } -static tb_void_t xm_engine_init_signal(xm_engine_t* engine) -{ +static tb_void_t xm_engine_init_signal(xm_engine_t *engine) { // we enable it to catch the current lua stack in ctrl-c signal handler if XMAKE_PROFILE=stuck - tb_char_t data[64] = {0}; + tb_char_t data[64] = { 0 }; if (!tb_environment_first("XMAKE_PROFILE", data, sizeof(data)) || tb_strcmp(data, "stuck")) - return ; + return; g_lua = engine->lua; #if defined(TB_CONFIG_OS_WINDOWS) @@ -1319,46 +1268,50 @@ static tb_void_t xm_engine_init_signal(xm_engine_t* engine) #if XM_HOOK_LUA_MEMALLOC // udata is unused, it has been used by engine. see xm_engine_bind_to_lua() -static tb_pointer_t xm_engine_lua_realloc(tb_pointer_t udata, tb_pointer_t data, size_t osize, size_t nsize) -{ +static tb_pointer_t xm_engine_lua_realloc(tb_pointer_t udata, tb_pointer_t data, size_t osize, size_t nsize) { tb_pointer_t ptr = tb_null; - if (nsize == 0 && data) tb_free(data); - else if (!data) ptr = tb_malloc((tb_size_t)nsize); - else if (nsize != osize) ptr = tb_ralloc(data, (tb_size_t)nsize); - else ptr = data; + if (nsize == 0 && data) + tb_free(data); + else if (!data) + ptr = tb_malloc((tb_size_t)nsize); + else if (nsize != osize) + ptr = tb_ralloc(data, (tb_size_t)nsize); + else + ptr = data; return ptr; } #endif #ifdef XM_EMBED_ENABLE -static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_char_t const* programdir, tb_byte_t const* data, tb_size_t size) -{ +static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t *engine, + tb_char_t const *programdir, + tb_byte_t const *data, + tb_size_t size) { // do decompress - tb_bool_t ok = tb_false; - LZ4F_errorCode_t code; + tb_bool_t ok = tb_false; + LZ4F_errorCode_t code; LZ4F_decompressionContext_t ctx = tb_null; - tb_buffer_t result; - do - { + tb_buffer_t result; + do { tb_buffer_init(&result); code = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION); - if (LZ4F_isError(code)) break; + if (LZ4F_isError(code)) + break; tb_byte_t buffer[8192]; tb_bool_t failed = tb_false; - while (1) - { - size_t advance = (size_t)size; + while (1) { + size_t advance = (size_t)size; size_t buffer_size = sizeof(buffer); - code = LZ4F_decompress(ctx, buffer, &buffer_size, data, &advance, tb_null); - if (LZ4F_isError(code)) - { + code = LZ4F_decompress(ctx, buffer, &buffer_size, data, &advance, tb_null); + if (LZ4F_isError(code)) { failed = tb_true; break; } - if (buffer_size == 0) break; + if (buffer_size == 0) + break; data += advance; size -= advance; @@ -1370,22 +1323,20 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_cha } while (0); // extract files to programdir - if (ok) - { - data = tb_buffer_data(&result); - size = tb_buffer_size(&result); - tb_byte_t const* p = data; - tb_byte_t const* e = data + size; - tb_size_t n = 0; - tb_char_t filepath[TB_PATH_MAXN]; - tb_long_t pos = tb_snprintf(filepath, sizeof(filepath), "%s/", programdir); - while (p < e) - { + if (ok) { + data = tb_buffer_data(&result); + size = tb_buffer_size(&result); + tb_byte_t const *p = data; + tb_byte_t const *e = data + size; + tb_size_t n = 0; + tb_char_t filepath[TB_PATH_MAXN]; + tb_long_t pos = tb_snprintf(filepath, sizeof(filepath), "%s/", programdir); + while (p < e) { // get filepath n = (tb_size_t)tb_bits_get_u16_be(p); p += 2; tb_assert_and_check_break(pos + n + 1 < sizeof(filepath)); - tb_strncpy(filepath + pos, (tb_char_t const*)p, n); + tb_strncpy(filepath + pos, (tb_char_t const *)p, n); filepath[pos + n] = '\0'; p += n; @@ -1395,11 +1346,12 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_cha // write file tb_trace_d("extracting %s, %lu bytes ..", filepath, n); - tb_stream_ref_t stream = tb_stream_init_from_file(filepath, TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC); + tb_stream_ref_t stream = tb_stream_init_from_file(filepath, + TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | + TB_FILE_MODE_TRUNC); tb_assert_and_check_break(stream); - if (tb_stream_open(stream)) - { + if (tb_stream_open(stream)) { tb_stream_bwrit(stream, p, n); tb_stream_exit(stream); } @@ -1407,18 +1359,14 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_cha p += n; } ok = (p == e); - if (!ok) - { + if (!ok) { tb_trace_e("extract program files failed"); } - } - else - { + } else { tb_trace_e("decompress program files failed, %s", LZ4F_getErrorName(code)); } - if (ctx) - { + if (ctx) { LZ4F_freeDecompressionContext(ctx); ctx = tb_null; } @@ -1426,19 +1374,16 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t* engine, tb_cha return ok; } -static tb_bool_t xm_engine_extract_programfiles(xm_engine_t* engine, tb_char_t const* programdir) -{ - tb_file_info_t info = {0}; - if (!tb_file_info(programdir, &info)) - { - tb_byte_t const* data = g_xmake_xmz_data; - tb_size_t size = sizeof(g_xmake_xmz_data); +static tb_bool_t xm_engine_extract_programfiles(xm_engine_t *engine, tb_char_t const *programdir) { + tb_file_info_t info = { 0 }; + if (!tb_file_info(programdir, &info)) { + tb_byte_t const *data = g_xmake_xmz_data; + tb_size_t size = sizeof(g_xmake_xmz_data); if (!xm_engine_extract_programfiles_impl(engine, programdir, data, size)) return tb_false; tb_size_t embedcount = engine->embedcount; - for (tb_size_t i = 0; i < embedcount; i++) - { + for (tb_size_t i = 0; i < embedcount; i++) { data = engine->embeddata[i]; size = engine->embedsize[i]; if (!xm_engine_extract_programfiles_impl(engine, programdir, data, size)) @@ -1449,27 +1394,23 @@ static tb_bool_t xm_engine_extract_programfiles(xm_engine_t* engine, tb_char_t c } #endif -static tb_void_t xm_engine_bind_to_lua(lua_State* lua, xm_engine_t* engine) -{ +static tb_void_t xm_engine_bind_to_lua(lua_State *lua, xm_engine_t *engine) { lua_pushlightuserdata(lua, engine); lua_setglobal(lua, "__global_engine"); } // load and execute the main script -static tb_bool_t xm_engine_load_main_script(xm_engine_t* engine, tb_char_t const* mainfile) -{ +static tb_bool_t xm_engine_load_main_script(xm_engine_t *engine, tb_char_t const *mainfile) { #ifdef TB_CONFIG_OS_WINDOWS // use tb_file_init to support unicode file path on windows - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_file_ref_t file = tb_null; - tb_byte_t* data = tb_null; + tb_byte_t *data = tb_null; - do - { + do { // open file file = tb_file_init(mainfile, TB_FILE_MODE_RO); - if (!file) - { + if (!file) { tb_printf("error: cannot open file: %s\n", mainfile); break; } @@ -1479,26 +1420,23 @@ static tb_bool_t xm_engine_load_main_script(xm_engine_t* engine, tb_char_t const tb_assert_and_check_break(size); // allocate buffer - data = (tb_byte_t*)tb_malloc(size); + data = (tb_byte_t *)tb_malloc(size); tb_assert_and_check_break(data); // read file content - if (!tb_file_read(file, data, size)) - { + if (!tb_file_read(file, data, size)) { tb_printf("error: cannot read file: %s\n", mainfile); break; } // load lua buffer - if (luaL_loadbuffer(engine->lua, (tb_char_t const*)data, size, mainfile)) - { + if (luaL_loadbuffer(engine->lua, (tb_char_t const *)data, size, mainfile)) { tb_printf("error: %s\n", lua_tostring(engine->lua, -1)); break; } // execute lua script - if (lua_pcall(engine->lua, 0, LUA_MULTRET, 0)) - { + if (lua_pcall(engine->lua, 0, LUA_MULTRET, 0)) { tb_printf("error: %s\n", lua_tostring(engine->lua, -1)); break; } @@ -1507,12 +1445,13 @@ static tb_bool_t xm_engine_load_main_script(xm_engine_t* engine, tb_char_t const } while (0); - if (data) tb_free(data); - if (file) tb_file_exit(file); + if (data) + tb_free(data); + if (file) + tb_file_exit(file); return ok; #else - if (luaL_dofile(engine->lua, mainfile)) - { + if (luaL_dofile(engine->lua, mainfile)) { tb_printf("error: %s\n", lua_tostring(engine->lua, -1)); return tb_false; } @@ -1523,12 +1462,10 @@ static tb_bool_t xm_engine_load_main_script(xm_engine_t* engine, tb_char_t const /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_cb_t lni_initalizer) -{ - tb_bool_t ok = tb_false; - xm_engine_t* engine = tb_null; - do - { +xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_cb_t lni_initalizer) { + tb_bool_t ok = tb_false; + xm_engine_t *engine = tb_null; + do { // init self engine = tb_malloc0_type(xm_engine_t); tb_assert_and_check_break(engine); @@ -1635,14 +1572,28 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c xm_engine_init_signal(engine); // get version - tb_version_t const* version = xm_version(); + tb_version_t const *version = xm_version(); tb_assert_and_check_break(version); // init version string - tb_char_t version_cstr[256] = {0}; + tb_char_t version_cstr[256] = { 0 }; if (tb_strcmp(XM_CONFIG_VERSION_BRANCH, "") && tb_strcmp(XM_CONFIG_VERSION_COMMIT, "")) - tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u+%s.%s", version->major, version->minor, version->alter, XM_CONFIG_VERSION_BRANCH, XM_CONFIG_VERSION_COMMIT); - else tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u+%llu", version->major, version->minor, version->alter, version->build); + tb_snprintf(version_cstr, + sizeof(version_cstr), + "%u.%u.%u+%s.%s", + version->major, + version->minor, + version->alter, + XM_CONFIG_VERSION_BRANCH, + XM_CONFIG_VERSION_COMMIT); + else + tb_snprintf(version_cstr, + sizeof(version_cstr), + "%u.%u.%u+%llu", + version->major, + version->minor, + version->alter, + version->build); lua_pushstring(engine->lua, version_cstr); lua_setglobal(engine->lua, "_VERSION"); @@ -1661,7 +1612,7 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c lua_setglobal(engine->lua, "_VERSION_SHORT"); // init engine name - lua_pushstring(engine->lua, name? name : "xmake"); + lua_pushstring(engine->lua, name ? name : "xmake"); lua_setglobal(engine->lua, "_NAME"); // use luajit as runtime? @@ -1681,17 +1632,16 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c * we can get the lni modules for _lni or `import("lib.lni.xxx")` in sandbox */ lua_newtable(engine->lua); - if (lni_initalizer) lni_initalizer((xm_engine_ref_t)engine, engine->lua); + if (lni_initalizer) + lni_initalizer((xm_engine_ref_t)engine, engine->lua); lua_setglobal(engine->lua, "_lni"); #ifdef TB_CONFIG_OS_WINDOWS // enable terminal colors output for windows cmd - HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE); - if (output != INVALID_HANDLE_VALUE) - { + HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE); + if (output != INVALID_HANDLE_VALUE) { DWORD mode; - if (GetConsoleMode(output, &mode)) - { + if (GetConsoleMode(output, &mode)) { // attempt to enable 0x4: ENABLE_VIRTUAL_TERMINAL_PROCESSING if (SetConsoleMode(output, mode | 0x4)) tb_environment_set("COLORTERM", "color256"); @@ -1702,64 +1652,69 @@ xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_c } while (0); - if (!ok) - { - if (engine) xm_engine_exit((xm_engine_ref_t)engine); + if (!ok) { + if (engine) + xm_engine_exit((xm_engine_ref_t)engine); engine = tb_null; } return (xm_engine_ref_t)engine; } -tb_void_t xm_engine_exit(xm_engine_ref_t self) -{ +tb_void_t xm_engine_exit(xm_engine_ref_t self) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine); // exit lua - if (engine->lua) lua_close(engine->lua); + if (engine->lua) + lua_close(engine->lua); engine->lua = tb_null; // exit poller - if (engine->poller) tb_poller_exit(engine->poller); + if (engine->poller) + tb_poller_exit(engine->poller); engine->poller = tb_null; // exit it tb_free(engine); } -tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv) -{ +tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, tb_char_t **taskargv) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine && engine->lua, -1); #if defined(TB_CONFIG_OS_WINDOWS) && defined(TB_COMPILER_IS_MSVC) // set "stdin" to have unicode mode - if (_isatty(_fileno(stdin))) _setmode(_fileno(stdin), _O_U16TEXT); + if (_isatty(_fileno(stdin))) + _setmode(_fileno(stdin), _O_U16TEXT); #endif // save main arguments to the global variable: _ARGV - if (!xm_engine_save_arguments(engine, argc, argv, taskargv)) return -1; + if (!xm_engine_save_arguments(engine, argc, argv, taskargv)) + return -1; // get the project directory - tb_char_t path[TB_PATH_MAXN] = {0}; - if (!xm_engine_get_project_directory(engine, path, sizeof(path))) return -1; + tb_char_t path[TB_PATH_MAXN] = { 0 }; + if (!xm_engine_get_project_directory(engine, path, sizeof(path))) + return -1; // get the program file - if (!xm_engine_get_program_file(engine, argv, path, sizeof(path))) return -1; + if (!xm_engine_get_program_file(engine, argv, path, sizeof(path))) + return -1; // get the program directory - if (!xm_engine_get_program_directory(engine, path, sizeof(path), path)) return -1; + if (!xm_engine_get_program_directory(engine, path, sizeof(path), path)) + return -1; #ifdef XM_EMBED_ENABLE - if (!xm_engine_extract_programfiles(engine, path)) return -1; + if (!xm_engine_extract_programfiles(engine, path)) + return -1; #endif // append the main script path tb_strcat(path, "/core/_xmake_main.lua"); // exists this script? - if (!tb_file_info(path, tb_null)) - { + if (!tb_file_info(path, tb_null)) { tb_printf("not found main script: %s\n", path); return -1; } @@ -1777,8 +1732,7 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t** argv, t // call the main function lua_getglobal(engine->lua, "_xmake_main"); - if (lua_pcall(engine->lua, 0, 1, -2)) - { + if (lua_pcall(engine->lua, 0, 1, -2)) { tb_printf("error: %s\n", lua_tostring(engine->lua, -1)); return -1; } @@ -1786,10 +1740,9 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t** argv, t // get the error code return (tb_int_t)lua_tonumber(engine->lua, -1); } -tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const* module, luaL_Reg const funcs[]) -{ +tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const *module, luaL_Reg const funcs[]) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine && engine->lua && module && funcs); // do register @@ -1799,10 +1752,9 @@ tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const* module, luaL lua_rawset(engine->lua, -3); } #ifdef XM_EMBED_ENABLE -tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const* data, tb_size_t size) -{ +tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const *data, tb_size_t size) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine && engine->embedcount < tb_arrayn(engine->embedsize) && data && size); engine->embeddata[engine->embedcount] = data; @@ -1810,25 +1762,22 @@ tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const* data, engine->embedcount++; } #endif -lua_State* xm_engine_lua(xm_engine_ref_t self) -{ +lua_State *xm_engine_lua(xm_engine_ref_t self) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine, tb_null); return engine->lua; } -tb_poller_ref_t xm_engine_poller(xm_engine_ref_t self) -{ +tb_poller_ref_t xm_engine_poller(xm_engine_ref_t self) { // check - xm_engine_t* engine = (xm_engine_t*)self; + xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine, tb_null); - if (!engine->poller) - { + if (!engine->poller) { // init poller engine->poller_state.lua = engine->lua; - tb_poller_ref_t poller = tb_poller_init(&engine->poller_state); + tb_poller_ref_t poller = tb_poller_init(&engine->poller_state); tb_assert_and_check_return_val(poller, tb_null); // attach poller to the current thread @@ -1837,14 +1786,15 @@ tb_poller_ref_t xm_engine_poller(xm_engine_ref_t self) } return engine->poller; } -tb_int_t xm_engine_run(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv, xm_engine_lni_initalizer_cb_t lni_initalizer) -{ +tb_int_t xm_engine_run(tb_char_t const *name, + tb_int_t argc, + tb_char_t **argv, + tb_char_t **taskargv, + xm_engine_lni_initalizer_cb_t lni_initalizer) { tb_int_t ok = -1; - if (xm_init()) - { + if (xm_init()) { xm_engine_ref_t engine = xm_engine_init(name, lni_initalizer); - if (engine) - { + if (engine) { ok = xm_engine_main(engine, argc, argv, taskargv); xm_engine_exit(engine); } @@ -1852,11 +1802,9 @@ tb_int_t xm_engine_run(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, t } return ok; } -xm_engine_ref_t xm_engine_get(lua_State* lua) -{ +xm_engine_ref_t xm_engine_get(lua_State *lua) { tb_assert_and_check_return_val(lua, tb_null); lua_getglobal(lua, "__global_engine"); return (xm_engine_ref_t)lua_touserdata(lua, -1); } - diff --git a/core/src/xmake/engine.h b/core/src/xmake/engine.h index 04ef958d9..a2f7058c6 100644 --- a/core/src/xmake/engine.h +++ b/core/src/xmake/engine.h @@ -36,10 +36,12 @@ __tb_extern_c_enter__ */ /// the xmake engine type -typedef struct {tb_int_t dummy;} const* xm_engine_ref_t; +typedef struct { + tb_int_t dummy; +} const *xm_engine_ref_t; /// the lni initializer callback type -typedef tb_void_t (*xm_engine_lni_initalizer_cb_t)(xm_engine_ref_t engine, lua_State* lua); +typedef tb_void_t (*xm_engine_lni_initalizer_cb_t)(xm_engine_ref_t engine, lua_State *lua); /* ////////////////////////////////////////////////////////////////////////////////////// * interfaces @@ -52,13 +54,13 @@ typedef tb_void_t (*xm_engine_lni_initalizer_cb_t)(xm_engine_ref_t engine, lua_S * * @return the engine */ -xm_engine_ref_t xm_engine_init(tb_char_t const* name, xm_engine_lni_initalizer_cb_t lni_initalizer); +xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_cb_t lni_initalizer); /*! exit the engine * * @param engine the engine */ -tb_void_t xm_engine_exit(xm_engine_ref_t engine); +tb_void_t xm_engine_exit(xm_engine_ref_t engine); /*! do the main entry of the engine * @@ -69,7 +71,7 @@ tb_void_t xm_engine_exit(xm_engine_ref_t engine); * * @return the error code of main() */ -tb_int_t xm_engine_main(xm_engine_ref_t engine, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv); +tb_int_t xm_engine_main(xm_engine_ref_t engine, tb_int_t argc, tb_char_t **argv, tb_char_t **taskargv); /*! register lni modules in the engine, @note we need to call it in lni_initalizer() * @@ -77,7 +79,7 @@ tb_int_t xm_engine_main(xm_engine_ref_t engine, tb_int_t argc * @param module the lni module name * @param funcs the lni module functions */ -tb_void_t xm_engine_register(xm_engine_ref_t engine, tb_char_t const* module, luaL_Reg const funcs[]); +tb_void_t xm_engine_register(xm_engine_ref_t engine, tb_char_t const *module, luaL_Reg const funcs[]); /*! add the embed files * @@ -85,7 +87,7 @@ tb_void_t xm_engine_register(xm_engine_ref_t engine, tb_char_t * @param data the embedfiles data * @param size the data size */ -tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t engine, tb_byte_t const* data, tb_size_t size); +tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t engine, tb_byte_t const *data, tb_size_t size); /* get lua state from engine * @@ -93,7 +95,7 @@ tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t engine, tb_ * * @return the lua state */ -lua_State* xm_engine_lua(xm_engine_ref_t engine); +lua_State *xm_engine_lua(xm_engine_ref_t engine); /* get poller from engine * @@ -101,7 +103,7 @@ lua_State* xm_engine_lua(xm_engine_ref_t engine); * * @return the poller */ -tb_poller_ref_t xm_engine_poller(xm_engine_ref_t engine); +tb_poller_ref_t xm_engine_poller(xm_engine_ref_t engine); /*! run main entry of the engine singleton * @@ -113,7 +115,11 @@ tb_poller_ref_t xm_engine_poller(xm_engine_ref_t engine); * * @return the error code of main() */ -tb_int_t xm_engine_run(tb_char_t const* name, tb_int_t argc, tb_char_t** argv, tb_char_t** taskargv, xm_engine_lni_initalizer_cb_t lni_initalizer); +tb_int_t xm_engine_run(tb_char_t const *name, + tb_int_t argc, + tb_char_t **argv, + tb_char_t **taskargv, + xm_engine_lni_initalizer_cb_t lni_initalizer); /*! get engine from the given lua state * @@ -121,7 +127,7 @@ tb_int_t xm_engine_run(tb_char_t const* name, tb_int_t argc, * * @return the engine */ -xm_engine_ref_t xm_engine_get(lua_State* lua); +xm_engine_ref_t xm_engine_get(lua_State *lua); /* ////////////////////////////////////////////////////////////////////////////////////// * extern diff --git a/core/src/xmake/engine_pool.c b/core/src/xmake/engine_pool.c index 78081399c..cf039d11e 100644 --- a/core/src/xmake/engine_pool.c +++ b/core/src/xmake/engine_pool.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "engine_pool" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "engine_pool" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -37,46 +37,41 @@ */ // the max engine pool count -#define XM_ENGINE_POOL_MAXN (128) +#define XM_ENGINE_POOL_MAXN (128) // the singleton type of engine pool -#define XM_ENGINE_POOL (TB_SINGLETON_TYPE_USER + 4) +#define XM_ENGINE_POOL (TB_SINGLETON_TYPE_USER + 4) /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_handle_t xm_engine_pool_instance_init(tb_cpointer_t* ppriv) -{ +static tb_handle_t xm_engine_pool_instance_init(tb_cpointer_t *ppriv) { xm_engine_pool_ref_t engine_pool = xm_engine_pool_init(); tb_assert_and_check_return_val(engine_pool, tb_null); return (tb_handle_t)engine_pool; } -static tb_void_t xm_engine_pool_instance_exit(tb_handle_t engine_pool, tb_cpointer_t priv) -{ - if (engine_pool) xm_engine_pool_exit((xm_engine_pool_ref_t)engine_pool); +static tb_void_t xm_engine_pool_instance_exit(tb_handle_t engine_pool, tb_cpointer_t priv) { + if (engine_pool) + xm_engine_pool_exit((xm_engine_pool_ref_t)engine_pool); } /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -xm_engine_pool_ref_t xm_engine_pool() -{ - return (xm_engine_pool_ref_t)tb_singleton_instance(XM_ENGINE_POOL, xm_engine_pool_instance_init, xm_engine_pool_instance_exit, tb_null, tb_null); +xm_engine_pool_ref_t xm_engine_pool() { + return (xm_engine_pool_ref_t)tb_singleton_instance( + XM_ENGINE_POOL, xm_engine_pool_instance_init, xm_engine_pool_instance_exit, tb_null, tb_null); } -xm_engine_pool_ref_t xm_engine_pool_init() -{ +xm_engine_pool_ref_t xm_engine_pool_init() { return tb_single_list_init(0, tb_element_ptr(tb_null, tb_null)); } -tb_void_t xm_engine_pool_exit(xm_engine_pool_ref_t engine_pool) -{ - if (engine_pool) - { - tb_for_all (xm_engine_ref_t, engine, engine_pool) - { +tb_void_t xm_engine_pool_exit(xm_engine_pool_ref_t engine_pool) { + if (engine_pool) { + tb_for_all(xm_engine_ref_t, engine, engine_pool) { if (engine) xm_engine_exit(engine); } @@ -84,24 +79,19 @@ tb_void_t xm_engine_pool_exit(xm_engine_pool_ref_t engine_pool) } } -xm_engine_ref_t xm_engine_pool_alloc(xm_engine_pool_ref_t engine_pool) -{ +xm_engine_ref_t xm_engine_pool_alloc(xm_engine_pool_ref_t engine_pool) { xm_engine_ref_t engine = tb_null; - if (tb_single_list_size(engine_pool) > 0) - { + if (tb_single_list_size(engine_pool) > 0) { engine = (xm_engine_ref_t)tb_single_list_head(engine_pool); tb_single_list_remove_head(engine_pool); } return engine; } -tb_bool_t xm_engine_pool_free(xm_engine_pool_ref_t engine_pool, xm_engine_ref_t engine) -{ - if (tb_single_list_size(engine_pool) < XM_ENGINE_POOL_MAXN) - { +tb_bool_t xm_engine_pool_free(xm_engine_pool_ref_t engine_pool, xm_engine_ref_t engine) { + if (tb_single_list_size(engine_pool) < XM_ENGINE_POOL_MAXN) { tb_single_list_insert_tail(engine_pool, engine); return tb_true; } return tb_false; } - diff --git a/core/src/xmake/engine_pool.h b/core/src/xmake/engine_pool.h index 853856d1c..05bdc4668 100644 --- a/core/src/xmake/engine_pool.h +++ b/core/src/xmake/engine_pool.h @@ -43,19 +43,19 @@ typedef tb_single_list_ref_t xm_engine_pool_ref_t; */ // get the engine pool singleton -xm_engine_pool_ref_t xm_engine_pool(tb_void_t); +xm_engine_pool_ref_t xm_engine_pool(tb_void_t); /*! init the engine_pool * * @return the engine pool */ -xm_engine_pool_ref_t xm_engine_pool_init(tb_void_t); +xm_engine_pool_ref_t xm_engine_pool_init(tb_void_t); /*! exit the engine_pool * * @param engine_pool the engine_pool */ -tb_void_t xm_engine_pool_exit(xm_engine_pool_ref_t engine_pool); +tb_void_t xm_engine_pool_exit(xm_engine_pool_ref_t engine_pool); /*! alloc a engine from the engine_pool * @@ -63,7 +63,7 @@ tb_void_t xm_engine_pool_exit(xm_engine_pool_ref_t engine_pool * * @return the engine */ -xm_engine_ref_t xm_engine_pool_alloc(xm_engine_pool_ref_t engine_pool); +xm_engine_ref_t xm_engine_pool_alloc(xm_engine_pool_ref_t engine_pool); /*! free a engine to the engine_pool * @@ -72,7 +72,7 @@ xm_engine_ref_t xm_engine_pool_alloc(xm_engine_pool_ref_t engine_poo * * @return tb_true or tb_false */ -tb_bool_t xm_engine_pool_free(xm_engine_pool_ref_t engine_pool, xm_engine_ref_t engine); +tb_bool_t xm_engine_pool_free(xm_engine_pool_ref_t engine_pool, xm_engine_ref_t engine); /* ////////////////////////////////////////////////////////////////////////////////////// * extern diff --git a/core/src/xmake/fwatcher/add.c b/core/src/xmake/fwatcher/add.c index 90c655eda..cda233104 100644 --- a/core/src/xmake/fwatcher/add.c +++ b/core/src/xmake/fwatcher/add.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "fwatcher.add" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "fwatcher.add" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // fwatcher.add(watchdir, recursion) -tb_int_t xm_fwatcher_add(lua_State* lua) -{ +tb_int_t xm_fwatcher_add(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -49,7 +48,7 @@ tb_int_t xm_fwatcher_add(lua_State* lua) tb_check_return_val(fwatcher, 0); // get watchdir - tb_char_t const* watchdir = luaL_checkstring(lua, 2); + tb_char_t const *watchdir = luaL_checkstring(lua, 2); tb_check_return_val(watchdir, 0); // get recursion diff --git a/core/src/xmake/fwatcher/close.c b/core/src/xmake/fwatcher/close.c index 6d9eced7a..8f6a680be 100644 --- a/core/src/xmake/fwatcher/close.c +++ b/core/src/xmake/fwatcher/close.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "fwatcher.close" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "fwatcher.close" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // fwatcher.close(p) -tb_int_t xm_fwatcher_close(lua_State* lua) -{ +tb_int_t xm_fwatcher_close(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); diff --git a/core/src/xmake/fwatcher/open.c b/core/src/xmake/fwatcher/open.c index 333c26616..05173660e 100644 --- a/core/src/xmake/fwatcher/open.c +++ b/core/src/xmake/fwatcher/open.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "fwatcher.open" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "fwatcher.open" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_fwatcher_open(lua_State* lua) -{ +tb_int_t xm_fwatcher_open(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // init fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)tb_fwatcher_init(); - if (fwatcher) xm_lua_pushpointer(lua, (tb_pointer_t)fwatcher); - else lua_pushnil(lua); + if (fwatcher) + xm_lua_pushpointer(lua, (tb_pointer_t)fwatcher); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/fwatcher/prefix.h b/core/src/xmake/fwatcher/prefix.h index c11421b55..767b8f022 100644 --- a/core/src/xmake/fwatcher/prefix.h +++ b/core/src/xmake/fwatcher/prefix.h @@ -27,5 +27,3 @@ #include "../prefix.h" #endif - - diff --git a/core/src/xmake/fwatcher/remove.c b/core/src/xmake/fwatcher/remove.c index c0e4d30bd..d7ef4d289 100644 --- a/core/src/xmake/fwatcher/remove.c +++ b/core/src/xmake/fwatcher/remove.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "fwatcher.remove" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "fwatcher.remove" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // fwatcher.remove(watchdir) -tb_int_t xm_fwatcher_remove(lua_State* lua) -{ +tb_int_t xm_fwatcher_remove(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -49,7 +48,7 @@ tb_int_t xm_fwatcher_remove(lua_State* lua) tb_check_return_val(fwatcher, 0); // get watchdir - tb_char_t const* watchdir = luaL_checkstring(lua, 2); + tb_char_t const *watchdir = luaL_checkstring(lua, 2); tb_check_return_val(watchdir, 0); // remove watchdir @@ -59,4 +58,3 @@ tb_int_t xm_fwatcher_remove(lua_State* lua) lua_pushboolean(lua, ok); return 1; } - diff --git a/core/src/xmake/fwatcher/wait.c b/core/src/xmake/fwatcher/wait.c index 72f48b50a..d4e64347f 100644 --- a/core/src/xmake/fwatcher/wait.c +++ b/core/src/xmake/fwatcher/wait.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "fwatcher.wait" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "fwatcher.wait" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // fwatcher.wait(p) -tb_int_t xm_fwatcher_wait(lua_State* lua) -{ +tb_int_t xm_fwatcher_wait(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -53,12 +52,11 @@ tb_int_t xm_fwatcher_wait(lua_State* lua) // wait fwatcher event tb_fwatcher_event_t event; - tb_long_t ok = tb_fwatcher_wait(fwatcher, &event, timeout); + tb_long_t ok = tb_fwatcher_wait(fwatcher, &event, timeout); // save result lua_pushinteger(lua, ok); - if (ok > 0) - { + if (ok > 0) { lua_newtable(lua); lua_pushstring(lua, "path"); lua_pushstring(lua, event.filepath); diff --git a/core/src/xmake/hash/md5.c b/core/src/xmake/hash/md5.c index 39fa82b15..91f7eafc9 100644 --- a/core/src/xmake/hash/md5.c +++ b/core/src/xmake/hash/md5.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "md5" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "md5" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_hash_md5(lua_State* lua) -{ +tb_int_t xm_hash_md5(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // is bytes? get data and size - if (xm_lua_isinteger(lua, 1) && xm_lua_isinteger(lua, 2)) - { - tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - tb_size_t size = (tb_size_t)lua_tointeger(lua, 2); - if (!data || !size) - { + if (xm_lua_isinteger(lua, 1) && xm_lua_isinteger(lua, 2)) { + tb_byte_t const *data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + tb_size_t size = (tb_size_t)lua_tointeger(lua, 2); + if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -65,33 +62,30 @@ tb_int_t xm_hash_md5(lua_State* lua) } // get the filename - tb_char_t const* filename = luaL_checkstring(lua, 1); + tb_char_t const *filename = luaL_checkstring(lua, 1); tb_check_return_val(filename, 0); // load data from file - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_stream_ref_t stream = tb_stream_init_from_file(filename, TB_FILE_MODE_RO); - if (stream) - { + if (stream) { // open stream - if (tb_stream_open(stream)) - { + if (tb_stream_open(stream)) { // init md5 tb_md5_t md5; tb_md5_init(&md5, 0); // read data and update md5 tb_byte_t data[TB_STREAM_BLOCK_MAXN]; - while (!tb_stream_beof(stream)) - { + while (!tb_stream_beof(stream)) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); // ok? - if (real > 0) tb_md5_spak(&md5, data, real); + if (real > 0) + tb_md5_spak(&md5, data, real); // no data? continue it - else if (!real) - { + else if (!real) { // wait real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, tb_stream_timeout(stream)); tb_check_break(real > 0); @@ -100,7 +94,8 @@ tb_int_t xm_hash_md5(lua_State* lua) tb_assert_and_check_break(real & TB_STREAM_WAIT_READ); } // failed or end? - else break; + else + break; } // exit md5 @@ -112,13 +107,14 @@ tb_int_t xm_hash_md5(lua_State* lua) tb_size_t n = xm_hash_make_cstr(s, buffer, 16); // save result - lua_pushlstring(lua, s, n); + lua_pushlstring(lua, s, n); ok = tb_true; } // exit stream tb_stream_exit(stream); } - if (!ok) lua_pushnil(lua); + if (!ok) + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/hash/prefix.h b/core/src/xmake/hash/prefix.h index 8a321e1eb..99a8e4e6d 100644 --- a/core/src/xmake/hash/prefix.h +++ b/core/src/xmake/hash/prefix.h @@ -30,8 +30,7 @@ * helper implementation */ -static __tb_inline__ tb_uint64_t xm_hash_xorshift64(tb_uint64_t x) -{ +static __tb_inline__ tb_uint64_t xm_hash_xorshift64(tb_uint64_t x) { x ^= x << 13; x ^= x >> 7; x ^= x << 17; @@ -39,27 +38,24 @@ static __tb_inline__ tb_uint64_t xm_hash_xorshift64(tb_uint64_t x) } // http://xorshift.di.unimi.it/xorshift128plus.c -static __tb_inline__ tb_uint64_t xm_hash_xorshift128(tb_uint64_t* s) -{ - tb_uint64_t s1 = s[0]; +static __tb_inline__ tb_uint64_t xm_hash_xorshift128(tb_uint64_t *s) { + tb_uint64_t s1 = s[0]; tb_uint64_t const s0 = s[1]; - s[0] = s0; + s[0] = s0; s1 ^= s1 << 23; s[1] = s1 ^ s0 ^ (s1 >> 18) ^ (s0 >> 5); return s[1] + s0; } -static __tb_inline__ tb_size_t xm_hash_make_cstr(tb_char_t hash[256], tb_byte_t const* data, tb_size_t size) -{ - static tb_char_t const* digits_table = "0123456789abcdef"; - tb_size_t i = 0; - tb_byte_t value; - tb_char_t* s = hash; - for (i = 0; i < size; ++i) - { +static __tb_inline__ tb_size_t xm_hash_make_cstr(tb_char_t hash[256], tb_byte_t const *data, tb_size_t size) { + static tb_char_t const *digits_table = "0123456789abcdef"; + tb_size_t i = 0; + tb_byte_t value; + tb_char_t *s = hash; + for (i = 0; i < size; ++i) { value = data[i]; - s[0] = digits_table[(value >> 4) & 15]; - s[1] = digits_table[value & 15]; + s[0] = digits_table[(value >> 4) & 15]; + s[1] = digits_table[value & 15]; s += 2; } *s = '\0'; @@ -67,5 +63,3 @@ static __tb_inline__ tb_size_t xm_hash_make_cstr(tb_char_t hash[256], tb_byte_t } #endif - - diff --git a/core/src/xmake/hash/rand128.c b/core/src/xmake/hash/rand128.c index 1e1f34fde..bb844aee9 100644 --- a/core/src/xmake/hash/rand128.c +++ b/core/src/xmake/hash/rand128.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "rand128" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "rand128" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_hash_rand128(lua_State* lua) -{ +tb_int_t xm_hash_rand128(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); - static union { tb_byte_t b[16]; tb_uint64_t word[2]; } s_seed = {0}; - if (!s_seed.word[0] && !s_seed.word[1]) - { + static union { + tb_byte_t b[16]; + tb_uint64_t word[2]; + } s_seed = { 0 }; + if (!s_seed.word[0] && !s_seed.word[1]) { s_seed.word[0] = (tb_uint64_t)tb_uclock(); s_seed.word[1] = (tb_uint64_t)tb_uclock(); } diff --git a/core/src/xmake/hash/rand32.c b/core/src/xmake/hash/rand32.c index bbf565acd..a8a2dc054 100644 --- a/core/src/xmake/hash/rand32.c +++ b/core/src/xmake/hash/rand32.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "rand32" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "rand32" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_hash_rand32(lua_State* lua) -{ +tb_int_t xm_hash_rand32(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -43,9 +42,9 @@ tb_int_t xm_hash_rand32(lua_State* lua) s_seed = (tb_uint64_t)tb_uclock(); s_seed = xm_hash_xorshift64(s_seed); - tb_char_t s[256]; + tb_char_t s[256]; tb_uint32_t word = (s_seed >> 32) ^ (s_seed & 0xffffffff); - tb_size_t n = xm_hash_make_cstr(s, (tb_byte_t const*)&word, 4); + tb_size_t n = xm_hash_make_cstr(s, (tb_byte_t const *)&word, 4); lua_pushlstring(lua, s, n); return 1; diff --git a/core/src/xmake/hash/rand64.c b/core/src/xmake/hash/rand64.c index 31732bc53..05b861327 100644 --- a/core/src/xmake/hash/rand64.c +++ b/core/src/xmake/hash/rand64.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "rand64" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "rand64" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,12 +33,14 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_hash_rand64(lua_State* lua) -{ +tb_int_t xm_hash_rand64(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); - static union { tb_byte_t b[8]; tb_uint64_t word; } s_seed = {0}; + static union { + tb_byte_t b[8]; + tb_uint64_t word; + } s_seed = { 0 }; if (!s_seed.word) s_seed.word = (tb_uint64_t)tb_uclock(); s_seed.word = xm_hash_xorshift64(s_seed.word); diff --git a/core/src/xmake/hash/sha.c b/core/src/xmake/hash/sha.c index ba5408279..12d98b860 100644 --- a/core/src/xmake/hash/sha.c +++ b/core/src/xmake/hash/sha.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "sha" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "sha" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_hash_sha(lua_State* lua) -{ +tb_int_t xm_hash_sha(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -42,12 +41,10 @@ tb_int_t xm_hash_sha(lua_State* lua) tb_size_t mode = (tb_size_t)lua_tointeger(lua, 1); // is bytes? get data and size - if (xm_lua_isinteger(lua, 2) && xm_lua_isinteger(lua, 3)) - { - tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - tb_size_t size = (tb_size_t)lua_tointeger(lua, 3); - if (!data || !size) - { + if (xm_lua_isinteger(lua, 2) && xm_lua_isinteger(lua, 3)) { + tb_byte_t const *data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + tb_size_t size = (tb_size_t)lua_tointeger(lua, 3); + if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -55,7 +52,7 @@ tb_int_t xm_hash_sha(lua_State* lua) tb_assert_static(sizeof(lua_Integer) >= sizeof(tb_pointer_t)); // compute sha - tb_sha_t sha; + tb_sha_t sha; tb_byte_t buffer[32]; tb_sha_init(&sha, mode); tb_sha_spak(&sha, data, size); @@ -63,7 +60,7 @@ tb_int_t xm_hash_sha(lua_State* lua) // make sha string tb_char_t s[256]; - tb_size_t n = sha.digest_len << 2; + tb_size_t n = sha.digest_len << 2; tb_size_t len = xm_hash_make_cstr(s, buffer, n); // save result @@ -72,33 +69,30 @@ tb_int_t xm_hash_sha(lua_State* lua) } // get the filename - tb_char_t const* filename = luaL_checkstring(lua, 2); + tb_char_t const *filename = luaL_checkstring(lua, 2); tb_check_return_val(filename, 0); // load data from file - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_stream_ref_t stream = tb_stream_init_from_file(filename, TB_FILE_MODE_RO); - if (stream) - { + if (stream) { // open stream - if (tb_stream_open(stream)) - { + if (tb_stream_open(stream)) { // init sha tb_sha_t sha; tb_sha_init(&sha, mode); // read data and update sha tb_byte_t data[TB_STREAM_BLOCK_MAXN]; - while (!tb_stream_beof(stream)) - { + while (!tb_stream_beof(stream)) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); // ok? - if (real > 0) tb_sha_spak(&sha, data, real); + if (real > 0) + tb_sha_spak(&sha, data, real); // no data? continue it - else if (!real) - { + else if (!real) { // wait real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, tb_stream_timeout(stream)); tb_check_break(real > 0); @@ -107,7 +101,8 @@ tb_int_t xm_hash_sha(lua_State* lua) tb_assert_and_check_break(real & TB_STREAM_WAIT_READ); } // failed or end? - else break; + else + break; } // exit sha @@ -116,17 +111,18 @@ tb_int_t xm_hash_sha(lua_State* lua) // make sha string tb_char_t s[256]; - tb_size_t n = sha.digest_len << 2; + tb_size_t n = sha.digest_len << 2; tb_size_t len = xm_hash_make_cstr(s, buffer, n); // save result - lua_pushlstring(lua, s, len); + lua_pushlstring(lua, s, len); ok = tb_true; } // exit stream tb_stream_exit(stream); } - if (!ok) lua_pushnil(lua); + if (!ok) + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/hash/uuid4.c b/core/src/xmake/hash/uuid4.c index a3c4e2360..d99e849d8 100644 --- a/core/src/xmake/hash/uuid4.c +++ b/core/src/xmake/hash/uuid4.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "uuid4" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "uuid4" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,16 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_hash_uuid4(lua_State* lua) -{ +tb_int_t xm_hash_uuid4(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the name - tb_char_t const* name = luaL_optstring(lua, 1, tb_null); + tb_char_t const *name = luaL_optstring(lua, 1, tb_null); // make uuid, use version 4 tb_char_t uuid[37]; - lua_pushstring(lua, tb_uuid4_make_cstr(uuid, name)); + lua_pushstring(lua, tb_uuid4_make_cstr(uuid, name)); return 1; } diff --git a/core/src/xmake/hash/xxhash.c b/core/src/xmake/hash/xxhash.c index cf4f67e37..49e1199e8 100644 --- a/core/src/xmake/hash/xxhash.c +++ b/core/src/xmake/hash/xxhash.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "xxhash" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "xxhash" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -37,27 +37,23 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_hash_xxhash(lua_State* lua) -{ +tb_int_t xm_hash_xxhash(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get mode tb_size_t mode = (tb_size_t)lua_tointeger(lua, 1); - if (mode != 32 && mode != 64 && mode != 128) - { + if (mode != 32 && mode != 64 && mode != 128) { lua_pushnil(lua); lua_pushfstring(lua, "invalid mode(%d)!", (tb_int_t)mode); return 2; } // is bytes? get data and size - if (xm_lua_isinteger(lua, 2) && xm_lua_isinteger(lua, 3)) - { - tb_byte_t const* data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - tb_size_t size = (tb_size_t)lua_tointeger(lua, 3); - if (!data || !size) - { + if (xm_lua_isinteger(lua, 2) && xm_lua_isinteger(lua, 3)) { + tb_byte_t const *data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + tb_size_t size = (tb_size_t)lua_tointeger(lua, 3); + if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -65,28 +61,22 @@ tb_int_t xm_hash_xxhash(lua_State* lua) tb_assert_static(sizeof(lua_Integer) >= sizeof(tb_pointer_t)); // compuate hash - tb_byte_t const* buffer = tb_null; - tb_uint32_t value32; - XXH64_hash_t value64; - XXH128_hash_t value128; - if (mode == 128) - { + tb_byte_t const *buffer = tb_null; + tb_uint32_t value32; + XXH64_hash_t value64; + XXH128_hash_t value128; + if (mode == 128) { value128 = XM_XXH3_128bits(data, size); - buffer = (tb_byte_t const*)&value128; - } - else if (mode == 64) - { + buffer = (tb_byte_t const *)&value128; + } else if (mode == 64) { value64 = XM_XXH3_64bits(data, size); - buffer = (tb_byte_t const*)&value64; - } - else if (mode == 32) - { + buffer = (tb_byte_t const *)&value64; + } else if (mode == 32) { value64 = XM_XXH3_64bits(data, size); value32 = (value64 >> 32) ^ (value64 & 0xffffffff); - buffer = (tb_byte_t const*)&value32; + buffer = (tb_byte_t const *)&value32; } - if (!buffer) - { + if (!buffer) { lua_pushnil(lua); lua_pushfstring(lua, "empty buffer!"); return 2; @@ -94,7 +84,7 @@ tb_int_t xm_hash_xxhash(lua_State* lua) // make xxhash string tb_char_t s[256]; - tb_size_t n = mode >> 3; + tb_size_t n = mode >> 3; tb_size_t len = xm_hash_make_cstr(s, buffer, n); // save result @@ -103,38 +93,37 @@ tb_int_t xm_hash_xxhash(lua_State* lua) } // get the filename - tb_char_t const* filename = luaL_checkstring(lua, 2); + tb_char_t const *filename = luaL_checkstring(lua, 2); tb_check_return_val(filename, 0); // load data from file - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_stream_ref_t stream = tb_stream_init_from_file(filename, TB_FILE_MODE_RO); - if (stream) - { + if (stream) { // open stream - XXH3_state_t* state = XM_XXH3_createState(); - if (tb_stream_open(stream) && state) - { + XXH3_state_t *state = XM_XXH3_createState(); + if (tb_stream_open(stream) && state) { // reset xxhash - if (mode == 32 || mode == 64) XM_XXH3_64bits_reset(state); - else XM_XXH3_128bits_reset(state); + if (mode == 32 || mode == 64) + XM_XXH3_64bits_reset(state); + else + XM_XXH3_128bits_reset(state); // read data and update xxhash tb_byte_t data[TB_STREAM_BLOCK_MAXN]; - while (!tb_stream_beof(stream)) - { + while (!tb_stream_beof(stream)) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); // ok? - if (real > 0) - { - if (mode == 32 || mode == 64) XM_XXH3_64bits_update(state, data, real); - else XM_XXH3_128bits_update(state, data, real); + if (real > 0) { + if (mode == 32 || mode == 64) + XM_XXH3_64bits_update(state, data, real); + else + XM_XXH3_128bits_update(state, data, real); } // no data? continue it - else if (!real) - { + else if (!real) { // wait real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, tb_stream_timeout(stream)); tb_check_break(real > 0); @@ -143,38 +132,34 @@ tb_int_t xm_hash_xxhash(lua_State* lua) tb_assert_and_check_break(real & TB_STREAM_WAIT_READ); } // failed or end? - else break; + else + break; } // compuate hash - tb_byte_t const* buffer; - tb_uint32_t value32; - XXH64_hash_t value64; - XXH128_hash_t value128; - if (mode == 128) - { + tb_byte_t const *buffer; + tb_uint32_t value32; + XXH64_hash_t value64; + XXH128_hash_t value128; + if (mode == 128) { value128 = XM_XXH3_128bits_digest(state); - buffer = (tb_byte_t const*)&value128; - } - else if (mode == 64) - { + buffer = (tb_byte_t const *)&value128; + } else if (mode == 64) { value64 = XM_XXH3_64bits_digest(state); - buffer = (tb_byte_t const*)&value64; - } - else if (mode == 32) - { + buffer = (tb_byte_t const *)&value64; + } else if (mode == 32) { value64 = XM_XXH3_64bits_digest(state); value32 = (value64 >> 32) ^ (value64 & 0xffffffff); - buffer = (tb_byte_t const*)&value32; + buffer = (tb_byte_t const *)&value32; } // make xxhash string tb_char_t s[256]; - tb_size_t n = mode >> 3; + tb_size_t n = mode >> 3; tb_size_t len = xm_hash_make_cstr(s, buffer, n); // save result - lua_pushlstring(lua, s, len); + lua_pushlstring(lua, s, len); ok = tb_true; } @@ -182,8 +167,10 @@ tb_int_t xm_hash_xxhash(lua_State* lua) tb_stream_exit(stream); // exit xxhash - if (state) XM_XXH3_freeState(state); + if (state) + XM_XXH3_freeState(state); } - if (!ok) lua_pushnil(lua); + if (!ok) + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/io/file_close.c b/core/src/xmake/io/file_close.c index dfd698457..e00946dd0 100644 --- a/core/src/xmake/io/file_close.c +++ b/core/src/xmake/io/file_close.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_close" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_close" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.file_close(file) -tb_int_t xm_io_file_close(lua_State* lua) -{ +tb_int_t xm_io_file_close(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -45,30 +44,29 @@ tb_int_t xm_io_file_close(lua_State* lua) xm_io_return_error(lua, "close(invalid file)!"); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 1); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); tb_check_return_val(file, 0); // close file - if (xm_io_file_is_file(file)) - { + if (xm_io_file_is_file(file)) { // check tb_assert(file->u.file_ref); #ifdef TB_CONFIG_OS_WINDOWS // write cached data first - tb_byte_t const* odata = tb_buffer_data(&file->wcache); + tb_byte_t const *odata = tb_buffer_data(&file->wcache); tb_size_t osize = tb_buffer_size(&file->wcache); - if (odata && osize) - { - if (!tb_stream_bwrit(file->u.file_ref, odata, osize)) return tb_false; + if (odata && osize) { + if (!tb_stream_bwrit(file->u.file_ref, odata, osize)) + return tb_false; tb_buffer_clear(&file->wcache); } #endif // flush filter stream cache, TODO we should fix it in tbox/stream - if ((file->mode & TB_FILE_MODE_RW) == TB_FILE_MODE_RW && file->fstream) - { - if (!tb_stream_sync(file->u.file_ref, tb_false)) return tb_false; + if ((file->mode & TB_FILE_MODE_RW) == TB_FILE_MODE_RW && file->fstream) { + if (!tb_stream_sync(file->u.file_ref, tb_false)) + return tb_false; } // close file @@ -76,11 +74,13 @@ tb_int_t xm_io_file_close(lua_State* lua) file->u.file_ref = tb_null; // exit fstream - if (file->fstream) tb_stream_exit(file->fstream); + if (file->fstream) + tb_stream_exit(file->fstream); file->fstream = tb_null; // exit stream - if (file->stream) tb_stream_exit(file->stream); + if (file->stream) + tb_stream_exit(file->stream); file->stream = tb_null; // exit the line cache buffer @@ -93,8 +93,7 @@ tb_int_t xm_io_file_close(lua_State* lua) // ok lua_pushboolean(lua, tb_true); return 1; - } - else // for stdfile (gc/close) + } else // for stdfile (gc/close) { // exit the line cache buffer tb_buffer_exit(&file->rcache); @@ -108,4 +107,3 @@ tb_int_t xm_io_file_close(lua_State* lua) return 1; } } - diff --git a/core/src/xmake/io/file_flush.c b/core/src/xmake/io/file_flush.c index e7650e29b..5aa3e9f58 100644 --- a/core/src/xmake/io/file_flush.c +++ b/core/src/xmake/io/file_flush.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_flush" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_flush" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,24 +33,22 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_bool_t xm_io_std_flush_impl(xm_io_file_t* file) -{ +static tb_bool_t xm_io_std_flush_impl(xm_io_file_t *file) { tb_assert_and_check_return_val(xm_io_file_is_std(file), tb_false); - return (file->u.std_ref != tb_stdfile_input())? tb_stdfile_flush(file->u.std_ref) : tb_false; + return (file->u.std_ref != tb_stdfile_input()) ? tb_stdfile_flush(file->u.std_ref) : tb_false; } -static tb_bool_t xm_io_file_flush_impl(xm_io_file_t* file) -{ +static tb_bool_t xm_io_file_flush_impl(xm_io_file_t *file) { // check tb_assert_and_check_return_val(xm_io_file_is_file(file), tb_false); #ifdef TB_CONFIG_OS_WINDOWS // write cached data first - tb_byte_t const* odata = tb_buffer_data(&file->wcache); + tb_byte_t const *odata = tb_buffer_data(&file->wcache); tb_size_t osize = tb_buffer_size(&file->wcache); - if (odata && osize) - { - if (!tb_stream_bwrit(file->u.file_ref, odata, osize)) return tb_false; + if (odata && osize) { + if (!tb_stream_bwrit(file->u.file_ref, odata, osize)) + return tb_false; tb_buffer_clear(&file->wcache); } #endif @@ -62,8 +60,7 @@ static tb_bool_t xm_io_file_flush_impl(xm_io_file_t* file) */ // io.file_flush(file) -tb_int_t xm_io_file_flush(lua_State* lua) -{ +tb_int_t xm_io_file_flush(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -72,15 +69,14 @@ tb_int_t xm_io_file_flush(lua_State* lua) xm_io_return_error(lua, "flush(invalid file)!"); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 1); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); tb_check_return_val(file, 0); // flush file - tb_bool_t ok = xm_io_file_is_file(file)? xm_io_file_flush_impl(file) : xm_io_std_flush_impl(file); - if (ok) - { + tb_bool_t ok = xm_io_file_is_file(file) ? xm_io_file_flush_impl(file) : xm_io_std_flush_impl(file); + if (ok) { lua_pushboolean(lua, tb_true); return 1; - } - else xm_io_return_error(lua, "failed to flush file"); + } else + xm_io_return_error(lua, "failed to flush file"); } diff --git a/core/src/xmake/io/file_isatty.c b/core/src/xmake/io/file_isatty.c index 53a9c4ac8..645431398 100644 --- a/core/src/xmake/io/file_isatty.c +++ b/core/src/xmake/io/file_isatty.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_isatty" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_isatty" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.file_isatty(file) -tb_int_t xm_io_file_isatty(lua_State* lua) -{ +tb_int_t xm_io_file_isatty(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -45,7 +44,7 @@ tb_int_t xm_io_file_isatty(lua_State* lua) xm_io_return_error(lua, "isatty(invalid file)!"); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 1); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); tb_check_return_val(file, 0); // is tty? diff --git a/core/src/xmake/io/file_open.c b/core/src/xmake/io/file_open.c index 0cd9c6cb6..56c0848fd 100644 --- a/core/src/xmake/io/file_open.c +++ b/core/src/xmake/io/file_open.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_open" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_open" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,46 +35,40 @@ */ // num of bytes read to guess encoding -#define CHECK_SIZE (1024) +#define CHECK_SIZE (1024) // is utf-8 tail character -#define IS_UTF8_TAIL(c) (c >= 0x80 && c < 0xc0) +#define IS_UTF8_TAIL(c) (c >= 0x80 && c < 0xc0) /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_size_t xm_io_file_detect_charset(tb_byte_t const** data_ptr, tb_long_t size) -{ +static tb_size_t xm_io_file_detect_charset(tb_byte_t const **data_ptr, tb_long_t size) { // check tb_assert(data_ptr && *data_ptr); - tb_byte_t const* data = *data_ptr; + tb_byte_t const *data = *data_ptr; tb_size_t charset = XM_IO_FILE_ENCODING_BINARY; - do - { + do { // is luajit bitcode? open as binary if (size >= 3 && data[0] == 27 && data[1] == 'L' && data[2] == 'J') break; // utf-8 with bom - if (size >= 3 && data[0] == 239 && data[1] == 187 && data[2] == 191) - { + if (size >= 3 && data[0] == 239 && data[1] == 187 && data[2] == 191) { charset = TB_CHARSET_TYPE_UTF8; data += 3; // skip bom break; } - if (size >= 2) - { + if (size >= 2) { // utf16be - if (data[0] == 254 && data[1] == 255) - { + if (data[0] == 254 && data[1] == 255) { charset = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_BE; data += 2; // skip bom break; } // utf16le - else if (data[0] == 255 && data[1] == 254) - { + else if (data[0] == 255 && data[1] == 254) { charset = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_LE; data += 2; // skip bom break; @@ -86,19 +80,20 @@ static tb_size_t xm_io_file_detect_charset(tb_byte_t const** data_ptr, tb_long_t tb_sint16_t utf8_conf = 0; tb_sint16_t ascii_conf = 0; tb_sint16_t zero_count = 0; - for (tb_long_t i = 0; i < (size - 4) && i < CHECK_SIZE; i++) - { - if (data[i] == 0) zero_count++; + for (tb_long_t i = 0; i < (size - 4) && i < CHECK_SIZE; i++) { + if (data[i] == 0) + zero_count++; if (data[i] < 0x80) ascii_conf++; else ascii_conf = TB_MINS16; - if (i % 2 == 0) - { - if (data[i] == 0) utf16be_conf++; - if (data[i + 1] == 0) utf16le_conf++; + if (i % 2 == 0) { + if (data[i] == 0) + utf16be_conf++; + if (data[i + 1] == 0) + utf16le_conf++; } if (IS_UTF8_TAIL(data[i])) @@ -109,34 +104,30 @@ static tb_size_t xm_io_file_detect_charset(tb_byte_t const** data_ptr, tb_long_t utf8_conf++; else if (data[i] >= 0xe0 && data[i] < 0xf0 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2])) utf8_conf++; - else if (data[i] >= 0xf0 && data[i] < 0xf8 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2]) && IS_UTF8_TAIL(data[i + 3])) + else if (data[i] >= 0xf0 && data[i] < 0xf8 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2]) && + IS_UTF8_TAIL(data[i + 3])) utf8_conf++; else utf8_conf = TB_MINS16; } - if (ascii_conf > 0 && zero_count <= 1) - { + if (ascii_conf > 0 && zero_count <= 1) { charset = TB_CHARSET_TYPE_UTF8; break; } - if (utf8_conf > 0 && zero_count <= 1) - { + if (utf8_conf > 0 && zero_count <= 1) { charset = TB_CHARSET_TYPE_UTF8; break; } - if (utf16be_conf > 0 && utf16be_conf > utf16le_conf) - { + if (utf16be_conf > 0 && utf16be_conf > utf16le_conf) { charset = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_BE; break; } - if (utf16le_conf > 0 && utf16le_conf >= utf16be_conf) - { + if (utf16le_conf > 0 && utf16le_conf >= utf16be_conf) { charset = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_LE; break; } - if (utf8_conf > 0) - { + if (utf8_conf > 0) { charset = TB_CHARSET_TYPE_UTF8; break; } @@ -150,20 +141,18 @@ static tb_size_t xm_io_file_detect_charset(tb_byte_t const** data_ptr, tb_long_t *data_ptr = data; return charset; } -static tb_size_t xm_io_file_detect_encoding(tb_stream_ref_t stream, tb_long_t* pbomoff) -{ +static tb_size_t xm_io_file_detect_encoding(tb_stream_ref_t stream, tb_long_t *pbomoff) { // check tb_assert_and_check_return_val(stream && pbomoff, XM_IO_FILE_ENCODING_BINARY); // detect encoding - tb_byte_t* data = tb_null; - tb_size_t encoding = XM_IO_FILE_ENCODING_BINARY; - tb_long_t size = tb_stream_peek(stream, &data, CHECK_SIZE); - if (size > 0) - { - tb_byte_t const* p = data; - encoding = xm_io_file_detect_charset(&p, size); - *pbomoff = p - data; + tb_byte_t *data = tb_null; + tb_size_t encoding = XM_IO_FILE_ENCODING_BINARY; + tb_long_t size = tb_stream_peek(stream, &data, CHECK_SIZE); + if (size > 0) { + tb_byte_t const *p = data; + encoding = xm_io_file_detect_charset(&p, size); + *pbomoff = p - data; } return encoding; } @@ -173,29 +162,34 @@ static tb_size_t xm_io_file_detect_encoding(tb_stream_ref_t stream, tb_long_t* p */ // io.file_open(path, modestr) -tb_int_t xm_io_file_open(lua_State* lua) -{ +tb_int_t xm_io_file_open(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get file path and mode - tb_char_t const* path = luaL_checkstring(lua, 1); - tb_char_t const* modestr = luaL_optstring(lua, 2, "r"); + tb_char_t const *path = luaL_checkstring(lua, 1); + tb_char_t const *modestr = luaL_optstring(lua, 2, "r"); tb_assert_and_check_return_val(path && modestr, 0); // get file mode value tb_size_t mode; - switch (modestr[0]) - { - case 'w': mode = TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC; break; - case 'a': mode = TB_FILE_MODE_RW | TB_FILE_MODE_APPEND | TB_FILE_MODE_CREAT; break; - case 'r': default: mode = TB_FILE_MODE_RO; break; + switch (modestr[0]) { + case 'w': + mode = TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC; + break; + case 'a': + mode = TB_FILE_MODE_RW | TB_FILE_MODE_APPEND | TB_FILE_MODE_CREAT; + break; + case 'r': + default: + mode = TB_FILE_MODE_RO; + break; } // get file encoding - tb_long_t bomoff = 0; - tb_stream_ref_t stream = tb_null; - tb_bool_t update = !!tb_strchr(modestr, '+'); + tb_long_t bomoff = 0; + tb_stream_ref_t stream = tb_null; + tb_bool_t update = !!tb_strchr(modestr, '+'); tb_size_t encoding = XM_IO_FILE_ENCODING_UNKNOWN; if (modestr[1] == 'b' || (update && modestr[2] == 'b')) encoding = XM_IO_FILE_ENCODING_BINARY; @@ -222,13 +216,13 @@ tb_int_t xm_io_file_open(lua_State* lua) stream = tb_stream_init_from_file(path, mode); if (stream && tb_stream_open(stream)) encoding = xm_io_file_detect_encoding(stream, &bomoff); - else - { - if (stream) tb_stream_exit(stream); + else { + if (stream) + tb_stream_exit(stream); xm_io_return_error(lua, "file not found!"); } - } - else xm_io_return_error(lua, "invalid open mode!"); + } else + xm_io_return_error(lua, "invalid open mode!"); tb_assert_and_check_return_val(encoding != XM_IO_FILE_ENCODING_UNKNOWN, 0); // write data with utf bom? e.g. utf8bom, utf16lebom, utf16bom @@ -237,19 +231,17 @@ tb_int_t xm_io_file_open(lua_State* lua) utfbom = tb_true; // open file - tb_bool_t open_ok = tb_false; + tb_bool_t open_ok = tb_false; tb_stream_ref_t file_ref = tb_null; - tb_stream_ref_t fstream = tb_null; - do - { + tb_stream_ref_t fstream = tb_null; + do { // init stream from file - stream = stream? stream : tb_stream_init_from_file(path, mode); + stream = stream ? stream : tb_stream_init_from_file(path, mode); tb_assert_and_check_break(stream); // is transcode? tb_bool_t is_transcode = encoding != TB_CHARSET_TYPE_UTF8 && encoding != XM_IO_FILE_ENCODING_BINARY; - if (is_transcode) - { + if (is_transcode) { if (modestr[0] == 'r') fstream = tb_stream_init_filter_from_charset(stream, encoding, TB_CHARSET_TYPE_UTF8); else @@ -258,14 +250,16 @@ tb_int_t xm_io_file_open(lua_State* lua) // use fstream as file file_ref = fstream; - } - else file_ref = stream; + } else + file_ref = stream; // open file stream - if (!tb_stream_open(file_ref)) break; + if (!tb_stream_open(file_ref)) + break; // skip bom characters if exists - if (bomoff > 0 && !tb_stream_seek(stream, bomoff)) break; + if (bomoff > 0 && !tb_stream_seek(stream, bomoff)) + break; // ok open_ok = tb_true; @@ -273,14 +267,15 @@ tb_int_t xm_io_file_open(lua_State* lua) } while (0); // open failed? - if (!open_ok) - { + if (!open_ok) { // exit stream - if (stream) tb_stream_exit(stream); + if (stream) + tb_stream_exit(stream); stream = tb_null; // exit charset stream filter - if (fstream) tb_stream_exit(fstream); + if (fstream) + tb_stream_exit(fstream); fstream = tb_null; // return errors @@ -288,7 +283,7 @@ tb_int_t xm_io_file_open(lua_State* lua) } // make file - xm_io_file_t* file = (xm_io_file_t*)lua_newuserdata(lua, sizeof(xm_io_file_t)); + xm_io_file_t *file = (xm_io_file_t *)lua_newuserdata(lua, sizeof(xm_io_file_t)); tb_assert_and_check_return_val(file, 0); // init file diff --git a/core/src/xmake/io/file_rawfd.c b/core/src/xmake/io/file_rawfd.c index 9e2383e0a..f4dc3ffee 100644 --- a/core/src/xmake/io/file_rawfd.c +++ b/core/src/xmake/io/file_rawfd.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_rawfd" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_rawfd" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,9 +36,9 @@ // file to fd #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) -# define xm_io_file2fd(file) (lua_Number)((tb_size_t)(file)) +#define xm_io_file2fd(file) (lua_Number)((tb_size_t)(file)) #else -# define xm_io_file2fd(file) (lua_Number)tb_file2fd(file) +#define xm_io_file2fd(file) (lua_Number) tb_file2fd(file) #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -51,8 +51,7 @@ * * e.g. set VS_UNICODE_OUTPUT=fd to enable vs unicode output, @see https://github.com/xmake-io/xmake/issues/528 */ -tb_int_t xm_io_file_rawfd(lua_State* lua) -{ +tb_int_t xm_io_file_rawfd(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -61,15 +60,13 @@ tb_int_t xm_io_file_rawfd(lua_State* lua) xm_io_return_error(lua, "get rawfd for invalid file!"); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 1); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); tb_check_return_val(file, 0); // get file raw fd - if (xm_io_file_is_file(file)) - { + if (xm_io_file_is_file(file)) { tb_file_ref_t rawfile = tb_null; - if (tb_stream_ctrl(file->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile)) - { + if (tb_stream_ctrl(file->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile)) { lua_pushnumber(lua, xm_io_file2fd(rawfile)); return 1; } diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c index 1c3af6dfe..2f349edb5 100644 --- a/core/src/xmake/io/file_read.c +++ b/core/src/xmake/io/file_read.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_read" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_read" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,58 +33,47 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -typedef enum __xm_pushline_state_e -{ +typedef enum __xm_pushline_state_e { PL_EOF, PL_FIN, PL_CONL, PL_FAIL, - } xm_pushline_state_e; /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_ref_t line) -{ +static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_ref_t line) { // check tb_assert_and_check_return_val(stream && line, -1); // read line and reserve crlf - tb_bool_t eof = tb_false; - tb_hize_t offset = 0; - tb_byte_t* data = tb_null; - tb_hong_t size = tb_stream_size(stream); - while (size < 0 || (offset = tb_stream_offset(stream)) < size) - { + tb_bool_t eof = tb_false; + tb_hize_t offset = 0; + tb_byte_t *data = tb_null; + tb_hong_t size = tb_stream_size(stream); + while (size < 0 || (offset = tb_stream_offset(stream)) < size) { tb_long_t real = tb_stream_peek(stream, &data, XM_IO_BLOCK_MAXN); - if (real > 0) - { - tb_char_t const* e = tb_strnchr((tb_char_t const*)data, real, '\n'); - if (e) - { - tb_size_t n = (tb_byte_t const*)e + 1 - data; - if (!tb_stream_skip(stream, n)) return -1; + if (real > 0) { + tb_char_t const *e = tb_strnchr((tb_char_t const *)data, real, '\n'); + if (e) { + tb_size_t n = (tb_byte_t const *)e + 1 - data; + if (!tb_stream_skip(stream, n)) + return -1; tb_buffer_memncat(line, data, n); break; - } - else - { - if (!tb_stream_skip(stream, real)) return -1; + } else { + if (!tb_stream_skip(stream, real)) + return -1; tb_buffer_memncat(line, data, real); } - } - else if (!real) - { + } else if (!real) { real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, -1); - if (real <= 0) - { + if (real <= 0) { eof = tb_true; break; } - } - else - { + } else { eof = tb_true; break; } @@ -92,20 +81,23 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re // ok? tb_size_t linesize = tb_buffer_size(line); - if (linesize) return linesize; - else return (eof || tb_stream_beof(stream))? -1 : 0; + if (linesize) + return linesize; + else + return (eof || tb_stream_beof(stream)) ? -1 : 0; } -static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t* file, tb_char_t const* continuation, tb_bool_t keep_crlf) -{ +static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, + xm_io_file_t *file, + tb_char_t const *continuation, + tb_bool_t keep_crlf) { // check tb_assert(buf && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // is binary? tb_bool_t is_binary = file->encoding == XM_IO_FILE_ENCODING_BINARY; - if (is_binary) - { + if (is_binary) { continuation = ""; - keep_crlf = tb_true; + keep_crlf = tb_true; } // clear line buffer @@ -115,53 +107,52 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t* fi tb_long_t size = xm_io_file_buffer_readline(file->u.file_ref, &file->rcache); // translate line data - tb_int_t result = PL_FAIL; - tb_char_t* data = tb_null; - tb_size_t conlen = tb_strlen(continuation); - do - { + tb_int_t result = PL_FAIL; + tb_char_t *data = tb_null; + tb_size_t conlen = tb_strlen(continuation); + do { // eof? - if (size < 0) - { + if (size < 0) { result = PL_EOF; break; } // patch two '\0' - tb_buffer_memncat(&file->rcache, (tb_byte_t const*)"\0\0", 2); + tb_buffer_memncat(&file->rcache, (tb_byte_t const *)"\0\0", 2); // get line data - data = (tb_char_t*)tb_buffer_data(&file->rcache); + data = (tb_char_t *)tb_buffer_data(&file->rcache); tb_assert_and_check_break(data); // no lf found if (size > 0 && data[size - 1] != '\n') result = PL_FIN; - else if (size > 1) - { + else if (size > 1) { // crlf? => lf - if (!is_binary && data[size - 2] == '\r') - { + if (!is_binary && data[size - 2] == '\r') { data[size - 2] = '\n'; size--; } // has continuation? - tb_bool_t has_conline = conlen && size >= conlen + 1 && tb_strncmp(continuation, (tb_char_t const*)(data + size - conlen - 1), conlen) == 0; + tb_bool_t has_conline = conlen && size >= conlen + 1 && + tb_strncmp(continuation, (tb_char_t const *)(data + size - conlen - 1), conlen) == + 0; // do not keep crlf, strip the last lf - if (!keep_crlf && !has_conline) size--; + if (!keep_crlf && !has_conline) + size--; // strip it if has continuation? - if (has_conline) size -= conlen + 1; + if (has_conline) + size -= conlen + 1; data[size] = '\0'; result = has_conline ? PL_CONL : PL_FIN; - } - else - { + } else { // a single '\n' - if (!keep_crlf) size = 0; + if (!keep_crlf) + size = 0; result = PL_FIN; } @@ -169,13 +160,12 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t* fi // push line data if (data && size > 0 && (result == PL_FIN || result == PL_CONL)) - tb_buffer_memncat(buf, (tb_byte_t const*)data, size); + tb_buffer_memncat(buf, (tb_byte_t const *)data, size); // return result return result; } -static tb_int_t xm_io_file_read_all_directly(lua_State* lua, xm_io_file_t* file) -{ +static tb_int_t xm_io_file_read_all_directly(lua_State *lua, xm_io_file_t *file) { // check tb_assert(lua && file && xm_io_file_is_file(file) && file->u.file_ref); @@ -184,36 +174,33 @@ static tb_int_t xm_io_file_read_all_directly(lua_State* lua, xm_io_file_t* file) if (!tb_buffer_init(&buf)) xm_io_return_error(lua, "init buffer failed!"); - tb_byte_t* data = tb_buffer_resize(&file->rcache, XM_IO_BLOCK_MAXN); - if (!data) - { + tb_byte_t *data = tb_buffer_resize(&file->rcache, XM_IO_BLOCK_MAXN); + if (!data) { tb_buffer_exit(&buf); xm_io_return_error(lua, "out of memory: failed to resize read cache"); } // read all tb_stream_ref_t stream = file->u.file_ref; - while (!tb_stream_beof(stream)) - { + while (!tb_stream_beof(stream)) { tb_long_t real = tb_stream_read(stream, data, XM_IO_BLOCK_MAXN); if (real > 0) tb_buffer_memncat(&buf, data, real); - else if (!real) - { + else if (!real) { real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, -1); tb_check_break(real > 0); - } - else break; + } else + break; } if (tb_buffer_size(&buf)) - lua_pushlstring(lua, (tb_char_t const*)tb_buffer_data(&buf), tb_buffer_size(&buf)); - else lua_pushliteral(lua, ""); + lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); + else + lua_pushliteral(lua, ""); tb_buffer_exit(&buf); return 1; } -static tb_int_t xm_io_file_read_all(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation) -{ +static tb_int_t xm_io_file_read_all(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation) { // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); @@ -229,13 +216,13 @@ static tb_int_t xm_io_file_read_all(lua_State* lua, xm_io_file_t* file, tb_char_ // read all tb_bool_t has_content = tb_false; - while (1) - { - switch (xm_io_file_buffer_pushline(&buf, file, continuation, tb_true)) - { + while (1) { + switch (xm_io_file_buffer_pushline(&buf, file, continuation, tb_true)) { case PL_EOF: - if (!has_content) lua_pushliteral(lua, ""); - else lua_pushlstring(lua, (tb_char_t const*)tb_buffer_data(&buf), tb_buffer_size(&buf)); + if (!has_content) + lua_pushliteral(lua, ""); + else + lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); tb_buffer_exit(&buf); return 1; case PL_FIN: @@ -251,8 +238,10 @@ static tb_int_t xm_io_file_read_all(lua_State* lua, xm_io_file_t* file, tb_char_ } } -static tb_int_t xm_io_file_read_line(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation, tb_bool_t keep_crlf) -{ +static tb_int_t xm_io_file_read_line(lua_State *lua, + xm_io_file_t *file, + tb_char_t const *continuation, + tb_bool_t keep_crlf) { // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); @@ -263,17 +252,17 @@ static tb_int_t xm_io_file_read_line(lua_State* lua, xm_io_file_t* file, tb_char // read line tb_bool_t has_content = tb_false; - while (1) - { - switch (xm_io_file_buffer_pushline(&buf, file, continuation, keep_crlf)) - { + while (1) { + switch (xm_io_file_buffer_pushline(&buf, file, continuation, keep_crlf)) { case PL_EOF: - if (!has_content) lua_pushnil(lua); - else lua_pushlstring(lua, (tb_char_t const*)tb_buffer_data(&buf), tb_buffer_size(&buf)); + if (!has_content) + lua_pushnil(lua); + else + lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); tb_buffer_exit(&buf); return 1; case PL_FIN: - lua_pushlstring(lua, (tb_char_t const*)tb_buffer_data(&buf), tb_buffer_size(&buf)); + lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); tb_buffer_exit(&buf); return 1; case PL_CONL: @@ -288,8 +277,7 @@ static tb_int_t xm_io_file_read_line(lua_State* lua, xm_io_file_t* file, tb_char } } -static tb_int_t xm_io_file_read_n(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation, tb_long_t n) -{ +static tb_int_t xm_io_file_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_long_t n) { // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); @@ -302,33 +290,30 @@ static tb_int_t xm_io_file_read_n(lua_State* lua, xm_io_file_t* file, tb_char_t xm_io_return_error(lua, "read number of bytes only allows binary file, reopen with 'rb' and try again"); tb_bool_t ok = tb_false; - if (n == 0) - { - tb_byte_t* data = tb_null; - if (tb_stream_need(file->u.file_ref, &data, 1)) - { + if (n == 0) { + tb_byte_t *data = tb_null; + if (tb_stream_need(file->u.file_ref, &data, 1)) { lua_pushliteral(lua, ""); ok = tb_true; } - } - else - { - tb_byte_t* bufptr = tb_buffer_resize(&file->rcache, n + 1); - if (bufptr) - { - if (tb_stream_bread(file->u.file_ref, bufptr, n)) - { - lua_pushlstring(lua, (tb_char_t const*)bufptr, n); + } else { + tb_byte_t *bufptr = tb_buffer_resize(&file->rcache, n + 1); + if (bufptr) { + if (tb_stream_bread(file->u.file_ref, bufptr, n)) { + lua_pushlstring(lua, (tb_char_t const *)bufptr, n); ok = tb_true; } } } - if (!ok) lua_pushnil(lua); + if (!ok) + lua_pushnil(lua); return 1; } -static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t* file, tb_char_t const* continuation, tb_bool_t keep_crlf) -{ +static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, + xm_io_file_t *file, + tb_char_t const *continuation, + tb_bool_t keep_crlf) { // check tb_assert(buf && file && continuation && xm_io_file_is_std(file)); @@ -338,49 +323,50 @@ static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_ tb_size_t result = PL_FAIL; if (tb_stdfile_gets(file->u.std_ref, strbuf, tb_arrayn(strbuf) - 1)) buflen = tb_strlen(strbuf); - else return PL_EOF; + else + return PL_EOF; tb_size_t conlen = tb_strlen(continuation); - if (buflen > 0 && strbuf[buflen - 1] != '\n') - { + if (buflen > 0 && strbuf[buflen - 1] != '\n') { // end of file, no lf found result = PL_FIN; - } - else if (buflen > 1) - { + } else if (buflen > 1) { // crlf? => lf - if (strbuf[buflen - 2] == '\r') - { + if (strbuf[buflen - 2] == '\r') { strbuf[buflen - 2] = '\n'; buflen--; } // has continuation? - tb_bool_t has_conline = conlen && buflen >= conlen + 1 && tb_strncmp(continuation, (strbuf + buflen - conlen - 1), conlen) == 0; + tb_bool_t has_conline = conlen && buflen >= conlen + 1 && + tb_strncmp(continuation, (strbuf + buflen - conlen - 1), conlen) == 0; // do not keep crlf, strip the last lf - if (!keep_crlf && !has_conline) buflen--; + if (!keep_crlf && !has_conline) + buflen--; // strip it if has continuation? - if (has_conline) buflen -= conlen + 1; - strbuf[buflen] = '\0'; + if (has_conline) + buflen -= conlen + 1; + strbuf[buflen] = '\0'; - result = has_conline? PL_CONL : PL_FIN; - } - else - { + result = has_conline ? PL_CONL : PL_FIN; + } else { // a single '\n' - if (!keep_crlf) buflen = 0; + if (!keep_crlf) + buflen = 0; result = PL_FIN; } if (result == PL_FIN || result == PL_CONL) - tb_buffer_memncat(buf, (tb_byte_t const*)strbuf, buflen); + tb_buffer_memncat(buf, (tb_byte_t const *)strbuf, buflen); return result; } -static tb_int_t xm_io_file_std_read_line(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation, tb_bool_t keep_crlf) -{ +static tb_int_t xm_io_file_std_read_line(lua_State *lua, + xm_io_file_t *file, + tb_char_t const *continuation, + tb_bool_t keep_crlf) { // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); @@ -391,17 +377,17 @@ static tb_int_t xm_io_file_std_read_line(lua_State* lua, xm_io_file_t* file, tb_ // read line tb_bool_t has_content = tb_false; - while (1) - { - switch (xm_io_file_std_buffer_pushline(&buf, file, continuation, keep_crlf)) - { + while (1) { + switch (xm_io_file_std_buffer_pushline(&buf, file, continuation, keep_crlf)) { case PL_EOF: - if (!has_content) lua_pushnil(lua); - else lua_pushlstring(lua, (tb_char_t const*)tb_buffer_data(&buf), tb_buffer_size(&buf)); + if (!has_content) + lua_pushnil(lua); + else + lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); tb_buffer_exit(&buf); return 1; case PL_FIN: - lua_pushlstring(lua, (tb_char_t const*)tb_buffer_data(&buf), tb_buffer_size(&buf)); + lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); tb_buffer_exit(&buf); return 1; case PL_CONL: @@ -416,8 +402,7 @@ static tb_int_t xm_io_file_std_read_line(lua_State* lua, xm_io_file_t* file, tb_ } } -static tb_int_t xm_io_file_std_read_all(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation) -{ +static tb_int_t xm_io_file_std_read_all(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation) { // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); @@ -428,13 +413,13 @@ static tb_int_t xm_io_file_std_read_all(lua_State* lua, xm_io_file_t* file, tb_c // read all tb_bool_t has_content = tb_false; - while (1) - { - switch (xm_io_file_std_buffer_pushline(&buf, file, continuation, tb_true)) - { + while (1) { + switch (xm_io_file_std_buffer_pushline(&buf, file, continuation, tb_true)) { case PL_EOF: - if (!has_content) lua_pushliteral(lua, ""); - else lua_pushlstring(lua, (tb_char_t const*)tb_buffer_data(&buf), tb_buffer_size(&buf)); + if (!has_content) + lua_pushliteral(lua, ""); + else + lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); tb_buffer_exit(&buf); return 1; case PL_FIN: @@ -450,8 +435,7 @@ static tb_int_t xm_io_file_std_read_all(lua_State* lua, xm_io_file_t* file, tb_c } } -static tb_int_t xm_io_file_std_read_n(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation, tb_long_t n) -{ +static tb_int_t xm_io_file_std_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_long_t n) { // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); @@ -460,8 +444,7 @@ static tb_int_t xm_io_file_std_read_n(lua_State* lua, xm_io_file_t* file, tb_cha xm_io_return_error(lua, "continuation is not supported for std streams"); // io.read(0) - if (n == 0) - { + if (n == 0) { tb_char_t ch; if (!tb_stdfile_peek(file->u.std_ref, &ch)) lua_pushnil(lua); @@ -471,18 +454,18 @@ static tb_int_t xm_io_file_std_read_n(lua_State* lua, xm_io_file_t* file, tb_cha } // get line buffer - tb_byte_t* buf_ptr = tb_buffer_resize(&file->rcache, (tb_size_t)n); + tb_byte_t *buf_ptr = tb_buffer_resize(&file->rcache, (tb_size_t)n); tb_assert(buf_ptr); // io.read(n) if (tb_stdfile_read(file->u.std_ref, buf_ptr, (tb_size_t)n)) - lua_pushlstring(lua, (tb_char_t const*)buf_ptr, (size_t)n); - else lua_pushnil(lua); + lua_pushlstring(lua, (tb_char_t const *)buf_ptr, (size_t)n); + else + lua_pushnil(lua); return 1; } -static tb_int_t xm_io_file_std_read_num(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation) -{ +static tb_int_t xm_io_file_std_read_num(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation) { // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); @@ -494,7 +477,8 @@ static tb_int_t xm_io_file_std_read_num(lua_State* lua, xm_io_file_t* file, tb_c tb_char_t strbuf[512]; if (tb_stdfile_gets(file->u.std_ref, strbuf, tb_arrayn(strbuf))) lua_pushnumber(lua, tb_s10tod(strbuf)); // TODO check invalid float number string and push nil - else lua_pushnil(lua); + else + lua_pushnil(lua); return 1; } @@ -505,8 +489,7 @@ static tb_int_t xm_io_file_std_read_num(lua_State* lua, xm_io_file_t* file, tb_c * io.file_read(file, "n") * io.file_read(file, 10) */ -tb_int_t xm_io_file_read(lua_State* lua) -{ +tb_int_t xm_io_file_read(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -515,46 +498,50 @@ tb_int_t xm_io_file_read(lua_State* lua) xm_io_return_error(lua, "read(invalid file)!"); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 1); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); tb_check_return_val(file, 0); // get arguments - tb_char_t const* mode = luaL_optstring(lua, 2, "l"); - tb_char_t const* continuation = luaL_optstring(lua, 3, ""); + tb_char_t const *mode = luaL_optstring(lua, 2, "l"); + tb_char_t const *continuation = luaL_optstring(lua, 3, ""); tb_assert_and_check_return_val(mode && continuation, 0); tb_long_t count = -1; - if (lua_isnumber(lua, 2)) - { + if (lua_isnumber(lua, 2)) { count = (tb_long_t)lua_tointeger(lua, 2); - if (count < 0) xm_io_return_error(lua, "invalid read size, must be positive nubmber or 0"); - } - else if (*mode == '*') + if (count < 0) + xm_io_return_error(lua, "invalid read size, must be positive nubmber or 0"); + } else if (*mode == '*') mode++; - if (xm_io_file_is_file(file)) - { - if (count >= 0) return xm_io_file_read_n(lua, file, continuation, count); - switch (*mode) - { - case 'a': return xm_io_file_read_all(lua, file, continuation); - case 'L': return xm_io_file_read_line(lua, file, continuation, tb_true); - case 'n': xm_io_return_error(lua, "read number is not implemented"); - case 'l': return xm_io_file_read_line(lua, file, continuation, tb_false); + if (xm_io_file_is_file(file)) { + if (count >= 0) + return xm_io_file_read_n(lua, file, continuation, count); + switch (*mode) { + case 'a': + return xm_io_file_read_all(lua, file, continuation); + case 'L': + return xm_io_file_read_line(lua, file, continuation, tb_true); + case 'n': + xm_io_return_error(lua, "read number is not implemented"); + case 'l': + return xm_io_file_read_line(lua, file, continuation, tb_false); default: xm_io_return_error(lua, "unknonwn read mode"); return 0; } - } - else - { - if (count >= 0) return xm_io_file_std_read_n(lua, file, continuation, count); - switch (*mode) - { - case 'a': return xm_io_file_std_read_all(lua, file, continuation); - case 'L': return xm_io_file_std_read_line(lua, file, continuation, tb_true); - case 'n': return xm_io_file_std_read_num(lua, file, continuation); - case 'l': return xm_io_file_std_read_line(lua, file, continuation, tb_false); + } else { + if (count >= 0) + return xm_io_file_std_read_n(lua, file, continuation, count); + switch (*mode) { + case 'a': + return xm_io_file_std_read_all(lua, file, continuation); + case 'L': + return xm_io_file_std_read_line(lua, file, continuation, tb_true); + case 'n': + return xm_io_file_std_read_num(lua, file, continuation); + case 'l': + return xm_io_file_std_read_line(lua, file, continuation, tb_false); default: xm_io_return_error(lua, "unknonwn read mode"); return 0; diff --git a/core/src/xmake/io/file_readable.c b/core/src/xmake/io/file_readable.c index edfe496d0..e3cca2dc9 100644 --- a/core/src/xmake/io/file_readable.c +++ b/core/src/xmake/io/file_readable.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_readable" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_readable" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,8 +34,7 @@ * implementation */ -tb_int_t xm_io_file_readable(lua_State* lua) -{ +tb_int_t xm_io_file_readable(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -44,13 +43,15 @@ tb_int_t xm_io_file_readable(lua_State* lua) xm_io_return_error(lua, "read(invalid file)!"); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 1); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); tb_check_return_val(file, 0); // has readable data? tb_bool_t ok = tb_false; - if (xm_io_file_is_file(file)) ok = tb_stream_left(file->u.file_ref) > 0; - else ok = tb_stdfile_readable(file->u.std_ref); + if (xm_io_file_is_file(file)) + ok = tb_stream_left(file->u.file_ref) > 0; + else + ok = tb_stdfile_readable(file->u.std_ref); lua_pushboolean(lua, ok); return 1; } diff --git a/core/src/xmake/io/file_seek.c b/core/src/xmake/io/file_seek.c index a0ace5408..ea053302b 100644 --- a/core/src/xmake/io/file_seek.c +++ b/core/src/xmake/io/file_seek.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_seek" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_seek" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.file_seek(file, [whence [, offset]]) -tb_int_t xm_io_file_seek(lua_State* lua) -{ +tb_int_t xm_io_file_seek(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -45,41 +44,38 @@ tb_int_t xm_io_file_seek(lua_State* lua) xm_io_return_error(lua, "seek(invalid file)!"); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 1); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); tb_check_return_val(file, 0); // get whence and offset - tb_char_t const* whence = luaL_optstring(lua, 2, "cur"); + tb_char_t const *whence = luaL_optstring(lua, 2, "cur"); tb_hong_t offset = (tb_hong_t)luaL_optnumber(lua, 3, 0); tb_assert_and_check_return_val(whence, 0); // seek file - if (xm_io_file_is_file(file)) - { + if (xm_io_file_is_file(file)) { tb_assert(file->u.file_ref); - switch (*whence) - { + switch (*whence) { case 's': // "set" break; case 'e': // "end" - { - tb_hong_t size = tb_stream_size(file->u.file_ref); - if (size > 0 && size + offset <= size) - offset = size + offset; - else xm_io_return_error(lua, "seek failed, invalid offset!"); - } - break; - default: // "cur" + { + tb_hong_t size = tb_stream_size(file->u.file_ref); + if (size > 0 && size + offset <= size) + offset = size + offset; + else + xm_io_return_error(lua, "seek failed, invalid offset!"); + } break; + default: // "cur" offset = tb_stream_offset(file->u.file_ref) + offset; break; } - if (tb_stream_seek(file->u.file_ref, offset)) - { + if (tb_stream_seek(file->u.file_ref, offset)) { lua_pushnumber(lua, (lua_Number)offset); return 1; - } - else xm_io_return_error(lua, "seek failed!"); - } - else xm_io_return_error(lua, "seek is not supported on this file"); + } else + xm_io_return_error(lua, "seek failed!"); + } else + xm_io_return_error(lua, "seek is not supported on this file"); } diff --git a/core/src/xmake/io/file_size.c b/core/src/xmake/io/file_size.c index 39c556896..df83a96b9 100644 --- a/core/src/xmake/io/file_size.c +++ b/core/src/xmake/io/file_size.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_size" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_size" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.file_size(file) -tb_int_t xm_io_file_size(lua_State* lua) -{ +tb_int_t xm_io_file_size(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -45,16 +44,15 @@ tb_int_t xm_io_file_size(lua_State* lua) xm_io_return_error(lua, "get size for invalid file!"); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 1); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); tb_check_return_val(file, 0); // get file length - if (xm_io_file_is_file(file)) - { + if (xm_io_file_is_file(file)) { // get size from raw file stream, because we cannot get size from fstream tb_assert(file->stream); lua_pushnumber(lua, (lua_Number)tb_stream_size(file->stream)); return 1; - } - else xm_io_return_error(lua, "get size for invalid file!"); + } else + xm_io_return_error(lua, "get size for invalid file!"); } diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c index b04303f62..bfe7321f3 100644 --- a/core/src/xmake/io/file_write.c +++ b/core/src/xmake/io/file_write.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "file_write" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "file_write" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,83 +33,69 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t xm_io_file_write_file_utfbom(xm_io_file_t* file) -{ +static tb_void_t xm_io_file_write_file_utfbom(xm_io_file_t *file) { // check tb_assert(file && xm_io_file_is_file(file) && file->u.file_ref); // write bom - switch (file->encoding) - { - case TB_CHARSET_TYPE_UTF8: - { - static tb_byte_t bom[] = {0xef, 0xbb, 0xbf}; - tb_stream_bwrit(file->u.file_ref, bom, sizeof(bom)); - } - break; - case TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_LE: - { - static tb_byte_t bom[] = {0xff, 0xfe}; - tb_stream_bwrit(file->u.file_ref, bom, sizeof(bom)); - } - break; - case TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_BE: - { - static tb_byte_t bom[] = {0xfe, 0xff}; - tb_stream_bwrit(file->u.file_ref, bom, sizeof(bom)); - } - break; + switch (file->encoding) { + case TB_CHARSET_TYPE_UTF8: { + static tb_byte_t bom[] = { 0xef, 0xbb, 0xbf }; + tb_stream_bwrit(file->u.file_ref, bom, sizeof(bom)); + } break; + case TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_LE: { + static tb_byte_t bom[] = { 0xff, 0xfe }; + tb_stream_bwrit(file->u.file_ref, bom, sizeof(bom)); + } break; + case TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_BE: { + static tb_byte_t bom[] = { 0xfe, 0xff }; + tb_stream_bwrit(file->u.file_ref, bom, sizeof(bom)); + } break; default: break; } } -static tb_void_t xm_io_file_write_file_directly(xm_io_file_t* file, tb_byte_t const* data, tb_size_t size) -{ +static tb_void_t xm_io_file_write_file_directly(xm_io_file_t *file, tb_byte_t const *data, tb_size_t size) { tb_assert(file && data && xm_io_file_is_file(file) && file->u.file_ref); tb_stream_bwrit(file->u.file_ref, data, size); } -static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t* file, tb_byte_t const* data, tb_size_t size) -{ +static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t *file, tb_byte_t const *data, tb_size_t size) { // check tb_assert(file && data && xm_io_file_is_file(file) && file->u.file_ref); #ifdef TB_CONFIG_OS_WINDOWS // write cached data first - tb_byte_t const* odata = tb_buffer_data(&file->wcache); + tb_byte_t const *odata = tb_buffer_data(&file->wcache); tb_size_t osize = tb_buffer_size(&file->wcache); - if (odata && osize) - { - if (!tb_stream_bwrit(file->u.file_ref, odata, osize)) return ; + if (odata && osize) { + if (!tb_stream_bwrit(file->u.file_ref, odata, osize)) + return; tb_buffer_clear(&file->wcache); } // write data by lines - tb_char_t const* p = (tb_char_t const*)data; - tb_char_t const* e = p + size; - tb_char_t const* lf = tb_null; - while (p < e) - { + tb_char_t const *p = (tb_char_t const *)data; + tb_char_t const *e = p + size; + tb_char_t const *lf = tb_null; + while (p < e) { lf = tb_strnchr(p, e - p, '\n'); - if (lf) - { - if (lf > p && lf[-1] == '\r') - { - if (!tb_stream_bwrit(file->u.file_ref, (tb_byte_t const*)p, lf + 1 - p)) break; - } - else - { - if (lf > p && !tb_stream_bwrit(file->u.file_ref, (tb_byte_t const*)p, lf - p)) break; - if (!tb_stream_bwrit(file->u.file_ref, (tb_byte_t const*)"\r\n", 2)) break; + if (lf) { + if (lf > p && lf[-1] == '\r') { + if (!tb_stream_bwrit(file->u.file_ref, (tb_byte_t const *)p, lf + 1 - p)) + break; + } else { + if (lf > p && !tb_stream_bwrit(file->u.file_ref, (tb_byte_t const *)p, lf - p)) + break; + if (!tb_stream_bwrit(file->u.file_ref, (tb_byte_t const *)"\r\n", 2)) + break; } // next line p = lf + 1; - } - else - { + } else { // cache the left data - tb_buffer_memncat(&file->wcache, (tb_byte_t const*)p, e - p); + tb_buffer_memncat(&file->wcache, (tb_byte_t const *)p, e - p); p = e; break; } @@ -118,8 +104,7 @@ static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t* file, tb_byte_t c return xm_io_file_write_file_directly(file, data, size); #endif } -static tb_void_t xm_io_file_write_std(xm_io_file_t* file, tb_byte_t const* data, tb_size_t size) -{ +static tb_void_t xm_io_file_write_std(xm_io_file_t *file, tb_byte_t const *data, tb_size_t size) { // check tb_assert(file && data && xm_io_file_is_std(file)); @@ -136,8 +121,7 @@ static tb_void_t xm_io_file_write_std(xm_io_file_t* file, tb_byte_t const* data, */ // io.file_write(file, ...) -tb_int_t xm_io_file_write(lua_State* lua) -{ +tb_int_t xm_io_file_write(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -146,28 +130,25 @@ tb_int_t xm_io_file_write(lua_State* lua) xm_io_return_error(lua, "write(invalid file)!"); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 1); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); tb_check_return_val(file, 0); // write file data tb_int_t narg = lua_gettop(lua); - if (narg > 1) - { + if (narg > 1) { tb_bool_t is_binary = file->encoding == XM_IO_FILE_ENCODING_BINARY; - for (tb_int_t i = 2; i <= narg; i++) - { + for (tb_int_t i = 2; i <= narg; i++) { // get data - size_t datasize = 0; - tb_byte_t const* data = tb_null; + size_t datasize = 0; + tb_byte_t const *data = tb_null; if (lua_isstring(lua, i)) - data = (tb_byte_t const*)luaL_checklstring(lua, i, &datasize); - else if (lua_istable(lua, i)) - { + data = (tb_byte_t const *)luaL_checklstring(lua, i, &datasize); + else if (lua_istable(lua, i)) { // get bytes data lua_pushstring(lua, "data"); lua_gettable(lua, i); if (xm_lua_isinteger(lua, -1)) - data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, -1); + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, -1); lua_pop(lua, 1); tb_assert_static(sizeof(lua_Integer) >= sizeof(tb_pointer_t)); @@ -189,11 +170,9 @@ tb_int_t xm_io_file_write(lua_State* lua) xm_io_file_write_std(file, data, (tb_size_t)datasize); else if (is_binary) xm_io_file_write_file_directly(file, data, (tb_size_t)datasize); - else - { + else { // write utf bom first? - if (file->utfbom) - { + if (file->utfbom) { xm_io_file_write_file_utfbom(file); file->utfbom = tb_false; } diff --git a/core/src/xmake/io/filelock_close.c b/core/src/xmake/io/filelock_close.c index 9e73e8d01..ad628cb5c 100644 --- a/core/src/xmake/io/filelock_close.c +++ b/core/src/xmake/io/filelock_close.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "filelock_close" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "filelock_close" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.filelock_close(lock) -tb_int_t xm_io_filelock_close(lua_State* lua) -{ +tb_int_t xm_io_filelock_close(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -57,4 +56,3 @@ tb_int_t xm_io_filelock_close(lua_State* lua) // ok return 1; } - diff --git a/core/src/xmake/io/filelock_lock.c b/core/src/xmake/io/filelock_lock.c index 00fea1415..109bb6dcd 100644 --- a/core/src/xmake/io/filelock_lock.c +++ b/core/src/xmake/io/filelock_lock.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "filelock_lock" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "filelock_lock" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -39,15 +39,13 @@ * exclusive lock: io.filelock_lock(lock, "/xxxx/filelock") * shared lock: io.filelock_lock(lock, "/xxxx/filelock", {shared = true}) */ -tb_int_t xm_io_filelock_lock(lua_State* lua) -{ +tb_int_t xm_io_filelock_lock(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get option argument tb_bool_t is_shared = tb_false; - if (lua_istable(lua, 2)) - { + if (lua_istable(lua, 2)) { // is shared lock? lua_pushstring(lua, "shared"); lua_gettable(lua, 2); @@ -64,7 +62,7 @@ tb_int_t xm_io_filelock_lock(lua_State* lua) tb_check_return_val(lock, 0); // lock it - tb_bool_t ok = tb_filelock_enter(lock, is_shared? TB_FILELOCK_MODE_SH : TB_FILELOCK_MODE_EX); + tb_bool_t ok = tb_filelock_enter(lock, is_shared ? TB_FILELOCK_MODE_SH : TB_FILELOCK_MODE_EX); lua_pushboolean(lua, ok); return 1; } diff --git a/core/src/xmake/io/filelock_open.c b/core/src/xmake/io/filelock_open.c index bd00aaf47..171c6c86a 100644 --- a/core/src/xmake/io/filelock_open.c +++ b/core/src/xmake/io/filelock_open.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "filelock_open" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "filelock_open" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -37,21 +37,24 @@ /* * io.filelock_open(path) */ -tb_int_t xm_io_filelock_open(lua_State* lua) -{ +tb_int_t xm_io_filelock_open(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get file path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_assert_and_check_return_val(path, 0); // init file lock - tb_long_t tryn = 2; + tb_long_t tryn = 2; tb_filelock_ref_t lock = tb_null; while (!lock && tryn-- > 0) - lock = tb_filelock_init_from_path(path, tb_file_info(path, tb_null)? TB_FILE_MODE_RW : TB_FILE_MODE_RW | TB_FILE_MODE_CREAT); - if (lock) xm_lua_pushpointer(lua, (tb_pointer_t)lock); - else lua_pushnil(lua); + lock = tb_filelock_init_from_path(path, + tb_file_info(path, tb_null) ? TB_FILE_MODE_RW + : TB_FILE_MODE_RW | TB_FILE_MODE_CREAT); + if (lock) + xm_lua_pushpointer(lua, (tb_pointer_t)lock); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/io/filelock_trylock.c b/core/src/xmake/io/filelock_trylock.c index 741d33744..d1a204d30 100644 --- a/core/src/xmake/io/filelock_trylock.c +++ b/core/src/xmake/io/filelock_trylock.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "filelock_trylock" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "filelock_trylock" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -39,15 +39,13 @@ * exclusive lock: io.filelock_trylock("/xxxx/filelock") * shared lock: io.filelock_trylock("/xxxx/filelock", {shared = true}) */ -tb_int_t xm_io_filelock_trylock(lua_State* lua) -{ +tb_int_t xm_io_filelock_trylock(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get option argument tb_bool_t is_shared = tb_false; - if (lua_istable(lua, 2)) - { + if (lua_istable(lua, 2)) { // is shared lock? lua_pushstring(lua, "shared"); lua_gettable(lua, 2); @@ -64,7 +62,7 @@ tb_int_t xm_io_filelock_trylock(lua_State* lua) tb_check_return_val(lock, 0); // try to lock it - tb_bool_t ok = tb_filelock_enter_try(lock, is_shared? TB_FILELOCK_MODE_SH : TB_FILELOCK_MODE_EX); + tb_bool_t ok = tb_filelock_enter_try(lock, is_shared ? TB_FILELOCK_MODE_SH : TB_FILELOCK_MODE_EX); lua_pushboolean(lua, ok); return 1; } diff --git a/core/src/xmake/io/filelock_unlock.c b/core/src/xmake/io/filelock_unlock.c index 62726e106..0eaa2bc98 100644 --- a/core/src/xmake/io/filelock_unlock.c +++ b/core/src/xmake/io/filelock_unlock.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "filelock_unlock" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "filelock_unlock" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.filelock_unlock(lock) -tb_int_t xm_io_filelock_unlock(lua_State* lua) -{ +tb_int_t xm_io_filelock_unlock(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); diff --git a/core/src/xmake/io/iscygpty.c b/core/src/xmake/io/iscygpty.c index 49850e25c..e78a9d8cb 100644 --- a/core/src/xmake/io/iscygpty.c +++ b/core/src/xmake/io/iscygpty.c @@ -36,82 +36,74 @@ #ifdef USE_FILEEXTD /* VC 7.1 or earlier doesn't support SAL. */ -# if !defined(_MSC_VER) || (_MSC_VER < 1400) -# define __out -# define __in -# define __in_opt -# endif +#if !defined(_MSC_VER) || (_MSC_VER < 1400) +#define __out +#define __in +#define __in_opt +#endif /* Win32 FileID API Library: * http://www.microsoft.com/en-us/download/details.aspx?id=22599 * Needed for WinXP. */ -# include +#include #else /* USE_FILEEXTD */ /* VC 8 or earlier. */ -# if defined(_MSC_VER) && (_MSC_VER < 1500) -# ifdef ENABLE_STUB_IMPL -# define STUB_IMPL -# else -# error "Win32 FileID API Library is required for VC2005 or earlier." -# endif -# endif +#if defined(_MSC_VER) && (_MSC_VER < 1500) +#ifdef ENABLE_STUB_IMPL +#define STUB_IMPL +#else +#error "Win32 FileID API Library is required for VC2005 or earlier." +#endif +#endif #endif /* USE_FILEEXTD */ #if _WIN32_WINNT >= 0x0600 -# define USE_DYNFILEID // we need to enable it for supporting xp +#define USE_DYNFILEID // we need to enable it for supporting xp #endif #ifdef USE_DYNFILEID -typedef BOOL (WINAPI *pfnGetFileInformationByHandleEx)( - HANDLE hFile, - FILE_INFO_BY_HANDLE_CLASS FileInformationClass, - LPVOID lpFileInformation, - DWORD dwBufferSize); +typedef BOOL(WINAPI *pfnGetFileInformationByHandleEx)(HANDLE hFile, + FILE_INFO_BY_HANDLE_CLASS FileInformationClass, + LPVOID lpFileInformation, + DWORD dwBufferSize); static pfnGetFileInformationByHandleEx pGetFileInformationByHandleEx = NULL; -# ifndef USE_FILEEXTD -static BOOL WINAPI stub_GetFileInformationByHandleEx( - HANDLE hFile, - FILE_INFO_BY_HANDLE_CLASS FileInformationClass, - LPVOID lpFileInformation, - DWORD dwBufferSize) -{ +#ifndef USE_FILEEXTD +static BOOL WINAPI stub_GetFileInformationByHandleEx(HANDLE hFile, + FILE_INFO_BY_HANDLE_CLASS FileInformationClass, + LPVOID lpFileInformation, + DWORD dwBufferSize) { return FALSE; } -# endif +#endif -static void setup_fileid_api(void) -{ +static void setup_fileid_api(void) { if (pGetFileInformationByHandleEx != NULL) { return; } pGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx) - GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), - "GetFileInformationByHandleEx"); + GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetFileInformationByHandleEx"); if (pGetFileInformationByHandleEx == NULL) { -# ifdef USE_FILEEXTD +#ifdef USE_FILEEXTD pGetFileInformationByHandleEx = GetFileInformationByHandleEx; -# else +#else pGetFileInformationByHandleEx = stub_GetFileInformationByHandleEx; -# endif +#endif } } #else -# define pGetFileInformationByHandleEx GetFileInformationByHandleEx -# define setup_fileid_api() +#define pGetFileInformationByHandleEx GetFileInformationByHandleEx +#define setup_fileid_api() #endif - -#define is_wprefix(s, prefix) \ - (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0) +#define is_wprefix(s, prefix) (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0) /* Check if the fd handle is a cygwin/msys's pty. */ -int is_cygpty(HANDLE h) -{ +int is_cygpty(HANDLE h) { #if defined(STUB_IMPL) return 0; #elif _WIN32_WINNT >= 0x0600 - int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * (MAX_PATH - 1); + int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * (MAX_PATH - 1); FILE_NAME_INFO *nameinfo; - WCHAR *p = NULL; + WCHAR *p = NULL; setup_fileid_api(); @@ -122,7 +114,7 @@ int is_cygpty(HANDLE h) if (GetFileType(h) != FILE_TYPE_PIPE) { return 0; } - nameinfo = (FILE_NAME_INFO*)malloc(size + sizeof(WCHAR)); + nameinfo = (FILE_NAME_INFO *)malloc(size + sizeof(WCHAR)); if (nameinfo == NULL) { return 0; } @@ -130,8 +122,8 @@ int is_cygpty(HANDLE h) * '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master' */ if (pGetFileInformationByHandleEx(h, FileNameInfo, nameinfo, size)) { nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0'; - p = nameinfo->FileName; - if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */ + p = nameinfo->FileName; + if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */ p += 8; } else if (is_wprefix(p, L"\\msys-")) { /* MSYS and MSYS2 */ p += 6; @@ -139,7 +131,7 @@ int is_cygpty(HANDLE h) p = NULL; } if (p != NULL) { - while (*p && isxdigit(*p)) /* Skip 16-digit hexadecimal. */ + while (*p && isxdigit(*p)) /* Skip 16-digit hexadecimal. */ ++p; if (is_wprefix(p, L"-pty")) { p += 4; @@ -148,7 +140,7 @@ int is_cygpty(HANDLE h) } } if (p != NULL) { - while (*p && isdigit(*p)) /* Skip pty number. */ + while (*p && isdigit(*p)) /* Skip pty number. */ ++p; if (is_wprefix(p, L"-from-master")) { //p += 12; @@ -167,5 +159,3 @@ int is_cygpty(HANDLE h) } #endif /* _WIN32 */ - - diff --git a/core/src/xmake/io/pipe_close.c b/core/src/xmake/io/pipe_close.c index 062e7009d..a3adb6d8c 100644 --- a/core/src/xmake/io/pipe_close.c +++ b/core/src/xmake/io/pipe_close.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "pipe_close" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "pipe_close" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.pipe_close(pipe) -tb_int_t xm_io_pipe_close(lua_State* lua) -{ +tb_int_t xm_io_pipe_close(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -52,4 +51,3 @@ tb_int_t xm_io_pipe_close(lua_State* lua) lua_pushboolean(lua, tb_pipe_file_exit(pipefile)); return 1; } - diff --git a/core/src/xmake/io/pipe_connect.c b/core/src/xmake/io/pipe_connect.c index aebf8b7a0..985817386 100644 --- a/core/src/xmake/io/pipe_connect.c +++ b/core/src/xmake/io/pipe_connect.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "pipe_connect" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "pipe_connect" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // io.pipe_connect(pipefile) -tb_int_t xm_io_pipe_connect(lua_State* lua) -{ +tb_int_t xm_io_pipe_connect(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check pipe - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushnumber(lua, -1); lua_pushliteral(lua, "invalid pipe!"); return 2; @@ -56,4 +54,3 @@ tb_int_t xm_io_pipe_connect(lua_State* lua) lua_pushnumber(lua, (tb_int_t)tb_pipe_file_connect(pipefile)); return 1; } - diff --git a/core/src/xmake/io/pipe_open.c b/core/src/xmake/io/pipe_open.c index a77cda6e8..d0dbe66e9 100644 --- a/core/src/xmake/io/pipe_open.c +++ b/core/src/xmake/io/pipe_open.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "pipe_open" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "pipe_open" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -37,29 +37,32 @@ /* * io.pipe_open(name, mode, buffsize) */ -tb_int_t xm_io_pipe_open(lua_State* lua) -{ +tb_int_t xm_io_pipe_open(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get pipe name and mode - tb_char_t const* name = luaL_checkstring(lua, 1); - tb_char_t const* modestr = luaL_optstring(lua, 2, "r"); + tb_char_t const *name = luaL_checkstring(lua, 1); + tb_char_t const *modestr = luaL_optstring(lua, 2, "r"); tb_assert_and_check_return_val(name && modestr, 0); // get pipe mode value tb_size_t mode = TB_PIPE_MODE_RO; - if (modestr[0] == 'w') mode = TB_PIPE_MODE_WO; + if (modestr[0] == 'w') + mode = TB_PIPE_MODE_WO; // set block mode - if (modestr[1] == 'B') mode |= TB_PIPE_MODE_BLOCK; + if (modestr[1] == 'B') + mode |= TB_PIPE_MODE_BLOCK; // get buffer size tb_size_t buffsize = (tb_size_t)luaL_checknumber(lua, 3); // open pipe file tb_pipe_file_ref_t pipefile = tb_pipe_file_init(name, mode, buffsize); - if (pipefile) xm_lua_pushpointer(lua, (tb_pointer_t)pipefile); - else lua_pushnil(lua); + if (pipefile) + xm_lua_pushpointer(lua, (tb_pointer_t)pipefile); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/io/pipe_openpair.c b/core/src/xmake/io/pipe_openpair.c index 03908b418..c95d13a62 100644 --- a/core/src/xmake/io/pipe_openpair.c +++ b/core/src/xmake/io/pipe_openpair.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "pipe_openpair" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "pipe_openpair" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -37,32 +37,30 @@ /* * io.pipe_openpair(mode, buffsize) */ -tb_int_t xm_io_pipe_openpair(lua_State* lua) -{ +tb_int_t xm_io_pipe_openpair(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get pipe mode - tb_char_t const* modestr = luaL_optstring(lua, 1, "AA"); + tb_char_t const *modestr = luaL_optstring(lua, 1, "AA"); tb_assert_and_check_return_val(modestr, 0); // init mode - tb_size_t mode[2] = {0}; - if (modestr[0] == 'B') mode[0] |= TB_PIPE_MODE_BLOCK; - if (modestr[1] == 'B') mode[1] |= TB_PIPE_MODE_BLOCK; + tb_size_t mode[2] = { 0 }; + if (modestr[0] == 'B') + mode[0] |= TB_PIPE_MODE_BLOCK; + if (modestr[1] == 'B') + mode[1] |= TB_PIPE_MODE_BLOCK; // get buffer size tb_size_t buffsize = (tb_size_t)luaL_checknumber(lua, 2); // init pipe tb_pipe_file_ref_t pipefile[2]; - if (tb_pipe_file_init_pair(pipefile, mode, buffsize)) - { + if (tb_pipe_file_init_pair(pipefile, mode, buffsize)) { xm_lua_pushpointer(lua, (tb_pointer_t)pipefile[0]); xm_lua_pushpointer(lua, (tb_pointer_t)pipefile[1]); - } - else - { + } else { lua_pushnil(lua); lua_pushnil(lua); } diff --git a/core/src/xmake/io/pipe_read.c b/core/src/xmake/io/pipe_read.c index cb3457fec..fb82c1ebd 100644 --- a/core/src/xmake/io/pipe_read.c +++ b/core/src/xmake/io/pipe_read.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "pipe_read" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "pipe_read" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // real, data_or_errors = io.pipe_read(pipefile, size) -tb_int_t xm_io_pipe_read(lua_State* lua) -{ +tb_int_t xm_io_pipe_read(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check pipe file - if (!xm_pipe_file_is_valid(lua, 1)) - { + if (!xm_pipe_file_is_valid(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid pipe file!"); return 2; @@ -53,11 +51,10 @@ tb_int_t xm_io_pipe_read(lua_State* lua) tb_check_return_val(pipefile, 0); // get data - tb_byte_t* data = tb_null; + tb_byte_t *data = tb_null; if (xm_lua_isinteger(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (!data) - { + data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; @@ -66,9 +63,9 @@ tb_int_t xm_io_pipe_read(lua_State* lua) // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); - if (size <= 0) - { + if (xm_lua_isinteger(lua, 3)) + size = (tb_long_t)lua_tointeger(lua, 3); + if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); return 2; diff --git a/core/src/xmake/io/pipe_wait.c b/core/src/xmake/io/pipe_wait.c index f39220d41..67d189892 100644 --- a/core/src/xmake/io/pipe_wait.c +++ b/core/src/xmake/io/pipe_wait.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "pipe_wait" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "pipe_wait" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.pipe_wait(pipefile, events, timeout) -tb_int_t xm_io_pipe_wait(lua_State* lua) -{ +tb_int_t xm_io_pipe_wait(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -58,4 +57,3 @@ tb_int_t xm_io_pipe_wait(lua_State* lua) lua_pushnumber(lua, (tb_int_t)tb_pipe_file_wait(pipefile, events, timeout)); return 1; } - diff --git a/core/src/xmake/io/pipe_write.c b/core/src/xmake/io/pipe_write.c index 140894428..9b0869299 100644 --- a/core/src/xmake/io/pipe_write.c +++ b/core/src/xmake/io/pipe_write.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "pipe_write" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "pipe_write" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // io.pipe_write(pipefile, data, start, last) -tb_int_t xm_io_pipe_write(lua_State* lua) -{ +tb_int_t xm_io_pipe_write(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check pipe - if (!xm_pipe_file_is_valid(lua, 1)) - { + if (!xm_pipe_file_is_valid(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid pipe file!"); return 2; @@ -54,11 +52,12 @@ tb_int_t xm_io_pipe_write(lua_State* lua) // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 2)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_lua_isinteger(lua, 3)) + size = (tb_size_t)lua_tointeger(lua, 3); + if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; diff --git a/core/src/xmake/io/poller.c b/core/src/xmake/io/poller.c index 7700c6858..e4c7cf494 100644 --- a/core/src/xmake/io/poller.c +++ b/core/src/xmake/io/poller.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "poller" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "poller" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,12 +34,11 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_poller_ref_t xm_io_poller(lua_State* lua) -{ +tb_poller_ref_t xm_io_poller(lua_State *lua) { tb_poller_ref_t poller = tb_null; xm_engine_ref_t engine = xm_engine_get(lua); - if (engine) poller = xm_engine_poller(engine); + if (engine) + poller = xm_engine_poller(engine); tb_assert(poller); return poller; } - diff --git a/core/src/xmake/io/poller.h b/core/src/xmake/io/poller.h index 887fc25ba..3c5937a68 100644 --- a/core/src/xmake/io/poller.h +++ b/core/src/xmake/io/poller.h @@ -31,12 +31,10 @@ */ // the poller state in wait events -typedef struct __xm_poller_state_t -{ - lua_State* lua; - tb_int_t events_count; - -}xm_poller_state_t; +typedef struct __xm_poller_state_t { + lua_State *lua; + tb_int_t events_count; +} xm_poller_state_t; /* ////////////////////////////////////////////////////////////////////////////////////// * interfaces @@ -46,8 +44,6 @@ typedef struct __xm_poller_state_t * * @return the io poller */ -tb_poller_ref_t xm_io_poller(lua_State* lua); +tb_poller_ref_t xm_io_poller(lua_State *lua); #endif - - diff --git a/core/src/xmake/io/poller_insert.c b/core/src/xmake/io/poller_insert.c index e78c3c18f..2b24b3b1e 100644 --- a/core/src/xmake/io/poller_insert.c +++ b/core/src/xmake/io/poller_insert.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "poller_insert" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "poller_insert" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,14 +36,12 @@ */ // io.poller_insert(obj:otype(), obj:cdata(), events) -tb_int_t xm_io_poller_insert(lua_State* lua) -{ +tb_int_t xm_io_poller_insert(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 2)) - { + if (!xm_lua_ispointer(lua, 2)) { lua_pushboolean(lua, tb_false); lua_pushfstring(lua, "invalid poller object!"); return 2; @@ -53,8 +51,8 @@ tb_int_t xm_io_poller_insert(lua_State* lua) tb_uint8_t otype = (tb_uint8_t)luaL_checknumber(lua, 1); // get cdata - tb_char_t const* cdata_str = tb_null; - tb_pointer_t cdata = (tb_pointer_t)xm_lua_topointer2(lua, 2, &cdata_str); + tb_char_t const *cdata_str = tb_null; + tb_pointer_t cdata = (tb_pointer_t)xm_lua_topointer2(lua, 2, &cdata_str); tb_check_return_val(cdata, 0); // get events @@ -67,4 +65,3 @@ tb_int_t xm_io_poller_insert(lua_State* lua) lua_pushboolean(lua, tb_poller_insert(xm_io_poller(lua), &object, events, cdata_str)); return 1; } - diff --git a/core/src/xmake/io/poller_modify.c b/core/src/xmake/io/poller_modify.c index 5ed858030..77dff2fbf 100644 --- a/core/src/xmake/io/poller_modify.c +++ b/core/src/xmake/io/poller_modify.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "poller_modify" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "poller_modify" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,14 +36,12 @@ */ // io.poller_modify(obj:otype(), obj:cdata(), events) -tb_int_t xm_io_poller_modify(lua_State* lua) -{ +tb_int_t xm_io_poller_modify(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 2)) - { + if (!xm_lua_ispointer(lua, 2)) { lua_pushboolean(lua, tb_false); lua_pushfstring(lua, "invalid poller object!"); return 2; @@ -53,8 +51,8 @@ tb_int_t xm_io_poller_modify(lua_State* lua) tb_uint8_t otype = (tb_uint8_t)luaL_checknumber(lua, 1); // get cdata - tb_char_t const* cdata_str = tb_null; - tb_pointer_t cdata = (tb_pointer_t)xm_lua_topointer2(lua, 2, &cdata_str); + tb_char_t const *cdata_str = tb_null; + tb_pointer_t cdata = (tb_pointer_t)xm_lua_topointer2(lua, 2, &cdata_str); tb_check_return_val(cdata, 0); // get events @@ -67,4 +65,3 @@ tb_int_t xm_io_poller_modify(lua_State* lua) lua_pushboolean(lua, tb_poller_modify(xm_io_poller(lua), &object, events, cdata_str)); return 1; } - diff --git a/core/src/xmake/io/poller_remove.c b/core/src/xmake/io/poller_remove.c index 3cad1aa0a..34242808f 100644 --- a/core/src/xmake/io/poller_remove.c +++ b/core/src/xmake/io/poller_remove.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "poller_remove" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "poller_remove" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,14 +36,12 @@ */ // io.poller_remove(obj:otype(), obj) -tb_int_t xm_io_poller_remove(lua_State* lua) -{ +tb_int_t xm_io_poller_remove(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 2)) - { + if (!xm_lua_ispointer(lua, 2)) { lua_pushboolean(lua, tb_false); lua_pushfstring(lua, "invalid poller object!"); return 2; @@ -63,4 +61,3 @@ tb_int_t xm_io_poller_remove(lua_State* lua) lua_pushboolean(lua, tb_poller_remove(xm_io_poller(lua), &object)); return 1; } - diff --git a/core/src/xmake/io/poller_spank.c b/core/src/xmake/io/poller_spank.c index ac7207763..1656a537e 100644 --- a/core/src/xmake/io/poller_spank.c +++ b/core/src/xmake/io/poller_spank.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "poller_spank" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "poller_spank" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,8 +36,7 @@ */ // io.poller_spank() -tb_int_t xm_io_poller_spank(lua_State* lua) -{ +tb_int_t xm_io_poller_spank(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -45,4 +44,3 @@ tb_int_t xm_io_poller_spank(lua_State* lua) tb_poller_spak(xm_io_poller(lua)); return 0; } - diff --git a/core/src/xmake/io/poller_support.c b/core/src/xmake/io/poller_support.c index 36ae52b34..d53cdc1ed 100644 --- a/core/src/xmake/io/poller_support.c +++ b/core/src/xmake/io/poller_support.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "poller_support" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "poller_support" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,8 +36,7 @@ */ // io.poller_support(events) -tb_int_t xm_io_poller_support(lua_State* lua) -{ +tb_int_t xm_io_poller_support(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -48,4 +47,3 @@ tb_int_t xm_io_poller_support(lua_State* lua) lua_pushboolean(lua, tb_poller_support(xm_io_poller(lua), events)); return 1; } - diff --git a/core/src/xmake/io/poller_wait.c b/core/src/xmake/io/poller_wait.c index 341893f74..141c4640b 100644 --- a/core/src/xmake/io/poller_wait.c +++ b/core/src/xmake/io/poller_wait.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "poller_wait" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "poller_wait" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,26 +34,28 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, tb_poller_object_ref_t object, tb_long_t events, tb_cpointer_t priv) -{ +static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, + tb_poller_object_ref_t object, + tb_long_t events, + tb_cpointer_t priv) { // check - xm_poller_state_t* state = (xm_poller_state_t*)tb_poller_priv(poller); + xm_poller_state_t *state = (xm_poller_state_t *)tb_poller_priv(poller); tb_assert_and_check_return(state && state->lua); // save object and events - lua_State* lua = state->lua; + lua_State *lua = state->lua; lua_newtable(lua); lua_pushinteger(lua, (tb_int_t)object->type); lua_rawseti(lua, -2, 1); - if (priv) lua_pushstring(lua, (tb_char_t const*)priv); - else lua_pushlightuserdata(lua, object->ref.ptr); + if (priv) + lua_pushstring(lua, (tb_char_t const *)priv); + else + lua_pushlightuserdata(lua, object->ref.ptr); lua_rawseti(lua, -2, 2); - if (object->type == TB_POLLER_OBJECT_FWATCHER) - { + if (object->type == TB_POLLER_OBJECT_FWATCHER) { lua_newtable(lua); - tb_fwatcher_event_t* event = (tb_fwatcher_event_t*)events; - if (event) - { + tb_fwatcher_event_t *event = (tb_fwatcher_event_t *)events; + if (event) { lua_pushstring(lua, "path"); lua_pushstring(lua, event->filepath); lua_settable(lua, -3); @@ -62,8 +64,8 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, tb_poller_object_ref lua_pushinteger(lua, event->event); lua_settable(lua, -3); } - } - else lua_pushinteger(lua, (tb_int_t)events); + } else + lua_pushinteger(lua, (tb_int_t)events); lua_rawseti(lua, -2, 3); lua_rawseti(lua, -2, ++state->events_count); } @@ -73,8 +75,7 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, tb_poller_object_ref */ // local events, count = io.poller_wait(timeout) -tb_int_t xm_io_poller_wait(lua_State* lua) -{ +tb_int_t xm_io_poller_wait(lua_State *lua) { // check tb_poller_ref_t poller = xm_io_poller(lua); tb_assert_and_check_return_val(poller && lua, 0); @@ -83,19 +84,16 @@ tb_int_t xm_io_poller_wait(lua_State* lua) tb_long_t timeout = (tb_long_t)luaL_checknumber(lua, 1); // reset events count - xm_poller_state_t* state = (xm_poller_state_t*)tb_poller_priv(poller); - state->events_count = 0; + xm_poller_state_t *state = (xm_poller_state_t *)tb_poller_priv(poller); + state->events_count = 0; // wait it lua_newtable(lua); tb_long_t count = tb_poller_wait(poller, xm_io_poller_event, timeout); - if (count > 0) - { + if (count > 0) { lua_pushinteger(lua, (tb_int_t)count); return 2; - } - else if (!count) - { + } else if (!count) { // timeout lua_pop(lua, 1); lua_pushnil(lua); @@ -109,4 +107,3 @@ tb_int_t xm_io_poller_wait(lua_State* lua) lua_pushinteger(lua, -1); return 2; } - diff --git a/core/src/xmake/io/prefix.h b/core/src/xmake/io/prefix.h index df4d09a17..4d312583c 100644 --- a/core/src/xmake/io/prefix.h +++ b/core/src/xmake/io/prefix.h @@ -29,88 +29,80 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * macros */ -#define XM_IO_BLOCK_MAXN (TB_STREAM_BLOCK_MAXN * 10) +#define XM_IO_BLOCK_MAXN (TB_STREAM_BLOCK_MAXN * 10) -#define xm_io_file_is_file(file) ((file)->type == XM_IO_FILE_TYPE_FILE) -#define xm_io_file_is_std(file) ((file)->type != XM_IO_FILE_TYPE_FILE) -#define xm_io_file_is_tty(file) (!!((file)->type & XM_IO_FILE_FLAG_TTY)) +#define xm_io_file_is_file(file) ((file)->type == XM_IO_FILE_TYPE_FILE) +#define xm_io_file_is_std(file) ((file)->type != XM_IO_FILE_TYPE_FILE) +#define xm_io_file_is_tty(file) (!!((file)->type & XM_IO_FILE_FLAG_TTY)) // return io error -#define xm_io_return_error(lua, error) \ - do \ - { \ - lua_pushnil(lua); \ - lua_pushliteral(lua, error); \ - return 2; \ +#define xm_io_return_error(lua, error) \ + do { \ + lua_pushnil(lua); \ + lua_pushliteral(lua, error); \ + return 2; \ } while (0) /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -typedef enum __xm_io_file_type_e -{ - XM_IO_FILE_TYPE_FILE = 0 //!< disk file +typedef enum __xm_io_file_type_e { + XM_IO_FILE_TYPE_FILE = 0 //!< disk file -, XM_IO_FILE_TYPE_STDIN = 1 -, XM_IO_FILE_TYPE_STDOUT = 2 -, XM_IO_FILE_TYPE_STDERR = 3 - -, XM_IO_FILE_FLAG_TTY = 0x10 //!< mark tty std stream + , + XM_IO_FILE_TYPE_STDIN = 1, + XM_IO_FILE_TYPE_STDOUT = 2, + XM_IO_FILE_TYPE_STDERR = 3 + , + XM_IO_FILE_FLAG_TTY = 0x10 //!< mark tty std stream } xm_io_file_type_e; /* use negetive numbers for this enum, its a extension for tb_charset_type_e * before adding new values, make sure they have not conflicts with values in tb_charset_type_e */ -typedef enum __xm_io_file_encoding_e -{ - XM_IO_FILE_ENCODING_UNKNOWN = -1 -, XM_IO_FILE_ENCODING_BINARY = -2 - +typedef enum __xm_io_file_encoding_e { + XM_IO_FILE_ENCODING_UNKNOWN = -1, + XM_IO_FILE_ENCODING_BINARY = -2 } xm_io_file_encoding_e; // the file type -typedef struct __xm_io_file_t -{ - union - { +typedef struct __xm_io_file_t { + union { /* the normal file for XM_IO_FILE_TYPE_FILE * * direct: file_ref -> stream -> file * transcode: file_ref -> fstream -> stream -> file */ - tb_stream_ref_t file_ref; + tb_stream_ref_t file_ref; // the standard io file - tb_stdfile_ref_t std_ref; - }u; - - tb_stream_ref_t stream; // the file stream for XM_IO_FILE_TYPE_FILE - tb_stream_ref_t fstream; // the file charset stream filter - tb_size_t mode; // tb_file_mode_t - tb_size_t type; // xm_io_file_type_e - tb_size_t encoding; // value of xm_io_file_encoding_e or tb_charset_type_e - tb_bool_t utfbom; // write utf-bom for utf encoding? - tb_buffer_t rcache; // the read line cache buffer - tb_buffer_t wcache; // the write line cache buffer - + tb_stdfile_ref_t std_ref; + } u; + + tb_stream_ref_t stream; // the file stream for XM_IO_FILE_TYPE_FILE + tb_stream_ref_t fstream; // the file charset stream filter + tb_size_t mode; // tb_file_mode_t + tb_size_t type; // xm_io_file_type_e + tb_size_t encoding; // value of xm_io_file_encoding_e or tb_charset_type_e + tb_bool_t utfbom; // write utf-bom for utf encoding? + tb_buffer_t rcache; // the read line cache buffer + tb_buffer_t wcache; // the write line cache buffer } xm_io_file_t; // check pipe file -static __tb_inline__ tb_bool_t xm_pipe_file_is_valid(lua_State* lua, tb_int_t index) -{ +static __tb_inline__ tb_bool_t xm_pipe_file_is_valid(lua_State *lua, tb_int_t index) { return xm_lua_ispointer(lua, index) || xm_lua_isinteger(lua, index); } // get the pipe file from arguments -static __tb_inline__ tb_pipe_file_ref_t xm_pipe_file_get(lua_State* lua, tb_int_t index) -{ +static __tb_inline__ tb_pipe_file_ref_t xm_pipe_file_get(lua_State *lua, tb_int_t index) { tb_pipe_file_ref_t pipe_file = tb_null; - if (xm_lua_isinteger(lua, index)) pipe_file = (tb_pipe_file_ref_t)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) pipe_file = (tb_pipe_file_ref_t)xm_lua_topointer(lua, index); + if (xm_lua_isinteger(lua, index)) + pipe_file = (tb_pipe_file_ref_t)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); + else if (xm_lua_ispointer(lua, index)) + pipe_file = (tb_pipe_file_ref_t)xm_lua_topointer(lua, index); return pipe_file; } #endif - - diff --git a/core/src/xmake/io/socket_accept.c b/core/src/xmake/io/socket_accept.c index 6a08d1908..5a303ef74 100644 --- a/core/src/xmake/io/socket_accept.c +++ b/core/src/xmake/io/socket_accept.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_accept" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_accept" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // local sock = io.socket_accept(sock) -tb_int_t xm_io_socket_accept(lua_State* lua) -{ +tb_int_t xm_io_socket_accept(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -50,8 +49,9 @@ tb_int_t xm_io_socket_accept(lua_State* lua) // accept socket tb_socket_ref_t client = tb_socket_accept(sock, tb_null); - if (client) xm_lua_pushpointer(lua, (tb_pointer_t)client); - else lua_pushnil(lua); + if (client) + xm_lua_pushpointer(lua, (tb_pointer_t)client); + else + lua_pushnil(lua); return 1; } - diff --git a/core/src/xmake/io/socket_bind.c b/core/src/xmake/io/socket_bind.c index e546c72c6..9ba441a6f 100644 --- a/core/src/xmake/io/socket_bind.c +++ b/core/src/xmake/io/socket_bind.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_bind" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_bind" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // io.socket_bind(sock, addr, port, family) -tb_int_t xm_io_socket_bind(lua_State* lua) -{ +tb_int_t xm_io_socket_bind(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check socket - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushboolean(lua, tb_false); lua_pushliteral(lua, "invalid socket!"); return 2; @@ -53,7 +51,7 @@ tb_int_t xm_io_socket_bind(lua_State* lua) tb_check_return_val(sock, 0); // get address - tb_char_t const* address = lua_tostring(lua, 2); + tb_char_t const *address = lua_tostring(lua, 2); tb_assert_and_check_return_val(address, 0); // get family @@ -61,13 +59,10 @@ tb_int_t xm_io_socket_bind(lua_State* lua) // init address tb_ipaddr_t addr; - if (family == TB_IPADDR_FAMILY_UNIX) - { + if (family == TB_IPADDR_FAMILY_UNIX) { tb_bool_t is_abstract = (tb_bool_t)lua_toboolean(lua, 3); tb_ipaddr_unix_set_cstr(&addr, address, is_abstract); - } - else - { + } else { tb_uint16_t port = (tb_uint16_t)luaL_checknumber(lua, 3); tb_ipaddr_set(&addr, address, port, family); } @@ -76,4 +71,3 @@ tb_int_t xm_io_socket_bind(lua_State* lua) lua_pushboolean(lua, tb_socket_bind(sock, &addr)); return 1; } - diff --git a/core/src/xmake/io/socket_close.c b/core/src/xmake/io/socket_close.c index a424a707f..d53228fe7 100644 --- a/core/src/xmake/io/socket_close.c +++ b/core/src/xmake/io/socket_close.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_close" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_close" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.socket_close(sock) -tb_int_t xm_io_socket_close(lua_State* lua) -{ +tb_int_t xm_io_socket_close(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -52,4 +51,3 @@ tb_int_t xm_io_socket_close(lua_State* lua) lua_pushboolean(lua, tb_socket_exit(sock)); return 1; } - diff --git a/core/src/xmake/io/socket_connect.c b/core/src/xmake/io/socket_connect.c index 636fe92b1..63d355fb4 100644 --- a/core/src/xmake/io/socket_connect.c +++ b/core/src/xmake/io/socket_connect.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_connect" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_connect" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // io.socket_connect(sock, addr, port, family) -tb_int_t xm_io_socket_connect(lua_State* lua) -{ +tb_int_t xm_io_socket_connect(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check socket - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushnumber(lua, -1); lua_pushliteral(lua, "invalid socket!"); return 2; @@ -53,7 +51,7 @@ tb_int_t xm_io_socket_connect(lua_State* lua) tb_check_return_val(sock, 0); // get address - tb_char_t const* address = lua_tostring(lua, 2); + tb_char_t const *address = lua_tostring(lua, 2); tb_assert_and_check_return_val(address, 0); // get family @@ -61,13 +59,10 @@ tb_int_t xm_io_socket_connect(lua_State* lua) // init address tb_ipaddr_t addr; - if (family == TB_IPADDR_FAMILY_UNIX) - { + if (family == TB_IPADDR_FAMILY_UNIX) { tb_bool_t is_abstract = (tb_bool_t)lua_toboolean(lua, 3); tb_ipaddr_unix_set_cstr(&addr, address, is_abstract); - } - else - { + } else { tb_uint16_t port = (tb_uint16_t)luaL_checknumber(lua, 3); tb_ipaddr_set(&addr, address, port, family); } @@ -76,4 +71,3 @@ tb_int_t xm_io_socket_connect(lua_State* lua) lua_pushnumber(lua, (tb_int_t)tb_socket_connect(sock, &addr)); return 1; } - diff --git a/core/src/xmake/io/socket_ctrl.c b/core/src/xmake/io/socket_ctrl.c index a4192850a..c16f2c20d 100644 --- a/core/src/xmake/io/socket_ctrl.c +++ b/core/src/xmake/io/socket_ctrl.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_ctrl" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_ctrl" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // io.socket_ctrl(sock, code, value) -tb_int_t xm_io_socket_ctrl(lua_State* lua) -{ +tb_int_t xm_io_socket_ctrl(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check socket - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushnumber(lua, -1); lua_pushliteral(lua, "invalid socket!"); return 2; @@ -62,4 +60,3 @@ tb_int_t xm_io_socket_ctrl(lua_State* lua) lua_pushboolean(lua, tb_socket_ctrl(sock, code, value)); return 1; } - diff --git a/core/src/xmake/io/socket_kill.c b/core/src/xmake/io/socket_kill.c index e590ece72..eb2956e53 100644 --- a/core/src/xmake/io/socket_kill.c +++ b/core/src/xmake/io/socket_kill.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_kill" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_kill" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // local sock = io.socket_kill(sock) -tb_int_t xm_io_socket_kill(lua_State* lua) -{ +tb_int_t xm_io_socket_kill(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -52,4 +51,3 @@ tb_int_t xm_io_socket_kill(lua_State* lua) tb_socket_kill(sock, TB_SOCKET_KILL_RW); return 0; } - diff --git a/core/src/xmake/io/socket_listen.c b/core/src/xmake/io/socket_listen.c index 67c10b7e0..6fece6087 100644 --- a/core/src/xmake/io/socket_listen.c +++ b/core/src/xmake/io/socket_listen.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_listen" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_listen" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.socket_listen(sock, backlog) -tb_int_t xm_io_socket_listen(lua_State* lua) -{ +tb_int_t xm_io_socket_listen(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -55,4 +54,3 @@ tb_int_t xm_io_socket_listen(lua_State* lua) lua_pushnumber(lua, (tb_int_t)tb_socket_listen(sock, backlog)); return 1; } - diff --git a/core/src/xmake/io/socket_open.c b/core/src/xmake/io/socket_open.c index 6453fa4d7..4189607c7 100644 --- a/core/src/xmake/io/socket_open.c +++ b/core/src/xmake/io/socket_open.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_open" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_open" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -37,8 +37,7 @@ /* * io.socket_open(socktype, family) */ -tb_int_t xm_io_socket_open(lua_State* lua) -{ +tb_int_t xm_io_socket_open(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -49,8 +48,7 @@ tb_int_t xm_io_socket_open(lua_State* lua) tb_size_t family = (tb_size_t)luaL_checknumber(lua, 2); // map socket type - switch (socktype) - { + switch (socktype) { case 2: socktype = TB_SOCKET_TYPE_UDP; break; @@ -64,7 +62,9 @@ tb_int_t xm_io_socket_open(lua_State* lua) // init socket tb_socket_ref_t sock = tb_socket_init(socktype, family); - if (sock) xm_lua_pushpointer(lua, (tb_pointer_t)sock); - else lua_pushnil(lua); + if (sock) + xm_lua_pushpointer(lua, (tb_pointer_t)sock); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/io/socket_peeraddr.c b/core/src/xmake/io/socket_peeraddr.c index f955672df..bcc03c289 100644 --- a/core/src/xmake/io/socket_peeraddr.c +++ b/core/src/xmake/io/socket_peeraddr.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_peeraddr" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_peeraddr" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,7 +35,7 @@ */ // socket to fd -#define xm_io_sock2fd(sock) (lua_Number)tb_sock2fd(sock) +#define xm_io_sock2fd(sock) (lua_Number) tb_sock2fd(sock) /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -43,8 +43,7 @@ /* io.socket_peeraddr(sock) */ -tb_int_t xm_io_socket_peeraddr(lua_State* lua) -{ +tb_int_t xm_io_socket_peeraddr(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -57,11 +56,12 @@ tb_int_t xm_io_socket_peeraddr(lua_State* lua) tb_check_return_val(sock, 0); // get peer address - tb_ipaddr_t addr; - tb_char_t data[256]; - tb_char_t const* cstr = tb_null; + tb_ipaddr_t addr; + tb_char_t data[256]; + tb_char_t const *cstr = tb_null; if (tb_socket_peer(sock, &addr) && (cstr = tb_ipaddr_cstr(&addr, data, sizeof(data)))) lua_pushstring(lua, cstr); - else lua_pushnil(lua); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/io/socket_rawfd.c b/core/src/xmake/io/socket_rawfd.c index 5e179b836..672a9dafa 100644 --- a/core/src/xmake/io/socket_rawfd.c +++ b/core/src/xmake/io/socket_rawfd.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_rawfd" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_rawfd" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,7 +35,7 @@ */ // socket to fd -#define xm_io_sock2fd(sock) (lua_Number)tb_sock2fd(sock) +#define xm_io_sock2fd(sock) (lua_Number) tb_sock2fd(sock) /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -43,8 +43,7 @@ /* io.socket_rawfd(sock) */ -tb_int_t xm_io_socket_rawfd(lua_State* lua) -{ +tb_int_t xm_io_socket_rawfd(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); diff --git a/core/src/xmake/io/socket_recv.c b/core/src/xmake/io/socket_recv.c index be6a91f93..cecdbb031 100644 --- a/core/src/xmake/io/socket_recv.c +++ b/core/src/xmake/io/socket_recv.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_recv" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_recv" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // real, data_or_errors = io.socket_recv(sock, size) -tb_int_t xm_io_socket_recv(lua_State* lua) -{ +tb_int_t xm_io_socket_recv(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check socket - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid socket!"); return 2; @@ -53,11 +51,10 @@ tb_int_t xm_io_socket_recv(lua_State* lua) tb_check_return_val(sock, 0); // get data - tb_byte_t* data = tb_null; + tb_byte_t *data = tb_null; if (xm_lua_isinteger(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (!data) - { + data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; @@ -66,9 +63,9 @@ tb_int_t xm_io_socket_recv(lua_State* lua) // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); - if (size <= 0) - { + if (xm_lua_isinteger(lua, 3)) + size = (tb_long_t)lua_tointeger(lua, 3); + if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); return 2; diff --git a/core/src/xmake/io/socket_recvfrom.c b/core/src/xmake/io/socket_recvfrom.c index 46beb6dc1..bc8f53bf8 100644 --- a/core/src/xmake/io/socket_recvfrom.c +++ b/core/src/xmake/io/socket_recvfrom.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_recvfrom" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_recvfrom" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // real, data_or_errors, addr, port = io.socket_recvfrom(sock, size) -tb_int_t xm_io_socket_recvfrom(lua_State* lua) -{ +tb_int_t xm_io_socket_recvfrom(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check socket - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid socket!"); return 2; @@ -53,11 +51,10 @@ tb_int_t xm_io_socket_recvfrom(lua_State* lua) tb_check_return_val(sock, 0); // get data - tb_byte_t* data = tb_null; + tb_byte_t *data = tb_null; if (xm_lua_isinteger(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (!data) - { + data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; @@ -66,9 +63,9 @@ tb_int_t xm_io_socket_recvfrom(lua_State* lua) // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); - if (size <= 0) - { + if (xm_lua_isinteger(lua, 3)) + size = (tb_long_t)lua_tointeger(lua, 3); + if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); return 2; @@ -77,19 +74,16 @@ tb_int_t xm_io_socket_recvfrom(lua_State* lua) // recv data tb_ipaddr_t ipaddr; tb_ipaddr_clear(&ipaddr); - tb_int_t retn = 1; - tb_long_t real = tb_socket_urecv(sock, &ipaddr, data, size); + tb_int_t retn = 1; + tb_long_t real = tb_socket_urecv(sock, &ipaddr, data, size); lua_pushinteger(lua, (tb_int_t)real); - if (real > 0) - { + if (real > 0) { retn = 2; lua_pushnil(lua); - if (!tb_ipaddr_is_empty(&ipaddr)) - { - tb_char_t buffer[256]; - tb_char_t const* ipstr = tb_ipaddr_ip_cstr(&ipaddr, buffer, sizeof(buffer)); - if (ipstr) - { + if (!tb_ipaddr_is_empty(&ipaddr)) { + tb_char_t buffer[256]; + tb_char_t const *ipstr = tb_ipaddr_ip_cstr(&ipaddr, buffer, sizeof(buffer)); + if (ipstr) { lua_pushstring(lua, ipstr); lua_pushinteger(lua, (tb_int_t)tb_ipaddr_port(&ipaddr)); retn = 4; diff --git a/core/src/xmake/io/socket_send.c b/core/src/xmake/io/socket_send.c index 4355db653..1b99d8d08 100644 --- a/core/src/xmake/io/socket_send.c +++ b/core/src/xmake/io/socket_send.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_send" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_send" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // io.socket_send(sock, data, start, last) -tb_int_t xm_io_socket_send(lua_State* lua) -{ +tb_int_t xm_io_socket_send(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check socket - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid socket!"); return 2; @@ -54,11 +52,12 @@ tb_int_t xm_io_socket_send(lua_State* lua) // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 2)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_lua_isinteger(lua, 3)) + size = (tb_size_t)lua_tointeger(lua, 3); + if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; diff --git a/core/src/xmake/io/socket_sendfile.c b/core/src/xmake/io/socket_sendfile.c index 3dbd83ca8..b5e6e10d6 100644 --- a/core/src/xmake/io/socket_sendfile.c +++ b/core/src/xmake/io/socket_sendfile.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_sendfile" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_sendfile" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,22 +35,19 @@ */ // io.socket_sendfile(sock, file, start, last) -tb_int_t xm_io_socket_sendfile(lua_State* lua) -{ +tb_int_t xm_io_socket_sendfile(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check socket - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid socket!"); return 2; } // check file - if (!lua_isuserdata(lua, 2)) - { + if (!lua_isuserdata(lua, 2)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid file!"); return 2; @@ -61,12 +58,11 @@ tb_int_t xm_io_socket_sendfile(lua_State* lua) tb_check_return_val(sock, 0); // get file - xm_io_file_t* file = (xm_io_file_t*)lua_touserdata(lua, 2); + xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 2); tb_check_return_val(file, 0); // does not support stdfile - if (!xm_io_file_is_file(file) || !file->stream) - { + if (!xm_io_file_is_file(file) || !file->stream) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid file type!"); return 2; @@ -74,8 +70,7 @@ tb_int_t xm_io_socket_sendfile(lua_State* lua) // get file reference tb_file_ref_t rawfile = tb_null; - if (!tb_stream_ctrl(file->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) || !rawfile) - { + if (!tb_stream_ctrl(file->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) || !rawfile) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "cannot get file reference!"); return 2; @@ -83,8 +78,7 @@ tb_int_t xm_io_socket_sendfile(lua_State* lua) // get file size tb_hize_t filesize = tb_file_size(rawfile); - if (!filesize) - { + if (!filesize) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "cannot send empty file!"); return 2; @@ -92,9 +86,9 @@ tb_int_t xm_io_socket_sendfile(lua_State* lua) // get start tb_long_t start = 1; - if (lua_isnumber(lua, 3)) start = (tb_long_t)lua_tonumber(lua, 3); - if (start < 1 || start > filesize) - { + if (lua_isnumber(lua, 3)) + start = (tb_long_t)lua_tonumber(lua, 3); + if (start < 1 || start > filesize) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid start position(%d)!", (tb_int_t)start); return 2; @@ -102,9 +96,9 @@ tb_int_t xm_io_socket_sendfile(lua_State* lua) // get last tb_long_t last = (tb_long_t)filesize; - if (lua_isnumber(lua, 4)) last = (tb_long_t)lua_tonumber(lua, 4); - if (last < start - 1 || last > filesize + start - 1) - { + if (lua_isnumber(lua, 4)) + last = (tb_long_t)lua_tonumber(lua, 4); + if (last < start - 1 || last > filesize + start - 1) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid last position(%d)!", (tb_int_t)last); return 2; diff --git a/core/src/xmake/io/socket_sendto.c b/core/src/xmake/io/socket_sendto.c index 5d5b4c8aa..cde81febf 100644 --- a/core/src/xmake/io/socket_sendto.c +++ b/core/src/xmake/io/socket_sendto.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_sendto" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_sendto" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // io.socket_sendto(sock, data, addr, port) -tb_int_t xm_io_socket_sendto(lua_State* lua) -{ +tb_int_t xm_io_socket_sendto(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check socket - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid socket!"); return 2; @@ -54,11 +52,12 @@ tb_int_t xm_io_socket_sendto(lua_State* lua) // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 2)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_lua_isinteger(lua, 3)) + size = (tb_size_t)lua_tointeger(lua, 3); + if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -66,10 +65,9 @@ tb_int_t xm_io_socket_sendto(lua_State* lua) tb_assert_static(sizeof(lua_Integer) >= sizeof(tb_pointer_t)); // get address - tb_char_t const* addr = lua_tostring(lua, 4); + tb_char_t const *addr = lua_tostring(lua, 4); tb_uint16_t port = (tb_uint16_t)luaL_checknumber(lua, 5); - if (!addr || !port) - { + if (!addr || !port) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid address!"); return 2; diff --git a/core/src/xmake/io/socket_wait.c b/core/src/xmake/io/socket_wait.c index 681cf20e8..fd9900e21 100644 --- a/core/src/xmake/io/socket_wait.c +++ b/core/src/xmake/io/socket_wait.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "socket_wait" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "socket_wait" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // io.socket_wait(sock, events, timeout) -tb_int_t xm_io_socket_wait(lua_State* lua) -{ +tb_int_t xm_io_socket_wait(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -58,4 +57,3 @@ tb_int_t xm_io_socket_wait(lua_State* lua) lua_pushnumber(lua, (tb_int_t)tb_socket_wait(sock, events, timeout)); return 1; } - diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 949aa6c3a..05e1fcf2a 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -22,21 +22,21 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "stdfile" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "stdfile" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #ifdef TB_CONFIG_OS_WINDOWS -# include -# include "iscygpty.c" +#include +#include "iscygpty.c" #else -# include -# include -# include -# include +#include +#include +#include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -44,24 +44,28 @@ */ // the singleton type of stdfile -#define XM_IO_STDFILE_STDIN (TB_SINGLETON_TYPE_USER + 1) -#define XM_IO_STDFILE_STDOUT (TB_SINGLETON_TYPE_USER + 2) -#define XM_IO_STDFILE_STDERR (TB_SINGLETON_TYPE_USER + 3) +#define XM_IO_STDFILE_STDIN (TB_SINGLETON_TYPE_USER + 1) +#define XM_IO_STDFILE_STDOUT (TB_SINGLETON_TYPE_USER + 2) +#define XM_IO_STDFILE_STDERR (TB_SINGLETON_TYPE_USER + 3) /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_size_t xm_io_stdfile_isatty(tb_size_t type) -{ +static tb_size_t xm_io_stdfile_isatty(tb_size_t type) { tb_bool_t answer = tb_false; #if defined(TB_CONFIG_OS_WINDOWS) DWORD mode; HANDLE console_handle = tb_null; - switch (type) - { - case XM_IO_FILE_TYPE_STDIN: console_handle = GetStdHandle(STD_INPUT_HANDLE); break; - case XM_IO_FILE_TYPE_STDOUT: console_handle = GetStdHandle(STD_OUTPUT_HANDLE); break; - case XM_IO_FILE_TYPE_STDERR: console_handle = GetStdHandle(STD_ERROR_HANDLE); break; + switch (type) { + case XM_IO_FILE_TYPE_STDIN: + console_handle = GetStdHandle(STD_INPUT_HANDLE); + break; + case XM_IO_FILE_TYPE_STDOUT: + console_handle = GetStdHandle(STD_OUTPUT_HANDLE); + break; + case XM_IO_FILE_TYPE_STDERR: + console_handle = GetStdHandle(STD_ERROR_HANDLE); + break; } answer = GetConsoleMode(console_handle, &mode); /* we cannot call is_cygpty for stdin, because it will cause io.readable is always true @@ -70,36 +74,39 @@ static tb_size_t xm_io_stdfile_isatty(tb_size_t type) if (!answer && type != XM_IO_FILE_TYPE_STDIN) answer = is_cygpty(console_handle); #else - switch (type) - { - case XM_IO_FILE_TYPE_STDIN: answer = isatty(fileno(stdin)); break; - case XM_IO_FILE_TYPE_STDOUT: answer = isatty(fileno(stdout)); break; - case XM_IO_FILE_TYPE_STDERR: answer = isatty(fileno(stderr)); break; + switch (type) { + case XM_IO_FILE_TYPE_STDIN: + answer = isatty(fileno(stdin)); + break; + case XM_IO_FILE_TYPE_STDOUT: + answer = isatty(fileno(stdout)); + break; + case XM_IO_FILE_TYPE_STDERR: + answer = isatty(fileno(stderr)); + break; } #endif - if (answer) type |= XM_IO_FILE_FLAG_TTY; + if (answer) + type |= XM_IO_FILE_FLAG_TTY; return type; } // @see https://github.com/xmake-io/xmake/issues/2580 -static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) -{ +static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) { #if !defined(TB_CONFIG_OS_WINDOWS) struct stat stats; - tb_int_t size = BUFSIZ; + tb_int_t size = BUFSIZ; if (fstat(fileno(stdout), &stats) != -1) size = stats.st_blksize; setvbuf(stdout, tb_null, _IOLBF, size); #endif } -static xm_io_file_t* xm_io_stdfile_new(lua_State* lua, tb_size_t type) -{ +static xm_io_file_t *xm_io_stdfile_new(lua_State *lua, tb_size_t type) { // init stdfile tb_stdfile_ref_t fp = tb_null; - switch (type) - { + switch (type) { case XM_IO_FILE_TYPE_STDIN: fp = tb_stdfile_input(); break; @@ -112,15 +119,15 @@ static xm_io_file_t* xm_io_stdfile_new(lua_State* lua, tb_size_t type) } // new file - xm_io_file_t* file = (xm_io_file_t*)lua_newuserdata(lua, sizeof(xm_io_file_t)); + xm_io_file_t *file = (xm_io_file_t *)lua_newuserdata(lua, sizeof(xm_io_file_t)); tb_assert_and_check_return_val(file, tb_null); // init file - file->u.std_ref = fp; - file->stream = tb_null; - file->fstream = tb_null; - file->type = xm_io_stdfile_isatty(type); - file->encoding = TB_CHARSET_TYPE_UTF8; + file->u.std_ref = fp; + file->stream = tb_null; + file->fstream = tb_null; + file->type = xm_io_stdfile_isatty(type); + file->encoding = TB_CHARSET_TYPE_UTF8; // init stdio buffer xm_io_stdfile_init_buffer(type); @@ -136,8 +143,7 @@ static xm_io_file_t* xm_io_stdfile_new(lua_State* lua, tb_size_t type) */ // io.stdfile(stdin: 1, stdout: 2, stderr: 3) -tb_int_t xm_io_stdfile(lua_State* lua) -{ +tb_int_t xm_io_stdfile(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -148,9 +154,9 @@ tb_int_t xm_io_stdfile(lua_State* lua) * * @note we need to ensure that it is a singleton in the external lua script, and will only be created once, e.g. io.stdin, io.stdout, io.stderr */ - xm_io_file_t* file = xm_io_stdfile_new(lua, type); - if (file) return 1; - else xm_io_return_error(lua, "invalid stdfile type!"); + xm_io_file_t *file = xm_io_stdfile_new(lua, type); + if (file) + return 1; + else + xm_io_return_error(lua, "invalid stdfile type!"); } - - diff --git a/core/src/xmake/libc/byteof.c b/core/src/xmake/libc/byteof.c index 6dff49100..be8820ff9 100644 --- a/core/src/xmake/libc/byteof.c +++ b/core/src/xmake/libc/byteof.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "byteof" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "byteof" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_libc_byteof(lua_State* lua) -{ +tb_int_t xm_libc_byteof(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -44,15 +43,15 @@ tb_int_t xm_libc_byteof(lua_State* lua) data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1); else if (lua_isstring(lua, 1)) data = (tb_pointer_t)luaL_checkstring(lua, 1); - else xm_libc_return_error(lua, "libc.byteof(invalid data)!"); + else + xm_libc_return_error(lua, "libc.byteof(invalid data)!"); // get offset tb_int_t offset = 0; if (lua_isnumber(lua, 2)) offset = (tb_int_t)lua_tointeger(lua, 2); - else xm_libc_return_error(lua, "libc.byteof(invalid offset)!"); - lua_pushinteger(lua, ((tb_byte_t const*)data)[offset]); + else + xm_libc_return_error(lua, "libc.byteof(invalid offset)!"); + lua_pushinteger(lua, ((tb_byte_t const *)data)[offset]); return 1; } - - diff --git a/core/src/xmake/libc/dataptr.c b/core/src/xmake/libc/dataptr.c index b78b32558..50b063b4e 100644 --- a/core/src/xmake/libc/dataptr.c +++ b/core/src/xmake/libc/dataptr.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "dataptr" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "dataptr" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_libc_dataptr(lua_State* lua) -{ +tb_int_t xm_libc_dataptr(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -45,8 +44,8 @@ tb_int_t xm_libc_dataptr(lua_State* lua) data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1); else if (xm_lua_ispointer(lua, 1)) data = (tb_pointer_t)xm_lua_topointer(lua, 1); - else xm_libc_return_error(lua, "libc.dataptr(invalid data)!"); + else + xm_libc_return_error(lua, "libc.dataptr(invalid data)!"); lua_pushinteger(lua, (lua_Integer)(tb_long_t)data); return 1; } - diff --git a/core/src/xmake/libc/free.c b/core/src/xmake/libc/free.c index 89dc65ed0..ad12ccfc9 100644 --- a/core/src/xmake/libc/free.c +++ b/core/src/xmake/libc/free.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "free" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "free" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,13 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_libc_free(lua_State* lua) -{ +tb_int_t xm_libc_free(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // do free tb_pointer_t data = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); - if (data) tb_free(data); + if (data) + tb_free(data); return 0; } - diff --git a/core/src/xmake/libc/malloc.c b/core/src/xmake/libc/malloc.c index 989cb6aac..8e2380955 100644 --- a/core/src/xmake/libc/malloc.c +++ b/core/src/xmake/libc/malloc.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "malloc" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "malloc" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,16 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_libc_malloc(lua_State* lua) -{ +tb_int_t xm_libc_malloc(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // do malloc tb_pointer_t data = tb_null; - tb_long_t size = (tb_long_t)luaL_checkinteger(lua, 1); - if (size > 0) data = tb_malloc(size); + tb_long_t size = (tb_long_t)luaL_checkinteger(lua, 1); + if (size > 0) + data = tb_malloc(size); lua_pushinteger(lua, (lua_Integer)(tb_long_t)data); return 1; } - diff --git a/core/src/xmake/libc/memcpy.c b/core/src/xmake/libc/memcpy.c index d565b300e..6baf66d39 100644 --- a/core/src/xmake/libc/memcpy.c +++ b/core/src/xmake/libc/memcpy.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "memcpy" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "memcpy" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_libc_memcpy(lua_State* lua) -{ +tb_int_t xm_libc_memcpy(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // do memcpy - tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); - tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2); - tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); + tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); + tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2); + tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); if (dst && src && size > 0) tb_memcpy(dst, src, size); return 0; } - diff --git a/core/src/xmake/libc/memmov.c b/core/src/xmake/libc/memmov.c index eaa6cc8bc..f43bccea6 100644 --- a/core/src/xmake/libc/memmov.c +++ b/core/src/xmake/libc/memmov.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "memmov" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "memmov" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_libc_memmov(lua_State* lua) -{ +tb_int_t xm_libc_memmov(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // do memmov - tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); - tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2); - tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); + tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); + tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2); + tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); if (dst && src && size > 0) tb_memmov(dst, src, size); return 0; } - diff --git a/core/src/xmake/libc/memset.c b/core/src/xmake/libc/memset.c index 4ac025fa2..2c0936017 100644 --- a/core/src/xmake/libc/memset.c +++ b/core/src/xmake/libc/memset.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "memset" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "memset" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_libc_memset(lua_State* lua) -{ +tb_int_t xm_libc_memset(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // do memset tb_pointer_t data = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); - tb_char_t ch = (tb_char_t)lua_tointeger(lua, 2); - tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); + tb_char_t ch = (tb_char_t)lua_tointeger(lua, 2); + tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); if (data && size > 0) tb_memset(data, ch, size); return 0; } - diff --git a/core/src/xmake/libc/prefix.h b/core/src/xmake/libc/prefix.h index dd6dcb2ec..3bed4da3d 100644 --- a/core/src/xmake/libc/prefix.h +++ b/core/src/xmake/libc/prefix.h @@ -31,14 +31,11 @@ */ // return libc error -#define xm_libc_return_error(lua, error) \ - do \ - { \ - lua_pushnil(lua); \ - lua_pushliteral(lua, error); \ - return 2; \ +#define xm_libc_return_error(lua, error) \ + do { \ + lua_pushnil(lua); \ + lua_pushliteral(lua, error); \ + return 2; \ } while (0) #endif - - diff --git a/core/src/xmake/libc/setbyte.c b/core/src/xmake/libc/setbyte.c index 5dd77396c..7ae959014 100644 --- a/core/src/xmake/libc/setbyte.c +++ b/core/src/xmake/libc/setbyte.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "setbyte" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "setbyte" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_libc_setbyte(lua_State* lua) -{ +tb_int_t xm_libc_setbyte(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -44,19 +43,20 @@ tb_int_t xm_libc_setbyte(lua_State* lua) data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1); else if (lua_isstring(lua, 1)) data = (tb_pointer_t)luaL_checkstring(lua, 1); - else xm_libc_return_error(lua, "libc.setbyte(invalid data)!"); + else + xm_libc_return_error(lua, "libc.setbyte(invalid data)!"); // get offset tb_int_t offset = 0; if (lua_isnumber(lua, 2)) offset = (tb_int_t)lua_tointeger(lua, 2); - else xm_libc_return_error(lua, "libc.setbyte(invalid offset)!"); + else + xm_libc_return_error(lua, "libc.setbyte(invalid offset)!"); // set byte if (lua_isnumber(lua, 3)) - ((tb_byte_t*)data)[offset] = (tb_byte_t)lua_tointeger(lua, 3); - else xm_libc_return_error(lua, "libc.setbyte(invalid value)!"); + ((tb_byte_t *)data)[offset] = (tb_byte_t)lua_tointeger(lua, 3); + else + xm_libc_return_error(lua, "libc.setbyte(invalid value)!"); return 0; } - - diff --git a/core/src/xmake/libc/strndup.c b/core/src/xmake/libc/strndup.c index f8b32b27d..d7d1204a0 100644 --- a/core/src/xmake/libc/strndup.c +++ b/core/src/xmake/libc/strndup.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "strndup" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "strndup" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,22 +33,22 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_libc_strndup(lua_State* lua) -{ +tb_int_t xm_libc_strndup(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // do strndup - tb_char_t const* s = tb_null; + tb_char_t const *s = tb_null; if (lua_isnumber(lua, 1)) - s = (tb_char_t const*)(tb_size_t)lua_tointeger(lua, 1); + s = (tb_char_t const *)(tb_size_t)lua_tointeger(lua, 1); else if (lua_isstring(lua, 2)) s = lua_tostring(lua, 2); - else xm_libc_return_error(lua, "libc.strndup(invalid args)!"); + else + xm_libc_return_error(lua, "libc.strndup(invalid args)!"); tb_int_t n = (tb_int_t)lua_tointeger(lua, 2); if (s && n >= 0) lua_pushlstring(lua, s, n); - else lua_pushliteral(lua, ""); + else + lua_pushliteral(lua, ""); return 1; } - diff --git a/core/src/xmake/lz4/block_compress.c b/core/src/xmake/lz4/block_compress.c index 8e07cea24..2c7f0c00f 100644 --- a/core/src/xmake/lz4/block_compress.c +++ b/core/src/xmake/lz4/block_compress.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "block_compress" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "block_compress" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,18 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_block_compress(lua_State* lua) -{ +tb_int_t xm_lz4_block_compress(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get data and size tb_int_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) size = (tb_int_t)lua_tointeger(lua, 2); - if (!data || !size || size > LZ4_MAX_INPUT_SIZE) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 1)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_lua_isinteger(lua, 2)) + size = (tb_int_t)lua_tointeger(lua, 2); + if (!data || !size || size > LZ4_MAX_INPUT_SIZE) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -52,30 +52,29 @@ tb_int_t xm_lz4_block_compress(lua_State* lua) tb_assert_static(sizeof(lua_Integer) >= sizeof(tb_pointer_t)); // do compress - tb_bool_t ok = tb_false; - tb_byte_t* output_data = tb_null; - tb_byte_t buffer[8192]; - do - { + tb_bool_t ok = tb_false; + tb_byte_t *output_data = tb_null; + tb_byte_t buffer[8192]; + do { tb_int_t output_size = LZ4_compressBound(size); tb_assert_and_check_break(output_size); - output_data = output_size <= sizeof(buffer)? buffer : (tb_byte_t*)tb_malloc(output_size); + output_data = output_size <= sizeof(buffer) ? buffer : (tb_byte_t *)tb_malloc(output_size); tb_assert_and_check_break(output_data); - tb_int_t real = LZ4_compress_default((tb_char_t const*)data, (tb_char_t*)output_data, size, output_size); + tb_int_t real = LZ4_compress_default((tb_char_t const *)data, (tb_char_t *)output_data, size, output_size); tb_assert_and_check_break(real > 0); - lua_pushlstring(lua, (tb_char_t const*)output_data, real); + lua_pushlstring(lua, (tb_char_t const *)output_data, real); ok = tb_true; } while (0); - if (output_data && output_data != buffer) - { + if (output_data && output_data != buffer) { tb_free(output_data); output_data = tb_null; } - if (!ok) lua_pushnil(lua); + if (!ok) + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/lz4/block_decompress.c b/core/src/xmake/lz4/block_decompress.c index c62b81489..f2f76a4bf 100644 --- a/core/src/xmake/lz4/block_decompress.c +++ b/core/src/xmake/lz4/block_decompress.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "block_decompress" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "block_decompress" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,18 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_block_decompress(lua_State* lua) -{ +tb_int_t xm_lz4_block_decompress(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 1)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_lua_isinteger(lua, 2)) + size = (tb_size_t)lua_tointeger(lua, 2); + if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -53,36 +53,33 @@ tb_int_t xm_lz4_block_decompress(lua_State* lua) // get real size tb_int_t real = (tb_int_t)lua_tointeger(lua, 3); - if (real <= 0) - { + if (real <= 0) { lua_pushnil(lua); lua_pushfstring(lua, "invalid output size(%d)!", real); return 2; } // do decompress - tb_bool_t ok = tb_false; - tb_byte_t* output_data = tb_null; - tb_byte_t buffer[8192]; - do - { - output_data = real <= sizeof(buffer)? buffer : (tb_byte_t*)tb_malloc(real); + tb_bool_t ok = tb_false; + tb_byte_t *output_data = tb_null; + tb_byte_t buffer[8192]; + do { + output_data = real <= sizeof(buffer) ? buffer : (tb_byte_t *)tb_malloc(real); tb_assert_and_check_break(output_data); - tb_int_t r = LZ4_decompress_safe((tb_char_t const*)data, (tb_char_t*)output_data, (tb_int_t)size, real); + tb_int_t r = LZ4_decompress_safe((tb_char_t const *)data, (tb_char_t *)output_data, (tb_int_t)size, real); tb_assert_and_check_break(r > 0); - lua_pushlstring(lua, (tb_char_t const*)output_data, r); + lua_pushlstring(lua, (tb_char_t const *)output_data, r); ok = tb_true; } while (0); - if (output_data && output_data != buffer) - { + if (output_data && output_data != buffer) { tb_free(output_data); output_data = tb_null; } - if (!ok) lua_pushnil(lua); + if (!ok) + lua_pushnil(lua); return 1; } - diff --git a/core/src/xmake/lz4/compress.c b/core/src/xmake/lz4/compress.c index 50ddc509c..352945d1f 100644 --- a/core/src/xmake/lz4/compress.c +++ b/core/src/xmake/lz4/compress.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "compress" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "compress" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,18 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_compress(lua_State* lua) -{ +tb_int_t xm_lz4_compress(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 1)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_lua_isinteger(lua, 2)) + size = (tb_size_t)lua_tointeger(lua, 2); + if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -52,39 +52,35 @@ tb_int_t xm_lz4_compress(lua_State* lua) tb_assert_static(sizeof(lua_Integer) >= sizeof(tb_pointer_t)); // do compress - tb_bool_t ok = tb_false; - tb_char_t const* error = tb_null; - tb_byte_t* output_data = tb_null; - tb_byte_t buffer[8192]; - do - { + tb_bool_t ok = tb_false; + tb_char_t const *error = tb_null; + tb_byte_t *output_data = tb_null; + tb_byte_t buffer[8192]; + do { tb_size_t output_size = LZ4F_compressFrameBound(size, tb_null); tb_assert_and_check_break(output_size); - output_data = output_size <= sizeof(buffer)? buffer : (tb_byte_t*)tb_malloc(output_size); + output_data = output_size <= sizeof(buffer) ? buffer : (tb_byte_t *)tb_malloc(output_size); tb_assert_and_check_break(output_data); tb_size_t real_or_errs = LZ4F_compressFrame(output_data, output_size, data, size, tb_null); - if (LZ4F_isError(real_or_errs)) - { + if (LZ4F_isError(real_or_errs)) { error = LZ4F_getErrorName(real_or_errs); break; } - lua_pushlstring(lua, (tb_char_t const*)output_data, real_or_errs); + lua_pushlstring(lua, (tb_char_t const *)output_data, real_or_errs); ok = tb_true; } while (0); - if (output_data && output_data != buffer) - { + if (output_data && output_data != buffer) { tb_free(output_data); output_data = tb_null; } - if (!ok) - { + if (!ok) { lua_pushnil(lua); - lua_pushstring(lua, error? error : "unknown"); + lua_pushstring(lua, error ? error : "unknown"); return 2; } return 1; diff --git a/core/src/xmake/lz4/compress_file.c b/core/src/xmake/lz4/compress_file.c index 662213864..be48184bd 100644 --- a/core/src/xmake/lz4/compress_file.c +++ b/core/src/xmake/lz4/compress_file.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "compress_file" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "compress_file" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,51 +33,46 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_compress_file(lua_State* lua) -{ +tb_int_t xm_lz4_compress_file(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the file paths - tb_char_t const* srcpath = luaL_checkstring(lua, 1); - tb_char_t const* dstpath = luaL_checkstring(lua, 2); + tb_char_t const *srcpath = luaL_checkstring(lua, 1); + tb_char_t const *dstpath = luaL_checkstring(lua, 2); tb_check_return_val(srcpath && dstpath, 0); // init lz4 stream - xm_lz4_cstream_t* stream_lz4 = xm_lz4_cstream_init(); + xm_lz4_cstream_t *stream_lz4 = xm_lz4_cstream_init(); tb_check_return_val(stream_lz4, 0); // do compress - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_stream_ref_t istream = tb_stream_init_from_file(srcpath, TB_FILE_MODE_RO); - tb_stream_ref_t ostream = tb_stream_init_from_file(dstpath, TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC); - if (istream && ostream && tb_stream_open(istream) && tb_stream_open(ostream)) - { + tb_stream_ref_t ostream = tb_stream_init_from_file(dstpath, + TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC); + if (istream && ostream && tb_stream_open(istream) && tb_stream_open(ostream)) { tb_bool_t write_ok = tb_false; tb_byte_t idata[TB_STREAM_BLOCK_MAXN]; tb_byte_t odata[TB_STREAM_BLOCK_MAXN]; - while (!tb_stream_beof(istream)) - { - write_ok = tb_false; + while (!tb_stream_beof(istream)) { + write_ok = tb_false; tb_long_t ireal = (tb_long_t)tb_stream_read(istream, idata, sizeof(idata)); - if (ireal > 0) - { + if (ireal > 0) { tb_long_t r = xm_lz4_cstream_write(stream_lz4, idata, ireal, tb_stream_beof(istream)); tb_assert_and_check_break(r >= 0); tb_check_continue(r > 0); tb_long_t oreal; - while ((oreal = xm_lz4_cstream_read(stream_lz4, odata, sizeof(odata))) > 0) - { - if (!tb_stream_bwrit(ostream, odata, oreal)) - { + while ((oreal = xm_lz4_cstream_read(stream_lz4, odata, sizeof(odata))) > 0) { + if (!tb_stream_bwrit(ostream, odata, oreal)) { oreal = -1; break; } } tb_assert_and_check_break(oreal >= 0); - } - else break; + } else + break; write_ok = tb_true; } @@ -86,13 +81,11 @@ tb_int_t xm_lz4_compress_file(lua_State* lua) } // exit stream - if (istream) - { + if (istream) { tb_stream_exit(istream); istream = tb_null; } - if (ostream) - { + if (ostream) { tb_stream_exit(ostream); ostream = tb_null; } diff --git a/core/src/xmake/lz4/compress_stream_close.c b/core/src/xmake/lz4/compress_stream_close.c index e4866c479..2bec169d0 100644 --- a/core/src/xmake/lz4/compress_stream_close.c +++ b/core/src/xmake/lz4/compress_stream_close.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "compress_stream_close" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "compress_stream_close" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_compress_stream_close(lua_State* lua) -{ +tb_int_t xm_lz4_compress_stream_close(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -43,7 +42,7 @@ tb_int_t xm_lz4_compress_stream_close(lua_State* lua) return 0; // get the stream - xm_lz4_cstream_t* stream = (xm_lz4_cstream_t*)xm_lua_topointer(lua, 1); + xm_lz4_cstream_t *stream = (xm_lz4_cstream_t *)xm_lua_topointer(lua, 1); tb_check_return_val(stream, 0); // exit stream @@ -53,4 +52,3 @@ tb_int_t xm_lz4_compress_stream_close(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/lz4/compress_stream_open.c b/core/src/xmake/lz4/compress_stream_open.c index e48201095..e4fd1de8b 100644 --- a/core/src/xmake/lz4/compress_stream_open.c +++ b/core/src/xmake/lz4/compress_stream_open.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "compress_stream_open" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "compress_stream_open" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,14 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_compress_stream_open(lua_State* lua) -{ +tb_int_t xm_lz4_compress_stream_open(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); - xm_lz4_cstream_t* stream = xm_lz4_cstream_init(); - if (stream) xm_lua_pushpointer(lua, (tb_pointer_t)stream); - else lua_pushnil(lua); + xm_lz4_cstream_t *stream = xm_lz4_cstream_init(); + if (stream) + xm_lua_pushpointer(lua, (tb_pointer_t)stream); + else + lua_pushnil(lua); return 1; } - diff --git a/core/src/xmake/lz4/compress_stream_read.c b/core/src/xmake/lz4/compress_stream_read.c index 1418a797f..7338ede02 100644 --- a/core/src/xmake/lz4/compress_stream_read.c +++ b/core/src/xmake/lz4/compress_stream_read.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "compress_stream_read" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "compress_stream_read" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,29 +34,26 @@ * implementation */ -tb_int_t xm_lz4_compress_stream_read(lua_State* lua) -{ +tb_int_t xm_lz4_compress_stream_read(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check handle - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid handle!"); return 2; } // get stream - xm_lz4_cstream_t* stream = (xm_lz4_cstream_t*)xm_lua_topointer(lua, 1); + xm_lz4_cstream_t *stream = (xm_lz4_cstream_t *)xm_lua_topointer(lua, 1); tb_check_return_val(stream, 0); // get data - tb_byte_t* data = tb_null; + tb_byte_t *data = tb_null; if (xm_lua_isinteger(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (!data) - { + data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; @@ -65,9 +62,9 @@ tb_int_t xm_lz4_compress_stream_read(lua_State* lua) // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); - if (size <= 0) - { + if (xm_lua_isinteger(lua, 3)) + size = (tb_long_t)lua_tointeger(lua, 3); + if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); return 2; diff --git a/core/src/xmake/lz4/compress_stream_write.c b/core/src/xmake/lz4/compress_stream_write.c index a805cea5f..aa6b87e85 100644 --- a/core/src/xmake/lz4/compress_stream_write.c +++ b/core/src/xmake/lz4/compress_stream_write.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "compress_stream_write" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "compress_stream_write" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,30 +34,29 @@ * implementation */ -tb_int_t xm_lz4_compress_stream_write(lua_State* lua) -{ +tb_int_t xm_lz4_compress_stream_write(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check handle - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid handle!"); return 2; } // get stream - xm_lz4_cstream_t* stream = (xm_lz4_cstream_t*)xm_lua_topointer(lua, 1); + xm_lz4_cstream_t *stream = (xm_lz4_cstream_t *)xm_lua_topointer(lua, 1); tb_check_return_val(stream, 0); // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 2)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_lua_isinteger(lua, 3)) + size = (tb_size_t)lua_tointeger(lua, 3); + if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -66,7 +65,8 @@ tb_int_t xm_lz4_compress_stream_write(lua_State* lua) // is end? tb_bool_t end = tb_false; - if (lua_isboolean(lua, 4)) end = lua_toboolean(lua, 4); + if (lua_isboolean(lua, 4)) + end = lua_toboolean(lua, 4); // write data tb_long_t real = xm_lz4_cstream_write(stream, data, size, end); diff --git a/core/src/xmake/lz4/decompress.c b/core/src/xmake/lz4/decompress.c index 1221cc042..c5382747d 100644 --- a/core/src/xmake/lz4/decompress.c +++ b/core/src/xmake/lz4/decompress.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "decompress" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "decompress" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,18 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_decompress(lua_State* lua) -{ +tb_int_t xm_lz4_decompress(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 1)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) size = (tb_size_t)lua_tointeger(lua, 2); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 1)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); + if (xm_lua_isinteger(lua, 2)) + size = (tb_size_t)lua_tointeger(lua, 2); + if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; @@ -52,31 +52,30 @@ tb_int_t xm_lz4_decompress(lua_State* lua) tb_assert_static(sizeof(lua_Integer) >= sizeof(tb_pointer_t)); // do decompress - tb_bool_t ok = tb_false; - LZ4F_errorCode_t code; + tb_bool_t ok = tb_false; + LZ4F_errorCode_t code; LZ4F_decompressionContext_t ctx = tb_null; - tb_buffer_t result; - do - { + tb_buffer_t result; + do { tb_buffer_init(&result); code = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION); - if (LZ4F_isError(code)) break; + if (LZ4F_isError(code)) + break; tb_byte_t buffer[8192]; tb_bool_t failed = tb_false; - while (1) - { - size_t advance = (size_t)size; + while (1) { + size_t advance = (size_t)size; size_t buffer_size = sizeof(buffer); - code = LZ4F_decompress(ctx, buffer, &buffer_size, data, &advance, tb_null); - if (LZ4F_isError(code)) - { + code = LZ4F_decompress(ctx, buffer, &buffer_size, data, &advance, tb_null); + if (LZ4F_isError(code)) { failed = tb_true; break; } - if (buffer_size == 0) break; + if (buffer_size == 0) + break; data += advance; size -= advance; @@ -84,24 +83,21 @@ tb_int_t xm_lz4_decompress(lua_State* lua) } tb_assert_and_check_break(!failed && tb_buffer_size(&result)); - lua_pushlstring(lua, (tb_char_t const*)tb_buffer_data(&result), tb_buffer_size(&result)); + lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&result), tb_buffer_size(&result)); ok = tb_true; } while (0); - if (ctx) - { + if (ctx) { LZ4F_freeDecompressionContext(ctx); ctx = tb_null; } tb_buffer_exit(&result); - if (!ok) - { - tb_char_t const* error = LZ4F_getErrorName(code); + if (!ok) { + tb_char_t const *error = LZ4F_getErrorName(code); lua_pushnil(lua); - lua_pushstring(lua, error? error : "unknown"); + lua_pushstring(lua, error ? error : "unknown"); return 2; } return 1; } - diff --git a/core/src/xmake/lz4/decompress_file.c b/core/src/xmake/lz4/decompress_file.c index 533d677c6..b65ee87a0 100644 --- a/core/src/xmake/lz4/decompress_file.c +++ b/core/src/xmake/lz4/decompress_file.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "dedecompress_file" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "dedecompress_file" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,51 +33,46 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_decompress_file(lua_State* lua) -{ +tb_int_t xm_lz4_decompress_file(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the file paths - tb_char_t const* srcpath = luaL_checkstring(lua, 1); - tb_char_t const* dstpath = luaL_checkstring(lua, 2); + tb_char_t const *srcpath = luaL_checkstring(lua, 1); + tb_char_t const *dstpath = luaL_checkstring(lua, 2); tb_check_return_val(srcpath && dstpath, 0); // init lz4 stream - xm_lz4_dstream_t* stream_lz4 = xm_lz4_dstream_init(); + xm_lz4_dstream_t *stream_lz4 = xm_lz4_dstream_init(); tb_check_return_val(stream_lz4, 0); // do decompress - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_stream_ref_t istream = tb_stream_init_from_file(srcpath, TB_FILE_MODE_RO); - tb_stream_ref_t ostream = tb_stream_init_from_file(dstpath, TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC); - if (istream && ostream && tb_stream_open(istream) && tb_stream_open(ostream)) - { + tb_stream_ref_t ostream = tb_stream_init_from_file(dstpath, + TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC); + if (istream && ostream && tb_stream_open(istream) && tb_stream_open(ostream)) { tb_bool_t write_ok = tb_false; tb_byte_t idata[TB_STREAM_BLOCK_MAXN]; tb_byte_t odata[TB_STREAM_BLOCK_MAXN]; - while (!tb_stream_beof(istream)) - { - write_ok = tb_false; + while (!tb_stream_beof(istream)) { + write_ok = tb_false; tb_long_t ireal = (tb_long_t)tb_stream_read(istream, idata, sizeof(idata)); - if (ireal > 0) - { + if (ireal > 0) { tb_long_t r = xm_lz4_dstream_write(stream_lz4, idata, ireal, tb_stream_beof(istream)); tb_assert_and_check_break(r >= 0); tb_check_continue(r > 0); tb_long_t oreal; - while ((oreal = xm_lz4_dstream_read(stream_lz4, odata, sizeof(odata))) > 0) - { - if (!tb_stream_bwrit(ostream, odata, oreal)) - { + while ((oreal = xm_lz4_dstream_read(stream_lz4, odata, sizeof(odata))) > 0) { + if (!tb_stream_bwrit(ostream, odata, oreal)) { oreal = -1; break; } } tb_assert_and_check_break(oreal >= 0); - } - else break; + } else + break; write_ok = tb_true; } @@ -86,13 +81,11 @@ tb_int_t xm_lz4_decompress_file(lua_State* lua) } // exit stream - if (istream) - { + if (istream) { tb_stream_exit(istream); istream = tb_null; } - if (ostream) - { + if (ostream) { tb_stream_exit(ostream); ostream = tb_null; } @@ -102,4 +95,3 @@ tb_int_t xm_lz4_decompress_file(lua_State* lua) lua_pushboolean(lua, ok); return 1; } - diff --git a/core/src/xmake/lz4/decompress_stream_close.c b/core/src/xmake/lz4/decompress_stream_close.c index 031330e93..ead2e3493 100644 --- a/core/src/xmake/lz4/decompress_stream_close.c +++ b/core/src/xmake/lz4/decompress_stream_close.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "decompress_stream_close" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "decompress_stream_close" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_decompress_stream_close(lua_State* lua) -{ +tb_int_t xm_lz4_decompress_stream_close(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -43,7 +42,7 @@ tb_int_t xm_lz4_decompress_stream_close(lua_State* lua) return 0; // get the stream - xm_lz4_dstream_t* stream = (xm_lz4_dstream_t*)xm_lua_topointer(lua, 1); + xm_lz4_dstream_t *stream = (xm_lz4_dstream_t *)xm_lua_topointer(lua, 1); tb_check_return_val(stream, 0); // exit stream @@ -53,4 +52,3 @@ tb_int_t xm_lz4_decompress_stream_close(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/lz4/decompress_stream_open.c b/core/src/xmake/lz4/decompress_stream_open.c index e9e65b555..673038e80 100644 --- a/core/src/xmake/lz4/decompress_stream_open.c +++ b/core/src/xmake/lz4/decompress_stream_open.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "decompress_stream_open" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "decompress_stream_open" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,14 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_lz4_decompress_stream_open(lua_State* lua) -{ +tb_int_t xm_lz4_decompress_stream_open(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); - xm_lz4_dstream_t* stream = xm_lz4_dstream_init(); - if (stream) xm_lua_pushpointer(lua, (tb_pointer_t)stream); - else lua_pushnil(lua); + xm_lz4_dstream_t *stream = xm_lz4_dstream_init(); + if (stream) + xm_lua_pushpointer(lua, (tb_pointer_t)stream); + else + lua_pushnil(lua); return 1; } - diff --git a/core/src/xmake/lz4/decompress_stream_read.c b/core/src/xmake/lz4/decompress_stream_read.c index 310f639b8..5f6486166 100644 --- a/core/src/xmake/lz4/decompress_stream_read.c +++ b/core/src/xmake/lz4/decompress_stream_read.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "decompress_stream_read" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "decompress_stream_read" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,29 +34,26 @@ * implementation */ -tb_int_t xm_lz4_decompress_stream_read(lua_State* lua) -{ +tb_int_t xm_lz4_decompress_stream_read(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check handle - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid handle!"); return 2; } // get stream - xm_lz4_dstream_t* stream = (xm_lz4_dstream_t*)xm_lua_topointer(lua, 1); + xm_lz4_dstream_t *stream = (xm_lz4_dstream_t *)xm_lua_topointer(lua, 1); tb_check_return_val(stream, 0); // get data - tb_byte_t* data = tb_null; + tb_byte_t *data = tb_null; if (xm_lua_isinteger(lua, 2)) - data = (tb_byte_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (!data) - { + data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); return 2; @@ -65,9 +62,9 @@ tb_int_t xm_lz4_decompress_stream_read(lua_State* lua) // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) size = (tb_long_t)lua_tointeger(lua, 3); - if (size <= 0) - { + if (xm_lua_isinteger(lua, 3)) + size = (tb_long_t)lua_tointeger(lua, 3); + if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); return 2; diff --git a/core/src/xmake/lz4/decompress_stream_write.c b/core/src/xmake/lz4/decompress_stream_write.c index 5f5856b8e..7fa45544c 100644 --- a/core/src/xmake/lz4/decompress_stream_write.c +++ b/core/src/xmake/lz4/decompress_stream_write.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "decompress_stream_write" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "decompress_stream_write" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,30 +34,29 @@ * implementation */ -tb_int_t xm_lz4_decompress_stream_write(lua_State* lua) -{ +tb_int_t xm_lz4_decompress_stream_write(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check handle - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { lua_pushinteger(lua, -1); lua_pushliteral(lua, "invalid handle!"); return 2; } // get stream - xm_lz4_dstream_t* stream = (xm_lz4_dstream_t*)xm_lua_topointer(lua, 1); + xm_lz4_dstream_t *stream = (xm_lz4_dstream_t *)xm_lua_topointer(lua, 1); tb_check_return_val(stream, 0); // get data and size tb_size_t size = 0; - tb_byte_t const* data = tb_null; - if (xm_lua_isinteger(lua, 2)) data = (tb_byte_t const*)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) size = (tb_size_t)lua_tointeger(lua, 3); - if (!data || !size) - { + tb_byte_t const *data = tb_null; + if (xm_lua_isinteger(lua, 2)) + data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + if (xm_lua_isinteger(lua, 3)) + size = (tb_size_t)lua_tointeger(lua, 3); + if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); return 2; diff --git a/core/src/xmake/lz4/prefix.h b/core/src/xmake/lz4/prefix.h index 3b7fdb820..996e53093 100644 --- a/core/src/xmake/lz4/prefix.h +++ b/core/src/xmake/lz4/prefix.h @@ -35,18 +35,18 @@ // we need to define LZ4_byte if < 1.9.3 #if defined(LZ4_VERSION_NUMBER) && LZ4_VERSION_NUMBER < (1 * 100 * 100 + 9 * 100 + 3) -# if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) -# include - typedef int8_t LZ4_i8; - typedef uint8_t LZ4_byte; - typedef uint16_t LZ4_u16; - typedef uint32_t LZ4_u32; -# else - typedef signed char LZ4_i8; - typedef unsigned char LZ4_byte; - typedef unsigned short LZ4_u16; - typedef unsigned int LZ4_u32; -# endif +#if defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) +#include +typedef int8_t LZ4_i8; +typedef uint8_t LZ4_byte; +typedef uint16_t LZ4_u16; +typedef uint32_t LZ4_u32; +#else +typedef signed char LZ4_i8; +typedef unsigned char LZ4_byte; +typedef unsigned short LZ4_u16; +typedef unsigned int LZ4_u32; +#endif #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -54,43 +54,37 @@ */ // the lz4 compress stream type -typedef struct __xm_lz4_cstream_t -{ - LZ4F_cctx* cctx; - LZ4_byte* buffer; - tb_size_t buffer_size; - tb_size_t buffer_maxn; - tb_size_t write_maxn; - tb_size_t header_size; - LZ4_byte header[LZ4F_HEADER_SIZE_MAX]; -}xm_lz4_cstream_t; +typedef struct __xm_lz4_cstream_t { + LZ4F_cctx *cctx; + LZ4_byte *buffer; + tb_size_t buffer_size; + tb_size_t buffer_maxn; + tb_size_t write_maxn; + tb_size_t header_size; + LZ4_byte header[LZ4F_HEADER_SIZE_MAX]; +} xm_lz4_cstream_t; // the lz4 decompress stream type -typedef struct __xm_lz4_dstream_t -{ - LZ4F_dctx* dctx; - LZ4_byte* buffer; - tb_size_t buffer_size; - tb_size_t buffer_maxn; - tb_size_t header_size; - LZ4_byte header[LZ4F_HEADER_SIZE_MAX]; -}xm_lz4_dstream_t; +typedef struct __xm_lz4_dstream_t { + LZ4F_dctx *dctx; + LZ4_byte *buffer; + tb_size_t buffer_size; + tb_size_t buffer_maxn; + tb_size_t header_size; + LZ4_byte header[LZ4F_HEADER_SIZE_MAX]; +} xm_lz4_dstream_t; /* ////////////////////////////////////////////////////////////////////////////////////// * interfaces */ -static __tb_inline__ tb_void_t xm_lz4_cstream_exit(xm_lz4_cstream_t* stream) -{ - if (stream) - { - if (stream->cctx) - { +static __tb_inline__ tb_void_t xm_lz4_cstream_exit(xm_lz4_cstream_t *stream) { + if (stream) { + if (stream->cctx) { LZ4F_freeCompressionContext(stream->cctx); stream->cctx = tb_null; } - if (stream->buffer) - { + if (stream->buffer) { tb_free(stream->buffer); stream->buffer = tb_null; } @@ -98,20 +92,18 @@ static __tb_inline__ tb_void_t xm_lz4_cstream_exit(xm_lz4_cstream_t* stream) } } -static __tb_inline__ xm_lz4_cstream_t* xm_lz4_cstream_init() -{ - tb_size_t ret; - tb_bool_t ok = tb_false; - xm_lz4_cstream_t* stream = tb_null; - LZ4F_preferences_t const* prefsPtr = tb_null; - do - { +static __tb_inline__ xm_lz4_cstream_t *xm_lz4_cstream_init() { + tb_size_t ret; + tb_bool_t ok = tb_false; + xm_lz4_cstream_t *stream = tb_null; + LZ4F_preferences_t const *prefsPtr = tb_null; + do { stream = tb_malloc0_type(xm_lz4_cstream_t); tb_assert_and_check_break(stream); - stream->write_maxn = 64 * 1024; + stream->write_maxn = 64 * 1024; stream->buffer_maxn = LZ4F_compressBound(stream->write_maxn, prefsPtr); - stream->buffer = (LZ4_byte*)tb_malloc(stream->buffer_maxn); + stream->buffer = (LZ4_byte *)tb_malloc(stream->buffer_maxn); tb_assert_and_check_break(stream->buffer); ret = LZ4F_createCompressionContext(&stream->cctx, LZ4F_getVersion()); @@ -128,31 +120,37 @@ static __tb_inline__ xm_lz4_cstream_t* xm_lz4_cstream_init() } while (0); - if (!ok && stream) - { + if (!ok && stream) { xm_lz4_cstream_exit(stream); stream = tb_null; } return stream; } -static __tb_inline__ tb_long_t xm_lz4_cstream_write(xm_lz4_cstream_t* stream, tb_byte_t const* idata, tb_size_t isize, tb_bool_t end) -{ +static __tb_inline__ tb_long_t xm_lz4_cstream_write(xm_lz4_cstream_t *stream, + tb_byte_t const *idata, + tb_size_t isize, + tb_bool_t end) { // check tb_assert_and_check_return_val(stream && stream->cctx && idata && isize, -1); tb_assert_and_check_return_val(isize <= stream->write_maxn, -1); tb_assert_and_check_return_val(stream->buffer_size + isize < stream->buffer_maxn, -1); - tb_size_t real = LZ4F_compressUpdate(stream->cctx, stream->buffer + stream->buffer_size, - stream->buffer_maxn - stream->buffer_size, idata, isize, tb_null); + tb_size_t real = LZ4F_compressUpdate(stream->cctx, + stream->buffer + stream->buffer_size, + stream->buffer_maxn - stream->buffer_size, + idata, + isize, + tb_null); if (LZ4F_isError(real)) return -1; stream->buffer_size += real; - if (end) - { - tb_size_t ret = LZ4F_compressEnd(stream->cctx, stream->buffer + stream->buffer_size, - stream->buffer_maxn - stream->buffer_size, tb_null); + if (end) { + tb_size_t ret = LZ4F_compressEnd(stream->cctx, + stream->buffer + stream->buffer_size, + stream->buffer_maxn - stream->buffer_size, + tb_null); if (LZ4F_isError(ret)) return -1; @@ -163,15 +161,13 @@ static __tb_inline__ tb_long_t xm_lz4_cstream_write(xm_lz4_cstream_t* stream, tb return isize; } -static __tb_inline__ tb_long_t xm_lz4_cstream_read(xm_lz4_cstream_t* stream, tb_byte_t* odata, tb_size_t osize) -{ +static __tb_inline__ tb_long_t xm_lz4_cstream_read(xm_lz4_cstream_t *stream, tb_byte_t *odata, tb_size_t osize) { // check tb_assert_and_check_return_val(stream && stream->cctx && odata && osize, -1); tb_assert_and_check_return_val(osize >= stream->header_size, -1); tb_size_t read = 0; - if (stream->header_size) - { + if (stream->header_size) { tb_memcpy(odata, stream->header, stream->header_size); read += stream->header_size; osize -= stream->header_size; @@ -187,17 +183,13 @@ static __tb_inline__ tb_long_t xm_lz4_cstream_read(xm_lz4_cstream_t* stream, tb_ return read; } -static __tb_inline__ tb_void_t xm_lz4_dstream_exit(xm_lz4_dstream_t* stream) -{ - if (stream) - { - if (stream->dctx) - { +static __tb_inline__ tb_void_t xm_lz4_dstream_exit(xm_lz4_dstream_t *stream) { + if (stream) { + if (stream->dctx) { LZ4F_freeDecompressionContext(stream->dctx); stream->dctx = tb_null; } - if (stream->buffer) - { + if (stream->buffer) { tb_free(stream->buffer); stream->buffer = tb_null; } @@ -205,13 +197,11 @@ static __tb_inline__ tb_void_t xm_lz4_dstream_exit(xm_lz4_dstream_t* stream) } } -static __tb_inline__ xm_lz4_dstream_t* xm_lz4_dstream_init() -{ - LZ4F_errorCode_t ret; - tb_bool_t ok = tb_false; - xm_lz4_dstream_t* stream = tb_null; - do - { +static __tb_inline__ xm_lz4_dstream_t *xm_lz4_dstream_init() { + LZ4F_errorCode_t ret; + tb_bool_t ok = tb_false; + xm_lz4_dstream_t *stream = tb_null; + do { stream = tb_malloc0_type(xm_lz4_dstream_t); tb_assert_and_check_break(stream); @@ -223,23 +213,23 @@ static __tb_inline__ xm_lz4_dstream_t* xm_lz4_dstream_init() } while (0); - if (!ok && stream) - { + if (!ok && stream) { xm_lz4_dstream_exit(stream); stream = tb_null; } return stream; } -static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t* stream, tb_byte_t const* idata, tb_size_t isize, tb_bool_t end) -{ +static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t *stream, + tb_byte_t const *idata, + tb_size_t isize, + tb_bool_t end) { // check tb_assert_and_check_return_val(stream && stream->dctx && idata && isize, -1); // read header first const tb_size_t header_size = sizeof(stream->header); - if (stream->header_size < header_size) - { + if (stream->header_size < header_size) { tb_size_t size = tb_min(header_size - stream->header_size, isize); tb_memcpy(stream->header + stream->header_size, idata, size); stream->header_size += size; @@ -247,16 +237,14 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t* stream, tb isize -= size; // get frame info if header is ok - if (stream->header_size == header_size) - { + if (stream->header_size == header_size) { LZ4F_frameInfo_t info; - size_t consumed_size = header_size; - LZ4F_errorCode_t ret = LZ4F_getFrameInfo(stream->dctx, &info, stream->header, &consumed_size); + size_t consumed_size = header_size; + LZ4F_errorCode_t ret = LZ4F_getFrameInfo(stream->dctx, &info, stream->header, &consumed_size); if (LZ4F_isError(ret)) return -1; - switch (info.blockSizeID) - { + switch (info.blockSizeID) { case LZ4F_default: case LZ4F_max64KB: stream->buffer_maxn = 64 * 1024; @@ -274,7 +262,7 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t* stream, tb return -1; } - stream->buffer = (LZ4_byte*)tb_malloc(stream->buffer_maxn); + stream->buffer = (LZ4_byte *)tb_malloc(stream->buffer_maxn); tb_assert_and_check_return_val(stream->buffer, -1); stream->buffer_size = header_size - consumed_size; @@ -290,16 +278,15 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t* stream, tb return isize; } -static __tb_inline__ tb_long_t xm_lz4_dstream_read(xm_lz4_dstream_t* stream, tb_byte_t* odata, tb_size_t osize) -{ +static __tb_inline__ tb_long_t xm_lz4_dstream_read(xm_lz4_dstream_t *stream, tb_byte_t *odata, tb_size_t osize) { // check tb_assert_and_check_return_val(stream && stream->dctx && stream->buffer && odata && osize, -1); tb_check_return_val(stream->buffer_size, 0); // do decompress - size_t srcsize = stream->buffer_size; - size_t dstsize = osize; - tb_size_t ret = LZ4F_decompress(stream->dctx, odata, &dstsize, stream->buffer, &srcsize, tb_null); + size_t srcsize = stream->buffer_size; + size_t dstsize = osize; + tb_size_t ret = LZ4F_decompress(stream->dctx, odata, &dstsize, stream->buffer, &srcsize, tb_null); if (LZ4F_isError(ret)) return -1; @@ -311,5 +298,3 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_read(xm_lz4_dstream_t* stream, tb_ } #endif - - diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c index f93a8d0db..d220e0350 100644 --- a/core/src/xmake/os/args.c +++ b/core/src/xmake/os/args.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "os.args" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "os.args" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,31 +33,30 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t tb_os_args_append(tb_string_ref_t result, tb_char_t const* cstr, tb_size_t size, tb_bool_t escape, tb_bool_t nowrap) -{ +static tb_void_t tb_os_args_append( + tb_string_ref_t result, tb_char_t const *cstr, tb_size_t size, tb_bool_t escape, tb_bool_t nowrap) { // check tb_assert_and_check_return(size < TB_PATH_MAXN); // need wrap quote? - tb_char_t ch; - tb_char_t const* p = cstr; - tb_bool_t wrap_quote = tb_false; - if (!nowrap) - { - while ((ch = *p)) - { - if (ch == ' ') wrap_quote = tb_true; + tb_char_t ch; + tb_char_t const *p = cstr; + tb_bool_t wrap_quote = tb_false; + if (!nowrap) { + while ((ch = *p)) { + if (ch == ' ') + wrap_quote = tb_true; p++; } } // wrap begin quote - if (wrap_quote) tb_string_chrcat(result, '\"'); + if (wrap_quote) + tb_string_chrcat(result, '\"'); // escape characters p = cstr; - while ((ch = *p)) - { + while ((ch = *p)) { // escape '"' or '\\' if (ch == '\"' || ((escape || wrap_quote) && ch == '\\')) tb_string_chrcat(result, '\\'); @@ -66,22 +65,21 @@ static tb_void_t tb_os_args_append(tb_string_ref_t result, tb_char_t const* cstr } // wrap end quote - if (wrap_quote) tb_string_chrcat(result, '\"'); + if (wrap_quote) + tb_string_chrcat(result, '\"'); } /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ // os.args({"xx", "yy"}, {escape = true}) -tb_int_t xm_os_args(lua_State* lua) -{ +tb_int_t xm_os_args(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // escape '\\' characters in global? tb_bool_t escape = tb_false; - if (lua_istable(lua, 2)) - { + if (lua_istable(lua, 2)) { // is escape? lua_pushstring(lua, "escape"); lua_gettable(lua, 2); @@ -91,8 +89,7 @@ tb_int_t xm_os_args(lua_State* lua) // disable to wrap quote characters in global? tb_bool_t nowrap = tb_false; - if (lua_istable(lua, 2)) - { + if (lua_istable(lua, 2)) { // is nowrap? lua_pushstring(lua, "nowrap"); lua_gettable(lua, 2); @@ -105,14 +102,13 @@ tb_int_t xm_os_args(lua_State* lua) tb_string_init(&result); // make string from arguments list - if (lua_istable(lua, 1)) - { + if (lua_istable(lua, 1)) { tb_size_t i = 0; tb_size_t n = (tb_size_t)lua_objlen(lua, 1); - for (i = 1; i <= n; i++) - { + for (i = 1; i <= n; i++) { // add space - if (i != 1) tb_string_chrcat(&result, ' '); + if (i != 1) + tb_string_chrcat(&result, ' '); // add argument lua_pushnumber(lua, (tb_int_t)i); @@ -121,34 +117,32 @@ tb_int_t xm_os_args(lua_State* lua) { lua_pushstring(lua, "_STR"); lua_gettable(lua, -2); - size_t size = 0; - tb_char_t const* cstr = luaL_checklstring(lua, -1, &size); + size_t size = 0; + tb_char_t const *cstr = luaL_checklstring(lua, -1, &size); if (cstr && size) tb_os_args_append(&result, cstr, size, escape, nowrap); lua_pop(lua, 1); - } - else - { - size_t size = 0; - tb_char_t const* cstr = luaL_checklstring(lua, -1, &size); + } else { + size_t size = 0; + tb_char_t const *cstr = luaL_checklstring(lua, -1, &size); if (cstr && size) tb_os_args_append(&result, cstr, size, escape, nowrap); } lua_pop(lua, 1); } - } - else - { - size_t size = 0; - tb_char_t const* cstr = luaL_checklstring(lua, 1, &size); + } else { + size_t size = 0; + tb_char_t const *cstr = luaL_checklstring(lua, 1, &size); if (cstr && size) tb_os_args_append(&result, cstr, size, escape, nowrap); } // return result tb_size_t size = tb_string_size(&result); - if (size) lua_pushlstring(lua, tb_string_cstr(&result), size); - else lua_pushliteral(lua, ""); + if (size) + lua_pushlstring(lua, tb_string_cstr(&result), size); + else + lua_pushliteral(lua, ""); tb_string_exit(&result); return 1; } diff --git a/core/src/xmake/os/argv.c b/core/src/xmake/os/argv.c index 023235e9a..89635fb2d 100644 --- a/core/src/xmake/os/argv.c +++ b/core/src/xmake/os/argv.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "os.argv" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "os.argv" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,19 +33,17 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_argv(lua_State* lua) -{ +tb_int_t xm_os_argv(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the argument string - tb_char_t const* args = luaL_checkstring(lua, 1); + tb_char_t const *args = luaL_checkstring(lua, 1); tb_check_return_val(args, 0); // split only? do not escape tb_bool_t splitonly = tb_false; - if (lua_istable(lua, 2)) - { + if (lua_istable(lua, 2)) { lua_pushstring(lua, "splitonly"); lua_gettable(lua, 2); splitonly = lua_toboolean(lua, -1); @@ -54,39 +52,44 @@ tb_int_t xm_os_argv(lua_State* lua) // parse argument list tb_string_t arg; - do - { + do { // init table lua_newtable(lua); // init arg - if (!tb_string_init(&arg)) break; + if (!tb_string_init(&arg)) + break; // parse command to the arguments - tb_int_t i = 1; - tb_int_t skip = 0; - tb_int_t escape = 0; - tb_char_t quote = 0; - tb_char_t ch = 0; - tb_char_t const* p = args; - while ((ch = *p)) - { + tb_int_t i = 1; + tb_int_t skip = 0; + tb_int_t escape = 0; + tb_char_t quote = 0; + tb_char_t ch = 0; + tb_char_t const *p = args; + while ((ch = *p)) { // no escape now? - if (!escape) - { + if (!escape) { // enter quote? - if (!quote && (ch == '\"' || ch == '\'')) { quote = ch; skip = 1; } + if (!quote && (ch == '\"' || ch == '\'')) { + quote = ch; + skip = 1; + } // leave quote? - else if (ch == quote) { quote = 0; skip = 1; } + else if (ch == quote) { + quote = 0; + skip = 1; + } // escape charactor? only escape \\, \" - else if (ch == '\\' && (p[1] == '\\' || p[1] == '\"')) { escape = 1; skip = 1; } + else if (ch == '\\' && (p[1] == '\\' || p[1] == '\"')) { + escape = 1; + skip = 1; + } // is argument end with ' '? - else if (!quote && tb_isspace(ch)) - { + else if (!quote && tb_isspace(ch)) { // save this argument tb_string_ltrim(&arg); - if (tb_string_size(&arg)) - { + if (tb_string_size(&arg)) { // save argument lua_pushstring(lua, tb_string_cstr(&arg)); lua_rawseti(lua, -2, i++); @@ -98,11 +101,14 @@ tb_int_t xm_os_argv(lua_State* lua) } // save this charactor to argument - if (splitonly || !skip) tb_string_chrcat(&arg, ch); + if (splitonly || !skip) + tb_string_chrcat(&arg, ch); // step and cancel escape - if (escape == 1) escape++; - else if (escape == 2) escape = 0; + if (escape == 1) + escape++; + else if (escape == 2) + escape = 0; // clear skip skip = 0; @@ -113,8 +119,7 @@ tb_int_t xm_os_argv(lua_State* lua) // save this argument tb_string_ltrim(&arg); - if (tb_string_size(&arg)) - { + if (tb_string_size(&arg)) { // save argument lua_pushstring(lua, tb_string_cstr(&arg)); lua_rawseti(lua, -2, i++); diff --git a/core/src/xmake/os/chdir.c b/core/src/xmake/os/chdir.c index b05e71414..537d6506c 100644 --- a/core/src/xmake/os/chdir.c +++ b/core/src/xmake/os/chdir.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "chdir" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "chdir" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,13 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_chdir(lua_State* lua) -{ +tb_int_t xm_os_chdir(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // done os.chdir(path) diff --git a/core/src/xmake/os/cpdir.c b/core/src/xmake/os/cpdir.c index cdae6f173..e2f2b89ee 100644 --- a/core/src/xmake/os/cpdir.c +++ b/core/src/xmake/os/cpdir.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "cpdir" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "cpdir" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,17 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_cpdir(lua_State* lua) -{ +tb_int_t xm_os_cpdir(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the source and destination - tb_char_t const* src = luaL_checkstring(lua, 1); - tb_char_t const* dst = luaL_checkstring(lua, 2); + tb_char_t const *src = luaL_checkstring(lua, 1); + tb_char_t const *dst = luaL_checkstring(lua, 2); tb_check_return_val(src && dst, 0); // init copy flags - tb_size_t flags = TB_FILE_COPY_NONE; + tb_size_t flags = TB_FILE_COPY_NONE; tb_bool_t is_symlink = lua_toboolean(lua, 3); if (is_symlink) flags |= TB_FILE_COPY_LINK; diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c index 7c2c312ce..b6597f87f 100644 --- a/core/src/xmake/os/cpfile.c +++ b/core/src/xmake/os/cpfile.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "cpfile" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "cpfile" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,17 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_cpfile(lua_State* lua) -{ +tb_int_t xm_os_cpfile(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the source and destination - tb_char_t const* src = luaL_checkstring(lua, 1); - tb_char_t const* dst = luaL_checkstring(lua, 2); + tb_char_t const *src = luaL_checkstring(lua, 1); + tb_char_t const *dst = luaL_checkstring(lua, 2); tb_check_return_val(src && dst, 0); // init copy flags - tb_size_t flags = TB_FILE_COPY_NONE; + tb_size_t flags = TB_FILE_COPY_NONE; tb_bool_t is_symlink = lua_toboolean(lua, 3); if (is_symlink) flags |= TB_FILE_COPY_LINK; diff --git a/core/src/xmake/os/cpuinfo.c b/core/src/xmake/os/cpuinfo.c index a2ce4bf26..a2ac1bbe4 100644 --- a/core/src/xmake/os/cpuinfo.c +++ b/core/src/xmake/os/cpuinfo.c @@ -22,37 +22,36 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "cpuinfo" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "cpuinfo" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #if defined(TB_CONFIG_OS_MACOSX) -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include #elif defined(TB_CONFIG_OS_WINDOWS) -# include +#include #elif defined(TB_CONFIG_OS_LINUX) -# include +#include #elif defined(TB_CONFIG_OS_BSD) -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ #if defined(TB_CONFIG_OS_WINDOWS) -static tb_uint64_t xm_os_cpuinfo_subtract_times(FILETIME const* one, FILETIME const* two) -{ +static tb_uint64_t xm_os_cpuinfo_subtract_times(FILETIME const *one, FILETIME const *two) { LARGE_INTEGER a, b; a.LowPart = one->dwLowDateTime; a.HighPart = one->dwHighDateTime; @@ -64,60 +63,59 @@ static tb_uint64_t xm_os_cpuinfo_subtract_times(FILETIME const* one, FILETIME co } #endif -static tb_float_t xm_os_cpuinfo_usagerate() -{ +static tb_float_t xm_os_cpuinfo_usagerate() { #if defined(TB_CONFIG_OS_MACOSX) - tb_float_t usagerate = 0; - natural_t cpu_count = 0; + tb_float_t usagerate = 0; + natural_t cpu_count = 0; processor_info_array_t cpuinfo; mach_msg_type_number_t cpuinfo_count; - static tb_hong_t s_time = 0; - if (tb_mclock() - s_time > 1000 && host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, &cpuinfo, &cpuinfo_count) == KERN_SUCCESS) - { - static processor_info_array_t s_cpuinfo_prev = tb_null; + static tb_hong_t s_time = 0; + if (tb_mclock() - s_time > 1000 && + host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, &cpuinfo, &cpuinfo_count) == + KERN_SUCCESS) { + static processor_info_array_t s_cpuinfo_prev = tb_null; static mach_msg_type_number_t s_cpuinfo_count_prev = 0; - for (tb_int_t i = 0; i < cpu_count; ++i) - { + for (tb_int_t i = 0; i < cpu_count; ++i) { tb_int_t use, total; - if (s_cpuinfo_prev) - { - use = (cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_USER] - s_cpuinfo_prev[(CPU_STATE_MAX * i) + CPU_STATE_USER]) - + (cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_SYSTEM] - s_cpuinfo_prev[(CPU_STATE_MAX * i) + CPU_STATE_SYSTEM]) - + (cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_NICE] - s_cpuinfo_prev[(CPU_STATE_MAX * i) + CPU_STATE_NICE]); - total = use + (cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_IDLE] - s_cpuinfo_prev[(CPU_STATE_MAX * i) + CPU_STATE_IDLE]); - } - else - { - use = cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_USER] + cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_SYSTEM] + cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_NICE]; + if (s_cpuinfo_prev) { + use = (cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_USER] - + s_cpuinfo_prev[(CPU_STATE_MAX * i) + CPU_STATE_USER]) + + (cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_SYSTEM] - + s_cpuinfo_prev[(CPU_STATE_MAX * i) + CPU_STATE_SYSTEM]) + + (cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_NICE] - + s_cpuinfo_prev[(CPU_STATE_MAX * i) + CPU_STATE_NICE]); + total = use + (cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_IDLE] - + s_cpuinfo_prev[(CPU_STATE_MAX * i) + CPU_STATE_IDLE]); + } else { + use = cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_USER] + cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_SYSTEM] + + cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_NICE]; total = use + cpuinfo[(CPU_STATE_MAX * i) + CPU_STATE_IDLE]; } - usagerate += total > 0? ((tb_float_t)use / (tb_float_t)total) : 0; + usagerate += total > 0 ? ((tb_float_t)use / (tb_float_t)total) : 0; } if (s_cpuinfo_prev) vm_deallocate(mach_task_self(), (vm_address_t)s_cpuinfo_prev, sizeof(integer_t) * s_cpuinfo_count_prev); - s_time = tb_mclock(); - s_cpuinfo_prev = cpuinfo; + s_time = tb_mclock(); + s_cpuinfo_prev = cpuinfo; s_cpuinfo_count_prev = cpuinfo_count; } - return cpu_count > 0? usagerate / cpu_count : 0; + return cpu_count > 0 ? usagerate / cpu_count : 0; #elif defined(TB_CONFIG_OS_WINDOWS) // kernel include idle_time tb_float_t usagerate = 0; - FILETIME idle, kernel, user; - if (GetSystemTimes(&idle, &kernel, &user)) - { - static FILETIME idle_prev = {0}; - static FILETIME kernel_prev = {0}; - static FILETIME user_prev = {0}; + FILETIME idle, kernel, user; + if (GetSystemTimes(&idle, &kernel, &user)) { + static FILETIME idle_prev = { 0 }; + static FILETIME kernel_prev = { 0 }; + static FILETIME user_prev = { 0 }; - if (idle_prev.dwLowDateTime != 0 && idle_prev.dwHighDateTime != 0) - { - tb_uint64_t idle_diff = xm_os_cpuinfo_subtract_times(&idle, &idle_prev); + if (idle_prev.dwLowDateTime != 0 && idle_prev.dwHighDateTime != 0) { + tb_uint64_t idle_diff = xm_os_cpuinfo_subtract_times(&idle, &idle_prev); tb_uint64_t kernel_diff = xm_os_cpuinfo_subtract_times(&kernel, &kernel_prev); - tb_uint64_t user_diff = xm_os_cpuinfo_subtract_times(&user, &user_prev); + tb_uint64_t user_diff = xm_os_cpuinfo_subtract_times(&user, &user_prev); // kernel_time - idle_time = kernel_time, because kernel include idle_time - tb_uint64_t sys_total = kernel_diff + user_diff; + tb_uint64_t sys_total = kernel_diff + user_diff; tb_uint64_t kernel_total = kernel_diff - idle_diff; // sometimes kernel_time > idle_time @@ -125,23 +123,20 @@ static tb_float_t xm_os_cpuinfo_usagerate() usagerate = (tb_float_t)((tb_double_t)(kernel_total + user_diff) / sys_total); } - idle_prev = idle; + idle_prev = idle; kernel_prev = kernel; - user_prev = user; + user_prev = user; } return usagerate; #elif defined(TB_CONFIG_OS_LINUX) tb_float_t usagerate = 0; - if (tb_file_info("/proc/stat", tb_null)) - { - FILE* fp = fopen("/proc/stat", "r"); - if (fp) - { - tb_char_t line[8192]; - static tb_int64_t total_prev = 0; + if (tb_file_info("/proc/stat", tb_null)) { + FILE *fp = fopen("/proc/stat", "r"); + if (fp) { + tb_char_t line[8192]; + static tb_int64_t total_prev = 0; static tb_int64_t active_prev = 0; - while (!feof(fp)) - { + while (!feof(fp)) { /* cpu 548760 0 867417 102226682 12430 0 9089 0 0 0 * cpu0 136863 0 218110 25632388 2706 0 2328 0 0 0 * cpu1 148383 0 213941 25627686 3925 0 2129 0 0 0 @@ -159,22 +154,31 @@ static tb_float_t xm_os_cpuinfo_usagerate() * guest * guest_nice */ - if (fgets(line, sizeof(line), fp) && !tb_strncmp(line, "cpu ", 4)) - { + if (fgets(line, sizeof(line), fp) && !tb_strncmp(line, "cpu ", 4)) { long long user, nice, sys, idle, iowait, irq, softirq, steal, guest, guest_nice; - if (10 == sscanf(line, "cpu %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld", - &user, &nice, &sys, &idle, &iowait, &irq, &softirq, &steal, &guest, &guest_nice)) - { - tb_int64_t active = (tb_int64_t)(user + nice + sys + irq + softirq + steal + guest + guest_nice); - tb_int64_t total = (tb_int64_t)(user + nice + sys + idle + iowait + irq + softirq + steal + guest + guest_nice); - if (total_prev > 0 && active_prev > 0) - { - tb_int64_t total_diff = total - total_prev; + if (10 == sscanf(line, + "cpu %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld", + &user, + &nice, + &sys, + &idle, + &iowait, + &irq, + &softirq, + &steal, + &guest, + &guest_nice)) { + tb_int64_t active = (tb_int64_t)(user + nice + sys + irq + softirq + steal + guest + + guest_nice); + tb_int64_t total = (tb_int64_t)(user + nice + sys + idle + iowait + irq + softirq + steal + + guest + guest_nice); + if (total_prev > 0 && active_prev > 0) { + tb_int64_t total_diff = total - total_prev; tb_int64_t active_diff = active - active_prev; if (total_diff > 0) usagerate = (tb_float_t)((tb_double_t)active_diff / total_diff); } - total_prev = total; + total_prev = total; active_prev = active; } break; @@ -185,37 +189,35 @@ static tb_float_t xm_os_cpuinfo_usagerate() } return usagerate; #elif defined(TB_CONFIG_OS_BSD) && !defined(__OpenBSD__) -# define CP_USER 0 -# define CP_NICE 1 -# define CP_SYS 2 -# define CP_INTR 3 -# define CP_IDLE 4 -# define CPUSTATES 5 +#define CP_USER 0 +#define CP_NICE 1 +#define CP_SYS 2 +#define CP_INTR 3 +#define CP_IDLE 4 +#define CPUSTATES 5 - static tb_int64_t total_prev = 0; + static tb_int64_t total_prev = 0; static tb_int64_t active_prev = 0; - tb_float_t usagerate = 0; - long states[CPUSTATES] = {0}; - size_t states_size = sizeof(states); - if (sysctlbyname("kern.cp_time", &states, &states_size, tb_null, 0) == 0) - { + tb_float_t usagerate = 0; + long states[CPUSTATES] = { 0 }; + size_t states_size = sizeof(states); + if (sysctlbyname("kern.cp_time", &states, &states_size, tb_null, 0) == 0) { tb_long_t user = states[CP_USER]; tb_long_t nice = states[CP_NICE]; - tb_long_t sys = states[CP_SYS]; + tb_long_t sys = states[CP_SYS]; tb_long_t intr = states[CP_INTR]; tb_long_t idle = states[CP_IDLE]; tb_int64_t active = user + nice + sys + intr; - tb_int64_t total = user + nice + sys + idle + intr; - if (total_prev > 0 && active_prev > 0) - { - tb_int64_t total_diff = total - total_prev; + tb_int64_t total = user + nice + sys + idle + intr; + if (total_prev > 0 && active_prev > 0) { + tb_int64_t total_diff = total - total_prev; tb_int64_t active_diff = active - active_prev; if (total_diff > 0) usagerate = (tb_float_t)((tb_double_t)active_diff / total_diff); } - total_prev = total; + total_prev = total; active_prev = active; } return usagerate; @@ -234,8 +236,7 @@ static tb_float_t xm_os_cpuinfo_usagerate() * ... * } */ -tb_int_t xm_os_cpuinfo(lua_State* lua) -{ +tb_int_t xm_os_cpuinfo(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -245,13 +246,12 @@ tb_int_t xm_os_cpuinfo(lua_State* lua) // get cpu number tb_int_t ncpu = (tb_int_t)tb_cpu_count(); lua_pushstring(lua, "ncpu"); - lua_pushinteger(lua, ncpu > 0? ncpu : 1); + lua_pushinteger(lua, ncpu > 0 ? ncpu : 1); lua_settable(lua, -3); // get cpu usage rate tb_float_t usagerate = xm_os_cpuinfo_usagerate(); - if (usagerate >= 0) - { + if (usagerate >= 0) { lua_pushstring(lua, "usagerate"); lua_pushnumber(lua, usagerate); lua_settable(lua, -3); diff --git a/core/src/xmake/os/curdir.c b/core/src/xmake/os/curdir.c index c42f4e0d6..b2ca8a273 100644 --- a/core/src/xmake/os/curdir.c +++ b/core/src/xmake/os/curdir.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "curdir" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "curdir" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_curdir(lua_State* lua) -{ +tb_int_t xm_os_curdir(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // os.curdir() tb_char_t path[TB_PATH_MAXN]; - if (tb_directory_current(path, sizeof(path))) lua_pushstring(lua, path); - else lua_pushnil(lua); + if (tb_directory_current(path, sizeof(path))) + lua_pushstring(lua, path); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/os/emptydir.c b/core/src/xmake/os/emptydir.c index 409a1445b..79ebd9807 100644 --- a/core/src/xmake/os/emptydir.c +++ b/core/src/xmake/os/emptydir.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "emptydir" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "emptydir" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,15 +33,13 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_long_t xm_os_emptydir_walk(tb_char_t const* path, tb_file_info_t const* info, tb_cpointer_t priv) -{ +static tb_long_t xm_os_emptydir_walk(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { // check - tb_bool_t* is_emptydir = (tb_bool_t*)priv; + tb_bool_t *is_emptydir = (tb_bool_t *)priv; tb_assert_and_check_return_val(path && info && is_emptydir, TB_DIRECTORY_WALK_CODE_END); // is emptydir? - if (info->type == TB_FILE_TYPE_FILE || info->type == TB_FILE_TYPE_DIRECTORY) - { + if (info->type == TB_FILE_TYPE_FILE || info->type == TB_FILE_TYPE_DIRECTORY) { *is_emptydir = tb_false; return tb_false; } @@ -51,13 +49,12 @@ static tb_long_t xm_os_emptydir_walk(tb_char_t const* path, tb_file_info_t const /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_emptydir(lua_State* lua) -{ +tb_int_t xm_os_emptydir(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the directory - tb_char_t const* dir = luaL_checkstring(lua, 1); + tb_char_t const *dir = luaL_checkstring(lua, 1); tb_check_return_val(dir, 0); // os.emptydir(dir) diff --git a/core/src/xmake/os/exists.c b/core/src/xmake/os/exists.c index d09115cda..403a1285d 100644 --- a/core/src/xmake/os/exists.c +++ b/core/src/xmake/os/exists.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "exists" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "exists" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,13 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_exists(lua_State* lua) -{ +tb_int_t xm_os_exists(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // os.exists(path) diff --git a/core/src/xmake/os/filesize.c b/core/src/xmake/os/filesize.c index 0c1c52953..115ab5665 100644 --- a/core/src/xmake/os/filesize.c +++ b/core/src/xmake/os/filesize.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "filesize" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "filesize" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,19 +33,19 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_filesize(lua_State* lua) -{ +tb_int_t xm_os_filesize(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // os.filesize(path) - tb_file_info_t info = {0}; + tb_file_info_t info = { 0 }; if (tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE)) lua_pushinteger(lua, (lua_Integer)info.size); - else lua_pushinteger(lua, 0); + else + lua_pushinteger(lua, 0); return 1; } diff --git a/core/src/xmake/os/find.c b/core/src/xmake/os/find.c index f1e11952b..91c5b0261 100644 --- a/core/src/xmake/os/find.c +++ b/core/src/xmake/os/find.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "find" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "find" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,17 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_long_t xm_os_find_walk(tb_char_t const* path, tb_file_info_t const* info, tb_cpointer_t priv) -{ +static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { // check tb_value_ref_t tuple = (tb_value_ref_t)priv; tb_assert_and_check_return_val(path && info && tuple, TB_DIRECTORY_WALK_CODE_END); // the lua - lua_State* lua = (lua_State*)tuple[0].ptr; + lua_State *lua = (lua_State *)tuple[0].ptr; tb_assert_and_check_return_val(lua, TB_DIRECTORY_WALK_CODE_END); // the pattern - tb_char_t const* pattern = (tb_char_t const*)tuple[1].cstr; + tb_char_t const *pattern = (tb_char_t const *)tuple[1].cstr; tb_assert_and_check_return_val(pattern, TB_DIRECTORY_WALK_CODE_END); // remove ./ for path @@ -55,13 +54,14 @@ static tb_long_t xm_os_find_walk(tb_char_t const* path, tb_file_info_t const* in tb_long_t mode = tuple[2].l; // the count - tb_size_t* pcount = &(tuple[3].ul); + tb_size_t *pcount = &(tuple[3].ul); // trace - tb_trace_d("path[%c]: %s", info->type == TB_FILE_TYPE_DIRECTORY? 'd' : 'f', path); + tb_trace_d("path[%c]: %s", info->type == TB_FILE_TYPE_DIRECTORY ? 'd' : 'f', path); // we can ignore it directly if this path is file, but we need directory - tb_size_t needtype = (mode == 1)? TB_FILE_TYPE_DIRECTORY : ((mode == 0)? TB_FILE_TYPE_FILE : (TB_FILE_TYPE_FILE | TB_FILE_TYPE_DIRECTORY)); + tb_size_t needtype = (mode == 1) ? TB_FILE_TYPE_DIRECTORY + : ((mode == 0) ? TB_FILE_TYPE_FILE : (TB_FILE_TYPE_FILE | TB_FILE_TYPE_DIRECTORY)); if (info->type == TB_FILE_TYPE_FILE && needtype == TB_FILE_TYPE_DIRECTORY) return TB_DIRECTORY_WALK_CODE_CONTINUE; @@ -69,25 +69,22 @@ static tb_long_t xm_os_find_walk(tb_char_t const* path, tb_file_info_t const* in lua_getfield(lua, -1, "match"); lua_pushstring(lua, path); lua_pushstring(lua, pattern); - if (lua_pcall(lua, 2, 1, 0)) - { + if (lua_pcall(lua, 2, 1, 0)) { // trace tb_printf("error: call string.match(%s, %s) failed: %s!\n", path, pattern, lua_tostring(lua, -1)); return TB_DIRECTORY_WALK_CODE_END; } // match ok? - tb_bool_t matched = tb_false; + tb_bool_t matched = tb_false; tb_bool_t skip_recursion = tb_false; - if (lua_isstring(lua, -1) && !tb_strcmp(path, lua_tostring(lua, -1))) - { + if (lua_isstring(lua, -1) && !tb_strcmp(path, lua_tostring(lua, -1))) { // exists excludes? tb_bool_t excluded = tb_false; - if (lua_istable(lua, 5)) - { + if (lua_istable(lua, 5)) { // the root directory - size_t rootlen = 0; - tb_char_t const* rootdir = luaL_checklstring(lua, 1, &rootlen); + size_t rootlen = 0; + tb_char_t const *rootdir = luaL_checklstring(lua, 1, &rootlen); tb_assert_and_check_return_val(rootdir && rootlen, TB_DIRECTORY_WALK_CODE_END); // check @@ -99,23 +96,23 @@ static tb_long_t xm_os_find_walk(tb_char_t const* path, tb_file_info_t const* in path += rootlen + 1; // exclude paths - tb_int_t i = 0; + tb_int_t i = 0; tb_int_t count = (tb_int_t)lua_objlen(lua, 5); - for (i = 0; i < count && !excluded; i++) - { + for (i = 0; i < count && !excluded; i++) { // get exclude lua_rawgeti(lua, 5, i + 1); - tb_char_t const* exclude = lua_tostring(lua, -1); - if (exclude) - { + tb_char_t const *exclude = lua_tostring(lua, -1); + if (exclude) { // do path:match(exclude) lua_getfield(lua, -3, "match"); lua_pushstring(lua, path); lua_pushstring(lua, exclude); - if (lua_pcall(lua, 2, 1, 0)) - { + if (lua_pcall(lua, 2, 1, 0)) { // trace - tb_printf("error: call string.match(%s, %s) failed: %s!\n", path, exclude, lua_tostring(lua, -1)); + tb_printf("error: call string.match(%s, %s) failed: %s!\n", + path, + exclude, + lua_tostring(lua, -1)); } // matched? @@ -131,17 +128,14 @@ static tb_long_t xm_os_find_walk(tb_char_t const* path, tb_file_info_t const* in } // does not exclude this path? - if (!excluded) - { + if (!excluded) { // match file or directory? - if (info->type & needtype) - { + if (info->type & needtype) { // save it lua_rawseti(lua, -3, (tb_int_t)(++*pcount)); // do callback function - if (lua_isfunction(lua, 6)) - { + if (lua_isfunction(lua, 6)) { // do callback(path, isdir) lua_pushvalue(lua, 6); lua_pushstring(lua, path); @@ -151,31 +145,33 @@ static tb_long_t xm_os_find_walk(tb_char_t const* path, tb_file_info_t const* in // is continue? tb_bool_t is_continue = lua_toboolean(lua, -1); lua_pop(lua, 1); - if (!is_continue) return TB_DIRECTORY_WALK_CODE_END; + if (!is_continue) + return TB_DIRECTORY_WALK_CODE_END; } matched = tb_true; } } // we do not recurse sub-directories if this path has been excluded and it's directory - else skip_recursion = tb_true; + else + skip_recursion = tb_true; } - if (!matched) lua_pop(lua, 1); - return skip_recursion? TB_DIRECTORY_WALK_CODE_SKIP_RECURSION : TB_DIRECTORY_WALK_CODE_CONTINUE; + if (!matched) + lua_pop(lua, 1); + return skip_recursion ? TB_DIRECTORY_WALK_CODE_SKIP_RECURSION : TB_DIRECTORY_WALK_CODE_CONTINUE; } /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_find(lua_State* lua) -{ +tb_int_t xm_os_find(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the root directory - tb_char_t const* rootdir = luaL_checkstring(lua, 1); + tb_char_t const *rootdir = luaL_checkstring(lua, 1); tb_check_return_val(rootdir, 0); // get the pattern - tb_char_t const* pattern = luaL_checkstring(lua, 2); + tb_char_t const *pattern = luaL_checkstring(lua, 2); tb_check_return_val(pattern, 0); // the recursion level @@ -192,10 +188,10 @@ tb_int_t xm_os_find(lua_State* lua) // do os.find(root, name) tb_value_t tuple[4]; - tuple[0].ptr = lua; - tuple[1].cstr = pattern; - tuple[2].l = mode; - tuple[3].ul = 0; + tuple[0].ptr = lua; + tuple[1].cstr = pattern; + tuple[2].l = mode; + tuple[3].ul = 0; tb_directory_walk(rootdir, recursion, tb_true, xm_os_find_walk, tuple); // pop string package diff --git a/core/src/xmake/os/fscase.c b/core/src/xmake/os/fscase.c index f7682f87a..6fa1c1c4a 100644 --- a/core/src/xmake/os/fscase.c +++ b/core/src/xmake/os/fscase.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "fscase" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "fscase" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,13 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_fscase(lua_State* lua) -{ +tb_int_t xm_os_fscase(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); #if ((TB_VERSION_MAJOR * 100) + (TB_VERSION_MINOR * 10) + TB_VERSION_ALTER) >= 174 - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); lua_pushinteger(lua, (tb_int_t)tb_file_fscase(path)); diff --git a/core/src/xmake/os/getenv.c b/core/src/xmake/os/getenv.c index f9eaf7f18..84411ae1a 100644 --- a/core/src/xmake/os/getenv.c +++ b/core/src/xmake/os/getenv.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "getenv" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "getenv" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,41 +36,40 @@ // the separator #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) -# define XM_OS_ENV_SEP ';' +#define XM_OS_ENV_SEP ';' #else -# define XM_OS_ENV_SEP ':' +#define XM_OS_ENV_SEP ':' #endif /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_getenv(lua_State* lua) -{ +tb_int_t xm_os_getenv(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the name - tb_char_t const* name = luaL_checkstring(lua, 1); + tb_char_t const *name = luaL_checkstring(lua, 1); tb_check_return_val(name, 0); // init values tb_string_t values; - if (!tb_string_init(&values)) return 0; + if (!tb_string_init(&values)) + return 0; // init environment tb_environment_ref_t environment = tb_environment_init(); - if (environment) - { + if (environment) { // load variable - if (tb_environment_load(environment, name)) - { + if (tb_environment_load(environment, name)) { // make values tb_bool_t is_first = tb_true; - tb_for_all_if (tb_char_t const*, value, environment, value) - { + tb_for_all_if(tb_char_t const *, value, environment, value) { // append separator - if (!is_first) tb_string_chrcat(&values, XM_OS_ENV_SEP); - else is_first = tb_false; + if (!is_first) + tb_string_chrcat(&values, XM_OS_ENV_SEP); + else + is_first = tb_false; // append value tb_string_cstrcat(&values, value); @@ -82,8 +81,10 @@ tb_int_t xm_os_getenv(lua_State* lua) } // save result - if (tb_string_size(&values)) lua_pushstring(lua, tb_string_cstr(&values)); - else lua_pushnil(lua); + if (tb_string_size(&values)) + lua_pushstring(lua, tb_string_cstr(&values)); + else + lua_pushnil(lua); // exit values tb_string_exit(&values); diff --git a/core/src/xmake/os/getenvs.c b/core/src/xmake/os/getenvs.c index 7e6d611d6..a3bc546b4 100644 --- a/core/src/xmake/os/getenvs.c +++ b/core/src/xmake/os/getenvs.c @@ -22,15 +22,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "getenvs" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "getenvs" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) -# include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -39,9 +39,9 @@ // the separator #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) -# define XM_OS_ENV_SEP ';' +#define XM_OS_ENV_SEP ';' #else -# define XM_OS_ENV_SEP ':' +#define XM_OS_ENV_SEP ':' #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -50,19 +50,18 @@ // the user environment #if !defined(TB_CONFIG_OS_WINDOWS) || defined(TB_COMPILER_LIKE_UNIX) -extern tb_char_t** environ; +extern tb_char_t **environ; #endif /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -static tb_void_t xm_os_getenvs_trim(tb_char_t const** sstr, tb_char_t const** estr) -{ +static tb_void_t xm_os_getenvs_trim(tb_char_t const **sstr, tb_char_t const **estr) { // check tb_assert(sstr && estr && *sstr && *estr); - tb_char_t const* p = *sstr; - tb_char_t const* e = *estr; + tb_char_t const *p = *sstr; + tb_char_t const *e = *estr; // trim left while (p < e && tb_isspace(*p)) @@ -77,8 +76,7 @@ static tb_void_t xm_os_getenvs_trim(tb_char_t const** sstr, tb_char_t const** es *estr = e; } -static tb_void_t xm_os_getenvs_process_line(lua_State* lua, tb_char_t const* line) -{ +static tb_void_t xm_os_getenvs_process_line(lua_State *lua, tb_char_t const *line) { // check tb_assert_and_check_return(lua && line); @@ -86,36 +84,36 @@ static tb_void_t xm_os_getenvs_process_line(lua_State* lua, tb_char_t const* lin tb_check_return(n > 0); // find '=' separator - tb_char_t const* p = tb_strchr(line, '='); + tb_char_t const *p = tb_strchr(line, '='); tb_check_return(p); // get key and value parts - tb_char_t const* key_start = line; - tb_char_t const* key_end = p; - tb_char_t const* value_start = p + 1; - tb_char_t const* value_end = line + n; + tb_char_t const *key_start = line; + tb_char_t const *key_end = p; + tb_char_t const *value_start = p + 1; + tb_char_t const *value_end = line + n; // trim key xm_os_getenvs_trim(&key_start, &key_end); - if (key_start >= key_end) return; + if (key_start >= key_end) + return; // trim value xm_os_getenvs_trim(&value_start, &value_end); // get key and value lengths - tb_size_t key_len = key_end - key_start; + tb_size_t key_len = key_end - key_start; tb_size_t value_len = value_end > value_start ? value_end - value_start : 0; // handle Windows-specific PATH conversion - tb_char_t const* final_key_start = key_start; - tb_size_t final_key_len = key_len; + tb_char_t const *final_key_start = key_start; + tb_size_t final_key_len = key_len; #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) - if (key_len == 4 && tb_strnicmp(key_start, "path", 4) == 0) - { + if (key_len == 4 && tb_strnicmp(key_start, "path", 4) == 0) { // use "PATH" instead of "path" static tb_char_t const PATH_UPPER[] = "PATH"; - final_key_start = PATH_UPPER; - final_key_len = 4; + final_key_start = PATH_UPPER; + final_key_len = 4; } #endif @@ -125,8 +123,7 @@ static tb_void_t xm_os_getenvs_process_line(lua_State* lua, tb_char_t const* lin lua_rawset(lua, -3); } -tb_int_t xm_os_getenvs(lua_State* lua) -{ +tb_int_t xm_os_getenvs(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -134,32 +131,24 @@ tb_int_t xm_os_getenvs(lua_State* lua) lua_newtable(lua); #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) - tb_wchar_t const* p = (tb_wchar_t const*)GetEnvironmentStringsW(); - if (p) - { - tb_char_t* data = tb_null; - tb_size_t maxn = 0; - tb_char_t line[TB_PATH_MAXN]; - tb_size_t n = 0; - while (*p) - { + tb_wchar_t const *p = (tb_wchar_t const *)GetEnvironmentStringsW(); + if (p) { + tb_char_t *data = tb_null; + tb_size_t maxn = 0; + tb_char_t line[TB_PATH_MAXN]; + tb_size_t n = 0; + while (*p) { n = tb_wcslen(p); - if (n + 1 < tb_arrayn(line)) - { + if (n + 1 < tb_arrayn(line)) { if (tb_wtoa(line, p, tb_arrayn(line)) >= 0) xm_os_getenvs_process_line(lua, line); - } - else - { - if (!data) - { + } else { + if (!data) { maxn = n + 1; - data = (tb_char_t*)tb_malloc(maxn); - } - else if (n >= maxn) - { + data = (tb_char_t *)tb_malloc(maxn); + } else if (n >= maxn) { maxn = n + TB_PATH_MAXN + 1; - data = (tb_char_t*)tb_ralloc(data, maxn); + data = (tb_char_t *)tb_ralloc(data, maxn); } tb_assert_and_check_break(data); @@ -168,15 +157,14 @@ tb_int_t xm_os_getenvs(lua_State* lua) } p += n + 1; } - if (data && data != line) tb_free(data); + if (data && data != line) + tb_free(data); data = tb_null; } #else - tb_char_t const** p = (tb_char_t const**)environ; - if (p) - { - while (*p) - { + tb_char_t const **p = (tb_char_t const **)environ; + if (p) { + while (*p) { xm_os_getenvs_process_line(lua, *p); p++; } diff --git a/core/src/xmake/os/getown.c b/core/src/xmake/os/getown.c index d032a44b8..54e2b589e 100644 --- a/core/src/xmake/os/getown.c +++ b/core/src/xmake/os/getown.c @@ -22,16 +22,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "getown" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "getown" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #ifndef TB_CONFIG_OS_WINDOWS -# include -# include +#include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -41,13 +41,12 @@ #ifndef TB_CONFIG_OS_WINDOWS // get owner by a given path -tb_int_t xm_os_getown(lua_State* lua) -{ +tb_int_t xm_os_getown(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the pathname - tb_char_t const* pathname = luaL_checkstring(lua, 1); + tb_char_t const *pathname = luaL_checkstring(lua, 1); tb_check_return_val(pathname, 0); // get stat diff --git a/core/src/xmake/os/getpid.c b/core/src/xmake/os/getpid.c index aeb0ace14..70b63804a 100644 --- a/core/src/xmake/os/getpid.c +++ b/core/src/xmake/os/getpid.c @@ -22,25 +22,24 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "getpid" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "getpid" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #ifdef TB_CONFIG_OS_WINDOWS -# include +#include #else -# include -# include +#include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_getpid(lua_State* lua) -{ +tb_int_t xm_os_getpid(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -51,4 +50,3 @@ tb_int_t xm_os_getpid(lua_State* lua) #endif return 1; } - diff --git a/core/src/xmake/os/getwinsize.c b/core/src/xmake/os/getwinsize.c index 919bfa9bd..9757867a9 100644 --- a/core/src/xmake/os/getwinsize.c +++ b/core/src/xmake/os/getwinsize.c @@ -22,19 +22,19 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "getwinsize" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "getwinsize" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) -# include +#include #else -# include -# include // for errno -# include // for STDOUT_FILENO +#include +#include // for errno +#include // for STDOUT_FILENO #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -42,8 +42,7 @@ */ // get console window size -tb_int_t xm_os_getwinsize(lua_State* lua) -{ +tb_int_t xm_os_getwinsize(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -53,15 +52,13 @@ tb_int_t xm_os_getwinsize(lua_State* lua) // get winsize #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) CONSOLE_SCREEN_BUFFER_INFO csbi; - if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) - { + if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) { w = (tb_int_t)csbi.dwSize.X; h = (tb_int_t)csbi.dwSize.Y; } #else struct winsize size; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) == 0) - { + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) == 0) { w = (tb_int_t)size.ws_col; h = (tb_int_t)size.ws_row; } diff --git a/core/src/xmake/os/gid.c b/core/src/xmake/os/gid.c index 739bfd64a..cd5915cd4 100644 --- a/core/src/xmake/os/gid.c +++ b/core/src/xmake/os/gid.c @@ -22,16 +22,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "gid" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "gid" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #ifndef TB_CONFIG_OS_WINDOWS -# include -# include +#include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -40,25 +40,20 @@ #ifndef TB_CONFIG_OS_WINDOWS // get & set gid -tb_int_t xm_os_gid(lua_State* lua) -{ +tb_int_t xm_os_gid(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); tb_int_t rgidset = -1; tb_int_t egidset = -1; - tb_int_t argc = lua_gettop(lua); - if (argc == 1) - { - if (lua_istable(lua, 1)) - { + tb_int_t argc = lua_gettop(lua); + if (argc == 1) { + if (lua_istable(lua, 1)) { // os.gid({["rgid"] = rgid, ["egid"] = egid}) lua_getfield(lua, 1, "rgid"); lua_getfield(lua, 1, "egid"); - if (!lua_isnil(lua, -1)) - { - if (!lua_isnumber(lua, -1)) - { + if (!lua_isnil(lua, -1)) { + if (!lua_isnumber(lua, -1)) { lua_pushfstring(lua, "invalid field type(%s) in `egid` for os.gid", luaL_typename(lua, -1)); lua_error(lua); return 0; @@ -66,10 +61,8 @@ tb_int_t xm_os_gid(lua_State* lua) egidset = (tb_int_t)lua_tonumber(lua, -1); } lua_pop(lua, 1); - if (!lua_isnil(lua, -1)) - { - if (!lua_isnumber(lua, -1)) - { + if (!lua_isnil(lua, -1)) { + if (!lua_isnumber(lua, -1)) { lua_pushfstring(lua, "invalid field type(%s) in `rgid` for os.gid", luaL_typename(lua, -1)); lua_error(lua); return 0; @@ -77,45 +70,33 @@ tb_int_t xm_os_gid(lua_State* lua) rgidset = (tb_int_t)lua_tonumber(lua, -1); } lua_pop(lua, 1); - } - else if (lua_isnumber(lua, 1)) - { + } else if (lua_isnumber(lua, 1)) { // os.gid(gid) rgidset = egidset = (tb_int_t)lua_tonumber(lua, 1); - } - else - { + } else { lua_pushfstring(lua, "invalid argument type(%s) for os.gid", luaL_typename(lua, 1)); lua_error(lua); return 0; } - } - else if (argc == 2) - { + } else if (argc == 2) { // os.gid(rgid, egid) - if (!lua_isnil(lua, 1)) - { - if (!lua_isnumber(lua, 1)) - { + if (!lua_isnil(lua, 1)) { + if (!lua_isnumber(lua, 1)) { lua_pushfstring(lua, "invalid argument type(%s) for os.gid", luaL_typename(lua, 1)); lua_error(lua); return 0; } rgidset = (tb_int_t)lua_tonumber(lua, 1); } - if (!lua_isnil(lua, 2)) - { - if (!lua_isnumber(lua, 2)) - { + if (!lua_isnil(lua, 2)) { + if (!lua_isnumber(lua, 2)) { lua_pushfstring(lua, "invalid argument type(%s) for os.gid", luaL_typename(lua, 2)); lua_error(lua); return 0; } egidset = (tb_int_t)lua_tonumber(lua, 2); } - } - else if (argc != 0) - { + } else if (argc != 0) { lua_pushstring(lua, "invalid argument count for os.gid"); lua_error(lua); return 0; @@ -124,8 +105,7 @@ tb_int_t xm_os_gid(lua_State* lua) // store return value lua_newtable(lua); - if (rgidset != -1 || egidset != -1) - { + if (rgidset != -1 || egidset != -1) { // set rgid & egid lua_pushstring(lua, "errno"); lua_pushinteger(lua, setregid(rgidset, egidset) != 0 ? errno : 0); diff --git a/core/src/xmake/os/isdir.c b/core/src/xmake/os/isdir.c index 531988486..6126ed6a8 100644 --- a/core/src/xmake/os/isdir.c +++ b/core/src/xmake/os/isdir.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "isdir" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "isdir" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_isdir(lua_State* lua) -{ +tb_int_t xm_os_isdir(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // is directory? - tb_file_info_t info = {0}; + tb_file_info_t info = { 0 }; lua_pushboolean(lua, tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_DIRECTORY)); return 1; } diff --git a/core/src/xmake/os/isfile.c b/core/src/xmake/os/isfile.c index 293692a98..f015b5f59 100644 --- a/core/src/xmake/os/isfile.c +++ b/core/src/xmake/os/isfile.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "isfile" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "isfile" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_isfile(lua_State* lua) -{ +tb_int_t xm_os_isfile(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // is file? - tb_file_info_t info = {0}; + tb_file_info_t info = { 0 }; lua_pushboolean(lua, tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE)); return 1; } diff --git a/core/src/xmake/os/islink.c b/core/src/xmake/os/islink.c index c2b70b74d..2de7e24fd 100644 --- a/core/src/xmake/os/islink.c +++ b/core/src/xmake/os/islink.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "islink" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "islink" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_islink(lua_State* lua) -{ +tb_int_t xm_os_islink(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // is link? - tb_file_info_t info = {0}; + tb_file_info_t info = { 0 }; lua_pushboolean(lua, tb_file_info(path, &info) && (info.flags & TB_FILE_FLAG_LINK)); return 1; } diff --git a/core/src/xmake/os/link.c b/core/src/xmake/os/link.c index 8c15dfa41..696355177 100644 --- a/core/src/xmake/os/link.c +++ b/core/src/xmake/os/link.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "link" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "link" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,13 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_link(lua_State* lua) -{ +tb_int_t xm_os_link(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the source and destination - tb_char_t const* src = luaL_checkstring(lua, 1); - tb_char_t const* dst = luaL_checkstring(lua, 2); + tb_char_t const *src = luaL_checkstring(lua, 1); + tb_char_t const *dst = luaL_checkstring(lua, 2); tb_check_return_val(src && dst, 0); // do os.link(src, dst) diff --git a/core/src/xmake/os/mclock.c b/core/src/xmake/os/mclock.c index 43e0e3f92..f6bc138d3 100644 --- a/core/src/xmake/os/mclock.c +++ b/core/src/xmake/os/mclock.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "mclock" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "mclock" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // os.mclock() -tb_int_t xm_os_mclock(lua_State* lua) -{ +tb_int_t xm_os_mclock(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); diff --git a/core/src/xmake/os/meminfo.c b/core/src/xmake/os/meminfo.c index 293359350..3c0b71d80 100644 --- a/core/src/xmake/os/meminfo.c +++ b/core/src/xmake/os/meminfo.c @@ -22,55 +22,54 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "meminfo" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "meminfo" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #if defined(TB_CONFIG_OS_MACOSX) -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include #elif defined(TB_CONFIG_OS_LINUX) -# include -# include +#include +#include #elif defined(TB_CONFIG_OS_WINDOWS) -# include +#include #elif defined(TB_CONFIG_OS_BSD) -# include -# include +#include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ #ifdef TB_CONFIG_OS_LINUX -static tb_int64_t xm_os_meminfo_get_value(tb_char_t const* buffer, tb_char_t const* name) -{ - tb_char_t const* p = tb_strstr(buffer, name); - return p? tb_stoi64(p + tb_strlen(name)) : 0; +static tb_int64_t xm_os_meminfo_get_value(tb_char_t const *buffer, tb_char_t const *name) { + tb_char_t const *p = tb_strstr(buffer, name); + return p ? tb_stoi64(p + tb_strlen(name)) : 0; } #endif // get the used memory size (MB) -static tb_bool_t xm_os_meminfo_stats(tb_int_t* ptotalsize, tb_int_t* pavailsize) -{ +static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) { #if defined(TB_CONFIG_OS_MACOSX) vm_statistics64_data_t vmstat; mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; - if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info_t) &vmstat, &count) == KERN_SUCCESS) - { - tb_int_t pagesize = (tb_int_t)tb_page_size(); - tb_int64_t totalsize = (tb_int64_t)(vmstat.inactive_count + vmstat.free_count + vmstat.active_count + vmstat.wire_count + if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info_t)&vmstat, &count) == KERN_SUCCESS) { + tb_int_t pagesize = (tb_int_t)tb_page_size(); + tb_int64_t totalsize = (tb_int64_t)(vmstat.inactive_count + vmstat.free_count + vmstat.active_count + + vmstat.wire_count #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 - + vmstat.compressor_page_count + + vmstat.compressor_page_count #endif - ) * pagesize; + ) * + pagesize; /* * NB: speculative pages are already accounted for in "free_count", * so "speculative_count" is the number of "free" pages that are @@ -78,7 +77,8 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t* ptotalsize, tb_int_t* pavailsize) * haven't actually been used by anyone so far. * */ - tb_int64_t availsize = (tb_int64_t)(vmstat.inactive_count + vmstat.free_count - vmstat.speculative_count) * pagesize; + tb_int64_t availsize = (tb_int64_t)(vmstat.inactive_count + vmstat.free_count - vmstat.speculative_count) * + pagesize; *ptotalsize = (tb_int_t)(totalsize / (1024 * 1024)); *pavailsize = (tb_int_t)(availsize / (1024 * 1024)); return tb_true; @@ -88,21 +88,17 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t* ptotalsize, tb_int_t* pavailsize) * * @see https://github.com/rfjakob/earlyoom/blob/cba1d599e4a7484c45ac017aa7702ff879f15846/meminfo.c#L52 */ - if (tb_file_info("/proc/meminfo", tb_null)) - { + if (tb_file_info("/proc/meminfo", tb_null)) { tb_bool_t ok = tb_false; - FILE* fp = fopen("/proc/meminfo", "r"); - if (fp) - { + FILE *fp = fopen("/proc/meminfo", "r"); + if (fp) { // 8192 should be enough for the foreseeable future. tb_char_t buffer[8192]; - size_t len = fread(buffer, 1, sizeof(buffer) - 1, fp); - if (!ferror(fp) && len) - { + size_t len = fread(buffer, 1, sizeof(buffer) - 1, fp); + if (!ferror(fp) && len) { tb_int64_t totalsize = xm_os_meminfo_get_value(buffer, "MemTotal:"); tb_int64_t availsize = xm_os_meminfo_get_value(buffer, "MemAvailable:"); - if (availsize <= 0) - { + if (availsize <= 0) { tb_int64_t cachesize = xm_os_meminfo_get_value(buffer, "Cached:"); tb_int64_t freesize = xm_os_meminfo_get_value(buffer, "MemFree:"); tb_int64_t buffersize = xm_os_meminfo_get_value(buffer, "Buffers:"); @@ -110,39 +106,34 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t* ptotalsize, tb_int_t* pavailsize) if (cachesize >= 0 && freesize >= 0 && buffersize >= 0 && shmemsize >= 0) availsize = freesize + buffersize + cachesize - shmemsize; } - if (totalsize > 0 && availsize >= 0) - { + if (totalsize > 0 && availsize >= 0) { *ptotalsize = (tb_int_t)(totalsize / 1024); *pavailsize = (tb_int_t)(availsize / 1024); - ok = tb_true; + ok = tb_true; } } fclose(fp); } return ok; - } - else - { - struct sysinfo info = {0}; - if (sysinfo(&info) == 0) - { + } else { + struct sysinfo info = { 0 }; + if (sysinfo(&info) == 0) { *ptotalsize = (tb_int_t)(info.totalram / (1024 * 1024)); - *pavailsize = (tb_int_t)((info.freeram + info.bufferram/* + cache size */) / (1024 * 1024)); + *pavailsize = (tb_int_t)((info.freeram + info.bufferram /* + cache size */) / (1024 * 1024)); return tb_true; } } #elif defined(TB_CONFIG_OS_WINDOWS) MEMORYSTATUSEX statex; statex.dwLength = sizeof(statex); - if (GlobalMemoryStatusEx(&statex)) - { + if (GlobalMemoryStatusEx(&statex)) { *ptotalsize = (tb_int_t)(statex.ullTotalPhys / (1024 * 1024)); *pavailsize = (tb_int_t)(statex.ullAvailPhys / (1024 * 1024)); return tb_true; } #elif defined(TB_CONFIG_OS_BSD) && !defined(__OpenBSD__) unsigned long totalsize; - size_t size = sizeof(totalsize); + size_t size = sizeof(totalsize); if (sysctlbyname("hw.physmem", &totalsize, &size, tb_null, 0) != 0) return tb_false; @@ -167,8 +158,7 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t* ptotalsize, tb_int_t* pavailsize) /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_meminfo(lua_State* lua) -{ +tb_int_t xm_os_meminfo(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -184,8 +174,7 @@ tb_int_t xm_os_meminfo(lua_State* lua) // get the memory size (MB) tb_int_t availsize = 0; tb_int_t totalsize = 0; - if (xm_os_meminfo_stats(&totalsize, &availsize)) - { + if (xm_os_meminfo_stats(&totalsize, &availsize)) { lua_pushstring(lua, "totalsize"); lua_pushinteger(lua, totalsize); lua_settable(lua, -3); diff --git a/core/src/xmake/os/mkdir.c b/core/src/xmake/os/mkdir.c index 6528ad71f..badc50fd6 100644 --- a/core/src/xmake/os/mkdir.c +++ b/core/src/xmake/os/mkdir.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "mkdir" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "mkdir" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,20 +33,20 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_mkdir(lua_State* lua) -{ +tb_int_t xm_os_mkdir(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // os.mkdir(path) - tb_file_info_t info = {0}; + tb_file_info_t info = { 0 }; if (!tb_file_info(path, &info) || (info.type != TB_FILE_TYPE_DIRECTORY)) lua_pushboolean(lua, tb_directory_create(path)); - else lua_pushboolean(lua, tb_true); + else + lua_pushboolean(lua, tb_true); // ok return 1; diff --git a/core/src/xmake/os/mtime.c b/core/src/xmake/os/mtime.c index 09c988caa..a3d9c44de 100644 --- a/core/src/xmake/os/mtime.c +++ b/core/src/xmake/os/mtime.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "mtime" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "mtime" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,19 +33,19 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_mtime(lua_State* lua) -{ +tb_int_t xm_os_mtime(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // os.mtime(path) - tb_file_info_t info = {0}; + tb_file_info_t info = { 0 }; if (tb_file_info(path, &info)) lua_pushinteger(lua, (lua_Integer)info.mtime); - else lua_pushinteger(lua, 0); + else + lua_pushinteger(lua, 0); return 1; } diff --git a/core/src/xmake/os/prefix.h b/core/src/xmake/os/prefix.h index adbe78c7d..f98808a6b 100644 --- a/core/src/xmake/os/prefix.h +++ b/core/src/xmake/os/prefix.h @@ -26,7 +26,4 @@ */ #include "../prefix.h" - #endif - - diff --git a/core/src/xmake/os/readlink.c b/core/src/xmake/os/readlink.c index 0877a10da..26ef78819 100644 --- a/core/src/xmake/os/readlink.c +++ b/core/src/xmake/os/readlink.c @@ -22,27 +22,26 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "readlink" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "readlink" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #ifndef TB_CONFIG_OS_WINDOWS -# include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_readlink(lua_State* lua) -{ +tb_int_t xm_os_readlink(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // is link? @@ -51,28 +50,23 @@ tb_int_t xm_os_readlink(lua_State* lua) #else tb_char_t srcpath[TB_PATH_MAXN]; tb_long_t size = readlink(path, srcpath, TB_PATH_MAXN); - if (size == TB_PATH_MAXN) - { + if (size == TB_PATH_MAXN) { tb_size_t maxn = TB_PATH_MAXN * 2; - tb_char_t* data = (tb_char_t*)tb_malloc(maxn); - if (data) - { + tb_char_t *data = (tb_char_t *)tb_malloc(maxn); + if (data) { tb_long_t size = readlink(path, data, maxn); - if (size > 0 && size < maxn) - { + if (size > 0 && size < maxn) { data[size] = '\0'; lua_pushstring(lua, data); - } - else lua_pushnil(lua); + } else + lua_pushnil(lua); tb_free(data); } - } - else if (size >= 0 && size < TB_PATH_MAXN) - { + } else if (size >= 0 && size < TB_PATH_MAXN) { srcpath[size] = '\0'; lua_pushstring(lua, srcpath); - } - else lua_pushnil(lua); + } else + lua_pushnil(lua); #endif // ok diff --git a/core/src/xmake/os/rename.c b/core/src/xmake/os/rename.c index 35a24ecb4..2f43797db 100644 --- a/core/src/xmake/os/rename.c +++ b/core/src/xmake/os/rename.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "rename" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "rename" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,13 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_rename(lua_State* lua) -{ +tb_int_t xm_os_rename(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the source and destination - tb_char_t const* src = luaL_checkstring(lua, 1); - tb_char_t const* dst = luaL_checkstring(lua, 2); + tb_char_t const *src = luaL_checkstring(lua, 1); + tb_char_t const *dst = luaL_checkstring(lua, 2); tb_check_return_val(src && dst, 0); // do rename diff --git a/core/src/xmake/os/rmdir.c b/core/src/xmake/os/rmdir.c index 28ef1d251..dd549adac 100644 --- a/core/src/xmake/os/rmdir.c +++ b/core/src/xmake/os/rmdir.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "rmdir" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "rmdir" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,29 +33,25 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_long_t xm_os_rmdir_empty(tb_char_t const* path, tb_file_info_t const* info, tb_cpointer_t priv) -{ +static tb_long_t xm_os_rmdir_empty(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { // check - tb_bool_t* is_emptydir = (tb_bool_t*)priv; + tb_bool_t *is_emptydir = (tb_bool_t *)priv; tb_assert_and_check_return_val(path && info && is_emptydir, TB_DIRECTORY_WALK_CODE_END); // is emptydir? - if (info->type == TB_FILE_TYPE_DIRECTORY || info->type == TB_FILE_TYPE_FILE) - { + if (info->type == TB_FILE_TYPE_DIRECTORY || info->type == TB_FILE_TYPE_FILE) { // not emptydir *is_emptydir = tb_false; return TB_DIRECTORY_WALK_CODE_END; } return TB_DIRECTORY_WALK_CODE_CONTINUE; } -static tb_long_t xm_os_rmdir_remove(tb_char_t const* path, tb_file_info_t const* info, tb_cpointer_t priv) -{ +static tb_long_t xm_os_rmdir_remove(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { // check tb_assert_and_check_return_val(path, TB_DIRECTORY_WALK_CODE_END); // is directory? - if (info->type == TB_FILE_TYPE_DIRECTORY) - { + if (info->type == TB_FILE_TYPE_DIRECTORY) { // is emptydir? tb_bool_t is_emptydir = tb_true; tb_directory_walk(path, tb_false, tb_true, xm_os_rmdir_empty, &is_emptydir); @@ -64,7 +60,8 @@ static tb_long_t xm_os_rmdir_remove(tb_char_t const* path, tb_file_info_t const* tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); // remove empty directory - if (is_emptydir) tb_directory_remove(path); + if (is_emptydir) + tb_directory_remove(path); } return TB_DIRECTORY_WALK_CODE_CONTINUE; } @@ -72,35 +69,32 @@ static tb_long_t xm_os_rmdir_remove(tb_char_t const* path, tb_file_info_t const* /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_rmdir(lua_State* lua) -{ +tb_int_t xm_os_rmdir(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // only remove empty directory? tb_bool_t rmempty = lua_toboolean(lua, 2); - if (rmempty) - { + if (rmempty) { // remove all empty directories tb_directory_walk(path, tb_true, tb_false, xm_os_rmdir_remove, tb_null); // remove empty root directory tb_bool_t is_emptydir = tb_true; tb_directory_walk(path, tb_false, tb_true, xm_os_rmdir_empty, &is_emptydir); - if (is_emptydir) tb_directory_remove(path); + if (is_emptydir) + tb_directory_remove(path); // trace tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); // ok? lua_pushboolean(lua, !tb_file_info(path, tb_null)); - } - else - { + } else { // os.rmdir(path) lua_pushboolean(lua, tb_directory_remove(path)); } diff --git a/core/src/xmake/os/rmfile.c b/core/src/xmake/os/rmfile.c index 1fd29e7c9..f4b204e25 100644 --- a/core/src/xmake/os/rmfile.c +++ b/core/src/xmake/os/rmfile.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "rmfile" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "rmfile" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,13 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_rmfile(lua_State* lua) -{ +tb_int_t xm_os_rmfile(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // do remove diff --git a/core/src/xmake/os/setenv.c b/core/src/xmake/os/setenv.c index b2f7042d7..99a9bf44e 100644 --- a/core/src/xmake/os/setenv.c +++ b/core/src/xmake/os/setenv.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "setenv" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "setenv" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,18 +34,17 @@ * implementation */ // ok = os.setenv(name, value) -tb_int_t xm_os_setenv(lua_State* lua) -{ +tb_int_t xm_os_setenv(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the name and value - size_t value_size = 0; - tb_char_t const* name = luaL_checkstring(lua, 1); - tb_char_t const* value = luaL_checklstring(lua, 2, &value_size); + size_t value_size = 0; + tb_char_t const *name = luaL_checkstring(lua, 1); + tb_char_t const *value = luaL_checklstring(lua, 2, &value_size); tb_check_return_val(name, 0); // set it - lua_pushboolean(lua, value? tb_environment_set(name, value) : tb_false); + lua_pushboolean(lua, value ? tb_environment_set(name, value) : tb_false); return 1; } diff --git a/core/src/xmake/os/signal.c b/core/src/xmake/os/signal.c index 86ae2aa00..c1f43ad6b 100644 --- a/core/src/xmake/os/signal.c +++ b/core/src/xmake/os/signal.c @@ -22,24 +22,25 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "signal" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "signal" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #if defined(TB_CONFIG_OS_MACOSX) || defined(TB_CONFIG_OS_IOS) -# include -# include -#elif defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD) || defined(TB_CONFIG_OS_ANDROID) || defined(TB_CONFIG_OS_HAIKU) -# include -# include +#include +#include +#elif defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD) || defined(TB_CONFIG_OS_ANDROID) || \ + defined(TB_CONFIG_OS_HAIKU) +#include +#include #endif #ifdef TB_CONFIG_OS_BSD -# include -# include -# include +#include +#include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -47,29 +48,27 @@ */ typedef enum __xm_os_signal_e { XM_OS_SIGINT = 2 -}xm_os_signal_e; +} xm_os_signal_e; typedef enum __xm_os_signal_handler_e { XM_OS_SIGFUN = 0, XM_OS_SIGDFL = 1, XM_OS_SIGIGN = 2, -}xm_os_signal_handler_e; +} xm_os_signal_handler_e; /* ////////////////////////////////////////////////////////////////////////////////////// * globals */ -static lua_State* g_lua = tb_null; +static lua_State *g_lua = tb_null; /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t xm_os_signal_handler_impl(tb_int_t signo) -{ +static tb_void_t xm_os_signal_handler_impl(tb_int_t signo) { // do callback(signo) - lua_State* lua = g_lua; - if (lua) - { - tb_char_t name[64] = {0}; + lua_State *lua = g_lua; + if (lua) { + tb_char_t name[64] = { 0 }; tb_snprintf(name, sizeof(name), "_SIGNAL_HANDLER_%d", signo); lua_getglobal(lua, name); lua_pushinteger(lua, signo); @@ -78,18 +77,15 @@ static tb_void_t xm_os_signal_handler_impl(tb_int_t signo) } #if defined(TB_CONFIG_OS_WINDOWS) -static BOOL WINAPI xm_os_signal_handler(DWORD ctrl_type) -{ +static BOOL WINAPI xm_os_signal_handler(DWORD ctrl_type) { if (ctrl_type == CTRL_C_EVENT) xm_os_signal_handler_impl(XM_OS_SIGINT); return TRUE; } #elif defined(SIGINT) -static tb_void_t xm_os_signal_handler(tb_int_t signo_native) -{ +static tb_void_t xm_os_signal_handler(tb_int_t signo_native) { tb_int_t signo = -1; - switch (signo_native) - { + switch (signo_native) { case SIGINT: signo = XM_OS_SIGINT; break; @@ -104,24 +100,22 @@ static tb_void_t xm_os_signal_handler(tb_int_t signo_native) /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_signal(lua_State* lua) -{ +tb_int_t xm_os_signal(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); - g_lua = lua; + g_lua = lua; tb_int_t handler = XM_OS_SIGFUN; // check signal handler if (lua_isnumber(lua, 2)) - handler = (tb_int_t) luaL_checkinteger(lua, 2); + handler = (tb_int_t)luaL_checkinteger(lua, 2); else if (!lua_isfunction(lua, 2)) return 0; // save signal handler tb_int_t signo = (tb_int_t)luaL_checkinteger(lua, 1); - if (handler == XM_OS_SIGFUN) - { - tb_char_t name[64] = {0}; + if (handler == XM_OS_SIGFUN) { + tb_char_t name[64] = { 0 }; tb_snprintf(name, sizeof(name), "_SIGNAL_HANDLER_%d", signo); lua_pushvalue(lua, 2); lua_setglobal(lua, name); @@ -131,23 +125,21 @@ tb_int_t xm_os_signal(lua_State* lua) if (signo != XM_OS_SIGINT) return 0; - switch (handler) - { - case XM_OS_SIGFUN: - SetConsoleCtrlHandler(xm_os_signal_handler, TRUE); - break; - case XM_OS_SIGDFL: - SetConsoleCtrlHandler(NULL, FALSE); - break; - case XM_OS_SIGIGN: - SetConsoleCtrlHandler(NULL, TRUE); - break; - default: - break; + switch (handler) { + case XM_OS_SIGFUN: + SetConsoleCtrlHandler(xm_os_signal_handler, TRUE); + break; + case XM_OS_SIGDFL: + SetConsoleCtrlHandler(NULL, FALSE); + break; + case XM_OS_SIGIGN: + SetConsoleCtrlHandler(NULL, TRUE); + break; + default: + break; } #elif defined(SIGINT) - switch (signo) - { + switch (signo) { case XM_OS_SIGINT: signo = SIGINT; break; @@ -155,19 +147,18 @@ tb_int_t xm_os_signal(lua_State* lua) return 0; } - switch (handler) - { - case XM_OS_SIGFUN: - signal(signo, xm_os_signal_handler); - break; - case XM_OS_SIGDFL: - signal(signo, SIG_DFL); - break; - case XM_OS_SIGIGN: - signal(signo, SIG_IGN); - break; - default: - break; + switch (handler) { + case XM_OS_SIGFUN: + signal(signo, xm_os_signal_handler); + break; + case XM_OS_SIGDFL: + signal(signo, SIG_DFL); + break; + case XM_OS_SIGIGN: + signal(signo, SIG_IGN); + break; + default: + break; } #endif return 0; diff --git a/core/src/xmake/os/sleep.c b/core/src/xmake/os/sleep.c index 528279d45..0c4172b43 100644 --- a/core/src/xmake/os/sleep.c +++ b/core/src/xmake/os/sleep.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "sleep" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "sleep" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,10 +33,10 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_sleep(lua_State* lua) -{ +tb_int_t xm_os_sleep(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); tb_long_t interval = (tb_long_t)luaL_checklong(lua, 1); - if (interval >= 0) tb_msleep(interval); + if (interval >= 0) + tb_msleep(interval); return 0; } diff --git a/core/src/xmake/os/strerror.c b/core/src/xmake/os/strerror.c index f801dc9c3..955ca8e24 100644 --- a/core/src/xmake/os/strerror.c +++ b/core/src/xmake/os/strerror.c @@ -22,35 +22,32 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "strerror" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "strerror" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) -# include +#include #else -# include -# include +#include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_strerror(lua_State* lua) -{ +tb_int_t xm_os_strerror(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get syserror state tb_size_t syserror = tb_syserror_state(); - if (syserror != TB_STATE_SYSERROR_UNKNOWN_ERROR) - { - tb_char_t const* strerr = "Unknown"; - switch (syserror) - { + if (syserror != TB_STATE_SYSERROR_UNKNOWN_ERROR) { + tb_char_t const *strerr = "Unknown"; + switch (syserror) { case TB_STATE_SYSERROR_NOT_PERM: strerr = "Permission denied"; break; @@ -66,11 +63,9 @@ tb_int_t xm_os_strerror(lua_State* lua) break; } lua_pushstring(lua, strerr); - } - else - { + } else { #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) - tb_char_t strerr[128] = {0}; + tb_char_t strerr[128] = { 0 }; tb_snprintf(strerr, sizeof(strerr), "Unknown Error (%lu)", (tb_size_t)GetLastError()); lua_pushstring(lua, strerr); #else diff --git a/core/src/xmake/os/syserror.c b/core/src/xmake/os/syserror.c index edd367422..b96a9894f 100644 --- a/core/src/xmake/os/syserror.c +++ b/core/src/xmake/os/syserror.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "syserror" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "syserror" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,22 +33,28 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_syserror(lua_State* lua) -{ +tb_int_t xm_os_syserror(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get syserror state - tb_int_t err = 0; + tb_int_t err = 0; tb_size_t syserror = tb_syserror_state(); - switch (syserror) - { - case TB_STATE_SYSERROR_NOT_PERM: err = 1; break; - case TB_STATE_SYSERROR_NOT_FILEDIR: err = 2; break; + switch (syserror) { + case TB_STATE_SYSERROR_NOT_PERM: + err = 1; + break; + case TB_STATE_SYSERROR_NOT_FILEDIR: + err = 2; + break; #if ((TB_VERSION_MAJOR * 100) + (TB_VERSION_MINOR * 10) + TB_VERSION_ALTER) >= 173 - case TB_STATE_SYSERROR_NOT_ACCESS: err = 3; break; + case TB_STATE_SYSERROR_NOT_ACCESS: + err = 3; + break; #endif - case TB_STATE_SYSERROR_UNKNOWN_ERROR: err = -1; break; + case TB_STATE_SYSERROR_UNKNOWN_ERROR: + err = -1; + break; } lua_pushinteger(lua, err); return 1; diff --git a/core/src/xmake/os/tmpdir.c b/core/src/xmake/os/tmpdir.c index b2c3a0c43..68b99ee8f 100644 --- a/core/src/xmake/os/tmpdir.c +++ b/core/src/xmake/os/tmpdir.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "tmpdir" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "tmpdir" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_tmpdir(lua_State* lua) -{ +tb_int_t xm_os_tmpdir(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // os.tmpdir() tb_char_t path[TB_PATH_MAXN]; - if (tb_directory_temporary(path, sizeof(path))) lua_pushstring(lua, path); - else lua_pushnil(lua); + if (tb_directory_temporary(path, sizeof(path))) + lua_pushstring(lua, path); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/os/touch.c b/core/src/xmake/os/touch.c index 30f214f2b..4e0bd5af8 100644 --- a/core/src/xmake/os/touch.c +++ b/core/src/xmake/os/touch.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "touch" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "touch" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,12 +33,11 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_os_touch(lua_State* lua) -{ +tb_int_t xm_os_touch(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); tb_time_t atime = (tb_time_t)luaL_checknumber(lua, 2); diff --git a/core/src/xmake/os/uid.c b/core/src/xmake/os/uid.c index 246b17b9a..b6413a5e5 100644 --- a/core/src/xmake/os/uid.c +++ b/core/src/xmake/os/uid.c @@ -22,16 +22,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "uid" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "uid" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #ifndef TB_CONFIG_OS_WINDOWS -# include -# include +#include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -40,25 +40,20 @@ #ifndef TB_CONFIG_OS_WINDOWS // get & set uid -tb_int_t xm_os_uid(lua_State* lua) -{ +tb_int_t xm_os_uid(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); tb_int_t ruidset = -1; tb_int_t euidset = -1; - tb_int_t argc = lua_gettop(lua); - if (argc == 1) - { - if (lua_istable(lua, 1)) - { + tb_int_t argc = lua_gettop(lua); + if (argc == 1) { + if (lua_istable(lua, 1)) { // os.uid({["ruid"] = ruid, ["euid"] = euid}) lua_getfield(lua, 1, "ruid"); lua_getfield(lua, 1, "euid"); - if (!lua_isnil(lua, -1)) - { - if (!lua_isnumber(lua, -1)) - { + if (!lua_isnil(lua, -1)) { + if (!lua_isnumber(lua, -1)) { lua_pushfstring(lua, "invalid field type(%s) in `euid` for os.uid", luaL_typename(lua, -1)); lua_error(lua); return 0; @@ -66,10 +61,8 @@ tb_int_t xm_os_uid(lua_State* lua) euidset = (tb_int_t)lua_tonumber(lua, -1); } lua_pop(lua, 1); - if (!lua_isnil(lua, -1)) - { - if (!lua_isnumber(lua, -1)) - { + if (!lua_isnil(lua, -1)) { + if (!lua_isnumber(lua, -1)) { lua_pushfstring(lua, "invalid field type(%s) in `ruid` for os.uid", luaL_typename(lua, -1)); lua_error(lua); return 0; @@ -77,45 +70,33 @@ tb_int_t xm_os_uid(lua_State* lua) ruidset = (tb_int_t)lua_tonumber(lua, -1); } lua_pop(lua, 1); - } - else if (lua_isnumber(lua, 1)) - { + } else if (lua_isnumber(lua, 1)) { // os.uid(uid) ruidset = euidset = (tb_int_t)lua_tonumber(lua, 1); - } - else - { + } else { lua_pushfstring(lua, "invalid argument type(%s) for os.uid", luaL_typename(lua, 1)); lua_error(lua); return 0; } - } - else if (argc == 2) - { + } else if (argc == 2) { // os.uid(ruid, euid) - if (!lua_isnil(lua, 1)) - { - if (!lua_isnumber(lua, 1)) - { + if (!lua_isnil(lua, 1)) { + if (!lua_isnumber(lua, 1)) { lua_pushfstring(lua, "invalid argument type(%s) for os.uid", luaL_typename(lua, 1)); lua_error(lua); return 0; } ruidset = (tb_int_t)lua_tonumber(lua, 1); } - if (!lua_isnil(lua, 2)) - { - if (!lua_isnumber(lua, 2)) - { + if (!lua_isnil(lua, 2)) { + if (!lua_isnumber(lua, 2)) { lua_pushfstring(lua, "invalid argument type(%s) for os.uid", luaL_typename(lua, 2)); lua_error(lua); return 0; } euidset = (tb_int_t)lua_tonumber(lua, 2); } - } - else if (argc != 0) - { + } else if (argc != 0) { lua_pushstring(lua, "invalid argument count for os.uid"); lua_error(lua); return 0; @@ -124,8 +105,7 @@ tb_int_t xm_os_uid(lua_State* lua) // store return value lua_newtable(lua); - if (ruidset != -1 || euidset != -1) - { + if (ruidset != -1 || euidset != -1) { // set ruid & euid lua_pushstring(lua, "errno"); lua_pushinteger(lua, setreuid(ruidset, euidset) != 0 ? errno : 0); diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 57c6a14d2..894141414 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -22,41 +22,39 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "loadxmi" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "loadxmi" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #ifdef USE_LUAJIT -# define XMI_USE_LUAJIT +#define XMI_USE_LUAJIT #endif #include "xmi.h" /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -typedef int (*xm_setup_func_t)(xmi_lua_ops_t* ops); +typedef int (*xm_setup_func_t)(xmi_lua_ops_t *ops); /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_package_loadxmi(lua_State* lua) -{ +tb_int_t xm_package_loadxmi(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); - tb_char_t const* name = luaL_checkstring(lua, 2); + tb_char_t const *name = luaL_checkstring(lua, 2); tb_check_return_val(name, 0); // load module library tb_dynamic_ref_t lib = tb_dynamic_init(path); - if (!lib) - { + if (!lib) { lua_pushnil(lua); lua_pushfstring(lua, "load %s failed", path); return 2; @@ -64,8 +62,7 @@ tb_int_t xm_package_loadxmi(lua_State* lua) // get xmiopen_xxx function lua_CFunction luaopen_func = (lua_CFunction)tb_dynamic_func(lib, name); - if (!luaopen_func) - { + if (!luaopen_func) { lua_pushnil(lua); lua_pushfstring(lua, "cannot get symbol %s failed", name); return 2; @@ -73,69 +70,67 @@ tb_int_t xm_package_loadxmi(lua_State* lua) // get xmisetup function xm_setup_func_t xmisetup_func = (xm_setup_func_t)tb_dynamic_func(lib, "xmisetup"); - if (!xmisetup_func) - { + if (!xmisetup_func) { lua_pushnil(lua); lua_pushfstring(lua, "cannot get symbol xmisetup failed"); return 2; } // setup lua interfaces - static xmi_lua_ops_t s_luaops = {0}; + static xmi_lua_ops_t s_luaops = { 0 }; static tb_bool_t s_luaops_inited = tb_false; - if (!s_luaops_inited) - { + if (!s_luaops_inited) { // get functions #ifdef XMI_USE_LUAJIT - s_luaops._lua_newuserdata = &lua_newuserdata; + s_luaops._lua_newuserdata = &lua_newuserdata; #else - s_luaops._lua_getglobal = &lua_getglobal; - s_luaops._lua_geti = &lua_geti; - s_luaops._lua_rawgetp = &lua_rawgetp; - s_luaops._lua_getiuservalue = &lua_getiuservalue; - s_luaops._lua_newuserdatauv = &lua_newuserdatauv; + s_luaops._lua_getglobal = &lua_getglobal; + s_luaops._lua_geti = &lua_geti; + s_luaops._lua_rawgetp = &lua_rawgetp; + s_luaops._lua_getiuservalue = &lua_getiuservalue; + s_luaops._lua_newuserdatauv = &lua_newuserdatauv; #endif - s_luaops._lua_gettable = &lua_gettable; - s_luaops._lua_getfield = &lua_getfield; - s_luaops._lua_rawget = &lua_rawget; - s_luaops._lua_rawgeti = &lua_rawgeti; - s_luaops._lua_createtable = &lua_createtable; - s_luaops._lua_getmetatable = &lua_getmetatable; + s_luaops._lua_gettable = &lua_gettable; + s_luaops._lua_getfield = &lua_getfield; + s_luaops._lua_rawget = &lua_rawget; + s_luaops._lua_rawgeti = &lua_rawgeti; + s_luaops._lua_createtable = &lua_createtable; + s_luaops._lua_getmetatable = &lua_getmetatable; // set functions #ifndef XMI_USE_LUAJIT - s_luaops._lua_setglobal = &lua_setglobal; - s_luaops._lua_seti = &lua_seti; - s_luaops._lua_rawsetp = &lua_rawsetp; - s_luaops._lua_setiuservalue = &lua_setiuservalue; + s_luaops._lua_setglobal = &lua_setglobal; + s_luaops._lua_seti = &lua_seti; + s_luaops._lua_rawsetp = &lua_rawsetp; + s_luaops._lua_setiuservalue = &lua_setiuservalue; #endif - s_luaops._lua_settable = &lua_settable; - s_luaops._lua_setfield = &lua_setfield; - s_luaops._lua_rawset = &lua_rawset; - s_luaops._lua_rawseti = &lua_rawseti; - s_luaops._lua_setmetatable = &lua_setmetatable; + s_luaops._lua_settable = &lua_settable; + s_luaops._lua_setfield = &lua_setfield; + s_luaops._lua_rawset = &lua_rawset; + s_luaops._lua_rawseti = &lua_rawseti; + s_luaops._lua_setmetatable = &lua_setmetatable; // access functions - s_luaops._lua_isnumber = &lua_isnumber; - s_luaops._lua_isstring = &lua_isstring; - s_luaops._lua_iscfunction = &lua_iscfunction; - s_luaops._lua_isuserdata = &lua_isuserdata; - s_luaops._lua_type = &lua_type; - s_luaops._lua_typename = &lua_typename; + s_luaops._lua_isnumber = &lua_isnumber; + s_luaops._lua_isstring = &lua_isstring; + s_luaops._lua_iscfunction = &lua_iscfunction; + s_luaops._lua_isuserdata = &lua_isuserdata; + s_luaops._lua_type = &lua_type; + s_luaops._lua_typename = &lua_typename; #ifndef XMI_USE_LUAJIT - s_luaops._lua_isinteger = &lua_isinteger; + s_luaops._lua_isinteger = &lua_isinteger; #endif - s_luaops._lua_tonumberx = &lua_tonumberx; - s_luaops._lua_tointegerx = &lua_tointegerx; - s_luaops._lua_toboolean = &lua_toboolean; - s_luaops._lua_tolstring = &lua_tolstring; - s_luaops._lua_tocfunction = &lua_tocfunction; - s_luaops._lua_touserdata = &lua_touserdata; - s_luaops._lua_tothread = &lua_tothread; - s_luaops._lua_topointer = &lua_topointer; + s_luaops._lua_tonumberx = &lua_tonumberx; + s_luaops._lua_tointegerx = &lua_tointegerx; + s_luaops._lua_toboolean = &lua_toboolean; + s_luaops._lua_tolstring = &lua_tolstring; + s_luaops._lua_tocfunction = &lua_tocfunction; + s_luaops._lua_touserdata = &lua_touserdata; + s_luaops._lua_tothread = &lua_tothread; + s_luaops._lua_topointer = &lua_topointer; #ifndef XMI_USE_LUAJIT - s_luaops._lua_rawlen = &lua_rawlen; + s_luaops._lua_rawlen = &lua_rawlen; #endif // push functions @@ -153,74 +148,74 @@ tb_int_t xm_package_loadxmi(lua_State* lua) // stack functions #ifdef XMI_USE_LUAJIT - s_luaops._lua_insert = &lua_insert; - s_luaops._lua_remove = &lua_remove; - s_luaops._lua_replace = &lua_replace; + s_luaops._lua_insert = &lua_insert; + s_luaops._lua_remove = &lua_remove; + s_luaops._lua_replace = &lua_replace; #else - s_luaops._lua_absindex = &lua_absindex; - s_luaops._lua_rotate = &lua_rotate; + s_luaops._lua_absindex = &lua_absindex; + s_luaops._lua_rotate = &lua_rotate; #endif - s_luaops._lua_gettop = &lua_gettop; - s_luaops._lua_settop = &lua_settop; - s_luaops._lua_pushvalue = &lua_pushvalue; - s_luaops._lua_copy = &lua_copy; - s_luaops._lua_checkstack = &lua_checkstack; - s_luaops._lua_xmove = &lua_xmove; + s_luaops._lua_gettop = &lua_gettop; + s_luaops._lua_settop = &lua_settop; + s_luaops._lua_pushvalue = &lua_pushvalue; + s_luaops._lua_copy = &lua_copy; + s_luaops._lua_checkstack = &lua_checkstack; + s_luaops._lua_xmove = &lua_xmove; // miscellaneous functions - s_luaops._lua_error = &lua_error; - s_luaops._lua_next = &lua_next; - s_luaops._lua_concat = &lua_concat; - s_luaops._lua_getallocf = &lua_getallocf; - s_luaops._lua_setallocf = &lua_setallocf; + s_luaops._lua_error = &lua_error; + s_luaops._lua_next = &lua_next; + s_luaops._lua_concat = &lua_concat; + s_luaops._lua_getallocf = &lua_getallocf; + s_luaops._lua_setallocf = &lua_setallocf; #ifndef XMI_USE_LUAJIT - s_luaops._lua_len = &lua_len; - s_luaops._lua_toclose = &lua_toclose; - s_luaops._lua_closeslot = &lua_closeslot; - s_luaops._lua_stringtonumber = &lua_stringtonumber; + s_luaops._lua_len = &lua_len; + s_luaops._lua_toclose = &lua_toclose; + s_luaops._lua_closeslot = &lua_closeslot; + s_luaops._lua_stringtonumber = &lua_stringtonumber; #endif // 'load' and 'call' functions #ifdef XMI_USE_LUAJIT - s_luaops._lua_call = &lua_call; - s_luaops._lua_pcall = &lua_pcall; + s_luaops._lua_call = &lua_call; + s_luaops._lua_pcall = &lua_pcall; #else - s_luaops._lua_callk = &lua_callk; - s_luaops._lua_pcallk = &lua_pcallk; + s_luaops._lua_callk = &lua_callk; + s_luaops._lua_pcallk = &lua_pcallk; #endif - s_luaops._lua_load = &lua_load; - s_luaops._lua_dump = &lua_dump; + s_luaops._lua_load = &lua_load; + s_luaops._lua_dump = &lua_dump; // luaL functions #ifndef XMI_USE_LUAJIT - s_luaops._luaL_tolstring = &luaL_tolstring; - s_luaops._luaL_typeerror = &luaL_typeerror; + s_luaops._luaL_tolstring = &luaL_tolstring; + s_luaops._luaL_typeerror = &luaL_typeerror; #endif - s_luaops._luaL_getmetafield = &luaL_getmetafield; - s_luaops._luaL_callmeta = &luaL_callmeta; - s_luaops._luaL_argerror = &luaL_argerror; - s_luaops._luaL_checklstring = &luaL_checklstring; - s_luaops._luaL_optlstring = &luaL_optlstring; - s_luaops._luaL_checknumber = &luaL_checknumber; - s_luaops._luaL_optnumber = &luaL_optnumber; - s_luaops._luaL_checkinteger = &luaL_checkinteger; - s_luaops._luaL_optinteger = &luaL_optinteger; - s_luaops._luaL_checkstack = &luaL_checkstack; - s_luaops._luaL_checktype = &luaL_checktype; - s_luaops._luaL_checkany = &luaL_checkany; - s_luaops._luaL_newmetatable = &luaL_newmetatable; - s_luaops._luaL_testudata = &luaL_testudata; - s_luaops._luaL_checkudata = &luaL_checkudata; - s_luaops._luaL_where = &luaL_where; - s_luaops._luaL_error = &luaL_error; - s_luaops._luaL_checkoption = &luaL_checkoption; - s_luaops._luaL_fileresult = &luaL_fileresult; - s_luaops._luaL_execresult = &luaL_execresult; - s_luaops._luaL_setfuncs = &luaL_setfuncs; - s_luaops._luaL_loadfilex = &luaL_loadfilex; - s_luaops._luaL_loadstring = &luaL_loadstring; - - s_luaops_inited = tb_true; + s_luaops._luaL_getmetafield = &luaL_getmetafield; + s_luaops._luaL_callmeta = &luaL_callmeta; + s_luaops._luaL_argerror = &luaL_argerror; + s_luaops._luaL_checklstring = &luaL_checklstring; + s_luaops._luaL_optlstring = &luaL_optlstring; + s_luaops._luaL_checknumber = &luaL_checknumber; + s_luaops._luaL_optnumber = &luaL_optnumber; + s_luaops._luaL_checkinteger = &luaL_checkinteger; + s_luaops._luaL_optinteger = &luaL_optinteger; + s_luaops._luaL_checkstack = &luaL_checkstack; + s_luaops._luaL_checktype = &luaL_checktype; + s_luaops._luaL_checkany = &luaL_checkany; + s_luaops._luaL_newmetatable = &luaL_newmetatable; + s_luaops._luaL_testudata = &luaL_testudata; + s_luaops._luaL_checkudata = &luaL_checkudata; + s_luaops._luaL_where = &luaL_where; + s_luaops._luaL_error = &luaL_error; + s_luaops._luaL_checkoption = &luaL_checkoption; + s_luaops._luaL_fileresult = &luaL_fileresult; + s_luaops._luaL_execresult = &luaL_execresult; + s_luaops._luaL_setfuncs = &luaL_setfuncs; + s_luaops._luaL_loadfilex = &luaL_loadfilex; + s_luaops._luaL_loadstring = &luaL_loadstring; + + s_luaops_inited = tb_true; } xmisetup_func(&s_luaops); diff --git a/core/src/xmake/package/prefix.h b/core/src/xmake/package/prefix.h index d6bed58b8..253140059 100644 --- a/core/src/xmake/package/prefix.h +++ b/core/src/xmake/package/prefix.h @@ -26,7 +26,4 @@ */ #include "../prefix.h" - #endif - - diff --git a/core/src/xmake/path/absolute.c b/core/src/xmake/path/absolute.c index a780cdce8..781d2f5e4 100644 --- a/core/src/xmake/path/absolute.c +++ b/core/src/xmake/path/absolute.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "absolute" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "absolute" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_path_absolute(lua_State* lua) -{ +tb_int_t xm_path_absolute(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // get the root - tb_char_t const* root = luaL_optstring(lua, 2, tb_null); + tb_char_t const *root = luaL_optstring(lua, 2, tb_null); // do path:absolute(root) tb_char_t data[TB_PATH_MAXN]; diff --git a/core/src/xmake/path/directory.c b/core/src/xmake/path/directory.c index 2af805d45..aca226a89 100644 --- a/core/src/xmake/path/directory.c +++ b/core/src/xmake/path/directory.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "directory" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "directory" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,19 +33,20 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_path_directory(lua_State* lua) -{ +tb_int_t xm_path_directory(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // do path:directory() - tb_char_t data[TB_PATH_MAXN]; - tb_char_t const* dir = tb_path_directory(path, data, sizeof(data)); - if (dir) lua_pushstring(lua, dir); - else lua_pushnil(lua); + tb_char_t data[TB_PATH_MAXN]; + tb_char_t const *dir = tb_path_directory(path, data, sizeof(data)); + if (dir) + lua_pushstring(lua, dir); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/path/is_absolute.c b/core/src/xmake/path/is_absolute.c index 7ced8d3fe..120476242 100644 --- a/core/src/xmake/path/is_absolute.c +++ b/core/src/xmake/path/is_absolute.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "is_absolute" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "is_absolute" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,13 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_path_is_absolute(lua_State* lua) -{ +tb_int_t xm_path_is_absolute(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // path:is_absolute() diff --git a/core/src/xmake/path/prefix.h b/core/src/xmake/path/prefix.h index 3fe86b204..c87dc37bf 100644 --- a/core/src/xmake/path/prefix.h +++ b/core/src/xmake/path/prefix.h @@ -26,7 +26,4 @@ */ #include "../prefix.h" - #endif - - diff --git a/core/src/xmake/path/relative.c b/core/src/xmake/path/relative.c index ec1dcc215..c6ddad14d 100644 --- a/core/src/xmake/path/relative.c +++ b/core/src/xmake/path/relative.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "relative" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "relative" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_path_relative(lua_State* lua) -{ +tb_int_t xm_path_relative(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path - tb_char_t const* path = luaL_checkstring(lua, 1); + tb_char_t const *path = luaL_checkstring(lua, 1); tb_check_return_val(path, 0); // get the root - tb_char_t const* root = luaL_optstring(lua, 2, tb_null); + tb_char_t const *root = luaL_optstring(lua, 2, tb_null); // path:relative(root) tb_char_t data[TB_PATH_MAXN]; diff --git a/core/src/xmake/path/translate.c b/core/src/xmake/path/translate.c index ecb545098..422cd0320 100644 --- a/core/src/xmake/path/translate.c +++ b/core/src/xmake/path/translate.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "translate" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "translate" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,20 +33,18 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_path_translate(lua_State* lua) -{ +tb_int_t xm_path_translate(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the path size_t path_size = 0; - tb_char_t const* path = luaL_checklstring(lua, 1, &path_size); + tb_char_t const *path = luaL_checklstring(lua, 1, &path_size); tb_check_return_val(path, 0); // get the option argument, e.g. {normalize = true} tb_bool_t normalize = tb_false; - if (lua_istable(lua, 2)) - { + if (lua_istable(lua, 2)) { lua_pushstring(lua, "normalize"); lua_gettable(lua, 2); if (lua_toboolean(lua, -1)) @@ -57,7 +55,9 @@ tb_int_t xm_path_translate(lua_State* lua) // do path:translate() tb_char_t data[TB_PATH_MAXN]; tb_size_t size = tb_path_translate_to(path, (tb_size_t)path_size, data, sizeof(data), normalize); - if (size) lua_pushlstring(lua, data, (size_t)size); - else lua_pushnil(lua); + if (size) + lua_pushlstring(lua, data, (size_t)size); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/prefix.h b/core/src/xmake/prefix.h index 790b9797b..4b159741e 100644 --- a/core/src/xmake/prefix.h +++ b/core/src/xmake/prefix.h @@ -27,19 +27,19 @@ #include "prefix/prefix.h" #include "luaconf.h" #if defined(TB_CONFIG_OS_WINDOWS) && defined(__cplusplus) -# undef LUA_API -# undef LUALIB_API -# define LUA_API extern "C" -# define LUALIB_API LUA_API +#undef LUA_API +#undef LUALIB_API +#define LUA_API extern "C" +#define LUALIB_API LUA_API #endif #ifdef USE_LUAJIT -# include "luajit.h" -# include "lualib.h" -# include "lauxlib.h" +#include "luajit.h" +#include "lualib.h" +#include "lauxlib.h" #else -# include "lua.h" -# include "lualib.h" -# include "lauxlib.h" +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -47,7 +47,7 @@ */ // this issue has been fixed, @see https://github.com/LuaJIT/LuaJIT/commit/e9af1abec542e6f9851ff2368e7f196b6382a44c -#if 0//TB_CPU_BIT64 +#if 0 //TB_CPU_BIT64 /* we use this interface instead of lua_pushlightuserdata() to fix bad light userdata pointer bug * * @see https://github.com/xmake-io/xmake/issues/914 @@ -95,41 +95,33 @@ static __tb_inline__ tb_pointer_t xm_lua_topointer(lua_State* lua, tb_int_t idx) return xm_lua_topointer2(lua, idx, tb_null); } #else -static __tb_inline__ tb_void_t xm_lua_pushpointer(lua_State* lua, tb_pointer_t ptr) -{ +static __tb_inline__ tb_void_t xm_lua_pushpointer(lua_State *lua, tb_pointer_t ptr) { lua_pushlightuserdata(lua, ptr); } -static __tb_inline__ tb_bool_t xm_lua_ispointer(lua_State* lua, tb_int_t idx) -{ +static __tb_inline__ tb_bool_t xm_lua_ispointer(lua_State *lua, tb_int_t idx) { return lua_isuserdata(lua, idx); } -static __tb_inline__ tb_pointer_t xm_lua_topointer2(lua_State* lua, tb_int_t idx, tb_char_t const** pstr) -{ - if (pstr) *pstr = tb_null; +static __tb_inline__ tb_pointer_t xm_lua_topointer2(lua_State *lua, tb_int_t idx, tb_char_t const **pstr) { + if (pstr) + *pstr = tb_null; return lua_touserdata(lua, idx); } -static __tb_inline__ tb_pointer_t xm_lua_topointer(lua_State* lua, tb_int_t idx) -{ +static __tb_inline__ tb_pointer_t xm_lua_topointer(lua_State *lua, tb_int_t idx) { return lua_touserdata(lua, idx); } #endif -static __tb_inline__ tb_void_t xm_lua_register(lua_State *lua, tb_char_t const* libname, luaL_Reg const* l) -{ +static __tb_inline__ tb_void_t xm_lua_register(lua_State *lua, tb_char_t const *libname, luaL_Reg const *l) { #if LUA_VERSION_NUM >= 504 - if (libname) - { + if (libname) { lua_getglobal(lua, libname); - if (lua_isnil(lua, -1)) - { + if (lua_isnil(lua, -1)) { lua_pop(lua, 1); lua_newtable(lua); } luaL_setfuncs(lua, l, 0); lua_setglobal(lua, libname); - } - else - { + } else { luaL_setfuncs(lua, l, 0); } #else @@ -137,8 +129,7 @@ static __tb_inline__ tb_void_t xm_lua_register(lua_State *lua, tb_char_t const* #endif } -static __tb_inline__ tb_int_t xm_lua_isinteger(lua_State* lua, int idx) -{ +static __tb_inline__ tb_int_t xm_lua_isinteger(lua_State *lua, int idx) { #ifdef USE_LUAJIT return lua_isnumber(lua, idx); #else @@ -147,5 +138,3 @@ static __tb_inline__ tb_int_t xm_lua_isinteger(lua_State* lua, int idx) } #endif - - diff --git a/core/src/xmake/prefix/config.h b/core/src/xmake/prefix/config.h index dbf9fb1cf..9ea5384f5 100644 --- a/core/src/xmake/prefix/config.h +++ b/core/src/xmake/prefix/config.h @@ -36,7 +36,7 @@ * small mode */ #if XM_CONFIG_SMALL -# define __xm_small__ +#define __xm_small__ #endif /*! @def __xm_debug__ @@ -44,7 +44,7 @@ * debug mode */ #ifdef __tb_debug__ -# define __xm_debug__ +#define __xm_debug__ #endif /* unix/gcc on msys/cygwin? do not support it now! @@ -64,9 +64,7 @@ * $ make install prefix=/mingw64 */ #if defined(TB_CONFIG_OS_WINDOWS) && defined(TB_COMPILER_LIKE_UNIX) -# error "do not support gcc on msys/cygwin, please uses mingw-w64-[i686|x86_64]-gcc" +#error "do not support gcc on msys/cygwin, please uses mingw-w64-[i686|x86_64]-gcc" #endif #endif - - diff --git a/core/src/xmake/prefix/prefix.h b/core/src/xmake/prefix/prefix.h index ee288bf96..954fca4c7 100644 --- a/core/src/xmake/prefix/prefix.h +++ b/core/src/xmake/prefix/prefix.h @@ -27,7 +27,4 @@ #include "config.h" #include "version.h" - #endif - - diff --git a/core/src/xmake/prefix/version.h b/core/src/xmake/prefix/version.h index 35f60ddf1..c5a3465e2 100644 --- a/core/src/xmake/prefix/version.h +++ b/core/src/xmake/prefix/version.h @@ -31,29 +31,37 @@ */ /// the major version -#define XM_VERSION_MAJOR XM_CONFIG_VERSION_MAJOR +#define XM_VERSION_MAJOR XM_CONFIG_VERSION_MAJOR /// the minor version -#define XM_VERSION_MINOR XM_CONFIG_VERSION_MINOR +#define XM_VERSION_MINOR XM_CONFIG_VERSION_MINOR /// the alter version -#define XM_VERSION_ALTER XM_CONFIG_VERSION_ALTER +#define XM_VERSION_ALTER XM_CONFIG_VERSION_ALTER /// the build version #ifndef XM_CONFIG_VERSION_BUILD -# define XM_CONFIG_VERSION_BUILD 0 +#define XM_CONFIG_VERSION_BUILD 0 #endif -#define XM_VERSION_BUILD XM_CONFIG_VERSION_BUILD +#define XM_VERSION_BUILD XM_CONFIG_VERSION_BUILD /// the build version string -#define XM_VERSION_BUILD_STRING __tb_mstring_ex__(XM_CONFIG_VERSION_BUILD) +#define XM_VERSION_BUILD_STRING __tb_mstring_ex__(XM_CONFIG_VERSION_BUILD) /// the version string -#define XM_VERSION_STRING __tb_mstrcat6__("xmake_", __tb_mstring_ex__(__tb_mconcat8_ex__(v, XM_VERSION_MAJOR, _, XM_VERSION_MINOR, _, XM_VERSION_ALTER, _, XM_CONFIG_VERSION_BUILD)), "_", TB_ARCH_VERSION_STRING, " by ", TB_COMPILER_VERSION_STRING) +#define XM_VERSION_STRING \ + __tb_mstrcat6__("xmake_", \ + __tb_mstring_ex__(__tb_mconcat8_ex__( \ + v, XM_VERSION_MAJOR, _, XM_VERSION_MINOR, _, XM_VERSION_ALTER, _, XM_CONFIG_VERSION_BUILD)), \ + "_", \ + TB_ARCH_VERSION_STRING, \ + " by ", \ + TB_COMPILER_VERSION_STRING) /// the short version string -#define XM_VERSION_SHORT_STRING __tb_mstrcat__("xmake_", __tb_mstring_ex__(__tb_mconcat8_ex__(v, XM_VERSION_MAJOR, _, XM_VERSION_MINOR, _, XM_VERSION_ALTER, _, XM_CONFIG_VERSION_BUILD))) +#define XM_VERSION_SHORT_STRING \ + __tb_mstrcat__("xmake_", \ + __tb_mstring_ex__(__tb_mconcat8_ex__( \ + v, XM_VERSION_MAJOR, _, XM_VERSION_MINOR, _, XM_VERSION_ALTER, _, XM_CONFIG_VERSION_BUILD))) #endif - - diff --git a/core/src/xmake/process/close.c b/core/src/xmake/process/close.c index 71485caac..272a02259 100644 --- a/core/src/xmake/process/close.c +++ b/core/src/xmake/process/close.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "process.close" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "process.close" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // process.close(p) -tb_int_t xm_process_close(lua_State* lua) -{ +tb_int_t xm_process_close(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); diff --git a/core/src/xmake/process/kill.c b/core/src/xmake/process/kill.c index ad153953a..7eb4f8fd7 100644 --- a/core/src/xmake/process/kill.c +++ b/core/src/xmake/process/kill.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "process.kill" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "process.kill" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,8 +35,7 @@ */ // process.kill(p) -tb_int_t xm_process_kill(lua_State* lua) -{ +tb_int_t xm_process_kill(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c index 48d85c1f3..8ed62a0cd 100644 --- a/core/src/xmake/process/open.c +++ b/core/src/xmake/process/open.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "process.open" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "process.open" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -41,33 +41,31 @@ * infile = "", inpipe = "", inpipe = "", * envs = {"PATH=xxx", "XXX=yyy"}}) */ -tb_int_t xm_process_open(lua_State* lua) -{ +tb_int_t xm_process_open(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get command - size_t command_size = 0; - tb_char_t const* command = luaL_checklstring(lua, 1, &command_size); + size_t command_size = 0; + tb_char_t const *command = luaL_checklstring(lua, 1, &command_size); tb_check_return_val(command, 0); // init attributes - tb_process_attr_t attr = {0}; + tb_process_attr_t attr = { 0 }; // get option arguments - tb_size_t envn = 0; - tb_char_t const* envs[1024] = {0}; - tb_char_t const* inpath = tb_null; - tb_char_t const* outpath = tb_null; - tb_char_t const* errpath = tb_null; - xm_io_file_t* infile = tb_null; - xm_io_file_t* outfile = tb_null; - xm_io_file_t* errfile = tb_null; - tb_pipe_file_ref_t inpipe = tb_null; - tb_pipe_file_ref_t outpipe = tb_null; - tb_pipe_file_ref_t errpipe = tb_null; - if (lua_istable(lua, 2)) - { + tb_size_t envn = 0; + tb_char_t const *envs[1024] = { 0 }; + tb_char_t const *inpath = tb_null; + tb_char_t const *outpath = tb_null; + tb_char_t const *errpath = tb_null; + xm_io_file_t *infile = tb_null; + xm_io_file_t *outfile = tb_null; + xm_io_file_t *errfile = tb_null; + tb_pipe_file_ref_t inpipe = tb_null; + tb_pipe_file_ref_t outpipe = tb_null; + tb_pipe_file_ref_t errpipe = tb_null; + if (lua_istable(lua, 2)) { // is detached? lua_pushstring(lua, "detach"); lua_gettable(lua, 2); @@ -100,35 +98,31 @@ tb_int_t xm_process_open(lua_State* lua) lua_pop(lua, 1); // get infile - if (!inpath) - { + if (!inpath) { lua_pushstring(lua, "infile"); lua_gettable(lua, 3); - infile = (xm_io_file_t*)lua_touserdata(lua, -1); + infile = (xm_io_file_t *)lua_touserdata(lua, -1); lua_pop(lua, 1); } // get outfile - if (!outpath) - { + if (!outpath) { lua_pushstring(lua, "outfile"); lua_gettable(lua, 3); - outfile = (xm_io_file_t*)lua_touserdata(lua, -1); + outfile = (xm_io_file_t *)lua_touserdata(lua, -1); lua_pop(lua, 1); } // get errfile - if (!errpath) - { + if (!errpath) { lua_pushstring(lua, "errfile"); lua_gettable(lua, 3); - errfile = (xm_io_file_t*)lua_touserdata(lua, -1); + errfile = (xm_io_file_t *)lua_touserdata(lua, -1); lua_pop(lua, 1); } // get inpipe - if (!inpath && !infile) - { + if (!inpath && !infile) { lua_pushstring(lua, "inpipe"); lua_gettable(lua, 3); inpipe = (tb_pipe_file_ref_t)lua_touserdata(lua, -1); @@ -136,8 +130,7 @@ tb_int_t xm_process_open(lua_State* lua) } // get outpipe - if (!outpath && !outfile) - { + if (!outpath && !outfile) { lua_pushstring(lua, "outpipe"); lua_gettable(lua, 3); outpipe = (tb_pipe_file_ref_t)lua_touserdata(lua, -1); @@ -145,8 +138,7 @@ tb_int_t xm_process_open(lua_State* lua) } // get errpipe - if (!errpath && !errfile) - { + if (!errpath && !errfile) { lua_pushstring(lua, "errpipe"); lua_gettable(lua, 3); errpipe = (tb_pipe_file_ref_t)lua_touserdata(lua, -1); @@ -156,36 +148,36 @@ tb_int_t xm_process_open(lua_State* lua) // get environments lua_pushstring(lua, "envs"); lua_gettable(lua, 2); - if (lua_istable(lua, -1)) - { + if (lua_istable(lua, -1)) { // get environment variables count tb_size_t count = (tb_size_t)lua_objlen(lua, -1); // get all passed environment variables tb_size_t i; - for (i = 0; i < count; i++) - { + for (i = 0; i < count; i++) { // get envs[i] lua_pushinteger(lua, i + 1); lua_gettable(lua, -2); // is string? - if (lua_isstring(lua, -1)) - { + if (lua_isstring(lua, -1)) { // add this environment value if (envn + 1 < tb_arrayn(envs)) envs[envn++] = lua_tostring(lua, -1); - else - { + else { // error - lua_pushfstring(lua, "envs is too large(%d > %d) for process.openv", (tb_int_t)envn, tb_arrayn(envs) - 1); + lua_pushfstring(lua, + "envs is too large(%d > %d) for process.openv", + (tb_int_t)envn, + tb_arrayn(envs) - 1); lua_error(lua); } - } - else - { + } else { // error - lua_pushfstring(lua, "invalid envs[%d] type(%s) for process.openv", (tb_int_t)i, luaL_typename(lua, -1)); + lua_pushfstring(lua, + "invalid envs[%d] type(%s) for process.openv", + (tb_int_t)i, + luaL_typename(lua, -1)); lua_error(lua); } @@ -197,81 +189,65 @@ tb_int_t xm_process_open(lua_State* lua) } // redirect stdin? - if (inpath) - { + if (inpath) { // redirect stdin to file attr.in.path = inpath; attr.inmode = TB_FILE_MODE_RO; attr.intype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; - } - else if (infile && xm_io_file_is_file(infile)) - { + } else if (infile && xm_io_file_is_file(infile)) { tb_file_ref_t rawfile = tb_null; - if (tb_stream_ctrl(infile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) - { + if (tb_stream_ctrl(infile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) { attr.in.file = rawfile; attr.intype = TB_PROCESS_REDIRECT_TYPE_FILE; } - } - else if (inpipe) - { + } else if (inpipe) { attr.in.pipe = inpipe; attr.intype = TB_PROCESS_REDIRECT_TYPE_PIPE; } - // redirect stdout? - if (outpath) - { + if (outpath) { // redirect stdout to file attr.out.path = outpath; attr.outmode = TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT; attr.outtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; - } - else if (outfile && xm_io_file_is_file(outfile)) - { + } else if (outfile && xm_io_file_is_file(outfile)) { tb_file_ref_t rawfile = tb_null; - if (tb_stream_ctrl(outfile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) - { + if (tb_stream_ctrl(outfile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) { attr.out.file = rawfile; attr.outtype = TB_PROCESS_REDIRECT_TYPE_FILE; } - } - else if (outpipe) - { + } else if (outpipe) { attr.out.pipe = outpipe; attr.outtype = TB_PROCESS_REDIRECT_TYPE_PIPE; } // redirect stderr? - if (errpath) - { + if (errpath) { // redirect stderr to file attr.err.path = errpath; attr.errmode = TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT; attr.errtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; - } - else if (errfile && xm_io_file_is_file(errfile)) - { + } else if (errfile && xm_io_file_is_file(errfile)) { tb_file_ref_t rawfile = tb_null; - if (tb_stream_ctrl(errfile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) - { + if (tb_stream_ctrl(errfile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) { attr.err.file = rawfile; attr.errtype = TB_PROCESS_REDIRECT_TYPE_FILE; } - } - else if (errpipe) - { + } else if (errpipe) { attr.err.pipe = errpipe; attr.errtype = TB_PROCESS_REDIRECT_TYPE_PIPE; } // set the new environments - if (envn > 0) attr.envp = envs; + if (envn > 0) + attr.envp = envs; // init process tb_process_ref_t process = (tb_process_ref_t)tb_process_init_cmd(command, &attr); - if (process) xm_lua_pushpointer(lua, (tb_pointer_t)process); - else lua_pushnil(lua); + if (process) + xm_lua_pushpointer(lua, (tb_pointer_t)process); + else + lua_pushnil(lua); return 1; } diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c index 24a8cc112..e605822b1 100644 --- a/core/src/xmake/process/openv.c +++ b/core/src/xmake/process/openv.c @@ -22,16 +22,17 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "process.openv" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "process.openv" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #include "../io/prefix.h" -#if defined(TB_CONFIG_OS_MACOSX) || defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD) || defined(TB_CONFIG_OS_HAIKU) || defined(TB_COMPILER_IS_MINGW) -# include +#if defined(TB_CONFIG_OS_MACOSX) || defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD) || \ + defined(TB_CONFIG_OS_HAIKU) || defined(TB_COMPILER_IS_MINGW) +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -44,14 +45,12 @@ * infile = "", inpipe = "", inpipe = "", * envs = {"PATH=xxx", "XXX=yyy"}}) */ -tb_int_t xm_process_openv(lua_State* lua) -{ +tb_int_t xm_process_openv(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // check argv - if (!lua_istable(lua, 2)) - { + if (!lua_istable(lua, 2)) { // error lua_pushfstring(lua, "invalid argv type(%s) for process.openv", luaL_typename(lua, 2)); lua_error(lua); @@ -59,7 +58,7 @@ tb_int_t xm_process_openv(lua_State* lua) } // get shellname - tb_char_t const* shellname = lua_tostring(lua, 1); + tb_char_t const *shellname = lua_tostring(lua, 1); tb_check_return_val(shellname, 0); // get the arguments count @@ -67,34 +66,29 @@ tb_int_t xm_process_openv(lua_State* lua) tb_check_return_val(argn >= 0, 0); // get arguments - tb_size_t argi = 0; - tb_char_t const** argv = tb_nalloc0_type(1 + argn + 1, tb_char_t const*); + tb_size_t argi = 0; + tb_char_t const **argv = tb_nalloc0_type(1 + argn + 1, tb_char_t const *); tb_check_return_val(argv, 0); // fill arguments argv[0] = shellname; - for (argi = 0; argi < argn; argi++) - { + for (argi = 0; argi < argn; argi++) { // get argv[i] lua_pushinteger(lua, argi + 1); lua_gettable(lua, 2); // is string? - if (lua_isstring(lua, -1)) - { + if (lua_isstring(lua, -1)) { // pass this argument argv[1 + argi] = lua_tostring(lua, -1); } // is path instance? - else if (lua_istable(lua, -1)) - { + else if (lua_istable(lua, -1)) { lua_pushstring(lua, "_STR"); lua_gettable(lua, -2); argv[1 + argi] = lua_tostring(lua, -1); lua_pop(lua, 1); - } - else - { + } else { // error lua_pushfstring(lua, "invalid argv[%d] type(%s) for process.openv", (tb_int_t)argi, luaL_typename(lua, -1)); lua_error(lua); @@ -105,23 +99,22 @@ tb_int_t xm_process_openv(lua_State* lua) } // init attributes - tb_process_attr_t attr = {0}; + tb_process_attr_t attr = { 0 }; // get option arguments - tb_bool_t exclusive = tb_false; - tb_size_t envn = 0; - tb_char_t const* envs[1024] = {0}; - tb_char_t const* inpath = tb_null; - tb_char_t const* outpath = tb_null; - tb_char_t const* errpath = tb_null; - xm_io_file_t* infile = tb_null; - xm_io_file_t* outfile = tb_null; - xm_io_file_t* errfile = tb_null; - tb_pipe_file_ref_t inpipe = tb_null; - tb_pipe_file_ref_t outpipe = tb_null; - tb_pipe_file_ref_t errpipe = tb_null; - if (lua_istable(lua, 3)) - { + tb_bool_t exclusive = tb_false; + tb_size_t envn = 0; + tb_char_t const *envs[1024] = { 0 }; + tb_char_t const *inpath = tb_null; + tb_char_t const *outpath = tb_null; + tb_char_t const *errpath = tb_null; + xm_io_file_t *infile = tb_null; + xm_io_file_t *outfile = tb_null; + xm_io_file_t *errfile = tb_null; + tb_pipe_file_ref_t inpipe = tb_null; + tb_pipe_file_ref_t outpipe = tb_null; + tb_pipe_file_ref_t errpipe = tb_null; + if (lua_istable(lua, 3)) { // is detached? lua_pushstring(lua, "detach"); lua_gettable(lua, 3); @@ -161,35 +154,31 @@ tb_int_t xm_process_openv(lua_State* lua) lua_pop(lua, 1); // get infile - if (!inpath) - { + if (!inpath) { lua_pushstring(lua, "infile"); lua_gettable(lua, 3); - infile = (xm_io_file_t*)lua_touserdata(lua, -1); + infile = (xm_io_file_t *)lua_touserdata(lua, -1); lua_pop(lua, 1); } // get outfile - if (!outpath) - { + if (!outpath) { lua_pushstring(lua, "outfile"); lua_gettable(lua, 3); - outfile = (xm_io_file_t*)lua_touserdata(lua, -1); + outfile = (xm_io_file_t *)lua_touserdata(lua, -1); lua_pop(lua, 1); } // get errfile - if (!errpath) - { + if (!errpath) { lua_pushstring(lua, "errfile"); lua_gettable(lua, 3); - errfile = (xm_io_file_t*)lua_touserdata(lua, -1); + errfile = (xm_io_file_t *)lua_touserdata(lua, -1); lua_pop(lua, 1); } // get inpipe - if (!inpath && !infile) - { + if (!inpath && !infile) { lua_pushstring(lua, "inpipe"); lua_gettable(lua, 3); inpipe = (tb_pipe_file_ref_t)lua_touserdata(lua, -1); @@ -197,8 +186,7 @@ tb_int_t xm_process_openv(lua_State* lua) } // get outpipe - if (!outpath && !outfile) - { + if (!outpath && !outfile) { lua_pushstring(lua, "outpipe"); lua_gettable(lua, 3); outpipe = (tb_pipe_file_ref_t)lua_touserdata(lua, -1); @@ -206,8 +194,7 @@ tb_int_t xm_process_openv(lua_State* lua) } // get errpipe - if (!errpath && !errfile) - { + if (!errpath && !errfile) { lua_pushstring(lua, "errpipe"); lua_gettable(lua, 3); errpipe = (tb_pipe_file_ref_t)lua_touserdata(lua, -1); @@ -217,36 +204,36 @@ tb_int_t xm_process_openv(lua_State* lua) // get environments lua_pushstring(lua, "envs"); lua_gettable(lua, 3); - if (lua_istable(lua, -1)) - { + if (lua_istable(lua, -1)) { // get environment variables count tb_size_t count = (tb_size_t)lua_objlen(lua, -1); // get all passed environment variables tb_size_t i; - for (i = 0; i < count; i++) - { + for (i = 0; i < count; i++) { // get envs[i] lua_pushinteger(lua, i + 1); lua_gettable(lua, -2); // is string? - if (lua_isstring(lua, -1)) - { + if (lua_isstring(lua, -1)) { // add this environment value if (envn + 1 < tb_arrayn(envs)) envs[envn++] = lua_tostring(lua, -1); - else - { + else { // error - lua_pushfstring(lua, "envs is too large(%d > %d) for process.openv", (tb_int_t)envn, tb_arrayn(envs) - 1); + lua_pushfstring(lua, + "envs is too large(%d > %d) for process.openv", + (tb_int_t)envn, + tb_arrayn(envs) - 1); lua_error(lua); } - } - else - { + } else { // error - lua_pushfstring(lua, "invalid envs[%d] type(%s) for process.openv", (tb_int_t)i, luaL_typename(lua, -1)); + lua_pushfstring(lua, + "invalid envs[%d] type(%s) for process.openv", + (tb_int_t)i, + luaL_typename(lua, -1)); lua_error(lua); } @@ -258,94 +245,82 @@ tb_int_t xm_process_openv(lua_State* lua) } // redirect stdin? - if (inpath) - { + if (inpath) { // redirect stdin to file attr.in.path = inpath; attr.inmode = TB_FILE_MODE_RO; attr.intype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; - } - else if (infile && xm_io_file_is_file(infile)) - { + } else if (infile && xm_io_file_is_file(infile)) { tb_file_ref_t rawfile = tb_null; - if (tb_stream_ctrl(infile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) - { + if (tb_stream_ctrl(infile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) { attr.in.file = rawfile; attr.intype = TB_PROCESS_REDIRECT_TYPE_FILE; } - } - else if (inpipe) - { + } else if (inpipe) { attr.in.pipe = inpipe; attr.intype = TB_PROCESS_REDIRECT_TYPE_PIPE; } // redirect stdout? - if (outpath) - { + if (outpath) { // redirect stdout to file attr.out.path = outpath; attr.outmode = TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT; attr.outtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; - } - else if (outfile && xm_io_file_is_file(outfile)) - { + } else if (outfile && xm_io_file_is_file(outfile)) { tb_file_ref_t rawfile = tb_null; - if (tb_stream_ctrl(outfile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) - { + if (tb_stream_ctrl(outfile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) { attr.out.file = rawfile; attr.outtype = TB_PROCESS_REDIRECT_TYPE_FILE; } - } - else if (outpipe) - { + } else if (outpipe) { attr.out.pipe = outpipe; attr.outtype = TB_PROCESS_REDIRECT_TYPE_PIPE; } // redirect stderr? - if (errpath) - { + if (errpath) { // redirect stderr to file attr.err.path = errpath; attr.errmode = TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT; attr.errtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; - } - else if (errfile && xm_io_file_is_file(errfile)) - { + } else if (errfile && xm_io_file_is_file(errfile)) { tb_file_ref_t rawfile = tb_null; - if (tb_stream_ctrl(errfile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) - { + if (tb_stream_ctrl(errfile->stream, TB_STREAM_CTRL_FILE_GET_FILE, &rawfile) && rawfile) { attr.err.file = rawfile; attr.errtype = TB_PROCESS_REDIRECT_TYPE_FILE; } - } - else if (errpipe) - { + } else if (errpipe) { attr.err.pipe = errpipe; attr.errtype = TB_PROCESS_REDIRECT_TYPE_PIPE; } // set the new environments - if (envn > 0) attr.envp = envs; + if (envn > 0) + attr.envp = envs; /* we need to ignore SIGINT and SIGQUIT if we enter exclusive mode * @see https://github.com/xmake-io/xmake/discussions/2893 */ #if defined(SIGINT) - if (exclusive) signal(SIGINT, SIG_IGN); + if (exclusive) + signal(SIGINT, SIG_IGN); #endif #if defined(SIGQUIT) - if (exclusive) signal(SIGQUIT, SIG_IGN); + if (exclusive) + signal(SIGQUIT, SIG_IGN); #endif // init process tb_process_ref_t process = (tb_process_ref_t)tb_process_init(shellname, argv, &attr); - if (process) xm_lua_pushpointer(lua, (tb_pointer_t)process); - else lua_pushnil(lua); + if (process) + xm_lua_pushpointer(lua, (tb_pointer_t)process); + else + lua_pushnil(lua); // exit argv - if (argv) tb_free(argv); + if (argv) + tb_free(argv); argv = tb_null; // ok diff --git a/core/src/xmake/process/prefix.h b/core/src/xmake/process/prefix.h index 8389ccc65..74fb665d4 100644 --- a/core/src/xmake/process/prefix.h +++ b/core/src/xmake/process/prefix.h @@ -27,5 +27,3 @@ #include "../prefix.h" #endif - - diff --git a/core/src/xmake/process/wait.c b/core/src/xmake/process/wait.c index 055ae4fab..2914d87cc 100644 --- a/core/src/xmake/process/wait.c +++ b/core/src/xmake/process/wait.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "process.wait" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "process.wait" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,14 +35,12 @@ */ // ok, status = process.wait(proc, timeout) -tb_int_t xm_process_wait(lua_State* lua) -{ +tb_int_t xm_process_wait(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) - { + if (!xm_lua_ispointer(lua, 1)) { // error lua_pushfstring(lua, "invalid argument type(%s) for process.wait", luaL_typename(lua, 1)); lua_error(lua); @@ -58,7 +56,7 @@ tb_int_t xm_process_wait(lua_State* lua) // wait it tb_long_t status = 0; - tb_long_t ok = tb_process_wait(process, &status, timeout); + tb_long_t ok = tb_process_wait(process, &status, timeout); // save result lua_pushinteger(lua, ok); diff --git a/core/src/xmake/readline/add_history.c b/core/src/xmake/readline/add_history.c index bac1aae24..f928cc446 100644 --- a/core/src/xmake/readline/add_history.c +++ b/core/src/xmake/readline/add_history.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "add_history" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "add_history" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,13 +36,12 @@ #ifdef XM_CONFIG_API_HAVE_READLINE // add_history wrapper -tb_int_t xm_readline_add_history(lua_State* lua) -{ +tb_int_t xm_readline_add_history(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get history - tb_char_t const* history = luaL_checkstring(lua, 1); + tb_char_t const *history = luaL_checkstring(lua, 1); tb_check_return_val(history, 0); // call add_history diff --git a/core/src/xmake/readline/clear_history.c b/core/src/xmake/readline/clear_history.c index 8582736f5..11f7ab30c 100644 --- a/core/src/xmake/readline/clear_history.c +++ b/core/src/xmake/readline/clear_history.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "clear_history" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "clear_history" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,8 +36,7 @@ #ifdef XM_CONFIG_API_HAVE_READLINE // clear_history wrapper -tb_int_t xm_readline_clear_history(lua_State* lua) -{ +tb_int_t xm_readline_clear_history(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); diff --git a/core/src/xmake/readline/history_list.c b/core/src/xmake/readline/history_list.c index c072cbd8d..56d84e114 100644 --- a/core/src/xmake/readline/history_list.c +++ b/core/src/xmake/readline/history_list.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "history_list" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "history_list" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -36,8 +36,7 @@ #ifdef XM_CONFIG_API_HAVE_READLINE // history_list wrapper -tb_int_t xm_readline_history_list(lua_State* lua) -{ +tb_int_t xm_readline_history_list(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -45,8 +44,7 @@ tb_int_t xm_readline_history_list(lua_State* lua) lua_newtable(lua); #ifdef TB_CONFIG_OS_MACOSX - for (tb_int_t i = 1; i <= history_length; ++i) - { + for (tb_int_t i = 1; i <= history_length; ++i) { lua_newtable(lua); // field line @@ -59,8 +57,7 @@ tb_int_t xm_readline_history_list(lua_State* lua) } #else tb_int_t i = 1; - for (HIST_ENTRY **p = history_list(); *p; ++p, ++i) - { + for (HIST_ENTRY **p = history_list(); *p; ++p, ++i) { lua_newtable(lua); // field line diff --git a/core/src/xmake/readline/prefix.h b/core/src/xmake/readline/prefix.h index 0a67aad27..959ea17f3 100644 --- a/core/src/xmake/readline/prefix.h +++ b/core/src/xmake/readline/prefix.h @@ -26,12 +26,9 @@ */ #include "../prefix.h" #ifdef XM_CONFIG_API_HAVE_READLINE -# include // on some OS (like centos) required -# include -# include +#include // on some OS (like centos) required +#include +#include #endif - #endif - - diff --git a/core/src/xmake/readline/readline.c b/core/src/xmake/readline/readline.c index 1e1fdc240..6675c6de2 100644 --- a/core/src/xmake/readline/readline.c +++ b/core/src/xmake/readline/readline.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "readline" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "readline" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -37,25 +37,23 @@ */ // readline wrapper -tb_int_t xm_readline_readline(lua_State* lua) -{ +tb_int_t xm_readline_readline(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the prompt - tb_char_t const* prompt = luaL_optstring(lua, 1, tb_null); + tb_char_t const *prompt = luaL_optstring(lua, 1, tb_null); // call readline - tb_char_t* line = readline(prompt); - if (line) - { + tb_char_t *line = readline(prompt); + if (line) { // return line lua_pushstring(lua, line); // free it tb_free(line); - } - else lua_pushnil(lua); + } else + lua_pushnil(lua); // ok return 1; diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c index 7c83ca06e..01bac19b4 100644 --- a/core/src/xmake/sandbox/interactive.c +++ b/core/src/xmake/sandbox/interactive.c @@ -38,10 +38,10 @@ #include "prefix.h" #include "../winos/ansi.h" #ifdef XM_CONFIG_API_HAVE_READLINE -# include -# include -# include -# include // on some OS (like centos) required +#include +#include +#include +#include // on some OS (like centos) required #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -53,7 +53,7 @@ // for lua5.4 #ifndef LUA_QL -# define LUA_QL(x) "'" x "'" +#define LUA_QL(x) "'" x "'" #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -61,13 +61,12 @@ */ // report results -static tb_void_t xm_sandbox_report(lua_State *lua) -{ - if (!lua_isnil(lua, -1)) - { +static tb_void_t xm_sandbox_report(lua_State *lua) { + if (!lua_isnil(lua, -1)) { // get message - tb_char_t const* msg = lua_tostring(lua, -1); - if (!msg) msg = "(error object is not a string)"; + tb_char_t const *msg = lua_tostring(lua, -1); + if (!msg) + msg = "(error object is not a string)"; // print it tb_printl(msg); @@ -79,10 +78,8 @@ static tb_void_t xm_sandbox_report(lua_State *lua) } // the traceback function -static tb_int_t xm_sandbox_traceback(lua_State *lua) -{ - if (!lua_isstring(lua, 1)) - { +static tb_int_t xm_sandbox_traceback(lua_State *lua) { + if (!lua_isstring(lua, 1)) { // non-string error object? try metamethod. if (lua_isnoneornil(lua, 1) || !luaL_callmeta(lua, 1, "__tostring") || !lua_isstring(lua, -1)) return 1; // return non-string error object. @@ -97,8 +94,7 @@ static tb_int_t xm_sandbox_traceback(lua_State *lua) } // execute codes -static tb_int_t xm_sandbox_docall(lua_State* lua, tb_int_t narg, tb_int_t clear) -{ +static tb_int_t xm_sandbox_docall(lua_State *lua, tb_int_t narg, tb_int_t clear) { /* get error function index * * stack: arg1(sandbox_scope) scriptfunc(top) -> ... @@ -122,23 +118,21 @@ static tb_int_t xm_sandbox_docall(lua_State* lua, tb_int_t narg, tb_int_t clear) lua_remove(lua, errfunc); // force a complete garbage collection in case of errors - if (status != 0) lua_gc(lua, LUA_GCCOLLECT, 0); + if (status != 0) + lua_gc(lua, LUA_GCCOLLECT, 0); // ok? return status; } // this line is incomplete? -static tb_int_t xm_sandbox_incomplete(lua_State *lua, tb_int_t status) -{ +static tb_int_t xm_sandbox_incomplete(lua_State *lua, tb_int_t status) { // syntax error? - if (status == LUA_ERRSYNTAX) - { + if (status == LUA_ERRSYNTAX) { size_t lmsg; - tb_char_t const* msg = lua_tolstring(lua, -1, &lmsg); - tb_char_t const* tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); - if (tb_strstr(msg, LUA_QL("")) == tp) - { + tb_char_t const *msg = lua_tolstring(lua, -1, &lmsg); + tb_char_t const *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); + if (tb_strstr(msg, LUA_QL("")) == tp) { lua_pop(lua, 1); return 1; } @@ -146,13 +140,11 @@ static tb_int_t xm_sandbox_incomplete(lua_State *lua, tb_int_t status) return 0; } // read line -static tb_size_t xm_sandbox_readline(tb_char_t* data, tb_size_t maxn, tb_char_t const* prompt) -{ +static tb_size_t xm_sandbox_readline(tb_char_t *data, tb_size_t maxn, tb_char_t const *prompt) { #ifdef XM_CONFIG_API_HAVE_READLINE // get line - tb_char_t const* line = readline(prompt); - if (line) - { + tb_char_t const *line = readline(prompt); + if (line) { // add line to history add_history(line); @@ -160,10 +152,11 @@ static tb_size_t xm_sandbox_readline(tb_char_t* data, tb_size_t maxn, tb_char_t tb_size_t size = tb_strlcpy(data, line, maxn); // free line - free((void*)line); + free((void *)line); // truncated? - if (size >= maxn) return 0; + if (size >= maxn) + return 0; // ok return size; @@ -184,13 +177,11 @@ static tb_size_t xm_sandbox_readline(tb_char_t* data, tb_size_t maxn, tb_char_t } // read and push input line -static tb_int_t xm_sandbox_pushline(lua_State* lua, tb_char_t const* prompt2) -{ +static tb_int_t xm_sandbox_pushline(lua_State *lua, tb_char_t const *prompt2) { // read line tb_char_t data[LUA_PROMPT_BUFSIZE]; tb_size_t size = xm_sandbox_readline(data, sizeof(data), prompt2); - if (size) - { + if (size) { // split line '\0' if (data[size - 1] == '\n') data[size - 1] = '\0'; @@ -207,28 +198,26 @@ static tb_int_t xm_sandbox_pushline(lua_State* lua, tb_char_t const* prompt2) } // load code line -static tb_int_t xm_sandbox_loadline(lua_State* lua, tb_int_t top) -{ +static tb_int_t xm_sandbox_loadline(lua_State *lua, tb_int_t top) { // clear stack lua_settop(lua, top); // get prompt strings from arg1(sandbox_scope) lua_pushstring(lua, "$interactive_prompt"); lua_gettable(lua, 1); - tb_char_t const* prompt = lua_tostring(lua, -1); + tb_char_t const *prompt = lua_tostring(lua, -1); lua_pop(lua, 1); lua_pushstring(lua, "$interactive_prompt2"); lua_gettable(lua, 1); - tb_char_t const* prompt2 = lua_tostring(lua, -1); + tb_char_t const *prompt2 = lua_tostring(lua, -1); lua_pop(lua, 1); // read first line tb_int_t status; tb_char_t data[LUA_PROMPT_BUFSIZE]; tb_size_t size = xm_sandbox_readline(data + 7, sizeof(data) - 7, prompt); - if (size) - { + if (size) { // split line '\0' if (data[size - 1] == '\n') data[--size] = '\0'; @@ -240,19 +229,19 @@ static tb_int_t xm_sandbox_loadline(lua_State* lua, tb_int_t top) status = luaL_loadbuffer(lua, data, size + 7, "=stdin"); // ok? - if (status != LUA_ERRSYNTAX) return status; + if (status != LUA_ERRSYNTAX) + return status; // pop error msg lua_pop(lua, 1); // push line to load it again lua_pushstring(lua, data + 7); - } - else return -1; + } else + return -1; // load input line - while (1) - { + while (1) { /* repeat until gets a complete line * * stack: arg1(sandbox_scope) scriptbuffer(top) -> ... @@ -261,14 +250,15 @@ static tb_int_t xm_sandbox_loadline(lua_State* lua, tb_int_t top) status = luaL_loadbuffer(lua, lua_tostring(lua, -1), (size_t)lua_strlen(lua, -1), "=stdin"); // complete? - if (!xm_sandbox_incomplete(lua, status)) break; + if (!xm_sandbox_incomplete(lua, status)) + break; // get more input - if (!xm_sandbox_pushline(lua, prompt2)) return -1; + if (!xm_sandbox_pushline(lua, prompt2)) + return -1; // cancel multi-line input? - if (!tb_strcmp(lua_tostring(lua, -1), "q")) - { + if (!tb_strcmp(lua_tostring(lua, -1), "q")) { lua_pop(lua, 2); lua_pushstring(lua, "return "); continue; @@ -301,8 +291,7 @@ static tb_int_t xm_sandbox_loadline(lua_State* lua, tb_int_t top) */ // sandbox.interactive() -tb_int_t xm_sandbox_interactive(lua_State* lua) -{ +tb_int_t xm_sandbox_interactive(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -314,11 +303,9 @@ tb_int_t xm_sandbox_interactive(lua_State* lua) // enter interactive tb_int_t status; - while ((status = xm_sandbox_loadline(lua, top)) != -1) - { + while ((status = xm_sandbox_loadline(lua, top)) != -1) { // execute codes - if (status == 0) - { + if (status == 0) { /* bind sandbox * * stack: arg1(top) scriptfunc arg1(sandbox_scope) -> ... @@ -332,7 +319,9 @@ tb_int_t xm_sandbox_interactive(lua_State* lua) lua_pushvalue(lua, -2); lua_pushvalue(lua, 1); if (lua_pcall(lua, 2, 0, 0) != 0) - tb_printl(lua_pushfstring(lua, "error calling " LUA_QL("$interactive_setfenv") " (%s)", lua_tostring(lua, -1))); + tb_printl(lua_pushfstring(lua, + "error calling " LUA_QL("$interactive_setfenv") " (%s)", + lua_tostring(lua, -1))); #endif /* run script @@ -347,8 +336,7 @@ tb_int_t xm_sandbox_interactive(lua_State* lua) xm_sandbox_report(lua); // print any results - if (status == 0 && lua_gettop(lua) > top) - { + if (status == 0 && lua_gettop(lua) > top) { // get results count tb_int_t count = lua_gettop(lua) - top; @@ -360,7 +348,8 @@ tb_int_t xm_sandbox_interactive(lua_State* lua) lua_getfield(lua, 1, "$interactive_dump"); // load $interactive_dump() from sandbox_scope lua_insert(lua, -(count + 1)); if (lua_pcall(lua, count, 0, 0) != 0) - tb_printl(lua_pushfstring(lua, "error calling " LUA_QL("$interactive_dump") " (%s)", lua_tostring(lua, -1))); + tb_printl( + lua_pushfstring(lua, "error calling " LUA_QL("$interactive_dump") " (%s)", lua_tostring(lua, -1))); } } diff --git a/core/src/xmake/sandbox/prefix.h b/core/src/xmake/sandbox/prefix.h index 5643b16f3..5c183bb7c 100644 --- a/core/src/xmake/sandbox/prefix.h +++ b/core/src/xmake/sandbox/prefix.h @@ -26,7 +26,4 @@ */ #include "../prefix.h" - #endif - - diff --git a/core/src/xmake/semver/compare.c b/core/src/xmake/semver/compare.c index 56139b934..87e2356a3 100644 --- a/core/src/xmake/semver/compare.c +++ b/core/src/xmake/semver/compare.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "compare" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "compare" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,33 +35,29 @@ */ // semver.compare("v1.0.1-beta", "1.2") > 0? -tb_int_t xm_semver_compare(lua_State* lua) -{ +tb_int_t xm_semver_compare(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the version1 string - tb_char_t const* version1_str = luaL_checkstring(lua, 1); + tb_char_t const *version1_str = luaL_checkstring(lua, 1); tb_check_return_val(version1_str, 0); // get the version2 string - tb_char_t const* version2_str = luaL_checkstring(lua, 2); + tb_char_t const *version2_str = luaL_checkstring(lua, 2); tb_check_return_val(version2_str, 0); // try to parse version1 string - semver_t semver1 = {0}; - if (semver_tryn(&semver1, version1_str, tb_strlen(version1_str))) - { + semver_t semver1 = { 0 }; + if (semver_tryn(&semver1, version1_str, tb_strlen(version1_str))) { lua_pushnil(lua); lua_pushfstring(lua, "unable to parse semver '%s'", version1_str); return 2; } - // try to parse version2 string - semver_t semver2 = {0}; - if (semver_tryn(&semver2, version2_str, tb_strlen(version2_str))) - { + semver_t semver2 = { 0 }; + if (semver_tryn(&semver2, version2_str, tb_strlen(version2_str))) { lua_pushnil(lua); lua_pushfstring(lua, "unable to parse semver '%s'", version2_str); return 2; diff --git a/core/src/xmake/semver/parse.c b/core/src/xmake/semver/parse.c index 1f458462d..e9dc221ee 100644 --- a/core/src/xmake/semver/parse.c +++ b/core/src/xmake/semver/parse.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "parse" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "parse" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -54,19 +54,17 @@ } * */ -tb_int_t xm_semver_parse(lua_State* lua) -{ +tb_int_t xm_semver_parse(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the version string - tb_char_t const* version_str = luaL_checkstring(lua, 1); + tb_char_t const *version_str = luaL_checkstring(lua, 1); tb_check_return_val(version_str, 0); // try to parse version string - semver_t semver = {0}; - if (semver_tryn(&semver, version_str, tb_strlen(version_str))) - { + semver_t semver = { 0 }; + if (semver_tryn(&semver, version_str, tb_strlen(version_str))) { lua_pushnil(lua); lua_pushfstring(lua, "unable to parse semver '%s'", version_str); return 2; diff --git a/core/src/xmake/semver/prefix.h b/core/src/xmake/semver/prefix.h index 2c365a73c..5d9f15b1d 100644 --- a/core/src/xmake/semver/prefix.h +++ b/core/src/xmake/semver/prefix.h @@ -42,7 +42,8 @@ __tb_extern_c_enter__ * @param semver the semver struct * */ -tb_void_t lua_pushsemver(lua_State *lua, semver_t const* semver); +tb_void_t +lua_pushsemver(lua_State *lua, semver_t const *semver); /* ////////////////////////////////////////////////////////////////////////////////////// * leave diff --git a/core/src/xmake/semver/satisfies.c b/core/src/xmake/semver/satisfies.c index 2c815e4dd..55c0decb9 100644 --- a/core/src/xmake/semver/satisfies.c +++ b/core/src/xmake/semver/satisfies.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "satisfies" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "satisfies" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -38,48 +38,39 @@ * * semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') => true */ -tb_int_t xm_semver_satisfies(lua_State* lua) -{ +tb_int_t xm_semver_satisfies(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the version string - tb_char_t const* version_str = luaL_checkstring(lua, 1); - tb_char_t const* range_str = luaL_checkstring(lua, 2); + tb_char_t const *version_str = luaL_checkstring(lua, 1); + tb_char_t const *range_str = luaL_checkstring(lua, 2); tb_assert_and_check_return_val(version_str && range_str, 0); // parse the version range string - semver_range_t range = {0}; - if (semver_rangen(&range, range_str, tb_strlen(range_str))) - { + semver_range_t range = { 0 }; + if (semver_rangen(&range, range_str, tb_strlen(range_str))) { // range is branch name? try to match it - semver_t range_semver = {0}; - if (!tb_strcmp(version_str, range_str)) - { + semver_t range_semver = { 0 }; + if (!tb_strcmp(version_str, range_str)) { lua_pushboolean(lua, tb_true); return 1; } // range is a single version? try to compare it - else if (!semver_tryn(&range_semver, range_str, tb_strlen(range_str))) - { - semver_t semver = {0}; - if (!semver_tryn(&semver, version_str, tb_strlen(version_str))) - { + else if (!semver_tryn(&range_semver, range_str, tb_strlen(range_str))) { + semver_t semver = { 0 }; + if (!semver_tryn(&semver, version_str, tb_strlen(version_str))) { lua_pushboolean(lua, semver_pcmp(&semver, &range_semver) == 0); semver_dtor(&semver); semver_dtor(&range_semver); return 1; - } - else - { + } else { semver_dtor(&range_semver); lua_pushnil(lua); lua_pushfstring(lua, "unable to parse semver '%s'", version_str); return 2; } - } - else - { + } else { lua_pushnil(lua); lua_pushfstring(lua, "unable to parse semver range '%s'", range_str); return 2; @@ -87,9 +78,8 @@ tb_int_t xm_semver_satisfies(lua_State* lua) } // try to parse the version string - semver_t semver = {0}; - if (semver_tryn(&semver, version_str, tb_strlen(version_str))) - { + semver_t semver = { 0 }; + if (semver_tryn(&semver, version_str, tb_strlen(version_str))) { lua_pushnil(lua); lua_pushfstring(lua, "unable to parse semver '%s'", version_str); return 2; diff --git a/core/src/xmake/semver/select.c b/core/src/xmake/semver/select.c index 762fd848f..373a71711 100644 --- a/core/src/xmake/semver/select.c +++ b/core/src/xmake/semver/select.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "select" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "select" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,24 +33,24 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_bool_t xm_semver_select_from_versions_tags1(lua_State* lua, tb_int_t fromidx, semver_t* semver, semver_range_t const* range, semvers_t* matches) -{ +static tb_bool_t xm_semver_select_from_versions_tags1( + lua_State *lua, tb_int_t fromidx, semver_t *semver, semver_range_t const *range, semvers_t *matches) { // clear matches semvers_pclear(matches); // select all matches lua_Integer i = 0; luaL_checktype(lua, fromidx, LUA_TTABLE); - for (i = lua_objlen(lua, fromidx); i > 0; --i) - { + for (i = lua_objlen(lua, fromidx); i > 0; --i) { lua_pushinteger(lua, i); lua_gettable(lua, fromidx); - tb_char_t const* source_str = luaL_checkstring(lua, -1); - if (source_str && semver_tryn(semver, source_str, tb_strlen(source_str)) == 0) - { - if (semver_range_pmatch(semver, range)) semvers_ppush(matches, *semver); - else semver_dtor(semver); + tb_char_t const *source_str = luaL_checkstring(lua, -1); + if (source_str && semver_tryn(semver, source_str, tb_strlen(source_str)) == 0) { + if (semver_range_pmatch(semver, range)) + semvers_ppush(matches, *semver); + else + semver_dtor(semver); } lua_pop(lua, 1); } @@ -69,7 +69,7 @@ static tb_bool_t xm_semver_select_from_versions_tags1(lua_State* lua, tb_int_t f lua_pushstring(lua, top.raw); lua_setfield(lua, -2, "version"); - lua_pushstring(lua, fromidx == 2? "version" : "tag"); + lua_pushstring(lua, fromidx == 2 ? "version" : "tag"); lua_setfield(lua, -2, "source"); // exit the popped semver @@ -78,44 +78,42 @@ static tb_bool_t xm_semver_select_from_versions_tags1(lua_State* lua, tb_int_t f // ok return tb_true; } -static tb_bool_t xm_semver_select_from_versions_tags2(lua_State* lua, tb_int_t fromidx, semver_t* semver, tb_char_t const* version_str, tb_size_t version_len) -{ +static tb_bool_t xm_semver_select_from_versions_tags2( + lua_State *lua, tb_int_t fromidx, semver_t *semver, tb_char_t const *version_str, tb_size_t version_len) { lua_Integer i = 0; luaL_checktype(lua, fromidx, LUA_TTABLE); - for (i = lua_objlen(lua, fromidx); i > 0; --i) - { + for (i = lua_objlen(lua, fromidx); i > 0; --i) { lua_pushinteger(lua, i); lua_gettable(lua, fromidx); - tb_char_t const* source_str = luaL_checkstring(lua, -1); - tb_size_t source_len = tb_strlen(source_str); + tb_char_t const *source_str = luaL_checkstring(lua, -1); + tb_size_t source_len = tb_strlen(source_str); lua_pop(lua, 1); - if (source_len == version_len && tb_strncmp(source_str, version_str, version_len) == 0) - { + if (source_len == version_len && tb_strncmp(source_str, version_str, version_len) == 0) { lua_createtable(lua, 0, 2); lua_pushlstring(lua, source_str, source_len); lua_setfield(lua, -2, "version"); - lua_pushstring(lua, fromidx == 2? "version" : "tag"); + lua_pushstring(lua, fromidx == 2 ? "version" : "tag"); lua_setfield(lua, -2, "source"); return tb_true; } } return tb_false; } -static tb_bool_t xm_semver_select_from_branches(lua_State* lua, tb_int_t fromidx, tb_char_t const* range_str, tb_size_t range_len) -{ +static tb_bool_t xm_semver_select_from_branches(lua_State *lua, + tb_int_t fromidx, + tb_char_t const *range_str, + tb_size_t range_len) { lua_Integer i = 0; luaL_checktype(lua, fromidx, LUA_TTABLE); - for (i = lua_objlen(lua, fromidx); i > 0; --i) - { + for (i = lua_objlen(lua, fromidx); i > 0; --i) { lua_pushinteger(lua, i); lua_gettable(lua, fromidx); - tb_char_t const* source_str = luaL_checkstring(lua, -1); - tb_size_t source_len = tb_strlen(source_str); + tb_char_t const *source_str = luaL_checkstring(lua, -1); + tb_size_t source_len = tb_strlen(source_str); lua_pop(lua, 1); - if (source_len == range_len && tb_memcmp(source_str, range_str, source_len) == 0) - { + if (source_len == range_len && tb_memcmp(source_str, range_str, source_len) == 0) { lua_createtable(lua, 0, 2); lua_pushlstring(lua, source_str, source_len); lua_setfield(lua, -2, "version"); @@ -126,20 +124,21 @@ static tb_bool_t xm_semver_select_from_branches(lua_State* lua, tb_int_t fromidx } return tb_false; } -static tb_bool_t xm_semver_select_latest_from_versions_tags(lua_State* lua, tb_int_t fromidx, semver_t* semver, semvers_t* matches) -{ +static tb_bool_t xm_semver_select_latest_from_versions_tags(lua_State *lua, + tb_int_t fromidx, + semver_t *semver, + semvers_t *matches) { // clear matches semvers_pclear(matches); // push all versions to matches lua_Integer i = 0; luaL_checktype(lua, fromidx, LUA_TTABLE); - for (i = lua_objlen(lua, fromidx); i > 0; --i) - { + for (i = lua_objlen(lua, fromidx); i > 0; --i) { lua_pushinteger(lua, i); lua_gettable(lua, fromidx); - tb_char_t const* source_str = luaL_checkstring(lua, -1); + tb_char_t const *source_str = luaL_checkstring(lua, -1); if (source_str && semver_tryn(semver, source_str, tb_strlen(source_str)) == 0) semvers_ppush(matches, *semver); @@ -158,14 +157,13 @@ static tb_bool_t xm_semver_select_latest_from_versions_tags(lua_State* lua, tb_i lua_pushstring(lua, top.raw); lua_setfield(lua, -2, "version"); - lua_pushstring(lua, fromidx == 2? "version" : "tag"); + lua_pushstring(lua, fromidx == 2 ? "version" : "tag"); lua_setfield(lua, -2, "source"); semver_dtor(&top); return tb_true; } - /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ @@ -174,20 +172,18 @@ static tb_bool_t xm_semver_select_latest_from_versions_tags(lua_State* lua, tb_i * * local versioninfo, errors = semver.select(">=1.5.0 <1.6", {"1.5.0", "1.5.1"}, {"v1.5.0", ..}, {"latest", "dev"}) */ -tb_int_t xm_semver_select(lua_State* lua) -{ +tb_int_t xm_semver_select(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // select version - tb_bool_t ok = tb_false; - tb_bool_t is_range = tb_false; - tb_char_t const* range_str = tb_null; - semver_t semver = {0}; - semvers_t matches = {0}; - semver_range_t range = {0}; - do - { + tb_bool_t ok = tb_false; + tb_bool_t is_range = tb_false; + tb_char_t const *range_str = tb_null; + semver_t semver = { 0 }; + semvers_t matches = { 0 }; + semver_range_t range = { 0 }; + do { // get the version range string range_str = luaL_checkstring(lua, 1); tb_check_break(range_str); @@ -197,59 +193,48 @@ tb_int_t xm_semver_select(lua_State* lua) // parse the version range string is_range = semver_rangen(&range, range_str, range_len) == 0; - if (is_range) - { + if (is_range) { // attempt to select version from the versions list first - if (xm_semver_select_from_versions_tags1(lua, 2, &semver, &range, &matches)) - { + if (xm_semver_select_from_versions_tags1(lua, 2, &semver, &range, &matches)) { ok = tb_true; break; } // attempt to select version from the tags list - if (xm_semver_select_from_versions_tags1(lua, 3, &semver, &range, &matches)) - { + if (xm_semver_select_from_versions_tags1(lua, 3, &semver, &range, &matches)) { ok = tb_true; break; } - } - else - { + } else { // attempt to select version from the versions list first - if (xm_semver_select_from_versions_tags2(lua, 2, &semver, range_str, range_len)) - { + if (xm_semver_select_from_versions_tags2(lua, 2, &semver, range_str, range_len)) { ok = tb_true; break; } // attempt to select version from the tags list - if (xm_semver_select_from_versions_tags2(lua, 3, &semver, range_str, range_len)) - { + if (xm_semver_select_from_versions_tags2(lua, 3, &semver, range_str, range_len)) { ok = tb_true; break; } } // attempt to select version from the branches - if (xm_semver_select_from_branches(lua, 4, range_str, range_len)) - { + if (xm_semver_select_from_branches(lua, 4, range_str, range_len)) { ok = tb_true; break; } // select the latest version from the tags and versions if be latest - if (!tb_strcmp(range_str, "latest")) - { + if (!tb_strcmp(range_str, "latest")) { // attempt to select latest version from the versions list - if (xm_semver_select_latest_from_versions_tags(lua, 2, &semver, &matches)) - { + if (xm_semver_select_latest_from_versions_tags(lua, 2, &semver, &matches)) { ok = tb_true; break; } // attempt to select latest version from the tags list - if (xm_semver_select_latest_from_versions_tags(lua, 3, &semver, &matches)) - { + if (xm_semver_select_latest_from_versions_tags(lua, 3, &semver, &matches)) { ok = tb_true; break; } @@ -264,10 +249,8 @@ tb_int_t xm_semver_select(lua_State* lua) semver_range_dtor(&range); // failed? - if (!ok) - { - if (!is_range) - { + if (!ok) { + if (!is_range) { lua_pushnil(lua); lua_pushfstring(lua, "unable to parse semver range '%s'", range_str); } diff --git a/core/src/xmake/semver/semver.c b/core/src/xmake/semver/semver.c index dcc1b9302..4fe48e5e9 100644 --- a/core/src/xmake/semver/semver.c +++ b/core/src/xmake/semver/semver.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "semver" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "semver" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_void_t lua_pushsemver(lua_State *lua, semver_t const* semver) -{ +tb_void_t lua_pushsemver(lua_State *lua, semver_t const *semver) { // check tb_assert(lua && semver); @@ -60,12 +59,13 @@ tb_void_t lua_pushsemver(lua_State *lua, semver_t const* semver) lua_pushstring(lua, "prerelease"); lua_newtable(lua); - tb_uchar_t i = 0; - semver_id_t const* id = &semver->prerelease; - while (id && id->len) - { - if (id->numeric) lua_pushinteger(lua, id->num); - else lua_pushlstring(lua, id->raw, id->len); + tb_uchar_t i = 0; + semver_id_t const *id = &semver->prerelease; + while (id && id->len) { + if (id->numeric) + lua_pushinteger(lua, id->num); + else + lua_pushlstring(lua, id->raw, id->len); id = id->next; lua_rawseti(lua, -2, ++i); } @@ -76,10 +76,11 @@ tb_void_t lua_pushsemver(lua_State *lua, semver_t const* semver) lua_pushstring(lua, "build"); lua_newtable(lua); id = &semver->build; - while (id && id->len) - { - if (id->numeric) lua_pushinteger(lua, id->num); - else lua_pushlstring(lua, id->raw, id->len); + while (id && id->len) { + if (id->numeric) + lua_pushinteger(lua, id->num); + else + lua_pushlstring(lua, id->raw, id->len); id = id->next; lua_rawseti(lua, -2, ++i); } diff --git a/core/src/xmake/string/convert.c b/core/src/xmake/string/convert.c index 0001b7f9c..65750d95e 100644 --- a/core/src/xmake/string/convert.c +++ b/core/src/xmake/string/convert.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "convert" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "convert" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,54 +35,51 @@ */ // the charset entry type -typedef struct __xm_charset_entry_t -{ +typedef struct __xm_charset_entry_t { // the charset type - tb_size_t type; + tb_size_t type; // the charset name - tb_char_t const* name; - -}xm_charset_entry_t, *xm_charset_entry_ref_t; + tb_char_t const *name; +} xm_charset_entry_t, *xm_charset_entry_ref_t; // the charsets, @note: type & name is sorted -static xm_charset_entry_t g_charsets[] = -{ - {TB_CHARSET_TYPE_ANSI, "ansi" } -, {TB_CHARSET_TYPE_ASCII, "ascii" } -, {TB_CHARSET_TYPE_GB2312, "gb2312" } -, {TB_CHARSET_TYPE_GBK, "gbk" } -, {TB_CHARSET_TYPE_ISO8859, "iso8859" } -, {TB_CHARSET_TYPE_UCS2 | TB_CHARSET_TYPE_NE, "ucs2" } -, {TB_CHARSET_TYPE_UCS4 | TB_CHARSET_TYPE_NE, "ucs4" } -, {TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_NE, "utf16" } -, {TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_BE, "utf16be" } -, {TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_LE, "utf16le" } -, {TB_CHARSET_TYPE_UTF32 | TB_CHARSET_TYPE_NE, "utf32" } -, {TB_CHARSET_TYPE_UTF32 | TB_CHARSET_TYPE_BE, "utf32be" } -, {TB_CHARSET_TYPE_UTF32 | TB_CHARSET_TYPE_LE, "utf32le" } -, {TB_CHARSET_TYPE_UTF8, "utf8" } +static xm_charset_entry_t g_charsets[] = { + { TB_CHARSET_TYPE_ANSI, "ansi" }, + { TB_CHARSET_TYPE_ASCII, "ascii" }, + { TB_CHARSET_TYPE_GB2312, "gb2312" }, + { TB_CHARSET_TYPE_GBK, "gbk" }, + { TB_CHARSET_TYPE_ISO8859, "iso8859" }, + { TB_CHARSET_TYPE_UCS2 | TB_CHARSET_TYPE_NE, "ucs2" }, + { TB_CHARSET_TYPE_UCS4 | TB_CHARSET_TYPE_NE, "ucs4" }, + { TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_NE, "utf16" }, + { TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_BE, "utf16be" }, + { TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_LE, "utf16le" }, + { TB_CHARSET_TYPE_UTF32 | TB_CHARSET_TYPE_NE, "utf32" }, + { TB_CHARSET_TYPE_UTF32 | TB_CHARSET_TYPE_BE, "utf32be" }, + { TB_CHARSET_TYPE_UTF32 | TB_CHARSET_TYPE_LE, "utf32le" }, + { TB_CHARSET_TYPE_UTF8, "utf8" }, }; /* ////////////////////////////////////////////////////////////////////////////////////// * finder */ -static tb_long_t xm_string_charset_comp_by_name(tb_iterator_ref_t iterator, tb_cpointer_t item, tb_cpointer_t name) -{ - return tb_stricmp(((xm_charset_entry_ref_t)item)->name, (tb_char_t const*)name); +static tb_long_t xm_string_charset_comp_by_name(tb_iterator_ref_t iterator, tb_cpointer_t item, tb_cpointer_t name) { + return tb_stricmp(((xm_charset_entry_ref_t)item)->name, (tb_char_t const *)name); } -static xm_charset_entry_ref_t xm_string_charset_find_by_name(tb_char_t const* name) -{ +static xm_charset_entry_ref_t xm_string_charset_find_by_name(tb_char_t const *name) { // make iterator tb_array_iterator_t array_iterator; - tb_iterator_ref_t iterator = tb_array_iterator_init_mem(&array_iterator, g_charsets, tb_arrayn(g_charsets), sizeof(xm_charset_entry_t)); + tb_iterator_ref_t iterator = + tb_array_iterator_init_mem(&array_iterator, g_charsets, tb_arrayn(g_charsets), sizeof(xm_charset_entry_t)); tb_assert_and_check_return_val(iterator, tb_null); // find it by the binary search tb_size_t itor = tb_binary_find_all_if(iterator, xm_string_charset_comp_by_name, name); if (itor != tb_iterator_tail(iterator)) return (xm_charset_entry_ref_t)tb_iterator_item(iterator, itor); - else return tb_null; + else + return tb_null; } /* ////////////////////////////////////////////////////////////////////////////////////// @@ -100,16 +97,15 @@ static xm_charset_entry_ref_t xm_string_charset_find_by_name(tb_char_t const* na * local result = string.convert(str, "utf8", "gb2312") * @endcode */ -tb_int_t xm_string_convert(lua_State* lua) -{ +tb_int_t xm_string_convert(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the string and charset types size_t src_size = 0; - tb_char_t const* src_cstr = luaL_checklstring(lua, 1, &src_size); - tb_char_t const* ftype_cstr = luaL_checkstring(lua, 2); - tb_char_t const* ttype_cstr = luaL_checkstring(lua, 3); + tb_char_t const *src_cstr = luaL_checklstring(lua, 1, &src_size); + tb_char_t const *ftype_cstr = luaL_checkstring(lua, 2); + tb_char_t const *ttype_cstr = luaL_checkstring(lua, 3); tb_check_return_val(src_cstr && ftype_cstr && ttype_cstr, 0); // find charsets @@ -120,18 +116,24 @@ tb_int_t xm_string_convert(lua_State* lua) tb_check_return_val(fcharset && tcharset, 0); // empty string? - if (!src_size) lua_pushstring(lua, ""); - else - { + if (!src_size) + lua_pushstring(lua, ""); + else { // convert string - tb_long_t dst_size = 0; - tb_size_t dst_maxn = (tb_size_t)src_size << 2; - tb_byte_t* dst_data = tb_malloc_bytes(dst_maxn); - if (dst_data && dst_maxn && (dst_size = tb_charset_conv_data(fcharset->type, tcharset->type, (tb_byte_t const*)src_cstr, (tb_size_t)src_size, dst_data, dst_maxn)) >= 0 && dst_size < dst_maxn) - { + tb_long_t dst_size = 0; + tb_size_t dst_maxn = (tb_size_t)src_size << 2; + tb_byte_t *dst_data = tb_malloc_bytes(dst_maxn); + if (dst_data && dst_maxn && + (dst_size = tb_charset_conv_data(fcharset->type, + tcharset->type, + (tb_byte_t const *)src_cstr, + (tb_size_t)src_size, + dst_data, + dst_maxn)) >= 0 && + dst_size < dst_maxn) { lua_pushlstring(lua, (tb_char_t const *)dst_data, dst_size); - } - else lua_pushnil(lua); + } else + lua_pushnil(lua); tb_free(dst_data); } diff --git a/core/src/xmake/string/endswith.c b/core/src/xmake/string/endswith.c index e6bb8b9c4..5905610f6 100644 --- a/core/src/xmake/string/endswith.c +++ b/core/src/xmake/string/endswith.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "endswith" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "endswith" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,16 +33,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_string_endswith(lua_State* lua) -{ +tb_int_t xm_string_endswith(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the string and suffix - size_t string_size = 0; - size_t suffix_size = 0; - tb_char_t const* string = luaL_checklstring(lua, 1, &string_size); - tb_char_t const* suffix = luaL_checklstring(lua, 2, &suffix_size); + size_t string_size = 0; + size_t suffix_size = 0; + tb_char_t const *string = luaL_checklstring(lua, 1, &string_size); + tb_char_t const *suffix = luaL_checklstring(lua, 2, &suffix_size); tb_check_return_val(string && suffix, 0); // string:endswith(suffix)? diff --git a/core/src/xmake/string/lastof.c b/core/src/xmake/string/lastof.c index 8e6f42300..c9df2213d 100644 --- a/core/src/xmake/string/lastof.c +++ b/core/src/xmake/string/lastof.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "string_lastof" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "string_lastof" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,16 +33,14 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t xm_string_lastof_str(lua_State* lua, tb_char_t const* cstr, tb_size_t nstr, tb_char_t const* csubstr, tb_size_t nsubstr) -{ +static tb_void_t xm_string_lastof_str( + lua_State *lua, tb_char_t const *cstr, tb_size_t nstr, tb_char_t const *csubstr, tb_size_t nsubstr) { // find it - tb_char_t const* curr = tb_null; - tb_char_t const* next = cstr; - do - { + tb_char_t const *curr = tb_null; + tb_char_t const *next = cstr; + do { next = tb_strstr(next, csubstr); // faster than tb_strnstr() - if (next) - { + if (next) { curr = next; next += nsubstr; } @@ -50,14 +48,17 @@ static tb_void_t xm_string_lastof_str(lua_State* lua, tb_char_t const* cstr, tb_ } while (!next); // found? - if (curr) lua_pushinteger(lua, curr - cstr + 1); - else lua_pushnil(lua); + if (curr) + lua_pushinteger(lua, curr - cstr + 1); + else + lua_pushnil(lua); } -static tb_void_t xm_string_lastof_chr(lua_State* lua, tb_char_t const* cstr, tb_size_t nstr, tb_char_t ch) -{ - tb_char_t const* pos = tb_strrchr(cstr, ch); // faster than tb_strnrchr() - if (pos) lua_pushinteger(lua, pos - cstr + 1); - else lua_pushnil(lua); +static tb_void_t xm_string_lastof_chr(lua_State *lua, tb_char_t const *cstr, tb_size_t nstr, tb_char_t ch) { + tb_char_t const *pos = tb_strrchr(cstr, ch); // faster than tb_strnrchr() + if (pos) + lua_pushinteger(lua, pos - cstr + 1); + else + lua_pushnil(lua); } /* ////////////////////////////////////////////////////////////////////////////////////// @@ -69,22 +70,23 @@ static tb_void_t xm_string_lastof_chr(lua_State* lua, tb_char_t const* cstr, tb_ * @param str the string * @param substr the substring */ -tb_int_t xm_string_lastof(lua_State* lua) -{ +tb_int_t xm_string_lastof(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get string size_t nstr = 0; - tb_char_t const* cstr = luaL_checklstring(lua, 1, &nstr); + tb_char_t const *cstr = luaL_checklstring(lua, 1, &nstr); // get substring size_t nsubstr = 0; - tb_char_t const* csubstr = luaL_checklstring(lua, 2, &nsubstr); + tb_char_t const *csubstr = luaL_checklstring(lua, 2, &nsubstr); // lastof it lua_newtable(lua); - if (nsubstr == 1) xm_string_lastof_chr(lua, cstr, (tb_size_t)nstr, csubstr[0]); - else xm_string_lastof_str(lua, cstr, (tb_size_t)nstr, csubstr, nsubstr); + if (nsubstr == 1) + xm_string_lastof_chr(lua, cstr, (tb_size_t)nstr, csubstr[0]); + else + xm_string_lastof_str(lua, cstr, (tb_size_t)nstr, csubstr, nsubstr); return 1; } diff --git a/core/src/xmake/string/prefix.h b/core/src/xmake/string/prefix.h index 8f9e53d94..890fc368c 100644 --- a/core/src/xmake/string/prefix.h +++ b/core/src/xmake/string/prefix.h @@ -26,7 +26,4 @@ */ #include "../prefix.h" - #endif - - diff --git a/core/src/xmake/string/split.c b/core/src/xmake/string/split.c index c035a5fab..be2904f99 100644 --- a/core/src/xmake/string/split.c +++ b/core/src/xmake/string/split.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "string_split" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "string_split" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,15 +33,18 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t xm_string_split_str(lua_State* lua, tb_char_t const* cstr, tb_size_t nstr, tb_char_t const* cdls, tb_size_t ndls, tb_bool_t strict, tb_int_t limit) -{ - tb_int_t num = 0; - tb_char_t const* end = cstr + nstr; - tb_char_t const* pos = tb_strstr(cstr, cdls); // faster than tb_strnstr() - while (pos && pos < end) - { - if (pos > cstr || strict) - { +static tb_void_t xm_string_split_str(lua_State *lua, + tb_char_t const *cstr, + tb_size_t nstr, + tb_char_t const *cdls, + tb_size_t ndls, + tb_bool_t strict, + tb_int_t limit) { + tb_int_t num = 0; + tb_char_t const *end = cstr + nstr; + tb_char_t const *pos = tb_strstr(cstr, cdls); // faster than tb_strnstr() + while (pos && pos < end) { + if (pos > cstr || strict) { if (limit > 0 && num + 1 >= limit) break; @@ -50,28 +53,23 @@ static tb_void_t xm_string_split_str(lua_State* lua, tb_char_t const* cstr, tb_s } cstr = pos + ndls; - pos = tb_strstr(cstr, cdls); + pos = tb_strstr(cstr, cdls); } - if (cstr < end) - { + if (cstr < end) { lua_pushlstring(lua, cstr, end - cstr); lua_rawseti(lua, -2, ++num); - } - else if (strict && (limit < 0 || num < limit) && cstr == end) - { + } else if (strict && (limit < 0 || num < limit) && cstr == end) { lua_pushliteral(lua, ""); lua_rawseti(lua, -2, ++num); } } -static tb_void_t xm_string_split_chr(lua_State* lua, tb_char_t const* cstr, tb_size_t nstr, tb_char_t ch, tb_bool_t strict, tb_int_t limit) -{ - tb_int_t num = 0; - tb_char_t const* end = cstr + nstr; - tb_char_t const* pos = tb_strchr(cstr, ch); // faster than tb_strnchr() - while (pos && pos < end) - { - if (pos > cstr || strict) - { +static tb_void_t xm_string_split_chr( + lua_State *lua, tb_char_t const *cstr, tb_size_t nstr, tb_char_t ch, tb_bool_t strict, tb_int_t limit) { + tb_int_t num = 0; + tb_char_t const *end = cstr + nstr; + tb_char_t const *pos = tb_strchr(cstr, ch); // faster than tb_strnchr() + while (pos && pos < end) { + if (pos > cstr || strict) { if (limit > 0 && num + 1 >= limit) break; @@ -80,15 +78,12 @@ static tb_void_t xm_string_split_chr(lua_State* lua, tb_char_t const* cstr, tb_s } cstr = pos + 1; - pos = tb_strchr(cstr, ch); + pos = tb_strchr(cstr, ch); } - if (cstr < end) - { + if (cstr < end) { lua_pushlstring(lua, cstr, end - cstr); lua_rawseti(lua, -2, ++num); - } - else if (strict && (limit < 0 || num < limit) && cstr == end) - { + } else if (strict && (limit < 0 || num < limit) && cstr == end) { lua_pushliteral(lua, ""); lua_rawseti(lua, -2, ++num); } @@ -105,28 +100,29 @@ static tb_void_t xm_string_split_chr(lua_State* lua, tb_char_t const* cstr, tb_s * @param strict is strict? * @param limit the limit count */ -tb_int_t xm_string_split(lua_State* lua) -{ +tb_int_t xm_string_split(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get string size_t nstr = 0; - tb_char_t const* cstr = luaL_checklstring(lua, 1, &nstr); + tb_char_t const *cstr = luaL_checklstring(lua, 1, &nstr); // get delimiter size_t ndls = 0; - tb_char_t const* cdls = luaL_checklstring(lua, 2, &ndls); + tb_char_t const *cdls = luaL_checklstring(lua, 2, &ndls); // is strict? - tb_bool_t const strict = (tb_bool_t)lua_toboolean(lua, 3); + tb_bool_t const strict = (tb_bool_t)lua_toboolean(lua, 3); // get limit count - tb_int_t const limit = (tb_int_t)luaL_optinteger(lua, 4, -1); + tb_int_t const limit = (tb_int_t)luaL_optinteger(lua, 4, -1); // split it lua_newtable(lua); - if (ndls == 1) xm_string_split_chr(lua, cstr, (tb_size_t)nstr, cdls[0], strict, limit); - else xm_string_split_str(lua, cstr, (tb_size_t)nstr, cdls, ndls, strict, limit); + if (ndls == 1) + xm_string_split_chr(lua, cstr, (tb_size_t)nstr, cdls[0], strict, limit); + else + xm_string_split_str(lua, cstr, (tb_size_t)nstr, cdls, ndls, strict, limit); return 1; } diff --git a/core/src/xmake/string/startswith.c b/core/src/xmake/string/startswith.c index d904de3cb..c7fe9dcca 100644 --- a/core/src/xmake/string/startswith.c +++ b/core/src/xmake/string/startswith.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "startswith" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "startswith" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,15 +33,14 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_string_startswith(lua_State* lua) -{ +tb_int_t xm_string_startswith(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the string and prefix - size_t prefix_size = 0; - tb_char_t const* string = luaL_checkstring(lua, 1); - tb_char_t const* prefix = luaL_checklstring(lua, 2, &prefix_size); + size_t prefix_size = 0; + tb_char_t const *string = luaL_checkstring(lua, 1); + tb_char_t const *prefix = luaL_checklstring(lua, 2, &prefix_size); tb_check_return_val(string && prefix, 0); // string:startswith(prefix)? diff --git a/core/src/xmake/string/trim.c b/core/src/xmake/string/trim.c index 42a4b846c..d22f86666 100644 --- a/core/src/xmake/string/trim.c +++ b/core/src/xmake/string/trim.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "string_trim" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "string_trim" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,13 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t xm_string_trim_space(tb_char_t const** psstr, tb_char_t const** pestr, tb_int_t mode) -{ +static tb_void_t xm_string_trim_space(tb_char_t const **psstr, tb_char_t const **pestr, tb_int_t mode) { // check tb_assert(psstr && pestr && *psstr && *pestr); - tb_char_t const* p = *psstr; - tb_char_t const* e = *pestr; + tb_char_t const *p = *psstr; + tb_char_t const *e = *pestr; // trim left? if (mode <= 0) @@ -47,8 +46,7 @@ static tb_void_t xm_string_trim_space(tb_char_t const** psstr, tb_char_t const** p++; // trim right - if (mode >= 0) - { + if (mode >= 0) { e--; while (e >= p && tb_isspace(*e)) e--; @@ -60,23 +58,27 @@ static tb_void_t xm_string_trim_space(tb_char_t const** psstr, tb_char_t const** *pestr = e; } -static tb_char_t const* xm_string_ltrim(tb_char_t const* sstr, tb_char_t const* estr, tb_char_t const* ctrim, size_t ntrim) -{ +static tb_char_t const *xm_string_ltrim(tb_char_t const *sstr, + tb_char_t const *estr, + tb_char_t const *ctrim, + size_t ntrim) { // check tb_assert(sstr && estr && ctrim); - tb_char_t const* p = sstr; + tb_char_t const *p = sstr; while (p < estr && tb_strnchr(ctrim, ntrim, *p)) p++; return p; } -static tb_char_t const* xm_string_rtrim(tb_char_t const* sstr, tb_char_t const* estr, tb_char_t const* ctrim, size_t ntrim) -{ +static tb_char_t const *xm_string_rtrim(tb_char_t const *sstr, + tb_char_t const *estr, + tb_char_t const *ctrim, + size_t ntrim) { // check tb_assert(sstr && estr && ctrim); - tb_char_t const* p = estr - 1; + tb_char_t const *p = estr - 1; while (p >= sstr && tb_strnchr(ctrim, ntrim, *p)) p--; return p + 1; @@ -97,30 +99,29 @@ static tb_char_t const* xm_string_rtrim(tb_char_t const* sstr, tb_char_t const* * local result = string.trim(str, "(", -1) * @endcode */ -tb_int_t xm_string_trim(lua_State* lua) -{ +tb_int_t xm_string_trim(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); size_t lstr, ltrim; - tb_char_t const* sstr = luaL_checklstring(lua, 1, &lstr); - tb_char_t const* estr = sstr + lstr; - tb_char_t const* trimchars = luaL_optlstring(lua, 2, "", <rim); + tb_char_t const *sstr = luaL_checklstring(lua, 1, &lstr); + tb_char_t const *estr = sstr + lstr; + tb_char_t const *trimchars = luaL_optlstring(lua, 2, "", <rim); tb_int_t const trimtype = (tb_int_t)luaL_optinteger(lua, 3, 0); - do - { + do { tb_assert_and_check_break(sstr && trimchars); tb_check_break(lstr != 0); - tb_char_t const* const rsstr = sstr; - tb_char_t const* const restr = estr; + tb_char_t const *const rsstr = sstr; + tb_char_t const *const restr = estr; if (ltrim == 0) xm_string_trim_space(&sstr, &estr, trimtype); - else - { + else { // trim chars - if (trimtype <= 0) sstr = xm_string_ltrim(sstr, estr, trimchars, ltrim); - if (trimtype >= 0) estr = xm_string_rtrim(sstr, estr, trimchars, ltrim); + if (trimtype <= 0) + sstr = xm_string_ltrim(sstr, estr, trimchars, ltrim); + if (trimtype >= 0) + estr = xm_string_rtrim(sstr, estr, trimchars, ltrim); } // no trimed chars diff --git a/core/src/xmake/thread/event_exit.c b/core/src/xmake/thread/event_exit.c index 54e977068..501a72a8f 100644 --- a/core/src/xmake/thread/event_exit.c +++ b/core/src/xmake/thread/event_exit.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_event" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_event" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,14 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_event_exit(lua_State* lua) -{ +tb_int_t xm_thread_event_exit(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_event_t* thread_event = xm_thread_event_get(lua, 1); + xm_thread_event_t *thread_event = xm_thread_event_get(lua, 1); tb_assert_and_check_return_val(thread_event && thread_event->handle, 0); - if (tb_atomic_fetch_and_sub(&thread_event->refn, 1) == 1) - { - if (thread_event->handle) - { + if (tb_atomic_fetch_and_sub(&thread_event->refn, 1) == 1) { + if (thread_event->handle) { tb_event_exit(thread_event->handle); thread_event->handle = tb_null; } @@ -52,4 +49,3 @@ tb_int_t xm_thread_event_exit(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/thread/event_incref.c b/core/src/xmake/thread/event_incref.c index ff8b658d9..28c631056 100644 --- a/core/src/xmake/thread/event_incref.c +++ b/core/src/xmake/thread/event_incref.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_event" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_event" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_event_incref(lua_State* lua) -{ +tb_int_t xm_thread_event_incref(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_event_t* thread_event = xm_thread_event_get(lua, 1); + xm_thread_event_t *thread_event = xm_thread_event_get(lua, 1); tb_assert_and_check_return_val(thread_event && thread_event->handle, 0); lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_event->refn, 1) >= 1); return 1; } - diff --git a/core/src/xmake/thread/event_init.c b/core/src/xmake/thread/event_init.c index 942537718..d661939b0 100644 --- a/core/src/xmake/thread/event_init.c +++ b/core/src/xmake/thread/event_init.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_event" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_event" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_event_init(lua_State* lua) -{ +tb_int_t xm_thread_event_init(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - tb_bool_t ok = tb_false; - xm_thread_event_t* thread_event = tb_null; - do - { + tb_bool_t ok = tb_false; + xm_thread_event_t *thread_event = tb_null; + do { thread_event = tb_malloc0_type(xm_thread_event_t); tb_assert_and_check_break(thread_event); - thread_event->refn = 1; + thread_event->refn = 1; thread_event->handle = tb_event_init(); tb_assert_and_check_break(thread_event->handle); @@ -53,12 +51,9 @@ tb_int_t xm_thread_event_init(lua_State* lua) } while (0); - if (!ok) - { - if (thread_event) - { - if (thread_event->handle) - { + if (!ok) { + if (thread_event) { + if (thread_event->handle) { tb_event_exit(thread_event->handle); thread_event->handle = tb_null; } diff --git a/core/src/xmake/thread/event_post.c b/core/src/xmake/thread/event_post.c index 0b8e5dabd..0762f6af1 100644 --- a/core/src/xmake/thread/event_post.c +++ b/core/src/xmake/thread/event_post.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_event" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_event" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_event_post(lua_State* lua) -{ +tb_int_t xm_thread_event_post(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_event_t* thread_event = xm_thread_event_get(lua, 1); + xm_thread_event_t *thread_event = xm_thread_event_get(lua, 1); tb_assert_and_check_return_val(thread_event && thread_event->handle, 0); lua_pushboolean(lua, tb_event_post(thread_event->handle)); return 1; } - diff --git a/core/src/xmake/thread/event_wait.c b/core/src/xmake/thread/event_wait.c index d6d628311..73e476427 100644 --- a/core/src/xmake/thread/event_wait.c +++ b/core/src/xmake/thread/event_wait.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_event" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_event" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,15 +33,13 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_event_wait(lua_State* lua) -{ +tb_int_t xm_thread_event_wait(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_event_t* thread_event = xm_thread_event_get(lua, 1); + xm_thread_event_t *thread_event = xm_thread_event_get(lua, 1); tb_assert_and_check_return_val(thread_event && thread_event->handle, 0); tb_long_t timeout = (tb_long_t)luaL_checknumber(lua, 2); lua_pushinteger(lua, tb_event_wait(thread_event->handle, timeout)); return 1; } - diff --git a/core/src/xmake/thread/mutex_exit.c b/core/src/xmake/thread/mutex_exit.c index 39d69ab8a..f415de339 100644 --- a/core/src/xmake/thread/mutex_exit.c +++ b/core/src/xmake/thread/mutex_exit.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_mutex" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_mutex" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,14 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_mutex_exit(lua_State* lua) -{ +tb_int_t xm_thread_mutex_exit(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1); + xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1); tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0); - if (tb_atomic_fetch_and_sub(&thread_mutex->refn, 1) == 1) - { - if (thread_mutex->handle) - { + if (tb_atomic_fetch_and_sub(&thread_mutex->refn, 1) == 1) { + if (thread_mutex->handle) { tb_mutex_exit(thread_mutex->handle); thread_mutex->handle = tb_null; } @@ -52,4 +49,3 @@ tb_int_t xm_thread_mutex_exit(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/thread/mutex_incref.c b/core/src/xmake/thread/mutex_incref.c index 34a234757..3706ec276 100644 --- a/core/src/xmake/thread/mutex_incref.c +++ b/core/src/xmake/thread/mutex_incref.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_mutex" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_mutex" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_mutex_incref(lua_State* lua) -{ +tb_int_t xm_thread_mutex_incref(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1); + xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1); tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0); lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_mutex->refn, 1) >= 1); return 1; } - diff --git a/core/src/xmake/thread/mutex_init.c b/core/src/xmake/thread/mutex_init.c index ff69e82ad..bca78a134 100644 --- a/core/src/xmake/thread/mutex_init.c +++ b/core/src/xmake/thread/mutex_init.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_mutex" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_mutex" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_mutex_init(lua_State* lua) -{ +tb_int_t xm_thread_mutex_init(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - tb_bool_t ok = tb_false; - xm_thread_mutex_t* thread_mutex = tb_null; - do - { + tb_bool_t ok = tb_false; + xm_thread_mutex_t *thread_mutex = tb_null; + do { thread_mutex = tb_malloc0_type(xm_thread_mutex_t); tb_assert_and_check_break(thread_mutex); - thread_mutex->refn = 1; + thread_mutex->refn = 1; thread_mutex->handle = tb_mutex_init(); tb_assert_and_check_break(thread_mutex->handle); @@ -53,12 +51,9 @@ tb_int_t xm_thread_mutex_init(lua_State* lua) } while (0); - if (!ok) - { - if (thread_mutex) - { - if (thread_mutex->handle) - { + if (!ok) { + if (thread_mutex) { + if (thread_mutex->handle) { tb_mutex_exit(thread_mutex->handle); thread_mutex->handle = tb_null; } diff --git a/core/src/xmake/thread/mutex_lock.c b/core/src/xmake/thread/mutex_lock.c index 380301da1..f5e9154ae 100644 --- a/core/src/xmake/thread/mutex_lock.c +++ b/core/src/xmake/thread/mutex_lock.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_mutex" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_mutex" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_mutex_lock(lua_State* lua) -{ +tb_int_t xm_thread_mutex_lock(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1); + xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1); tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0); lua_pushboolean(lua, tb_mutex_enter(thread_mutex->handle)); return 1; } - diff --git a/core/src/xmake/thread/mutex_trylock.c b/core/src/xmake/thread/mutex_trylock.c index 7b83f3a90..fdc90e883 100644 --- a/core/src/xmake/thread/mutex_trylock.c +++ b/core/src/xmake/thread/mutex_trylock.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_mutex" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_mutex" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_mutex_trylock(lua_State* lua) -{ +tb_int_t xm_thread_mutex_trylock(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1); + xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1); tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0); lua_pushboolean(lua, tb_mutex_enter_try(thread_mutex->handle)); return 1; } - diff --git a/core/src/xmake/thread/mutex_unlock.c b/core/src/xmake/thread/mutex_unlock.c index beb0c9e0a..93503e197 100644 --- a/core/src/xmake/thread/mutex_unlock.c +++ b/core/src/xmake/thread/mutex_unlock.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_mutex" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_mutex" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_mutex_unlock(lua_State* lua) -{ +tb_int_t xm_thread_mutex_unlock(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1); + xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1); tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0); lua_pushboolean(lua, tb_mutex_leave(thread_mutex->handle)); return 1; } - diff --git a/core/src/xmake/thread/prefix.h b/core/src/xmake/thread/prefix.h index 2b841e6a7..9b038a8cb 100644 --- a/core/src/xmake/thread/prefix.h +++ b/core/src/xmake/thread/prefix.h @@ -31,126 +31,112 @@ */ // the thread type -typedef struct __xm_thread_t -{ +typedef struct __xm_thread_t { tb_thread_ref_t handle; tb_string_t callback; tb_string_t callinfo; - -}xm_thread_t; +} xm_thread_t; // the thread value kind -typedef enum __xm_thread_value_kind_e -{ +typedef enum __xm_thread_value_kind_e { XM_THREAD_VALUE_NIL = 0, XM_THREAD_VALUE_BOOL = 1, XM_THREAD_VALUE_INT = 2, XM_THREAD_VALUE_NUM = 3, XM_THREAD_VALUE_STR = 4 - -}xm_thread_value_kind_e; +} xm_thread_value_kind_e; // the thread value type -typedef struct __xm_thread_value_t -{ - tb_uint32_t kind : 3; - tb_uint32_t size : 29; - union - { - tb_char_t* string; +typedef struct __xm_thread_value_t { + tb_uint32_t kind : 3; + tb_uint32_t size : 29; + union { + tb_char_t *string; tb_bool_t boolean; lua_Integer integer; lua_Number number; } u; - -}xm_thread_value_t; +} xm_thread_value_t; // the thread event type -typedef struct __xm_thread_event_t -{ - tb_event_ref_t handle; - tb_atomic_t refn; - -}xm_thread_event_t; +typedef struct __xm_thread_event_t { + tb_event_ref_t handle; + tb_atomic_t refn; +} xm_thread_event_t; // the thread mutex type -typedef struct __xm_thread_mutex_t -{ - tb_mutex_ref_t handle; - tb_atomic_t refn; - -}xm_thread_mutex_t; +typedef struct __xm_thread_mutex_t { + tb_mutex_ref_t handle; + tb_atomic_t refn; +} xm_thread_mutex_t; // the thread semaphore type -typedef struct __xm_thread_semaphore_t -{ +typedef struct __xm_thread_semaphore_t { tb_semaphore_ref_t handle; tb_atomic_t refn; - -}xm_thread_semaphore_t; +} xm_thread_semaphore_t; // the thread queue type -typedef struct __xm_thread_queue_t -{ - tb_queue_ref_t handle; - tb_atomic_t refn; - -}xm_thread_queue_t; +typedef struct __xm_thread_queue_t { + tb_queue_ref_t handle; + tb_atomic_t refn; +} xm_thread_queue_t; // the thread sharedata type -typedef struct __xm_thread_sharedata_t -{ +typedef struct __xm_thread_sharedata_t { xm_thread_value_t value; tb_buffer_t buffer; tb_atomic_t refn; - -}xm_thread_sharedata_t; +} xm_thread_sharedata_t; // get the thread event from arguments -static __tb_inline__ xm_thread_event_t* xm_thread_event_get(lua_State* lua, tb_int_t index) -{ - xm_thread_event_t* thread_event = tb_null; - if (xm_lua_isinteger(lua, index)) thread_event = (xm_thread_event_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) thread_event = (xm_thread_event_t*)xm_lua_topointer(lua, index); +static __tb_inline__ xm_thread_event_t *xm_thread_event_get(lua_State *lua, tb_int_t index) { + xm_thread_event_t *thread_event = tb_null; + if (xm_lua_isinteger(lua, index)) + thread_event = (xm_thread_event_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); + else if (xm_lua_ispointer(lua, index)) + thread_event = (xm_thread_event_t *)xm_lua_topointer(lua, index); return thread_event; } // get the thread mutex from arguments -static __tb_inline__ xm_thread_mutex_t* xm_thread_mutex_get(lua_State* lua, tb_int_t index) -{ - xm_thread_mutex_t* thread_mutex = tb_null; - if (xm_lua_isinteger(lua, index)) thread_mutex = (xm_thread_mutex_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) thread_mutex = (xm_thread_mutex_t*)xm_lua_topointer(lua, index); +static __tb_inline__ xm_thread_mutex_t *xm_thread_mutex_get(lua_State *lua, tb_int_t index) { + xm_thread_mutex_t *thread_mutex = tb_null; + if (xm_lua_isinteger(lua, index)) + thread_mutex = (xm_thread_mutex_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); + else if (xm_lua_ispointer(lua, index)) + thread_mutex = (xm_thread_mutex_t *)xm_lua_topointer(lua, index); return thread_mutex; } // get the thread semaphore from arguments -static __tb_inline__ xm_thread_semaphore_t* xm_thread_semaphore_get(lua_State* lua, tb_int_t index) -{ - xm_thread_semaphore_t* thread_semaphore = tb_null; - if (xm_lua_isinteger(lua, index)) thread_semaphore = (xm_thread_semaphore_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) thread_semaphore = (xm_thread_semaphore_t*)xm_lua_topointer(lua, index); +static __tb_inline__ xm_thread_semaphore_t *xm_thread_semaphore_get(lua_State *lua, tb_int_t index) { + xm_thread_semaphore_t *thread_semaphore = tb_null; + if (xm_lua_isinteger(lua, index)) + thread_semaphore = (xm_thread_semaphore_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); + else if (xm_lua_ispointer(lua, index)) + thread_semaphore = (xm_thread_semaphore_t *)xm_lua_topointer(lua, index); return thread_semaphore; } // get the thread queue from arguments -static __tb_inline__ xm_thread_queue_t* xm_thread_queue_get(lua_State* lua, tb_int_t index) -{ - xm_thread_queue_t* thread_queue = tb_null; - if (xm_lua_isinteger(lua, index)) thread_queue = (xm_thread_queue_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) thread_queue = (xm_thread_queue_t*)xm_lua_topointer(lua, index); +static __tb_inline__ xm_thread_queue_t *xm_thread_queue_get(lua_State *lua, tb_int_t index) { + xm_thread_queue_t *thread_queue = tb_null; + if (xm_lua_isinteger(lua, index)) + thread_queue = (xm_thread_queue_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); + else if (xm_lua_ispointer(lua, index)) + thread_queue = (xm_thread_queue_t *)xm_lua_topointer(lua, index); return thread_queue; } // get the thread sharedata from arguments -static __tb_inline__ xm_thread_sharedata_t* xm_thread_sharedata_get(lua_State* lua, tb_int_t index) -{ - xm_thread_sharedata_t* thread_sharedata = tb_null; - if (xm_lua_isinteger(lua, index)) thread_sharedata = (xm_thread_sharedata_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) thread_sharedata = (xm_thread_sharedata_t*)xm_lua_topointer(lua, index); +static __tb_inline__ xm_thread_sharedata_t *xm_thread_sharedata_get(lua_State *lua, tb_int_t index) { + xm_thread_sharedata_t *thread_sharedata = tb_null; + if (xm_lua_isinteger(lua, index)) + thread_sharedata = (xm_thread_sharedata_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); + else if (xm_lua_ispointer(lua, index)) + thread_sharedata = (xm_thread_sharedata_t *)xm_lua_topointer(lua, index); return thread_sharedata; } #endif - - diff --git a/core/src/xmake/thread/queue_clear.c b/core/src/xmake/thread/queue_clear.c index 4888babe2..021475a14 100644 --- a/core/src/xmake/thread/queue_clear.c +++ b/core/src/xmake/thread/queue_clear.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_queue" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_queue" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,15 +33,13 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_queue_clear(lua_State* lua) -{ +tb_int_t xm_thread_queue_clear(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1); + xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1); tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0); tb_queue_clear(thread_queue->handle); lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/thread/queue_exit.c b/core/src/xmake/thread/queue_exit.c index 8178ea22f..c30c6b97c 100644 --- a/core/src/xmake/thread/queue_exit.c +++ b/core/src/xmake/thread/queue_exit.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_queue" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_queue" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,14 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_queue_exit(lua_State* lua) -{ +tb_int_t xm_thread_queue_exit(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1); + xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1); tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0); - if (tb_atomic_fetch_and_sub(&thread_queue->refn, 1) == 1) - { - if (thread_queue->handle) - { + if (tb_atomic_fetch_and_sub(&thread_queue->refn, 1) == 1) { + if (thread_queue->handle) { tb_queue_exit(thread_queue->handle); thread_queue->handle = tb_null; } @@ -52,4 +49,3 @@ tb_int_t xm_thread_queue_exit(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/thread/queue_incref.c b/core/src/xmake/thread/queue_incref.c index 4f06807c4..9dd88b013 100644 --- a/core/src/xmake/thread/queue_incref.c +++ b/core/src/xmake/thread/queue_incref.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_queue" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_queue" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_queue_incref(lua_State* lua) -{ +tb_int_t xm_thread_queue_incref(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1); + xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1); tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0); lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_queue->refn, 1) >= 1); return 1; } - diff --git a/core/src/xmake/thread/queue_init.c b/core/src/xmake/thread/queue_init.c index 0c8af884d..20c08ce50 100644 --- a/core/src/xmake/thread/queue_init.c +++ b/core/src/xmake/thread/queue_init.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_queue" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_queue" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t xm_thread_value_free(tb_element_ref_t element, tb_pointer_t buff) -{ - xm_thread_value_t* item = (xm_thread_value_t*)buff; - if (item) - { - if (item->kind == XM_THREAD_VALUE_STR) - { - if (item->u.string) tb_free((tb_pointer_t)item->u.string); +static tb_void_t xm_thread_value_free(tb_element_ref_t element, tb_pointer_t buff) { + xm_thread_value_t *item = (xm_thread_value_t *)buff; + if (item) { + if (item->kind == XM_THREAD_VALUE_STR) { + if (item->u.string) + tb_free((tb_pointer_t)item->u.string); item->u.string = tb_null; } item->size = 0; @@ -50,19 +48,18 @@ static tb_void_t xm_thread_value_free(tb_element_ref_t element, tb_pointer_t buf /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_queue_init(lua_State* lua) -{ +tb_int_t xm_thread_queue_init(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - tb_bool_t ok = tb_false; - xm_thread_queue_t* thread_queue = tb_null; - do - { + tb_bool_t ok = tb_false; + xm_thread_queue_t *thread_queue = tb_null; + do { thread_queue = tb_malloc0_type(xm_thread_queue_t); tb_assert_and_check_break(thread_queue); - thread_queue->refn = 1; - thread_queue->handle = tb_queue_init(0, tb_element_mem(sizeof(xm_thread_value_t), xm_thread_value_free, tb_null)); + thread_queue->refn = 1; + thread_queue->handle = tb_queue_init(0, + tb_element_mem(sizeof(xm_thread_value_t), xm_thread_value_free, tb_null)); tb_assert_and_check_break(thread_queue->handle); xm_lua_pushpointer(lua, (tb_pointer_t)thread_queue); @@ -70,12 +67,9 @@ tb_int_t xm_thread_queue_init(lua_State* lua) } while (0); - if (!ok) - { - if (thread_queue) - { - if (thread_queue->handle) - { + if (!ok) { + if (thread_queue) { + if (thread_queue->handle) { tb_queue_exit(thread_queue->handle); thread_queue->handle = tb_null; } diff --git a/core/src/xmake/thread/queue_pop.c b/core/src/xmake/thread/queue_pop.c index c666a85dd..ef5f761ec 100644 --- a/core/src/xmake/thread/queue_pop.c +++ b/core/src/xmake/thread/queue_pop.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_queue" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_queue" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,30 +33,28 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_queue_pop(lua_State* lua) -{ +tb_int_t xm_thread_queue_pop(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1); + xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1); tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0); - if (tb_queue_null(thread_queue->handle)) - { + if (tb_queue_null(thread_queue->handle)) { lua_pushnil(lua); lua_pushliteral(lua, "the thread queue is empty"); return 2; } - xm_thread_value_t* item = (xm_thread_value_t*)tb_queue_get(thread_queue->handle); + xm_thread_value_t *item = (xm_thread_value_t *)tb_queue_get(thread_queue->handle); tb_assert_and_check_return_val(item, 0); tb_bool_t ok = tb_false; - switch (item->kind) - { + switch (item->kind) { case XM_THREAD_VALUE_STR: if (item->size) lua_pushlstring(lua, item->u.string, item->size); - else lua_pushliteral(lua, ""); + else + lua_pushliteral(lua, ""); ok = tb_true; break; case XM_THREAD_VALUE_INT: @@ -79,8 +77,7 @@ tb_int_t xm_thread_queue_pop(lua_State* lua) break; } - if (!ok) - { + if (!ok) { lua_pushnil(lua); lua_pushliteral(lua, "invalid thread queue item"); return 2; @@ -89,4 +86,3 @@ tb_int_t xm_thread_queue_pop(lua_State* lua) tb_queue_pop(thread_queue->handle); return 1; } - diff --git a/core/src/xmake/thread/queue_push.c b/core/src/xmake/thread/queue_push.c index 8125f2b9a..058ac8f81 100644 --- a/core/src/xmake/thread/queue_push.c +++ b/core/src/xmake/thread/queue_push.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_queue" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_queue" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,57 +33,43 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_queue_push(lua_State* lua) -{ +tb_int_t xm_thread_queue_push(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1); + xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1); tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0); - if (tb_queue_full(thread_queue->handle)) - { + if (tb_queue_full(thread_queue->handle)) { lua_pushboolean(lua, tb_false); lua_pushliteral(lua, "the thread queue is full"); return 2; } xm_thread_value_t item; - if (lua_isstring(lua, 2)) - { - size_t data_size = 0; - tb_char_t const* data = luaL_checklstring(lua, 2, &data_size); + if (lua_isstring(lua, 2)) { + size_t data_size = 0; + tb_char_t const *data = luaL_checklstring(lua, 2, &data_size); tb_assert_and_check_return_val(data, 0); item.kind = (tb_uint32_t)XM_THREAD_VALUE_STR; item.size = (tb_uint32_t)data_size; - if (data_size) - { + if (data_size) { item.u.string = tb_malloc_cstr(data_size); tb_assert_and_check_return_val(item.u.string, 0); tb_memcpy(item.u.string, data, data_size); } - } - else if (xm_lua_isinteger(lua, 2)) - { - item.kind = (tb_uint32_t)XM_THREAD_VALUE_INT; + } else if (xm_lua_isinteger(lua, 2)) { + item.kind = (tb_uint32_t)XM_THREAD_VALUE_INT; item.u.integer = lua_tointeger(lua, 2); - } - else if (lua_isnumber(lua, 2)) - { - item.kind = (tb_uint32_t)XM_THREAD_VALUE_NUM; + } else if (lua_isnumber(lua, 2)) { + item.kind = (tb_uint32_t)XM_THREAD_VALUE_NUM; item.u.number = lua_tonumber(lua, 2); - } - else if (lua_isboolean(lua, 2)) - { - item.kind = (tb_uint32_t)XM_THREAD_VALUE_BOOL; + } else if (lua_isboolean(lua, 2)) { + item.kind = (tb_uint32_t)XM_THREAD_VALUE_BOOL; item.u.boolean = lua_toboolean(lua, 2); - } - else if (lua_isnil(lua, 2)) - { + } else if (lua_isnil(lua, 2)) { item.kind = (tb_uint32_t)XM_THREAD_VALUE_NIL; - } - else - { + } else { lua_pushboolean(lua, tb_false); lua_pushliteral(lua, "unsupported thread queue item"); return 2; @@ -93,4 +79,3 @@ tb_int_t xm_thread_queue_push(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/thread/queue_size.c b/core/src/xmake/thread/queue_size.c index 559a1dceb..68a9b5a91 100644 --- a/core/src/xmake/thread/queue_size.c +++ b/core/src/xmake/thread/queue_size.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_queue" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_queue" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_queue_size(lua_State* lua) -{ +tb_int_t xm_thread_queue_size(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1); + xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1); tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0); lua_pushinteger(lua, (tb_int_t)tb_queue_size(thread_queue->handle)); return 1; } - diff --git a/core/src/xmake/thread/semaphore_exit.c b/core/src/xmake/thread/semaphore_exit.c index cffffa249..bbc426917 100644 --- a/core/src/xmake/thread/semaphore_exit.c +++ b/core/src/xmake/thread/semaphore_exit.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_semaphore" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_semaphore" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,17 +33,14 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_semaphore_exit(lua_State* lua) -{ +tb_int_t xm_thread_semaphore_exit(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_semaphore_t* thread_semaphore = xm_thread_semaphore_get(lua, 1); + xm_thread_semaphore_t *thread_semaphore = xm_thread_semaphore_get(lua, 1); tb_assert_and_check_return_val(thread_semaphore && thread_semaphore->handle, 0); - if (tb_atomic_fetch_and_sub(&thread_semaphore->refn, 1) == 1) - { - if (thread_semaphore->handle) - { + if (tb_atomic_fetch_and_sub(&thread_semaphore->refn, 1) == 1) { + if (thread_semaphore->handle) { tb_semaphore_exit(thread_semaphore->handle); thread_semaphore->handle = tb_null; } @@ -52,4 +49,3 @@ tb_int_t xm_thread_semaphore_exit(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/thread/semaphore_incref.c b/core/src/xmake/thread/semaphore_incref.c index 84c2118d3..129a2177d 100644 --- a/core/src/xmake/thread/semaphore_incref.c +++ b/core/src/xmake/thread/semaphore_incref.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_semaphore" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_semaphore" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_semaphore_incref(lua_State* lua) -{ +tb_int_t xm_thread_semaphore_incref(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_semaphore_t* thread_semaphore = xm_thread_semaphore_get(lua, 1); + xm_thread_semaphore_t *thread_semaphore = xm_thread_semaphore_get(lua, 1); tb_assert_and_check_return_val(thread_semaphore && thread_semaphore->handle, 0); lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_semaphore->refn, 1) >= 1); return 1; } - diff --git a/core/src/xmake/thread/semaphore_init.c b/core/src/xmake/thread/semaphore_init.c index 976b48de9..a4c7a80fe 100644 --- a/core/src/xmake/thread/semaphore_init.c +++ b/core/src/xmake/thread/semaphore_init.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_semaphore" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_semaphore" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,20 +33,18 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_semaphore_init(lua_State* lua) -{ +tb_int_t xm_thread_semaphore_init(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - tb_bool_t ok = tb_false; - xm_thread_semaphore_t* thread_semaphore = tb_null; - do - { + tb_bool_t ok = tb_false; + xm_thread_semaphore_t *thread_semaphore = tb_null; + do { tb_long_t value = (tb_long_t)luaL_checknumber(lua, 1); thread_semaphore = tb_malloc0_type(xm_thread_semaphore_t); tb_assert_and_check_break(thread_semaphore); - thread_semaphore->refn = 1; + thread_semaphore->refn = 1; thread_semaphore->handle = tb_semaphore_init(value); tb_assert_and_check_break(thread_semaphore->handle); @@ -55,12 +53,9 @@ tb_int_t xm_thread_semaphore_init(lua_State* lua) } while (0); - if (!ok) - { - if (thread_semaphore) - { - if (thread_semaphore->handle) - { + if (!ok) { + if (thread_semaphore) { + if (thread_semaphore->handle) { tb_semaphore_exit(thread_semaphore->handle); thread_semaphore->handle = tb_null; } diff --git a/core/src/xmake/thread/semaphore_post.c b/core/src/xmake/thread/semaphore_post.c index 9ca94bda5..d709e5a5e 100644 --- a/core/src/xmake/thread/semaphore_post.c +++ b/core/src/xmake/thread/semaphore_post.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_semaphore" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_semaphore" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,15 +33,13 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_semaphore_post(lua_State* lua) -{ +tb_int_t xm_thread_semaphore_post(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_semaphore_t* thread_semaphore = xm_thread_semaphore_get(lua, 1); + xm_thread_semaphore_t *thread_semaphore = xm_thread_semaphore_get(lua, 1); tb_assert_and_check_return_val(thread_semaphore && thread_semaphore->handle, 0); tb_long_t value = (tb_long_t)luaL_checknumber(lua, 2); lua_pushboolean(lua, tb_semaphore_post(thread_semaphore->handle, value)); return 1; } - diff --git a/core/src/xmake/thread/semaphore_wait.c b/core/src/xmake/thread/semaphore_wait.c index c8e4d1491..40337a117 100644 --- a/core/src/xmake/thread/semaphore_wait.c +++ b/core/src/xmake/thread/semaphore_wait.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_semaphore" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_semaphore" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,15 +33,13 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_semaphore_wait(lua_State* lua) -{ +tb_int_t xm_thread_semaphore_wait(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_semaphore_t* thread_semaphore = xm_thread_semaphore_get(lua, 1); + xm_thread_semaphore_t *thread_semaphore = xm_thread_semaphore_get(lua, 1); tb_assert_and_check_return_val(thread_semaphore && thread_semaphore->handle, 0); tb_long_t timeout = (tb_long_t)luaL_checknumber(lua, 2); lua_pushinteger(lua, tb_semaphore_wait(thread_semaphore->handle, timeout)); return 1; } - diff --git a/core/src/xmake/thread/sharedata_clear.c b/core/src/xmake/thread/sharedata_clear.c index 0c8b4afcf..426785e0e 100644 --- a/core/src/xmake/thread/sharedata_clear.c +++ b/core/src/xmake/thread/sharedata_clear.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_sharedata" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_sharedata" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,11 +33,10 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_sharedata_clear(lua_State* lua) -{ +tb_int_t xm_thread_sharedata_clear(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1); + xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1); tb_assert_and_check_return_val(thread_sharedata, 0); thread_sharedata->value.kind = XM_THREAD_VALUE_NIL; @@ -45,4 +44,3 @@ tb_int_t xm_thread_sharedata_clear(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/thread/sharedata_exit.c b/core/src/xmake/thread/sharedata_exit.c index ad4a9f33f..ad017f2b6 100644 --- a/core/src/xmake/thread/sharedata_exit.c +++ b/core/src/xmake/thread/sharedata_exit.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_sharedata" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_sharedata" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,19 +33,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_sharedata_exit(lua_State* lua) -{ +tb_int_t xm_thread_sharedata_exit(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1); + xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1); tb_assert_and_check_return_val(thread_sharedata, 0); - if (tb_atomic_fetch_and_sub(&thread_sharedata->refn, 1) == 1) - { + if (tb_atomic_fetch_and_sub(&thread_sharedata->refn, 1) == 1) { tb_buffer_exit(&thread_sharedata->buffer); tb_free(thread_sharedata); } lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/thread/sharedata_get.c b/core/src/xmake/thread/sharedata_get.c index abd020d3b..a239fb02d 100644 --- a/core/src/xmake/thread/sharedata_get.c +++ b/core/src/xmake/thread/sharedata_get.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_sharedata" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_sharedata" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,20 +33,21 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_sharedata_get_(lua_State* lua) -{ +tb_int_t xm_thread_sharedata_get_(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1); + xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1); tb_assert_and_check_return_val(thread_sharedata, 0); tb_bool_t ok = tb_false; - switch (thread_sharedata->value.kind) - { + switch (thread_sharedata->value.kind) { case XM_THREAD_VALUE_STR: if (tb_buffer_size(&thread_sharedata->buffer) > 0) - lua_pushlstring(lua, (tb_char_t*)tb_buffer_data(&thread_sharedata->buffer), tb_buffer_size(&thread_sharedata->buffer)); - else lua_pushliteral(lua, ""); + lua_pushlstring(lua, + (tb_char_t *)tb_buffer_data(&thread_sharedata->buffer), + tb_buffer_size(&thread_sharedata->buffer)); + else + lua_pushliteral(lua, ""); ok = tb_true; break; case XM_THREAD_VALUE_INT: @@ -69,8 +70,7 @@ tb_int_t xm_thread_sharedata_get_(lua_State* lua) break; } - if (!ok) - { + if (!ok) { lua_pushnil(lua); lua_pushliteral(lua, "invalid thread sharedata thread_sharedata"); return 2; @@ -78,5 +78,3 @@ tb_int_t xm_thread_sharedata_get_(lua_State* lua) return 1; } - - diff --git a/core/src/xmake/thread/sharedata_incref.c b/core/src/xmake/thread/sharedata_incref.c index e0d32c600..3c11f7d15 100644 --- a/core/src/xmake/thread/sharedata_incref.c +++ b/core/src/xmake/thread/sharedata_incref.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_sharedata" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_sharedata" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,14 +33,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_sharedata_incref(lua_State* lua) -{ +tb_int_t xm_thread_sharedata_incref(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1); + xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1); tb_assert_and_check_return_val(thread_sharedata, 0); lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_sharedata->refn, 1) >= 1); return 1; } - diff --git a/core/src/xmake/thread/sharedata_init.c b/core/src/xmake/thread/sharedata_init.c index b38fc217a..ac712e5f3 100644 --- a/core/src/xmake/thread/sharedata_init.c +++ b/core/src/xmake/thread/sharedata_init.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_sharedata" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_sharedata" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,18 +33,16 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_sharedata_init(lua_State* lua) -{ +tb_int_t xm_thread_sharedata_init(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - tb_bool_t ok = tb_false; - xm_thread_sharedata_t* thread_sharedata = tb_null; - do - { + tb_bool_t ok = tb_false; + xm_thread_sharedata_t *thread_sharedata = tb_null; + do { thread_sharedata = tb_malloc0_type(xm_thread_sharedata_t); tb_assert_and_check_break(thread_sharedata); - thread_sharedata->refn = 1; + thread_sharedata->refn = 1; thread_sharedata->value.kind = XM_THREAD_VALUE_NIL; tb_buffer_init(&thread_sharedata->buffer); @@ -53,10 +51,8 @@ tb_int_t xm_thread_sharedata_init(lua_State* lua) } while (0); - if (!ok) - { - if (thread_sharedata) - { + if (!ok) { + if (thread_sharedata) { tb_buffer_exit(&thread_sharedata->buffer); tb_free(thread_sharedata); } diff --git a/core/src/xmake/thread/sharedata_set.c b/core/src/xmake/thread/sharedata_set.c index 08e661f20..9f1e6b613 100644 --- a/core/src/xmake/thread/sharedata_set.c +++ b/core/src/xmake/thread/sharedata_set.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread_sharedata" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread_sharedata" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,45 +33,34 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_sharedata_set(lua_State* lua) -{ +tb_int_t xm_thread_sharedata_set(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); - xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1); + xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1); tb_assert_and_check_return_val(thread_sharedata, 0); - if (lua_isstring(lua, 2)) - { - size_t data_size = 0; - tb_char_t const* data = luaL_checklstring(lua, 2, &data_size); + if (lua_isstring(lua, 2)) { + size_t data_size = 0; + tb_char_t const *data = luaL_checklstring(lua, 2, &data_size); tb_assert_and_check_return_val(data, 0); thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_STR; if (data_size) - tb_buffer_memncpy(&thread_sharedata->buffer, (tb_byte_t const*)data, data_size); - else tb_buffer_clear(&thread_sharedata->buffer); - } - else if (xm_lua_isinteger(lua, 2)) - { - thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_INT; + tb_buffer_memncpy(&thread_sharedata->buffer, (tb_byte_t const *)data, data_size); + else + tb_buffer_clear(&thread_sharedata->buffer); + } else if (xm_lua_isinteger(lua, 2)) { + thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_INT; thread_sharedata->value.u.integer = lua_tointeger(lua, 2); - } - else if (lua_isnumber(lua, 2)) - { - thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_NUM; + } else if (lua_isnumber(lua, 2)) { + thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_NUM; thread_sharedata->value.u.number = lua_tonumber(lua, 2); - } - else if (lua_isboolean(lua, 2)) - { - thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_BOOL; + } else if (lua_isboolean(lua, 2)) { + thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_BOOL; thread_sharedata->value.u.boolean = lua_toboolean(lua, 2); - } - else if (lua_isnil(lua, 2)) - { + } else if (lua_isnil(lua, 2)) { thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_NIL; - } - else - { + } else { lua_pushboolean(lua, tb_false); lua_pushliteral(lua, "unsupported thread sharedata item"); return 2; @@ -80,5 +69,3 @@ tb_int_t xm_thread_sharedata_set(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - - diff --git a/core/src/xmake/thread/thread_exit.c b/core/src/xmake/thread/thread_exit.c index 9d2c8e908..a91018ac6 100644 --- a/core/src/xmake/thread/thread_exit.c +++ b/core/src/xmake/thread/thread_exit.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_exit(lua_State* lua) -{ +tb_int_t xm_thread_exit(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -43,16 +42,14 @@ tb_int_t xm_thread_exit(lua_State* lua) return 0; // get thread - xm_thread_t* thread = (xm_thread_t*)xm_lua_topointer(lua, 1); + xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1); tb_check_return_val(thread, 0); // exit thread - if (thread) - { + if (thread) { tb_string_exit(&thread->callback); tb_string_exit(&thread->callinfo); - if (thread->handle) - { + if (thread->handle) { tb_thread_exit(thread->handle); thread->handle = tb_null; } @@ -61,4 +58,3 @@ tb_int_t xm_thread_exit(lua_State* lua) lua_pushboolean(lua, tb_true); return 1; } - diff --git a/core/src/xmake/thread/thread_init.c b/core/src/xmake/thread/thread_init.c index 6fc44267a..60d694ae1 100644 --- a/core/src/xmake/thread/thread_init.c +++ b/core/src/xmake/thread/thread_init.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,44 +35,41 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * macros */ -#define XM_THREAD_ENGINE_NAME "xmake" +#define XM_THREAD_ENGINE_NAME "xmake" /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_int_t xm_thread_func(tb_cpointer_t priv) -{ - xm_thread_t* thread = (xm_thread_t*)priv; +static tb_int_t xm_thread_func(tb_cpointer_t priv) { + xm_thread_t *thread = (xm_thread_t *)priv; tb_assert_and_check_return_val(thread, 0); xm_engine_ref_t engine = xm_engine_pool_alloc(xm_engine_pool()); - if (!engine) engine = xm_engine_init(XM_THREAD_ENGINE_NAME, tb_null); - if (engine) - { - lua_State* lua = xm_engine_lua(engine); + if (!engine) + engine = xm_engine_init(XM_THREAD_ENGINE_NAME, tb_null); + if (engine) { + lua_State *lua = xm_engine_lua(engine); tb_assert(lua); // pass callback - tb_char_t const* callback_data = tb_string_cstr(&thread->callback); + tb_char_t const *callback_data = tb_string_cstr(&thread->callback); tb_size_t callback_size = tb_string_size(&thread->callback); - if (callback_data && callback_size) - { + if (callback_data && callback_size) { lua_pushlstring(lua, callback_data, callback_size); lua_setglobal(lua, "_THREAD_CALLBACK"); } // pass callinfo - tb_char_t const* callinfo_data = tb_string_cstr(&thread->callinfo); + tb_char_t const *callinfo_data = tb_string_cstr(&thread->callinfo); tb_size_t callinfo_size = tb_string_size(&thread->callinfo); - if (callinfo_data && callinfo_size) - { + if (callinfo_data && callinfo_size) { lua_pushlstring(lua, callinfo_data, callinfo_size); lua_setglobal(lua, "_THREAD_CALLINFO"); } // start engine - tb_char_t* argv[] = {XM_THREAD_ENGINE_NAME, tb_null}; + tb_char_t *argv[] = { XM_THREAD_ENGINE_NAME, tb_null }; xm_engine_main(engine, 1, argv, tb_null); if (!xm_engine_pool_free(xm_engine_pool(), engine)) xm_engine_exit(engine); @@ -83,26 +80,24 @@ static tb_int_t xm_thread_func(tb_cpointer_t priv) /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_init(lua_State* lua) -{ +tb_int_t xm_thread_init(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); - tb_bool_t ok = tb_false; - xm_thread_t* thread = tb_null; - do - { + tb_bool_t ok = tb_false; + xm_thread_t *thread = tb_null; + do { // get thread name - tb_char_t const* name = luaL_checkstring(lua, 1); + tb_char_t const *name = luaL_checkstring(lua, 1); // get callback - size_t callback_size = 0; - tb_char_t const* callback_data = luaL_checklstring(lua, 2, &callback_size); + size_t callback_size = 0; + tb_char_t const *callback_data = luaL_checklstring(lua, 2, &callback_size); tb_assert_and_check_break(callback_data && callback_size); // get callinfo - size_t callinfo_size = 0; - tb_char_t const* callinfo_data = luaL_checklstring(lua, 3, &callinfo_size); + size_t callinfo_size = 0; + tb_char_t const *callinfo_data = luaL_checklstring(lua, 3, &callinfo_size); tb_assert_and_check_break(callinfo_data && callinfo_size); // get stack size @@ -127,14 +122,11 @@ tb_int_t xm_thread_init(lua_State* lua) } while (0); - if (!ok) - { - if (thread) - { + if (!ok) { + if (thread) { tb_string_exit(&thread->callback); tb_string_exit(&thread->callinfo); - if (thread->handle) - { + if (thread->handle) { tb_thread_exit(thread->handle); thread->handle = tb_null; } diff --git a/core/src/xmake/thread/thread_resume.c b/core/src/xmake/thread/thread_resume.c index 9843ac2d7..9a3630338 100644 --- a/core/src/xmake/thread/thread_resume.c +++ b/core/src/xmake/thread/thread_resume.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_resume(lua_State* lua) -{ +tb_int_t xm_thread_resume(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -43,11 +42,10 @@ tb_int_t xm_thread_resume(lua_State* lua) return 0; // get thread - xm_thread_t* thread = (xm_thread_t*)xm_lua_topointer(lua, 1); + xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1); tb_check_return_val(thread && thread->handle, 0); // resume thread lua_pushboolean(lua, tb_thread_resume(thread->handle)); return 1; } - diff --git a/core/src/xmake/thread/thread_suspend.c b/core/src/xmake/thread/thread_suspend.c index e21509413..dcb24c4f6 100644 --- a/core/src/xmake/thread/thread_suspend.c +++ b/core/src/xmake/thread/thread_suspend.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_suspend(lua_State* lua) -{ +tb_int_t xm_thread_suspend(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -43,11 +42,10 @@ tb_int_t xm_thread_suspend(lua_State* lua) return 0; // get thread - xm_thread_t* thread = (xm_thread_t*)xm_lua_topointer(lua, 1); + xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1); tb_check_return_val(thread && thread->handle, 0); // suspend thread lua_pushboolean(lua, tb_thread_suspend(thread->handle)); return 1; } - diff --git a/core/src/xmake/thread/thread_wait.c b/core/src/xmake/thread/thread_wait.c index f2d7199ec..4a921f39c 100644 --- a/core/src/xmake/thread/thread_wait.c +++ b/core/src/xmake/thread/thread_wait.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "thread" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "thread" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,8 +33,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_int_t xm_thread_wait(lua_State* lua) -{ +tb_int_t xm_thread_wait(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -43,7 +42,7 @@ tb_int_t xm_thread_wait(lua_State* lua) return 0; // get thread - xm_thread_t* thread = (xm_thread_t*)xm_lua_topointer(lua, 1); + xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1); tb_check_return_val(thread->handle, 0); // get timeout @@ -54,4 +53,3 @@ tb_int_t xm_thread_wait(lua_State* lua) lua_pushinteger(lua, (tb_int_t)tb_thread_wait(thread->handle, timeout, &retval)); return 1; } - diff --git a/core/src/xmake/tty/prefix.h b/core/src/xmake/tty/prefix.h index 6fb63c5f6..1afa646e3 100644 --- a/core/src/xmake/tty/prefix.h +++ b/core/src/xmake/tty/prefix.h @@ -26,7 +26,4 @@ */ #include "../prefix.h" - #endif - - diff --git a/core/src/xmake/tty/term_mode.c b/core/src/xmake/tty/term_mode.c index ec5f55ae9..78380de5f 100644 --- a/core/src/xmake/tty/term_mode.c +++ b/core/src/xmake/tty/term_mode.c @@ -22,15 +22,15 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "term_mode" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "term_mode" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "prefix.h" #ifdef TB_CONFIG_OS_WINDOWS -# include +#include #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -40,8 +40,7 @@ /* local oldmode = tty.term_mode(stdtype) * local oldmode = tty.term_mode(stdtype, newmode) */ -tb_int_t xm_tty_term_mode(lua_State* lua) -{ +tb_int_t xm_tty_term_mode(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -51,17 +50,21 @@ tb_int_t xm_tty_term_mode(lua_State* lua) tb_int_t stdtype = (tb_int_t)luaL_checkinteger(lua, 1); // get and set terminal mode - DWORD mode = 0; + DWORD mode = 0; HANDLE console_handle = INVALID_HANDLE_VALUE; - switch (stdtype) - { - case 1: console_handle = GetStdHandle(STD_INPUT_HANDLE); break; - case 2: console_handle = GetStdHandle(STD_OUTPUT_HANDLE); break; - case 3: console_handle = GetStdHandle(STD_ERROR_HANDLE); break; + switch (stdtype) { + case 1: + console_handle = GetStdHandle(STD_INPUT_HANDLE); + break; + case 2: + console_handle = GetStdHandle(STD_OUTPUT_HANDLE); + break; + case 3: + console_handle = GetStdHandle(STD_ERROR_HANDLE); + break; } GetConsoleMode(console_handle, &mode); - if (lua_isnumber(lua, 2)) - { + if (lua_isnumber(lua, 2)) { tb_int_t newmode = (tb_int_t)lua_tointeger(lua, 2); if (console_handle != INVALID_HANDLE_VALUE) SetConsoleMode(console_handle, (DWORD)newmode); diff --git a/core/src/xmake/utils/bin2c.c b/core/src/xmake/utils/bin2c.c index aeb80efac..fef00fb4e 100644 --- a/core/src/xmake/utils/bin2c.c +++ b/core/src/xmake/utils/bin2c.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "bin2c" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "bin2c" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -33,39 +33,37 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static __tb_inline__ tb_size_t xm_utils_bin2c_hex2str(tb_char_t str[5], tb_byte_t value) -{ - static tb_char_t const* digits_table = "0123456789ABCDEF"; - str[0] = ' '; - str[1] = '0'; - str[2] = 'x'; - str[3] = digits_table[(value >> 4) & 15]; - str[4] = digits_table[value & 15]; +static __tb_inline__ tb_size_t xm_utils_bin2c_hex2str(tb_char_t str[5], tb_byte_t value) { + static tb_char_t const *digits_table = "0123456789ABCDEF"; + str[0] = ' '; + str[1] = '0'; + str[2] = 'x'; + str[3] = digits_table[(value >> 4) & 15]; + str[4] = digits_table[value & 15]; return 5; } -static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream, tb_stream_ref_t ostream, tb_int_t linewidth, tb_bool_t nozeroend) -{ +static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream, + tb_stream_ref_t ostream, + tb_int_t linewidth, + tb_bool_t nozeroend) { tb_bool_t first = tb_true; - tb_hong_t i = 0; - tb_hong_t left = 0; + tb_hong_t i = 0; + tb_hong_t left = 0; tb_char_t line[4096]; tb_byte_t data[512]; tb_size_t linesize = 0; - tb_size_t need = 0; + tb_size_t need = 0; tb_assert_and_check_return_val(linewidth < sizeof(data), tb_false); - while (!tb_stream_beof(istream)) - { + while (!tb_stream_beof(istream)) { linesize = 0; - left = tb_stream_left(istream); - need = (tb_size_t)tb_min(left, linewidth); - if (need) - { + left = tb_stream_left(istream); + need = (tb_size_t)tb_min(left, linewidth); + if (need) { if (!tb_stream_bread(istream, data, need)) break; - if (!nozeroend && tb_stream_beof(istream)) - { + if (!nozeroend && tb_stream_beof(istream)) { tb_assert_and_check_break(need + 1 < sizeof(data)); data[need++] = '\0'; } @@ -73,16 +71,14 @@ static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream, tb_stream_ref_t os tb_assert_and_check_break(linesize + 6 * need < sizeof(line)); i = 0; - if (first) - { - first = tb_false; + if (first) { + first = tb_false; line[linesize++] = ' '; - } - else line[linesize++] = ','; + } else + line[linesize++] = ','; linesize += xm_utils_bin2c_hex2str(line + linesize, data[i]); - for (i = 1; i < need; i++) - { + for (i = 1; i < need; i++) { line[linesize++] = ','; linesize += xm_utils_bin2c_hex2str(line + linesize, data[i]); } @@ -104,17 +100,16 @@ static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream, tb_stream_ref_t os * * local ok, errors = utils.bin2c(binaryfile, outputfile, linewidth, nozeroend) */ -tb_int_t xm_utils_bin2c(lua_State* lua) -{ +tb_int_t xm_utils_bin2c(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the binaryfile - tb_char_t const* binaryfile = luaL_checkstring(lua, 1); + tb_char_t const *binaryfile = luaL_checkstring(lua, 1); tb_check_return_val(binaryfile, 0); // get the outputfile - tb_char_t const* outputfile = luaL_checkstring(lua, 2); + tb_char_t const *outputfile = luaL_checkstring(lua, 2); tb_check_return_val(outputfile, 0); // get line width @@ -124,27 +119,24 @@ tb_int_t xm_utils_bin2c(lua_State* lua) tb_bool_t nozeroend = (tb_bool_t)lua_toboolean(lua, 4); // do dump - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_stream_ref_t istream = tb_stream_init_from_file(binaryfile, TB_FILE_MODE_RO); - tb_stream_ref_t ostream = tb_stream_init_from_file(outputfile, TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC); - do - { - if (!tb_stream_open(istream)) - { + tb_stream_ref_t ostream = tb_stream_init_from_file(outputfile, + TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC); + do { + if (!tb_stream_open(istream)) { lua_pushboolean(lua, tb_false); lua_pushfstring(lua, "bin2c: open %s failed", binaryfile); break; } - if (!tb_stream_open(ostream)) - { + if (!tb_stream_open(ostream)) { lua_pushboolean(lua, tb_false); lua_pushfstring(lua, "bin2c: open %s failed", outputfile); break; } - if (!xm_utils_bin2c_dump(istream, ostream, linewidth, nozeroend)) - { + if (!xm_utils_bin2c_dump(istream, ostream, linewidth, nozeroend)) { lua_pushboolean(lua, tb_false); lua_pushfstring(lua, "bin2c: dump data failed"); break; @@ -155,11 +147,13 @@ tb_int_t xm_utils_bin2c(lua_State* lua) } while (0); - if (istream) tb_stream_clos(istream); + if (istream) + tb_stream_clos(istream); istream = tb_null; - if (ostream) tb_stream_clos(ostream); + if (ostream) + tb_stream_clos(ostream); ostream = tb_null; - return ok? 1 : 2; + return ok ? 1 : 2; } diff --git a/core/src/xmake/utils/prefix.h b/core/src/xmake/utils/prefix.h index 287e6bb45..a9f509e72 100644 --- a/core/src/xmake/utils/prefix.h +++ b/core/src/xmake/utils/prefix.h @@ -27,5 +27,3 @@ #include "../prefix.h" #endif - - diff --git a/core/src/xmake/winos/ansi.c b/core/src/xmake/winos/ansi.c index e4780d134..137f18742 100644 --- a/core/src/xmake/winos/ansi.c +++ b/core/src/xmake/winos/ansi.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "ansi" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "ansi" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,64 +35,56 @@ * implementation */ -static tb_int_t xm_expand_cp(tb_int_t cp) -{ +static tb_int_t xm_expand_cp(tb_int_t cp) { // check tb_assert_and_check_return_val(cp >= 0 && cp <= 65535, 0); - if (cp == CP_OEMCP) return GetOEMCP(); - if (cp == CP_ACP) return GetACP(); + if (cp == CP_OEMCP) + return GetOEMCP(); + if (cp == CP_ACP) + return GetACP(); return cp; } -tb_int_t xm_winos_console_cp(lua_State* lua) -{ +tb_int_t xm_winos_console_cp(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); tb_int_t n = lua_gettop(lua); - if (n >= 1) - { + if (n >= 1) { lua_Integer cp = luaL_checkinteger(lua, 1); luaL_argcheck(lua, cp >= 0 && cp < 65536, 1, "invalid code page"); cp = xm_expand_cp((tb_uint_t)cp); luaL_argcheck(lua, SetConsoleCP((tb_uint_t)cp), 1, "failed to set code page"); lua_pushinteger(lua, cp); return 1; - } - else - { + } else { tb_uint_t cp = GetConsoleCP(); lua_pushinteger(lua, (lua_Integer)cp); return 1; } } -tb_int_t xm_winos_console_output_cp(lua_State* lua) -{ +tb_int_t xm_winos_console_output_cp(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); tb_int_t n = lua_gettop(lua); - if (n >= 1) - { + if (n >= 1) { lua_Integer cp = luaL_checkinteger(lua, 1); luaL_argcheck(lua, cp >= 0 && cp < 65536, 1, "invalid code page"); cp = xm_expand_cp((tb_uint_t)cp); luaL_argcheck(lua, SetConsoleOutputCP((tb_uint_t)cp), 1, "failed to set code page"); lua_pushinteger(lua, cp); return 1; - } - else - { + } else { tb_uint_t cp = GetConsoleOutputCP(); lua_pushinteger(lua, (lua_Integer)cp); return 1; } } -tb_int_t xm_winos_cp_info(lua_State* lua) -{ +tb_int_t xm_winos_cp_info(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -104,7 +96,7 @@ tb_int_t xm_winos_cp_info(lua_State* lua) lua_newtable(lua); lua_pushliteral(lua, "name"); - tb_char_t* namebuf = tb_malloc_cstr(sizeof(cp_info.CodePageName) * 2); + tb_char_t *namebuf = tb_malloc_cstr(sizeof(cp_info.CodePageName) * 2); tb_assert_and_check_return_val(namebuf, 0); tb_size_t namelen = tb_wtoa(namebuf, (const tb_wchar_t *)cp_info.CodePageName, sizeof(cp_info.CodePageName) * 2); tb_assert_and_check_return_val(namelen < sizeof(cp_info.CodePageName) * 2, 0); @@ -121,13 +113,12 @@ tb_int_t xm_winos_cp_info(lua_State* lua) lua_settable(lua, -3); lua_pushliteral(lua, "default_char"); - lua_pushstring(lua, (tb_char_t const*)cp_info.DefaultChar); + lua_pushstring(lua, (tb_char_t const *)cp_info.DefaultChar); lua_settable(lua, -3); lua_pushliteral(lua, "lead_byte"); lua_createtable(lua, MAX_LEADBYTES / 2, 0); - for (tb_size_t i = 0; i < MAX_LEADBYTES && cp_info.LeadByte[i] != 0 && cp_info.LeadByte[i + 1] != 0; i += 2) - { + for (tb_size_t i = 0; i < MAX_LEADBYTES && cp_info.LeadByte[i] != 0 && cp_info.LeadByte[i + 1] != 0; i += 2) { lua_pushinteger(lua, (i / 2) + 1); lua_createtable(lua, 0, 2); @@ -146,8 +137,7 @@ tb_int_t xm_winos_cp_info(lua_State* lua) return 1; } -tb_int_t xm_winos_ansi_cp(lua_State* lua) -{ +tb_int_t xm_winos_ansi_cp(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -156,8 +146,7 @@ tb_int_t xm_winos_ansi_cp(lua_State* lua) return 1; } -tb_int_t xm_winos_oem_cp(lua_State* lua) -{ +tb_int_t xm_winos_oem_cp(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -165,4 +154,3 @@ tb_int_t xm_winos_oem_cp(lua_State* lua) lua_pushinteger(lua, (lua_Integer)cp); return 1; } - diff --git a/core/src/xmake/winos/logical_drives.c b/core/src/xmake/winos/logical_drives.c index f10e4e09b..48b05886e 100644 --- a/core/src/xmake/winos/logical_drives.c +++ b/core/src/xmake/winos/logical_drives.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "logical_drives" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "logical_drives" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,21 +35,19 @@ */ // get the logical drives -tb_int_t xm_winos_logical_drives(lua_State* lua) -{ +tb_int_t xm_winos_logical_drives(lua_State *lua) { // init table lua_newtable(lua); // get logical drives - tb_char_t* data = tb_null; - do - { + tb_char_t *data = tb_null; + do { // get buffer size DWORD size = GetLogicalDriveStringsA(0, tb_null); tb_assert_and_check_break(size); // make data buffer - data = (tb_char_t*)tb_malloc0(size + 1); + data = (tb_char_t *)tb_malloc0(size + 1); tb_assert_and_check_break(data); // get logical drives @@ -57,10 +55,9 @@ tb_int_t xm_winos_logical_drives(lua_State* lua) tb_assert_and_check_break(size); // parse logical drives - tb_size_t i = 1; - tb_char_t const* p = data; - while (*p) - { + tb_size_t i = 1; + tb_char_t const *p = data; + while (*p) { // save drive lua_pushinteger(lua, i++); lua_pushstring(lua, p); @@ -72,7 +69,8 @@ tb_int_t xm_winos_logical_drives(lua_State* lua) } while (0); // exit data - if (data) tb_free(data); + if (data) + tb_free(data); data = tb_null; // ok diff --git a/core/src/xmake/winos/prefix.h b/core/src/xmake/winos/prefix.h index 3c7e103dc..6543b112d 100644 --- a/core/src/xmake/winos/prefix.h +++ b/core/src/xmake/winos/prefix.h @@ -26,10 +26,7 @@ */ #include "../prefix.h" #ifdef TB_CONFIG_OS_WINDOWS -# include +#include #endif - #endif - - diff --git a/core/src/xmake/winos/registry_keys.c b/core/src/xmake/winos/registry_keys.c index 807a094a1..42a37e33d 100644 --- a/core/src/xmake/winos/registry_keys.c +++ b/core/src/xmake/winos/registry_keys.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "registry_keys" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "registry_keys" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,75 +35,79 @@ */ // the enum info type -typedef struct __xm_winos_registry_enum_info_t -{ - lua_State* lua; - HKEY key; - tb_int_t ok; - tb_char_t const* error; - tb_int_t count; - tb_wchar_t key_name[1024]; - tb_char_t key_path_a[TB_PATH_MAXN]; - -}xm_winos_registry_enum_info_t; +typedef struct __xm_winos_registry_enum_info_t { + lua_State *lua; + HKEY key; + tb_int_t ok; + tb_char_t const *error; + tb_int_t count; + tb_wchar_t key_name[1024]; + tb_char_t key_path_a[TB_PATH_MAXN]; +} xm_winos_registry_enum_info_t; /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info, tb_wchar_t const* rootdir, tb_long_t recursion) -{ +static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t *info, + tb_wchar_t const *rootdir, + tb_long_t recursion) { // enum keys - HKEY keynew = tb_null; - lua_State* lua = info->lua; - tb_wchar_t* key_path = tb_null; + HKEY keynew = tb_null; + lua_State *lua = info->lua; + tb_wchar_t *key_path = tb_null; tb_size_t key_path_maxn = TB_PATH_MAXN; - do - { + do { // open registry key - if (RegOpenKeyExW(info->key, rootdir, 0, KEY_READ, &keynew) != ERROR_SUCCESS && keynew) - { - info->ok = -1; + if (RegOpenKeyExW(info->key, rootdir, 0, KEY_READ, &keynew) != ERROR_SUCCESS && keynew) { + info->ok = -1; info->error = "open registry key failed"; break; } // query keys - DWORD key_name_num = 0; + DWORD key_name_num = 0; DWORD key_name_maxn = 0; - if (RegQueryInfoKeyW(keynew, tb_null, tb_null, tb_null, &key_name_num, &key_name_maxn, tb_null, tb_null, tb_null, tb_null, tb_null, tb_null) != ERROR_SUCCESS) - { + if (RegQueryInfoKeyW(keynew, + tb_null, + tb_null, + tb_null, + &key_name_num, + &key_name_maxn, + tb_null, + tb_null, + tb_null, + tb_null, + tb_null, + tb_null) != ERROR_SUCCESS) { // cannot query this key, we ignore it break; } key_name_maxn++; // add `\0` // ensure enough key path buffer - if (key_name_maxn > tb_arrayn(info->key_name)) - { - info->ok = -1; + if (key_name_maxn > tb_arrayn(info->key_name)) { + info->ok = -1; info->error = "no enough key path buffer"; break; } // init key path - key_path = (tb_wchar_t*)tb_malloc(key_path_maxn * sizeof(tb_wchar_t)); - if (!key_path) - { - info->ok = -1; + key_path = (tb_wchar_t *)tb_malloc(key_path_maxn * sizeof(tb_wchar_t)); + if (!key_path) { + info->ok = -1; info->error = "no enough key path buffer"; break; } // get all keys DWORD i = 0; - for (i = 0; i < key_name_num && info->ok > 0; i++) - { + for (i = 0; i < key_name_num && info->ok > 0; i++) { // get key name - info->key_name[0] = L'\0'; + info->key_name[0] = L'\0'; DWORD key_name_size = tb_arrayn(info->key_name); - if (RegEnumKeyExW(keynew, i, info->key_name, &key_name_size, tb_null, tb_null, tb_null, tb_null) != ERROR_SUCCESS) - { - info->ok = -1; + if (RegEnumKeyExW(keynew, i, info->key_name, &key_name_size, tb_null, tb_null, tb_null, tb_null) != + ERROR_SUCCESS) { + info->ok = -1; info->error = "get registry key failed"; break; } @@ -113,9 +117,8 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info // get key path (mbs) tb_size_t key_path_a_size = tb_wtoa(info->key_path_a, key_path, sizeof(info->key_path_a)); - if (key_path_a_size == -1) - { - info->ok = -1; + if (key_path_a_size == -1) { + info->ok = -1; info->error = "convert registry key path failed"; break; } @@ -129,15 +132,14 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info // is continue? tb_bool_t is_continue = lua_toboolean(lua, -1); lua_pop(lua, 1); - if (!is_continue) - { + if (!is_continue) { info->ok = 0; break; } // enum all subkeys if (recursion > 0 || recursion < 0) - xm_winos_registry_enum_keys(info, key_path, recursion > 0? recursion - 1 : recursion); + xm_winos_registry_enum_keys(info, key_path, recursion > 0 ? recursion - 1 : recursion); } } while (0); @@ -148,7 +150,8 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info keynew = tb_null; // free key path - if (key_path) tb_free(key_path); + if (key_path) + tb_free(key_path); key_path = tb_null; } @@ -164,36 +167,42 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info * return true -- continue or break * end) */ -tb_int_t xm_winos_registry_keys(lua_State* lua) -{ +tb_int_t xm_winos_registry_keys(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the arguments - tb_char_t const* rootkey = luaL_checkstring(lua, 1); - tb_char_t const* rootdir = luaL_checkstring(lua, 2); - tb_long_t recursion = (tb_long_t)lua_tointeger(lua, 3); - tb_bool_t is_function = lua_isfunction(lua, 4); + tb_char_t const *rootkey = luaL_checkstring(lua, 1); + tb_char_t const *rootdir = luaL_checkstring(lua, 2); + tb_long_t recursion = (tb_long_t)lua_tointeger(lua, 3); + tb_bool_t is_function = lua_isfunction(lua, 4); tb_check_return_val(rootkey && rootdir && is_function, 0); // enum keys - tb_bool_t ok = tb_false; - tb_int_t count = 0; - HKEY key = tb_null; - do - { + tb_bool_t ok = tb_false; + tb_int_t count = 0; + HKEY key = tb_null; + do { // get registry rootkey - if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKCR")) key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKCC")) key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKCU")) key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKLM")) key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKEY_USERS")) key = HKEY_USERS; - else - { + if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) + key = HKEY_CLASSES_ROOT; + else if (!tb_strcmp(rootkey, "HKCR")) + key = HKEY_CLASSES_ROOT; + else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) + key = HKEY_CURRENT_CONFIG; + else if (!tb_strcmp(rootkey, "HKCC")) + key = HKEY_CURRENT_CONFIG; + else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) + key = HKEY_CURRENT_USER; + else if (!tb_strcmp(rootkey, "HKCU")) + key = HKEY_CURRENT_USER; + else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) + key = HKEY_LOCAL_MACHINE; + else if (!tb_strcmp(rootkey, "HKLM")) + key = HKEY_LOCAL_MACHINE; + else if (!tb_strcmp(rootkey, "HKEY_USERS")) + key = HKEY_USERS; + else { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey: %s", rootkey); break; @@ -201,8 +210,7 @@ tb_int_t xm_winos_registry_keys(lua_State* lua) // do enum tb_wchar_t rootdir_w[TB_PATH_MAXN]; - if (tb_atow(rootdir_w, rootdir, TB_PATH_MAXN) == -1) - { + if (tb_atow(rootdir_w, rootdir, TB_PATH_MAXN) == -1) { lua_pushnil(lua); lua_pushfstring(lua, "rootdir is too long: %s", rootdir); break; @@ -216,20 +224,17 @@ tb_int_t xm_winos_registry_keys(lua_State* lua) xm_winos_registry_enum_keys(&info, rootdir_w, recursion); count = info.count; ok = info.ok >= 0; - if (!ok) - { + if (!ok) { lua_pushnil(lua); - lua_pushfstring(lua, "%s: %s\\%s", info.error? info.error : "enum registry keys failed", rootkey, rootdir); + lua_pushfstring(lua, "%s: %s\\%s", info.error ? info.error : "enum registry keys failed", rootkey, rootdir); } } while (0); // ok? - if (ok) - { + if (ok) { lua_pushinteger(lua, count); return 1; - } - else return 2; + } else + return 2; } - diff --git a/core/src/xmake/winos/registry_query.c b/core/src/xmake/winos/registry_query.c index d494a6db9..23fda76ff 100644 --- a/core/src/xmake/winos/registry_query.c +++ b/core/src/xmake/winos/registry_query.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "registry_query" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "registry_query" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,7 +34,8 @@ * types */ // the RegGetValueW func type -typedef BOOL (WINAPI* xm_RegGetValueW_t)(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData); +typedef BOOL(WINAPI *xm_RegGetValueW_t)( + HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData); /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -44,38 +45,44 @@ typedef BOOL (WINAPI* xm_RegGetValueW_t)(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lp * * local value, errors = winos.registry_query("HKEY_LOCAL_MACHINE", "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", "Debugger") */ -tb_int_t xm_winos_registry_query(lua_State* lua) -{ +tb_int_t xm_winos_registry_query(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the arguments - tb_char_t const* rootkey = luaL_checkstring(lua, 1); - tb_char_t const* rootdir = luaL_checkstring(lua, 2); - tb_char_t const* valuename = luaL_checkstring(lua, 3); + tb_char_t const *rootkey = luaL_checkstring(lua, 1); + tb_char_t const *rootdir = luaL_checkstring(lua, 2); + tb_char_t const *valuename = luaL_checkstring(lua, 3); tb_check_return_val(rootkey && rootdir && valuename, 0); // query key-value - tb_bool_t ok = tb_false; - HKEY key = tb_null; - HKEY keynew = tb_null; - tb_char_t* value = tb_null; - tb_wchar_t* value_w = tb_null; + tb_bool_t ok = tb_false; + HKEY key = tb_null; + HKEY keynew = tb_null; + tb_char_t *value = tb_null; + tb_wchar_t *value_w = tb_null; tb_size_t value_n = (tb_size_t)-1; - do - { + do { // get registry rootkey - if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKCR")) key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKCC")) key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKCU")) key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKLM")) key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKEY_USERS")) key = HKEY_USERS; - else - { + if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) + key = HKEY_CLASSES_ROOT; + else if (!tb_strcmp(rootkey, "HKCR")) + key = HKEY_CLASSES_ROOT; + else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) + key = HKEY_CURRENT_CONFIG; + else if (!tb_strcmp(rootkey, "HKCC")) + key = HKEY_CURRENT_CONFIG; + else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) + key = HKEY_CURRENT_USER; + else if (!tb_strcmp(rootkey, "HKCU")) + key = HKEY_CURRENT_USER; + else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) + key = HKEY_LOCAL_MACHINE; + else if (!tb_strcmp(rootkey, "HKLM")) + key = HKEY_LOCAL_MACHINE; + else if (!tb_strcmp(rootkey, "HKEY_USERS")) + key = HKEY_USERS; + else { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey: %s", rootkey); break; @@ -83,8 +90,7 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // convert rootdir to wide characters tb_wchar_t rootdir_w[TB_PATH_MAXN]; - if (tb_atow(rootdir_w, rootdir, TB_PATH_MAXN) == (tb_size_t)-1) - { + if (tb_atow(rootdir_w, rootdir, TB_PATH_MAXN) == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey:: %s", rootdir); break; @@ -92,8 +98,7 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // convert valuename to wide characters tb_wchar_t valuename_w[TB_PATH_MAXN]; - if (tb_atow(valuename_w, valuename, TB_PATH_MAXN) == (tb_size_t)-1) - { + if (tb_atow(valuename_w, valuename, TB_PATH_MAXN) == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry valuename: %s", valuename); break; @@ -101,22 +106,21 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // attempt to load RegGetValueW static xm_RegGetValueW_t s_RegGetValueW = tb_null; - if (!s_RegGetValueW) - { + if (!s_RegGetValueW) { // load the advapi32 module tb_dynamic_ref_t module = (tb_dynamic_ref_t)GetModuleHandleA("advapi32.dll"); - if (!module) module = tb_dynamic_init("advapi32.dll"); - if (module) s_RegGetValueW = (xm_RegGetValueW_t)tb_dynamic_func(module, "RegGetValueW"); + if (!module) + module = tb_dynamic_init("advapi32.dll"); + if (module) + s_RegGetValueW = (xm_RegGetValueW_t)tb_dynamic_func(module, "RegGetValueW"); } // get registry value DWORD type = 0; - if (s_RegGetValueW) - { + if (s_RegGetValueW) { // get registry value size DWORD valuesize_w = 0; - if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, 0, tb_null, &valuesize_w) != ERROR_SUCCESS) - { + if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, 0, tb_null, &valuesize_w) != ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value size failed: %s\\%s;%s", rootkey, rootdir, valuename); break; @@ -124,34 +128,32 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // make value buffer DWORD valuesize = valuesize_w * 2; - value = (tb_char_t*)tb_malloc0(valuesize); + value = (tb_char_t *)tb_malloc0(valuesize); tb_assert_and_check_break(value); - value_w = (tb_wchar_t*)tb_malloc0(valuesize_w); + value_w = (tb_wchar_t *)tb_malloc0(valuesize_w); tb_assert_and_check_break(value_w); // get value result, we attempt to do not expand value if get failed type = 0; - if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, &type, (PVOID)value_w, &valuesize_w) != ERROR_SUCCESS && - s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY | RRF_NOEXPAND, &type, (PVOID)value_w, &valuesize_w) != ERROR_SUCCESS) - { + if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, &type, (PVOID)value_w, &valuesize_w) != + ERROR_SUCCESS && + s_RegGetValueW( + key, rootdir_w, valuename_w, RRF_RT_ANY | RRF_NOEXPAND, &type, (PVOID)value_w, &valuesize_w) != + ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value failed: %s\\%s;%s", rootkey, rootdir, valuename); break; } - + value_n = tb_wtoa(value, value_w, valuesize); - if (value_n == (tb_size_t)-1) - { + if (value_n == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "wtoa registry value failed: %s\\%s;%s", rootkey, rootdir, valuename); break; } - } - else - { + } else { // open registry key - if (RegOpenKeyExW(key, rootdir_w, 0, KEY_QUERY_VALUE, &keynew) != ERROR_SUCCESS && keynew) - { + if (RegOpenKeyExW(key, rootdir_w, 0, KEY_QUERY_VALUE, &keynew) != ERROR_SUCCESS && keynew) { lua_pushnil(lua); lua_pushfstring(lua, "open registry key failed: %s\\%s", rootkey, rootdir); break; @@ -159,8 +161,7 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // get registry value size DWORD valuesize_w = 0; - if (RegQueryValueExW(keynew, valuename_w, tb_null, tb_null, tb_null, &valuesize_w) != ERROR_SUCCESS) - { + if (RegQueryValueExW(keynew, valuename_w, tb_null, tb_null, tb_null, &valuesize_w) != ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value size failed: %s\\%s;%s", rootkey, rootdir, valuename); break; @@ -168,23 +169,21 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // make value buffer DWORD valuesize = valuesize_w * 2; - value = (tb_char_t*)tb_malloc0(valuesize); + value = (tb_char_t *)tb_malloc0(valuesize); tb_assert_and_check_break(value); - value_w = (tb_wchar_t*)tb_malloc0(valuesize_w); + value_w = (tb_wchar_t *)tb_malloc0(valuesize_w); tb_assert_and_check_break(value_w); // get value result type = 0; - if (RegQueryValueExW(keynew, valuename_w, tb_null, &type, (LPBYTE)value_w, &valuesize_w) != ERROR_SUCCESS) - { + if (RegQueryValueExW(keynew, valuename_w, tb_null, &type, (LPBYTE)value_w, &valuesize_w) != ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value failed: %s\\%s;%s", rootkey, rootdir, valuename); break; } value_n = tb_wtoa(value, value_w, valuesize); - if (value_n == (tb_size_t)-1) - { + if (value_n == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "wtoa registry value failed: %s\\%s;%s", rootkey, rootdir, valuename); break; @@ -192,19 +191,18 @@ tb_int_t xm_winos_registry_query(lua_State* lua) } // save result - switch (type) - { + switch (type) { case REG_SZ: case REG_EXPAND_SZ: lua_pushlstring(lua, value, value_n); ok = tb_true; break; case REG_DWORD: - lua_pushfstring(lua, "%d", *((tb_int_t*)value)); + lua_pushfstring(lua, "%d", *((tb_int_t *)value)); ok = tb_true; break; case REG_QWORD: - lua_pushfstring(lua, "%lld", *((tb_int64_t*)value)); + lua_pushfstring(lua, "%lld", *((tb_int64_t *)value)); ok = tb_true; break; default: @@ -221,11 +219,13 @@ tb_int_t xm_winos_registry_query(lua_State* lua) keynew = tb_null; // exit value - if (value) tb_free(value); + if (value) + tb_free(value); value = tb_null; - if (value_w) tb_free(value_w); + if (value_w) + tb_free(value_w); value_w = tb_null; // ok? - return ok? 1 : 2; + return ok ? 1 : 2; } diff --git a/core/src/xmake/winos/registry_values.c b/core/src/xmake/winos/registry_values.c index 7ce8ada10..1f72d978b 100644 --- a/core/src/xmake/winos/registry_values.c +++ b/core/src/xmake/winos/registry_values.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "registry_values" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "registry_values" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -42,54 +42,69 @@ * return true -- continue or break * end) */ -tb_int_t xm_winos_registry_values(lua_State* lua) -{ +tb_int_t xm_winos_registry_values(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the arguments - tb_char_t const* rootkey = luaL_checkstring(lua, 1); - tb_char_t const* rootdir = luaL_checkstring(lua, 2); - tb_bool_t is_function = lua_isfunction(lua, 3); + tb_char_t const *rootkey = luaL_checkstring(lua, 1); + tb_char_t const *rootdir = luaL_checkstring(lua, 2); + tb_bool_t is_function = lua_isfunction(lua, 3); tb_check_return_val(rootkey && rootdir && is_function, 0); // enum values - tb_bool_t ok = tb_false; - tb_int_t count = 0; - HKEY key = tb_null; - HKEY keynew = tb_null; - do - { + tb_bool_t ok = tb_false; + tb_int_t count = 0; + HKEY key = tb_null; + HKEY keynew = tb_null; + do { // get registry rootkey - if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKCR")) key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKCC")) key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKCU")) key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKLM")) key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKEY_USERS")) key = HKEY_USERS; - else - { + if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) + key = HKEY_CLASSES_ROOT; + else if (!tb_strcmp(rootkey, "HKCR")) + key = HKEY_CLASSES_ROOT; + else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) + key = HKEY_CURRENT_CONFIG; + else if (!tb_strcmp(rootkey, "HKCC")) + key = HKEY_CURRENT_CONFIG; + else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) + key = HKEY_CURRENT_USER; + else if (!tb_strcmp(rootkey, "HKCU")) + key = HKEY_CURRENT_USER; + else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) + key = HKEY_LOCAL_MACHINE; + else if (!tb_strcmp(rootkey, "HKLM")) + key = HKEY_LOCAL_MACHINE; + else if (!tb_strcmp(rootkey, "HKEY_USERS")) + key = HKEY_USERS; + else { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey: %s", rootkey); break; } // open registry key - if (RegOpenKeyExA(key, rootdir, 0, KEY_QUERY_VALUE, &keynew) != ERROR_SUCCESS && keynew) - { + if (RegOpenKeyExA(key, rootdir, 0, KEY_QUERY_VALUE, &keynew) != ERROR_SUCCESS && keynew) { lua_pushnil(lua); lua_pushfstring(lua, "open registry key failed: %s\\%s", rootkey, rootdir); break; } // query values - DWORD value_name_num = 0; + DWORD value_name_num = 0; DWORD value_name_maxn = 0; - if (RegQueryInfoKeyW(keynew, tb_null, tb_null, tb_null, tb_null, tb_null, tb_null, &value_name_num, &value_name_maxn, tb_null, tb_null, tb_null) != ERROR_SUCCESS) - { + if (RegQueryInfoKeyW(keynew, + tb_null, + tb_null, + tb_null, + tb_null, + tb_null, + tb_null, + &value_name_num, + &value_name_maxn, + tb_null, + tb_null, + tb_null) != ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "query registry info failed: %s\\%s", rootkey, rootdir); break; @@ -98,23 +113,21 @@ tb_int_t xm_winos_registry_values(lua_State* lua) // ensure enough value name buffer tb_wchar_t value_name[1024]; - if (value_name_maxn > tb_arrayn(value_name)) - { + if (value_name_maxn > tb_arrayn(value_name)) { lua_pushnil(lua); lua_pushfstring(lua, "no enough value name buffer: %s\\%s", rootkey, rootdir); break; } // get all values - DWORD i = 0; + DWORD i = 0; tb_char_t value_name_a[1024]; - for (i = 0; i < value_name_num; i++) - { + for (i = 0; i < value_name_num; i++) { // get value name - value_name[0] = L'\0'; + value_name[0] = L'\0'; DWORD value_name_size = tb_arrayn(value_name); - if (RegEnumValueW(keynew, i, value_name, &value_name_size, tb_null, tb_null, tb_null, tb_null) != ERROR_SUCCESS) - { + if (RegEnumValueW(keynew, i, value_name, &value_name_size, tb_null, tb_null, tb_null, tb_null) != + ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value name(%d) failed: %s\\%s", i, rootkey, rootdir); break; @@ -122,8 +135,7 @@ tb_int_t xm_winos_registry_values(lua_State* lua) // get value name (mbs) tb_size_t value_name_a_size = tb_wtoa(value_name_a, value_name, sizeof(value_name_a)); - if (value_name_a_size == -1) - { + if (value_name_a_size == -1) { lua_pushnil(lua); lua_pushfstring(lua, "convert registry value name(%d) failed: %s\\%s", i, rootkey, rootdir); break; @@ -138,8 +150,7 @@ tb_int_t xm_winos_registry_values(lua_State* lua) // is continue? tb_bool_t is_continue = lua_toboolean(lua, -1); lua_pop(lua, 1); - if (!is_continue) - { + if (!is_continue) { ok = tb_true; break; } @@ -157,10 +168,9 @@ tb_int_t xm_winos_registry_values(lua_State* lua) keynew = tb_null; // ok? - if (ok) - { + if (ok) { lua_pushinteger(lua, count); return 1; - } - else return 2; + } else + return 2; } diff --git a/core/src/xmake/winos/short_path.c b/core/src/xmake/winos/short_path.c index 5812a20da..5c6e20b30 100644 --- a/core/src/xmake/winos/short_path.c +++ b/core/src/xmake/winos/short_path.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "short_path" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "short_path" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -38,19 +38,17 @@ * * local short_path, errors = winos.short_path(long_path) */ -tb_int_t xm_winos_short_path(lua_State* lua) -{ +tb_int_t xm_winos_short_path(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the arguments - tb_char_t const* long_path = luaL_checkstring(lua, 1); + tb_char_t const *long_path = luaL_checkstring(lua, 1); tb_check_return_val(long_path, 0); // convert long path to wide characters tb_wchar_t long_path_w[TB_PATH_MAXN]; - if (tb_atow(long_path_w, long_path, TB_PATH_MAXN) == (tb_size_t)-1) - { + if (tb_atow(long_path_w, long_path, TB_PATH_MAXN) == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "invalid long path: %s", long_path); return 2; @@ -58,18 +56,16 @@ tb_int_t xm_winos_short_path(lua_State* lua) // get short path tb_wchar_t short_path_w[TB_PATH_MAXN]; - if (GetShortPathNameW(long_path_w, short_path_w, TB_PATH_MAXN) == 0) - { + if (GetShortPathNameW(long_path_w, short_path_w, TB_PATH_MAXN) == 0) { lua_pushnil(lua); lua_pushfstring(lua, "cannot get short path from: %s", long_path); return 2; } // return result - tb_char_t* short_path_a = (tb_char_t*)long_path_w; + tb_char_t *short_path_a = (tb_char_t *)long_path_w; tb_size_t short_path_n = tb_wtoa(short_path_a, short_path_w, TB_PATH_MAXN); - if (short_path_n == (tb_size_t)-1) - { + if (short_path_n == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "invalid short path from %s!", long_path); return 2; diff --git a/core/src/xmake/xmake.c b/core/src/xmake/xmake.c index 3e7fee7fb..89b288c79 100644 --- a/core/src/xmake/xmake.c +++ b/core/src/xmake/xmake.c @@ -27,31 +27,26 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static __tb_inline__ tb_bool_t xm_check_mode(tb_size_t mode) -{ +static __tb_inline__ tb_bool_t xm_check_mode(tb_size_t mode) { #ifdef __xm_debug__ - if (!(mode & TB_MODE_DEBUG)) - { + if (!(mode & TB_MODE_DEBUG)) { tb_trace_e("libxmake.a has __tb_debug__ but xmake/xmake.h not"); return tb_false; } #else - if (mode & TB_MODE_DEBUG) - { + if (mode & TB_MODE_DEBUG) { tb_trace_e("xmake/xmake.h has __tb_debug__ but libxmake.a not"); return tb_false; } #endif #ifdef __xm_small__ - if (!(mode & TB_MODE_SMALL)) - { + if (!(mode & TB_MODE_SMALL)) { tb_trace_e("libxmake.a has __tb_small__ but xmake/xmake.h not"); return tb_false; } #else - if (mode & TB_MODE_SMALL) - { + if (mode & TB_MODE_SMALL) { tb_trace_e("xmake/xmake.h has __tb_small__ but libxmake.a not"); return tb_false; } @@ -60,19 +55,16 @@ static __tb_inline__ tb_bool_t xm_check_mode(tb_size_t mode) // ok return tb_true; } -static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build) -{ +static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build) { // the version oly for link the static vtag string - tb_version_t const* version = xm_version(); tb_used(version); + tb_version_t const *version = xm_version(); + tb_used(version); // ok - if ((build / 100) == (XM_VERSION_BUILD / 100)) - { + if ((build / 100) == (XM_VERSION_BUILD / 100)) { tb_trace_d("version: %s", XM_VERSION_STRING); return tb_true; - } - else - { + } else { tb_trace_w("version: %s != %llu", XM_VERSION_STRING, build); } @@ -83,13 +75,13 @@ static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build) /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) -{ +tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) { // trace tb_trace_d("init: .."); // check mode - if (!xm_check_mode(mode)) return tb_false; + if (!xm_check_mode(mode)) + return tb_false; // check version xm_version_check(build); @@ -99,7 +91,8 @@ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) if (!tb_init(tb_null, tb_default_allocator(tb_null, 0))) return tb_false; #else // init tbox, since small compilation mode is enabled, it still uses the native allocator - if (!tb_init(tb_null, tb_null)) return tb_false; + if (!tb_init(tb_null, tb_null)) + return tb_false; #endif // trace @@ -108,20 +101,18 @@ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) // ok return tb_true; } -tb_void_t xm_exit() -{ +tb_void_t xm_exit() { // exit tbox tb_exit(); } -tb_version_t const* xm_version() -{ +tb_version_t const *xm_version() { // init version tag for binary search - static __tb_volatile__ tb_char_t const* s_vtag = "[xmake]: [vtag]: " XM_VERSION_STRING; tb_used(s_vtag); + static __tb_volatile__ tb_char_t const *s_vtag = "[xmake]: [vtag]: " XM_VERSION_STRING; + tb_used(s_vtag); // init version - static tb_version_t s_version = {0}; - if (!s_version.major) - { + static tb_version_t s_version = { 0 }; + if (!s_version.major) { s_version.major = XM_VERSION_MAJOR; s_version.minor = XM_VERSION_MINOR; s_version.alter = XM_VERSION_ALTER; @@ -130,4 +121,3 @@ tb_version_t const* xm_version() return &s_version; } - diff --git a/core/src/xmake/xmake.h b/core/src/xmake/xmake.h index 0d4c5bfcd..bdca229f7 100644 --- a/core/src/xmake/xmake.h +++ b/core/src/xmake/xmake.h @@ -37,15 +37,15 @@ __tb_extern_c_enter__ */ #ifdef __xm_debug__ -# define __xm_mode_debug__ TB_MODE_DEBUG +#define __xm_mode_debug__ TB_MODE_DEBUG #else -# define __xm_mode_debug__ (0) +#define __xm_mode_debug__ (0) #endif #ifdef __xm_small__ -# define __xm_mode_small__ TB_MODE_SMALL +#define __xm_mode_small__ TB_MODE_SMALL #else -# define __xm_mode_small__ (0) +#define __xm_mode_small__ (0) #endif /*! init xmake @@ -67,7 +67,7 @@ __tb_extern_c_enter__ } * @endcode */ -#define xm_init() xm_init_((tb_size_t)(__xm_mode_debug__ | __xm_mode_small__), XM_VERSION_BUILD) +#define xm_init() xm_init_((tb_size_t)(__xm_mode_debug__ | __xm_mode_small__), XM_VERSION_BUILD) /* ////////////////////////////////////////////////////////////////////////////////////// * interfaces @@ -80,16 +80,17 @@ __tb_extern_c_enter__ * * @return tb_true or tb_false */ -tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build); +tb_bool_t +xm_init_(tb_size_t mode, tb_hize_t build); /// exit the xmake library -tb_void_t xm_exit(tb_noarg_t); +tb_void_t xm_exit(tb_noarg_t); /*! the xmake version * * @return the xmake version */ -tb_version_t const* xm_version(tb_noarg_t); +tb_version_t const *xm_version(tb_noarg_t); /* ////////////////////////////////////////////////////////////////////////////////////// * extern -- cgit v1.3.1 From 39189e3a1bd2979b7b454547b03e5926a8027431 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 19:54:35 +0800 Subject: remove unused comments --- core/src/xmake/base64/decode.c | 1 - core/src/xmake/base64/encode.c | 1 - core/src/xmake/bloom_filter/bloom_filter_clear.c | 1 - core/src/xmake/bloom_filter/bloom_filter_close.c | 1 - core/src/xmake/bloom_filter/bloom_filter_data.c | 1 - .../src/xmake/bloom_filter/bloom_filter_data_set.c | 1 - core/src/xmake/bloom_filter/bloom_filter_get.c | 1 - core/src/xmake/bloom_filter/bloom_filter_open.c | 1 - core/src/xmake/bloom_filter/bloom_filter_set.c | 1 - core/src/xmake/bloom_filter/bloom_filter_size.c | 1 - core/src/xmake/engine.c | 24 ---------------------- core/src/xmake/fwatcher/add.c | 1 - core/src/xmake/fwatcher/close.c | 1 - core/src/xmake/fwatcher/open.c | 1 - core/src/xmake/fwatcher/remove.c | 1 - core/src/xmake/fwatcher/wait.c | 1 - core/src/xmake/hash/md5.c | 2 -- core/src/xmake/hash/rand128.c | 1 - core/src/xmake/hash/rand32.c | 1 - core/src/xmake/hash/rand64.c | 1 - core/src/xmake/hash/sha.c | 2 -- core/src/xmake/hash/uuid4.c | 1 - core/src/xmake/hash/xxhash.c | 2 -- core/src/xmake/io/file_close.c | 4 ---- core/src/xmake/io/file_flush.c | 2 -- core/src/xmake/io/file_isatty.c | 1 - core/src/xmake/io/file_open.c | 4 ---- core/src/xmake/io/file_rawfd.c | 1 - core/src/xmake/io/file_read.c | 13 ------------ core/src/xmake/io/file_readable.c | 1 - core/src/xmake/io/file_seek.c | 1 - core/src/xmake/io/file_size.c | 1 - core/src/xmake/io/file_write.c | 4 ---- core/src/xmake/io/filelock_close.c | 2 -- core/src/xmake/io/filelock_lock.c | 1 - core/src/xmake/io/filelock_open.c | 1 - core/src/xmake/io/filelock_trylock.c | 1 - core/src/xmake/io/filelock_unlock.c | 1 - core/src/xmake/io/pipe_close.c | 1 - core/src/xmake/io/pipe_connect.c | 1 - core/src/xmake/io/pipe_open.c | 1 - core/src/xmake/io/pipe_openpair.c | 1 - core/src/xmake/io/pipe_read.c | 1 - core/src/xmake/io/pipe_wait.c | 1 - core/src/xmake/io/pipe_write.c | 1 - core/src/xmake/io/poller_insert.c | 1 - core/src/xmake/io/poller_modify.c | 1 - core/src/xmake/io/poller_remove.c | 1 - core/src/xmake/io/poller_spank.c | 1 - core/src/xmake/io/poller_support.c | 1 - core/src/xmake/io/poller_wait.c | 3 --- core/src/xmake/io/socket_accept.c | 1 - core/src/xmake/io/socket_bind.c | 1 - core/src/xmake/io/socket_close.c | 1 - core/src/xmake/io/socket_connect.c | 1 - core/src/xmake/io/socket_ctrl.c | 1 - core/src/xmake/io/socket_kill.c | 1 - core/src/xmake/io/socket_listen.c | 1 - core/src/xmake/io/socket_open.c | 1 - core/src/xmake/io/socket_peeraddr.c | 1 - core/src/xmake/io/socket_rawfd.c | 1 - core/src/xmake/io/socket_recv.c | 1 - core/src/xmake/io/socket_recvfrom.c | 1 - core/src/xmake/io/socket_send.c | 1 - core/src/xmake/io/socket_sendfile.c | 1 - core/src/xmake/io/socket_sendto.c | 1 - core/src/xmake/io/socket_wait.c | 1 - core/src/xmake/io/stdfile.c | 1 - core/src/xmake/libc/byteof.c | 1 - core/src/xmake/libc/dataptr.c | 1 - core/src/xmake/libc/free.c | 1 - core/src/xmake/libc/malloc.c | 1 - core/src/xmake/libc/memcpy.c | 1 - core/src/xmake/libc/memmov.c | 1 - core/src/xmake/libc/memset.c | 1 - core/src/xmake/libc/setbyte.c | 1 - core/src/xmake/libc/strndup.c | 1 - core/src/xmake/lz4/block_compress.c | 1 - core/src/xmake/lz4/block_decompress.c | 1 - core/src/xmake/lz4/compress.c | 1 - core/src/xmake/lz4/compress_file.c | 2 -- core/src/xmake/lz4/compress_stream_close.c | 1 - core/src/xmake/lz4/compress_stream_open.c | 1 - core/src/xmake/lz4/compress_stream_read.c | 1 - core/src/xmake/lz4/compress_stream_write.c | 1 - core/src/xmake/lz4/decompress.c | 1 - core/src/xmake/lz4/decompress_file.c | 2 -- core/src/xmake/lz4/decompress_stream_close.c | 1 - core/src/xmake/lz4/decompress_stream_open.c | 1 - core/src/xmake/lz4/decompress_stream_read.c | 1 - core/src/xmake/lz4/decompress_stream_write.c | 1 - core/src/xmake/lz4/prefix.h | 4 ---- core/src/xmake/os/args.c | 2 -- core/src/xmake/os/argv.c | 1 - core/src/xmake/os/chdir.c | 2 -- core/src/xmake/os/cpdir.c | 1 - core/src/xmake/os/cpfile.c | 1 - core/src/xmake/os/cpuinfo.c | 1 - core/src/xmake/os/curdir.c | 1 - core/src/xmake/os/emptydir.c | 2 -- core/src/xmake/os/exists.c | 1 - core/src/xmake/os/filesize.c | 1 - core/src/xmake/os/find.c | 6 ------ core/src/xmake/os/fscase.c | 1 - core/src/xmake/os/getenv.c | 2 -- core/src/xmake/os/getenvs.c | 3 --- core/src/xmake/os/getown.c | 2 -- core/src/xmake/os/getpid.c | 1 - core/src/xmake/os/getwinsize.c | 2 -- core/src/xmake/os/gid.c | 2 -- core/src/xmake/os/isdir.c | 1 - core/src/xmake/os/isfile.c | 1 - core/src/xmake/os/islink.c | 1 - core/src/xmake/os/link.c | 2 -- core/src/xmake/os/mclock.c | 2 -- core/src/xmake/os/meminfo.c | 1 - core/src/xmake/os/mkdir.c | 2 -- core/src/xmake/os/mtime.c | 1 - core/src/xmake/os/readlink.c | 2 -- core/src/xmake/os/rename.c | 1 - core/src/xmake/os/rmdir.c | 6 ------ core/src/xmake/os/rmfile.c | 1 - core/src/xmake/os/setenv.c | 1 - core/src/xmake/os/signal.c | 1 - core/src/xmake/os/strerror.c | 1 - core/src/xmake/os/syserror.c | 1 - core/src/xmake/os/tmpdir.c | 1 - core/src/xmake/os/touch.c | 1 - core/src/xmake/os/uid.c | 2 -- core/src/xmake/package/loadxmi.c | 1 - core/src/xmake/path/absolute.c | 1 - core/src/xmake/path/directory.c | 1 - core/src/xmake/path/is_absolute.c | 1 - core/src/xmake/path/relative.c | 1 - core/src/xmake/path/translate.c | 1 - core/src/xmake/process/close.c | 1 - core/src/xmake/process/kill.c | 1 - core/src/xmake/process/open.c | 1 - core/src/xmake/process/openv.c | 2 -- core/src/xmake/process/wait.c | 2 -- core/src/xmake/readline/add_history.c | 2 -- core/src/xmake/readline/clear_history.c | 2 -- core/src/xmake/readline/history_list.c | 2 -- core/src/xmake/readline/readline.c | 2 -- core/src/xmake/sandbox/interactive.c | 6 ------ core/src/xmake/semver/compare.c | 2 -- core/src/xmake/semver/parse.c | 2 -- core/src/xmake/semver/satisfies.c | 1 - core/src/xmake/semver/select.c | 3 --- core/src/xmake/semver/semver.c | 1 - core/src/xmake/string/convert.c | 2 -- core/src/xmake/string/endswith.c | 2 -- core/src/xmake/string/lastof.c | 1 - core/src/xmake/string/split.c | 1 - core/src/xmake/string/startswith.c | 2 -- core/src/xmake/string/trim.c | 5 ----- core/src/xmake/thread/thread_exit.c | 1 - core/src/xmake/thread/thread_init.c | 1 - core/src/xmake/thread/thread_resume.c | 1 - core/src/xmake/thread/thread_suspend.c | 1 - core/src/xmake/thread/thread_wait.c | 1 - core/src/xmake/tty/term_mode.c | 1 - core/src/xmake/utils/bin2c.c | 1 - core/src/xmake/winos/ansi.c | 6 ------ core/src/xmake/winos/logical_drives.c | 1 - core/src/xmake/winos/registry_keys.c | 2 -- core/src/xmake/winos/registry_query.c | 2 -- core/src/xmake/winos/registry_values.c | 3 --- core/src/xmake/winos/short_path.c | 1 - core/src/xmake/xmake.c | 5 ----- 170 files changed, 285 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/base64/decode.c b/core/src/xmake/base64/decode.c index 41555f5cc..cb1b7eb82 100644 --- a/core/src/xmake/base64/decode.c +++ b/core/src/xmake/base64/decode.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_base64_decode(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the string diff --git a/core/src/xmake/base64/encode.c b/core/src/xmake/base64/encode.c index cf2135e56..d896cb55e 100644 --- a/core/src/xmake/base64/encode.c +++ b/core/src/xmake/base64/encode.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_base64_encode(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/bloom_filter/bloom_filter_clear.c b/core/src/xmake/bloom_filter/bloom_filter_clear.c index 3f6e36bd0..2657cc5dc 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_clear.c +++ b/core/src/xmake/bloom_filter/bloom_filter_clear.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_clear(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_close.c b/core/src/xmake/bloom_filter/bloom_filter_close.c index 5c916b460..59d3e59a1 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_close.c +++ b/core/src/xmake/bloom_filter/bloom_filter_close.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_data.c b/core/src/xmake/bloom_filter/bloom_filter_data.c index e37aea966..9d6f34e64 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_data(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_data_set.c b/core/src/xmake/bloom_filter/bloom_filter_data_set.c index a6949d730..984ec6562 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data_set.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data_set.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_data_set(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_get.c b/core/src/xmake/bloom_filter/bloom_filter_get.c index 755446a09..dd1f8d1e6 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_get.c +++ b/core/src/xmake/bloom_filter/bloom_filter_get.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_get(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_open.c b/core/src/xmake/bloom_filter/bloom_filter_open.c index 68af8ae92..be364be91 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_open.c +++ b/core/src/xmake/bloom_filter/bloom_filter_open.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get arguments diff --git a/core/src/xmake/bloom_filter/bloom_filter_set.c b/core/src/xmake/bloom_filter/bloom_filter_set.c index 9387d5354..51d85d0a7 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_set.c +++ b/core/src/xmake/bloom_filter/bloom_filter_set.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_set(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/bloom_filter/bloom_filter_size.c b/core/src/xmake/bloom_filter/bloom_filter_size.c index 219035fe7..977b455f3 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_size.c +++ b/core/src/xmake/bloom_filter/bloom_filter_size.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_bloom_filter_size(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index a65395423..7a07d72da 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -705,7 +705,6 @@ static tb_byte_t g_xmake_xmz_data[] = { * private implementation */ static tb_bool_t xm_engine_save_arguments(xm_engine_t *engine, tb_int_t argc, tb_char_t **argv, tb_char_t **taskargv) { - // check tb_assert_and_check_return_val(engine && engine->lua && argc >= 1 && argv, tb_false); #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) @@ -745,7 +744,6 @@ static tb_bool_t xm_engine_save_arguments(xm_engine_t *engine, tb_int_t argc, tb } static tb_bool_t xm_engine_get_program_file(xm_engine_t *engine, tb_char_t **argv, tb_char_t *path, tb_size_t maxn) { - // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); /* we cache it, because the current path will be changed in thread. @@ -774,13 +772,11 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t *engine, tb_char_t **arg tb_wchar_t buf[TB_PATH_MAXN] = { 0 }; tb_size_t size = (tb_size_t)GetModuleFileNameW(tb_null, buf, (DWORD)TB_PATH_MAXN); tb_assert_and_check_break(size < TB_PATH_MAXN); - // end buf[size] = L'\0'; size = tb_wcstombs(path, buf, maxn); tb_assert_and_check_break(size < maxn); path[size] = '\0'; - // ok ok = tb_true; #elif defined(TB_CONFIG_OS_MACOSX) || defined(TB_CONFIG_OS_IOS) @@ -855,9 +851,7 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t *engine, tb_char_t **arg } while (0); - // ok? if (ok) { - // trace tb_trace_d("programfile: %s", path); // cache it @@ -894,7 +888,6 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, tb_char_t *path, tb_size_t maxn, tb_char_t const *programfile) { - // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); static tb_char_t s_program_directory[TB_PATH_MAXN] = { 0 }; @@ -980,9 +973,7 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, } while (0); - // ok? if (ok) { - // trace tb_trace_d("programdir: %s", path); // cache it @@ -993,12 +984,10 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, lua_setglobal(engine->lua, "_PROGRAM_DIR"); } - // ok? return ok; } static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t *path, tb_size_t maxn) { - // check tb_assert_and_check_return_val(engine && path && maxn, tb_false); tb_bool_t ok = tb_false; @@ -1011,14 +1000,12 @@ static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t break; } - // trace tb_trace_d("project: %s", path); // save the directory to the global variable: _PROJECT_DIR lua_pushstring(engine->lua, path); lua_setglobal(engine->lua, "_PROJECT_DIR"); - // ok ok = tb_true; } while (0); @@ -1027,7 +1014,6 @@ static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t if (!ok) tb_printf("error: not found the project directory!\n"); - // ok? return ok; } @@ -1061,7 +1047,6 @@ static tb_void_t xm_engine_signal_handler(tb_int_t signo) { #endif static tb_void_t xm_engine_init_host(xm_engine_t *engine) { - // check tb_assert_and_check_return(engine && engine->lua); // init system host @@ -1146,7 +1131,6 @@ static __tb_inline__ tb_char_t const *xm_engine_xmake_arch() { } static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { - // check tb_assert_and_check_return(engine && engine->lua); // init xmake arch @@ -1225,7 +1209,6 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { } static tb_void_t xm_engine_init_features(xm_engine_t *engine) { - // check tb_assert_and_check_return(engine && engine->lua); // init features @@ -1660,7 +1643,6 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c return (xm_engine_ref_t)engine; } tb_void_t xm_engine_exit(xm_engine_ref_t self) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine); @@ -1678,7 +1660,6 @@ tb_void_t xm_engine_exit(xm_engine_ref_t self) { tb_free(engine); } tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, tb_char_t **taskargv) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine && engine->lua, -1); @@ -1719,7 +1700,6 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, t return -1; } - // trace tb_trace_d("main: %s", path); // load and execute the main script @@ -1741,7 +1721,6 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, t return (tb_int_t)lua_tonumber(engine->lua, -1); } tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const *module, luaL_Reg const funcs[]) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine && engine->lua && module && funcs); @@ -1753,7 +1732,6 @@ tb_void_t xm_engine_register(xm_engine_ref_t self, tb_char_t const *module, luaL } #ifdef XM_EMBED_ENABLE tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const *data, tb_size_t size) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return(engine && engine->embedcount < tb_arrayn(engine->embedsize) && data && size); @@ -1763,14 +1741,12 @@ tb_void_t xm_engine_add_embedfiles(xm_engine_ref_t self, tb_byte_t const *data, } #endif lua_State *xm_engine_lua(xm_engine_ref_t self) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine, tb_null); return engine->lua; } tb_poller_ref_t xm_engine_poller(xm_engine_ref_t self) { - // check xm_engine_t *engine = (xm_engine_t *)self; tb_assert_and_check_return_val(engine, tb_null); diff --git a/core/src/xmake/fwatcher/add.c b/core/src/xmake/fwatcher/add.c index cda233104..77c23ea48 100644 --- a/core/src/xmake/fwatcher/add.c +++ b/core/src/xmake/fwatcher/add.c @@ -36,7 +36,6 @@ // fwatcher.add(watchdir, recursion) tb_int_t xm_fwatcher_add(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/fwatcher/close.c b/core/src/xmake/fwatcher/close.c index 8f6a680be..a5501d906 100644 --- a/core/src/xmake/fwatcher/close.c +++ b/core/src/xmake/fwatcher/close.c @@ -36,7 +36,6 @@ // fwatcher.close(p) tb_int_t xm_fwatcher_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/fwatcher/open.c b/core/src/xmake/fwatcher/open.c index 05173660e..13ab91d5a 100644 --- a/core/src/xmake/fwatcher/open.c +++ b/core/src/xmake/fwatcher/open.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_fwatcher_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init fwatcher diff --git a/core/src/xmake/fwatcher/remove.c b/core/src/xmake/fwatcher/remove.c index d7ef4d289..6285b0649 100644 --- a/core/src/xmake/fwatcher/remove.c +++ b/core/src/xmake/fwatcher/remove.c @@ -36,7 +36,6 @@ // fwatcher.remove(watchdir) tb_int_t xm_fwatcher_remove(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/fwatcher/wait.c b/core/src/xmake/fwatcher/wait.c index d4e64347f..42b01b8aa 100644 --- a/core/src/xmake/fwatcher/wait.c +++ b/core/src/xmake/fwatcher/wait.c @@ -36,7 +36,6 @@ // fwatcher.wait(p) tb_int_t xm_fwatcher_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/hash/md5.c b/core/src/xmake/hash/md5.c index 91f7eafc9..3c871b063 100644 --- a/core/src/xmake/hash/md5.c +++ b/core/src/xmake/hash/md5.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_md5(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is bytes? get data and size @@ -81,7 +80,6 @@ tb_int_t xm_hash_md5(lua_State *lua) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); - // ok? if (real > 0) tb_md5_spak(&md5, data, real); // no data? continue it diff --git a/core/src/xmake/hash/rand128.c b/core/src/xmake/hash/rand128.c index bb844aee9..625e75326 100644 --- a/core/src/xmake/hash/rand128.c +++ b/core/src/xmake/hash/rand128.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_rand128(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); static union { diff --git a/core/src/xmake/hash/rand32.c b/core/src/xmake/hash/rand32.c index a8a2dc054..844dd83e7 100644 --- a/core/src/xmake/hash/rand32.c +++ b/core/src/xmake/hash/rand32.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_rand32(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); static tb_uint64_t s_seed = 0; diff --git a/core/src/xmake/hash/rand64.c b/core/src/xmake/hash/rand64.c index 05b861327..0f9e39069 100644 --- a/core/src/xmake/hash/rand64.c +++ b/core/src/xmake/hash/rand64.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_rand64(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); static union { diff --git a/core/src/xmake/hash/sha.c b/core/src/xmake/hash/sha.c index 12d98b860..158a09208 100644 --- a/core/src/xmake/hash/sha.c +++ b/core/src/xmake/hash/sha.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_sha(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get mode @@ -88,7 +87,6 @@ tb_int_t xm_hash_sha(lua_State *lua) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); - // ok? if (real > 0) tb_sha_spak(&sha, data, real); // no data? continue it diff --git a/core/src/xmake/hash/uuid4.c b/core/src/xmake/hash/uuid4.c index d99e849d8..8712e9efa 100644 --- a/core/src/xmake/hash/uuid4.c +++ b/core/src/xmake/hash/uuid4.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_hash_uuid4(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the name diff --git a/core/src/xmake/hash/xxhash.c b/core/src/xmake/hash/xxhash.c index 49e1199e8..7a55ce63d 100644 --- a/core/src/xmake/hash/xxhash.c +++ b/core/src/xmake/hash/xxhash.c @@ -38,7 +38,6 @@ * implementation */ tb_int_t xm_hash_xxhash(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get mode @@ -115,7 +114,6 @@ tb_int_t xm_hash_xxhash(lua_State *lua) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); - // ok? if (real > 0) { if (mode == 32 || mode == 64) XM_XXH3_64bits_update(state, data, real); diff --git a/core/src/xmake/io/file_close.c b/core/src/xmake/io/file_close.c index e00946dd0..6547b8156 100644 --- a/core/src/xmake/io/file_close.c +++ b/core/src/xmake/io/file_close.c @@ -36,7 +36,6 @@ // io.file_close(file) tb_int_t xm_io_file_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? @@ -49,7 +48,6 @@ tb_int_t xm_io_file_close(lua_State *lua) { // close file if (xm_io_file_is_file(file)) { - // check tb_assert(file->u.file_ref); #ifdef TB_CONFIG_OS_WINDOWS @@ -90,7 +88,6 @@ tb_int_t xm_io_file_close(lua_State *lua) { // gc will free it if no any refs for lua_newuserdata() // ... - // ok lua_pushboolean(lua, tb_true); return 1; } else // for stdfile (gc/close) @@ -102,7 +99,6 @@ tb_int_t xm_io_file_close(lua_State *lua) { // gc will free it if no any refs for lua_newuserdata() // ... - // ok lua_pushboolean(lua, tb_true); return 1; } diff --git a/core/src/xmake/io/file_flush.c b/core/src/xmake/io/file_flush.c index 5aa3e9f58..e5776a60e 100644 --- a/core/src/xmake/io/file_flush.c +++ b/core/src/xmake/io/file_flush.c @@ -39,7 +39,6 @@ static tb_bool_t xm_io_std_flush_impl(xm_io_file_t *file) { } static tb_bool_t xm_io_file_flush_impl(xm_io_file_t *file) { - // check tb_assert_and_check_return_val(xm_io_file_is_file(file), tb_false); #ifdef TB_CONFIG_OS_WINDOWS @@ -61,7 +60,6 @@ static tb_bool_t xm_io_file_flush_impl(xm_io_file_t *file) { // io.file_flush(file) tb_int_t xm_io_file_flush(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_isatty.c b/core/src/xmake/io/file_isatty.c index 645431398..264cabd53 100644 --- a/core/src/xmake/io/file_isatty.c +++ b/core/src/xmake/io/file_isatty.c @@ -36,7 +36,6 @@ // io.file_isatty(file) tb_int_t xm_io_file_isatty(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_open.c b/core/src/xmake/io/file_open.c index 56c0848fd..f4a080077 100644 --- a/core/src/xmake/io/file_open.c +++ b/core/src/xmake/io/file_open.c @@ -44,7 +44,6 @@ * private implementation */ static tb_size_t xm_io_file_detect_charset(tb_byte_t const **data_ptr, tb_long_t size) { - // check tb_assert(data_ptr && *data_ptr); tb_byte_t const *data = *data_ptr; @@ -142,7 +141,6 @@ static tb_size_t xm_io_file_detect_charset(tb_byte_t const **data_ptr, tb_long_t return charset; } static tb_size_t xm_io_file_detect_encoding(tb_stream_ref_t stream, tb_long_t *pbomoff) { - // check tb_assert_and_check_return_val(stream && pbomoff, XM_IO_FILE_ENCODING_BINARY); // detect encoding @@ -163,7 +161,6 @@ static tb_size_t xm_io_file_detect_encoding(tb_stream_ref_t stream, tb_long_t *p // io.file_open(path, modestr) tb_int_t xm_io_file_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get file path and mode @@ -261,7 +258,6 @@ tb_int_t xm_io_file_open(lua_State *lua) { if (bomoff > 0 && !tb_stream_seek(stream, bomoff)) break; - // ok open_ok = tb_true; } while (0); diff --git a/core/src/xmake/io/file_rawfd.c b/core/src/xmake/io/file_rawfd.c index f4dc3ffee..c94dc4a98 100644 --- a/core/src/xmake/io/file_rawfd.c +++ b/core/src/xmake/io/file_rawfd.c @@ -52,7 +52,6 @@ * e.g. set VS_UNICODE_OUTPUT=fd to enable vs unicode output, @see https://github.com/xmake-io/xmake/issues/528 */ tb_int_t xm_io_file_rawfd(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c index 2f349edb5..2be05a05a 100644 --- a/core/src/xmake/io/file_read.c +++ b/core/src/xmake/io/file_read.c @@ -44,7 +44,6 @@ typedef enum __xm_pushline_state_e { * implementation */ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_ref_t line) { - // check tb_assert_and_check_return_val(stream && line, -1); // read line and reserve crlf @@ -79,7 +78,6 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re } } - // ok? tb_size_t linesize = tb_buffer_size(line); if (linesize) return linesize; @@ -90,7 +88,6 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t *file, tb_char_t const *continuation, tb_bool_t keep_crlf) { - // check tb_assert(buf && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // is binary? @@ -166,7 +163,6 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, return result; } static tb_int_t xm_io_file_read_all_directly(lua_State *lua, xm_io_file_t *file) { - // check tb_assert(lua && file && xm_io_file_is_file(file) && file->u.file_ref); // init buffer @@ -201,7 +197,6 @@ static tb_int_t xm_io_file_read_all_directly(lua_State *lua, xm_io_file_t *file) return 1; } static tb_int_t xm_io_file_read_all(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation) { - // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // is binary? read all directly @@ -242,7 +237,6 @@ static tb_int_t xm_io_file_read_line(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_bool_t keep_crlf) { - // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // init buffer @@ -278,7 +272,6 @@ static tb_int_t xm_io_file_read_line(lua_State *lua, } static tb_int_t xm_io_file_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_long_t n) { - // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // check continuation @@ -314,7 +307,6 @@ static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t *file, tb_char_t const *continuation, tb_bool_t keep_crlf) { - // check tb_assert(buf && file && continuation && xm_io_file_is_std(file)); // get input buffer @@ -367,7 +359,6 @@ static tb_int_t xm_io_file_std_read_line(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_bool_t keep_crlf) { - // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); // init buffer @@ -403,7 +394,6 @@ static tb_int_t xm_io_file_std_read_line(lua_State *lua, } static tb_int_t xm_io_file_std_read_all(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation) { - // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); // init buffer @@ -436,7 +426,6 @@ static tb_int_t xm_io_file_std_read_all(lua_State *lua, xm_io_file_t *file, tb_c } static tb_int_t xm_io_file_std_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation, tb_long_t n) { - // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); // check continuation @@ -466,7 +455,6 @@ static tb_int_t xm_io_file_std_read_n(lua_State *lua, xm_io_file_t *file, tb_cha } static tb_int_t xm_io_file_std_read_num(lua_State *lua, xm_io_file_t *file, tb_char_t const *continuation) { - // check tb_assert(lua && file && continuation && xm_io_file_is_std(file)); // check continuation @@ -490,7 +478,6 @@ static tb_int_t xm_io_file_std_read_num(lua_State *lua, xm_io_file_t *file, tb_c * io.file_read(file, 10) */ tb_int_t xm_io_file_read(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_readable.c b/core/src/xmake/io/file_readable.c index e3cca2dc9..5f9a84329 100644 --- a/core/src/xmake/io/file_readable.c +++ b/core/src/xmake/io/file_readable.c @@ -35,7 +35,6 @@ */ tb_int_t xm_io_file_readable(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_seek.c b/core/src/xmake/io/file_seek.c index ea053302b..421e5cdf1 100644 --- a/core/src/xmake/io/file_seek.c +++ b/core/src/xmake/io/file_seek.c @@ -36,7 +36,6 @@ // io.file_seek(file, [whence [, offset]]) tb_int_t xm_io_file_seek(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_size.c b/core/src/xmake/io/file_size.c index df83a96b9..34f519306 100644 --- a/core/src/xmake/io/file_size.c +++ b/core/src/xmake/io/file_size.c @@ -36,7 +36,6 @@ // io.file_size(file) tb_int_t xm_io_file_size(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c index bfe7321f3..5f70e1a49 100644 --- a/core/src/xmake/io/file_write.c +++ b/core/src/xmake/io/file_write.c @@ -34,7 +34,6 @@ * private implementation */ static tb_void_t xm_io_file_write_file_utfbom(xm_io_file_t *file) { - // check tb_assert(file && xm_io_file_is_file(file) && file->u.file_ref); // write bom @@ -60,7 +59,6 @@ static tb_void_t xm_io_file_write_file_directly(xm_io_file_t *file, tb_byte_t co tb_stream_bwrit(file->u.file_ref, data, size); } static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t *file, tb_byte_t const *data, tb_size_t size) { - // check tb_assert(file && data && xm_io_file_is_file(file) && file->u.file_ref); #ifdef TB_CONFIG_OS_WINDOWS @@ -105,7 +103,6 @@ static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t *file, tb_byte_t c #endif } static tb_void_t xm_io_file_write_std(xm_io_file_t *file, tb_byte_t const *data, tb_size_t size) { - // check tb_assert(file && data && xm_io_file_is_std(file)); // check type @@ -122,7 +119,6 @@ static tb_void_t xm_io_file_write_std(xm_io_file_t *file, tb_byte_t const *data, // io.file_write(file, ...) tb_int_t xm_io_file_write(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is user data? diff --git a/core/src/xmake/io/filelock_close.c b/core/src/xmake/io/filelock_close.c index ad628cb5c..02a2fb039 100644 --- a/core/src/xmake/io/filelock_close.c +++ b/core/src/xmake/io/filelock_close.c @@ -36,7 +36,6 @@ // io.filelock_close(lock) tb_int_t xm_io_filelock_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check lock? @@ -53,6 +52,5 @@ tb_int_t xm_io_filelock_close(lua_State *lua) { // save result: ok lua_pushboolean(lua, tb_true); - // ok return 1; } diff --git a/core/src/xmake/io/filelock_lock.c b/core/src/xmake/io/filelock_lock.c index 109bb6dcd..9e0c2493e 100644 --- a/core/src/xmake/io/filelock_lock.c +++ b/core/src/xmake/io/filelock_lock.c @@ -40,7 +40,6 @@ * shared lock: io.filelock_lock(lock, "/xxxx/filelock", {shared = true}) */ tb_int_t xm_io_filelock_lock(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get option argument diff --git a/core/src/xmake/io/filelock_open.c b/core/src/xmake/io/filelock_open.c index 171c6c86a..e9687ba54 100644 --- a/core/src/xmake/io/filelock_open.c +++ b/core/src/xmake/io/filelock_open.c @@ -38,7 +38,6 @@ * io.filelock_open(path) */ tb_int_t xm_io_filelock_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get file path diff --git a/core/src/xmake/io/filelock_trylock.c b/core/src/xmake/io/filelock_trylock.c index d1a204d30..aaf1da246 100644 --- a/core/src/xmake/io/filelock_trylock.c +++ b/core/src/xmake/io/filelock_trylock.c @@ -40,7 +40,6 @@ * shared lock: io.filelock_trylock("/xxxx/filelock", {shared = true}) */ tb_int_t xm_io_filelock_trylock(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get option argument diff --git a/core/src/xmake/io/filelock_unlock.c b/core/src/xmake/io/filelock_unlock.c index 0eaa2bc98..94dfe1b7d 100644 --- a/core/src/xmake/io/filelock_unlock.c +++ b/core/src/xmake/io/filelock_unlock.c @@ -36,7 +36,6 @@ // io.filelock_unlock(lock) tb_int_t xm_io_filelock_unlock(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check lock? diff --git a/core/src/xmake/io/pipe_close.c b/core/src/xmake/io/pipe_close.c index a3adb6d8c..23e200606 100644 --- a/core/src/xmake/io/pipe_close.c +++ b/core/src/xmake/io/pipe_close.c @@ -36,7 +36,6 @@ // io.pipe_close(pipe) tb_int_t xm_io_pipe_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe? diff --git a/core/src/xmake/io/pipe_connect.c b/core/src/xmake/io/pipe_connect.c index 985817386..f13f612f9 100644 --- a/core/src/xmake/io/pipe_connect.c +++ b/core/src/xmake/io/pipe_connect.c @@ -36,7 +36,6 @@ // io.pipe_connect(pipefile) tb_int_t xm_io_pipe_connect(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe diff --git a/core/src/xmake/io/pipe_open.c b/core/src/xmake/io/pipe_open.c index d0dbe66e9..d82406dee 100644 --- a/core/src/xmake/io/pipe_open.c +++ b/core/src/xmake/io/pipe_open.c @@ -38,7 +38,6 @@ * io.pipe_open(name, mode, buffsize) */ tb_int_t xm_io_pipe_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get pipe name and mode diff --git a/core/src/xmake/io/pipe_openpair.c b/core/src/xmake/io/pipe_openpair.c index c95d13a62..dd2205613 100644 --- a/core/src/xmake/io/pipe_openpair.c +++ b/core/src/xmake/io/pipe_openpair.c @@ -38,7 +38,6 @@ * io.pipe_openpair(mode, buffsize) */ tb_int_t xm_io_pipe_openpair(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get pipe mode diff --git a/core/src/xmake/io/pipe_read.c b/core/src/xmake/io/pipe_read.c index fb82c1ebd..637fb3b7d 100644 --- a/core/src/xmake/io/pipe_read.c +++ b/core/src/xmake/io/pipe_read.c @@ -36,7 +36,6 @@ // real, data_or_errors = io.pipe_read(pipefile, size) tb_int_t xm_io_pipe_read(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe file diff --git a/core/src/xmake/io/pipe_wait.c b/core/src/xmake/io/pipe_wait.c index 67d189892..785efe950 100644 --- a/core/src/xmake/io/pipe_wait.c +++ b/core/src/xmake/io/pipe_wait.c @@ -36,7 +36,6 @@ // io.pipe_wait(pipefile, events, timeout) tb_int_t xm_io_pipe_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe? diff --git a/core/src/xmake/io/pipe_write.c b/core/src/xmake/io/pipe_write.c index 9b0869299..2f2865c47 100644 --- a/core/src/xmake/io/pipe_write.c +++ b/core/src/xmake/io/pipe_write.c @@ -36,7 +36,6 @@ // io.pipe_write(pipefile, data, start, last) tb_int_t xm_io_pipe_write(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check pipe diff --git a/core/src/xmake/io/poller_insert.c b/core/src/xmake/io/poller_insert.c index 2b24b3b1e..81f66cce9 100644 --- a/core/src/xmake/io/poller_insert.c +++ b/core/src/xmake/io/poller_insert.c @@ -37,7 +37,6 @@ // io.poller_insert(obj:otype(), obj:cdata(), events) tb_int_t xm_io_poller_insert(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/poller_modify.c b/core/src/xmake/io/poller_modify.c index 77dff2fbf..f9283aecb 100644 --- a/core/src/xmake/io/poller_modify.c +++ b/core/src/xmake/io/poller_modify.c @@ -37,7 +37,6 @@ // io.poller_modify(obj:otype(), obj:cdata(), events) tb_int_t xm_io_poller_modify(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/poller_remove.c b/core/src/xmake/io/poller_remove.c index 34242808f..3127bf2b4 100644 --- a/core/src/xmake/io/poller_remove.c +++ b/core/src/xmake/io/poller_remove.c @@ -37,7 +37,6 @@ // io.poller_remove(obj:otype(), obj) tb_int_t xm_io_poller_remove(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/poller_spank.c b/core/src/xmake/io/poller_spank.c index 1656a537e..7fdb38605 100644 --- a/core/src/xmake/io/poller_spank.c +++ b/core/src/xmake/io/poller_spank.c @@ -37,7 +37,6 @@ // io.poller_spank() tb_int_t xm_io_poller_spank(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // spank the poller, break the tb_poller_wait() and return all events diff --git a/core/src/xmake/io/poller_support.c b/core/src/xmake/io/poller_support.c index d53cdc1ed..d63f8da34 100644 --- a/core/src/xmake/io/poller_support.c +++ b/core/src/xmake/io/poller_support.c @@ -37,7 +37,6 @@ // io.poller_support(events) tb_int_t xm_io_poller_support(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get events diff --git a/core/src/xmake/io/poller_wait.c b/core/src/xmake/io/poller_wait.c index 141c4640b..f1e4ed7a7 100644 --- a/core/src/xmake/io/poller_wait.c +++ b/core/src/xmake/io/poller_wait.c @@ -38,7 +38,6 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, tb_poller_object_ref_t object, tb_long_t events, tb_cpointer_t priv) { - // check xm_poller_state_t *state = (xm_poller_state_t *)tb_poller_priv(poller); tb_assert_and_check_return(state && state->lua); @@ -76,7 +75,6 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, // local events, count = io.poller_wait(timeout) tb_int_t xm_io_poller_wait(lua_State *lua) { - // check tb_poller_ref_t poller = xm_io_poller(lua); tb_assert_and_check_return_val(poller && lua, 0); @@ -101,7 +99,6 @@ tb_int_t xm_io_poller_wait(lua_State *lua) { return 2; } - // failed lua_pop(lua, 1); lua_pushnil(lua); lua_pushinteger(lua, -1); diff --git a/core/src/xmake/io/socket_accept.c b/core/src/xmake/io/socket_accept.c index 5a303ef74..77a6c6c86 100644 --- a/core/src/xmake/io/socket_accept.c +++ b/core/src/xmake/io/socket_accept.c @@ -36,7 +36,6 @@ // local sock = io.socket_accept(sock) tb_int_t xm_io_socket_accept(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_bind.c b/core/src/xmake/io/socket_bind.c index 9ba441a6f..d1a30789a 100644 --- a/core/src/xmake/io/socket_bind.c +++ b/core/src/xmake/io/socket_bind.c @@ -36,7 +36,6 @@ // io.socket_bind(sock, addr, port, family) tb_int_t xm_io_socket_bind(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_close.c b/core/src/xmake/io/socket_close.c index d53228fe7..922987c10 100644 --- a/core/src/xmake/io/socket_close.c +++ b/core/src/xmake/io/socket_close.c @@ -36,7 +36,6 @@ // io.socket_close(sock) tb_int_t xm_io_socket_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_connect.c b/core/src/xmake/io/socket_connect.c index 63d355fb4..94c2f1e8d 100644 --- a/core/src/xmake/io/socket_connect.c +++ b/core/src/xmake/io/socket_connect.c @@ -36,7 +36,6 @@ // io.socket_connect(sock, addr, port, family) tb_int_t xm_io_socket_connect(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_ctrl.c b/core/src/xmake/io/socket_ctrl.c index c16f2c20d..0a51d65bc 100644 --- a/core/src/xmake/io/socket_ctrl.c +++ b/core/src/xmake/io/socket_ctrl.c @@ -36,7 +36,6 @@ // io.socket_ctrl(sock, code, value) tb_int_t xm_io_socket_ctrl(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_kill.c b/core/src/xmake/io/socket_kill.c index eb2956e53..63e110257 100644 --- a/core/src/xmake/io/socket_kill.c +++ b/core/src/xmake/io/socket_kill.c @@ -36,7 +36,6 @@ // local sock = io.socket_kill(sock) tb_int_t xm_io_socket_kill(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_listen.c b/core/src/xmake/io/socket_listen.c index 6fece6087..3aa541016 100644 --- a/core/src/xmake/io/socket_listen.c +++ b/core/src/xmake/io/socket_listen.c @@ -36,7 +36,6 @@ // io.socket_listen(sock, backlog) tb_int_t xm_io_socket_listen(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_open.c b/core/src/xmake/io/socket_open.c index 4189607c7..cae80d182 100644 --- a/core/src/xmake/io/socket_open.c +++ b/core/src/xmake/io/socket_open.c @@ -38,7 +38,6 @@ * io.socket_open(socktype, family) */ tb_int_t xm_io_socket_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get socket type diff --git a/core/src/xmake/io/socket_peeraddr.c b/core/src/xmake/io/socket_peeraddr.c index bcc03c289..e1ad43931 100644 --- a/core/src/xmake/io/socket_peeraddr.c +++ b/core/src/xmake/io/socket_peeraddr.c @@ -44,7 +44,6 @@ /* io.socket_peeraddr(sock) */ tb_int_t xm_io_socket_peeraddr(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_rawfd.c b/core/src/xmake/io/socket_rawfd.c index 672a9dafa..6340c0c19 100644 --- a/core/src/xmake/io/socket_rawfd.c +++ b/core/src/xmake/io/socket_rawfd.c @@ -44,7 +44,6 @@ /* io.socket_rawfd(sock) */ tb_int_t xm_io_socket_rawfd(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/io/socket_recv.c b/core/src/xmake/io/socket_recv.c index cecdbb031..ed629a8f5 100644 --- a/core/src/xmake/io/socket_recv.c +++ b/core/src/xmake/io/socket_recv.c @@ -36,7 +36,6 @@ // real, data_or_errors = io.socket_recv(sock, size) tb_int_t xm_io_socket_recv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_recvfrom.c b/core/src/xmake/io/socket_recvfrom.c index bc8f53bf8..8601f6302 100644 --- a/core/src/xmake/io/socket_recvfrom.c +++ b/core/src/xmake/io/socket_recvfrom.c @@ -36,7 +36,6 @@ // real, data_or_errors, addr, port = io.socket_recvfrom(sock, size) tb_int_t xm_io_socket_recvfrom(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_send.c b/core/src/xmake/io/socket_send.c index 1b99d8d08..d83b02add 100644 --- a/core/src/xmake/io/socket_send.c +++ b/core/src/xmake/io/socket_send.c @@ -36,7 +36,6 @@ // io.socket_send(sock, data, start, last) tb_int_t xm_io_socket_send(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_sendfile.c b/core/src/xmake/io/socket_sendfile.c index b5e6e10d6..0d4be4219 100644 --- a/core/src/xmake/io/socket_sendfile.c +++ b/core/src/xmake/io/socket_sendfile.c @@ -36,7 +36,6 @@ // io.socket_sendfile(sock, file, start, last) tb_int_t xm_io_socket_sendfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_sendto.c b/core/src/xmake/io/socket_sendto.c index cde81febf..15403d4d8 100644 --- a/core/src/xmake/io/socket_sendto.c +++ b/core/src/xmake/io/socket_sendto.c @@ -36,7 +36,6 @@ // io.socket_sendto(sock, data, addr, port) tb_int_t xm_io_socket_sendto(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket diff --git a/core/src/xmake/io/socket_wait.c b/core/src/xmake/io/socket_wait.c index fd9900e21..42674f4f9 100644 --- a/core/src/xmake/io/socket_wait.c +++ b/core/src/xmake/io/socket_wait.c @@ -36,7 +36,6 @@ // io.socket_wait(sock, events, timeout) tb_int_t xm_io_socket_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check socket? diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 05e1fcf2a..0dcb43501 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -144,7 +144,6 @@ static xm_io_file_t *xm_io_stdfile_new(lua_State *lua, tb_size_t type) { // io.stdfile(stdin: 1, stdout: 2, stderr: 3) tb_int_t xm_io_stdfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get std type diff --git a/core/src/xmake/libc/byteof.c b/core/src/xmake/libc/byteof.c index be8820ff9..dac772e9b 100644 --- a/core/src/xmake/libc/byteof.c +++ b/core/src/xmake/libc/byteof.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_byteof(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data diff --git a/core/src/xmake/libc/dataptr.c b/core/src/xmake/libc/dataptr.c index 50b063b4e..363853800 100644 --- a/core/src/xmake/libc/dataptr.c +++ b/core/src/xmake/libc/dataptr.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_dataptr(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_pointer_t data = tb_null; diff --git a/core/src/xmake/libc/free.c b/core/src/xmake/libc/free.c index ad12ccfc9..6f0d70f3d 100644 --- a/core/src/xmake/libc/free.c +++ b/core/src/xmake/libc/free.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_free(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do free diff --git a/core/src/xmake/libc/malloc.c b/core/src/xmake/libc/malloc.c index 8e2380955..faaa00e97 100644 --- a/core/src/xmake/libc/malloc.c +++ b/core/src/xmake/libc/malloc.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_malloc(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do malloc diff --git a/core/src/xmake/libc/memcpy.c b/core/src/xmake/libc/memcpy.c index 6baf66d39..e0e8b1492 100644 --- a/core/src/xmake/libc/memcpy.c +++ b/core/src/xmake/libc/memcpy.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_memcpy(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do memcpy diff --git a/core/src/xmake/libc/memmov.c b/core/src/xmake/libc/memmov.c index f43bccea6..66120e168 100644 --- a/core/src/xmake/libc/memmov.c +++ b/core/src/xmake/libc/memmov.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_memmov(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do memmov diff --git a/core/src/xmake/libc/memset.c b/core/src/xmake/libc/memset.c index 2c0936017..4f8864842 100644 --- a/core/src/xmake/libc/memset.c +++ b/core/src/xmake/libc/memset.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_memset(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do memset diff --git a/core/src/xmake/libc/setbyte.c b/core/src/xmake/libc/setbyte.c index 7ae959014..d53c30229 100644 --- a/core/src/xmake/libc/setbyte.c +++ b/core/src/xmake/libc/setbyte.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_setbyte(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data diff --git a/core/src/xmake/libc/strndup.c b/core/src/xmake/libc/strndup.c index d7d1204a0..f61cebb2c 100644 --- a/core/src/xmake/libc/strndup.c +++ b/core/src/xmake/libc/strndup.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_libc_strndup(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // do strndup diff --git a/core/src/xmake/lz4/block_compress.c b/core/src/xmake/lz4/block_compress.c index 2c7f0c00f..53b592a22 100644 --- a/core/src/xmake/lz4/block_compress.c +++ b/core/src/xmake/lz4/block_compress.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_block_compress(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/lz4/block_decompress.c b/core/src/xmake/lz4/block_decompress.c index f2f76a4bf..2a6ed1d20 100644 --- a/core/src/xmake/lz4/block_decompress.c +++ b/core/src/xmake/lz4/block_decompress.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_block_decompress(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/lz4/compress.c b/core/src/xmake/lz4/compress.c index 352945d1f..69af51113 100644 --- a/core/src/xmake/lz4/compress.c +++ b/core/src/xmake/lz4/compress.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_compress(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/lz4/compress_file.c b/core/src/xmake/lz4/compress_file.c index be48184bd..48596e17b 100644 --- a/core/src/xmake/lz4/compress_file.c +++ b/core/src/xmake/lz4/compress_file.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_compress_file(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the file paths @@ -91,7 +90,6 @@ tb_int_t xm_lz4_compress_file(lua_State *lua) { } xm_lz4_cstream_exit(stream_lz4); - // ok? lua_pushboolean(lua, ok); return 1; } diff --git a/core/src/xmake/lz4/compress_stream_close.c b/core/src/xmake/lz4/compress_stream_close.c index 2bec169d0..d1f534cde 100644 --- a/core/src/xmake/lz4/compress_stream_close.c +++ b/core/src/xmake/lz4/compress_stream_close.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_compress_stream_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/lz4/compress_stream_open.c b/core/src/xmake/lz4/compress_stream_open.c index e4fd1de8b..d4ac50667 100644 --- a/core/src/xmake/lz4/compress_stream_open.c +++ b/core/src/xmake/lz4/compress_stream_open.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_compress_stream_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); xm_lz4_cstream_t *stream = xm_lz4_cstream_init(); diff --git a/core/src/xmake/lz4/compress_stream_read.c b/core/src/xmake/lz4/compress_stream_read.c index 7338ede02..ff1315c3e 100644 --- a/core/src/xmake/lz4/compress_stream_read.c +++ b/core/src/xmake/lz4/compress_stream_read.c @@ -35,7 +35,6 @@ */ tb_int_t xm_lz4_compress_stream_read(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check handle diff --git a/core/src/xmake/lz4/compress_stream_write.c b/core/src/xmake/lz4/compress_stream_write.c index aa6b87e85..730a4f986 100644 --- a/core/src/xmake/lz4/compress_stream_write.c +++ b/core/src/xmake/lz4/compress_stream_write.c @@ -35,7 +35,6 @@ */ tb_int_t xm_lz4_compress_stream_write(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check handle diff --git a/core/src/xmake/lz4/decompress.c b/core/src/xmake/lz4/decompress.c index c5382747d..51a50c112 100644 --- a/core/src/xmake/lz4/decompress.c +++ b/core/src/xmake/lz4/decompress.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_decompress(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get data and size diff --git a/core/src/xmake/lz4/decompress_file.c b/core/src/xmake/lz4/decompress_file.c index b65ee87a0..7d91c5be4 100644 --- a/core/src/xmake/lz4/decompress_file.c +++ b/core/src/xmake/lz4/decompress_file.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_decompress_file(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the file paths @@ -91,7 +90,6 @@ tb_int_t xm_lz4_decompress_file(lua_State *lua) { } xm_lz4_dstream_exit(stream_lz4); - // ok? lua_pushboolean(lua, ok); return 1; } diff --git a/core/src/xmake/lz4/decompress_stream_close.c b/core/src/xmake/lz4/decompress_stream_close.c index ead2e3493..89c868c53 100644 --- a/core/src/xmake/lz4/decompress_stream_close.c +++ b/core/src/xmake/lz4/decompress_stream_close.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_decompress_stream_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/lz4/decompress_stream_open.c b/core/src/xmake/lz4/decompress_stream_open.c index 673038e80..eb3db7193 100644 --- a/core/src/xmake/lz4/decompress_stream_open.c +++ b/core/src/xmake/lz4/decompress_stream_open.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_lz4_decompress_stream_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); xm_lz4_dstream_t *stream = xm_lz4_dstream_init(); diff --git a/core/src/xmake/lz4/decompress_stream_read.c b/core/src/xmake/lz4/decompress_stream_read.c index 5f6486166..85ecdbe9f 100644 --- a/core/src/xmake/lz4/decompress_stream_read.c +++ b/core/src/xmake/lz4/decompress_stream_read.c @@ -35,7 +35,6 @@ */ tb_int_t xm_lz4_decompress_stream_read(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check handle diff --git a/core/src/xmake/lz4/decompress_stream_write.c b/core/src/xmake/lz4/decompress_stream_write.c index 7fa45544c..4359a41d7 100644 --- a/core/src/xmake/lz4/decompress_stream_write.c +++ b/core/src/xmake/lz4/decompress_stream_write.c @@ -35,7 +35,6 @@ */ tb_int_t xm_lz4_decompress_stream_write(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check handle diff --git a/core/src/xmake/lz4/prefix.h b/core/src/xmake/lz4/prefix.h index 996e53093..534e5361a 100644 --- a/core/src/xmake/lz4/prefix.h +++ b/core/src/xmake/lz4/prefix.h @@ -131,7 +131,6 @@ static __tb_inline__ tb_long_t xm_lz4_cstream_write(xm_lz4_cstream_t *stream, tb_byte_t const *idata, tb_size_t isize, tb_bool_t end) { - // check tb_assert_and_check_return_val(stream && stream->cctx && idata && isize, -1); tb_assert_and_check_return_val(isize <= stream->write_maxn, -1); tb_assert_and_check_return_val(stream->buffer_size + isize < stream->buffer_maxn, -1); @@ -162,7 +161,6 @@ static __tb_inline__ tb_long_t xm_lz4_cstream_write(xm_lz4_cstream_t *stream, } static __tb_inline__ tb_long_t xm_lz4_cstream_read(xm_lz4_cstream_t *stream, tb_byte_t *odata, tb_size_t osize) { - // check tb_assert_and_check_return_val(stream && stream->cctx && odata && osize, -1); tb_assert_and_check_return_val(osize >= stream->header_size, -1); @@ -224,7 +222,6 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t *stream, tb_byte_t const *idata, tb_size_t isize, tb_bool_t end) { - // check tb_assert_and_check_return_val(stream && stream->dctx && idata && isize, -1); // read header first @@ -279,7 +276,6 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t *stream, } static __tb_inline__ tb_long_t xm_lz4_dstream_read(xm_lz4_dstream_t *stream, tb_byte_t *odata, tb_size_t osize) { - // check tb_assert_and_check_return_val(stream && stream->dctx && stream->buffer && odata && osize, -1); tb_check_return_val(stream->buffer_size, 0); diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c index d220e0350..8b2c002c9 100644 --- a/core/src/xmake/os/args.c +++ b/core/src/xmake/os/args.c @@ -35,7 +35,6 @@ */ static tb_void_t tb_os_args_append( tb_string_ref_t result, tb_char_t const *cstr, tb_size_t size, tb_bool_t escape, tb_bool_t nowrap) { - // check tb_assert_and_check_return(size < TB_PATH_MAXN); // need wrap quote? @@ -74,7 +73,6 @@ static tb_void_t tb_os_args_append( */ // os.args({"xx", "yy"}, {escape = true}) tb_int_t xm_os_args(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // escape '\\' characters in global? diff --git a/core/src/xmake/os/argv.c b/core/src/xmake/os/argv.c index 89635fb2d..f7230d057 100644 --- a/core/src/xmake/os/argv.c +++ b/core/src/xmake/os/argv.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_argv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the argument string diff --git a/core/src/xmake/os/chdir.c b/core/src/xmake/os/chdir.c index 537d6506c..73619122c 100644 --- a/core/src/xmake/os/chdir.c +++ b/core/src/xmake/os/chdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_chdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path @@ -44,6 +43,5 @@ tb_int_t xm_os_chdir(lua_State *lua) { // done os.chdir(path) lua_pushboolean(lua, tb_directory_current_set(path)); - // ok return 1; } diff --git a/core/src/xmake/os/cpdir.c b/core/src/xmake/os/cpdir.c index e2f2b89ee..0df435436 100644 --- a/core/src/xmake/os/cpdir.c +++ b/core/src/xmake/os/cpdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_cpdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the source and destination diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c index b6597f87f..7291385a7 100644 --- a/core/src/xmake/os/cpfile.c +++ b/core/src/xmake/os/cpfile.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_cpfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the source and destination diff --git a/core/src/xmake/os/cpuinfo.c b/core/src/xmake/os/cpuinfo.c index a2ac1bbe4..f8ef7d46b 100644 --- a/core/src/xmake/os/cpuinfo.c +++ b/core/src/xmake/os/cpuinfo.c @@ -237,7 +237,6 @@ static tb_float_t xm_os_cpuinfo_usagerate() { * } */ tb_int_t xm_os_cpuinfo(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init table diff --git a/core/src/xmake/os/curdir.c b/core/src/xmake/os/curdir.c index b2ca8a273..2d27cf905 100644 --- a/core/src/xmake/os/curdir.c +++ b/core/src/xmake/os/curdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_curdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // os.curdir() diff --git a/core/src/xmake/os/emptydir.c b/core/src/xmake/os/emptydir.c index 79ebd9807..aab016d28 100644 --- a/core/src/xmake/os/emptydir.c +++ b/core/src/xmake/os/emptydir.c @@ -34,7 +34,6 @@ * private implementation */ static tb_long_t xm_os_emptydir_walk(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { - // check tb_bool_t *is_emptydir = (tb_bool_t *)priv; tb_assert_and_check_return_val(path && info && is_emptydir, TB_DIRECTORY_WALK_CODE_END); @@ -50,7 +49,6 @@ static tb_long_t xm_os_emptydir_walk(tb_char_t const *path, tb_file_info_t const * implementation */ tb_int_t xm_os_emptydir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the directory diff --git a/core/src/xmake/os/exists.c b/core/src/xmake/os/exists.c index 403a1285d..9bb244510 100644 --- a/core/src/xmake/os/exists.c +++ b/core/src/xmake/os/exists.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_exists(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/filesize.c b/core/src/xmake/os/filesize.c index 115ab5665..a99651fbf 100644 --- a/core/src/xmake/os/filesize.c +++ b/core/src/xmake/os/filesize.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_filesize(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/find.c b/core/src/xmake/os/find.c index 91c5b0261..2ed5611ad 100644 --- a/core/src/xmake/os/find.c +++ b/core/src/xmake/os/find.c @@ -34,7 +34,6 @@ * private implementation */ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { - // check tb_value_ref_t tuple = (tb_value_ref_t)priv; tb_assert_and_check_return_val(path && info && tuple, TB_DIRECTORY_WALK_CODE_END); @@ -56,7 +55,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in // the count tb_size_t *pcount = &(tuple[3].ul); - // trace tb_trace_d("path[%c]: %s", info->type == TB_FILE_TYPE_DIRECTORY ? 'd' : 'f', path); // we can ignore it directly if this path is file, but we need directory @@ -70,7 +68,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in lua_pushstring(lua, path); lua_pushstring(lua, pattern); if (lua_pcall(lua, 2, 1, 0)) { - // trace tb_printf("error: call string.match(%s, %s) failed: %s!\n", path, pattern, lua_tostring(lua, -1)); return TB_DIRECTORY_WALK_CODE_END; } @@ -87,7 +84,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in tb_char_t const *rootdir = luaL_checklstring(lua, 1, &rootlen); tb_assert_and_check_return_val(rootdir && rootlen, TB_DIRECTORY_WALK_CODE_END); - // check tb_assert(!tb_strncmp(path, rootdir, rootlen)); tb_assert(rootlen + 1 <= tb_strlen(path)); @@ -108,7 +104,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in lua_pushstring(lua, path); lua_pushstring(lua, exclude); if (lua_pcall(lua, 2, 1, 0)) { - // trace tb_printf("error: call string.match(%s, %s) failed: %s!\n", path, exclude, @@ -163,7 +158,6 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in * implementation */ tb_int_t xm_os_find(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the root directory diff --git a/core/src/xmake/os/fscase.c b/core/src/xmake/os/fscase.c index 6fa1c1c4a..b24a36e50 100644 --- a/core/src/xmake/os/fscase.c +++ b/core/src/xmake/os/fscase.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_fscase(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); #if ((TB_VERSION_MAJOR * 100) + (TB_VERSION_MINOR * 10) + TB_VERSION_ALTER) >= 174 diff --git a/core/src/xmake/os/getenv.c b/core/src/xmake/os/getenv.c index 84411ae1a..dc5578ebe 100644 --- a/core/src/xmake/os/getenv.c +++ b/core/src/xmake/os/getenv.c @@ -45,7 +45,6 @@ * implementation */ tb_int_t xm_os_getenv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the name @@ -89,6 +88,5 @@ tb_int_t xm_os_getenv(lua_State *lua) { // exit values tb_string_exit(&values); - // ok return 1; } diff --git a/core/src/xmake/os/getenvs.c b/core/src/xmake/os/getenvs.c index a3bc546b4..70c6af7bf 100644 --- a/core/src/xmake/os/getenvs.c +++ b/core/src/xmake/os/getenvs.c @@ -57,7 +57,6 @@ extern tb_char_t **environ; * implementation */ static tb_void_t xm_os_getenvs_trim(tb_char_t const **sstr, tb_char_t const **estr) { - // check tb_assert(sstr && estr && *sstr && *estr); tb_char_t const *p = *sstr; @@ -77,7 +76,6 @@ static tb_void_t xm_os_getenvs_trim(tb_char_t const **sstr, tb_char_t const **es } static tb_void_t xm_os_getenvs_process_line(lua_State *lua, tb_char_t const *line) { - // check tb_assert_and_check_return(lua && line); tb_size_t n = tb_strlen(line); @@ -124,7 +122,6 @@ static tb_void_t xm_os_getenvs_process_line(lua_State *lua, tb_char_t const *lin } tb_int_t xm_os_getenvs(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init table diff --git a/core/src/xmake/os/getown.c b/core/src/xmake/os/getown.c index 54e2b589e..ef7846ad1 100644 --- a/core/src/xmake/os/getown.c +++ b/core/src/xmake/os/getown.c @@ -42,7 +42,6 @@ // get owner by a given path tb_int_t xm_os_getown(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the pathname @@ -63,7 +62,6 @@ tb_int_t xm_os_getown(lua_State *lua) { lua_pushinteger(lua, sts.st_gid); lua_settable(lua, -3); - // ok return 1; } diff --git a/core/src/xmake/os/getpid.c b/core/src/xmake/os/getpid.c index 70b63804a..ad1a6f880 100644 --- a/core/src/xmake/os/getpid.c +++ b/core/src/xmake/os/getpid.c @@ -40,7 +40,6 @@ * implementation */ tb_int_t xm_os_getpid(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); #ifdef TB_CONFIG_OS_WINDOWS diff --git a/core/src/xmake/os/getwinsize.c b/core/src/xmake/os/getwinsize.c index 9757867a9..6faef97d0 100644 --- a/core/src/xmake/os/getwinsize.c +++ b/core/src/xmake/os/getwinsize.c @@ -43,7 +43,6 @@ // get console window size tb_int_t xm_os_getwinsize(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init default window size (we will not consider winsize limit if cannot get it) @@ -80,6 +79,5 @@ tb_int_t xm_os_getwinsize(lua_State *lua) { lua_pushinteger(lua, h); lua_settable(lua, -3); - // ok return 1; } diff --git a/core/src/xmake/os/gid.c b/core/src/xmake/os/gid.c index cd5915cd4..feb13791b 100644 --- a/core/src/xmake/os/gid.c +++ b/core/src/xmake/os/gid.c @@ -41,7 +41,6 @@ // get & set gid tb_int_t xm_os_gid(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_int_t rgidset = -1; @@ -124,7 +123,6 @@ tb_int_t xm_os_gid(lua_State *lua) { lua_pushinteger(lua, egid); lua_settable(lua, -3); - // ok return 1; } diff --git a/core/src/xmake/os/isdir.c b/core/src/xmake/os/isdir.c index 6126ed6a8..f182e029d 100644 --- a/core/src/xmake/os/isdir.c +++ b/core/src/xmake/os/isdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_isdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/isfile.c b/core/src/xmake/os/isfile.c index f015b5f59..d7b1d66f2 100644 --- a/core/src/xmake/os/isfile.c +++ b/core/src/xmake/os/isfile.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_isfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/islink.c b/core/src/xmake/os/islink.c index 2de7e24fd..51181ecd2 100644 --- a/core/src/xmake/os/islink.c +++ b/core/src/xmake/os/islink.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_islink(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/link.c b/core/src/xmake/os/link.c index 696355177..cead7f88c 100644 --- a/core/src/xmake/os/link.c +++ b/core/src/xmake/os/link.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_link(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the source and destination @@ -45,6 +44,5 @@ tb_int_t xm_os_link(lua_State *lua) { // do os.link(src, dst) lua_pushboolean(lua, tb_file_link(src, dst)); - // ok return 1; } diff --git a/core/src/xmake/os/mclock.c b/core/src/xmake/os/mclock.c index f6bc138d3..5fa440db6 100644 --- a/core/src/xmake/os/mclock.c +++ b/core/src/xmake/os/mclock.c @@ -36,12 +36,10 @@ // os.mclock() tb_int_t xm_os_mclock(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // save result lua_pushnumber(lua, (lua_Number)tb_mclock()); - // ok return 1; } diff --git a/core/src/xmake/os/meminfo.c b/core/src/xmake/os/meminfo.c index 3c0b71d80..1e6e5f422 100644 --- a/core/src/xmake/os/meminfo.c +++ b/core/src/xmake/os/meminfo.c @@ -159,7 +159,6 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) * implementation */ tb_int_t xm_os_meminfo(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // init table diff --git a/core/src/xmake/os/mkdir.c b/core/src/xmake/os/mkdir.c index badc50fd6..19507b5aa 100644 --- a/core/src/xmake/os/mkdir.c +++ b/core/src/xmake/os/mkdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_mkdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path @@ -48,6 +47,5 @@ tb_int_t xm_os_mkdir(lua_State *lua) { else lua_pushboolean(lua, tb_true); - // ok return 1; } diff --git a/core/src/xmake/os/mtime.c b/core/src/xmake/os/mtime.c index a3d9c44de..73014666b 100644 --- a/core/src/xmake/os/mtime.c +++ b/core/src/xmake/os/mtime.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_mtime(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/readlink.c b/core/src/xmake/os/readlink.c index 26ef78819..603ab7104 100644 --- a/core/src/xmake/os/readlink.c +++ b/core/src/xmake/os/readlink.c @@ -37,7 +37,6 @@ * implementation */ tb_int_t xm_os_readlink(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path @@ -69,6 +68,5 @@ tb_int_t xm_os_readlink(lua_State *lua) { lua_pushnil(lua); #endif - // ok return 1; } diff --git a/core/src/xmake/os/rename.c b/core/src/xmake/os/rename.c index 2f43797db..0cc469ded 100644 --- a/core/src/xmake/os/rename.c +++ b/core/src/xmake/os/rename.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_rename(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the source and destination diff --git a/core/src/xmake/os/rmdir.c b/core/src/xmake/os/rmdir.c index dd549adac..f04ba2a9c 100644 --- a/core/src/xmake/os/rmdir.c +++ b/core/src/xmake/os/rmdir.c @@ -34,7 +34,6 @@ * private implementation */ static tb_long_t xm_os_rmdir_empty(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { - // check tb_bool_t *is_emptydir = (tb_bool_t *)priv; tb_assert_and_check_return_val(path && info && is_emptydir, TB_DIRECTORY_WALK_CODE_END); @@ -47,7 +46,6 @@ static tb_long_t xm_os_rmdir_empty(tb_char_t const *path, tb_file_info_t const * return TB_DIRECTORY_WALK_CODE_CONTINUE; } static tb_long_t xm_os_rmdir_remove(tb_char_t const *path, tb_file_info_t const *info, tb_cpointer_t priv) { - // check tb_assert_and_check_return_val(path, TB_DIRECTORY_WALK_CODE_END); // is directory? @@ -56,7 +54,6 @@ static tb_long_t xm_os_rmdir_remove(tb_char_t const *path, tb_file_info_t const tb_bool_t is_emptydir = tb_true; tb_directory_walk(path, tb_false, tb_true, xm_os_rmdir_empty, &is_emptydir); - // trace tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); // remove empty directory @@ -70,7 +67,6 @@ static tb_long_t xm_os_rmdir_remove(tb_char_t const *path, tb_file_info_t const * implementation */ tb_int_t xm_os_rmdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path @@ -89,10 +85,8 @@ tb_int_t xm_os_rmdir(lua_State *lua) { if (is_emptydir) tb_directory_remove(path); - // trace tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); - // ok? lua_pushboolean(lua, !tb_file_info(path, tb_null)); } else { // os.rmdir(path) diff --git a/core/src/xmake/os/rmfile.c b/core/src/xmake/os/rmfile.c index f4b204e25..2032d4ee2 100644 --- a/core/src/xmake/os/rmfile.c +++ b/core/src/xmake/os/rmfile.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_rmfile(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/os/setenv.c b/core/src/xmake/os/setenv.c index 99a9bf44e..be375b2f4 100644 --- a/core/src/xmake/os/setenv.c +++ b/core/src/xmake/os/setenv.c @@ -35,7 +35,6 @@ */ // ok = os.setenv(name, value) tb_int_t xm_os_setenv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the name and value diff --git a/core/src/xmake/os/signal.c b/core/src/xmake/os/signal.c index c1f43ad6b..4d9e8a4c5 100644 --- a/core/src/xmake/os/signal.c +++ b/core/src/xmake/os/signal.c @@ -101,7 +101,6 @@ static tb_void_t xm_os_signal_handler(tb_int_t signo_native) { * implementation */ tb_int_t xm_os_signal(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); g_lua = lua; tb_int_t handler = XM_OS_SIGFUN; diff --git a/core/src/xmake/os/strerror.c b/core/src/xmake/os/strerror.c index 955ca8e24..c1ae41039 100644 --- a/core/src/xmake/os/strerror.c +++ b/core/src/xmake/os/strerror.c @@ -40,7 +40,6 @@ * implementation */ tb_int_t xm_os_strerror(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get syserror state diff --git a/core/src/xmake/os/syserror.c b/core/src/xmake/os/syserror.c index b96a9894f..3ef2a5c52 100644 --- a/core/src/xmake/os/syserror.c +++ b/core/src/xmake/os/syserror.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_syserror(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get syserror state diff --git a/core/src/xmake/os/tmpdir.c b/core/src/xmake/os/tmpdir.c index 68b99ee8f..4396603d4 100644 --- a/core/src/xmake/os/tmpdir.c +++ b/core/src/xmake/os/tmpdir.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_tmpdir(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // os.tmpdir() diff --git a/core/src/xmake/os/touch.c b/core/src/xmake/os/touch.c index 4e0bd5af8..5c470440b 100644 --- a/core/src/xmake/os/touch.c +++ b/core/src/xmake/os/touch.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_os_touch(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_char_t const *path = luaL_checkstring(lua, 1); diff --git a/core/src/xmake/os/uid.c b/core/src/xmake/os/uid.c index b6413a5e5..2785437d0 100644 --- a/core/src/xmake/os/uid.c +++ b/core/src/xmake/os/uid.c @@ -41,7 +41,6 @@ // get & set uid tb_int_t xm_os_uid(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_int_t ruidset = -1; @@ -124,7 +123,6 @@ tb_int_t xm_os_uid(lua_State *lua) { lua_pushinteger(lua, euid); lua_settable(lua, -3); - // ok return 1; } diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c index 894141414..15a579f91 100644 --- a/core/src/xmake/package/loadxmi.c +++ b/core/src/xmake/package/loadxmi.c @@ -43,7 +43,6 @@ typedef int (*xm_setup_func_t)(xmi_lua_ops_t *ops); * implementation */ tb_int_t xm_package_loadxmi(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_char_t const *path = luaL_checkstring(lua, 1); diff --git a/core/src/xmake/path/absolute.c b/core/src/xmake/path/absolute.c index 781d2f5e4..9b05bc07d 100644 --- a/core/src/xmake/path/absolute.c +++ b/core/src/xmake/path/absolute.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_absolute(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/path/directory.c b/core/src/xmake/path/directory.c index aca226a89..0c7d77f2d 100644 --- a/core/src/xmake/path/directory.c +++ b/core/src/xmake/path/directory.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_directory(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/path/is_absolute.c b/core/src/xmake/path/is_absolute.c index 120476242..7ac489e26 100644 --- a/core/src/xmake/path/is_absolute.c +++ b/core/src/xmake/path/is_absolute.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_is_absolute(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/path/relative.c b/core/src/xmake/path/relative.c index c6ddad14d..5d3beaaa5 100644 --- a/core/src/xmake/path/relative.c +++ b/core/src/xmake/path/relative.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_relative(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/path/translate.c b/core/src/xmake/path/translate.c index 422cd0320..7611d188a 100644 --- a/core/src/xmake/path/translate.c +++ b/core/src/xmake/path/translate.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_path_translate(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the path diff --git a/core/src/xmake/process/close.c b/core/src/xmake/process/close.c index 272a02259..fc57453e6 100644 --- a/core/src/xmake/process/close.c +++ b/core/src/xmake/process/close.c @@ -36,7 +36,6 @@ // process.close(p) tb_int_t xm_process_close(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/process/kill.c b/core/src/xmake/process/kill.c index 7eb4f8fd7..4859027b4 100644 --- a/core/src/xmake/process/kill.c +++ b/core/src/xmake/process/kill.c @@ -36,7 +36,6 @@ // process.kill(p) tb_int_t xm_process_kill(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c index 8ed62a0cd..f0885719a 100644 --- a/core/src/xmake/process/open.c +++ b/core/src/xmake/process/open.c @@ -42,7 +42,6 @@ * envs = {"PATH=xxx", "XXX=yyy"}}) */ tb_int_t xm_process_open(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get command diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c index e605822b1..99a6133d0 100644 --- a/core/src/xmake/process/openv.c +++ b/core/src/xmake/process/openv.c @@ -46,7 +46,6 @@ * envs = {"PATH=xxx", "XXX=yyy"}}) */ tb_int_t xm_process_openv(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // check argv @@ -323,6 +322,5 @@ tb_int_t xm_process_openv(lua_State *lua) { tb_free(argv); argv = tb_null; - // ok return 1; } diff --git a/core/src/xmake/process/wait.c b/core/src/xmake/process/wait.c index 2914d87cc..84d3b7079 100644 --- a/core/src/xmake/process/wait.c +++ b/core/src/xmake/process/wait.c @@ -36,7 +36,6 @@ // ok, status = process.wait(proc, timeout) tb_int_t xm_process_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? @@ -62,6 +61,5 @@ tb_int_t xm_process_wait(lua_State *lua) { lua_pushinteger(lua, ok); lua_pushinteger(lua, status); - // ok return 2; } diff --git a/core/src/xmake/readline/add_history.c b/core/src/xmake/readline/add_history.c index f928cc446..8f0c1cf4d 100644 --- a/core/src/xmake/readline/add_history.c +++ b/core/src/xmake/readline/add_history.c @@ -37,7 +37,6 @@ // add_history wrapper tb_int_t xm_readline_add_history(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get history @@ -47,7 +46,6 @@ tb_int_t xm_readline_add_history(lua_State *lua) { // call add_history add_history(history); - // ok return 0; } #endif diff --git a/core/src/xmake/readline/clear_history.c b/core/src/xmake/readline/clear_history.c index 11f7ab30c..0235ea4ee 100644 --- a/core/src/xmake/readline/clear_history.c +++ b/core/src/xmake/readline/clear_history.c @@ -37,7 +37,6 @@ // clear_history wrapper tb_int_t xm_readline_clear_history(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); #ifdef TB_CONFIG_OS_MACOSX @@ -48,7 +47,6 @@ tb_int_t xm_readline_clear_history(lua_State *lua) { clear_history(); #endif - // ok return 0; } diff --git a/core/src/xmake/readline/history_list.c b/core/src/xmake/readline/history_list.c index 56d84e114..45267edd5 100644 --- a/core/src/xmake/readline/history_list.c +++ b/core/src/xmake/readline/history_list.c @@ -37,7 +37,6 @@ // history_list wrapper tb_int_t xm_readline_history_list(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // history list @@ -70,7 +69,6 @@ tb_int_t xm_readline_history_list(lua_State *lua) { } #endif - // ok return 1; } diff --git a/core/src/xmake/readline/readline.c b/core/src/xmake/readline/readline.c index 6675c6de2..b6988e35c 100644 --- a/core/src/xmake/readline/readline.c +++ b/core/src/xmake/readline/readline.c @@ -38,7 +38,6 @@ // readline wrapper tb_int_t xm_readline_readline(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the prompt @@ -55,7 +54,6 @@ tb_int_t xm_readline_readline(lua_State *lua) { } else lua_pushnil(lua); - // ok return 1; } diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c index 01bac19b4..9e94f876d 100644 --- a/core/src/xmake/sandbox/interactive.c +++ b/core/src/xmake/sandbox/interactive.c @@ -121,7 +121,6 @@ static tb_int_t xm_sandbox_docall(lua_State *lua, tb_int_t narg, tb_int_t clear) if (status != 0) lua_gc(lua, LUA_GCCOLLECT, 0); - // ok? return status; } @@ -158,7 +157,6 @@ static tb_size_t xm_sandbox_readline(tb_char_t *data, tb_size_t maxn, tb_char_t if (size >= maxn) return 0; - // ok return size; } #else @@ -189,7 +187,6 @@ static tb_int_t xm_sandbox_pushline(lua_State *lua, tb_char_t const *prompt2) { // push line lua_pushstring(lua, data); - // ok return 1; } @@ -228,7 +225,6 @@ static tb_int_t xm_sandbox_loadline(lua_State *lua, tb_int_t top) { // attempt to load "return ..." status = luaL_loadbuffer(lua, data, size + 7, "=stdin"); - // ok? if (status != LUA_ERRSYNTAX) return status; @@ -292,7 +288,6 @@ static tb_int_t xm_sandbox_loadline(lua_State *lua, tb_int_t top) { // sandbox.interactive() tb_int_t xm_sandbox_interactive(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); /* get init stack top @@ -358,6 +353,5 @@ tb_int_t xm_sandbox_interactive(lua_State *lua) { tb_printl(""); tb_print_sync(); - // end return 0; } diff --git a/core/src/xmake/semver/compare.c b/core/src/xmake/semver/compare.c index 87e2356a3..8310b73fc 100644 --- a/core/src/xmake/semver/compare.c +++ b/core/src/xmake/semver/compare.c @@ -36,7 +36,6 @@ // semver.compare("v1.0.1-beta", "1.2") > 0? tb_int_t xm_semver_compare(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the version1 string @@ -66,7 +65,6 @@ tb_int_t xm_semver_compare(lua_State *lua) { // do compare lua_pushinteger(lua, semver_pcmp(&semver1, &semver2)); - // end semver_dtor(&semver1); semver_dtor(&semver2); return 1; diff --git a/core/src/xmake/semver/parse.c b/core/src/xmake/semver/parse.c index e9dc221ee..63bd47f93 100644 --- a/core/src/xmake/semver/parse.c +++ b/core/src/xmake/semver/parse.c @@ -55,7 +55,6 @@ * */ tb_int_t xm_semver_parse(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the version string @@ -70,7 +69,6 @@ tb_int_t xm_semver_parse(lua_State *lua) { return 2; } - // ok lua_pushsemver(lua, &semver); semver_dtor(&semver); return 1; diff --git a/core/src/xmake/semver/satisfies.c b/core/src/xmake/semver/satisfies.c index 55c0decb9..a7c47f4fa 100644 --- a/core/src/xmake/semver/satisfies.c +++ b/core/src/xmake/semver/satisfies.c @@ -39,7 +39,6 @@ * semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') => true */ tb_int_t xm_semver_satisfies(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the version string diff --git a/core/src/xmake/semver/select.c b/core/src/xmake/semver/select.c index 373a71711..7109bfc83 100644 --- a/core/src/xmake/semver/select.c +++ b/core/src/xmake/semver/select.c @@ -75,7 +75,6 @@ static tb_bool_t xm_semver_select_from_versions_tags1( // exit the popped semver semver_dtor(&top); - // ok return tb_true; } static tb_bool_t xm_semver_select_from_versions_tags2( @@ -173,7 +172,6 @@ static tb_bool_t xm_semver_select_latest_from_versions_tags(lua_State *lua, * local versioninfo, errors = semver.select(">=1.5.0 <1.6", {"1.5.0", "1.5.1"}, {"v1.5.0", ..}, {"latest", "dev"}) */ tb_int_t xm_semver_select(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // select version @@ -260,6 +258,5 @@ tb_int_t xm_semver_select(lua_State *lua) { return 2; } - // ok return 1; } diff --git a/core/src/xmake/semver/semver.c b/core/src/xmake/semver/semver.c index 4fe48e5e9..bd13828fa 100644 --- a/core/src/xmake/semver/semver.c +++ b/core/src/xmake/semver/semver.c @@ -34,7 +34,6 @@ * implementation */ tb_void_t lua_pushsemver(lua_State *lua, semver_t const *semver) { - // check tb_assert(lua && semver); // return a semver table diff --git a/core/src/xmake/string/convert.c b/core/src/xmake/string/convert.c index 65750d95e..88dc5ceb1 100644 --- a/core/src/xmake/string/convert.c +++ b/core/src/xmake/string/convert.c @@ -98,7 +98,6 @@ static xm_charset_entry_ref_t xm_string_charset_find_by_name(tb_char_t const *na * @endcode */ tb_int_t xm_string_convert(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the string and charset types @@ -137,6 +136,5 @@ tb_int_t xm_string_convert(lua_State *lua) { tb_free(dst_data); } - // ok return 1; } diff --git a/core/src/xmake/string/endswith.c b/core/src/xmake/string/endswith.c index 5905610f6..f7e5e1805 100644 --- a/core/src/xmake/string/endswith.c +++ b/core/src/xmake/string/endswith.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_string_endswith(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the string and suffix @@ -47,6 +46,5 @@ tb_int_t xm_string_endswith(lua_State *lua) { // string:endswith(suffix)? lua_pushboolean(lua, string_size >= suffix_size && !tb_strcmp(string + string_size - suffix_size, suffix)); - // ok return 1; } diff --git a/core/src/xmake/string/lastof.c b/core/src/xmake/string/lastof.c index c9df2213d..0d52e01ac 100644 --- a/core/src/xmake/string/lastof.c +++ b/core/src/xmake/string/lastof.c @@ -71,7 +71,6 @@ static tb_void_t xm_string_lastof_chr(lua_State *lua, tb_char_t const *cstr, tb_ * @param substr the substring */ tb_int_t xm_string_lastof(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get string diff --git a/core/src/xmake/string/split.c b/core/src/xmake/string/split.c index be2904f99..56e8a636d 100644 --- a/core/src/xmake/string/split.c +++ b/core/src/xmake/string/split.c @@ -101,7 +101,6 @@ static tb_void_t xm_string_split_chr( * @param limit the limit count */ tb_int_t xm_string_split(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get string diff --git a/core/src/xmake/string/startswith.c b/core/src/xmake/string/startswith.c index c7fe9dcca..04b53ffa7 100644 --- a/core/src/xmake/string/startswith.c +++ b/core/src/xmake/string/startswith.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_string_startswith(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the string and prefix @@ -46,6 +45,5 @@ tb_int_t xm_string_startswith(lua_State *lua) { // string:startswith(prefix)? lua_pushboolean(lua, !tb_strncmp(string, prefix, (tb_size_t)prefix_size)); - // ok return 1; } diff --git a/core/src/xmake/string/trim.c b/core/src/xmake/string/trim.c index d22f86666..c1dcdad8d 100644 --- a/core/src/xmake/string/trim.c +++ b/core/src/xmake/string/trim.c @@ -34,7 +34,6 @@ * private implementation */ static tb_void_t xm_string_trim_space(tb_char_t const **psstr, tb_char_t const **pestr, tb_int_t mode) { - // check tb_assert(psstr && pestr && *psstr && *pestr); tb_char_t const *p = *psstr; @@ -62,7 +61,6 @@ static tb_char_t const *xm_string_ltrim(tb_char_t const *sstr, tb_char_t const *estr, tb_char_t const *ctrim, size_t ntrim) { - // check tb_assert(sstr && estr && ctrim); tb_char_t const *p = sstr; @@ -75,7 +73,6 @@ static tb_char_t const *xm_string_rtrim(tb_char_t const *sstr, tb_char_t const *estr, tb_char_t const *ctrim, size_t ntrim) { - // check tb_assert(sstr && estr && ctrim); tb_char_t const *p = estr - 1; @@ -100,7 +97,6 @@ static tb_char_t const *xm_string_rtrim(tb_char_t const *sstr, * @endcode */ tb_int_t xm_string_trim(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); size_t lstr, ltrim; @@ -127,7 +123,6 @@ tb_int_t xm_string_trim(lua_State *lua) { // no trimed chars tb_check_break(sstr != rsstr || estr != restr); - // ok lua_pushlstring(lua, sstr, estr - sstr); return 1; diff --git a/core/src/xmake/thread/thread_exit.c b/core/src/xmake/thread/thread_exit.c index a91018ac6..ae828805e 100644 --- a/core/src/xmake/thread/thread_exit.c +++ b/core/src/xmake/thread/thread_exit.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_thread_exit(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/thread/thread_init.c b/core/src/xmake/thread/thread_init.c index 60d694ae1..2a792463a 100644 --- a/core/src/xmake/thread/thread_init.c +++ b/core/src/xmake/thread/thread_init.c @@ -81,7 +81,6 @@ static tb_int_t xm_thread_func(tb_cpointer_t priv) { * implementation */ tb_int_t xm_thread_init(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_bool_t ok = tb_false; diff --git a/core/src/xmake/thread/thread_resume.c b/core/src/xmake/thread/thread_resume.c index 9a3630338..45253b418 100644 --- a/core/src/xmake/thread/thread_resume.c +++ b/core/src/xmake/thread/thread_resume.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_thread_resume(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/thread/thread_suspend.c b/core/src/xmake/thread/thread_suspend.c index dcb24c4f6..1df3063ef 100644 --- a/core/src/xmake/thread/thread_suspend.c +++ b/core/src/xmake/thread/thread_suspend.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_thread_suspend(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/thread/thread_wait.c b/core/src/xmake/thread/thread_wait.c index 4a921f39c..8ceb45524 100644 --- a/core/src/xmake/thread/thread_wait.c +++ b/core/src/xmake/thread/thread_wait.c @@ -34,7 +34,6 @@ * implementation */ tb_int_t xm_thread_wait(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // is pointer? diff --git a/core/src/xmake/tty/term_mode.c b/core/src/xmake/tty/term_mode.c index 78380de5f..34998c60b 100644 --- a/core/src/xmake/tty/term_mode.c +++ b/core/src/xmake/tty/term_mode.c @@ -41,7 +41,6 @@ * local oldmode = tty.term_mode(stdtype, newmode) */ tb_int_t xm_tty_term_mode(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); #ifdef TB_CONFIG_OS_WINDOWS diff --git a/core/src/xmake/utils/bin2c.c b/core/src/xmake/utils/bin2c.c index fef00fb4e..77a1b2a8c 100644 --- a/core/src/xmake/utils/bin2c.c +++ b/core/src/xmake/utils/bin2c.c @@ -101,7 +101,6 @@ static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream, * local ok, errors = utils.bin2c(binaryfile, outputfile, linewidth, nozeroend) */ tb_int_t xm_utils_bin2c(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the binaryfile diff --git a/core/src/xmake/winos/ansi.c b/core/src/xmake/winos/ansi.c index 137f18742..48bb9df82 100644 --- a/core/src/xmake/winos/ansi.c +++ b/core/src/xmake/winos/ansi.c @@ -36,7 +36,6 @@ */ static tb_int_t xm_expand_cp(tb_int_t cp) { - // check tb_assert_and_check_return_val(cp >= 0 && cp <= 65535, 0); if (cp == CP_OEMCP) @@ -47,7 +46,6 @@ static tb_int_t xm_expand_cp(tb_int_t cp) { } tb_int_t xm_winos_console_cp(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_int_t n = lua_gettop(lua); @@ -66,7 +64,6 @@ tb_int_t xm_winos_console_cp(lua_State *lua) { } tb_int_t xm_winos_console_output_cp(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_int_t n = lua_gettop(lua); @@ -85,7 +82,6 @@ tb_int_t xm_winos_console_output_cp(lua_State *lua) { } tb_int_t xm_winos_cp_info(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); lua_Integer cp = luaL_checkinteger(lua, 1); @@ -138,7 +134,6 @@ tb_int_t xm_winos_cp_info(lua_State *lua) { } tb_int_t xm_winos_ansi_cp(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_uint_t cp = GetACP(); @@ -147,7 +142,6 @@ tb_int_t xm_winos_ansi_cp(lua_State *lua) { } tb_int_t xm_winos_oem_cp(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); tb_uint_t cp = GetOEMCP(); diff --git a/core/src/xmake/winos/logical_drives.c b/core/src/xmake/winos/logical_drives.c index 48b05886e..7227069b9 100644 --- a/core/src/xmake/winos/logical_drives.c +++ b/core/src/xmake/winos/logical_drives.c @@ -73,6 +73,5 @@ tb_int_t xm_winos_logical_drives(lua_State *lua) { tb_free(data); data = tb_null; - // ok return 1; } diff --git a/core/src/xmake/winos/registry_keys.c b/core/src/xmake/winos/registry_keys.c index 42a37e33d..7daf44ff4 100644 --- a/core/src/xmake/winos/registry_keys.c +++ b/core/src/xmake/winos/registry_keys.c @@ -168,7 +168,6 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t *info * end) */ tb_int_t xm_winos_registry_keys(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the arguments @@ -231,7 +230,6 @@ tb_int_t xm_winos_registry_keys(lua_State *lua) { } while (0); - // ok? if (ok) { lua_pushinteger(lua, count); return 1; diff --git a/core/src/xmake/winos/registry_query.c b/core/src/xmake/winos/registry_query.c index 23fda76ff..5e98af2cd 100644 --- a/core/src/xmake/winos/registry_query.c +++ b/core/src/xmake/winos/registry_query.c @@ -46,7 +46,6 @@ typedef BOOL(WINAPI *xm_RegGetValueW_t)( * local value, errors = winos.registry_query("HKEY_LOCAL_MACHINE", "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", "Debugger") */ tb_int_t xm_winos_registry_query(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the arguments @@ -226,6 +225,5 @@ tb_int_t xm_winos_registry_query(lua_State *lua) { tb_free(value_w); value_w = tb_null; - // ok? return ok ? 1 : 2; } diff --git a/core/src/xmake/winos/registry_values.c b/core/src/xmake/winos/registry_values.c index 1f72d978b..6bda8e690 100644 --- a/core/src/xmake/winos/registry_values.c +++ b/core/src/xmake/winos/registry_values.c @@ -43,7 +43,6 @@ * end) */ tb_int_t xm_winos_registry_values(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the arguments @@ -156,7 +155,6 @@ tb_int_t xm_winos_registry_values(lua_State *lua) { } } - // ok if (i == value_name_num) ok = tb_true; @@ -167,7 +165,6 @@ tb_int_t xm_winos_registry_values(lua_State *lua) { RegCloseKey(keynew); keynew = tb_null; - // ok? if (ok) { lua_pushinteger(lua, count); return 1; diff --git a/core/src/xmake/winos/short_path.c b/core/src/xmake/winos/short_path.c index 5c6e20b30..9c2192787 100644 --- a/core/src/xmake/winos/short_path.c +++ b/core/src/xmake/winos/short_path.c @@ -39,7 +39,6 @@ * local short_path, errors = winos.short_path(long_path) */ tb_int_t xm_winos_short_path(lua_State *lua) { - // check tb_assert_and_check_return_val(lua, 0); // get the arguments diff --git a/core/src/xmake/xmake.c b/core/src/xmake/xmake.c index 89b288c79..8d4a77284 100644 --- a/core/src/xmake/xmake.c +++ b/core/src/xmake/xmake.c @@ -52,7 +52,6 @@ static __tb_inline__ tb_bool_t xm_check_mode(tb_size_t mode) { } #endif - // ok return tb_true; } static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build) { @@ -60,7 +59,6 @@ static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build) { tb_version_t const *version = xm_version(); tb_used(version); - // ok if ((build / 100) == (XM_VERSION_BUILD / 100)) { tb_trace_d("version: %s", XM_VERSION_STRING); return tb_true; @@ -76,7 +74,6 @@ static __tb_inline__ tb_bool_t xm_version_check(tb_hize_t build) { * implementation */ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) { - // trace tb_trace_d("init: .."); // check mode @@ -95,10 +92,8 @@ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) { return tb_false; #endif - // trace tb_trace_d("init: ok"); - // ok return tb_true; } tb_void_t xm_exit() { -- cgit v1.3.1 From 12e00a411dfe202dcfa1de9a8511a802ce1af40d Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 20:16:46 +0800 Subject: format single line --- core/src/xmake/base64/encode.c | 6 ++++-- core/src/xmake/bloom_filter/bloom_filter_clear.c | 3 ++- core/src/xmake/bloom_filter/bloom_filter_close.c | 3 ++- core/src/xmake/bloom_filter/bloom_filter_data.c | 9 ++++++--- core/src/xmake/bloom_filter/bloom_filter_data_set.c | 9 ++++++--- core/src/xmake/bloom_filter/bloom_filter_get.c | 3 ++- core/src/xmake/bloom_filter/bloom_filter_open.c | 6 ++++-- core/src/xmake/bloom_filter/bloom_filter_set.c | 3 ++- core/src/xmake/bloom_filter/bloom_filter_size.c | 3 ++- core/src/xmake/thread/sharedata_get.c | 6 ++++-- core/src/xmake/thread/sharedata_set.c | 6 ++++-- core/src/xmake/thread/thread_exit.c | 3 ++- core/src/xmake/thread/thread_init.c | 6 ++++-- 13 files changed, 44 insertions(+), 22 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/base64/encode.c b/core/src/xmake/base64/encode.c index d896cb55e..d5ce56306 100644 --- a/core/src/xmake/base64/encode.c +++ b/core/src/xmake/base64/encode.c @@ -39,10 +39,12 @@ tb_int_t xm_base64_encode(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 1)) + if (xm_lua_isinteger(lua, 1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) + } + if (xm_lua_isinteger(lua, 2)) { size = (tb_size_t)lua_tointeger(lua, 2); + } if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); diff --git a/core/src/xmake/bloom_filter/bloom_filter_clear.c b/core/src/xmake/bloom_filter/bloom_filter_clear.c index 2657cc5dc..7693baa48 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_clear.c +++ b/core/src/xmake/bloom_filter/bloom_filter_clear.c @@ -37,8 +37,9 @@ tb_int_t xm_bloom_filter_clear(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the bloom filter tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/bloom_filter/bloom_filter_close.c b/core/src/xmake/bloom_filter/bloom_filter_close.c index 59d3e59a1..ba47860a5 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_close.c +++ b/core/src/xmake/bloom_filter/bloom_filter_close.c @@ -37,8 +37,9 @@ tb_int_t xm_bloom_filter_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the bloom filter tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/bloom_filter/bloom_filter_data.c b/core/src/xmake/bloom_filter/bloom_filter_data.c index 9d6f34e64..d60b97d11 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data.c @@ -37,8 +37,9 @@ tb_int_t xm_bloom_filter_data(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the bloom filter tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1); @@ -46,9 +47,11 @@ tb_int_t xm_bloom_filter_data(lua_State *lua) { // get data tb_pointer_t data = (tb_pointer_t)tb_bloom_filter_data(filter); - if (data) + if (data) { xm_lua_pushpointer(lua, data); - else + } + else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/bloom_filter/bloom_filter_data_set.c b/core/src/xmake/bloom_filter/bloom_filter_data_set.c index 984ec6562..6d2d48606 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data_set.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data_set.c @@ -37,8 +37,9 @@ tb_int_t xm_bloom_filter_data_set(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the bloom filter tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1); @@ -47,10 +48,12 @@ tb_int_t xm_bloom_filter_data_set(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) + } + if (xm_lua_isinteger(lua, 3)) { size = (tb_size_t)lua_tointeger(lua, 3); + } if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); diff --git a/core/src/xmake/bloom_filter/bloom_filter_get.c b/core/src/xmake/bloom_filter/bloom_filter_get.c index dd1f8d1e6..ffd1f82c7 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_get.c +++ b/core/src/xmake/bloom_filter/bloom_filter_get.c @@ -37,8 +37,9 @@ tb_int_t xm_bloom_filter_get(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the bloom filter tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/bloom_filter/bloom_filter_open.c b/core/src/xmake/bloom_filter/bloom_filter_open.c index be364be91..a97ab6d81 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_open.c +++ b/core/src/xmake/bloom_filter/bloom_filter_open.c @@ -48,9 +48,11 @@ tb_int_t xm_bloom_filter_open(lua_State *lua) { // init the bloom filter tb_bloom_filter_ref_t filter = tb_bloom_filter_init(probability, hash_count, item_maxn, tb_element_str(tb_true)); - if (filter) + if (filter) { xm_lua_pushpointer(lua, (tb_pointer_t)filter); - else + } + else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/bloom_filter/bloom_filter_set.c b/core/src/xmake/bloom_filter/bloom_filter_set.c index 51d85d0a7..6762ea5bc 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_set.c +++ b/core/src/xmake/bloom_filter/bloom_filter_set.c @@ -37,8 +37,9 @@ tb_int_t xm_bloom_filter_set(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the bloom filter tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/bloom_filter/bloom_filter_size.c b/core/src/xmake/bloom_filter/bloom_filter_size.c index 977b455f3..730968a12 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_size.c +++ b/core/src/xmake/bloom_filter/bloom_filter_size.c @@ -37,8 +37,9 @@ tb_int_t xm_bloom_filter_size(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the bloom filter tb_bloom_filter_ref_t filter = (tb_bloom_filter_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/thread/sharedata_get.c b/core/src/xmake/thread/sharedata_get.c index a239fb02d..cffc5860c 100644 --- a/core/src/xmake/thread/sharedata_get.c +++ b/core/src/xmake/thread/sharedata_get.c @@ -42,12 +42,14 @@ tb_int_t xm_thread_sharedata_get_(lua_State *lua) { tb_bool_t ok = tb_false; switch (thread_sharedata->value.kind) { case XM_THREAD_VALUE_STR: - if (tb_buffer_size(&thread_sharedata->buffer) > 0) + if (tb_buffer_size(&thread_sharedata->buffer) > 0) { lua_pushlstring(lua, (tb_char_t *)tb_buffer_data(&thread_sharedata->buffer), tb_buffer_size(&thread_sharedata->buffer)); - else + } + else { lua_pushliteral(lua, ""); + } ok = tb_true; break; case XM_THREAD_VALUE_INT: diff --git a/core/src/xmake/thread/sharedata_set.c b/core/src/xmake/thread/sharedata_set.c index 9f1e6b613..33f8a8561 100644 --- a/core/src/xmake/thread/sharedata_set.c +++ b/core/src/xmake/thread/sharedata_set.c @@ -45,10 +45,12 @@ tb_int_t xm_thread_sharedata_set(lua_State *lua) { tb_assert_and_check_return_val(data, 0); thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_STR; - if (data_size) + if (data_size) { tb_buffer_memncpy(&thread_sharedata->buffer, (tb_byte_t const *)data, data_size); - else + } + else { tb_buffer_clear(&thread_sharedata->buffer); + } } else if (xm_lua_isinteger(lua, 2)) { thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_INT; thread_sharedata->value.u.integer = lua_tointeger(lua, 2); diff --git a/core/src/xmake/thread/thread_exit.c b/core/src/xmake/thread/thread_exit.c index ae828805e..ca495d4a5 100644 --- a/core/src/xmake/thread/thread_exit.c +++ b/core/src/xmake/thread/thread_exit.c @@ -37,8 +37,9 @@ tb_int_t xm_thread_exit(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get thread xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/thread/thread_init.c b/core/src/xmake/thread/thread_init.c index 2a792463a..2d3e067f7 100644 --- a/core/src/xmake/thread/thread_init.c +++ b/core/src/xmake/thread/thread_init.c @@ -46,8 +46,9 @@ static tb_int_t xm_thread_func(tb_cpointer_t priv) { tb_assert_and_check_return_val(thread, 0); xm_engine_ref_t engine = xm_engine_pool_alloc(xm_engine_pool()); - if (!engine) + if (!engine) { engine = xm_engine_init(XM_THREAD_ENGINE_NAME, tb_null); + } if (engine) { lua_State *lua = xm_engine_lua(engine); tb_assert(lua); @@ -71,8 +72,9 @@ static tb_int_t xm_thread_func(tb_cpointer_t priv) { // start engine tb_char_t *argv[] = { XM_THREAD_ENGINE_NAME, tb_null }; xm_engine_main(engine, 1, argv, tb_null); - if (!xm_engine_pool_free(xm_engine_pool(), engine)) + if (!xm_engine_pool_free(xm_engine_pool(), engine)) { xm_engine_exit(engine); + } } return 0; } -- cgit v1.3.1 From 1b8d7a8ef65e54bfd86d5cafbab9f197974b0c82 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 20:20:24 +0800 Subject: format if-else --- core/src/xmake/engine_pool.c | 6 ++++-- core/src/xmake/hash/md5.c | 9 ++++++--- core/src/xmake/hash/rand32.c | 3 ++- core/src/xmake/hash/rand64.c | 3 ++- core/src/xmake/hash/sha.c | 9 ++++++--- core/src/xmake/hash/xxhash.c | 21 ++++++++++++++------- 6 files changed, 34 insertions(+), 17 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/engine_pool.c b/core/src/xmake/engine_pool.c index cf039d11e..39bdb1339 100644 --- a/core/src/xmake/engine_pool.c +++ b/core/src/xmake/engine_pool.c @@ -53,8 +53,9 @@ static tb_handle_t xm_engine_pool_instance_init(tb_cpointer_t *ppriv) { } static tb_void_t xm_engine_pool_instance_exit(tb_handle_t engine_pool, tb_cpointer_t priv) { - if (engine_pool) + if (engine_pool) { xm_engine_pool_exit((xm_engine_pool_ref_t)engine_pool); + } } /* ////////////////////////////////////////////////////////////////////////////////////// @@ -72,8 +73,9 @@ xm_engine_pool_ref_t xm_engine_pool_init() { tb_void_t xm_engine_pool_exit(xm_engine_pool_ref_t engine_pool) { if (engine_pool) { tb_for_all(xm_engine_ref_t, engine, engine_pool) { - if (engine) + if (engine) { xm_engine_exit(engine); + } } tb_single_list_exit(engine_pool); } diff --git a/core/src/xmake/hash/md5.c b/core/src/xmake/hash/md5.c index 3c871b063..d07c355e4 100644 --- a/core/src/xmake/hash/md5.c +++ b/core/src/xmake/hash/md5.c @@ -80,9 +80,10 @@ tb_int_t xm_hash_md5(lua_State *lua) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); - if (real > 0) + if (real > 0) { tb_md5_spak(&md5, data, real); // no data? continue it + } else if (!real) { // wait real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, tb_stream_timeout(stream)); @@ -92,8 +93,9 @@ tb_int_t xm_hash_md5(lua_State *lua) { tb_assert_and_check_break(real & TB_STREAM_WAIT_READ); } // failed or end? - else + else { break; + } } // exit md5 @@ -112,7 +114,8 @@ tb_int_t xm_hash_md5(lua_State *lua) { // exit stream tb_stream_exit(stream); } - if (!ok) + if (!ok) { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/hash/rand32.c b/core/src/xmake/hash/rand32.c index 844dd83e7..7f5286b8e 100644 --- a/core/src/xmake/hash/rand32.c +++ b/core/src/xmake/hash/rand32.c @@ -37,8 +37,9 @@ tb_int_t xm_hash_rand32(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); static tb_uint64_t s_seed = 0; - if (!s_seed) + if (!s_seed) { s_seed = (tb_uint64_t)tb_uclock(); + } s_seed = xm_hash_xorshift64(s_seed); tb_char_t s[256]; diff --git a/core/src/xmake/hash/rand64.c b/core/src/xmake/hash/rand64.c index 0f9e39069..ea9539ced 100644 --- a/core/src/xmake/hash/rand64.c +++ b/core/src/xmake/hash/rand64.c @@ -40,8 +40,9 @@ tb_int_t xm_hash_rand64(lua_State *lua) { tb_byte_t b[8]; tb_uint64_t word; } s_seed = { 0 }; - if (!s_seed.word) + if (!s_seed.word) { s_seed.word = (tb_uint64_t)tb_uclock(); + } s_seed.word = xm_hash_xorshift64(s_seed.word); tb_char_t s[256]; diff --git a/core/src/xmake/hash/sha.c b/core/src/xmake/hash/sha.c index 158a09208..4fddb0b83 100644 --- a/core/src/xmake/hash/sha.c +++ b/core/src/xmake/hash/sha.c @@ -87,9 +87,10 @@ tb_int_t xm_hash_sha(lua_State *lua) { // read data tb_long_t real = tb_stream_read(stream, data, sizeof(data)); - if (real > 0) + if (real > 0) { tb_sha_spak(&sha, data, real); // no data? continue it + } else if (!real) { // wait real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, tb_stream_timeout(stream)); @@ -99,8 +100,9 @@ tb_int_t xm_hash_sha(lua_State *lua) { tb_assert_and_check_break(real & TB_STREAM_WAIT_READ); } // failed or end? - else + else { break; + } } // exit sha @@ -120,7 +122,8 @@ tb_int_t xm_hash_sha(lua_State *lua) { // exit stream tb_stream_exit(stream); } - if (!ok) + if (!ok) { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/hash/xxhash.c b/core/src/xmake/hash/xxhash.c index 7a55ce63d..035ba4497 100644 --- a/core/src/xmake/hash/xxhash.c +++ b/core/src/xmake/hash/xxhash.c @@ -103,10 +103,12 @@ tb_int_t xm_hash_xxhash(lua_State *lua) { XXH3_state_t *state = XM_XXH3_createState(); if (tb_stream_open(stream) && state) { // reset xxhash - if (mode == 32 || mode == 64) + if (mode == 32 || mode == 64) { XM_XXH3_64bits_reset(state); - else + } + else { XM_XXH3_128bits_reset(state); + } // read data and update xxhash tb_byte_t data[TB_STREAM_BLOCK_MAXN]; @@ -115,10 +117,12 @@ tb_int_t xm_hash_xxhash(lua_State *lua) { tb_long_t real = tb_stream_read(stream, data, sizeof(data)); if (real > 0) { - if (mode == 32 || mode == 64) + if (mode == 32 || mode == 64) { XM_XXH3_64bits_update(state, data, real); - else + } + else { XM_XXH3_128bits_update(state, data, real); + } } // no data? continue it else if (!real) { @@ -130,8 +134,9 @@ tb_int_t xm_hash_xxhash(lua_State *lua) { tb_assert_and_check_break(real & TB_STREAM_WAIT_READ); } // failed or end? - else + else { break; + } } // compuate hash @@ -165,10 +170,12 @@ tb_int_t xm_hash_xxhash(lua_State *lua) { tb_stream_exit(stream); // exit xxhash - if (state) + if (state) { XM_XXH3_freeState(state); + } } - if (!ok) + if (!ok) { lua_pushnil(lua); + } return 1; } -- cgit v1.3.1 From f2f3821a0248b24941566c90e7aabcc0e7d95e77 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 21:38:38 +0800 Subject: format more code --- .clang-format | 10 ++++++++++ core/src/xmake/bloom_filter/bloom_filter_data.c | 3 +-- core/src/xmake/bloom_filter/bloom_filter_open.c | 3 +-- core/src/xmake/hash/md5.c | 3 +-- core/src/xmake/hash/sha.c | 3 +-- core/src/xmake/hash/xxhash.c | 6 ++---- core/src/xmake/thread/sharedata_get.c | 3 +-- core/src/xmake/thread/sharedata_set.c | 3 +-- 8 files changed, 18 insertions(+), 16 deletions(-) (limited to 'core/src') diff --git a/.clang-format b/.clang-format index 2fbb26713..8f5c54331 100644 --- a/.clang-format +++ b/.clang-format @@ -11,6 +11,16 @@ UseTab: Never # Braces BreakBeforeBraces: Attach +BraceWrapping: + AfterControlStatement: false + AfterFunction: false + AfterEnum: false + AfterClass: false + AfterStruct: false + AfterUnion: false + BeforeElse: false + BeforeCatch: false + BeforeLambdaBody: false # Alignment AlignAfterOpenBracket: Align diff --git a/core/src/xmake/bloom_filter/bloom_filter_data.c b/core/src/xmake/bloom_filter/bloom_filter_data.c index d60b97d11..d622a6f31 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_data.c +++ b/core/src/xmake/bloom_filter/bloom_filter_data.c @@ -49,8 +49,7 @@ tb_int_t xm_bloom_filter_data(lua_State *lua) { tb_pointer_t data = (tb_pointer_t)tb_bloom_filter_data(filter); if (data) { xm_lua_pushpointer(lua, data); - } - else { + } else { lua_pushnil(lua); } return 1; diff --git a/core/src/xmake/bloom_filter/bloom_filter_open.c b/core/src/xmake/bloom_filter/bloom_filter_open.c index a97ab6d81..4cd79e73f 100644 --- a/core/src/xmake/bloom_filter/bloom_filter_open.c +++ b/core/src/xmake/bloom_filter/bloom_filter_open.c @@ -50,8 +50,7 @@ tb_int_t xm_bloom_filter_open(lua_State *lua) { tb_bloom_filter_ref_t filter = tb_bloom_filter_init(probability, hash_count, item_maxn, tb_element_str(tb_true)); if (filter) { xm_lua_pushpointer(lua, (tb_pointer_t)filter); - } - else { + } else { lua_pushnil(lua); } return 1; diff --git a/core/src/xmake/hash/md5.c b/core/src/xmake/hash/md5.c index d07c355e4..6d18b72ba 100644 --- a/core/src/xmake/hash/md5.c +++ b/core/src/xmake/hash/md5.c @@ -83,8 +83,7 @@ tb_int_t xm_hash_md5(lua_State *lua) { if (real > 0) { tb_md5_spak(&md5, data, real); // no data? continue it - } - else if (!real) { + } else if (!real) { // wait real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, tb_stream_timeout(stream)); tb_check_break(real > 0); diff --git a/core/src/xmake/hash/sha.c b/core/src/xmake/hash/sha.c index 4fddb0b83..7ddcab62f 100644 --- a/core/src/xmake/hash/sha.c +++ b/core/src/xmake/hash/sha.c @@ -90,8 +90,7 @@ tb_int_t xm_hash_sha(lua_State *lua) { if (real > 0) { tb_sha_spak(&sha, data, real); // no data? continue it - } - else if (!real) { + } else if (!real) { // wait real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, tb_stream_timeout(stream)); tb_check_break(real > 0); diff --git a/core/src/xmake/hash/xxhash.c b/core/src/xmake/hash/xxhash.c index 035ba4497..a7fe4a985 100644 --- a/core/src/xmake/hash/xxhash.c +++ b/core/src/xmake/hash/xxhash.c @@ -105,8 +105,7 @@ tb_int_t xm_hash_xxhash(lua_State *lua) { // reset xxhash if (mode == 32 || mode == 64) { XM_XXH3_64bits_reset(state); - } - else { + } else { XM_XXH3_128bits_reset(state); } @@ -119,8 +118,7 @@ tb_int_t xm_hash_xxhash(lua_State *lua) { if (real > 0) { if (mode == 32 || mode == 64) { XM_XXH3_64bits_update(state, data, real); - } - else { + } else { XM_XXH3_128bits_update(state, data, real); } } diff --git a/core/src/xmake/thread/sharedata_get.c b/core/src/xmake/thread/sharedata_get.c index cffc5860c..51ebdf62f 100644 --- a/core/src/xmake/thread/sharedata_get.c +++ b/core/src/xmake/thread/sharedata_get.c @@ -46,8 +46,7 @@ tb_int_t xm_thread_sharedata_get_(lua_State *lua) { lua_pushlstring(lua, (tb_char_t *)tb_buffer_data(&thread_sharedata->buffer), tb_buffer_size(&thread_sharedata->buffer)); - } - else { + } else { lua_pushliteral(lua, ""); } ok = tb_true; diff --git a/core/src/xmake/thread/sharedata_set.c b/core/src/xmake/thread/sharedata_set.c index 33f8a8561..9a4ad3cbd 100644 --- a/core/src/xmake/thread/sharedata_set.c +++ b/core/src/xmake/thread/sharedata_set.c @@ -47,8 +47,7 @@ tb_int_t xm_thread_sharedata_set(lua_State *lua) { thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_STR; if (data_size) { tb_buffer_memncpy(&thread_sharedata->buffer, (tb_byte_t const *)data, data_size); - } - else { + } else { tb_buffer_clear(&thread_sharedata->buffer); } } else if (xm_lua_isinteger(lua, 2)) { -- cgit v1.3.1 From bf2da8a3d7f04bf5ffcdce8fd4c334d5421d3494 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 22:34:50 +0800 Subject: format core --- core/src/xmake/engine.c | 94 ++++++++++++++++++++++-------------- core/src/xmake/io/file_close.c | 6 ++- core/src/xmake/io/file_flush.c | 6 ++- core/src/xmake/io/file_isatty.c | 3 +- core/src/xmake/io/file_open.c | 90 +++++++++++++++++++--------------- core/src/xmake/io/file_rawfd.c | 3 +- core/src/xmake/io/file_read.c | 89 +++++++++++++++++++++------------- core/src/xmake/io/file_readable.c | 8 +-- core/src/xmake/io/file_seek.c | 14 ++++-- core/src/xmake/io/file_size.c | 6 ++- core/src/xmake/io/file_write.c | 16 +++--- core/src/xmake/io/filelock_close.c | 3 +- core/src/xmake/io/filelock_lock.c | 3 +- core/src/xmake/io/filelock_open.c | 8 +-- core/src/xmake/io/filelock_trylock.c | 3 +- core/src/xmake/io/filelock_unlock.c | 3 +- core/src/xmake/io/iscygpty.c | 6 ++- core/src/xmake/io/pipe_close.c | 3 +- core/src/xmake/io/pipe_open.c | 11 +++-- core/src/xmake/io/pipe_openpair.c | 6 ++- core/src/xmake/io/pipe_read.c | 6 ++- core/src/xmake/io/pipe_wait.c | 3 +- core/src/xmake/io/pipe_write.c | 6 ++- core/src/xmake/io/poller.c | 3 +- core/src/xmake/io/poller_wait.c | 8 +-- core/src/xmake/io/socket_accept.c | 8 +-- core/src/xmake/io/socket_close.c | 3 +- core/src/xmake/io/socket_kill.c | 3 +- core/src/xmake/io/socket_listen.c | 3 +- core/src/xmake/io/socket_open.c | 5 +- core/src/xmake/io/socket_peeraddr.c | 8 +-- core/src/xmake/io/socket_recv.c | 6 ++- core/src/xmake/io/socket_recvfrom.c | 6 ++- core/src/xmake/io/socket_send.c | 6 ++- core/src/xmake/io/socket_sendfile.c | 6 ++- core/src/xmake/io/socket_sendto.c | 6 ++- core/src/xmake/io/socket_wait.c | 3 +- core/src/xmake/io/stdfile.c | 14 ++++-- core/src/xmake/xmake.c | 6 ++- 39 files changed, 307 insertions(+), 183 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 7a07d72da..0405fc230 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -898,18 +898,20 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t *engine, return tb_true; } - tb_bool_t ok = tb_false; + tb_bool_t ok = tb_false; tb_char_t data[TB_PATH_MAXN] = { 0 }; do { #ifdef XM_EMBED_ENABLE tb_size_t embedcount = engine->embedcount; if (embedcount) { tb_uint32_t crc32 = 0; - for (tb_size_t i = 0; i < embedcount; i++) + for (tb_size_t i = 0; i < embedcount; i++) { crc32 += tb_crc32_make(engine->embeddata[i], engine->embedsize[i], 0); + } tb_snprintf(path, maxn, "%s/%x", engine->tmpdir, crc32); - } else + } else { tb_strlcpy(path, engine->tmpdir, maxn); + } ok = tb_true; break; #endif @@ -1011,8 +1013,9 @@ static tb_bool_t xm_engine_get_project_directory(xm_engine_t *engine, tb_char_t } while (0); // failed? - if (!ok) + if (!ok) { tb_printf("error: not found the project directory!\n"); + } return ok; } @@ -1054,12 +1057,13 @@ static tb_void_t xm_engine_init_host(xm_engine_t *engine) { #if defined(__COSMOPOLITAN__) struct utsname buffer; if (uname(&buffer) == 0) { - if (tb_strstr(buffer.sysname, "Darwin")) + if (tb_strstr(buffer.sysname, "Darwin")) { syshost = "macosx"; - else if (tb_strstr(buffer.sysname, "Linux")) + } else if (tb_strstr(buffer.sysname, "Linux")) { syshost = "linux"; - else if (tb_strstr(buffer.sysname, "Windows")) + } else if (tb_strstr(buffer.sysname, "Windows")) { syshost = "windows"; + } } #elif defined(TB_CONFIG_OS_WINDOWS) syshost = "windows"; @@ -1096,8 +1100,9 @@ static tb_void_t xm_engine_init_host(xm_engine_t *engine) { "clang", 5) // clang32/64 on msys2, @see https://github.com/xmake-io/xmake/issues/3060 || !tb_stricmp(data, "ucrt64") // ucrt64 https://www.msys2.org/docs/environments/ - || !tb_stricmp(data, "msys")) // on msys2 + || !tb_stricmp(data, "msys")) { // on msys2 subhost = "msys"; + } } } #endif @@ -1145,12 +1150,14 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { if (uname(&buffer) == 0) { sysarch = buffer.machine; if (tb_strstr(buffer.sysname, "Windows")) { - if (!tb_strcmp(buffer.machine, "x86_64")) + if (!tb_strcmp(buffer.machine, "x86_64")) { sysarch = "x64"; - else if (!tb_strcmp(buffer.machine, "i686") || !tb_strcmp(buffer.machine, "i386")) + } else if (!tb_strcmp(buffer.machine, "i686") || !tb_strcmp(buffer.machine, "i386")) { sysarch = "x86"; - } else if (!tb_strcmp(buffer.machine, "aarch64")) + } + } else if (!tb_strcmp(buffer.machine, "aarch64")) { sysarch = "arm64"; + } } #elif defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) // the GetNativeSystemInfo function type @@ -1160,12 +1167,14 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { SYSTEM_INFO systeminfo = { 0 }; GetNativeSystemInfo_t pGetNativeSystemInfo = tb_null; tb_dynamic_ref_t kernel32 = tb_dynamic_init("kernel32.dll"); - if (kernel32) + if (kernel32) { pGetNativeSystemInfo = (GetNativeSystemInfo_t)tb_dynamic_func(kernel32, "GetNativeSystemInfo"); - if (pGetNativeSystemInfo) + } + if (pGetNativeSystemInfo) { pGetNativeSystemInfo(&systeminfo); - else + } else { GetSystemInfo(&systeminfo); + } // init architecture switch (systeminfo.wProcessorArchitecture) { @@ -1187,8 +1196,9 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { break; } #endif - if (!sysarch) + if (!sysarch) { sysarch = xmakearch; + } lua_pushstring(engine->lua, sysarch); lua_setglobal(engine->lua, "_ARCH"); @@ -1198,10 +1208,11 @@ static tb_void_t xm_engine_init_arch(xm_engine_t *engine) { // get architecture from msys environment tb_char_t data[64] = { 0 }; if (tb_environment_first("MSYSTEM_CARCH", data, sizeof(data))) { - if (!tb_strcmp(data, "i686")) + if (!tb_strcmp(data, "i686")) { subarch = "i386"; - else + } else { subarch = data; + } } #endif lua_pushstring(engine->lua, subarch); @@ -1238,8 +1249,9 @@ static tb_void_t xm_engine_init_features(xm_engine_t *engine) { static tb_void_t xm_engine_init_signal(xm_engine_t *engine) { // we enable it to catch the current lua stack in ctrl-c signal handler if XMAKE_PROFILE=stuck tb_char_t data[64] = { 0 }; - if (!tb_environment_first("XMAKE_PROFILE", data, sizeof(data)) || tb_strcmp(data, "stuck")) + if (!tb_environment_first("XMAKE_PROFILE", data, sizeof(data)) || tb_strcmp(data, "stuck")) { return; + } g_lua = engine->lua; #if defined(TB_CONFIG_OS_WINDOWS) @@ -1253,14 +1265,15 @@ static tb_void_t xm_engine_init_signal(xm_engine_t *engine) { // udata is unused, it has been used by engine. see xm_engine_bind_to_lua() static tb_pointer_t xm_engine_lua_realloc(tb_pointer_t udata, tb_pointer_t data, size_t osize, size_t nsize) { tb_pointer_t ptr = tb_null; - if (nsize == 0 && data) + if (nsize == 0 && data) { tb_free(data); - else if (!data) + } else if (!data) { ptr = tb_malloc((tb_size_t)nsize); - else if (nsize != osize) + } else if (nsize != osize) { ptr = tb_ralloc(data, (tb_size_t)nsize); - else + } else { ptr = data; + } return ptr; } #endif @@ -1293,8 +1306,9 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t *engine, break; } - if (buffer_size == 0) + if (buffer_size == 0) { break; + } data += advance; size -= advance; @@ -1428,10 +1442,12 @@ static tb_bool_t xm_engine_load_main_script(xm_engine_t *engine, tb_char_t const } while (0); - if (data) + if (data) { tb_free(data); - if (file) + } + if (file) { tb_file_exit(file); + } return ok; #else if (luaL_dofile(engine->lua, mainfile)) { @@ -1560,7 +1576,7 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c // init version string tb_char_t version_cstr[256] = { 0 }; - if (tb_strcmp(XM_CONFIG_VERSION_BRANCH, "") && tb_strcmp(XM_CONFIG_VERSION_COMMIT, "")) + if (tb_strcmp(XM_CONFIG_VERSION_BRANCH, "") && tb_strcmp(XM_CONFIG_VERSION_COMMIT, "")) { tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u+%s.%s", @@ -1569,14 +1585,15 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c version->alter, XM_CONFIG_VERSION_BRANCH, XM_CONFIG_VERSION_COMMIT); - else + } else { tb_snprintf(version_cstr, sizeof(version_cstr), "%u.%u.%u+%llu", version->major, version->minor, version->alter, - version->build); + (unsigned long long)version->build); + } lua_pushstring(engine->lua, version_cstr); lua_setglobal(engine->lua, "_VERSION"); @@ -1615,8 +1632,9 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c * we can get the lni modules for _lni or `import("lib.lni.xxx")` in sandbox */ lua_newtable(engine->lua); - if (lni_initalizer) + if (lni_initalizer) { lni_initalizer((xm_engine_ref_t)engine, engine->lua); + } lua_setglobal(engine->lua, "_lni"); #ifdef TB_CONFIG_OS_WINDOWS @@ -1626,8 +1644,9 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c DWORD mode; if (GetConsoleMode(output, &mode)) { // attempt to enable 0x4: ENABLE_VIRTUAL_TERMINAL_PROCESSING - if (SetConsoleMode(output, mode | 0x4)) + if (SetConsoleMode(output, mode | 0x4)) { tb_environment_set("COLORTERM", "color256"); + } } } #endif @@ -1636,8 +1655,9 @@ xm_engine_ref_t xm_engine_init(tb_char_t const *name, xm_engine_lni_initalizer_c } while (0); if (!ok) { - if (engine) + if (engine) { xm_engine_exit((xm_engine_ref_t)engine); + } engine = tb_null; } return (xm_engine_ref_t)engine; @@ -1647,13 +1667,15 @@ tb_void_t xm_engine_exit(xm_engine_ref_t self) { tb_assert_and_check_return(engine); // exit lua - if (engine->lua) + if (engine->lua) { lua_close(engine->lua); + } engine->lua = tb_null; // exit poller - if (engine->poller) + if (engine->poller) { tb_poller_exit(engine->poller); + } engine->poller = tb_null; // exit it @@ -1665,13 +1687,15 @@ tb_int_t xm_engine_main(xm_engine_ref_t self, tb_int_t argc, tb_char_t **argv, t #if defined(TB_CONFIG_OS_WINDOWS) && defined(TB_COMPILER_IS_MSVC) // set "stdin" to have unicode mode - if (_isatty(_fileno(stdin))) + if (_isatty(_fileno(stdin))) { _setmode(_fileno(stdin), _O_U16TEXT); + } #endif // save main arguments to the global variable: _ARGV - if (!xm_engine_save_arguments(engine, argc, argv, taskargv)) + if (!xm_engine_save_arguments(engine, argc, argv, taskargv)) { return -1; + } // get the project directory tb_char_t path[TB_PATH_MAXN] = { 0 }; diff --git a/core/src/xmake/io/file_close.c b/core/src/xmake/io/file_close.c index 6547b8156..cbcb237af 100644 --- a/core/src/xmake/io/file_close.c +++ b/core/src/xmake/io/file_close.c @@ -72,13 +72,15 @@ tb_int_t xm_io_file_close(lua_State *lua) { file->u.file_ref = tb_null; // exit fstream - if (file->fstream) + if (file->fstream) { tb_stream_exit(file->fstream); + } file->fstream = tb_null; // exit stream - if (file->stream) + if (file->stream) { tb_stream_exit(file->stream); + } file->stream = tb_null; // exit the line cache buffer diff --git a/core/src/xmake/io/file_flush.c b/core/src/xmake/io/file_flush.c index e5776a60e..73652ce20 100644 --- a/core/src/xmake/io/file_flush.c +++ b/core/src/xmake/io/file_flush.c @@ -63,8 +63,9 @@ tb_int_t xm_io_file_flush(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "flush(invalid file)!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); @@ -75,6 +76,7 @@ tb_int_t xm_io_file_flush(lua_State *lua) { if (ok) { lua_pushboolean(lua, tb_true); return 1; - } else + } else { xm_io_return_error(lua, "failed to flush file"); + } } diff --git a/core/src/xmake/io/file_isatty.c b/core/src/xmake/io/file_isatty.c index 264cabd53..4f6bf4272 100644 --- a/core/src/xmake/io/file_isatty.c +++ b/core/src/xmake/io/file_isatty.c @@ -39,8 +39,9 @@ tb_int_t xm_io_file_isatty(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "isatty(invalid file)!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); diff --git a/core/src/xmake/io/file_open.c b/core/src/xmake/io/file_open.c index f4a080077..901a3f86d 100644 --- a/core/src/xmake/io/file_open.c +++ b/core/src/xmake/io/file_open.c @@ -50,8 +50,9 @@ static tb_size_t xm_io_file_detect_charset(tb_byte_t const **data_ptr, tb_long_t tb_size_t charset = XM_IO_FILE_ENCODING_BINARY; do { // is luajit bitcode? open as binary - if (size >= 3 && data[0] == 27 && data[1] == 'L' && data[2] == 'J') + if (size >= 3 && data[0] == 27 && data[1] == 'L' && data[2] == 'J') { break; + } // utf-8 with bom if (size >= 3 && data[0] == 239 && data[1] == 187 && data[2] == 191) { @@ -80,34 +81,39 @@ static tb_size_t xm_io_file_detect_charset(tb_byte_t const **data_ptr, tb_long_t tb_sint16_t ascii_conf = 0; tb_sint16_t zero_count = 0; for (tb_long_t i = 0; i < (size - 4) && i < CHECK_SIZE; i++) { - if (data[i] == 0) + if (data[i] == 0) { zero_count++; + } - if (data[i] < 0x80) + if (data[i] < 0x80) { ascii_conf++; - else + } else { ascii_conf = TB_MINS16; + } if (i % 2 == 0) { - if (data[i] == 0) + if (data[i] == 0) { utf16be_conf++; - if (data[i + 1] == 0) + } + if (data[i + 1] == 0) { utf16le_conf++; + } } - if (IS_UTF8_TAIL(data[i])) - ; - else if (data[i] < 0x80) + if (IS_UTF8_TAIL(data[i])) { + // continue + } else if (data[i] < 0x80) { utf8_conf++; - else if (data[i] >= 0xc0 && data[i] < 0xe0 && IS_UTF8_TAIL(data[i + 1])) + } else if (data[i] >= 0xc0 && data[i] < 0xe0 && IS_UTF8_TAIL(data[i + 1])) { utf8_conf++; - else if (data[i] >= 0xe0 && data[i] < 0xf0 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2])) + } else if (data[i] >= 0xe0 && data[i] < 0xf0 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2])) { utf8_conf++; - else if (data[i] >= 0xf0 && data[i] < 0xf8 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2]) && - IS_UTF8_TAIL(data[i + 3])) + } else if (data[i] >= 0xf0 && data[i] < 0xf8 && IS_UTF8_TAIL(data[i + 1]) && IS_UTF8_TAIL(data[i + 2]) && + IS_UTF8_TAIL(data[i + 3])) { utf8_conf++; - else + } else { utf8_conf = TB_MINS16; + } } if (ascii_conf > 0 && zero_count <= 1) { @@ -188,44 +194,46 @@ tb_int_t xm_io_file_open(lua_State *lua) { tb_stream_ref_t stream = tb_null; tb_bool_t update = !!tb_strchr(modestr, '+'); tb_size_t encoding = XM_IO_FILE_ENCODING_UNKNOWN; - if (modestr[1] == 'b' || (update && modestr[2] == 'b')) + if (modestr[1] == 'b' || (update && modestr[2] == 'b')) { encoding = XM_IO_FILE_ENCODING_BINARY; - else if (tb_strstr(modestr, "utf8") || tb_strstr(modestr, "utf-8")) + } else if (tb_strstr(modestr, "utf8") || tb_strstr(modestr, "utf-8")) { encoding = TB_CHARSET_TYPE_UTF8; - else if (tb_strstr(modestr, "utf16le") || tb_strstr(modestr, "utf-16le")) + } else if (tb_strstr(modestr, "utf16le") || tb_strstr(modestr, "utf-16le")) { encoding = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_LE; - else if (tb_strstr(modestr, "utf16be") || tb_strstr(modestr, "utf-16be")) + } else if (tb_strstr(modestr, "utf16be") || tb_strstr(modestr, "utf-16be")) { encoding = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_BE; - else if (tb_strstr(modestr, "utf16") || tb_strstr(modestr, "utf-16")) + } else if (tb_strstr(modestr, "utf16") || tb_strstr(modestr, "utf-16")) { encoding = TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_NE; - else if (tb_strstr(modestr, "ansi")) + } else if (tb_strstr(modestr, "ansi")) { encoding = TB_CHARSET_TYPE_ANSI; - else if (tb_strstr(modestr, "gbk")) + } else if (tb_strstr(modestr, "gbk")) { encoding = TB_CHARSET_TYPE_GBK; - else if (tb_strstr(modestr, "gb2312")) + } else if (tb_strstr(modestr, "gb2312")) { encoding = TB_CHARSET_TYPE_GB2312; - else if (tb_strstr(modestr, "iso8859")) + } else if (tb_strstr(modestr, "iso8859")) { encoding = TB_CHARSET_TYPE_ISO8859; - else if (modestr[0] == 'w' || modestr[0] == 'a') // set to utf-8 if not specified for the writing mode + } else if (modestr[0] == 'w' || modestr[0] == 'a') { // set to utf-8 if not specified for the writing mode encoding = TB_CHARSET_TYPE_UTF8; - else if (modestr[0] == 'r') // detect encoding if not specified for the reading mode - { + } else if (modestr[0] == 'r') { // detect encoding if not specified for the reading mode stream = tb_stream_init_from_file(path, mode); - if (stream && tb_stream_open(stream)) + if (stream && tb_stream_open(stream)) { encoding = xm_io_file_detect_encoding(stream, &bomoff); - else { - if (stream) + } else { + if (stream) { tb_stream_exit(stream); + } xm_io_return_error(lua, "file not found!"); } - } else + } else { xm_io_return_error(lua, "invalid open mode!"); + } tb_assert_and_check_return_val(encoding != XM_IO_FILE_ENCODING_UNKNOWN, 0); // write data with utf bom? e.g. utf8bom, utf16lebom, utf16bom tb_bool_t utfbom = tb_false; - if (tb_strstr(modestr, "bom")) + if (tb_strstr(modestr, "bom")) { utfbom = tb_true; + } // open file tb_bool_t open_ok = tb_false; @@ -239,24 +247,28 @@ tb_int_t xm_io_file_open(lua_State *lua) { // is transcode? tb_bool_t is_transcode = encoding != TB_CHARSET_TYPE_UTF8 && encoding != XM_IO_FILE_ENCODING_BINARY; if (is_transcode) { - if (modestr[0] == 'r') + if (modestr[0] == 'r') { fstream = tb_stream_init_filter_from_charset(stream, encoding, TB_CHARSET_TYPE_UTF8); - else + } else { fstream = tb_stream_init_filter_from_charset(stream, TB_CHARSET_TYPE_UTF8, encoding); + } tb_assert_and_check_break(fstream); // use fstream as file file_ref = fstream; - } else + } else { file_ref = stream; + } // open file stream - if (!tb_stream_open(file_ref)) + if (!tb_stream_open(file_ref)) { break; + } // skip bom characters if exists - if (bomoff > 0 && !tb_stream_seek(stream, bomoff)) + if (bomoff > 0 && !tb_stream_seek(stream, bomoff)) { break; + } open_ok = tb_true; @@ -265,13 +277,15 @@ tb_int_t xm_io_file_open(lua_State *lua) { // open failed? if (!open_ok) { // exit stream - if (stream) + if (stream) { tb_stream_exit(stream); + } stream = tb_null; // exit charset stream filter - if (fstream) + if (fstream) { tb_stream_exit(fstream); + } fstream = tb_null; // return errors diff --git a/core/src/xmake/io/file_rawfd.c b/core/src/xmake/io/file_rawfd.c index c94dc4a98..419955118 100644 --- a/core/src/xmake/io/file_rawfd.c +++ b/core/src/xmake/io/file_rawfd.c @@ -55,8 +55,9 @@ tb_int_t xm_io_file_rawfd(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "get rawfd for invalid file!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c index 2be05a05a..0b255f4c1 100644 --- a/core/src/xmake/io/file_read.c +++ b/core/src/xmake/io/file_read.c @@ -79,10 +79,11 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re } tb_size_t linesize = tb_buffer_size(line); - if (linesize) + if (linesize) { return linesize; - else + } else { return (eof || tb_stream_beof(stream)) ? -1 : 0; + } } static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t *file, @@ -122,9 +123,9 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, tb_assert_and_check_break(data); // no lf found - if (size > 0 && data[size - 1] != '\n') + if (size > 0 && data[size - 1] != '\n') { result = PL_FIN; - else if (size > 1) { + } else if (size > 1) { // crlf? => lf if (!is_binary && data[size - 2] == '\r') { data[size - 2] = '\n'; @@ -137,27 +138,31 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, 0; // do not keep crlf, strip the last lf - if (!keep_crlf && !has_conline) + if (!keep_crlf && !has_conline) { size--; + } // strip it if has continuation? - if (has_conline) + if (has_conline) { size -= conlen + 1; + } data[size] = '\0'; result = has_conline ? PL_CONL : PL_FIN; } else { // a single '\n' - if (!keep_crlf) + if (!keep_crlf) { size = 0; + } result = PL_FIN; } } while (0); // push line data - if (data && size > 0 && (result == PL_FIN || result == PL_CONL)) + if (data && size > 0 && (result == PL_FIN || result == PL_CONL)) { tb_buffer_memncat(buf, (tb_byte_t const *)data, size); + } // return result return result; @@ -167,8 +172,9 @@ static tb_int_t xm_io_file_read_all_directly(lua_State *lua, xm_io_file_t *file) // init buffer tb_buffer_t buf; - if (!tb_buffer_init(&buf)) + if (!tb_buffer_init(&buf)) { xm_io_return_error(lua, "init buffer failed!"); + } tb_byte_t *data = tb_buffer_resize(&file->rcache, XM_IO_BLOCK_MAXN); if (!data) { @@ -180,19 +186,21 @@ static tb_int_t xm_io_file_read_all_directly(lua_State *lua, xm_io_file_t *file) tb_stream_ref_t stream = file->u.file_ref; while (!tb_stream_beof(stream)) { tb_long_t real = tb_stream_read(stream, data, XM_IO_BLOCK_MAXN); - if (real > 0) + if (real > 0) { tb_buffer_memncat(&buf, data, real); - else if (!real) { + } else if (!real) { real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, -1); tb_check_break(real > 0); - } else + } else { break; + } } - if (tb_buffer_size(&buf)) + if (tb_buffer_size(&buf)) { lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); - else + } else { lua_pushliteral(lua, ""); + } tb_buffer_exit(&buf); return 1; } @@ -201,23 +209,26 @@ static tb_int_t xm_io_file_read_all(lua_State *lua, xm_io_file_t *file, tb_char_ // is binary? read all directly tb_bool_t is_binary = file->encoding == XM_IO_FILE_ENCODING_BINARY; - if (is_binary) + if (is_binary) { return xm_io_file_read_all_directly(lua, file); + } // init buffer tb_buffer_t buf; - if (!tb_buffer_init(&buf)) + if (!tb_buffer_init(&buf)) { xm_io_return_error(lua, "init buffer failed!"); + } // read all tb_bool_t has_content = tb_false; while (1) { switch (xm_io_file_buffer_pushline(&buf, file, continuation, tb_true)) { case PL_EOF: - if (!has_content) + if (!has_content) { lua_pushliteral(lua, ""); - else + } else { lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); + } tb_buffer_exit(&buf); return 1; case PL_FIN: @@ -241,18 +252,20 @@ static tb_int_t xm_io_file_read_line(lua_State *lua, // init buffer tb_buffer_t buf; - if (!tb_buffer_init(&buf)) + if (!tb_buffer_init(&buf)) { xm_io_return_error(lua, "init buffer failed!"); + } // read line tb_bool_t has_content = tb_false; while (1) { switch (xm_io_file_buffer_pushline(&buf, file, continuation, keep_crlf)) { case PL_EOF: - if (!has_content) + if (!has_content) { lua_pushnil(lua); - else + } else { lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); + } tb_buffer_exit(&buf); return 1; case PL_FIN: @@ -275,12 +288,14 @@ static tb_int_t xm_io_file_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref); // check continuation - if (*continuation != '\0') + if (*continuation != '\0') { xm_io_return_error(lua, "continuation is not supported for read number of bytes"); + } // check encoding - if (file->encoding != XM_IO_FILE_ENCODING_BINARY) + if (file->encoding != XM_IO_FILE_ENCODING_BINARY) { xm_io_return_error(lua, "read number of bytes only allows binary file, reopen with 'rb' and try again"); + } tb_bool_t ok = tb_false; if (n == 0) { @@ -298,8 +313,9 @@ static tb_int_t xm_io_file_read_n(lua_State *lua, xm_io_file_t *file, tb_char_t } } } - if (!ok) + if (!ok) { lua_pushnil(lua); + } return 1; } @@ -313,10 +329,11 @@ static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, tb_char_t strbuf[8192]; tb_size_t buflen = 0; tb_size_t result = PL_FAIL; - if (tb_stdfile_gets(file->u.std_ref, strbuf, tb_arrayn(strbuf) - 1)) + if (tb_stdfile_gets(file->u.std_ref, strbuf, tb_arrayn(strbuf) - 1)) { buflen = tb_strlen(strbuf); - else + } else { return PL_EOF; + } tb_size_t conlen = tb_strlen(continuation); if (buflen > 0 && strbuf[buflen - 1] != '\n') { @@ -334,24 +351,28 @@ static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, tb_strncmp(continuation, (strbuf + buflen - conlen - 1), conlen) == 0; // do not keep crlf, strip the last lf - if (!keep_crlf && !has_conline) + if (!keep_crlf && !has_conline) { buflen--; + } // strip it if has continuation? - if (has_conline) + if (has_conline) { buflen -= conlen + 1; + } strbuf[buflen] = '\0'; result = has_conline ? PL_CONL : PL_FIN; } else { // a single '\n' - if (!keep_crlf) + if (!keep_crlf) { buflen = 0; + } result = PL_FIN; } - if (result == PL_FIN || result == PL_CONL) + if (result == PL_FIN || result == PL_CONL) { tb_buffer_memncat(buf, (tb_byte_t const *)strbuf, buflen); + } return result; } @@ -363,18 +384,20 @@ static tb_int_t xm_io_file_std_read_line(lua_State *lua, // init buffer tb_buffer_t buf; - if (!tb_buffer_init(&buf)) + if (!tb_buffer_init(&buf)) { xm_io_return_error(lua, "init buffer failed!"); + } // read line tb_bool_t has_content = tb_false; while (1) { switch (xm_io_file_std_buffer_pushline(&buf, file, continuation, keep_crlf)) { case PL_EOF: - if (!has_content) + if (!has_content) { lua_pushnil(lua); - else + } else { lua_pushlstring(lua, (tb_char_t const *)tb_buffer_data(&buf), tb_buffer_size(&buf)); + } tb_buffer_exit(&buf); return 1; case PL_FIN: diff --git a/core/src/xmake/io/file_readable.c b/core/src/xmake/io/file_readable.c index 5f9a84329..78ea82888 100644 --- a/core/src/xmake/io/file_readable.c +++ b/core/src/xmake/io/file_readable.c @@ -38,8 +38,9 @@ tb_int_t xm_io_file_readable(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "read(invalid file)!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); @@ -47,10 +48,11 @@ tb_int_t xm_io_file_readable(lua_State *lua) { // has readable data? tb_bool_t ok = tb_false; - if (xm_io_file_is_file(file)) + if (xm_io_file_is_file(file)) { ok = tb_stream_left(file->u.file_ref) > 0; - else + } else { ok = tb_stdfile_readable(file->u.std_ref); + } lua_pushboolean(lua, ok); return 1; } diff --git a/core/src/xmake/io/file_seek.c b/core/src/xmake/io/file_seek.c index 421e5cdf1..c7c043e7a 100644 --- a/core/src/xmake/io/file_seek.c +++ b/core/src/xmake/io/file_seek.c @@ -39,8 +39,9 @@ tb_int_t xm_io_file_seek(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "seek(invalid file)!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); @@ -60,10 +61,11 @@ tb_int_t xm_io_file_seek(lua_State *lua) { case 'e': // "end" { tb_hong_t size = tb_stream_size(file->u.file_ref); - if (size > 0 && size + offset <= size) + if (size > 0 && size + offset <= size) { offset = size + offset; - else + } else { xm_io_return_error(lua, "seek failed, invalid offset!"); + } } break; default: // "cur" offset = tb_stream_offset(file->u.file_ref) + offset; @@ -73,8 +75,10 @@ tb_int_t xm_io_file_seek(lua_State *lua) { if (tb_stream_seek(file->u.file_ref, offset)) { lua_pushnumber(lua, (lua_Number)offset); return 1; - } else + } else { xm_io_return_error(lua, "seek failed!"); - } else + } + } else { xm_io_return_error(lua, "seek is not supported on this file"); + } } diff --git a/core/src/xmake/io/file_size.c b/core/src/xmake/io/file_size.c index 34f519306..351bd7ebf 100644 --- a/core/src/xmake/io/file_size.c +++ b/core/src/xmake/io/file_size.c @@ -39,8 +39,9 @@ tb_int_t xm_io_file_size(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is user data? - if (!lua_isuserdata(lua, 1)) + if (!lua_isuserdata(lua, 1)) { xm_io_return_error(lua, "get size for invalid file!"); + } // get file xm_io_file_t *file = (xm_io_file_t *)lua_touserdata(lua, 1); @@ -52,6 +53,7 @@ tb_int_t xm_io_file_size(lua_State *lua) { tb_assert(file->stream); lua_pushnumber(lua, (lua_Number)tb_stream_size(file->stream)); return 1; - } else + } else { xm_io_return_error(lua, "get size for invalid file!"); + } } diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c index 5f70e1a49..08655379a 100644 --- a/core/src/xmake/io/file_write.c +++ b/core/src/xmake/io/file_write.c @@ -137,21 +137,23 @@ tb_int_t xm_io_file_write(lua_State *lua) { // get data size_t datasize = 0; tb_byte_t const *data = tb_null; - if (lua_isstring(lua, i)) + if (lua_isstring(lua, i)) { data = (tb_byte_t const *)luaL_checklstring(lua, i, &datasize); - else if (lua_istable(lua, i)) { + } else if (lua_istable(lua, i)) { // get bytes data lua_pushstring(lua, "data"); lua_gettable(lua, i); - if (xm_lua_isinteger(lua, -1)) + if (xm_lua_isinteger(lua, -1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, -1); + } lua_pop(lua, 1); tb_assert_static(sizeof(lua_Integer) >= sizeof(tb_pointer_t)); lua_pushstring(lua, "size"); lua_gettable(lua, i); - if (xm_lua_isinteger(lua, -1)) + if (xm_lua_isinteger(lua, -1)) { datasize = (tb_size_t)lua_tointeger(lua, -1); + } lua_pop(lua, 1); // mark as binary data @@ -162,11 +164,11 @@ tb_int_t xm_io_file_write(lua_State *lua) { tb_assert_and_check_break(data); // write data to std or file - if (xm_io_file_is_std(file)) + if (xm_io_file_is_std(file)) { xm_io_file_write_std(file, data, (tb_size_t)datasize); - else if (is_binary) + } else if (is_binary) { xm_io_file_write_file_directly(file, data, (tb_size_t)datasize); - else { + } else { // write utf bom first? if (file->utfbom) { xm_io_file_write_file_utfbom(file); diff --git a/core/src/xmake/io/filelock_close.c b/core/src/xmake/io/filelock_close.c index 02a2fb039..69bea4e39 100644 --- a/core/src/xmake/io/filelock_close.c +++ b/core/src/xmake/io/filelock_close.c @@ -39,8 +39,9 @@ tb_int_t xm_io_filelock_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check lock? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get lock tb_filelock_ref_t lock = (tb_filelock_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/filelock_lock.c b/core/src/xmake/io/filelock_lock.c index 9e0c2493e..070af2eaf 100644 --- a/core/src/xmake/io/filelock_lock.c +++ b/core/src/xmake/io/filelock_lock.c @@ -53,8 +53,9 @@ tb_int_t xm_io_filelock_lock(lua_State *lua) { } // check lock? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get lock tb_filelock_ref_t lock = (tb_filelock_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/filelock_open.c b/core/src/xmake/io/filelock_open.c index e9687ba54..2afb173d3 100644 --- a/core/src/xmake/io/filelock_open.c +++ b/core/src/xmake/io/filelock_open.c @@ -47,13 +47,15 @@ tb_int_t xm_io_filelock_open(lua_State *lua) { // init file lock tb_long_t tryn = 2; tb_filelock_ref_t lock = tb_null; - while (!lock && tryn-- > 0) + while (!lock && tryn-- > 0) { lock = tb_filelock_init_from_path(path, tb_file_info(path, tb_null) ? TB_FILE_MODE_RW : TB_FILE_MODE_RW | TB_FILE_MODE_CREAT); - if (lock) + } + if (lock) { xm_lua_pushpointer(lua, (tb_pointer_t)lock); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/filelock_trylock.c b/core/src/xmake/io/filelock_trylock.c index aaf1da246..d84024834 100644 --- a/core/src/xmake/io/filelock_trylock.c +++ b/core/src/xmake/io/filelock_trylock.c @@ -53,8 +53,9 @@ tb_int_t xm_io_filelock_trylock(lua_State *lua) { } // check lock? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get lock tb_filelock_ref_t lock = (tb_filelock_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/filelock_unlock.c b/core/src/xmake/io/filelock_unlock.c index 94dfe1b7d..007bedd54 100644 --- a/core/src/xmake/io/filelock_unlock.c +++ b/core/src/xmake/io/filelock_unlock.c @@ -39,8 +39,9 @@ tb_int_t xm_io_filelock_unlock(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check lock? - if (!xm_lua_topointer(lua, 1)) + if (!xm_lua_topointer(lua, 1)) { return 0; + } // get lock tb_filelock_ref_t lock = (tb_filelock_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/iscygpty.c b/core/src/xmake/io/iscygpty.c index e78a9d8cb..656e86fe7 100644 --- a/core/src/xmake/io/iscygpty.c +++ b/core/src/xmake/io/iscygpty.c @@ -131,8 +131,9 @@ int is_cygpty(HANDLE h) { p = NULL; } if (p != NULL) { - while (*p && isxdigit(*p)) /* Skip 16-digit hexadecimal. */ + while (*p && isxdigit(*p)) { /* Skip 16-digit hexadecimal. */ ++p; + } if (is_wprefix(p, L"-pty")) { p += 4; } else { @@ -140,8 +141,9 @@ int is_cygpty(HANDLE h) { } } if (p != NULL) { - while (*p && isdigit(*p)) /* Skip pty number. */ + while (*p && isdigit(*p)) { /* Skip pty number. */ ++p; + } if (is_wprefix(p, L"-from-master")) { //p += 12; } else if (is_wprefix(p, L"-to-master")) { diff --git a/core/src/xmake/io/pipe_close.c b/core/src/xmake/io/pipe_close.c index 23e200606..aaf708a31 100644 --- a/core/src/xmake/io/pipe_close.c +++ b/core/src/xmake/io/pipe_close.c @@ -39,8 +39,9 @@ tb_int_t xm_io_pipe_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check pipe? - if (!xm_pipe_file_is_valid(lua, 1)) + if (!xm_pipe_file_is_valid(lua, 1)) { return 0; + } // get the pipe file tb_pipe_file_ref_t pipefile = xm_pipe_file_get(lua, 1); diff --git a/core/src/xmake/io/pipe_open.c b/core/src/xmake/io/pipe_open.c index d82406dee..6bfe26347 100644 --- a/core/src/xmake/io/pipe_open.c +++ b/core/src/xmake/io/pipe_open.c @@ -47,21 +47,24 @@ tb_int_t xm_io_pipe_open(lua_State *lua) { // get pipe mode value tb_size_t mode = TB_PIPE_MODE_RO; - if (modestr[0] == 'w') + if (modestr[0] == 'w') { mode = TB_PIPE_MODE_WO; + } // set block mode - if (modestr[1] == 'B') + if (modestr[1] == 'B') { mode |= TB_PIPE_MODE_BLOCK; + } // get buffer size tb_size_t buffsize = (tb_size_t)luaL_checknumber(lua, 3); // open pipe file tb_pipe_file_ref_t pipefile = tb_pipe_file_init(name, mode, buffsize); - if (pipefile) + if (pipefile) { xm_lua_pushpointer(lua, (tb_pointer_t)pipefile); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/pipe_openpair.c b/core/src/xmake/io/pipe_openpair.c index dd2205613..bf4829f6c 100644 --- a/core/src/xmake/io/pipe_openpair.c +++ b/core/src/xmake/io/pipe_openpair.c @@ -46,10 +46,12 @@ tb_int_t xm_io_pipe_openpair(lua_State *lua) { // init mode tb_size_t mode[2] = { 0 }; - if (modestr[0] == 'B') + if (modestr[0] == 'B') { mode[0] |= TB_PIPE_MODE_BLOCK; - if (modestr[1] == 'B') + } + if (modestr[1] == 'B') { mode[1] |= TB_PIPE_MODE_BLOCK; + } // get buffer size tb_size_t buffsize = (tb_size_t)luaL_checknumber(lua, 2); diff --git a/core/src/xmake/io/pipe_read.c b/core/src/xmake/io/pipe_read.c index 637fb3b7d..e0e383bfb 100644 --- a/core/src/xmake/io/pipe_read.c +++ b/core/src/xmake/io/pipe_read.c @@ -51,8 +51,9 @@ tb_int_t xm_io_pipe_read(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + } if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); @@ -62,8 +63,9 @@ tb_int_t xm_io_pipe_read(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/io/pipe_wait.c b/core/src/xmake/io/pipe_wait.c index 785efe950..d2979dcdd 100644 --- a/core/src/xmake/io/pipe_wait.c +++ b/core/src/xmake/io/pipe_wait.c @@ -39,8 +39,9 @@ tb_int_t xm_io_pipe_wait(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check pipe? - if (!xm_pipe_file_is_valid(lua, 1)) + if (!xm_pipe_file_is_valid(lua, 1)) { return 0; + } // get pipe file tb_pipe_file_ref_t pipefile = xm_pipe_file_get(lua, 1); diff --git a/core/src/xmake/io/pipe_write.c b/core/src/xmake/io/pipe_write.c index 2f2865c47..d3098dd60 100644 --- a/core/src/xmake/io/pipe_write.c +++ b/core/src/xmake/io/pipe_write.c @@ -52,10 +52,12 @@ tb_int_t xm_io_pipe_write(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) + } + if (xm_lua_isinteger(lua, 3)) { size = (tb_size_t)lua_tointeger(lua, 3); + } if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); diff --git a/core/src/xmake/io/poller.c b/core/src/xmake/io/poller.c index e4c7cf494..6e155e4a8 100644 --- a/core/src/xmake/io/poller.c +++ b/core/src/xmake/io/poller.c @@ -37,8 +37,9 @@ tb_poller_ref_t xm_io_poller(lua_State *lua) { tb_poller_ref_t poller = tb_null; xm_engine_ref_t engine = xm_engine_get(lua); - if (engine) + if (engine) { poller = xm_engine_poller(engine); + } tb_assert(poller); return poller; } diff --git a/core/src/xmake/io/poller_wait.c b/core/src/xmake/io/poller_wait.c index f1e4ed7a7..dc1418a03 100644 --- a/core/src/xmake/io/poller_wait.c +++ b/core/src/xmake/io/poller_wait.c @@ -46,10 +46,11 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, lua_newtable(lua); lua_pushinteger(lua, (tb_int_t)object->type); lua_rawseti(lua, -2, 1); - if (priv) + if (priv) { lua_pushstring(lua, (tb_char_t const *)priv); - else + } else { lua_pushlightuserdata(lua, object->ref.ptr); + } lua_rawseti(lua, -2, 2); if (object->type == TB_POLLER_OBJECT_FWATCHER) { lua_newtable(lua); @@ -63,8 +64,9 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, lua_pushinteger(lua, event->event); lua_settable(lua, -3); } - } else + } else { lua_pushinteger(lua, (tb_int_t)events); + } lua_rawseti(lua, -2, 3); lua_rawseti(lua, -2, ++state->events_count); } diff --git a/core/src/xmake/io/socket_accept.c b/core/src/xmake/io/socket_accept.c index 77a6c6c86..5aed6d263 100644 --- a/core/src/xmake/io/socket_accept.c +++ b/core/src/xmake/io/socket_accept.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_accept(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); @@ -48,9 +49,10 @@ tb_int_t xm_io_socket_accept(lua_State *lua) { // accept socket tb_socket_ref_t client = tb_socket_accept(sock, tb_null); - if (client) + if (client) { xm_lua_pushpointer(lua, (tb_pointer_t)client); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/socket_close.c b/core/src/xmake/io/socket_close.c index 922987c10..401ffd7b6 100644 --- a/core/src/xmake/io/socket_close.c +++ b/core/src/xmake/io/socket_close.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/socket_kill.c b/core/src/xmake/io/socket_kill.c index 63e110257..33d36ef18 100644 --- a/core/src/xmake/io/socket_kill.c +++ b/core/src/xmake/io/socket_kill.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_kill(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/socket_listen.c b/core/src/xmake/io/socket_listen.c index 3aa541016..14971e589 100644 --- a/core/src/xmake/io/socket_listen.c +++ b/core/src/xmake/io/socket_listen.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_listen(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/socket_open.c b/core/src/xmake/io/socket_open.c index cae80d182..2ed04ca97 100644 --- a/core/src/xmake/io/socket_open.c +++ b/core/src/xmake/io/socket_open.c @@ -61,9 +61,10 @@ tb_int_t xm_io_socket_open(lua_State *lua) { // init socket tb_socket_ref_t sock = tb_socket_init(socktype, family); - if (sock) + if (sock) { xm_lua_pushpointer(lua, (tb_pointer_t)sock); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/socket_peeraddr.c b/core/src/xmake/io/socket_peeraddr.c index e1ad43931..686d46799 100644 --- a/core/src/xmake/io/socket_peeraddr.c +++ b/core/src/xmake/io/socket_peeraddr.c @@ -47,8 +47,9 @@ tb_int_t xm_io_socket_peeraddr(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { xm_io_return_error(lua, "get peer address for invalid sock!"); + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); @@ -58,9 +59,10 @@ tb_int_t xm_io_socket_peeraddr(lua_State *lua) { tb_ipaddr_t addr; tb_char_t data[256]; tb_char_t const *cstr = tb_null; - if (tb_socket_peer(sock, &addr) && (cstr = tb_ipaddr_cstr(&addr, data, sizeof(data)))) + if (tb_socket_peer(sock, &addr) && (cstr = tb_ipaddr_cstr(&addr, data, sizeof(data)))) { lua_pushstring(lua, cstr); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/io/socket_recv.c b/core/src/xmake/io/socket_recv.c index ed629a8f5..3ccb9b461 100644 --- a/core/src/xmake/io/socket_recv.c +++ b/core/src/xmake/io/socket_recv.c @@ -51,8 +51,9 @@ tb_int_t xm_io_socket_recv(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + } if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); @@ -62,8 +63,9 @@ tb_int_t xm_io_socket_recv(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/io/socket_recvfrom.c b/core/src/xmake/io/socket_recvfrom.c index 8601f6302..5e212bed8 100644 --- a/core/src/xmake/io/socket_recvfrom.c +++ b/core/src/xmake/io/socket_recvfrom.c @@ -51,8 +51,9 @@ tb_int_t xm_io_socket_recvfrom(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + } if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); @@ -62,8 +63,9 @@ tb_int_t xm_io_socket_recvfrom(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/io/socket_send.c b/core/src/xmake/io/socket_send.c index d83b02add..3a11d0d43 100644 --- a/core/src/xmake/io/socket_send.c +++ b/core/src/xmake/io/socket_send.c @@ -52,10 +52,12 @@ tb_int_t xm_io_socket_send(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) + } + if (xm_lua_isinteger(lua, 3)) { size = (tb_size_t)lua_tointeger(lua, 3); + } if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); diff --git a/core/src/xmake/io/socket_sendfile.c b/core/src/xmake/io/socket_sendfile.c index 0d4be4219..e12e574d7 100644 --- a/core/src/xmake/io/socket_sendfile.c +++ b/core/src/xmake/io/socket_sendfile.c @@ -85,8 +85,9 @@ tb_int_t xm_io_socket_sendfile(lua_State *lua) { // get start tb_long_t start = 1; - if (lua_isnumber(lua, 3)) + if (lua_isnumber(lua, 3)) { start = (tb_long_t)lua_tonumber(lua, 3); + } if (start < 1 || start > filesize) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid start position(%d)!", (tb_int_t)start); @@ -95,8 +96,9 @@ tb_int_t xm_io_socket_sendfile(lua_State *lua) { // get last tb_long_t last = (tb_long_t)filesize; - if (lua_isnumber(lua, 4)) + if (lua_isnumber(lua, 4)) { last = (tb_long_t)lua_tonumber(lua, 4); + } if (last < start - 1 || last > filesize + start - 1) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid last position(%d)!", (tb_int_t)last); diff --git a/core/src/xmake/io/socket_sendto.c b/core/src/xmake/io/socket_sendto.c index 15403d4d8..ccbbb1cc2 100644 --- a/core/src/xmake/io/socket_sendto.c +++ b/core/src/xmake/io/socket_sendto.c @@ -52,10 +52,12 @@ tb_int_t xm_io_socket_sendto(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) + } + if (xm_lua_isinteger(lua, 3)) { size = (tb_size_t)lua_tointeger(lua, 3); + } if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); diff --git a/core/src/xmake/io/socket_wait.c b/core/src/xmake/io/socket_wait.c index 42674f4f9..409d69c91 100644 --- a/core/src/xmake/io/socket_wait.c +++ b/core/src/xmake/io/socket_wait.c @@ -39,8 +39,9 @@ tb_int_t xm_io_socket_wait(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // check socket? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get socket tb_socket_ref_t sock = (tb_socket_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 0dcb43501..ac77b272d 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -71,8 +71,9 @@ static tb_size_t xm_io_stdfile_isatty(tb_size_t type) { /* we cannot call is_cygpty for stdin, because it will cause io.readable is always true * https://github.com/xmake-io/xmake/issues/2504#issuecomment-1170130756 */ - if (!answer && type != XM_IO_FILE_TYPE_STDIN) + if (!answer && type != XM_IO_FILE_TYPE_STDIN) { answer = is_cygpty(console_handle); + } #else switch (type) { case XM_IO_FILE_TYPE_STDIN: @@ -87,8 +88,9 @@ static tb_size_t xm_io_stdfile_isatty(tb_size_t type) { } #endif - if (answer) + if (answer) { type |= XM_IO_FILE_FLAG_TTY; + } return type; } @@ -97,8 +99,9 @@ static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) { #if !defined(TB_CONFIG_OS_WINDOWS) struct stat stats; tb_int_t size = BUFSIZ; - if (fstat(fileno(stdout), &stats) != -1) + if (fstat(fileno(stdout), &stats) != -1) { size = stats.st_blksize; + } setvbuf(stdout, tb_null, _IOLBF, size); #endif } @@ -154,8 +157,9 @@ tb_int_t xm_io_stdfile(lua_State *lua) { * @note we need to ensure that it is a singleton in the external lua script, and will only be created once, e.g. io.stdin, io.stdout, io.stderr */ xm_io_file_t *file = xm_io_stdfile_new(lua, type); - if (file) + if (file) { return 1; - else + } else { xm_io_return_error(lua, "invalid stdfile type!"); + } } diff --git a/core/src/xmake/xmake.c b/core/src/xmake/xmake.c index 8d4a77284..c673d776a 100644 --- a/core/src/xmake/xmake.c +++ b/core/src/xmake/xmake.c @@ -77,8 +77,9 @@ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) { tb_trace_d("init: .."); // check mode - if (!xm_check_mode(mode)) + if (!xm_check_mode(mode)) { return tb_false; + } // check version xm_version_check(build); @@ -88,8 +89,9 @@ tb_bool_t xm_init_(tb_size_t mode, tb_hize_t build) { if (!tb_init(tb_null, tb_default_allocator(tb_null, 0))) return tb_false; #else // init tbox, since small compilation mode is enabled, it still uses the native allocator - if (!tb_init(tb_null, tb_null)) + if (!tb_init(tb_null, tb_null)) { return tb_false; + } #endif tb_trace_d("init: ok"); -- cgit v1.3.1 From 831447a51da0b094e08bb047247bf269a6e6cf71 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Nov 2025 23:22:44 +0800 Subject: format more if-else --- core/src/xmake/curses/curses.c | 21 +++++++++++------- core/src/xmake/fwatcher/add.c | 3 ++- core/src/xmake/fwatcher/close.c | 3 ++- core/src/xmake/fwatcher/open.c | 5 +++-- core/src/xmake/fwatcher/remove.c | 3 ++- core/src/xmake/fwatcher/wait.c | 3 ++- core/src/xmake/libc/byteof.c | 12 ++++++----- core/src/xmake/libc/dataptr.c | 9 ++++---- core/src/xmake/libc/free.c | 3 ++- core/src/xmake/libc/malloc.c | 3 ++- core/src/xmake/libc/memcpy.c | 3 ++- core/src/xmake/libc/memmov.c | 3 ++- core/src/xmake/libc/memset.c | 3 ++- core/src/xmake/libc/setbyte.c | 17 +++++++++------ core/src/xmake/libc/strndup.c | 12 ++++++----- core/src/xmake/lz4/block_compress.c | 9 +++++--- core/src/xmake/lz4/block_decompress.c | 9 +++++--- core/src/xmake/lz4/compress.c | 6 ++++-- core/src/xmake/lz4/compress_file.c | 6 ++++-- core/src/xmake/lz4/compress_stream_close.c | 3 ++- core/src/xmake/lz4/compress_stream_open.c | 5 +++-- core/src/xmake/lz4/compress_stream_read.c | 6 ++++-- core/src/xmake/lz4/compress_stream_write.c | 9 +++++--- core/src/xmake/lz4/decompress.c | 12 +++++++---- core/src/xmake/lz4/decompress_file.c | 6 ++++-- core/src/xmake/lz4/decompress_stream_close.c | 3 ++- core/src/xmake/lz4/decompress_stream_open.c | 5 +++-- core/src/xmake/lz4/decompress_stream_read.c | 6 ++++-- core/src/xmake/lz4/decompress_stream_write.c | 6 ++++-- core/src/xmake/os/args.c | 32 +++++++++++++++++----------- core/src/xmake/os/argv.c | 23 +++++++++----------- core/src/xmake/os/cpdir.c | 6 ++++-- core/src/xmake/os/cpfile.c | 9 +++++--- core/src/xmake/os/cpuinfo.c | 12 +++++++---- core/src/xmake/os/curdir.c | 5 +++-- core/src/xmake/os/filesize.c | 5 +++-- core/src/xmake/os/find.c | 18 ++++++++++------ core/src/xmake/os/getenv.c | 13 ++++++----- core/src/xmake/os/getenvs.c | 18 ++++++++++------ core/src/xmake/os/getown.c | 3 ++- core/src/xmake/os/meminfo.c | 12 +++++++---- core/src/xmake/os/mkdir.c | 5 +++-- core/src/xmake/os/mtime.c | 5 +++-- core/src/xmake/os/readlink.c | 6 ++++-- core/src/xmake/os/rmdir.c | 6 ++++-- core/src/xmake/os/signal.c | 14 +++++++----- core/src/xmake/os/sleep.c | 3 ++- core/src/xmake/os/tmpdir.c | 5 +++-- 48 files changed, 247 insertions(+), 147 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/curses/curses.c b/core/src/xmake/curses/curses.c index 988e6840c..4f8c03028 100644 --- a/core/src/xmake/curses/curses.c +++ b/core/src/xmake/curses/curses.c @@ -105,10 +105,12 @@ static int g_mapkey = 0; * private implementation */ static chtype xm_curses_checkch(lua_State *lua, int index) { - if (lua_type(lua, index) == LUA_TNUMBER) + if (lua_type(lua, index) == LUA_TNUMBER) { return (chtype)luaL_checknumber(lua, index); - if (lua_type(lua, index) == LUA_TSTRING) + } + if (lua_type(lua, index) == LUA_TSTRING) { return *lua_tostring(lua, index); + } #ifdef USE_LUAJIT luaL_typerror(lua, index, "chtype"); #endif @@ -685,26 +687,29 @@ static int xm_curses_napms(lua_State *lua) { } static int xm_curses_cbreak(lua_State *lua) { - if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) + if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) { lua_pushboolean(lua, XM_CURSES_OK(cbreak())); - else + } else { lua_pushboolean(lua, XM_CURSES_OK(nocbreak())); + } return 1; } static int xm_curses_echo(lua_State *lua) { - if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) + if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) { lua_pushboolean(lua, XM_CURSES_OK(echo())); - else + } else { lua_pushboolean(lua, XM_CURSES_OK(noecho())); + } return 1; } static int xm_curses_nl(lua_State *lua) { - if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) + if (lua_isnoneornil(lua, 1) || lua_toboolean(lua, 1)) { lua_pushboolean(lua, XM_CURSES_OK(nl())); - else + } else { lua_pushboolean(lua, XM_CURSES_OK(nonl())); + } return 1; } diff --git a/core/src/xmake/fwatcher/add.c b/core/src/xmake/fwatcher/add.c index 77c23ea48..10c31b6b0 100644 --- a/core/src/xmake/fwatcher/add.c +++ b/core/src/xmake/fwatcher/add.c @@ -39,8 +39,9 @@ tb_int_t xm_fwatcher_add(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/fwatcher/close.c b/core/src/xmake/fwatcher/close.c index a5501d906..61c78868a 100644 --- a/core/src/xmake/fwatcher/close.c +++ b/core/src/xmake/fwatcher/close.c @@ -39,8 +39,9 @@ tb_int_t xm_fwatcher_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/fwatcher/open.c b/core/src/xmake/fwatcher/open.c index 13ab91d5a..032921fb3 100644 --- a/core/src/xmake/fwatcher/open.c +++ b/core/src/xmake/fwatcher/open.c @@ -38,9 +38,10 @@ tb_int_t xm_fwatcher_open(lua_State *lua) { // init fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)tb_fwatcher_init(); - if (fwatcher) + if (fwatcher) { xm_lua_pushpointer(lua, (tb_pointer_t)fwatcher); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/fwatcher/remove.c b/core/src/xmake/fwatcher/remove.c index 6285b0649..a3636dbe3 100644 --- a/core/src/xmake/fwatcher/remove.c +++ b/core/src/xmake/fwatcher/remove.c @@ -39,8 +39,9 @@ tb_int_t xm_fwatcher_remove(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/fwatcher/wait.c b/core/src/xmake/fwatcher/wait.c index 42b01b8aa..0602c931c 100644 --- a/core/src/xmake/fwatcher/wait.c +++ b/core/src/xmake/fwatcher/wait.c @@ -39,8 +39,9 @@ tb_int_t xm_fwatcher_wait(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the fwatcher tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/libc/byteof.c b/core/src/xmake/libc/byteof.c index dac772e9b..1d49bf815 100644 --- a/core/src/xmake/libc/byteof.c +++ b/core/src/xmake/libc/byteof.c @@ -38,19 +38,21 @@ tb_int_t xm_libc_byteof(lua_State *lua) { // get data tb_pointer_t data = tb_null; - if (lua_isnumber(lua, 1)) + if (lua_isnumber(lua, 1)) { data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1); - else if (lua_isstring(lua, 1)) + } else if (lua_isstring(lua, 1)) { data = (tb_pointer_t)luaL_checkstring(lua, 1); - else + } else { xm_libc_return_error(lua, "libc.byteof(invalid data)!"); + } // get offset tb_int_t offset = 0; - if (lua_isnumber(lua, 2)) + if (lua_isnumber(lua, 2)) { offset = (tb_int_t)lua_tointeger(lua, 2); - else + } else { xm_libc_return_error(lua, "libc.byteof(invalid offset)!"); + } lua_pushinteger(lua, ((tb_byte_t const *)data)[offset]); return 1; } diff --git a/core/src/xmake/libc/dataptr.c b/core/src/xmake/libc/dataptr.c index 363853800..881b373d2 100644 --- a/core/src/xmake/libc/dataptr.c +++ b/core/src/xmake/libc/dataptr.c @@ -37,14 +37,15 @@ tb_int_t xm_libc_dataptr(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); tb_pointer_t data = tb_null; - if (lua_isstring(lua, 1)) + if (lua_isstring(lua, 1)) { data = (tb_pointer_t)luaL_checkstring(lua, 1); - else if (lua_isnumber(lua, 1)) + } else if (lua_isnumber(lua, 1)) { data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1); - else if (xm_lua_ispointer(lua, 1)) + } else if (xm_lua_ispointer(lua, 1)) { data = (tb_pointer_t)xm_lua_topointer(lua, 1); - else + } else { xm_libc_return_error(lua, "libc.dataptr(invalid data)!"); + } lua_pushinteger(lua, (lua_Integer)(tb_long_t)data); return 1; } diff --git a/core/src/xmake/libc/free.c b/core/src/xmake/libc/free.c index 6f0d70f3d..0b686aeb5 100644 --- a/core/src/xmake/libc/free.c +++ b/core/src/xmake/libc/free.c @@ -38,7 +38,8 @@ tb_int_t xm_libc_free(lua_State *lua) { // do free tb_pointer_t data = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); - if (data) + if (data) { tb_free(data); + } return 0; } diff --git a/core/src/xmake/libc/malloc.c b/core/src/xmake/libc/malloc.c index faaa00e97..6bda4167d 100644 --- a/core/src/xmake/libc/malloc.c +++ b/core/src/xmake/libc/malloc.c @@ -39,8 +39,9 @@ tb_int_t xm_libc_malloc(lua_State *lua) { // do malloc tb_pointer_t data = tb_null; tb_long_t size = (tb_long_t)luaL_checkinteger(lua, 1); - if (size > 0) + if (size > 0) { data = tb_malloc(size); + } lua_pushinteger(lua, (lua_Integer)(tb_long_t)data); return 1; } diff --git a/core/src/xmake/libc/memcpy.c b/core/src/xmake/libc/memcpy.c index e0e8b1492..ce5e34312 100644 --- a/core/src/xmake/libc/memcpy.c +++ b/core/src/xmake/libc/memcpy.c @@ -40,7 +40,8 @@ tb_int_t xm_libc_memcpy(lua_State *lua) { tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2); tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); - if (dst && src && size > 0) + if (dst && src && size > 0) { tb_memcpy(dst, src, size); + } return 0; } diff --git a/core/src/xmake/libc/memmov.c b/core/src/xmake/libc/memmov.c index 66120e168..1843a4301 100644 --- a/core/src/xmake/libc/memmov.c +++ b/core/src/xmake/libc/memmov.c @@ -40,7 +40,8 @@ tb_int_t xm_libc_memmov(lua_State *lua) { tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2); tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); - if (dst && src && size > 0) + if (dst && src && size > 0) { tb_memmov(dst, src, size); + } return 0; } diff --git a/core/src/xmake/libc/memset.c b/core/src/xmake/libc/memset.c index 4f8864842..01b4f3f89 100644 --- a/core/src/xmake/libc/memset.c +++ b/core/src/xmake/libc/memset.c @@ -40,7 +40,8 @@ tb_int_t xm_libc_memset(lua_State *lua) { tb_pointer_t data = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1); tb_char_t ch = (tb_char_t)lua_tointeger(lua, 2); tb_int_t size = (tb_int_t)lua_tointeger(lua, 3); - if (data && size > 0) + if (data && size > 0) { tb_memset(data, ch, size); + } return 0; } diff --git a/core/src/xmake/libc/setbyte.c b/core/src/xmake/libc/setbyte.c index d53c30229..3bcc3fcdc 100644 --- a/core/src/xmake/libc/setbyte.c +++ b/core/src/xmake/libc/setbyte.c @@ -38,24 +38,27 @@ tb_int_t xm_libc_setbyte(lua_State *lua) { // get data tb_pointer_t data = tb_null; - if (lua_isnumber(lua, 1)) + if (lua_isnumber(lua, 1)) { data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1); - else if (lua_isstring(lua, 1)) + } else if (lua_isstring(lua, 1)) { data = (tb_pointer_t)luaL_checkstring(lua, 1); - else + } else { xm_libc_return_error(lua, "libc.setbyte(invalid data)!"); + } // get offset tb_int_t offset = 0; - if (lua_isnumber(lua, 2)) + if (lua_isnumber(lua, 2)) { offset = (tb_int_t)lua_tointeger(lua, 2); - else + } else { xm_libc_return_error(lua, "libc.setbyte(invalid offset)!"); + } // set byte - if (lua_isnumber(lua, 3)) + if (lua_isnumber(lua, 3)) { ((tb_byte_t *)data)[offset] = (tb_byte_t)lua_tointeger(lua, 3); - else + } else { xm_libc_return_error(lua, "libc.setbyte(invalid value)!"); + } return 0; } diff --git a/core/src/xmake/libc/strndup.c b/core/src/xmake/libc/strndup.c index f61cebb2c..138a4907f 100644 --- a/core/src/xmake/libc/strndup.c +++ b/core/src/xmake/libc/strndup.c @@ -38,16 +38,18 @@ tb_int_t xm_libc_strndup(lua_State *lua) { // do strndup tb_char_t const *s = tb_null; - if (lua_isnumber(lua, 1)) + if (lua_isnumber(lua, 1)) { s = (tb_char_t const *)(tb_size_t)lua_tointeger(lua, 1); - else if (lua_isstring(lua, 2)) + } else if (lua_isstring(lua, 2)) { s = lua_tostring(lua, 2); - else + } else { xm_libc_return_error(lua, "libc.strndup(invalid args)!"); + } tb_int_t n = (tb_int_t)lua_tointeger(lua, 2); - if (s && n >= 0) + if (s && n >= 0) { lua_pushlstring(lua, s, n); - else + } else { lua_pushliteral(lua, ""); + } return 1; } diff --git a/core/src/xmake/lz4/block_compress.c b/core/src/xmake/lz4/block_compress.c index 53b592a22..34fb06def 100644 --- a/core/src/xmake/lz4/block_compress.c +++ b/core/src/xmake/lz4/block_compress.c @@ -39,10 +39,12 @@ tb_int_t xm_lz4_block_compress(lua_State *lua) { // get data and size tb_int_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 1)) + if (xm_lua_isinteger(lua, 1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) + } + if (xm_lua_isinteger(lua, 2)) { size = (tb_int_t)lua_tointeger(lua, 2); + } if (!data || !size || size > LZ4_MAX_INPUT_SIZE) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); @@ -73,7 +75,8 @@ tb_int_t xm_lz4_block_compress(lua_State *lua) { output_data = tb_null; } - if (!ok) + if (!ok) { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/lz4/block_decompress.c b/core/src/xmake/lz4/block_decompress.c index 2a6ed1d20..07c80236d 100644 --- a/core/src/xmake/lz4/block_decompress.c +++ b/core/src/xmake/lz4/block_decompress.c @@ -39,10 +39,12 @@ tb_int_t xm_lz4_block_decompress(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 1)) + if (xm_lua_isinteger(lua, 1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) + } + if (xm_lua_isinteger(lua, 2)) { size = (tb_size_t)lua_tointeger(lua, 2); + } if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); @@ -78,7 +80,8 @@ tb_int_t xm_lz4_block_decompress(lua_State *lua) { output_data = tb_null; } - if (!ok) + if (!ok) { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/lz4/compress.c b/core/src/xmake/lz4/compress.c index 69af51113..dffda1f23 100644 --- a/core/src/xmake/lz4/compress.c +++ b/core/src/xmake/lz4/compress.c @@ -39,10 +39,12 @@ tb_int_t xm_lz4_compress(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 1)) + if (xm_lua_isinteger(lua, 1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) + } + if (xm_lua_isinteger(lua, 2)) { size = (tb_size_t)lua_tointeger(lua, 2); + } if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); diff --git a/core/src/xmake/lz4/compress_file.c b/core/src/xmake/lz4/compress_file.c index 48596e17b..552ece99d 100644 --- a/core/src/xmake/lz4/compress_file.c +++ b/core/src/xmake/lz4/compress_file.c @@ -70,13 +70,15 @@ tb_int_t xm_lz4_compress_file(lua_State *lua) { } } tb_assert_and_check_break(oreal >= 0); - } else + } else { break; + } write_ok = tb_true; } - if (tb_stream_beof(istream) && write_ok) + if (tb_stream_beof(istream) && write_ok) { ok = tb_true; + } } // exit stream diff --git a/core/src/xmake/lz4/compress_stream_close.c b/core/src/xmake/lz4/compress_stream_close.c index d1f534cde..4bea381e9 100644 --- a/core/src/xmake/lz4/compress_stream_close.c +++ b/core/src/xmake/lz4/compress_stream_close.c @@ -37,8 +37,9 @@ tb_int_t xm_lz4_compress_stream_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the stream xm_lz4_cstream_t *stream = (xm_lz4_cstream_t *)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/lz4/compress_stream_open.c b/core/src/xmake/lz4/compress_stream_open.c index d4ac50667..536e259e0 100644 --- a/core/src/xmake/lz4/compress_stream_open.c +++ b/core/src/xmake/lz4/compress_stream_open.c @@ -37,9 +37,10 @@ tb_int_t xm_lz4_compress_stream_open(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); xm_lz4_cstream_t *stream = xm_lz4_cstream_init(); - if (stream) + if (stream) { xm_lua_pushpointer(lua, (tb_pointer_t)stream); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/lz4/compress_stream_read.c b/core/src/xmake/lz4/compress_stream_read.c index ff1315c3e..6d0515eb5 100644 --- a/core/src/xmake/lz4/compress_stream_read.c +++ b/core/src/xmake/lz4/compress_stream_read.c @@ -50,8 +50,9 @@ tb_int_t xm_lz4_compress_stream_read(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + } if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); @@ -61,8 +62,9 @@ tb_int_t xm_lz4_compress_stream_read(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/lz4/compress_stream_write.c b/core/src/xmake/lz4/compress_stream_write.c index 730a4f986..8a4276318 100644 --- a/core/src/xmake/lz4/compress_stream_write.c +++ b/core/src/xmake/lz4/compress_stream_write.c @@ -51,10 +51,12 @@ tb_int_t xm_lz4_compress_stream_write(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) + } + if (xm_lua_isinteger(lua, 3)) { size = (tb_size_t)lua_tointeger(lua, 3); + } if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); @@ -64,8 +66,9 @@ tb_int_t xm_lz4_compress_stream_write(lua_State *lua) { // is end? tb_bool_t end = tb_false; - if (lua_isboolean(lua, 4)) + if (lua_isboolean(lua, 4)) { end = lua_toboolean(lua, 4); + } // write data tb_long_t real = xm_lz4_cstream_write(stream, data, size, end); diff --git a/core/src/xmake/lz4/decompress.c b/core/src/xmake/lz4/decompress.c index 51a50c112..500e932a1 100644 --- a/core/src/xmake/lz4/decompress.c +++ b/core/src/xmake/lz4/decompress.c @@ -39,10 +39,12 @@ tb_int_t xm_lz4_decompress(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 1)) + if (xm_lua_isinteger(lua, 1)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 1); - if (xm_lua_isinteger(lua, 2)) + } + if (xm_lua_isinteger(lua, 2)) { size = (tb_size_t)lua_tointeger(lua, 2); + } if (!data || !size) { lua_pushnil(lua); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); @@ -59,8 +61,9 @@ tb_int_t xm_lz4_decompress(lua_State *lua) { tb_buffer_init(&result); code = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION); - if (LZ4F_isError(code)) + if (LZ4F_isError(code)) { break; + } tb_byte_t buffer[8192]; tb_bool_t failed = tb_false; @@ -73,8 +76,9 @@ tb_int_t xm_lz4_decompress(lua_State *lua) { break; } - if (buffer_size == 0) + if (buffer_size == 0) { break; + } data += advance; size -= advance; diff --git a/core/src/xmake/lz4/decompress_file.c b/core/src/xmake/lz4/decompress_file.c index 7d91c5be4..accc993f8 100644 --- a/core/src/xmake/lz4/decompress_file.c +++ b/core/src/xmake/lz4/decompress_file.c @@ -70,13 +70,15 @@ tb_int_t xm_lz4_decompress_file(lua_State *lua) { } } tb_assert_and_check_break(oreal >= 0); - } else + } else { break; + } write_ok = tb_true; } - if (tb_stream_beof(istream) && write_ok) + if (tb_stream_beof(istream) && write_ok) { ok = tb_true; + } } // exit stream diff --git a/core/src/xmake/lz4/decompress_stream_close.c b/core/src/xmake/lz4/decompress_stream_close.c index 89c868c53..c50cd4268 100644 --- a/core/src/xmake/lz4/decompress_stream_close.c +++ b/core/src/xmake/lz4/decompress_stream_close.c @@ -37,8 +37,9 @@ tb_int_t xm_lz4_decompress_stream_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the stream xm_lz4_dstream_t *stream = (xm_lz4_dstream_t *)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/lz4/decompress_stream_open.c b/core/src/xmake/lz4/decompress_stream_open.c index eb3db7193..7a37f4378 100644 --- a/core/src/xmake/lz4/decompress_stream_open.c +++ b/core/src/xmake/lz4/decompress_stream_open.c @@ -37,9 +37,10 @@ tb_int_t xm_lz4_decompress_stream_open(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); xm_lz4_dstream_t *stream = xm_lz4_dstream_init(); - if (stream) + if (stream) { xm_lua_pushpointer(lua, (tb_pointer_t)stream); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/lz4/decompress_stream_read.c b/core/src/xmake/lz4/decompress_stream_read.c index 85ecdbe9f..eb095d4e0 100644 --- a/core/src/xmake/lz4/decompress_stream_read.c +++ b/core/src/xmake/lz4/decompress_stream_read.c @@ -50,8 +50,9 @@ tb_int_t xm_lz4_decompress_stream_read(lua_State *lua) { // get data tb_byte_t *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); + } if (!data) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p)!", data); @@ -61,8 +62,9 @@ tb_int_t xm_lz4_decompress_stream_read(lua_State *lua) { // get size tb_long_t size = 0; - if (xm_lua_isinteger(lua, 3)) + if (xm_lua_isinteger(lua, 3)) { size = (tb_long_t)lua_tointeger(lua, 3); + } if (size <= 0) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid size(%d)!", (tb_int_t)size); diff --git a/core/src/xmake/lz4/decompress_stream_write.c b/core/src/xmake/lz4/decompress_stream_write.c index 4359a41d7..94be0533e 100644 --- a/core/src/xmake/lz4/decompress_stream_write.c +++ b/core/src/xmake/lz4/decompress_stream_write.c @@ -51,10 +51,12 @@ tb_int_t xm_lz4_decompress_stream_write(lua_State *lua) { // get data and size tb_size_t size = 0; tb_byte_t const *data = tb_null; - if (xm_lua_isinteger(lua, 2)) + if (xm_lua_isinteger(lua, 2)) { data = (tb_byte_t const *)(tb_size_t)(tb_long_t)lua_tointeger(lua, 2); - if (xm_lua_isinteger(lua, 3)) + } + if (xm_lua_isinteger(lua, 3)) { size = (tb_size_t)lua_tointeger(lua, 3); + } if (!data || !size) { lua_pushinteger(lua, -1); lua_pushfstring(lua, "invalid data(%p) and size(%d)!", data, (tb_int_t)size); diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c index 8b2c002c9..b48445c89 100644 --- a/core/src/xmake/os/args.c +++ b/core/src/xmake/os/args.c @@ -43,29 +43,33 @@ static tb_void_t tb_os_args_append( tb_bool_t wrap_quote = tb_false; if (!nowrap) { while ((ch = *p)) { - if (ch == ' ') + if (ch == ' ') { wrap_quote = tb_true; + } p++; } } // wrap begin quote - if (wrap_quote) + if (wrap_quote) { tb_string_chrcat(result, '\"'); + } // escape characters p = cstr; while ((ch = *p)) { // escape '"' or '\\' - if (ch == '\"' || ((escape || wrap_quote) && ch == '\\')) + if (ch == '\"' || ((escape || wrap_quote) && ch == '\\')) { tb_string_chrcat(result, '\\'); + } tb_string_chrcat(result, ch); p++; } // wrap end quote - if (wrap_quote) + if (wrap_quote) { tb_string_chrcat(result, '\"'); + } } /* ////////////////////////////////////////////////////////////////////////////////////// @@ -105,42 +109,46 @@ tb_int_t xm_os_args(lua_State *lua) { tb_size_t n = (tb_size_t)lua_objlen(lua, 1); for (i = 1; i <= n; i++) { // add space - if (i != 1) + if (i != 1) { tb_string_chrcat(&result, ' '); + } // add argument lua_pushnumber(lua, (tb_int_t)i); lua_rawget(lua, 1); - if (lua_istable(lua, -1)) // is path instance? - { + if (lua_istable(lua, -1)) { // is path instance? lua_pushstring(lua, "_STR"); lua_gettable(lua, -2); size_t size = 0; tb_char_t const *cstr = luaL_checklstring(lua, -1, &size); - if (cstr && size) + if (cstr && size) { tb_os_args_append(&result, cstr, size, escape, nowrap); + } lua_pop(lua, 1); } else { size_t size = 0; tb_char_t const *cstr = luaL_checklstring(lua, -1, &size); - if (cstr && size) + if (cstr && size) { tb_os_args_append(&result, cstr, size, escape, nowrap); + } } lua_pop(lua, 1); } } else { size_t size = 0; tb_char_t const *cstr = luaL_checklstring(lua, 1, &size); - if (cstr && size) + if (cstr && size) { tb_os_args_append(&result, cstr, size, escape, nowrap); + } } // return result tb_size_t size = tb_string_size(&result); - if (size) + if (size) { lua_pushlstring(lua, tb_string_cstr(&result), size); - else + } else { lua_pushliteral(lua, ""); + } tb_string_exit(&result); return 1; } diff --git a/core/src/xmake/os/argv.c b/core/src/xmake/os/argv.c index f7230d057..12b1f88ec 100644 --- a/core/src/xmake/os/argv.c +++ b/core/src/xmake/os/argv.c @@ -56,8 +56,9 @@ tb_int_t xm_os_argv(lua_State *lua) { lua_newtable(lua); // init arg - if (!tb_string_init(&arg)) + if (!tb_string_init(&arg)) { break; + } // parse command to the arguments tb_int_t i = 1; @@ -73,19 +74,13 @@ tb_int_t xm_os_argv(lua_State *lua) { if (!quote && (ch == '\"' || ch == '\'')) { quote = ch; skip = 1; - } - // leave quote? - else if (ch == quote) { + } else if (ch == quote) { // leave quote? quote = 0; skip = 1; - } - // escape charactor? only escape \\, \" - else if (ch == '\\' && (p[1] == '\\' || p[1] == '\"')) { + } else if (ch == '\\' && (p[1] == '\\' || p[1] == '\"')) { // escape character? only escape \\ and \" escape = 1; skip = 1; - } - // is argument end with ' '? - else if (!quote && tb_isspace(ch)) { + } else if (!quote && tb_isspace(ch)) { // is argument end with ' '? // save this argument tb_string_ltrim(&arg); if (tb_string_size(&arg)) { @@ -100,14 +95,16 @@ tb_int_t xm_os_argv(lua_State *lua) { } // save this charactor to argument - if (splitonly || !skip) + if (splitonly || !skip) { tb_string_chrcat(&arg, ch); + } // step and cancel escape - if (escape == 1) + if (escape == 1) { escape++; - else if (escape == 2) + } else if (escape == 2) { escape = 0; + } // clear skip skip = 0; diff --git a/core/src/xmake/os/cpdir.c b/core/src/xmake/os/cpdir.c index 0df435436..2ea0be1ed 100644 --- a/core/src/xmake/os/cpdir.c +++ b/core/src/xmake/os/cpdir.c @@ -44,12 +44,14 @@ tb_int_t xm_os_cpdir(lua_State *lua) { // init copy flags tb_size_t flags = TB_FILE_COPY_NONE; tb_bool_t is_symlink = lua_toboolean(lua, 3); - if (is_symlink) + if (is_symlink) { flags |= TB_FILE_COPY_LINK; + } tb_bool_t copy_if_different = lua_toboolean(lua, 4); - if (copy_if_different) + if (copy_if_different) { flags |= TB_FILE_COPY_IF_DIFFERENT; + } // do copy lua_pushboolean(lua, tb_directory_copy(src, dst, flags)); diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c index 7291385a7..d3c62832e 100644 --- a/core/src/xmake/os/cpfile.c +++ b/core/src/xmake/os/cpfile.c @@ -44,16 +44,19 @@ tb_int_t xm_os_cpfile(lua_State *lua) { // init copy flags tb_size_t flags = TB_FILE_COPY_NONE; tb_bool_t is_symlink = lua_toboolean(lua, 3); - if (is_symlink) + if (is_symlink) { flags |= TB_FILE_COPY_LINK; + } tb_bool_t is_writeable = lua_toboolean(lua, 4); - if (is_writeable) + if (is_writeable) { flags |= TB_FILE_COPY_WRITEABLE; + } tb_bool_t copy_if_different = lua_toboolean(lua, 5); - if (copy_if_different) + if (copy_if_different) { flags |= TB_FILE_COPY_IF_DIFFERENT; + } // do copy lua_pushboolean(lua, tb_file_copy(src, dst, flags)); diff --git a/core/src/xmake/os/cpuinfo.c b/core/src/xmake/os/cpuinfo.c index f8ef7d46b..7be9172cc 100644 --- a/core/src/xmake/os/cpuinfo.c +++ b/core/src/xmake/os/cpuinfo.c @@ -93,8 +93,9 @@ static tb_float_t xm_os_cpuinfo_usagerate() { } usagerate += total > 0 ? ((tb_float_t)use / (tb_float_t)total) : 0; } - if (s_cpuinfo_prev) + if (s_cpuinfo_prev) { vm_deallocate(mach_task_self(), (vm_address_t)s_cpuinfo_prev, sizeof(integer_t) * s_cpuinfo_count_prev); + } s_time = tb_mclock(); s_cpuinfo_prev = cpuinfo; s_cpuinfo_count_prev = cpuinfo_count; @@ -119,8 +120,9 @@ static tb_float_t xm_os_cpuinfo_usagerate() { tb_uint64_t kernel_total = kernel_diff - idle_diff; // sometimes kernel_time > idle_time - if (sys_total > 0) + if (sys_total > 0) { usagerate = (tb_float_t)((tb_double_t)(kernel_total + user_diff) / sys_total); + } } idle_prev = idle; @@ -175,8 +177,9 @@ static tb_float_t xm_os_cpuinfo_usagerate() { if (total_prev > 0 && active_prev > 0) { tb_int64_t total_diff = total - total_prev; tb_int64_t active_diff = active - active_prev; - if (total_diff > 0) + if (total_diff > 0) { usagerate = (tb_float_t)((tb_double_t)active_diff / total_diff); + } } total_prev = total; active_prev = active; @@ -214,8 +217,9 @@ static tb_float_t xm_os_cpuinfo_usagerate() { if (total_prev > 0 && active_prev > 0) { tb_int64_t total_diff = total - total_prev; tb_int64_t active_diff = active - active_prev; - if (total_diff > 0) + if (total_diff > 0) { usagerate = (tb_float_t)((tb_double_t)active_diff / total_diff); + } } total_prev = total; active_prev = active; diff --git a/core/src/xmake/os/curdir.c b/core/src/xmake/os/curdir.c index 2d27cf905..987aa60c9 100644 --- a/core/src/xmake/os/curdir.c +++ b/core/src/xmake/os/curdir.c @@ -38,9 +38,10 @@ tb_int_t xm_os_curdir(lua_State *lua) { // os.curdir() tb_char_t path[TB_PATH_MAXN]; - if (tb_directory_current(path, sizeof(path))) + if (tb_directory_current(path, sizeof(path))) { lua_pushstring(lua, path); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/os/filesize.c b/core/src/xmake/os/filesize.c index a99651fbf..c746d96ed 100644 --- a/core/src/xmake/os/filesize.c +++ b/core/src/xmake/os/filesize.c @@ -42,9 +42,10 @@ tb_int_t xm_os_filesize(lua_State *lua) { // os.filesize(path) tb_file_info_t info = { 0 }; - if (tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE)) + if (tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE)) { lua_pushinteger(lua, (lua_Integer)info.size); - else + } else { lua_pushinteger(lua, 0); + } return 1; } diff --git a/core/src/xmake/os/find.c b/core/src/xmake/os/find.c index 2ed5611ad..144ab4daa 100644 --- a/core/src/xmake/os/find.c +++ b/core/src/xmake/os/find.c @@ -46,8 +46,9 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in tb_assert_and_check_return_val(pattern, TB_DIRECTORY_WALK_CODE_END); // remove ./ for path - if (path[0] == '.' && (path[1] == '/' || path[1] == '\\')) + if (path[0] == '.' && (path[1] == '/' || path[1] == '\\')) { path = path + 2; + } // the match mode tb_long_t mode = tuple[2].l; @@ -60,8 +61,9 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in // we can ignore it directly if this path is file, but we need directory tb_size_t needtype = (mode == 1) ? TB_FILE_TYPE_DIRECTORY : ((mode == 0) ? TB_FILE_TYPE_FILE : (TB_FILE_TYPE_FILE | TB_FILE_TYPE_DIRECTORY)); - if (info->type == TB_FILE_TYPE_FILE && needtype == TB_FILE_TYPE_DIRECTORY) + if (info->type == TB_FILE_TYPE_FILE && needtype == TB_FILE_TYPE_DIRECTORY) { return TB_DIRECTORY_WALK_CODE_CONTINUE; + } // do path:match(pattern) lua_getfield(lua, -1, "match"); @@ -88,8 +90,9 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in tb_assert(rootlen + 1 <= tb_strlen(path)); // skip the rootdir if not "." - if (tb_strcmp(rootdir, ".")) + if (tb_strcmp(rootdir, ".")) { path += rootlen + 1; + } // exclude paths tb_int_t i = 0; @@ -140,18 +143,21 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in // is continue? tb_bool_t is_continue = lua_toboolean(lua, -1); lua_pop(lua, 1); - if (!is_continue) + if (!is_continue) { return TB_DIRECTORY_WALK_CODE_END; + } } matched = tb_true; } } // we do not recurse sub-directories if this path has been excluded and it's directory - else + else { skip_recursion = tb_true; + } } - if (!matched) + if (!matched) { lua_pop(lua, 1); + } return skip_recursion ? TB_DIRECTORY_WALK_CODE_SKIP_RECURSION : TB_DIRECTORY_WALK_CODE_CONTINUE; } /* ////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/xmake/os/getenv.c b/core/src/xmake/os/getenv.c index dc5578ebe..4d82e0524 100644 --- a/core/src/xmake/os/getenv.c +++ b/core/src/xmake/os/getenv.c @@ -53,8 +53,9 @@ tb_int_t xm_os_getenv(lua_State *lua) { // init values tb_string_t values; - if (!tb_string_init(&values)) + if (!tb_string_init(&values)) { return 0; + } // init environment tb_environment_ref_t environment = tb_environment_init(); @@ -65,10 +66,11 @@ tb_int_t xm_os_getenv(lua_State *lua) { tb_bool_t is_first = tb_true; tb_for_all_if(tb_char_t const *, value, environment, value) { // append separator - if (!is_first) + if (!is_first) { tb_string_chrcat(&values, XM_OS_ENV_SEP); - else + } else { is_first = tb_false; + } // append value tb_string_cstrcat(&values, value); @@ -80,10 +82,11 @@ tb_int_t xm_os_getenv(lua_State *lua) { } // save result - if (tb_string_size(&values)) + if (tb_string_size(&values)) { lua_pushstring(lua, tb_string_cstr(&values)); - else + } else { lua_pushnil(lua); + } // exit values tb_string_exit(&values); diff --git a/core/src/xmake/os/getenvs.c b/core/src/xmake/os/getenvs.c index 70c6af7bf..1576c101d 100644 --- a/core/src/xmake/os/getenvs.c +++ b/core/src/xmake/os/getenvs.c @@ -63,12 +63,14 @@ static tb_void_t xm_os_getenvs_trim(tb_char_t const **sstr, tb_char_t const **es tb_char_t const *e = *estr; // trim left - while (p < e && tb_isspace(*p)) + while (p < e && tb_isspace(*p)) { p++; + } // trim right - while (e > p && tb_isspace(*(e - 1))) + while (e > p && tb_isspace(*(e - 1))) { e--; + } // save trimmed string *sstr = p; @@ -93,8 +95,9 @@ static tb_void_t xm_os_getenvs_process_line(lua_State *lua, tb_char_t const *lin // trim key xm_os_getenvs_trim(&key_start, &key_end); - if (key_start >= key_end) + if (key_start >= key_end) { return; + } // trim value xm_os_getenvs_trim(&value_start, &value_end); @@ -137,8 +140,9 @@ tb_int_t xm_os_getenvs(lua_State *lua) { while (*p) { n = tb_wcslen(p); if (n + 1 < tb_arrayn(line)) { - if (tb_wtoa(line, p, tb_arrayn(line)) >= 0) + if (tb_wtoa(line, p, tb_arrayn(line)) >= 0) { xm_os_getenvs_process_line(lua, line); + } } else { if (!data) { maxn = n + 1; @@ -149,13 +153,15 @@ tb_int_t xm_os_getenvs(lua_State *lua) { } tb_assert_and_check_break(data); - if (tb_wtoa(data, p, maxn) >= 0) + if (tb_wtoa(data, p, maxn) >= 0) { xm_os_getenvs_process_line(lua, data); + } } p += n + 1; } - if (data && data != line) + if (data && data != line) { tb_free(data); + } data = tb_null; } #else diff --git a/core/src/xmake/os/getown.c b/core/src/xmake/os/getown.c index ef7846ad1..3d002cb96 100644 --- a/core/src/xmake/os/getown.c +++ b/core/src/xmake/os/getown.c @@ -50,8 +50,9 @@ tb_int_t xm_os_getown(lua_State *lua) { // get stat struct stat sts; - if (stat(pathname, &sts) != 0) + if (stat(pathname, &sts) != 0) { return 0; + } // push lua_newtable(lua); diff --git a/core/src/xmake/os/meminfo.c b/core/src/xmake/os/meminfo.c index 1e6e5f422..44fbb7770 100644 --- a/core/src/xmake/os/meminfo.c +++ b/core/src/xmake/os/meminfo.c @@ -103,8 +103,9 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) tb_int64_t freesize = xm_os_meminfo_get_value(buffer, "MemFree:"); tb_int64_t buffersize = xm_os_meminfo_get_value(buffer, "Buffers:"); tb_int64_t shmemsize = xm_os_meminfo_get_value(buffer, "Shmem:"); - if (cachesize >= 0 && freesize >= 0 && buffersize >= 0 && shmemsize >= 0) + if (cachesize >= 0 && freesize >= 0 && buffersize >= 0 && shmemsize >= 0) { availsize = freesize + buffersize + cachesize - shmemsize; + } } if (totalsize > 0 && availsize >= 0) { *ptotalsize = (tb_int_t)(totalsize / 1024); @@ -134,19 +135,22 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) #elif defined(TB_CONFIG_OS_BSD) && !defined(__OpenBSD__) unsigned long totalsize; size_t size = sizeof(totalsize); - if (sysctlbyname("hw.physmem", &totalsize, &size, tb_null, 0) != 0) + if (sysctlbyname("hw.physmem", &totalsize, &size, tb_null, 0) != 0) { return tb_false; + } // http://web.mit.edu/freebsd/head/usr.bin/systat/vmstat.c tb_uint32_t v_free_count; size = sizeof(v_free_count); - if (sysctlbyname("vm.stats.vm.v_free_count", &v_free_count, &size, tb_null, 0) != 0) + if (sysctlbyname("vm.stats.vm.v_free_count", &v_free_count, &size, tb_null, 0) != 0) { return tb_false; + } tb_uint32_t v_inactive_count; size = sizeof(v_inactive_count); - if (sysctlbyname("vm.stats.vm.v_inactive_count", &v_inactive_count, &size, tb_null, 0) != 0) + if (sysctlbyname("vm.stats.vm.v_inactive_count", &v_inactive_count, &size, tb_null, 0) != 0) { return tb_false; + } *ptotalsize = (tb_int_t)(totalsize / (1024 * 1024)); *pavailsize = (tb_int_t)(((tb_int64_t)(v_free_count + v_inactive_count) * tb_page_size()) / (1024 * 1024)); diff --git a/core/src/xmake/os/mkdir.c b/core/src/xmake/os/mkdir.c index 19507b5aa..9f8b3399d 100644 --- a/core/src/xmake/os/mkdir.c +++ b/core/src/xmake/os/mkdir.c @@ -42,10 +42,11 @@ tb_int_t xm_os_mkdir(lua_State *lua) { // os.mkdir(path) tb_file_info_t info = { 0 }; - if (!tb_file_info(path, &info) || (info.type != TB_FILE_TYPE_DIRECTORY)) + if (!tb_file_info(path, &info) || (info.type != TB_FILE_TYPE_DIRECTORY)) { lua_pushboolean(lua, tb_directory_create(path)); - else + } else { lua_pushboolean(lua, tb_true); + } return 1; } diff --git a/core/src/xmake/os/mtime.c b/core/src/xmake/os/mtime.c index 73014666b..0dd10c7ca 100644 --- a/core/src/xmake/os/mtime.c +++ b/core/src/xmake/os/mtime.c @@ -42,9 +42,10 @@ tb_int_t xm_os_mtime(lua_State *lua) { // os.mtime(path) tb_file_info_t info = { 0 }; - if (tb_file_info(path, &info)) + if (tb_file_info(path, &info)) { lua_pushinteger(lua, (lua_Integer)info.mtime); - else + } else { lua_pushinteger(lua, 0); + } return 1; } diff --git a/core/src/xmake/os/readlink.c b/core/src/xmake/os/readlink.c index 603ab7104..c1a45cf4b 100644 --- a/core/src/xmake/os/readlink.c +++ b/core/src/xmake/os/readlink.c @@ -57,15 +57,17 @@ tb_int_t xm_os_readlink(lua_State *lua) { if (size > 0 && size < maxn) { data[size] = '\0'; lua_pushstring(lua, data); - } else + } else { lua_pushnil(lua); + } tb_free(data); } } else if (size >= 0 && size < TB_PATH_MAXN) { srcpath[size] = '\0'; lua_pushstring(lua, srcpath); - } else + } else { lua_pushnil(lua); + } #endif return 1; diff --git a/core/src/xmake/os/rmdir.c b/core/src/xmake/os/rmdir.c index f04ba2a9c..21b7005a8 100644 --- a/core/src/xmake/os/rmdir.c +++ b/core/src/xmake/os/rmdir.c @@ -57,8 +57,9 @@ static tb_long_t xm_os_rmdir_remove(tb_char_t const *path, tb_file_info_t const tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); // remove empty directory - if (is_emptydir) + if (is_emptydir) { tb_directory_remove(path); + } } return TB_DIRECTORY_WALK_CODE_CONTINUE; } @@ -82,8 +83,9 @@ tb_int_t xm_os_rmdir(lua_State *lua) { // remove empty root directory tb_bool_t is_emptydir = tb_true; tb_directory_walk(path, tb_false, tb_true, xm_os_rmdir_empty, &is_emptydir); - if (is_emptydir) + if (is_emptydir) { tb_directory_remove(path); + } tb_trace_d("path: %s, emptydir: %u", path, is_emptydir); diff --git a/core/src/xmake/os/signal.c b/core/src/xmake/os/signal.c index 4d9e8a4c5..64f68762a 100644 --- a/core/src/xmake/os/signal.c +++ b/core/src/xmake/os/signal.c @@ -78,8 +78,9 @@ static tb_void_t xm_os_signal_handler_impl(tb_int_t signo) { #if defined(TB_CONFIG_OS_WINDOWS) static BOOL WINAPI xm_os_signal_handler(DWORD ctrl_type) { - if (ctrl_type == CTRL_C_EVENT) + if (ctrl_type == CTRL_C_EVENT) { xm_os_signal_handler_impl(XM_OS_SIGINT); + } return TRUE; } #elif defined(SIGINT) @@ -92,8 +93,9 @@ static tb_void_t xm_os_signal_handler(tb_int_t signo_native) { default: break; } - if (signo >= 0) + if (signo >= 0) { xm_os_signal_handler_impl(signo); + } } #endif @@ -106,10 +108,11 @@ tb_int_t xm_os_signal(lua_State *lua) { tb_int_t handler = XM_OS_SIGFUN; // check signal handler - if (lua_isnumber(lua, 2)) + if (lua_isnumber(lua, 2)) { handler = (tb_int_t)luaL_checkinteger(lua, 2); - else if (!lua_isfunction(lua, 2)) + } else if (!lua_isfunction(lua, 2)) { return 0; + } // save signal handler tb_int_t signo = (tb_int_t)luaL_checkinteger(lua, 1); @@ -121,8 +124,9 @@ tb_int_t xm_os_signal(lua_State *lua) { } #if defined(TB_CONFIG_OS_WINDOWS) - if (signo != XM_OS_SIGINT) + if (signo != XM_OS_SIGINT) { return 0; + } switch (handler) { case XM_OS_SIGFUN: diff --git a/core/src/xmake/os/sleep.c b/core/src/xmake/os/sleep.c index 0c4172b43..0c8fa135e 100644 --- a/core/src/xmake/os/sleep.c +++ b/core/src/xmake/os/sleep.c @@ -36,7 +36,8 @@ tb_int_t xm_os_sleep(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); tb_long_t interval = (tb_long_t)luaL_checklong(lua, 1); - if (interval >= 0) + if (interval >= 0) { tb_msleep(interval); + } return 0; } diff --git a/core/src/xmake/os/tmpdir.c b/core/src/xmake/os/tmpdir.c index 4396603d4..6d20fc546 100644 --- a/core/src/xmake/os/tmpdir.c +++ b/core/src/xmake/os/tmpdir.c @@ -38,9 +38,10 @@ tb_int_t xm_os_tmpdir(lua_State *lua) { // os.tmpdir() tb_char_t path[TB_PATH_MAXN]; - if (tb_directory_temporary(path, sizeof(path))) + if (tb_directory_temporary(path, sizeof(path))) { lua_pushstring(lua, path); - else + } else { lua_pushnil(lua); + } return 1; } -- cgit v1.3.1 From 2c387895657ae13cd717d7f42f5baed5eb028a8e Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 10 Nov 2025 21:00:21 +0800 Subject: format more if-else codes in core --- core/src/xmake/path/directory.c | 5 ++-- core/src/xmake/path/translate.c | 8 ++++--- core/src/xmake/process/close.c | 3 ++- core/src/xmake/process/kill.c | 3 ++- core/src/xmake/process/open.c | 15 +++++++----- core/src/xmake/process/openv.c | 27 ++++++++++++++-------- core/src/xmake/readline/clear_history.c | 3 ++- core/src/xmake/readline/readline.c | 3 ++- core/src/xmake/sandbox/interactive.c | 39 +++++++++++++++++++++----------- core/src/xmake/semver/select.c | 8 ++++--- core/src/xmake/semver/semver.c | 10 ++++---- core/src/xmake/string/convert.c | 12 ++++++---- core/src/xmake/string/lastof.c | 15 +++++++----- core/src/xmake/string/split.c | 11 +++++---- core/src/xmake/string/trim.c | 25 ++++++++++++-------- core/src/xmake/thread/event_exit.c | 2 +- core/src/xmake/thread/event_incref.c | 2 +- core/src/xmake/thread/event_post.c | 2 +- core/src/xmake/thread/event_wait.c | 2 +- core/src/xmake/thread/mutex_exit.c | 2 +- core/src/xmake/thread/mutex_incref.c | 2 +- core/src/xmake/thread/mutex_lock.c | 2 +- core/src/xmake/thread/mutex_trylock.c | 2 +- core/src/xmake/thread/mutex_unlock.c | 2 +- core/src/xmake/thread/prefix.h | 25 ++++++++++++-------- core/src/xmake/thread/queue_clear.c | 2 +- core/src/xmake/thread/queue_exit.c | 2 +- core/src/xmake/thread/queue_incref.c | 2 +- core/src/xmake/thread/queue_init.c | 3 ++- core/src/xmake/thread/queue_pop.c | 7 +++--- core/src/xmake/thread/queue_push.c | 2 +- core/src/xmake/thread/queue_size.c | 2 +- core/src/xmake/thread/semaphore_exit.c | 2 +- core/src/xmake/thread/semaphore_incref.c | 2 +- core/src/xmake/thread/semaphore_post.c | 2 +- core/src/xmake/thread/semaphore_wait.c | 2 +- core/src/xmake/thread/sharedata_clear.c | 2 +- core/src/xmake/thread/sharedata_exit.c | 2 +- core/src/xmake/thread/sharedata_get.c | 2 +- core/src/xmake/thread/sharedata_incref.c | 2 +- core/src/xmake/thread/sharedata_set.c | 2 +- core/src/xmake/thread/thread_resume.c | 3 ++- core/src/xmake/thread/thread_suspend.c | 3 ++- core/src/xmake/thread/thread_wait.c | 3 ++- core/src/xmake/tty/term_mode.c | 3 ++- core/src/xmake/utils/bin2c.c | 3 ++- core/src/xmake/winos/ansi.c | 6 +++-- core/src/xmake/winos/logical_drives.c | 3 ++- core/src/xmake/winos/registry_keys.c | 32 ++++++++++++++------------ core/src/xmake/winos/registry_query.c | 29 +++++++++++++----------- core/src/xmake/winos/registry_values.c | 26 +++++++++++---------- 51 files changed, 226 insertions(+), 153 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/path/directory.c b/core/src/xmake/path/directory.c index 0c7d77f2d..7a6b37863 100644 --- a/core/src/xmake/path/directory.c +++ b/core/src/xmake/path/directory.c @@ -43,9 +43,10 @@ tb_int_t xm_path_directory(lua_State *lua) { // do path:directory() tb_char_t data[TB_PATH_MAXN]; tb_char_t const *dir = tb_path_directory(path, data, sizeof(data)); - if (dir) + if (dir) { lua_pushstring(lua, dir); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/path/translate.c b/core/src/xmake/path/translate.c index 7611d188a..8d1debda0 100644 --- a/core/src/xmake/path/translate.c +++ b/core/src/xmake/path/translate.c @@ -46,17 +46,19 @@ tb_int_t xm_path_translate(lua_State *lua) { if (lua_istable(lua, 2)) { lua_pushstring(lua, "normalize"); lua_gettable(lua, 2); - if (lua_toboolean(lua, -1)) + if (lua_toboolean(lua, -1)) { normalize = tb_true; + } lua_pop(lua, 1); } // do path:translate() tb_char_t data[TB_PATH_MAXN]; tb_size_t size = tb_path_translate_to(path, (tb_size_t)path_size, data, sizeof(data), normalize); - if (size) + if (size) { lua_pushlstring(lua, data, (size_t)size); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/process/close.c b/core/src/xmake/process/close.c index fc57453e6..bd39d49ee 100644 --- a/core/src/xmake/process/close.c +++ b/core/src/xmake/process/close.c @@ -39,8 +39,9 @@ tb_int_t xm_process_close(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the process tb_process_ref_t process = (tb_process_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/process/kill.c b/core/src/xmake/process/kill.c index 4859027b4..21cc68149 100644 --- a/core/src/xmake/process/kill.c +++ b/core/src/xmake/process/kill.c @@ -39,8 +39,9 @@ tb_int_t xm_process_kill(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get the process tb_process_ref_t process = (tb_process_ref_t)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c index f0885719a..669e90ff1 100644 --- a/core/src/xmake/process/open.c +++ b/core/src/xmake/process/open.c @@ -68,8 +68,9 @@ tb_int_t xm_process_open(lua_State *lua) { // is detached? lua_pushstring(lua, "detach"); lua_gettable(lua, 2); - if (lua_toboolean(lua, -1)) + if (lua_toboolean(lua, -1)) { attr.flags |= TB_PROCESS_FLAG_DETACH; + } lua_pop(lua, 1); // get curdir @@ -161,9 +162,9 @@ tb_int_t xm_process_open(lua_State *lua) { // is string? if (lua_isstring(lua, -1)) { // add this environment value - if (envn + 1 < tb_arrayn(envs)) + if (envn + 1 < tb_arrayn(envs)) { envs[envn++] = lua_tostring(lua, -1); - else { + } else { // error lua_pushfstring(lua, "envs is too large(%d > %d) for process.openv", @@ -239,14 +240,16 @@ tb_int_t xm_process_open(lua_State *lua) { } // set the new environments - if (envn > 0) + if (envn > 0) { attr.envp = envs; + } // init process tb_process_ref_t process = (tb_process_ref_t)tb_process_init_cmd(command, &attr); - if (process) + if (process) { xm_lua_pushpointer(lua, (tb_pointer_t)process); - else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c index 99a6133d0..1b95c45fe 100644 --- a/core/src/xmake/process/openv.c +++ b/core/src/xmake/process/openv.c @@ -117,15 +117,17 @@ tb_int_t xm_process_openv(lua_State *lua) { // is detached? lua_pushstring(lua, "detach"); lua_gettable(lua, 3); - if (lua_toboolean(lua, -1)) + if (lua_toboolean(lua, -1)) { attr.flags |= TB_PROCESS_FLAG_DETACH; + } lua_pop(lua, 1); // is exclusive? lua_pushstring(lua, "exclusive"); lua_gettable(lua, 3); - if (lua_toboolean(lua, -1)) + if (lua_toboolean(lua, -1)) { exclusive = tb_true; + } lua_pop(lua, 1); // get curdir @@ -217,9 +219,9 @@ tb_int_t xm_process_openv(lua_State *lua) { // is string? if (lua_isstring(lua, -1)) { // add this environment value - if (envn + 1 < tb_arrayn(envs)) + if (envn + 1 < tb_arrayn(envs)) { envs[envn++] = lua_tostring(lua, -1); - else { + } else { // error lua_pushfstring(lua, "envs is too large(%d > %d) for process.openv", @@ -295,31 +297,36 @@ tb_int_t xm_process_openv(lua_State *lua) { } // set the new environments - if (envn > 0) + if (envn > 0) { attr.envp = envs; + } /* we need to ignore SIGINT and SIGQUIT if we enter exclusive mode * @see https://github.com/xmake-io/xmake/discussions/2893 */ #if defined(SIGINT) - if (exclusive) + if (exclusive) { signal(SIGINT, SIG_IGN); + } #endif #if defined(SIGQUIT) - if (exclusive) + if (exclusive) { signal(SIGQUIT, SIG_IGN); + } #endif // init process tb_process_ref_t process = (tb_process_ref_t)tb_process_init(shellname, argv, &attr); - if (process) + if (process) { xm_lua_pushpointer(lua, (tb_pointer_t)process); - else + } else { lua_pushnil(lua); + } // exit argv - if (argv) + if (argv) { tb_free(argv); + } argv = tb_null; return 1; diff --git a/core/src/xmake/readline/clear_history.c b/core/src/xmake/readline/clear_history.c index 0235ea4ee..d29690bea 100644 --- a/core/src/xmake/readline/clear_history.c +++ b/core/src/xmake/readline/clear_history.c @@ -41,8 +41,9 @@ tb_int_t xm_readline_clear_history(lua_State *lua) { #ifdef TB_CONFIG_OS_MACOSX // call clear_history (will crash on macOS) - for (tb_int_t i = history_length - 1; i >= 0; --i) + for (tb_int_t i = history_length - 1; i >= 0; --i) { remove_history(i); + } #else clear_history(); #endif diff --git a/core/src/xmake/readline/readline.c b/core/src/xmake/readline/readline.c index b6988e35c..fa3e631cc 100644 --- a/core/src/xmake/readline/readline.c +++ b/core/src/xmake/readline/readline.c @@ -51,8 +51,9 @@ tb_int_t xm_readline_readline(lua_State *lua) { // free it tb_free(line); - } else + } else { lua_pushnil(lua); + } return 1; } diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c index 9e94f876d..ac3566577 100644 --- a/core/src/xmake/sandbox/interactive.c +++ b/core/src/xmake/sandbox/interactive.c @@ -65,8 +65,9 @@ static tb_void_t xm_sandbox_report(lua_State *lua) { if (!lua_isnil(lua, -1)) { // get message tb_char_t const *msg = lua_tostring(lua, -1); - if (!msg) + if (!msg) { msg = "(error object is not a string)"; + } // print it tb_printl(msg); @@ -81,8 +82,9 @@ static tb_void_t xm_sandbox_report(lua_State *lua) { static tb_int_t xm_sandbox_traceback(lua_State *lua) { if (!lua_isstring(lua, 1)) { // non-string error object? try metamethod. - if (lua_isnoneornil(lua, 1) || !luaL_callmeta(lua, 1, "__tostring") || !lua_isstring(lua, -1)) + if (lua_isnoneornil(lua, 1) || !luaL_callmeta(lua, 1, "__tostring") || !lua_isstring(lua, -1)) { return 1; // return non-string error object. + } // replace object by result of __tostring metamethod. lua_remove(lua, 1); @@ -118,8 +120,9 @@ static tb_int_t xm_sandbox_docall(lua_State *lua, tb_int_t narg, tb_int_t clear) lua_remove(lua, errfunc); // force a complete garbage collection in case of errors - if (status != 0) + if (status != 0) { lua_gc(lua, LUA_GCCOLLECT, 0); + } return status; } @@ -154,8 +157,9 @@ static tb_size_t xm_sandbox_readline(tb_char_t *data, tb_size_t maxn, tb_char_t free((void *)line); // truncated? - if (size >= maxn) + if (size >= maxn) { return 0; + } return size; } @@ -166,8 +170,9 @@ static tb_size_t xm_sandbox_readline(tb_char_t *data, tb_size_t maxn, tb_char_t tb_print_sync(); // get input buffer - if (tb_stdfile_gets(tb_stdfile_input(), data, maxn)) + if (tb_stdfile_gets(tb_stdfile_input(), data, maxn)) { return tb_strlen(data); + } #endif // no more input @@ -181,8 +186,9 @@ static tb_int_t xm_sandbox_pushline(lua_State *lua, tb_char_t const *prompt2) { tb_size_t size = xm_sandbox_readline(data, sizeof(data), prompt2); if (size) { // split line '\0' - if (data[size - 1] == '\n') + if (data[size - 1] == '\n') { data[size - 1] = '\0'; + } // push line lua_pushstring(lua, data); @@ -216,8 +222,9 @@ static tb_int_t xm_sandbox_loadline(lua_State *lua, tb_int_t top) { tb_size_t size = xm_sandbox_readline(data + 7, sizeof(data) - 7, prompt); if (size) { // split line '\0' - if (data[size - 1] == '\n') + if (data[size - 1] == '\n') { data[--size] = '\0'; + } // patch "return " tb_memcpy(data, "return ", 7); @@ -225,8 +232,9 @@ static tb_int_t xm_sandbox_loadline(lua_State *lua, tb_int_t top) { // attempt to load "return ..." status = luaL_loadbuffer(lua, data, size + 7, "=stdin"); - if (status != LUA_ERRSYNTAX) + if (status != LUA_ERRSYNTAX) { return status; + } // pop error msg lua_pop(lua, 1); @@ -246,12 +254,14 @@ static tb_int_t xm_sandbox_loadline(lua_State *lua, tb_int_t top) { status = luaL_loadbuffer(lua, lua_tostring(lua, -1), (size_t)lua_strlen(lua, -1), "=stdin"); // complete? - if (!xm_sandbox_incomplete(lua, status)) + if (!xm_sandbox_incomplete(lua, status)) { break; + } // get more input - if (!xm_sandbox_pushline(lua, prompt2)) + if (!xm_sandbox_pushline(lua, prompt2)) { return -1; + } // cancel multi-line input? if (!tb_strcmp(lua_tostring(lua, -1), "q")) { @@ -313,10 +323,11 @@ tb_int_t xm_sandbox_interactive(lua_State *lua) { lua_getfield(lua, 1, "$interactive_setfenv"); lua_pushvalue(lua, -2); lua_pushvalue(lua, 1); - if (lua_pcall(lua, 2, 0, 0) != 0) + if (lua_pcall(lua, 2, 0, 0) != 0) { tb_printl(lua_pushfstring(lua, "error calling " LUA_QL("$interactive_setfenv") " (%s)", lua_tostring(lua, -1))); + } #endif /* run script @@ -327,8 +338,9 @@ tb_int_t xm_sandbox_interactive(lua_State *lua) { } // report errors - if (status) + if (status) { xm_sandbox_report(lua); + } // print any results if (status == 0 && lua_gettop(lua) > top) { @@ -342,9 +354,10 @@ tb_int_t xm_sandbox_interactive(lua_State *lua) { */ lua_getfield(lua, 1, "$interactive_dump"); // load $interactive_dump() from sandbox_scope lua_insert(lua, -(count + 1)); - if (lua_pcall(lua, count, 0, 0) != 0) + if (lua_pcall(lua, count, 0, 0) != 0) { tb_printl( lua_pushfstring(lua, "error calling " LUA_QL("$interactive_dump") " (%s)", lua_tostring(lua, -1))); + } } } diff --git a/core/src/xmake/semver/select.c b/core/src/xmake/semver/select.c index 7109bfc83..de3904288 100644 --- a/core/src/xmake/semver/select.c +++ b/core/src/xmake/semver/select.c @@ -47,10 +47,11 @@ static tb_bool_t xm_semver_select_from_versions_tags1( tb_char_t const *source_str = luaL_checkstring(lua, -1); if (source_str && semver_tryn(semver, source_str, tb_strlen(source_str)) == 0) { - if (semver_range_pmatch(semver, range)) + if (semver_range_pmatch(semver, range)) { semvers_ppush(matches, *semver); - else + } else { semver_dtor(semver); + } } lua_pop(lua, 1); } @@ -138,8 +139,9 @@ static tb_bool_t xm_semver_select_latest_from_versions_tags(lua_State *lua, lua_gettable(lua, fromidx); tb_char_t const *source_str = luaL_checkstring(lua, -1); - if (source_str && semver_tryn(semver, source_str, tb_strlen(source_str)) == 0) + if (source_str && semver_tryn(semver, source_str, tb_strlen(source_str)) == 0) { semvers_ppush(matches, *semver); + } lua_pop(lua, 1); } diff --git a/core/src/xmake/semver/semver.c b/core/src/xmake/semver/semver.c index bd13828fa..201f83435 100644 --- a/core/src/xmake/semver/semver.c +++ b/core/src/xmake/semver/semver.c @@ -61,10 +61,11 @@ tb_void_t lua_pushsemver(lua_State *lua, semver_t const *semver) { tb_uchar_t i = 0; semver_id_t const *id = &semver->prerelease; while (id && id->len) { - if (id->numeric) + if (id->numeric) { lua_pushinteger(lua, id->num); - else + } else { lua_pushlstring(lua, id->raw, id->len); + } id = id->next; lua_rawseti(lua, -2, ++i); } @@ -76,10 +77,11 @@ tb_void_t lua_pushsemver(lua_State *lua, semver_t const *semver) { lua_newtable(lua); id = &semver->build; while (id && id->len) { - if (id->numeric) + if (id->numeric) { lua_pushinteger(lua, id->num); - else + } else { lua_pushlstring(lua, id->raw, id->len); + } id = id->next; lua_rawseti(lua, -2, ++i); } diff --git a/core/src/xmake/string/convert.c b/core/src/xmake/string/convert.c index 88dc5ceb1..b3adaf8b8 100644 --- a/core/src/xmake/string/convert.c +++ b/core/src/xmake/string/convert.c @@ -76,10 +76,11 @@ static xm_charset_entry_ref_t xm_string_charset_find_by_name(tb_char_t const *na // find it by the binary search tb_size_t itor = tb_binary_find_all_if(iterator, xm_string_charset_comp_by_name, name); - if (itor != tb_iterator_tail(iterator)) + if (itor != tb_iterator_tail(iterator)) { return (xm_charset_entry_ref_t)tb_iterator_item(iterator, itor); - else + } else { return tb_null; + } } /* ////////////////////////////////////////////////////////////////////////////////////// @@ -115,9 +116,9 @@ tb_int_t xm_string_convert(lua_State *lua) { tb_check_return_val(fcharset && tcharset, 0); // empty string? - if (!src_size) + if (!src_size) { lua_pushstring(lua, ""); - else { + } else { // convert string tb_long_t dst_size = 0; tb_size_t dst_maxn = (tb_size_t)src_size << 2; @@ -131,8 +132,9 @@ tb_int_t xm_string_convert(lua_State *lua) { dst_maxn)) >= 0 && dst_size < dst_maxn) { lua_pushlstring(lua, (tb_char_t const *)dst_data, dst_size); - } else + } else { lua_pushnil(lua); + } tb_free(dst_data); } diff --git a/core/src/xmake/string/lastof.c b/core/src/xmake/string/lastof.c index 0d52e01ac..8785e3987 100644 --- a/core/src/xmake/string/lastof.c +++ b/core/src/xmake/string/lastof.c @@ -48,17 +48,19 @@ static tb_void_t xm_string_lastof_str( } while (!next); // found? - if (curr) + if (curr) { lua_pushinteger(lua, curr - cstr + 1); - else + } else { lua_pushnil(lua); + } } static tb_void_t xm_string_lastof_chr(lua_State *lua, tb_char_t const *cstr, tb_size_t nstr, tb_char_t ch) { tb_char_t const *pos = tb_strrchr(cstr, ch); // faster than tb_strnrchr() - if (pos) + if (pos) { lua_pushinteger(lua, pos - cstr + 1); - else + } else { lua_pushnil(lua); + } } /* ////////////////////////////////////////////////////////////////////////////////////// @@ -83,9 +85,10 @@ tb_int_t xm_string_lastof(lua_State *lua) { // lastof it lua_newtable(lua); - if (nsubstr == 1) + if (nsubstr == 1) { xm_string_lastof_chr(lua, cstr, (tb_size_t)nstr, csubstr[0]); - else + } else { xm_string_lastof_str(lua, cstr, (tb_size_t)nstr, csubstr, nsubstr); + } return 1; } diff --git a/core/src/xmake/string/split.c b/core/src/xmake/string/split.c index 56e8a636d..5ca0c92bb 100644 --- a/core/src/xmake/string/split.c +++ b/core/src/xmake/string/split.c @@ -45,8 +45,9 @@ static tb_void_t xm_string_split_str(lua_State *lua, tb_char_t const *pos = tb_strstr(cstr, cdls); // faster than tb_strnstr() while (pos && pos < end) { if (pos > cstr || strict) { - if (limit > 0 && num + 1 >= limit) + if (limit > 0 && num + 1 >= limit) { break; + } lua_pushlstring(lua, cstr, pos - cstr); lua_rawseti(lua, -2, ++num); @@ -70,8 +71,9 @@ static tb_void_t xm_string_split_chr( tb_char_t const *pos = tb_strchr(cstr, ch); // faster than tb_strnchr() while (pos && pos < end) { if (pos > cstr || strict) { - if (limit > 0 && num + 1 >= limit) + if (limit > 0 && num + 1 >= limit) { break; + } lua_pushlstring(lua, cstr, pos - cstr); lua_rawseti(lua, -2, ++num); @@ -119,9 +121,10 @@ tb_int_t xm_string_split(lua_State *lua) { // split it lua_newtable(lua); - if (ndls == 1) + if (ndls == 1) { xm_string_split_chr(lua, cstr, (tb_size_t)nstr, cdls[0], strict, limit); - else + } else { xm_string_split_str(lua, cstr, (tb_size_t)nstr, cdls, ndls, strict, limit); + } return 1; } diff --git a/core/src/xmake/string/trim.c b/core/src/xmake/string/trim.c index c1dcdad8d..54e6e4b5a 100644 --- a/core/src/xmake/string/trim.c +++ b/core/src/xmake/string/trim.c @@ -40,15 +40,18 @@ static tb_void_t xm_string_trim_space(tb_char_t const **psstr, tb_char_t const * tb_char_t const *e = *pestr; // trim left? - if (mode <= 0) - while (p < e && tb_isspace(*p)) + if (mode <= 0) { + while (p < e && tb_isspace(*p)) { p++; + } + } // trim right if (mode >= 0) { e--; - while (e >= p && tb_isspace(*e)) + while (e >= p && tb_isspace(*e)) { e--; + } e++; } @@ -64,8 +67,9 @@ static tb_char_t const *xm_string_ltrim(tb_char_t const *sstr, tb_assert(sstr && estr && ctrim); tb_char_t const *p = sstr; - while (p < estr && tb_strnchr(ctrim, ntrim, *p)) + while (p < estr && tb_strnchr(ctrim, ntrim, *p)) { p++; + } return p; } @@ -76,8 +80,9 @@ static tb_char_t const *xm_string_rtrim(tb_char_t const *sstr, tb_assert(sstr && estr && ctrim); tb_char_t const *p = estr - 1; - while (p >= sstr && tb_strnchr(ctrim, ntrim, *p)) + while (p >= sstr && tb_strnchr(ctrim, ntrim, *p)) { p--; + } return p + 1; } @@ -110,14 +115,16 @@ tb_int_t xm_string_trim(lua_State *lua) { tb_char_t const *const rsstr = sstr; tb_char_t const *const restr = estr; - if (ltrim == 0) + if (ltrim == 0) { xm_string_trim_space(&sstr, &estr, trimtype); - else { + } else { // trim chars - if (trimtype <= 0) + if (trimtype <= 0) { sstr = xm_string_ltrim(sstr, estr, trimchars, ltrim); - if (trimtype >= 0) + } + if (trimtype >= 0) { estr = xm_string_rtrim(sstr, estr, trimchars, ltrim); + } } // no trimed chars diff --git a/core/src/xmake/thread/event_exit.c b/core/src/xmake/thread/event_exit.c index 501a72a8f..a9b16db6c 100644 --- a/core/src/xmake/thread/event_exit.c +++ b/core/src/xmake/thread/event_exit.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_event_exit.c + * @file event_exit.c * */ diff --git a/core/src/xmake/thread/event_incref.c b/core/src/xmake/thread/event_incref.c index 28c631056..9a2b6163a 100644 --- a/core/src/xmake/thread/event_incref.c +++ b/core/src/xmake/thread/event_incref.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_event_incref.c + * @file event_incref.c * */ diff --git a/core/src/xmake/thread/event_post.c b/core/src/xmake/thread/event_post.c index 0762f6af1..fea3fdd82 100644 --- a/core/src/xmake/thread/event_post.c +++ b/core/src/xmake/thread/event_post.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_event_lock.c + * @file event_post.c * */ diff --git a/core/src/xmake/thread/event_wait.c b/core/src/xmake/thread/event_wait.c index 73e476427..ae4453d5e 100644 --- a/core/src/xmake/thread/event_wait.c +++ b/core/src/xmake/thread/event_wait.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_event_wait.c + * @file event_wait.c * */ diff --git a/core/src/xmake/thread/mutex_exit.c b/core/src/xmake/thread/mutex_exit.c index f415de339..6d79e6197 100644 --- a/core/src/xmake/thread/mutex_exit.c +++ b/core/src/xmake/thread/mutex_exit.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_mutex_exit.c + * @file mutex_exit.c * */ diff --git a/core/src/xmake/thread/mutex_incref.c b/core/src/xmake/thread/mutex_incref.c index 3706ec276..d76f49daf 100644 --- a/core/src/xmake/thread/mutex_incref.c +++ b/core/src/xmake/thread/mutex_incref.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_mutex_incref.c + * @file mutex_incref.c * */ diff --git a/core/src/xmake/thread/mutex_lock.c b/core/src/xmake/thread/mutex_lock.c index f5e9154ae..711c3a07b 100644 --- a/core/src/xmake/thread/mutex_lock.c +++ b/core/src/xmake/thread/mutex_lock.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_mutex_lock.c + * @file mutex_lock.c * */ diff --git a/core/src/xmake/thread/mutex_trylock.c b/core/src/xmake/thread/mutex_trylock.c index fdc90e883..7149a2b62 100644 --- a/core/src/xmake/thread/mutex_trylock.c +++ b/core/src/xmake/thread/mutex_trylock.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_mutex_trylock.c + * @file mutex_trylock.c * */ diff --git a/core/src/xmake/thread/mutex_unlock.c b/core/src/xmake/thread/mutex_unlock.c index 93503e197..a73d04dc1 100644 --- a/core/src/xmake/thread/mutex_unlock.c +++ b/core/src/xmake/thread/mutex_unlock.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_mutex_unlock.c + * @file mutex_unlock.c * */ diff --git a/core/src/xmake/thread/prefix.h b/core/src/xmake/thread/prefix.h index 9b038a8cb..2ddd14adf 100644 --- a/core/src/xmake/thread/prefix.h +++ b/core/src/xmake/thread/prefix.h @@ -92,50 +92,55 @@ typedef struct __xm_thread_sharedata_t { // get the thread event from arguments static __tb_inline__ xm_thread_event_t *xm_thread_event_get(lua_State *lua, tb_int_t index) { xm_thread_event_t *thread_event = tb_null; - if (xm_lua_isinteger(lua, index)) + if (xm_lua_isinteger(lua, index)) { thread_event = (xm_thread_event_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) + } else if (xm_lua_ispointer(lua, index)) { thread_event = (xm_thread_event_t *)xm_lua_topointer(lua, index); + } return thread_event; } // get the thread mutex from arguments static __tb_inline__ xm_thread_mutex_t *xm_thread_mutex_get(lua_State *lua, tb_int_t index) { xm_thread_mutex_t *thread_mutex = tb_null; - if (xm_lua_isinteger(lua, index)) + if (xm_lua_isinteger(lua, index)) { thread_mutex = (xm_thread_mutex_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) + } else if (xm_lua_ispointer(lua, index)) { thread_mutex = (xm_thread_mutex_t *)xm_lua_topointer(lua, index); + } return thread_mutex; } // get the thread semaphore from arguments static __tb_inline__ xm_thread_semaphore_t *xm_thread_semaphore_get(lua_State *lua, tb_int_t index) { xm_thread_semaphore_t *thread_semaphore = tb_null; - if (xm_lua_isinteger(lua, index)) + if (xm_lua_isinteger(lua, index)) { thread_semaphore = (xm_thread_semaphore_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) + } else if (xm_lua_ispointer(lua, index)) { thread_semaphore = (xm_thread_semaphore_t *)xm_lua_topointer(lua, index); + } return thread_semaphore; } // get the thread queue from arguments static __tb_inline__ xm_thread_queue_t *xm_thread_queue_get(lua_State *lua, tb_int_t index) { xm_thread_queue_t *thread_queue = tb_null; - if (xm_lua_isinteger(lua, index)) + if (xm_lua_isinteger(lua, index)) { thread_queue = (xm_thread_queue_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) + } else if (xm_lua_ispointer(lua, index)) { thread_queue = (xm_thread_queue_t *)xm_lua_topointer(lua, index); + } return thread_queue; } // get the thread sharedata from arguments static __tb_inline__ xm_thread_sharedata_t *xm_thread_sharedata_get(lua_State *lua, tb_int_t index) { xm_thread_sharedata_t *thread_sharedata = tb_null; - if (xm_lua_isinteger(lua, index)) + if (xm_lua_isinteger(lua, index)) { thread_sharedata = (xm_thread_sharedata_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index); - else if (xm_lua_ispointer(lua, index)) + } else if (xm_lua_ispointer(lua, index)) { thread_sharedata = (xm_thread_sharedata_t *)xm_lua_topointer(lua, index); + } return thread_sharedata; } diff --git a/core/src/xmake/thread/queue_clear.c b/core/src/xmake/thread/queue_clear.c index 021475a14..533c035ed 100644 --- a/core/src/xmake/thread/queue_clear.c +++ b/core/src/xmake/thread/queue_clear.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_queue_clear.c + * @file queue_clear.c * */ diff --git a/core/src/xmake/thread/queue_exit.c b/core/src/xmake/thread/queue_exit.c index c30c6b97c..de051250e 100644 --- a/core/src/xmake/thread/queue_exit.c +++ b/core/src/xmake/thread/queue_exit.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_queue_exit.c + * @file queue_exit.c * */ diff --git a/core/src/xmake/thread/queue_incref.c b/core/src/xmake/thread/queue_incref.c index 9dd88b013..2322ce241 100644 --- a/core/src/xmake/thread/queue_incref.c +++ b/core/src/xmake/thread/queue_incref.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_queue_incref.c + * @file queue_incref.c * */ diff --git a/core/src/xmake/thread/queue_init.c b/core/src/xmake/thread/queue_init.c index 20c08ce50..a0d683dd3 100644 --- a/core/src/xmake/thread/queue_init.c +++ b/core/src/xmake/thread/queue_init.c @@ -37,8 +37,9 @@ static tb_void_t xm_thread_value_free(tb_element_ref_t element, tb_pointer_t buf xm_thread_value_t *item = (xm_thread_value_t *)buff; if (item) { if (item->kind == XM_THREAD_VALUE_STR) { - if (item->u.string) + if (item->u.string) { tb_free((tb_pointer_t)item->u.string); + } item->u.string = tb_null; } item->size = 0; diff --git a/core/src/xmake/thread/queue_pop.c b/core/src/xmake/thread/queue_pop.c index ef5f761ec..256cb151e 100644 --- a/core/src/xmake/thread/queue_pop.c +++ b/core/src/xmake/thread/queue_pop.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_queue_pop.c + * @file queue_pop.c * */ @@ -51,10 +51,11 @@ tb_int_t xm_thread_queue_pop(lua_State *lua) { tb_bool_t ok = tb_false; switch (item->kind) { case XM_THREAD_VALUE_STR: - if (item->size) + if (item->size) { lua_pushlstring(lua, item->u.string, item->size); - else + } else { lua_pushliteral(lua, ""); + } ok = tb_true; break; case XM_THREAD_VALUE_INT: diff --git a/core/src/xmake/thread/queue_push.c b/core/src/xmake/thread/queue_push.c index 058ac8f81..0a9ff63e1 100644 --- a/core/src/xmake/thread/queue_push.c +++ b/core/src/xmake/thread/queue_push.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_queue_push.c + * @file queue_push.c * */ diff --git a/core/src/xmake/thread/queue_size.c b/core/src/xmake/thread/queue_size.c index 68a9b5a91..9adfbe028 100644 --- a/core/src/xmake/thread/queue_size.c +++ b/core/src/xmake/thread/queue_size.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_queue_lock.c + * @file queue_size.c * */ diff --git a/core/src/xmake/thread/semaphore_exit.c b/core/src/xmake/thread/semaphore_exit.c index bbc426917..ca6386757 100644 --- a/core/src/xmake/thread/semaphore_exit.c +++ b/core/src/xmake/thread/semaphore_exit.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_semaphore_exit.c + * @file semaphore_exit.c * */ diff --git a/core/src/xmake/thread/semaphore_incref.c b/core/src/xmake/thread/semaphore_incref.c index 129a2177d..315332981 100644 --- a/core/src/xmake/thread/semaphore_incref.c +++ b/core/src/xmake/thread/semaphore_incref.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_semaphore_incref.c + * @file semaphore_incref.c * */ diff --git a/core/src/xmake/thread/semaphore_post.c b/core/src/xmake/thread/semaphore_post.c index d709e5a5e..20aea4dc0 100644 --- a/core/src/xmake/thread/semaphore_post.c +++ b/core/src/xmake/thread/semaphore_post.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_semaphore_lock.c + * @file semaphore_post.c * */ diff --git a/core/src/xmake/thread/semaphore_wait.c b/core/src/xmake/thread/semaphore_wait.c index 40337a117..1c886d1bc 100644 --- a/core/src/xmake/thread/semaphore_wait.c +++ b/core/src/xmake/thread/semaphore_wait.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_semaphore_unlock.c + * @file semaphore_wait.c * */ diff --git a/core/src/xmake/thread/sharedata_clear.c b/core/src/xmake/thread/sharedata_clear.c index 426785e0e..e55d5b059 100644 --- a/core/src/xmake/thread/sharedata_clear.c +++ b/core/src/xmake/thread/sharedata_clear.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_sharedata_clear.c + * @file sharedata_clear.c * */ diff --git a/core/src/xmake/thread/sharedata_exit.c b/core/src/xmake/thread/sharedata_exit.c index ad017f2b6..419718f0f 100644 --- a/core/src/xmake/thread/sharedata_exit.c +++ b/core/src/xmake/thread/sharedata_exit.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_sharedata_exit.c + * @file sharedata_exit.c * */ diff --git a/core/src/xmake/thread/sharedata_get.c b/core/src/xmake/thread/sharedata_get.c index 51ebdf62f..6699a7500 100644 --- a/core/src/xmake/thread/sharedata_get.c +++ b/core/src/xmake/thread/sharedata_get.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_sharedata_get.c + * @file sharedata_get.c * */ diff --git a/core/src/xmake/thread/sharedata_incref.c b/core/src/xmake/thread/sharedata_incref.c index 3c11f7d15..8706c00a3 100644 --- a/core/src/xmake/thread/sharedata_incref.c +++ b/core/src/xmake/thread/sharedata_incref.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_sharedata_incref.c + * @file sharedata_incref.c * */ diff --git a/core/src/xmake/thread/sharedata_set.c b/core/src/xmake/thread/sharedata_set.c index 9a4ad3cbd..2bd66d1f9 100644 --- a/core/src/xmake/thread/sharedata_set.c +++ b/core/src/xmake/thread/sharedata_set.c @@ -15,7 +15,7 @@ * Copyright (C) 2015-present, Xmake Open Source Community. * * @author ruki - * @file thread_sharedata_set.c + * @file sharedata_set.c * */ diff --git a/core/src/xmake/thread/thread_resume.c b/core/src/xmake/thread/thread_resume.c index 45253b418..d9ab421cf 100644 --- a/core/src/xmake/thread/thread_resume.c +++ b/core/src/xmake/thread/thread_resume.c @@ -37,8 +37,9 @@ tb_int_t xm_thread_resume(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get thread xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/thread/thread_suspend.c b/core/src/xmake/thread/thread_suspend.c index 1df3063ef..7eb6a6a36 100644 --- a/core/src/xmake/thread/thread_suspend.c +++ b/core/src/xmake/thread/thread_suspend.c @@ -37,8 +37,9 @@ tb_int_t xm_thread_suspend(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get thread xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/thread/thread_wait.c b/core/src/xmake/thread/thread_wait.c index 8ceb45524..8c9ffab18 100644 --- a/core/src/xmake/thread/thread_wait.c +++ b/core/src/xmake/thread/thread_wait.c @@ -37,8 +37,9 @@ tb_int_t xm_thread_wait(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // is pointer? - if (!xm_lua_ispointer(lua, 1)) + if (!xm_lua_ispointer(lua, 1)) { return 0; + } // get thread xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1); diff --git a/core/src/xmake/tty/term_mode.c b/core/src/xmake/tty/term_mode.c index 34998c60b..df5af5b4c 100644 --- a/core/src/xmake/tty/term_mode.c +++ b/core/src/xmake/tty/term_mode.c @@ -65,8 +65,9 @@ tb_int_t xm_tty_term_mode(lua_State *lua) { GetConsoleMode(console_handle, &mode); if (lua_isnumber(lua, 2)) { tb_int_t newmode = (tb_int_t)lua_tointeger(lua, 2); - if (console_handle != INVALID_HANDLE_VALUE) + if (console_handle != INVALID_HANDLE_VALUE) { SetConsoleMode(console_handle, (DWORD)newmode); + } } #else tb_int_t mode = 0; diff --git a/core/src/xmake/utils/bin2c.c b/core/src/xmake/utils/bin2c.c index 77a1b2a8c..61befeaa9 100644 --- a/core/src/xmake/utils/bin2c.c +++ b/core/src/xmake/utils/bin2c.c @@ -74,8 +74,9 @@ static tb_bool_t xm_utils_bin2c_dump(tb_stream_ref_t istream, if (first) { first = tb_false; line[linesize++] = ' '; - } else + } else { line[linesize++] = ','; + } linesize += xm_utils_bin2c_hex2str(line + linesize, data[i]); for (i = 1; i < need; i++) { diff --git a/core/src/xmake/winos/ansi.c b/core/src/xmake/winos/ansi.c index 48bb9df82..9646db59b 100644 --- a/core/src/xmake/winos/ansi.c +++ b/core/src/xmake/winos/ansi.c @@ -38,10 +38,12 @@ static tb_int_t xm_expand_cp(tb_int_t cp) { tb_assert_and_check_return_val(cp >= 0 && cp <= 65535, 0); - if (cp == CP_OEMCP) + if (cp == CP_OEMCP) { return GetOEMCP(); - if (cp == CP_ACP) + } + if (cp == CP_ACP) { return GetACP(); + } return cp; } diff --git a/core/src/xmake/winos/logical_drives.c b/core/src/xmake/winos/logical_drives.c index 7227069b9..9f6df60ea 100644 --- a/core/src/xmake/winos/logical_drives.c +++ b/core/src/xmake/winos/logical_drives.c @@ -69,8 +69,9 @@ tb_int_t xm_winos_logical_drives(lua_State *lua) { } while (0); // exit data - if (data) + if (data) { tb_free(data); + } data = tb_null; return 1; diff --git a/core/src/xmake/winos/registry_keys.c b/core/src/xmake/winos/registry_keys.c index 7daf44ff4..49ddf613f 100644 --- a/core/src/xmake/winos/registry_keys.c +++ b/core/src/xmake/winos/registry_keys.c @@ -138,20 +138,23 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t *info } // enum all subkeys - if (recursion > 0 || recursion < 0) + if (recursion > 0 || recursion < 0) { xm_winos_registry_enum_keys(info, key_path, recursion > 0 ? recursion - 1 : recursion); + } } } while (0); // exit registry key - if (keynew) + if (keynew) { RegCloseKey(keynew); + } keynew = tb_null; // free key path - if (key_path) + if (key_path) { tb_free(key_path); + } key_path = tb_null; } @@ -183,25 +186,25 @@ tb_int_t xm_winos_registry_keys(lua_State *lua) { HKEY key = tb_null; do { // get registry rootkey - if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) + if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) { key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKCR")) + } else if (!tb_strcmp(rootkey, "HKCR")) { key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) + } else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) { key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKCC")) + } else if (!tb_strcmp(rootkey, "HKCC")) { key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) + } else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) { key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKCU")) + } else if (!tb_strcmp(rootkey, "HKCU")) { key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) + } else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) { key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKLM")) + } else if (!tb_strcmp(rootkey, "HKLM")) { key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKEY_USERS")) + } else if (!tb_strcmp(rootkey, "HKEY_USERS")) { key = HKEY_USERS; - else { + } else { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey: %s", rootkey); break; @@ -233,6 +236,7 @@ tb_int_t xm_winos_registry_keys(lua_State *lua) { if (ok) { lua_pushinteger(lua, count); return 1; - } else + } else { return 2; + } } diff --git a/core/src/xmake/winos/registry_query.c b/core/src/xmake/winos/registry_query.c index 5e98af2cd..bfaebe744 100644 --- a/core/src/xmake/winos/registry_query.c +++ b/core/src/xmake/winos/registry_query.c @@ -63,25 +63,25 @@ tb_int_t xm_winos_registry_query(lua_State *lua) { tb_size_t value_n = (tb_size_t)-1; do { // get registry rootkey - if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) + if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) { key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKCR")) + } else if (!tb_strcmp(rootkey, "HKCR")) { key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) + } else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) { key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKCC")) + } else if (!tb_strcmp(rootkey, "HKCC")) { key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) + } else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) { key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKCU")) + } else if (!tb_strcmp(rootkey, "HKCU")) { key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) + } else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) { key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKLM")) + } else if (!tb_strcmp(rootkey, "HKLM")) { key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKEY_USERS")) + } else if (!tb_strcmp(rootkey, "HKEY_USERS")) { key = HKEY_USERS; - else { + } else { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey: %s", rootkey); break; @@ -213,16 +213,19 @@ tb_int_t xm_winos_registry_query(lua_State *lua) { } while (0); // exit registry key - if (keynew) + if (keynew) { RegCloseKey(keynew); + } keynew = tb_null; // exit value - if (value) + if (value) { tb_free(value); + } value = tb_null; - if (value_w) + if (value_w) { tb_free(value_w); + } value_w = tb_null; return ok ? 1 : 2; diff --git a/core/src/xmake/winos/registry_values.c b/core/src/xmake/winos/registry_values.c index 6bda8e690..543665853 100644 --- a/core/src/xmake/winos/registry_values.c +++ b/core/src/xmake/winos/registry_values.c @@ -58,25 +58,25 @@ tb_int_t xm_winos_registry_values(lua_State *lua) { HKEY keynew = tb_null; do { // get registry rootkey - if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) + if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) { key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKCR")) + } else if (!tb_strcmp(rootkey, "HKCR")) { key = HKEY_CLASSES_ROOT; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) + } else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) { key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKCC")) + } else if (!tb_strcmp(rootkey, "HKCC")) { key = HKEY_CURRENT_CONFIG; - else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) + } else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) { key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKCU")) + } else if (!tb_strcmp(rootkey, "HKCU")) { key = HKEY_CURRENT_USER; - else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) + } else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) { key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKLM")) + } else if (!tb_strcmp(rootkey, "HKLM")) { key = HKEY_LOCAL_MACHINE; - else if (!tb_strcmp(rootkey, "HKEY_USERS")) + } else if (!tb_strcmp(rootkey, "HKEY_USERS")) { key = HKEY_USERS; - else { + } else { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey: %s", rootkey); break; @@ -161,13 +161,15 @@ tb_int_t xm_winos_registry_values(lua_State *lua) { } while (0); // exit registry key - if (keynew) + if (keynew) { RegCloseKey(keynew); + } keynew = tb_null; if (ok) { lua_pushinteger(lua, count); return 1; - } else + } else { return 2; + } } -- cgit v1.3.1