1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmProcessTools.h"
14 #include <cmsys/Process.h>
16 //----------------------------------------------------------------------------
17 void cmProcessTools::RunProcess(struct cmsysProcess_s* cp,
18 OutputParser* out, OutputParser* err)
20 cmsysProcess_Execute(cp);
24 while((out||err) && (p=cmsysProcess_WaitForData(cp, &data, &length, 0), p))
26 if(out && p == cmsysProcess_Pipe_STDOUT)
28 if(!out->Process(data, length))
33 else if(err && p == cmsysProcess_Pipe_STDERR)
35 if(!err->Process(data, length))
41 cmsysProcess_WaitForExit(cp, 0);
45 //----------------------------------------------------------------------------
46 cmProcessTools::LineParser::LineParser(char sep, bool ignoreCR):
47 Separator(sep), IgnoreCR(ignoreCR), Log(0), Prefix(0), LineEnd('\0')
51 //----------------------------------------------------------------------------
52 void cmProcessTools::LineParser::SetLog(std::ostream* log, const char* prefix)
55 this->Prefix = prefix? prefix : "";
58 //----------------------------------------------------------------------------
59 bool cmProcessTools::LineParser::ProcessChunk(const char* first, int length)
61 const char* last = first + length;
62 for(const char* c = first; c != last; ++c)
64 if(*c == this->Separator || *c == '\0')
69 if(this->Log && this->Prefix)
71 *this->Log << this->Prefix << this->Line << "\n";
74 // Hand this line to the subclass implementation.
75 if(!this->ProcessLine())
83 else if(*c != '\r' || !this->IgnoreCR)
85 // Append this character to the line under construction.
86 this->Line.append(1, *c);