int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) { EnvMap sample; SampleConfig config; config.windowDesc.title = "Skybox Sample"; sample.run(config); }
std::string EnvExpand(const std::string & str, const EnvMap & map) { // Early exit if no magic characters are found. if(pystring::find(str, "$") == -1 && pystring::find(str, "%") == -1) return str; std::string orig = str; std::string newstr = str; // This walks through the envmap in key order, // from longest to shortest to handle envvars which are // substrings. // ie. '$TEST_$TESTING_$TE' will expand in this order '2 1 3' for (EnvMap::const_iterator iter = map.begin(); iter != map.end(); ++iter) { newstr = pystring::replace(newstr, ("${"+iter->first+"}"), iter->second); newstr = pystring::replace(newstr, ("$"+iter->first), iter->second); newstr = pystring::replace(newstr, ("%"+iter->first+"%"), iter->second); } // recursively call till string doesn't expand anymore if(newstr != orig) { return EnvExpand(newstr, map); } return orig; }
void EvnVarList::InsertVariable(const wxString& setName, const wxString& name, const wxString& value) { wxString actualSetName; DoGetSetVariablesStr(setName, actualSetName); EnvMap set = GetVariables(actualSetName, false, wxEmptyString, wxEmptyString); if(!set.Contains(name)) { set.Put(name, value); } m_envVarSets[actualSetName] = set.String(); }
wxArrayString EnvironmentConfig::GetActiveSetEnvNames(bool includeWorkspace, const wxString& project) { //read the environments variables EvnVarList vars; ReadObject(wxT("Variables"), &vars); wxArrayString envnames; // get the active environment variables set EnvMap variables = vars.GetVariables(wxEmptyString, includeWorkspace, project, wxEmptyString); for(size_t i=0; i<variables.GetCount(); ++i) { wxString key, val; variables.Get(i, key, val); envnames.Add( key ); } return envnames; }
EnvMap EvnVarList::GetVariables( const wxString& setName, bool includeWorkspaceEnvs, const wxString& projectName, const wxString& configName) { EnvMap variables; wxString actualSetName; wxString currentValueStr = DoGetSetVariablesStr(setName, actualSetName); if(includeWorkspaceEnvs && !clCxxWorkspaceST::Get()->GetName().IsEmpty()) { currentValueStr.Trim().Trim(false); currentValueStr << wxT("\n"); currentValueStr << clCxxWorkspaceST::Get()->GetEnvironmentVariabels(); if(projectName.IsEmpty() == false) { currentValueStr.Trim().Trim(false); BuildConfigPtr buildConf = clCxxWorkspaceST::Get()->GetProjBuildConf(projectName, configName); if(buildConf) { currentValueStr << wxT("\n"); currentValueStr << buildConf->GetEnvvars(); } } } wxArrayString currentValues = wxStringTokenize(currentValueStr, wxT("\r\n"), wxTOKEN_STRTOK); for(size_t i = 0; i < currentValues.GetCount(); i++) { wxString entry = currentValues.Item(i); // remove any comment from the line int where = entry.Find(wxT("#")); if(where != wxNOT_FOUND) { entry = entry.Left(where); } entry.Trim().Trim(false); if(entry.IsEmpty()) { continue; } wxString varname = entry.BeforeFirst(wxT('=')); wxString varvalue = entry.AfterFirst(wxT('=')); // Expand macros (which are not environment variables) varvalue = MacroManager::Instance()->ExpandNoEnv(varvalue, projectName, configName); variables.Put(varname, varvalue); } return variables; }
void LoadEnvironment(EnvMap & map) { for (char **env = GetEnviron(); *env != NULL; ++env) { // split environment up into std::map[name] = value std::string env_str = (char*)*env; int pos = static_cast<int>(env_str.find_first_of('=')); map.insert( EnvMap::value_type(env_str.substr(0, pos), env_str.substr(pos+1, env_str.length())) ); } }
RainExample(void) : env_map(0) , ripples(1) , water_prog() , water(water_prog, shapes::Plane(Vec3f(40,0,0), Vec3f(0,0,-40))) { water_prog.light_position.Set(2.0, 10.0, -4.0); water_prog.ripple_tex.Set(ripples.TexUnit()); water_prog.env_tex.Set(env_map.TexUnit()); gl.ClearColor(0.4f, 0.4f, 0.4f, 0.0f); gl.ClearDepth(1.0f); gl.Enable(Capability::DepthTest); }
//static ProcessHandlePtr Process::launch(const std::string& command, const Args& args, const EnvMap& envVariables, const std::string& sWorkDir) { if (!sWorkDir.empty()) { File f(sWorkDir); if (!f.createDirectories()) { FIRTEX_THROW(SystemException, "Cannot create work " "directory for: [%s]", command.c_str()); } } int pid = fork(); if (pid < 0) { FIRTEX_THROW(SystemException, "Cannot fork process for: [%s]", command.c_str()); } //fill arguments char** argv = new char*[args.size() + 2]; int i = 0; argv[i++] = const_cast<char*>(command.c_str()); for (Args::const_iterator it = args.begin(); it != args.end(); ++it) { argv[i++] = const_cast<char*>(it->c_str()); } argv[i] = NULL; if (pid == 0) //the child process { for (EnvMap::const_iterator it = envVariables.begin(); it != envVariables.end(); ++it) { Environment::set(it->first, it->second); } if (!sWorkDir.empty()) { if (chdir(sWorkDir.c_str()) == -1) { FIRTEX_THROW(RuntimeException, "chdir(%s) FAILED", sWorkDir.c_str()); } } // close all open file descriptors other than stdin, stdout, stderr for (int i = 3; i < getdtablesize(); ++i) { close(i); } stringstream ss; ss << "." << getpid(); Path path(sWorkDir); path.makeDirectory(); path.setFileName(STDOUT_FILE_NAME + ss.str()); if (freopen(path.toString().c_str(), "w+", stdout) == NULL) { FX_LOG(ERROR, "Reopen [%s] FAILED", path.toString().c_str()); } path.setFileName(STDERR_FILE_NAME + ss.str()); if (freopen(path.toString().c_str(), "w+", stderr) == NULL) { FX_LOG(ERROR, "Reopen [%s] FAILED", path.toString().c_str()); } execvp(command.c_str(), argv); fprintf(stderr, "command: [%s] execvp FAILED, error code: %d(%s)", command.c_str(), errno, strerror(errno)); fflush(stderr); _exit(72); } else { delete[] argv; //parent process return ProcessHandlePtr(new ProcessHandle(pid)); } //never get here return ProcessHandlePtr(); }
void CodeLiteApp::MSWReadRegistry() { #ifdef __WXMSW__ EvnVarList vars; EnvironmentConfig::Instance()->Load(); EnvironmentConfig::Instance()->ReadObject(wxT("Variables"), &vars); ///////////////////////////////////////////////////////////////// // New way of registry: // Read the registry INI file ///////////////////////////////////////////////////////////////// // Update PATH environment variable with the install directory and // MinGW default installation (if exists) wxString pathEnv; wxGetEnv(wxT("PATH"), &pathEnv); wxString codeliteInstallDir; codeliteInstallDir << ManagerST::Get()->GetInstallDir() << wxT(";"); pathEnv.Prepend(codeliteInstallDir); // Load the registry file wxString iniFile; iniFile << ManagerST::Get()->GetInstallDir() << wxFileName::GetPathSeparator() << wxT("registry.ini"); if(wxFileName::FileExists(iniFile)) { clRegistry::SetFilename(iniFile); clRegistry registry; m_parserPaths.Clear(); wxString strWx, strMingw, strUnitTestPP; // registry.Read(wxT("wx"), strWx); registry.Read(wxT("mingw"), strMingw); registry.Read(wxT("unittestpp"), strUnitTestPP); // Supprot for wxWidgets if(strWx.IsEmpty() == false) { // we have WX installed on this machine, set the path of WXWIN & WXCFG to point to it EnvMap envs = vars.GetVariables(wxT("Default"), false, wxT("")); if(!envs.Contains(wxT("WXWIN"))) { vars.AddVariable(wxT("Default"), wxT("WXWIN"), strWx); vars.AddVariable(wxT("Default"), wxT("PATH"), wxT("$(WXWIN)\\lib\\gcc_dll;$(PATH)")); } if(!envs.Contains(wxT("WXCFG"))) vars.AddVariable(wxT("Default"), wxT("WXCFG"), wxT("gcc_dll\\mswu")); EnvironmentConfig::Instance()->WriteObject(wxT("Variables"), &vars); wxSetEnv(wxT("WX_INCL_HOME"), strWx + wxT("\\include")); } // Support for UnitTest++ if(strUnitTestPP.IsEmpty() == false) { // we have UnitTest++ installed on this machine EnvMap envs = vars.GetVariables(wxT("Default"), false, wxT("")); if(!envs.Contains(wxT("UNIT_TEST_PP_SRC_DIR"))) { vars.AddVariable(wxT("Default"), wxT("UNIT_TEST_PP_SRC_DIR"), strUnitTestPP); } EnvironmentConfig::Instance()->WriteObject(wxT("Variables"), &vars); } // Support for MinGW if(strMingw.IsEmpty() == false) { // Make sure that codelite's MinGW comes first before any other // MinGW installation that might exist on the machine strMingw << wxFileName::GetPathSeparator() << wxT("bin;"); pathEnv.Prepend(strMingw); } wxSetEnv(wxT("PATH"), pathEnv); } #endif }
void EnvironmentConfig::ApplyEnv(wxStringMap_t *overrideMap, const wxString &project, const wxString &config) { // We lock the CS here and it will be released in UnApplyEnv // this is safe to call without Locker since the UnApplyEnv // will always be called after ApplyEnv (ApplyEnv and UnApplyEnv are // protected functions that can only be called from EnvSetter class // which always call UnApplyEnv in its destructor) m_cs.Enter(); ++m_envApplied; if ( m_envApplied > 1 ) { //CL_DEBUG("Thread-%d: Applying environment variables... (not needed)", (int)wxThread::GetCurrentId()); return; } //CL_DEBUG("Thread-%d: Applying environment variables...", (int)wxThread::GetCurrentId()); //read the environments variables EvnVarList vars; ReadObject(wxT("Variables"), &vars); // get the active environment variables set EnvMap variables = vars.GetVariables(wxEmptyString, true, project, config); // if we have an "override map" place all the entries from the override map // into the global map before applying the environment if(overrideMap) { wxStringMap_t::iterator it = overrideMap->begin(); for(; it != overrideMap->end(); it++) { variables.Put(it->first, it->second); } } m_envSnapshot.clear(); for (size_t i=0; i<variables.GetCount(); i++) { wxString key, val; variables.Get(i, key, val); //keep old value before changing it wxString oldVal(wxEmptyString); if( wxGetEnv(key, &oldVal) == false ) { oldVal = __NO_SUCH_ENV__; } // keep the old value, however, don't override it if it // already exists as it might cause the variable to grow in size... // Simple case: // PATH=$(PATH);\New\Path // PATH=$(PATH);\Another\New\Path // If we replace the value, PATH will contain the original PATH + \New\Path if ( m_envSnapshot.count( key ) == 0 ) { m_envSnapshot.insert( std::make_pair( key, oldVal ) ); } // Incase this line contains other environment variables, expand them before setting this environment variable wxString newVal = DoExpandVariables(val); //set the new value wxSetEnv(key, newVal); } }