diff options
author | Ken Martin <ken.martin@kitware.com> | 2001-06-29 20:46:28 (GMT) |
---|---|---|
committer | Ken Martin <ken.martin@kitware.com> | 2001-06-29 20:46:28 (GMT) |
commit | 901d2626ce4c6bfac769e9da04865c475f1df9ec (patch) | |
tree | 78e64e7a4fb31431cea6d57783c226df39546bd3 /Source/cmConfigureFileCommand.cxx | |
parent | 51a89146301bfa89d69218cb830e1c4201508cb8 (diff) | |
download | CMake-901d2626ce4c6bfac769e9da04865c475f1df9ec.zip CMake-901d2626ce4c6bfac769e9da04865c475f1df9ec.tar.gz CMake-901d2626ce4c6bfac769e9da04865c475f1df9ec.tar.bz2 |
better configure file command
Diffstat (limited to 'Source/cmConfigureFileCommand.cxx')
-rw-r--r-- | Source/cmConfigureFileCommand.cxx | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx index 58e40e7..d92212b 100644 --- a/Source/cmConfigureFileCommand.cxx +++ b/Source/cmConfigureFileCommand.cxx @@ -81,13 +81,6 @@ void cmConfigureFileCommand::FinalPass() { m_Makefile->ExpandVariablesInString(m_InputFile); m_Makefile->ExpandVariablesInString(m_OuputFile); - std::ifstream fin(m_InputFile.c_str()); - if(!fin) - { - cmSystemTools::Error("Could not open file for read in copy operatation", - m_InputFile.c_str()); - return; - } cmSystemTools::ConvertToUnixSlashes(m_OuputFile); std::string::size_type pos = m_OuputFile.rfind('/'); if(pos != std::string::npos) @@ -95,29 +88,43 @@ void cmConfigureFileCommand::FinalPass() std::string path = m_OuputFile.substr(0, pos); cmSystemTools::MakeDirectory(path.c_str()); } - std::string tempOutputFile = m_OuputFile; - tempOutputFile += ".tmp"; - std::ofstream fout(tempOutputFile.c_str()); - if(!fout) + + if(m_CopyOnly) { - cmSystemTools::Error("Could not open file for write in copy operatation", - tempOutputFile.c_str()); - return; + cmSystemTools::CopyFileIfDifferent(m_InputFile.c_str(), + m_OuputFile.c_str()); } - // now copy input to output and expand varibles in the - // input file at the same time - const int bufSize = 4096; - char buffer[bufSize]; - std::string inLine; - cmRegularExpression cmdefine("#cmakedefine[ \t]*([A-Za-z_0-9]*)"); - while(fin) + else { - fin.getline(buffer, bufSize); - if(fin) + std::string tempOutputFile = m_OuputFile; + tempOutputFile += ".tmp"; + std::ofstream fout(tempOutputFile.c_str()); + if(!fout) + { + cmSystemTools::Error("Could not open file for write in copy operatation", + tempOutputFile.c_str()); + return; + } + std::ifstream fin(m_InputFile.c_str()); + if(!fin) + { + cmSystemTools::Error("Could not open file for read in copy operatation", + m_InputFile.c_str()); + return; + } + + // now copy input to output and expand varibles in the + // input file at the same time + const int bufSize = 4096; + char buffer[bufSize]; + std::string inLine; + cmRegularExpression cmdefine("#cmakedefine[ \t]*([A-Za-z_0-9]*)"); + while(fin) { - inLine = buffer; - if(!m_CopyOnly) + fin.getline(buffer, bufSize); + if(fin) { + inLine = buffer; m_Makefile->ExpandVariablesInString(inLine, m_EscapeQuotes); m_Makefile->RemoveVariablesInString(inLine); // look for special cmakedefine symbol and handle it @@ -139,13 +146,13 @@ void cmConfigureFileCommand::FinalPass() } fout << inLine << "\n"; } + // close the files before attempting to copy + fin.close(); + fout.close(); + cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(), + m_OuputFile.c_str()); + cmSystemTools::RemoveFile(tempOutputFile.c_str()); } - // close the files before attempting to copy - fin.close(); - fout.close(); - cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(), - m_OuputFile.c_str()); - cmSystemTools::RemoveFile(tempOutputFile.c_str()); } |