diff options
| author | ruki <[email protected]> | 2021-01-11 23:45:36 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-01-11 23:45:36 +0800 |
| commit | bb1180282099720fae44bb619a97f325bd1b04e1 (patch) | |
| tree | 84da0a01625e80d086c99660504b1fbaac5b54a4 /core/src | |
| parent | ab41e77a5db0ab37b4b2f54cc737cfc45c55a463 (diff) | |
| parent | 415cc70c5fff491510cbc667e756c86bf139e172 (diff) | |
Merge pull request #1188 from xmake-io/argv
fix add_defines bug
Diffstat (limited to 'core/src')
| m--------- | core/src/tbox/tbox | 0 | ||||
| -rw-r--r-- | core/src/xmake/os/args.c | 46 | ||||
| -rw-r--r-- | core/src/xmake/os/argv.c | 16 |
3 files changed, 31 insertions, 31 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox -Subproject a175e44090dac8891769d28968a7c06191b1813 +Subproject 3b24fdb96bccec99b2fbb99f1d6b04f67f249da diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c index adfe843a9..4f1c89f7f 100644 --- a/core/src/xmake/os/args.c +++ b/core/src/xmake/os/args.c @@ -38,43 +38,35 @@ static tb_void_t tb_os_args_append(tb_string_ref_t result, tb_char_t const* cstr // check tb_assert_and_check_return(size < TB_PATH_MAXN); - // wrap and escape characters + // need wrap quote? tb_char_t ch; - tb_size_t n = 0; tb_char_t const* p = cstr; tb_bool_t wrap_quote = tb_false; - tb_char_t buff[TB_PATH_MAXN]; - tb_size_t m = tb_arrayn(buff); - while ((ch = *p) && n < m) + if (!nowrap) { - // escape '"' or '\\' - if (ch == '\"' || (escape && ch == '\\')) + while ((ch = *p)) { - if (n < m) buff[n++] = '\\'; + if (ch == ' ' || ch == '(' || ch == ')') wrap_quote = tb_true; + p++; } - else if (ch == ' ' || ch == '(' || ch == ')') wrap_quote = tb_true; - if (n < m) buff[n++] = ch; - p++; } - tb_assert_and_check_return(n < m); - buff[n] = '\0'; - // wrap "" if exists escape characters and spaces? - if (wrap_quote && !nowrap) + // wrap begin quote + if (wrap_quote) tb_string_chrcat(result, '\"'); + + // escape characters + p = cstr; + while ((ch = *p)) { - tb_string_chrcat(result, '\"'); - tb_size_t i = 0; - tb_char_t ch; - for (i = 0; i < n; i++) - { - ch = buff[i]; - if (ch == '\\') // escape the '\\' characters in "" - tb_string_chrcat(result, '\\'); - tb_string_chrcat(result, ch); - } - tb_string_chrcat(result, '\"'); + // escape '"' or '\\' + if (ch == '\"' || ((escape || wrap_quote) && ch == '\\')) + tb_string_chrcat(result, '\\'); + tb_string_chrcat(result, ch); + p++; } - else if (n) tb_string_cstrncat(result, buff, n); + + // wrap end quote + if (wrap_quote) tb_string_chrcat(result, '\"'); } /* ////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/xmake/os/argv.c b/core/src/xmake/os/argv.c index f484fc6cf..980be8863 100644 --- a/core/src/xmake/os/argv.c +++ b/core/src/xmake/os/argv.c @@ -42,7 +42,17 @@ tb_int_t xm_os_argv(lua_State* lua) tb_char_t const* args = luaL_checkstring(lua, 1); tb_check_return_val(args, 0); - // done + // split only? do not escape + tb_bool_t splitonly = tb_false; + if (lua_istable(lua, 2)) + { + lua_pushstring(lua, "splitonly"); + lua_gettable(lua, 2); + splitonly = lua_toboolean(lua, -1); + lua_pop(lua, 1); + } + + // parse argument list tb_string_t arg; do { @@ -88,7 +98,7 @@ tb_int_t xm_os_argv(lua_State* lua) } // save this charactor to argument - if (!skip) tb_string_chrcat(&arg, ch); + if (splitonly || !skip) tb_string_chrcat(&arg, ch); // step and cancel escape if (escape == 1) escape++; @@ -114,7 +124,5 @@ tb_int_t xm_os_argv(lua_State* lua) // exit arg tb_string_exit(&arg); - - // ok return 1; } |
