[RFC PATCH 25/28] cli: lil: Always quote items in lil_list_to_value

Sean Anderson
2021-07-01T06:20:53Z

This function took an argument do_quote which determined whether or not to
quote an item. All callers set it to true, so remove it and always quote.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

common/cli_lil.c | 34 ++++++++++++++--------------------
include/cli_lil.h | 2 +-
2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/common/cli_lil.c b/common/cli_lil.c
index 1c7c340bda..153c34791b 100644
--- a/common/cli_lil.c
+++ b/common/cli_lil.c
@@ -2092,7 +2092,7 @@ static struct lil_value *run_cmd(struct lil *lil, struct lil_func *cmd,
if (cmd->argnames->c == 1 &&
!strcmp(lil_to_string(lil_list_get(cmd->argnames, 0)),
"args")) {
- struct lil_value *args = lil_list_to_value(words, 1);
+ struct lil_value *args = lil_list_to_value(words);

lil_set_var(lil, "args", args, LIL_SETVAR_LOCAL_NEW);
lil_free_value(args);
@@ -2389,7 +2389,7 @@ braces:
return needs;
}

-struct lil_value *lil_list_to_value(struct lil_list *list, bool do_escape)
+struct lil_value *lil_list_to_value(struct lil_list *list)
{
struct lil_value *val = alloc_value(NULL);
size_t i, j;
@@ -2397,17 +2397,11 @@ struct lil_value *lil_list_to_value(struct lil_list *list, bool do_escape)
for (i = 0; i < list->c; i++) {
char q;
struct lil_value *item = lil_list_get(list, i);
- enum needs needs;
-
- if (do_escape)
- needs = item_needs(lil_to_string(item), item->l);
- else
- needs = NEEDS_NOTHING;

if (i)
lil_append_char(val, ' ');

- switch (needs) {
+ switch (item_needs(lil_to_string(item), item->l)) {
case NEEDS_NOTHING:
if (lil_append_val(val, item))
goto err;
@@ -3087,7 +3081,7 @@ static struct lil_value *fnc_reflect(struct lil *lil, size_t argc,
func = lil_find_cmd(lil, lil_to_string(argv[1]));
if (!func || !func->argnames)
return NULL;
- return lil_list_to_value(func->argnames, 1);
+ return lil_list_to_value(func->argnames);
}

if (!strcmp(type, "body")) {
@@ -3111,7 +3105,7 @@ static struct lil_value *fnc_reflect(struct lil *lil, size_t argc,
lil_list_append(funcs,
lil_alloc_string(lil->cmd[i]->name));

- r = lil_list_to_value(funcs, 1);
+ r = lil_list_to_value(funcs);
lil_free_list(funcs);
return r;
}
@@ -3130,7 +3124,7 @@ static struct lil_value *fnc_reflect(struct lil *lil, size_t argc,
env = env->parent;
}

- r = lil_list_to_value(vars, 1);
+ r = lil_list_to_value(vars);
lil_free_list(vars);
return r;
}
@@ -3145,7 +3139,7 @@ static struct lil_value *fnc_reflect(struct lil *lil, size_t argc,
lil_list_append(vars, var);
}

- r = lil_list_to_value(vars, 1);
+ r = lil_list_to_value(vars);
lil_free_list(vars);
return r;
}
@@ -3513,7 +3507,7 @@ static struct lil_value *fnc_append(struct lil *lil, size_t argc,
for (i = base; i < argc; i++)
lil_list_append(list, lil_clone_value(argv[i]));

- r = lil_list_to_value(list, 1);
+ r = lil_list_to_value(list);
lil_free_list(list);
lil_set_var(lil, varname, r, access);
return r;
@@ -3548,7 +3542,7 @@ static struct lil_value *fnc_slice(struct lil *lil, size_t argc,
lil_list_append(slice, lil_clone_value(lil_list_get(list, i)));
lil_free_list(list);

- r = lil_list_to_value(slice, 1);
+ r = lil_list_to_value(slice);
lil_free_list(slice);
return r;
}
@@ -3586,7 +3580,7 @@ static struct lil_value *fnc_filter(struct lil *lil, size_t argc,
}
lil_free_list(list);

- r = lil_list_to_value(filtered, 1);
+ r = lil_list_to_value(filtered);
lil_free_list(filtered);
return r;
}
@@ -3601,7 +3595,7 @@ static struct lil_value *fnc_list(struct lil *lil, size_t argc,
for (i = 0; i < argc; i++)
lil_list_append(list, lil_clone_value(argv[i]));

- r = lil_list_to_value(list, 1);
+ r = lil_list_to_value(list);
lil_free_list(list);
return r;
}
@@ -3628,7 +3622,7 @@ static struct lil_value *fnc_concat(struct lil *lil, size_t argc,
r = lil_alloc_string("");
for (i = 0; i < argc; i++) {
list = lil_subst_to_list(lil, argv[i]);
- tmp = lil_list_to_value(list, 1);
+ tmp = lil_list_to_value(list);
lil_free_list(list);
lil_append_val(r, tmp);
lil_free_value(tmp);
@@ -3672,7 +3666,7 @@ static struct lil_value *fnc_foreach(struct lil *lil, size_t argc,
break;
}

- r = lil_list_to_value(rlist, 1);
+ r = lil_list_to_value(rlist);
lil_free_list(list);
lil_free_list(rlist);
return r;
@@ -4147,7 +4141,7 @@ static struct lil_value *fnc_split(struct lil *lil, size_t argc,
}

lil_list_append(list, val);
- val = lil_list_to_value(list, 1);
+ val = lil_list_to_value(list);
lil_free_list(list);
return val;
}
diff --git a/include/cli_lil.h b/include/cli_lil.h
index 290329372a..6fbc270f1b 100644
--- a/include/cli_lil.h
+++ b/include/cli_lil.h
@@ -161,7 +161,7 @@ void lil_free_list(struct lil_list *list);
int lil_list_append(struct lil_list *list, void *item);
size_t lil_list_size(struct lil_list *list);
struct lil_value *lil_list_get(struct lil_list *list, size_t index);
-struct lil_value *lil_list_to_value(struct lil_list *list, bool do_escape);
+struct lil_value *lil_list_to_value(struct lil_list *list);

struct lil_list *lil_subst_to_list(struct lil *lil, struct lil_value *code);
struct lil_value *lil_subst_to_value(struct lil *lil, struct lil_value *code);
--
2.32.0