~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/cmExecProgramCommand.cxx

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2005-03-02 09:22:44 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050302092244-y6o9j8wr27vqcqvx
Tags: 2.0.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*=========================================================================
2
2
 
3
 
  Program:   Insight Segmentation & Registration Toolkit
 
3
  Program:   CMake - Cross-Platform Makefile Generator
4
4
  Module:    $RCSfile: cmExecProgramCommand.cxx,v $
5
5
  Language:  C++
6
 
  Date:      $Date: 2001/09/20 19:08:22 $
7
 
  Version:   $Revision: 1.3 $
8
 
 
9
 
Copyright (c) 2001 Insight Consortium
10
 
All rights reserved.
11
 
 
12
 
Redistribution and use in source and binary forms, with or without
13
 
modification, are permitted provided that the following conditions are met:
14
 
 
15
 
 * Redistributions of source code must retain the above copyright notice,
16
 
   this list of conditions and the following disclaimer.
17
 
 
18
 
 * Redistributions in binary form must reproduce the above copyright notice,
19
 
   this list of conditions and the following disclaimer in the documentation
20
 
   and/or other materials provided with the distribution.
21
 
 
22
 
 * The name of the Insight Consortium, nor the names of any consortium members,
23
 
   nor of any contributors, may be used to endorse or promote products derived
24
 
   from this software without specific prior written permission.
25
 
 
26
 
  * Modified source versions must be plainly marked as such, and must not be
27
 
    misrepresented as being the original software.
28
 
 
29
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
30
 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32
 
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
33
 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35
 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
 
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
 
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
6
  Date:      $Date: 2004/07/07 21:09:55 $
 
7
  Version:   $Revision: 1.18.8.1 $
 
8
 
 
9
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
 
10
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
 
11
 
 
12
     This software is distributed WITHOUT ANY WARRANTY; without even 
 
13
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 
14
     PURPOSE.  See the above copyright notices for more information.
39
15
 
40
16
=========================================================================*/
41
17
#include "cmExecProgramCommand.h"
42
18
#include "cmSystemTools.h"
43
19
 
44
20
// cmExecProgramCommand
45
 
bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
 
21
bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
46
22
{
47
 
  std::vector<std::string>  args = argsIn;
48
23
  if(args.size() < 1 )
49
24
    {
50
25
    this->SetError("called with incorrect number of arguments");
51
26
    return false;
52
27
    }
 
28
  std::string arguments;
 
29
  bool doingargs = false;
 
30
  int count = 0;
 
31
  std::string output_variable;
 
32
  bool haveoutput_variable = false;
 
33
  std::string return_variable;
 
34
  bool havereturn_variable = false;
 
35
  for(size_t i=0; i < args.size(); ++i)
 
36
    {
 
37
    if(args[i] == "OUTPUT_VARIABLE")
 
38
      {
 
39
      count++;
 
40
      doingargs = false;
 
41
      havereturn_variable = false;
 
42
      haveoutput_variable = true;
 
43
      }    
 
44
    else if ( haveoutput_variable )
 
45
      {
 
46
      if ( output_variable.size() > 0 )
 
47
        {
 
48
        this->SetError("called with incorrect number of arguments");
 
49
        return false;
 
50
        }
 
51
      output_variable = args[i];
 
52
      haveoutput_variable = false;
 
53
      count ++;
 
54
      }
 
55
    else if(args[i] == "RETURN_VALUE")
 
56
      {
 
57
      count++;
 
58
      doingargs = false;
 
59
      haveoutput_variable = false;
 
60
      havereturn_variable = true;
 
61
      }    
 
62
    else if ( havereturn_variable )
 
63
      {
 
64
      if ( return_variable.size() > 0 )
 
65
        {
 
66
        this->SetError("called with incorrect number of arguments");
 
67
        return false;
 
68
        }
 
69
      return_variable = args[i];
 
70
      havereturn_variable = false;
 
71
      count ++;
 
72
      }
 
73
    else if(args[i] == "ARGS")
 
74
      {
 
75
      count++;
 
76
      havereturn_variable = false;
 
77
      haveoutput_variable = false;
 
78
      doingargs = true;
 
79
      }
 
80
    else if(doingargs)
 
81
      {
 
82
      arguments += args[i];
 
83
      arguments += " ";
 
84
      count++;
 
85
      }
 
86
    }
 
87
 
 
88
  std::string command;
 
89
  if(arguments.size())
 
90
    {
 
91
    command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str());
 
92
    command += " ";
 
93
    command += arguments;
 
94
    }
 
95
  else
 
96
    {
 
97
    command = args[0];
 
98
    }
 
99
  bool verbose = true;
 
100
  if(output_variable.size() > 0)
 
101
    {
 
102
    verbose = false;
 
103
    }
 
104
  int retVal = 0;
53
105
  std::string output;
54
 
    m_Makefile->ExpandVariablesInString(args[0]);
55
 
    m_Makefile->ExpandVariablesInString(args[1]);
56
 
  if(args.size() == 2)
 
106
  bool result = true;
 
107
  if(args.size() - count == 2)
57
108
    {
58
109
    cmSystemTools::MakeDirectory(args[1].c_str());
59
 
    std::string command;
60
 
    command = "cd ";
61
 
    command += args[1].c_str();
62
 
    command += "; ";
63
 
    command += args[0].c_str();
64
 
    cmSystemTools::RunCommand(command.c_str(), output);
 
110
    result = cmSystemTools::RunCommand(command.c_str(), output, retVal,
 
111
                                       args[1].c_str(), verbose);
65
112
    }
66
113
  else
67
114
    {
68
 
    cmSystemTools::RunCommand(args[0].c_str(), output);
69
 
    }
 
115
    result = cmSystemTools::RunCommand(command.c_str(), output, retVal, 0, verbose);
 
116
    }
 
117
  if(!result)
 
118
    {
 
119
    retVal = -1;
 
120
    }
 
121
 
 
122
  if ( output_variable.size() > 0 )
 
123
    {    
 
124
    std::string::size_type first = output.find_first_not_of(" \n\t\r");
 
125
    std::string::size_type last = output.find_last_not_of(" \n\t\r");
 
126
    if(first == std::string::npos)
 
127
      {
 
128
      first = 0;
 
129
      }
 
130
    if(last == std::string::npos)
 
131
      {
 
132
      last = output.size()-1;
 
133
      }
 
134
    
 
135
    std::string coutput = std::string(output, first, last-first+1);
 
136
    m_Makefile->AddDefinition(output_variable.c_str(), coutput.c_str());
 
137
    }
 
138
 
 
139
  if ( return_variable.size() > 0 )
 
140
    {
 
141
    char buffer[100];
 
142
    sprintf(buffer, "%d", retVal);
 
143
    m_Makefile->AddDefinition(return_variable.c_str(), buffer);
 
144
    }
 
145
  
70
146
  return true;
71
147
}
72
148