From b432fc82c78bb890eca5938c7754950f089c7abe Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 23 Sep 2024 14:36:20 -0400 Subject: Add shell escaping for arrays of text --- stdlib/shell.c | 11 +++++++++++ stdlib/shell.h | 1 + 2 files changed, 12 insertions(+) (limited to 'stdlib') diff --git a/stdlib/shell.c b/stdlib/shell.c index 977fa512..28c85fb1 100644 --- a/stdlib/shell.c +++ b/stdlib/shell.c @@ -33,6 +33,17 @@ public Shell_t Shell$escape_text(Text_t text) return (Text_t){.length=shell_graphemes.length, .tag=TEXT_GRAPHEMES, .graphemes=shell_graphemes.data}; } +public Shell_t Shell$escape_text_array(Array_t texts) +{ + Array_t all_escaped = {}; + for (int64_t i = 0; i < texts.length; i++) { + Text_t raw = *(Text_t*)(texts.data + i*texts.stride); + Text_t escaped = Shell$escape_text(raw); + Array$insert(&all_escaped, &escaped, I(0), sizeof(Text_t)); + } + return Text$join(Text(" "), all_escaped); +} + public OptionalArray_t Shell$run_bytes(Shell_t command) { const char *cmd_str = Text$as_c_string(command); diff --git a/stdlib/shell.h b/stdlib/shell.h index 16d0b10d..14a086ef 100644 --- a/stdlib/shell.h +++ b/stdlib/shell.h @@ -17,6 +17,7 @@ OptionalClosure_t Shell$by_line(Shell_t command); Shell_t Shell$escape_text(Text_t text); +Shell_t Shell$escape_text_array(Array_t texts); OptionalArray_t Shell$run_bytes(Shell_t command); OptionalText_t Shell$run(Shell_t command); -- cgit v1.2.3