From 9c2f3c91f97fc572f60b034b9991ebe360405e7f Mon Sep 17 00:00:00 2001 From: zawwz Date: Wed, 20 Jan 2021 12:03:32 +0100 Subject: [PATCH] implement bash specific var=() parsing --- src/debashify.cpp | 20 ++++++++++++-------- src/parse.cpp | 10 +++++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/debashify.cpp b/src/debashify.cpp index f98aecf..941e925 100644 --- a/src/debashify.cpp +++ b/src/debashify.cpp @@ -25,11 +25,18 @@ bool debashify_array_def(cmd* in) for(auto it: in->var_assigns) { if(it.second->size()>0 && it.second->sa[0]->type == _obj::subarg_string && it.second->sa[0]->generate(0) == "(") - throw std::runtime_error("Cannot debashify VAR=() variable arrays"); + throw std::runtime_error("Cannot debashify 'VAR=()' arrays"); } return false; } +bool debashify_array_call(variable* in) +{ + if(in->index != nullptr) + throw std::runtime_error("Cannot debashify 'VAR[I]' arrays"); + return false; +} + bool debashify_herestring(pipeline* pl) { if(pl->cmds.size()>0) @@ -87,13 +94,6 @@ bool debashify_combined_redirects(block* in) return has_replaced; } -// replace <<< and -// <<< : TODO -bool debashify_extended_redirects(pipeline* in) -{ - return false; -} - // replace <() and >() /* REPLACE TO: @@ -192,6 +192,10 @@ bool r_debashify(_obj* o, bool* need_random_func) { switch(o->type) { + case _obj::_variable: { + variable* t = dynamic_cast(o); + debashify_array_call(t); + } break; case _obj::_list: { list* t = dynamic_cast(o); if(debashify_procsub(t)) diff --git a/src/parse.cpp b/src/parse.cpp index 1165d71..9394c98 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -1086,7 +1086,15 @@ std::pair parse_cmd(const char* in, uint32_t size, uint32_t star vp.first->definition=true; i=vp.second+1; arg* ta; - if( is_in(in[i], ARG_END) ) // no value : give empty value + if(g_bash && in[i] == '(') + { + auto pp=parse_arg(in, size, i+1, ")"); + ta=pp.first; + ta->insert(0, new string_subarg("(") ); + ta->add(new string_subarg(")") ); + i=pp.second+1; + } + else if( is_in(in[i], ARG_END) ) // no value : give empty value { ta = new arg; }