summaryrefslogtreecommitdiff
path: root/core/src/xmake/os/args.c
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-12 00:29:12 +0800
committerruki <[email protected]>2021-01-12 00:29:12 +0800
commitbbb48dbc7ee40d510ff6a192417b1b4497d0ca95 (patch)
tree9c735d063db1ef5c9d29b994bf20888a7beaa6de /core/src/xmake/os/args.c
parente2b269b725607e0458cc337555e64c9c7fecde9f (diff)
fix os.args and split flags
Diffstat (limited to 'core/src/xmake/os/args.c')
-rw-r--r--core/src/xmake/os/args.c46
1 files changed, 19 insertions, 27 deletions
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, '\"');
}
/* //////////////////////////////////////////////////////////////////////////////////////