fix bug on minimizing collisions on 'unset' with bash
This commit is contained in:
parent
ed2ebba6ff
commit
ebce56c29c
7 changed files with 41 additions and 13 deletions
|
|
@ -61,6 +61,7 @@ void list_fcts(_obj* in, std::regex const& exclude);
|
|||
void list_cmds(_obj* in, std::regex const& exclude);
|
||||
|
||||
// recursives
|
||||
bool r_get_unsets(_obj* in, set_t* unsets);
|
||||
bool r_get_var(_obj* in, countmap_t* defmap, countmap_t* callmap);
|
||||
bool r_get_cmd(_obj* in, countmap_t* all_cmds);
|
||||
bool r_get_fct(_obj* in, countmap_t* fct_map);
|
||||
|
|
|
|||
|
|
@ -262,10 +262,13 @@ public:
|
|||
|
||||
void add_arg(arg* in);
|
||||
|
||||
|
||||
// preceding var assigns
|
||||
std::vector<std::pair<std::string,arg*>> var_assigns;
|
||||
|
||||
// get var assigns in special cmds (export, unset, read)
|
||||
// check if cmd is this (ex: unset)
|
||||
bool is(std::string const& in);
|
||||
// for var assigns in special cmds (export, unset, read, local)
|
||||
bool is_argvar();
|
||||
std::vector<subarg*> subarg_vars();
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,14 @@ std::set<T> map_to_set(std::map<T,T2> in)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void concat_sets(std::set<std::string>& a, std::set<std::string> const& b);
|
||||
template <class T>
|
||||
void concat_sets(std::set<T>& a, std::set<T> const& b)
|
||||
{
|
||||
for(auto it: b)
|
||||
{
|
||||
a.insert( it );
|
||||
}
|
||||
}
|
||||
|
||||
std::set<std::string> prune_matching(std::set<std::string>& in, std::regex re);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef VERSION_H
|
||||
#define VERSION_H
|
||||
|
||||
#define VERSION_STRING "v0.2"
|
||||
#define VERSION_STRING "v0.2.1"
|
||||
|
||||
#endif //VERSION_H
|
||||
|
|
|
|||
|
|
@ -179,14 +179,16 @@ void minimize_var(_obj* in, std::regex const& exclude)
|
|||
void minimize_fct(_obj* in, std::regex const& exclude)
|
||||
{
|
||||
// countmap_t fcts, cmdmap;
|
||||
set_t allcmds, excluded;
|
||||
set_t allcmds, excluded, unsets;
|
||||
strmap_t fctmap;
|
||||
// get fcts and cmds
|
||||
fctmap_get(in, exclude);
|
||||
cmdmap_get(in, regex_null);
|
||||
recurse(r_get_unsets, in, &unsets);
|
||||
// concatenate cmds and excluded commands
|
||||
allcmds=map_to_set(m_cmds);
|
||||
concat_sets(allcmds, m_excluded_fct);
|
||||
concat_sets(allcmds, unsets);
|
||||
// create mapping
|
||||
fctmap=gen_minimal_map(m_fcts, allcmds);
|
||||
// perform replace
|
||||
|
|
|
|||
|
|
@ -161,6 +161,11 @@ bool cmd::is_argvar()
|
|||
return cmd_is_argvar(this->firstarg_string());
|
||||
}
|
||||
|
||||
bool cmd::is(std::string const& in)
|
||||
{
|
||||
return in == this->firstarg_string();
|
||||
}
|
||||
|
||||
/** GETTERS **/
|
||||
|
||||
void varmap_get(_obj* in, std::regex const& exclude)
|
||||
|
|
@ -196,7 +201,6 @@ void cmdmap_get(_obj* in, std::regex const& exclude)
|
|||
|
||||
/** OUTPUT **/
|
||||
|
||||
|
||||
void list_vars(_obj* in, std::regex const& exclude)
|
||||
{
|
||||
varmap_get(in, exclude);
|
||||
|
|
@ -286,6 +290,25 @@ bool r_get_var(_obj* in, countmap_t* defmap, countmap_t* callmap)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool r_get_unsets(_obj* in, set_t* unsets)
|
||||
{
|
||||
switch(in->type)
|
||||
{
|
||||
case _obj::block_cmd: {
|
||||
cmd* t = dynamic_cast<cmd*>(in);
|
||||
if(t->is("unset"))
|
||||
{
|
||||
for(uint32_t i=1; i<t->args->size(); i++)
|
||||
{
|
||||
unsets->insert(t->args->args[i]->string());
|
||||
}
|
||||
}
|
||||
}; break;
|
||||
default: break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool r_get_cmd(_obj* in, countmap_t* all_cmds)
|
||||
{
|
||||
switch(in->type)
|
||||
|
|
|
|||
|
|
@ -114,14 +114,6 @@ std::string concatargs(std::vector<std::string> const& args)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void concat_sets(std::set<std::string>& a, std::set<std::string> const& b)
|
||||
{
|
||||
for(auto it: b)
|
||||
{
|
||||
a.insert( it );
|
||||
}
|
||||
}
|
||||
|
||||
std::set<std::string> prune_matching(std::set<std::string>& in, std::regex re)
|
||||
{
|
||||
std::set<std::string> ret;
|
||||
|
|
|
|||
Loading…
Reference in a new issue