From e4de55ebffbb44fef181d1f5654aca8416a425d9 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Thu, 6 Jul 2023 15:36:18 +0800 Subject: [PATCH] improve tools/common --- docs/changes.md | 3 +++ tools/common/main.inc | 30 +++++++++++++++++++++++++++++- tools/common/utils.c | 27 --------------------------- tools/common/utils.h | 3 --- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index c17281d50..113470440 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,5 +1,8 @@ # 最新动态 +2023/07/06 + * 完善tools/common。 + 2023/07/05 * 完善serial helper的文档(感谢俊杰提供补丁)。 * 完善资源生成脚本(感谢智明提供补丁)。 diff --git a/tools/common/main.inc b/tools/common/main.inc index 8b276911f..e67ba5888 100644 --- a/tools/common/main.inc +++ b/tools/common/main.inc @@ -1,4 +1,32 @@ -#include "common/utils.h" +#include "tkc.h" + +wchar_t** argvw_create(int argc, char* argv[]) { + int i = 0; + wstr_t str; + wchar_t** argvw = (wchar_t**)TKMEM_ALLOC((argc + 1) * sizeof(wchar_t*)); + return_value_if_fail(argvw != NULL, NULL); + wstr_init(&str, 100); + + for (i = 0; i < argc; i++) { + wstr_set_utf8(&str, argv[i]); + argvw[i] = wcs_dup(str.str); + } + argvw[i] = NULL; + + return argvw; +} + +ret_t argvw_destroy(wchar_t** argvw) { + uint32_t i = 0; + return_value_if_fail(argvw != NULL, RET_BAD_PARAMS); + + for (i = 0; argvw[i] != NULL; i++) { + TKMEM_FREE(argvw[i]); + } + TKMEM_FREE(argvw); + + return RET_OK; +} #if !defined(WIN32) || defined(MINGW) int main(int argc, char* argv[]) { diff --git a/tools/common/utils.c b/tools/common/utils.c index dd5c4ea33..ef2b5d73c 100644 --- a/tools/common/utils.c +++ b/tools/common/utils.c @@ -315,30 +315,3 @@ const char* filter_name(char* name) { return name; } -wchar_t** argvw_create(int argc, char* argv[]) { - int i = 0; - wstr_t str; - wchar_t** argvw = TKMEM_ALLOC((argc + 1) * sizeof(wchar_t*)); - return_value_if_fail(argvw != NULL, NULL); - wstr_init(&str, 100); - - for (i = 0; i < argc; i++) { - wstr_set_utf8(&str, argv[i]); - argvw[i] = wcs_dup(str.str); - } - argvw[i] = NULL; - - return argvw; -} - -ret_t argvw_destroy(wchar_t** argvw) { - uint32_t i = 0; - return_value_if_fail(argvw != NULL, RET_BAD_PARAMS); - - for (i = 0; argvw[i] != NULL; i++) { - TKMEM_FREE(argvw[i]); - } - TKMEM_FREE(argvw); - - return RET_OK; -} diff --git a/tools/common/utils.h b/tools/common/utils.h index 29f9a46d1..ac9b804ea 100644 --- a/tools/common/utils.h +++ b/tools/common/utils.h @@ -54,9 +54,6 @@ const char* get_next_token(const char* p, char* token, char c); const char* filter_name(char* name); -wchar_t** argvw_create(int argc, char* argv[]); -ret_t argvw_destroy(wchar_t** argvw); - END_C_DECLS #endif // UTILS_H