cmConfigureFileNoAutoconf.cxx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmConfigureFileNoAutoconf.h"
  12. // cmConfigureFileNoAutoconf
  13. bool cmConfigureFileNoAutoconf::Invoke(std::vector<std::string>& args)
  14. {
  15. if(args.size() != 2 )
  16. {
  17. this->SetError("called with incorrect number of arguments, expected 2");
  18. return false;
  19. }
  20. m_InputFile = args[0];
  21. m_OuputFile = args[1];
  22. return true;
  23. }
  24. void cmConfigureFileNoAutoconf::FinalPass()
  25. {
  26. #ifdef CMAKE_HAS_AUTOCONF
  27. return;
  28. #else
  29. m_Makefile->ExpandVariablesInString(m_InputFile);
  30. m_Makefile->ExpandVariablesInString(m_OuputFile);
  31. std::ifstream fin(m_InputFile.c_str());
  32. if(!fin)
  33. {
  34. cmSystemTools::Error("Could not open file for read in copy operatation",
  35. m_InputFile.c_str());
  36. return;
  37. }
  38. cmSystemTools::ConvertToUnixSlashes(m_OuputFile);
  39. std::string::size_type pos = m_OuputFile.rfind('/');
  40. if(pos != std::string::npos)
  41. {
  42. std::string path = m_OuputFile.substr(0, pos);
  43. cmSystemTools::MakeDirectory(path.c_str());
  44. }
  45. std::ofstream fout(m_OuputFile.c_str());
  46. if(!fout)
  47. {
  48. cmSystemTools::Error("Could not open file for write in copy operatation",
  49. m_OuputFile.c_str());
  50. return;
  51. }
  52. // now copy input to output and expand varibles in the
  53. // input file at the same time
  54. const int bufSize = 4096;
  55. char buffer[bufSize];
  56. std::string inLine;
  57. while(fin)
  58. {
  59. fin.getline(buffer, bufSize);
  60. inLine = buffer;
  61. m_Makefile->ExpandVariablesInString(inLine);
  62. fout << inLine << "\n";
  63. }
  64. #endif
  65. }