diff --git a/src/debashify.cpp b/src/debashify.cpp index 93e06fe..583f730 100644 --- a/src/debashify.cpp +++ b/src/debashify.cpp @@ -103,17 +103,21 @@ bool debashify_bashtest(pipeline* pl) arg *a=nullptr; uint32_t j=1; bool or_op=false; + std::string tmpstr; for(uint32_t i=1 ; iargs->size() ; i++) { a = in->args->args[i]; + tmpstr = a->string(); + bool logic_op = ( tmpstr == "&&" || tmpstr == "||" ); - if(i >= in->args->size()-1 || a->string() == "&&" || a->string() == "||") + if(i >= in->args->size()-1 || logic_op) { block* tbl = gen_bashtest_cmd(std::vector(in->args->args.begin()+j, in->args->args.begin()+i)); cl->add(new pipeline(tbl), or_op); - or_op = a->string() == "||"; + or_op = tmpstr == "||"; j=i+1; - + if(logic_op) + delete a; } } @@ -814,7 +818,7 @@ bool debashify_procsub(list* lst, debashify_params* params) delete affected_args[i].first->sa[0]; affected_args[i].first->sa[0] = new string_subarg("\""); affected_args[i].first->add( new variable_subarg( new variable(strf("_lxshfifo%u", i)) ) ); - affected_args[i].first->add( new string_subarg("\"") ); + affected_args[i].first->add( "\"" ); } lst->insert(li, *lst_insert ); li+= lst_insert->size(); @@ -854,20 +858,24 @@ condlist* debashify_manipulation_substring(variable* v, debashify_params* params arg1->add(v->manip->sa[j]); std::string val=t->val.substr(0, colon_pos); if(val != "") - arg1->add(new string_subarg(val)); + arg1->add(val); val=t->val.substr(colon_pos+1); if(val != "") - arg2->add(new string_subarg(val)); + arg2->add(val); for(uint32_t j=i+1; jmanip->sa.size(); j++) arg2->add(v->manip->sa[j]); + delete v->manip->sa[i]; + v->manip->sa.resize(0); break; // TODO } } } if(arg1 == nullptr) + { arg1 = v->manip; - v->manip = nullptr; + v->manip = nullptr; + } } else { @@ -878,13 +886,13 @@ condlist* debashify_manipulation_substring(variable* v, debashify_params* params pipeline* pl = new pipeline(make_printf_variable(v->varname)); arg* retarg = new arg; retarg->add(new arithmetic_subarg(make_arithmetic(arg1, "+", new arg("1")))); - retarg->add(new string_subarg("-")); + retarg->add("-"); pl->add(make_cmd({new arg("cut"), new arg("-c"), retarg})); if(arg2 != nullptr) { retarg = new arg; - retarg->add(new string_subarg("-")); + retarg->add("-"); for(auto it: arg2->sa) { retarg->add(it); @@ -895,6 +903,10 @@ condlist* debashify_manipulation_substring(variable* v, debashify_params* params pl->add(make_cmd({new arg("cut"), new arg("-c"), retarg})); } + if(v->manip != nullptr) + delete v->manip; + v->manip = nullptr; + return new condlist(pl); } @@ -913,9 +925,9 @@ bool debashify_manipulation(arg* in, debashify_params* params) if(v->is_manip && v->precedence && v->manip->string() == "!") { arg* eval_arg = new arg; - eval_arg->add(new string_subarg("\\\"\\${")); + eval_arg->add("\\\"\\${"); eval_arg->add(new variable_subarg(new variable(v->varname))); - eval_arg->add(new string_subarg("}\\\"")); + eval_arg->add("}\\\""); cmd* eval_cmd = make_cmd({new arg("eval"), new arg("echo"), eval_arg}); r = new subshell_subarg(new subshell(eval_cmd)); } @@ -926,8 +938,8 @@ bool debashify_manipulation(arg* in, debashify_params* params) cmd* sed = make_cmd({std::string("sed")}); arg* sedarg=v->manip; v->manip = nullptr; - sedarg->insert(0, new string_subarg("s")); - sedarg->add(new string_subarg("/")); + sedarg->insert(0, "s"); + sedarg->add("/"); force_quotes(sedarg); sed->add(sedarg); // sed "s///g" diff --git a/src/minify.cpp b/src/minify.cpp index fb2ea47..8c09223 100644 --- a/src/minify.cpp +++ b/src/minify.cpp @@ -480,9 +480,9 @@ bool r_minify_single_block(_obj* in) // deindex t->cmds[i]->redirs.resize(0); if(t->cmds[i]->type == _obj::block_brace) - dynamic_cast(t->cmds[i])->lst->cls[0]->pls[0] = nullptr; + dynamic_cast(t->cmds[i])->lst->cls[0]->pls[0]->cmds[0] = nullptr; else if(t->cmds[i]->type == _obj::block_subshell) - dynamic_cast(t->cmds[i])->lst->cls[0]->pls[0] = nullptr; + dynamic_cast(t->cmds[i])->lst->cls[0]->pls[0]->cmds[0] = nullptr; // replace value delete t->cmds[i]; diff --git a/src/processing.cpp b/src/processing.cpp index 711f497..c6daba5 100644 --- a/src/processing.cpp +++ b/src/processing.cpp @@ -542,7 +542,7 @@ void string_processors(_obj* in) std::string quote_string(std::string const& in) { - return '"' + stringReplace(in, "\"", "\\\"") + '"'; + return '"' + stringReplace(stringReplace(stringReplace(in, "\\", "\\\\"), "\"", "\\\""), "\n", "\\n") + '"'; } std::string gen_json(std::vector> const& vec) diff --git a/src/struc_helper.cpp b/src/struc_helper.cpp index 5d43f06..e1e2a96 100644 --- a/src/struc_helper.cpp +++ b/src/struc_helper.cpp @@ -113,6 +113,7 @@ arithmetic* make_arithmetic(arg* a) }; break; default: break; } + delete a; return ret; } @@ -138,8 +139,8 @@ void force_quotes(arg* in) if(!in->sa[i]->quoted && (in->sa[i]->type == _obj::subarg_variable || in->sa[i]->type == _obj::subarg_subshell) ) { in->sa[i]->quoted=true; - in->insert(i+1, new string_subarg("\"")); - in->insert(i, new string_subarg("\"")); + in->insert(i+1, "\""); + in->insert(i, "\""); i+=2; } } @@ -151,7 +152,7 @@ void add_quotes(arg* in) in->sa[i]->quoted=true; in->insert(0, new string_subarg("\"")); - in->add(new string_subarg("\"")); + in->add("\""); } // ** TESTERS ** // @@ -344,7 +345,7 @@ void condlist::prune_first_cmd() void arg::insert(uint32_t i, std::string const& in) { - if(i>0 && sa[i-1]->type == _obj::subarg_string) + if(i>0 && i<=sa.size() && sa[i-1]->type == _obj::subarg_string) { string_subarg* t = dynamic_cast(sa[i-1]); t->val += in; @@ -367,15 +368,17 @@ void arg::insert(uint32_t i, subarg* val) if(val->type == _obj::subarg_string) { string_subarg* tval = dynamic_cast(val); - if(i>0 && sa[i-1]->type == _obj::subarg_string) + if(i>0 && i<=sa.size() && sa[i-1]->type == _obj::subarg_string) { string_subarg* t = dynamic_cast(sa[i-1]); t->val += tval->val; + delete val; } else if(itype == _obj::subarg_string) { string_subarg* t = dynamic_cast(sa[i]); t->val = tval->val + t->val; + delete val; } else sa.insert(sa.begin()+i, val);