diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-09-01 20:36:52 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-09-01 20:36:52 -0700 |
commit | a5d5536fcf2fe616b8c0941df0bc92f3bd9761ba (patch) | |
tree | 59d522eb4ec987ed034707d2644827cb4bc051e8 /stream.c | |
parent | 9c0e5743188588ece98197880a3f1174170dc563 (diff) | |
download | txr-a5d5536fcf2fe616b8c0941df0bc92f3bd9761ba.tar.gz txr-a5d5536fcf2fe616b8c0941df0bc92f3bd9761ba.tar.bz2 txr-a5d5536fcf2fe616b8c0941df0bc92f3bd9761ba.zip |
New functions for shell escaping.
* stream.c (sh_esc, sh_esc_all, sh_esc_dq, sh_esc_sq): New static
functions.
(stream_init): sh-esc, sh-esc-all, sh-esc-dq, sh-esc-sq: Intrinsics
registered.
* tests/018/sh-esc.tl: New file.
* txr.1: Documented.
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -4838,6 +4838,26 @@ static val sh(val command) #endif +static val sh_esc(val string) +{ + return str_esc(lit("|&;<>()$`\\\"' \t\n*?[#~"), chr('\\'), string); +} + +static val sh_esc_all(val string) +{ + return str_esc(lit("|&;<>()$`\\\"' \t\n*?[#~=%"), chr('\\'), string); +} + +static val sh_esc_dq(val string) +{ + return str_esc(lit("$`\\\"\n"), chr('\\'), string); +} + +static val sh_esc_sq(val string) +{ + return str_esc(lit("'"), lit("'\\'"), string); +} + val remove_path(val path, val throw_on_error) { val self = lit("remove-path"); @@ -5556,6 +5576,10 @@ void stream_init(void) reg_fun(intern(lit("sh"), user_package), func_n1(sh)); reg_fun(intern(lit("run"), user_package), func_n2o(run, 1)); #endif + reg_fun(intern(lit("sh-esc"), user_package), func_n1(sh_esc)); + reg_fun(intern(lit("sh-esc-all"), user_package), func_n1(sh_esc_all)); + reg_fun(intern(lit("sh-esc-dq"), user_package), func_n1(sh_esc_dq)); + reg_fun(intern(lit("sh-esc-sq"), user_package), func_n1(sh_esc_sq)); reg_fun(intern(lit("remove-path"), user_package), func_n2o(remove_path, 1)); reg_fun(intern(lit("rename-path"), user_package), func_n2(rename_path)); reg_fun(intern(lit("open-files"), user_package), func_n3o(open_files, 1)); |