From e34aa12e6666a58fb3f0cb0ce0411228bbe763af Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Thu, 15 Feb 2024 08:27:54 -0500 Subject: KWSys 2024-02-15 (aad06964) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit aad0696498a4174581910624788d5b537cbb6236 (master). Upstream Shortlog ----------------- Christoph GrĂ¼ninger (3): d3f3c38b Use prefix ++ operators for non-primitive types 9fd52415 Range-for loop with const reference 2310be95 Make variable more local scivision (1): 6624edf2 SystemTools:FileIs{Directory,Executable,FIFO}: refactor for simplicity --- CommandLineArguments.cxx | 16 ++++++++-------- SystemInformation.cxx | 2 +- SystemTools.cxx | 34 ++++++++++------------------------ 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/CommandLineArguments.cxx b/CommandLineArguments.cxx index 50171dd..61703ad 100644 --- a/CommandLineArguments.cxx +++ b/CommandLineArguments.cxx @@ -132,7 +132,7 @@ bool CommandLineArguments::GetMatchedArguments( // Does the argument match to any we know about? for (it = this->Internals->Callbacks.begin(); - it != this->Internals->Callbacks.end(); it++) { + it != this->Internals->Callbacks.end(); ++it) { const CommandLineArguments::Internal::String& parg = it->first; CommandLineArgumentsCallbackStructure* cs = &it->second; if (cs->ArgumentType == CommandLineArguments::NO_ARGUMENT || @@ -467,7 +467,7 @@ void CommandLineArguments::GenerateHelp() MapArgs mp; MapArgs::iterator mpit, smpit; for (it = this->Internals->Callbacks.begin(); - it != this->Internals->Callbacks.end(); it++) { + it != this->Internals->Callbacks.end(); ++it) { CommandLineArgumentsCallbackStructure* cs = &(it->second); mpit = mp.find(cs->Help); if (mpit != mp.end()) { @@ -478,14 +478,14 @@ void CommandLineArguments::GenerateHelp() } } for (it = this->Internals->Callbacks.begin(); - it != this->Internals->Callbacks.end(); it++) { + it != this->Internals->Callbacks.end(); ++it) { CommandLineArgumentsCallbackStructure* cs = &(it->second); mpit = mp.find(cs->Help); if (mpit != mp.end()) { mpit->second.insert(it->first); smpit = mp.find(it->first); CommandLineArguments::Internal::SetOfStrings::iterator sit; - for (sit = smpit->second.begin(); sit != smpit->second.end(); sit++) { + for (sit = smpit->second.begin(); sit != smpit->second.end(); ++sit) { mpit->second.insert(*sit); } mp.erase(smpit); @@ -496,9 +496,9 @@ void CommandLineArguments::GenerateHelp() // Find the length of the longest string CommandLineArguments::Internal::String::size_type maxlen = 0; - for (mpit = mp.begin(); mpit != mp.end(); mpit++) { + for (mpit = mp.begin(); mpit != mp.end(); ++mpit) { CommandLineArguments::Internal::SetOfStrings::iterator sit; - for (sit = mpit->second.begin(); sit != mpit->second.end(); sit++) { + for (sit = mpit->second.begin(); sit != mpit->second.end(); ++sit) { CommandLineArguments::Internal::String::size_type clen = sit->size(); switch (this->Internals->Callbacks[*sit].ArgumentType) { case CommandLineArguments::NO_ARGUMENT: @@ -524,9 +524,9 @@ void CommandLineArguments::GenerateHelp() maxlen += 4; // For the space before and after the option // Print help for each option - for (mpit = mp.begin(); mpit != mp.end(); mpit++) { + for (mpit = mp.begin(); mpit != mp.end(); ++mpit) { CommandLineArguments::Internal::SetOfStrings::iterator sit; - for (sit = mpit->second.begin(); sit != mpit->second.end(); sit++) { + for (sit = mpit->second.begin(); sit != mpit->second.end(); ++sit) { str << std::endl; std::string argument = *sit; switch (this->Internals->Callbacks[*sit].ArgumentType) { diff --git a/SystemInformation.cxx b/SystemInformation.cxx index 369ff9a..37526dc 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -4890,7 +4890,7 @@ std::string SystemInformationImplementation::ParseValueFromKStat( args.reserve(3 + args_string.size()); args.push_back("kstat"); args.push_back("-p"); - for (auto& i : args_string) { + for (const auto& i : args_string) { args.push_back(i.c_str()); } args.push_back(nullptr); diff --git a/SystemTools.cxx b/SystemTools.cxx index 53b55f6..3f714de 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -2867,9 +2867,8 @@ std::string SystemToolsStatic::FindName( path.reserve(path.size() + userPaths.size()); path.insert(path.end(), userPaths.begin(), userPaths.end()); // now look for the file - std::string tryPath; for (std::string const& p : path) { - tryPath = p; + std::string tryPath = p; if (tryPath.empty() || tryPath.back() != '/') { tryPath += '/'; } @@ -2938,8 +2937,6 @@ std::string SystemTools::FindProgram(const std::string& name, const std::vector& userPaths, bool no_system_path) { - std::string tryPath; - #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) std::vector extensions; // check to see if the name already has a .xxx at @@ -2951,7 +2948,7 @@ std::string SystemTools::FindProgram(const std::string& name, // first try with extensions if the os supports them for (std::string const& ext : extensions) { - tryPath = name; + std::string tryPath = name; tryPath += ext; if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); @@ -2988,7 +2985,7 @@ std::string SystemTools::FindProgram(const std::string& name, #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) // first try with extensions for (std::string const& ext : extensions) { - tryPath = p; + std::string tryPath = p; tryPath += name; tryPath += ext; if (SystemTools::FileIsExecutable(tryPath)) { @@ -2997,7 +2994,7 @@ std::string SystemTools::FindProgram(const std::string& name, } #endif // now try it without them - tryPath = p; + std::string tryPath = p; tryPath += name; if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); @@ -3152,16 +3149,13 @@ bool SystemTools::FileIsDirectory(const std::string& inName) #if defined(_WIN32) DWORD attr = GetFileAttributesW(Encoding::ToWindowsExtendedPath(name).c_str()); - if (attr != INVALID_FILE_ATTRIBUTES) { - return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0; + return (attr != INVALID_FILE_ATTRIBUTES) && + (attr & FILE_ATTRIBUTE_DIRECTORY); #else struct stat fs; - if (stat(name, &fs) == 0) { - return S_ISDIR(fs.st_mode); + + return (stat(name, &fs) == 0) && S_ISDIR(fs.st_mode); #endif - } else { - return false; - } } bool SystemTools::FileIsExecutable(const std::string& inName) @@ -3226,11 +3220,7 @@ bool SystemTools::FileIsSymlink(const std::string& name) return FileIsSymlinkWithAttr(path, GetFileAttributesW(path.c_str())); #else struct stat fs; - if (lstat(name.c_str(), &fs) == 0) { - return S_ISLNK(fs.st_mode); - } else { - return false; - } + return (lstat(name.c_str(), &fs) == 0) && S_ISLNK(fs.st_mode); #endif } @@ -3248,11 +3238,7 @@ bool SystemTools::FileIsFIFO(const std::string& name) return type == FILE_TYPE_PIPE; #else struct stat fs; - if (lstat(name.c_str(), &fs) == 0) { - return S_ISFIFO(fs.st_mode); - } else { - return false; - } + return (lstat(name.c_str(), &fs) == 0) && S_ISFIFO(fs.st_mode); #endif } -- cgit v0.12