summaryrefslogtreecommitdiffstats
path: root/Source/cmConfigureFileNoAutoconf.cxx
blob: e4815a10ea3c790c0a98726a99f9fe1cde060d1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) 2000 National Library of Medicine
  All rights reserved.

  See COPYRIGHT.txt for copyright details.

=========================================================================*/
#include "cmConfigureFileNoAutoconf.h"

// cmConfigureFileNoAutoconf
bool cmConfigureFileNoAutoconf::Invoke(std::vector<std::string>& args)
{
  if(args.size() != 2 )
    {
    this->SetError("called with incorrect number of arguments, expected 2");
    return false;
    }
  m_InputFile = args[0];
  m_OuputFile = args[1];
  return true;
}

void cmConfigureFileNoAutoconf::FinalPass()
{
#ifdef CMAKE_HAS_AUTOCONF
  return;
#else  
  m_Makefile->ExpandVariblesInString(m_InputFile);
  m_Makefile->ExpandVariblesInString(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)
    {
    std::string path = m_OuputFile.substr(0, pos);
    cmSystemTools::MakeDirectory(path.c_str());
    }
  std::ofstream fout(m_OuputFile.c_str());
  if(!fout)
    {
    cmSystemTools::Error("Could not open file for write in copy operatation", 
                         m_OuputFile.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;
  while(fin)
    {
    fin.getline(buffer, bufSize);
    inLine = buffer;
    m_Makefile->ExpandVariblesInString(inLine);
    fout << inLine << "\n";
    }
#endif
}