/**
   Remove variable with specified name
*/
void env_universal_common_remove(const wcstring &name)
{
    env_var_table_t::iterator result =  env_universal_var.find(name);
    if (result != env_universal_var.end())
    {
        var_uni_entry_t* v = result->second;
        env_universal_var.erase(result);
        delete v;
    }
}
void env_universal_common_destroy()
{
    env_var_table_t::iterator iter;

    for (iter = env_universal_var.begin(); iter != env_universal_var.end(); ++iter)
    {
        var_uni_entry_t* value = iter->second;
        delete value;
    }
}
int env_universal_common_get_export(const wcstring &name)
{
    env_var_table_t::const_iterator result = env_universal_var.find(name);
    if (result != env_universal_var.end())
    {
        const var_uni_entry_t *e = result->second;
        if (e != NULL)
            return e->exportv;
    }
    return 0;
}
wchar_t *env_universal_common_get(const wcstring &name)
{
    env_var_table_t::const_iterator result = env_universal_var.find(name);

    if (result != env_universal_var.end())
    {
        const var_uni_entry_t *e = result->second;
        if (e)
            return const_cast<wchar_t*>(e->val.c_str());
    }

    return 0;
}
void enqueue_all(connection_t *c)
{
    env_var_table_t::const_iterator iter;

    for (iter = env_universal_var.begin(); iter != env_universal_var.end(); ++iter)
    {
        const wcstring &key = iter->first;
        const var_uni_entry_t *val = iter->second;

        message_t *msg = create_message(val->exportv?SET_EXPORT:SET, key.c_str(), val->val.c_str());
        msg->count=1;
        c->unsent->push(msg);
    }

    try_send_all(c);
}
/**
  Put exported or unexported variables in a string list
*/
void env_universal_common_get_names(wcstring_list_t &lst,
                                    int show_exported,
                                    int show_unexported)
{
    env_var_table_t::const_iterator iter;
    for (iter = env_universal_var.begin(); iter != env_universal_var.end(); ++iter)
    {
        const wcstring& key = iter->first;
        const var_uni_entry_t *e = iter->second;
        if ((e->exportv && show_exported) ||
                (!e->exportv && show_unexported))
        {
            lst.push_back(key);
        }

    }

}
/**
   Remove variable with specified name
*/
void env_universal_common_remove(const wcstring &name)
{
    env_universal_var.erase(name);
}