/* =====================================================================================================================
* File - main.cpp
* ---------------------------------------------------------------------------------------------------------------------
*/
/* =====================================================================================================================
* ---------------------------------------------------------------------------------------------------------------------
*/
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <string>
#include <utility>
#include <vector>
/* =====================================================================================================================
* ---------------------------------------------------------------------------------------------------------------------
*/
typedef std::map<const std::string, const std::string> dict_t;
typedef std::map<const std::string, const std::string>::iterator dict_itr;
typedef std::map<const std::string, const std::string>::const_iterator dict_const_itr;
/* =====================================================================================================================
* ---------------------------------------------------------------------------------------------------------------------
*/
dict_t g_dictEnvironment;
/* =====================================================================================================================
* ---------------------------------------------------------------------------------------------------------------------
*/
int main(int argc, char* argv[], char* envv[])
{
using std::cout;
using std::endl;
using std::ostream_iterator;
using std::string;
string strT;
// Insert 'key' named "ApplicationName" with 'value' as the name of this executable into the dictionary
// 'g_dictEnvironment' ...
strT = argv[0];
strT.erase(0, strT.find_last_of('/') + 1);
g_dictEnvironment.insert(make_pair("ApplicationName", strT));
// ... add the environment variables in effect at executables launch into the dictionary 'g_dictEnvironment' ...
char** penvvT = envv;
do
{
strT = *penvvT;
g_dictEnvironment.insert(make_pair(strT.substr(0, strT.find('=')), strT.substr(strT.find('=') + 1)));
} while ( *++penvvT );
// ... request equivalent of shell $HOME ...
dict_const_itr itr = g_dictEnvironment.find("HOME");
if ( itr != g_dictEnvironment.end() )
{
cout << "Home directory: " << (*itr).second << "\n\n";
}
// ... dump the dictionary 'g_dictEnvironment'
for ( dict_itr itr = g_dictEnvironment.begin(); itr != g_dictEnvironment.end(); ++itr )
{
cout << (*itr).first << " = " << (*itr).second << endl;
}
return EXIT_SUCCESS;
}