From 3132ea801c2466773309edda82387025f903fc12 Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Sun, 20 Jan 2019 00:03:35 -0500 Subject: cmSystemTools: Stdout(),Stderr() accept std::string argument --- Source/cmCTest.cxx | 4 ++-- Source/cmDepends.cxx | 8 +++---- Source/cmExecProgramCommand.cxx | 6 +++--- Source/cmExecuteProcessCommand.cxx | 8 +++---- Source/cmLocalUnixMakefileGenerator3.cxx | 6 +++--- Source/cmQtAutoGenerator.cxx | 8 +++---- Source/cmSystemTools.cxx | 36 +++++++++++--------------------- Source/cmSystemTools.h | 6 ++---- Source/cmake.cxx | 16 +++++++------- 9 files changed, 42 insertions(+), 56 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 1c0d9f6..5ba3370 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2781,13 +2781,13 @@ bool cmCTest::RunCommand(std::vector const& args, if ((res == cmsysProcess_Pipe_STDOUT || res == cmsysProcess_Pipe_STDERR) && this->ExtraVerbose) { processOutput.DecodeText(data, length, strdata); - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } } if (this->ExtraVerbose) { processOutput.DecodeText(std::string(), strdata); if (!strdata.empty()) { - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } } diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index 2acb015..e4eb5e5 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -87,7 +87,7 @@ void cmDepends::Clear(const char* file) if (this->Verbose) { std::ostringstream msg; msg << "Clearing dependencies in \"" << file << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } // Write an empty dependency file. @@ -170,7 +170,7 @@ bool cmDepends::CheckDependencies( std::ostringstream msg; msg << "Dependee \"" << dependee << "\" does not exist for depender \"" << depender << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } } else { if (dependerExists) { @@ -187,7 +187,7 @@ bool cmDepends::CheckDependencies( std::ostringstream msg; msg << "Dependee \"" << dependee << "\" is newer than depender \"" << depender << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } } } else { @@ -206,7 +206,7 @@ bool cmDepends::CheckDependencies( msg << "Dependee \"" << dependee << "\" is newer than depends file \"" << internalDependsFileName << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } } } diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index ea4cd40..49d9841 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -221,7 +221,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, if (p == cmsysProcess_Pipe_STDOUT || p == cmsysProcess_Pipe_STDERR) { if (verbose) { processOutput.DecodeText(data, length, strdata); - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } output.append(data, length); } @@ -230,7 +230,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, if (verbose) { processOutput.DecodeText(std::string(), strdata); if (!strdata.empty()) { - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } } @@ -270,7 +270,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, } msg += "\n"; if (verbose) { - cmSystemTools::Stdout(msg.c_str()); + cmSystemTools::Stdout(msg); } output += msg; #else diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 679a648..08a8be7 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -249,14 +249,14 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, if (p == cmsysProcess_Pipe_STDOUT && !output_quiet) { if (output_variable.empty()) { processOutput.DecodeText(data, length, strdata, 1); - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } else { cmExecuteProcessCommandAppend(tempOutput, data, length); } } else if (p == cmsysProcess_Pipe_STDERR && !error_quiet) { if (error_variable.empty()) { processOutput.DecodeText(data, length, strdata, 2); - cmSystemTools::Stderr(strdata.c_str(), strdata.size()); + cmSystemTools::Stderr(strdata); } else { cmExecuteProcessCommandAppend(tempError, data, length); } @@ -265,13 +265,13 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, if (!output_quiet && output_variable.empty()) { processOutput.DecodeText(std::string(), strdata, 1); if (!strdata.empty()) { - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } } if (!error_quiet && error_variable.empty()) { processOutput.DecodeText(std::string(), strdata, 2); if (!strdata.empty()) { - cmSystemTools::Stderr(strdata.c_str(), strdata.size()); + cmSystemTools::Stderr(strdata); } } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 707a1b5..eca6bea 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1286,7 +1286,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo, std::ostringstream msg; msg << "Dependee \"" << tgtInfo << "\" is newer than depender \"" << internalDependFile << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } needRescanDependInfo = true; } @@ -1307,7 +1307,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo, std::ostringstream msg; msg << "Dependee \"" << dirInfoFile << "\" is newer than depender \"" << internalDependFile << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } needRescanDirInfo = true; } @@ -1489,7 +1489,7 @@ void cmLocalUnixMakefileGenerator3::CheckMultipleOutputs(bool verbose) msg << "Deleting primary custom command output \"" << dependee << "\" because another output \"" << depender << "\" does not exist." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } cmSystemTools::RemoveFile(dependee); } diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx index c5d5d7c..e2d7deb 100644 --- a/Source/cmQtAutoGenerator.cxx +++ b/Source/cmQtAutoGenerator.cxx @@ -54,7 +54,7 @@ void cmQtAutoGenerator::Logger::Info(GeneratorT genType, } { std::lock_guard lock(Mutex_); - cmSystemTools::Stdout(msg.c_str(), msg.size()); + cmSystemTools::Stdout(msg); } } @@ -78,7 +78,7 @@ void cmQtAutoGenerator::Logger::Warning(GeneratorT genType, msg.push_back('\n'); { std::lock_guard lock(Mutex_); - cmSystemTools::Stdout(msg.c_str(), msg.size()); + cmSystemTools::Stdout(msg); } } @@ -107,7 +107,7 @@ void cmQtAutoGenerator::Logger::Error(GeneratorT genType, msg.push_back('\n'); { std::lock_guard lock(Mutex_); - cmSystemTools::Stderr(msg.c_str(), msg.size()); + cmSystemTools::Stderr(msg); } } @@ -149,7 +149,7 @@ void cmQtAutoGenerator::Logger::ErrorCommand( msg.push_back('\n'); { std::lock_guard lock(Mutex_); - cmSystemTools::Stderr(msg.c_str(), msg.size()); + cmSystemTools::Stderr(msg); } } diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index be65853..cb97cba 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -302,33 +302,21 @@ void cmSystemTools::SetStderrCallback(OutputCallback f, void* clientData) s_StderrCallbackClientData = clientData; } -void cmSystemTools::Stdout(const char* s) -{ - cmSystemTools::Stdout(s, strlen(s)); -} - -void cmSystemTools::Stderr(const char* s) -{ - cmSystemTools::Stderr(s, strlen(s)); -} - -void cmSystemTools::Stderr(const char* s, size_t length) +void cmSystemTools::Stderr(const std::string& s) { if (s_StderrCallback) { - (*s_StderrCallback)(s, length, s_StderrCallbackClientData); + (*s_StderrCallback)(s.c_str(), s.length(), s_StderrCallbackClientData); } else { - std::cerr.write(s, length); - std::cerr.flush(); + std::cerr << s << std::flush; } } -void cmSystemTools::Stdout(const char* s, size_t length) +void cmSystemTools::Stdout(const std::string& s) { if (s_StdoutCallback) { - (*s_StdoutCallback)(s, length, s_StdoutCallbackClientData); + (*s_StdoutCallback)(s.c_str(), s.length(), s_StdoutCallbackClientData); } else { - std::cout.write(s, length); - std::cout.flush(); + std::cout << s << std::flush; } } @@ -792,7 +780,7 @@ bool cmSystemTools::RunSingleCommand(std::vector const& command, if (pipe == cmsysProcess_Pipe_STDOUT) { if (outputflag != OUTPUT_NONE) { processOutput.DecodeText(data, length, strdata, 1); - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } if (captureStdOut) { tempStdOut.insert(tempStdOut.end(), data, data + length); @@ -800,7 +788,7 @@ bool cmSystemTools::RunSingleCommand(std::vector const& command, } else if (pipe == cmsysProcess_Pipe_STDERR) { if (outputflag != OUTPUT_NONE) { processOutput.DecodeText(data, length, strdata, 2); - cmSystemTools::Stderr(strdata.c_str(), strdata.size()); + cmSystemTools::Stderr(strdata); } if (captureStdErr) { tempStdErr.insert(tempStdErr.end(), data, data + length); @@ -811,11 +799,11 @@ bool cmSystemTools::RunSingleCommand(std::vector const& command, if (outputflag != OUTPUT_NONE) { processOutput.DecodeText(std::string(), strdata, 1); if (!strdata.empty()) { - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } processOutput.DecodeText(std::string(), strdata, 2); if (!strdata.empty()) { - cmSystemTools::Stderr(strdata.c_str(), strdata.size()); + cmSystemTools::Stderr(strdata); } } } @@ -1899,13 +1887,13 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) if (verbose) { if (extract) { cmSystemTools::Stdout("x "); - cmSystemTools::Stdout(cm_archive_entry_pathname(entry).c_str()); + cmSystemTools::Stdout(cm_archive_entry_pathname(entry)); } else { list_item_verbose(stdout, entry); } cmSystemTools::Stdout("\n"); } else if (!extract) { - cmSystemTools::Stdout(cm_archive_entry_pathname(entry).c_str()); + cmSystemTools::Stdout(cm_archive_entry_pathname(entry)); cmSystemTools::Stdout("\n"); } if (extract) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index c0999e7..365be36 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -79,13 +79,11 @@ public: typedef void (*OutputCallback)(const char*, size_t length, void*); ///! Send a string to stdout - static void Stdout(const char* s); - static void Stdout(const char* s, size_t length); + static void Stdout(const std::string& s); static void SetStdoutCallback(OutputCallback, void* clientData = nullptr); ///! Send a string to stderr - static void Stderr(const char* s); - static void Stderr(const char* s, size_t length); + static void Stderr(const std::string& s); static void SetStderrCallback(OutputCallback, void* clientData = nullptr); typedef bool (*InterruptCallback)(void*); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 9fcfbde..c8e54aa 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2006,7 +2006,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake no build system arguments\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2017,7 +2017,7 @@ int cmake::CheckBuildSystem() std::ostringstream msg; msg << "Re-run cmake missing file: " << this->CheckBuildSystemArgument << "\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2037,7 +2037,7 @@ int cmake::CheckBuildSystem() std::ostringstream msg; msg << "Re-run cmake error reading : " << this->CheckBuildSystemArgument << "\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } // There was an error reading the file. Just rerun. return 1; @@ -2071,7 +2071,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake, missing byproduct: " << p << "\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2092,7 +2092,7 @@ int cmake::CheckBuildSystem() std::ostringstream msg; msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS " "or CMAKE_MAKEFILE_OUTPUTS :\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2111,7 +2111,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake: build system dependency is missing\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2131,7 +2131,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake: build system output is missing\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2147,7 +2147,7 @@ int cmake::CheckBuildSystem() std::ostringstream msg; msg << "Re-run cmake file: " << out_oldest << " older than: " << dep_newest << "\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } -- cgit v0.12