summaryrefslogtreecommitdiff
path: root/Source/cmProcessTools.cxx
diff options
context:
space:
mode:
authorMyungJoo Ham <myungjoo.ham@samsung.com>2017-10-11 15:16:57 +0900
committerMyungJoo Ham <myungjoo.ham@samsung.com>2017-10-11 15:16:57 +0900
commit915c76ded744c0f5f151402b9fa69f3fd8452573 (patch)
treeca6a387466543248890f346847acaa8343989b22 /Source/cmProcessTools.cxx
parent317dbdb79761ef65e45c7358cfc7571c6afa54ad (diff)
downloadcmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.gz
cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.bz2
cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.zip
Imported Upstream version 3.9.4upstream/3.9.4
Diffstat (limited to 'Source/cmProcessTools.cxx')
-rw-r--r--Source/cmProcessTools.cxx101
1 files changed, 49 insertions, 52 deletions
diff --git a/Source/cmProcessTools.cxx b/Source/cmProcessTools.cxx
index d2f7bf320..de7b06126 100644
--- a/Source/cmProcessTools.cxx
+++ b/Source/cmProcessTools.cxx
@@ -1,90 +1,87 @@
-/*============================================================================
- CMake - Cross Platform Makefile Generator
- Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
-
- Distributed under the OSI-approved BSD License (the "License");
- see accompanying file Copyright.txt for details.
-
- This software is distributed WITHOUT ANY WARRANTY; without even the
- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the License for more information.
-============================================================================*/
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmProcessTools.h"
+#include "cmProcessOutput.h"
-#include <cmsys/Process.h>
+#include "cmsys/Process.h"
+#include <ostream>
-//----------------------------------------------------------------------------
-void cmProcessTools::RunProcess(struct cmsysProcess_s* cp,
- OutputParser* out, OutputParser* err)
+void cmProcessTools::RunProcess(struct cmsysProcess_s* cp, OutputParser* out,
+ OutputParser* err, Encoding encoding)
{
cmsysProcess_Execute(cp);
- char* data = 0;
+ char* data = CM_NULLPTR;
int length = 0;
int p;
- while((out||err) && (p=cmsysProcess_WaitForData(cp, &data, &length, 0), p))
- {
- if(out && p == cmsysProcess_Pipe_STDOUT)
- {
- if(!out->Process(data, length))
- {
- out = 0;
- }
+ cmProcessOutput processOutput(encoding);
+ std::string strdata;
+ while ((out || err) &&
+ (p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
+ if (out && p == cmsysProcess_Pipe_STDOUT) {
+ processOutput.DecodeText(data, length, strdata, 1);
+ if (!out->Process(strdata.c_str(), int(strdata.size()))) {
+ out = CM_NULLPTR;
}
- else if(err && p == cmsysProcess_Pipe_STDERR)
- {
- if(!err->Process(data, length))
- {
- err = 0;
- }
+ } else if (err && p == cmsysProcess_Pipe_STDERR) {
+ processOutput.DecodeText(data, length, strdata, 2);
+ if (!err->Process(strdata.c_str(), int(strdata.size()))) {
+ err = CM_NULLPTR;
}
}
- cmsysProcess_WaitForExit(cp, 0);
+ }
+ if (out) {
+ processOutput.DecodeText(std::string(), strdata, 1);
+ if (!strdata.empty()) {
+ out->Process(strdata.c_str(), int(strdata.size()));
+ }
+ }
+ if (err) {
+ processOutput.DecodeText(std::string(), strdata, 2);
+ if (!strdata.empty()) {
+ out->Process(strdata.c_str(), int(strdata.size()));
+ }
+ }
+ cmsysProcess_WaitForExit(cp, CM_NULLPTR);
}
-
-//----------------------------------------------------------------------------
-cmProcessTools::LineParser::LineParser(char sep, bool ignoreCR):
- Separator(sep), IgnoreCR(ignoreCR), Log(0), Prefix(0), LineEnd('\0')
+cmProcessTools::LineParser::LineParser(char sep, bool ignoreCR)
+ : Log(CM_NULLPTR)
+ , Prefix(CM_NULLPTR)
+ , Separator(sep)
+ , LineEnd('\0')
+ , IgnoreCR(ignoreCR)
{
}
-//----------------------------------------------------------------------------
void cmProcessTools::LineParser::SetLog(std::ostream* log, const char* prefix)
{
this->Log = log;
- this->Prefix = prefix? prefix : "";
+ this->Prefix = prefix ? prefix : "";
}
-//----------------------------------------------------------------------------
bool cmProcessTools::LineParser::ProcessChunk(const char* first, int length)
{
const char* last = first + length;
- for(const char* c = first; c != last; ++c)
- {
- if(*c == this->Separator || *c == '\0')
- {
+ for (const char* c = first; c != last; ++c) {
+ if (*c == this->Separator || *c == '\0') {
this->LineEnd = *c;
// Log this line.
- if(this->Log && this->Prefix)
- {
+ if (this->Log && this->Prefix) {
*this->Log << this->Prefix << this->Line << "\n";
- }
+ }
// Hand this line to the subclass implementation.
- if(!this->ProcessLine())
- {
+ if (!this->ProcessLine()) {
this->Line = "";
return false;
- }
+ }
this->Line = "";
- }
- else if(*c != '\r' || !this->IgnoreCR)
- {
+ } else if (*c != '\r' || !this->IgnoreCR) {
// Append this character to the line under construction.
this->Line.append(1, *c);
- }
}
+ }
return true;
}