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/thread/queue_clear.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'core/src/xmake/thread/queue_clear.c') 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; } - -- 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/xmake/thread/queue_clear.c') 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