ENH: check in almost building VMS stuff with VMSBuild directory since the bootstrap...
[cmake.git] / Source / cmProcessTools.cxx
blob606bb72714e9b1e0a85e0935f0a717e98d9b24b9
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmProcessTools.cxx,v $
5 Language: C++
6 Date: $Date: 2009-02-24 15:40:18 $
7 Version: $Revision: 1.1 $
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.
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.
16 =========================================================================*/
17 #include "cmProcessTools.h"
19 #include <cmsys/Process.h>
21 //----------------------------------------------------------------------------
22 void cmProcessTools::RunProcess(struct cmsysProcess_s* cp,
23 OutputParser* out, OutputParser* err)
25 cmsysProcess_Execute(cp);
26 char* data = 0;
27 int length = 0;
28 int p;
29 while((out||err) && (p=cmsysProcess_WaitForData(cp, &data, &length, 0), p))
31 if(out && p == cmsysProcess_Pipe_STDOUT)
33 if(!out->Process(data, length))
35 out = 0;
38 else if(err && p == cmsysProcess_Pipe_STDERR)
40 if(!err->Process(data, length))
42 err = 0;
46 cmsysProcess_WaitForExit(cp, 0);
50 //----------------------------------------------------------------------------
51 cmProcessTools::LineParser::LineParser(char sep, bool ignoreCR):
52 Separator(sep), IgnoreCR(ignoreCR), Log(0), Prefix(0)
56 //----------------------------------------------------------------------------
57 void cmProcessTools::LineParser::SetLog(std::ostream* log, const char* prefix)
59 this->Log = log;
60 this->Prefix = prefix? prefix : "";
63 //----------------------------------------------------------------------------
64 bool cmProcessTools::LineParser::ProcessChunk(const char* first, int length)
66 const char* last = first + length;
67 for(const char* c = first; c != last; ++c)
69 if(*c == this->Separator)
71 // Log this line.
72 if(this->Log && this->Prefix)
74 *this->Log << this->Prefix << this->Line << "\n";
77 // Hand this line to the subclass implementation.
78 if(!this->ProcessLine())
80 this->Line = "";
81 return false;
84 this->Line = "";
86 else if(*c != '\r' || !this->IgnoreCR)
88 // Append this character to the line under construction.
89 this->Line.append(1, *c);
92 return true;