implement debashify on <<< herestring
This commit is contained in:
parent
142a91e68a
commit
1b0c97f5bb
5 changed files with 52 additions and 4 deletions
|
|
@ -103,6 +103,8 @@ class subarg : public _obj
|
||||||
public:
|
public:
|
||||||
virtual ~subarg() {;}
|
virtual ~subarg() {;}
|
||||||
virtual std::string generate(int ind)=0;
|
virtual std::string generate(int ind)=0;
|
||||||
|
|
||||||
|
bool quoted;
|
||||||
};
|
};
|
||||||
|
|
||||||
class arg : public _obj
|
class arg : public _obj
|
||||||
|
|
@ -445,7 +447,7 @@ public:
|
||||||
class variable_subarg : public subarg
|
class variable_subarg : public subarg
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
variable_subarg(std::string const& in="") { type=_obj::subarg_variable; varname=in; }
|
variable_subarg(std::string const& in="", bool inq=false) { type=_obj::subarg_variable; varname=in; quoted=inq; }
|
||||||
~variable_subarg() {;}
|
~variable_subarg() {;}
|
||||||
|
|
||||||
std::string varname;
|
std::string varname;
|
||||||
|
|
@ -471,7 +473,6 @@ public:
|
||||||
~subshell_subarg() { if(sbsh != nullptr) delete sbsh; }
|
~subshell_subarg() { if(sbsh != nullptr) delete sbsh; }
|
||||||
|
|
||||||
subshell* sbsh;
|
subshell* sbsh;
|
||||||
bool quoted;
|
|
||||||
|
|
||||||
std::string generate(int ind);
|
std::string generate(int ind);
|
||||||
};
|
};
|
||||||
|
|
@ -479,7 +480,7 @@ public:
|
||||||
class manipulation_subarg : public subarg
|
class manipulation_subarg : public subarg
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
manipulation_subarg(arg* in=nullptr) { type=_obj::subarg_manipulation; size=false; manip=in; }
|
manipulation_subarg(std::string varname="", arg* in=nullptr, bool inq=false) { type=_obj::subarg_manipulation; size=false; manip=in; quoted=inq; }
|
||||||
~manipulation_subarg() { if(manip!=nullptr) delete manip; }
|
~manipulation_subarg() { if(manip!=nullptr) delete manip; }
|
||||||
|
|
||||||
bool size;
|
bool size;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ cmd* make_cmd(std::vector<std::string> const& args);
|
||||||
cmd* make_cmd(std::string const& in);
|
cmd* make_cmd(std::string const& in);
|
||||||
condlist* make_condlist(std::string const& in);
|
condlist* make_condlist(std::string const& in);
|
||||||
|
|
||||||
|
void force_quotes(arg* in);
|
||||||
|
|
||||||
inline bool operator==(arg a, std::string const& b) { return a.equals(b); }
|
inline bool operator==(arg a, std::string const& b) { return a.equals(b); }
|
||||||
|
|
||||||
#endif //STRUC_HELPER_HPP
|
#endif //STRUC_HELPER_HPP
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,27 @@ bool debashify_array_def(cmd* in)
|
||||||
|
|
||||||
bool debashify_herestring(pipeline* pl)
|
bool debashify_herestring(pipeline* pl)
|
||||||
{
|
{
|
||||||
|
if(pl->cmds.size()>0)
|
||||||
|
{
|
||||||
|
block* c=pl->cmds[0];
|
||||||
|
for(uint32_t i=0; i<c->redirs.size() ; i++)
|
||||||
|
{
|
||||||
|
if(c->redirs[i]->op == "<<<")
|
||||||
|
{
|
||||||
|
force_quotes(c->redirs[i]->target);
|
||||||
|
cmd* printcmd = make_cmd("printf '%s\\n'");
|
||||||
|
printcmd->add(c->redirs[i]->target);
|
||||||
|
pl->cmds.insert(pl->cmds.begin(), printcmd);
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
c->redirs[i]->target=nullptr;
|
||||||
|
delete c->redirs[i];
|
||||||
|
c->redirs.erase(pl->cmds[1]->redirs.begin()+i);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,6 +208,10 @@ bool r_debashify(_obj* o, bool* need_random_func)
|
||||||
if(debashify_procsub(t))
|
if(debashify_procsub(t))
|
||||||
*need_random_func = true;
|
*need_random_func = true;
|
||||||
} break;
|
} break;
|
||||||
|
case _obj::_pipeline: {
|
||||||
|
pipeline* t = dynamic_cast<pipeline*>(o);
|
||||||
|
debashify_herestring(t);
|
||||||
|
} break;
|
||||||
case _obj::block_cmd: {
|
case _obj::block_cmd: {
|
||||||
cmd* t = dynamic_cast<cmd*>(o);
|
cmd* t = dynamic_cast<cmd*>(o);
|
||||||
debashify_combined_redirects(t);
|
debashify_combined_redirects(t);
|
||||||
|
|
|
||||||
|
|
@ -252,6 +252,7 @@ std::pair<arg*, uint32_t> parse_arg(const char* in, uint32_t size, uint32_t star
|
||||||
ret->add(new string_subarg(tmpstr));
|
ret->add(new string_subarg(tmpstr));
|
||||||
// get arithmetic
|
// get arithmetic
|
||||||
auto r=parse_arithmetic(in, size, i+3);
|
auto r=parse_arithmetic(in, size, i+3);
|
||||||
|
r.first->quoted=true;
|
||||||
ret->add(r.first);
|
ret->add(r.first);
|
||||||
j = i = r.second;
|
j = i = r.second;
|
||||||
}
|
}
|
||||||
|
|
@ -274,6 +275,7 @@ std::pair<arg*, uint32_t> parse_arg(const char* in, uint32_t size, uint32_t star
|
||||||
ret->add(new string_subarg(tmpstr));
|
ret->add(new string_subarg(tmpstr));
|
||||||
// get manipulation
|
// get manipulation
|
||||||
auto r=parse_manipulation(in, size, i+2);
|
auto r=parse_manipulation(in, size, i+2);
|
||||||
|
r.first->quoted=true;
|
||||||
ret->add(r.first);
|
ret->add(r.first);
|
||||||
j = i = r.second;
|
j = i = r.second;
|
||||||
}
|
}
|
||||||
|
|
@ -287,7 +289,7 @@ std::pair<arg*, uint32_t> parse_arg(const char* in, uint32_t size, uint32_t star
|
||||||
if(tmpstr!="")
|
if(tmpstr!="")
|
||||||
ret->add(new string_subarg(tmpstr));
|
ret->add(new string_subarg(tmpstr));
|
||||||
// add varname
|
// add varname
|
||||||
ret->add(new variable_subarg(r.first));
|
ret->add(new variable_subarg(r.first, true));
|
||||||
j = i = r.second;
|
j = i = r.second;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
// ** FUNCTIONS ** //
|
// ** FUNCTIONS ** //
|
||||||
|
|
||||||
|
// makers
|
||||||
|
|
||||||
arg* make_arg(std::string const& in)
|
arg* make_arg(std::string const& in)
|
||||||
{
|
{
|
||||||
return parse_arg(in.c_str(), in.size(), 0).first;
|
return parse_arg(in.c_str(), in.size(), 0).first;
|
||||||
|
|
@ -31,6 +33,22 @@ condlist* make_condlist(std::string const& in)
|
||||||
return parse_condlist(in.c_str(), in.size(), 0).first;
|
return parse_condlist(in.c_str(), in.size(), 0).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// modifiers
|
||||||
|
|
||||||
|
void force_quotes(arg* in)
|
||||||
|
{
|
||||||
|
for(uint32_t i=0; i < in->sa.size() ; i++)
|
||||||
|
{
|
||||||
|
if(!in->sa[i]->quoted && (in->sa[i]->type == _obj::subarg_variable || in->sa[i]->type == _obj::subarg_manipulation || in->sa[i]->type == _obj::subarg_subshell) )
|
||||||
|
{
|
||||||
|
in->sa[i]->quoted=true;
|
||||||
|
in->insert(i, new string_subarg("\""));
|
||||||
|
i+=2;
|
||||||
|
in->insert(i, new string_subarg("\""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ** CLASS EXTENSIONS ** //
|
// ** CLASS EXTENSIONS ** //
|
||||||
|
|
||||||
/// GETTERS ///
|
/// GETTERS ///
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue