1
/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
3
* schroot is free software; you can redistribute it and/or modify it
4
* under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* schroot is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18
*********************************************************************/
22
#include "sbuild-environment.h"
25
using namespace sbuild;
27
environment::environment ():
28
std::map<std::string,std::string>()
32
environment::environment (char **environment):
33
std::map<std::string,std::string>()
38
environment::~environment ()
43
environment::add (char **environment)
47
for (char **ev = environment; ev != 0 && *ev != 0; ++ev)
48
add(std::string(*ev));
53
environment::add (environment const& environment)
55
for (const_iterator pos = environment.begin();
56
pos != environment.end();
62
environment::add (std::string const& value)
64
std::string::size_type pos = value.find('=');
65
if (pos != std::string::npos && pos != 0)
67
std::string key = value.substr(0, pos);
69
if (pos < value.length())
70
val = value.substr(pos + 1);
71
add(std::make_pair(key, val));
75
add(std::make_pair(value, std::string()));
80
environment::add (value_type const& value)
83
if (!value.second.empty())
88
environment::remove (char **environment)
92
for (char **ev = environment; ev != 0 && *ev != 0; ++ev)
93
remove(std::string(*ev));
98
environment::remove (environment const& environment)
100
for (const_iterator pos = environment.begin();
101
pos != environment.end();
107
environment::remove (std::string const& value)
109
std::string::size_type pos = value.find('=');
110
if (pos != std::string::npos && pos != 0)
112
std::string key = value.substr(0, pos);
114
if (pos < value.length())
115
val = value.substr(pos + 1);
116
remove(std::make_pair(key, val));
120
remove(std::make_pair(value, std::string()));
125
environment::remove (value_type const& value)
127
iterator pos = find(value.first);
133
environment::get_strv () const
135
char **ret = new char *[size() + 1];
138
for (const_iterator pos = begin(); pos != end(); ++pos, ++idx)
140
std::string envitem = pos->first + "=" + pos->second;
141
ret[idx] = new char[envitem.length() + 1];
142
std::strcpy(ret[idx], envitem.c_str());