1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmProcessTools.cxx,v $
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
);
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
))
38 else if(err
&& p
== cmsysProcess_Pipe_STDERR
)
40 if(!err
->Process(data
, length
))
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
)
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
)
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())
86 else if(*c
!= '\r' || !this->IgnoreCR
)
88 // Append this character to the line under construction.
89 this->Line
.append(1, *c
);