From f5dbca49714bea423c505f7aab6690673b528b4d Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Wed, 22 Jun 2005 13:32:11 -0400 Subject: ENH: changed FOREACH to use variables instead of string replacement --- Source/cmForEachCommand.cxx | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx index 0e68dbc..5b11271 100644 --- a/Source/cmForEachCommand.cxx +++ b/Source/cmForEachCommand.cxx @@ -33,6 +33,8 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf) mf.ExpandArguments(lff.m_Arguments, expandedArguments); if(!expandedArguments.empty() && (expandedArguments[0] == m_Args[0])) { + // store the old value + const char *oldDef = mf.GetDefinition(m_Args[0].c_str()); m_Executing = true; std::string variable = "${"; variable += m_Args[0]; @@ -44,29 +46,16 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf) cmListFileArgument arg; for( ; j != m_Args.end(); ++j) { + // set the variable to the loop value + mf.AddDefinition(m_Args[0].c_str(),j->c_str()); // Invoke all the functions that were collected in the block. for(unsigned int c = 0; c < m_Functions.size(); ++c) { - // Replace the loop variable and then invoke the command. - cmListFileFunction newLFF; - newLFF.m_Name = m_Functions[c].m_Name; - newLFF.m_FilePath = m_Functions[c].m_FilePath; - newLFF.m_Line = m_Functions[c].m_Line; - for (std::vector::const_iterator k = - m_Functions[c].m_Arguments.begin(); - k != m_Functions[c].m_Arguments.end(); ++k) - { - tmps = k->Value; - cmSystemTools::ReplaceString(tmps, variable.c_str(), j->c_str()); - arg.Value = tmps; - arg.Quoted = k->Quoted; - arg.FilePath = k->FilePath; - arg.Line = k->Line; - newLFF.m_Arguments.push_back(arg); - } - mf.ExecuteCommand(newLFF); + mf.ExecuteCommand(m_Functions[c]); } } + // restore the variable to its prior value + mf.AddDefinition(m_Args[0].c_str(),oldDef); mf.RemoveFunctionBlocker(lff); return true; } -- cgit v0.12