summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx196
1 files changed, 81 insertions, 115 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 575b973..0ab722e 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -121,13 +121,14 @@ bool cmSystemTools::s_FatalErrorOccured = false;
bool cmSystemTools::s_DisableMessages = false;
bool cmSystemTools::s_ForceUnixPaths = false;
-void (*cmSystemTools::s_ErrorCallback)(const char*, const char*,
- bool&, void*);
-void (*cmSystemTools::s_StdoutCallback)(const char*, int len, void*);
-void* cmSystemTools::s_ErrorCallbackClientData = 0;
-void* cmSystemTools::s_StdoutCallbackClientData = 0;
-bool (*cmSystemTools::s_InterruptCallback)(void*);
-void* cmSystemTools::s_InterruptCallbackClientData = 0;
+cmSystemTools::MessageCallback cmSystemTools::s_MessageCallback;
+cmSystemTools::OutputCallback cmSystemTools::s_StdoutCallback;
+cmSystemTools::OutputCallback cmSystemTools::s_StderrCallback;
+cmSystemTools::InterruptCallback cmSystemTools::s_InterruptCallback;
+void* cmSystemTools::s_MessageCallbackClientData;
+void* cmSystemTools::s_StdoutCallbackClientData;
+void* cmSystemTools::s_StderrCallbackClientData;
+void* cmSystemTools::s_InterruptCallbackClientData;
// replace replace with with as many times as it shows up in source.
// write the result into source.
@@ -179,10 +180,11 @@ void cmSystemTools::ExpandRegistryValues(std::string& source, KeyWOW64)
}
#endif
-std::string cmSystemTools::EscapeQuotes(const char* str)
+std::string cmSystemTools::EscapeQuotes(const std::string& str)
{
- std::string result = "";
- for(const char* ch = str; *ch != '\0'; ++ch)
+ std::string result;
+ result.reserve(str.size());
+ for(const char* ch = str.c_str(); *ch != '\0'; ++ch)
{
if(*ch == '"')
{
@@ -253,39 +255,48 @@ bool cmSystemTools::GetInterruptFlag()
return false;
}
-void cmSystemTools::SetErrorCallback(ErrorCallback f, void* clientData)
+void cmSystemTools::SetMessageCallback(MessageCallback f, void* clientData)
{
- s_ErrorCallback = f;
- s_ErrorCallbackClientData = clientData;
+ s_MessageCallback = f;
+ s_MessageCallbackClientData = clientData;
}
-void cmSystemTools::SetStdoutCallback(StdoutCallback f, void* clientData)
+void cmSystemTools::SetStdoutCallback(OutputCallback f, void* clientData)
{
s_StdoutCallback = f;
s_StdoutCallbackClientData = clientData;
}
+void cmSystemTools::SetStderrCallback(OutputCallback f, void* clientData)
+{
+ s_StderrCallback = f;
+ s_StderrCallbackClientData = clientData;
+}
+
void cmSystemTools::Stdout(const char* s)
{
- if(s_StdoutCallback)
+ 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)
+{
+ if(s_StderrCallback)
{
- (*s_StdoutCallback)(s, static_cast<int>(strlen(s)),
- s_StdoutCallbackClientData);
+ (*s_StderrCallback)(s, length, s_StderrCallbackClientData);
}
else
{
- std::cout << s;
- std::cout.flush();
- }
-}
-
-void cmSystemTools::Stderr(const char* s, int length)
-{
std::cerr.write(s, length);
std::cerr.flush();
+ }
}
-void cmSystemTools::Stdout(const char* s, int length)
+void cmSystemTools::Stdout(const char* s, size_t length)
{
if(s_StdoutCallback)
{
@@ -304,10 +315,10 @@ void cmSystemTools::Message(const char* m1, const char *title)
{
return;
}
- if(s_ErrorCallback)
+ if(s_MessageCallback)
{
- (*s_ErrorCallback)(m1, title, s_DisableMessages,
- s_ErrorCallbackClientData);
+ (*s_MessageCallback)(m1, title, s_DisableMessages,
+ s_MessageCallbackClientData);
return;
}
else
@@ -428,7 +439,7 @@ void cmSystemTools::ParseWindowsCommandLine(const char* command,
{
arg.append(backslashes, '\\');
backslashes = 0;
- if(isspace(*c))
+ if(((*c & 0x80) == 0 ) && isspace(*c))
{
if(in_quotes)
{
@@ -476,13 +487,6 @@ public:
args.push_back(*arg);
}
}
- void Store(std::vector<cmStdString>& args) const
- {
- for(char** arg = this->ArgV; arg && *arg; ++arg)
- {
- args.push_back(*arg);
- }
- }
};
//----------------------------------------------------------------------------
@@ -494,15 +498,6 @@ void cmSystemTools::ParseUnixCommandLine(const char* command,
argv.Store(args);
}
-//----------------------------------------------------------------------------
-void cmSystemTools::ParseUnixCommandLine(const char* command,
- std::vector<cmStdString>& args)
-{
- // Invoke the underlying parser.
- cmSystemToolsArgV argv = cmsysSystem_Parse_CommandForUnix(command, 0);
- argv.Store(args);
-}
-
std::string cmSystemTools::EscapeWindowsShellArgument(const char* arg,
int shell_flags)
{
@@ -522,9 +517,9 @@ std::string cmSystemTools::EscapeWindowsShellArgument(const char* arg,
return result;
}
-std::vector<cmStdString> cmSystemTools::ParseArguments(const char* command)
+std::vector<std::string> cmSystemTools::ParseArguments(const char* command)
{
- std::vector<cmStdString> args;
+ std::vector<std::string> args;
std::string arg;
bool win_path = false;
@@ -605,22 +600,6 @@ std::vector<cmStdString> cmSystemTools::ParseArguments(const char* command)
}
-bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command,
- std::string* output ,
- int* retVal , const char* dir ,
- OutputOption outputflag ,
- double timeout )
-{
- std::vector<std::string> cmd;
- for(std::vector<cmStdString>::const_iterator i = command.begin();
- i != command.end(); ++i)
- {
- cmd.push_back(*i);
- }
- return cmSystemTools::RunSingleCommand(cmd, output, retVal, dir,
- outputflag, timeout);
-}
-
bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
std::string* output ,
int* retVal , const char* dir ,
@@ -780,7 +759,7 @@ bool cmSystemTools::RunSingleCommand(
outputflag = OUTPUT_NONE;
}
- std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
+ std::vector<std::string> args = cmSystemTools::ParseArguments(command);
if(args.size() < 1)
{
@@ -946,7 +925,7 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
#endif
}
-bool cmSystemTools::ComputeFileMD5(const char* source, char* md5out)
+bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
cmCryptoHashMD5 md5;
@@ -961,7 +940,7 @@ bool cmSystemTools::ComputeFileMD5(const char* source, char* md5out)
#endif
}
-std::string cmSystemTools::ComputeStringMD5(const char* input)
+std::string cmSystemTools::ComputeStringMD5(const std::string& input)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
cmCryptoHashMD5 md5;
@@ -973,13 +952,14 @@ std::string cmSystemTools::ComputeStringMD5(const char* input)
#endif
}
-void cmSystemTools::Glob(const char *directory, const char *regexp,
+void cmSystemTools::Glob(const std::string& directory,
+ const std::string& regexp,
std::vector<std::string>& files)
{
cmsys::Directory d;
- cmsys::RegularExpression reg(regexp);
+ cmsys::RegularExpression reg(regexp.c_str());
- if (d.Load(directory))
+ if (d.Load(directory.c_str()))
{
size_t numf;
unsigned int i;
@@ -996,14 +976,13 @@ void cmSystemTools::Glob(const char *directory, const char *regexp,
}
-void cmSystemTools::GlobDirs(const char *fullPath,
+void cmSystemTools::GlobDirs(const std::string& path,
std::vector<std::string>& files)
{
- std::string path = fullPath;
std::string::size_type pos = path.find("/*");
if(pos == std::string::npos)
{
- files.push_back(fullPath);
+ files.push_back(path);
return;
}
std::string startPath = path.substr(0, pos);
@@ -1023,7 +1002,7 @@ void cmSystemTools::GlobDirs(const char *fullPath,
if(cmSystemTools::FileIsDirectory(fname.c_str()))
{
fname += finishPath;
- cmSystemTools::GlobDirs(fname.c_str(), files);
+ cmSystemTools::GlobDirs(fname, files);
}
}
}
@@ -1046,7 +1025,7 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
bool emptyArgs)
{
// If argument is empty, it is an empty list.
- if(arg.length() == 0 && !emptyArgs)
+ if(!emptyArgs && arg.empty())
{
return;
}
@@ -1056,10 +1035,11 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
newargs.push_back(arg);
return;
}
- std::vector<char> newArgVec;
+ std::string newArg;
+ const char *last = arg.c_str();
// Break the string at non-escaped semicolons not nested in [].
int squareNesting = 0;
- for(const char* c = arg.c_str(); *c; ++c)
+ for(const char* c = last; *c; ++c)
{
switch(*c)
{
@@ -1067,34 +1047,21 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
{
// We only want to allow escaping of semicolons. Other
// escapes should not be processed here.
- ++c;
- if(*c == ';')
+ const char* next = c + 1;
+ if(*next == ';')
{
- newArgVec.push_back(*c);
- }
- else
- {
- newArgVec.push_back('\\');
- if(*c)
- {
- newArgVec.push_back(*c);
- }
- else
- {
- // Terminate the loop properly.
- --c;
- }
+ newArg.append(last, c - last);
+ // Skip over the escape character
+ last = c = next;
}
} break;
case '[':
{
++squareNesting;
- newArgVec.push_back(*c);
} break;
case ']':
{
--squareNesting;
- newArgVec.push_back(*c);
} break;
case ';':
{
@@ -1102,36 +1069,33 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
// brackets.
if(squareNesting == 0)
{
- if ( newArgVec.size() || emptyArgs )
+ newArg.append(last, c - last);
+ // Skip over the semicolon
+ last = c + 1;
+ if ( !newArg.empty() || emptyArgs )
{
// Add the last argument if the string is not empty.
- newArgVec.push_back(0);
- newargs.push_back(&*newArgVec.begin());
- newArgVec.clear();
+ newargs.push_back(newArg);
+ newArg = "";
}
}
- else
- {
- newArgVec.push_back(*c);
- }
} break;
default:
{
// Just append this character.
- newArgVec.push_back(*c);
} break;
}
}
- if ( newArgVec.size() || emptyArgs )
+ newArg.append(last);
+ if ( !newArg.empty() || emptyArgs )
{
// Add the last argument if the string is not empty.
- newArgVec.push_back(0);
- newargs.push_back(&*newArgVec.begin());
+ newargs.push_back(newArg);
}
}
-bool cmSystemTools::SimpleGlob(const cmStdString& glob,
- std::vector<cmStdString>& files,
+bool cmSystemTools::SimpleGlob(const std::string& glob,
+ std::vector<std::string>& files,
int type /* = 0 */)
{
files.clear();
@@ -1249,7 +1213,7 @@ cmSystemTools::FileFormat cmSystemTools::GetFileFormat(const char* cext)
return cmSystemTools::UNKNOWN_FILE_FORMAT;
}
-bool cmSystemTools::Split(const char* s, std::vector<cmStdString>& l)
+bool cmSystemTools::Split(const char* s, std::vector<std::string>& l)
{
std::vector<std::string> temp;
bool res = Superclass::Split(s, temp);
@@ -1461,7 +1425,7 @@ bool cmSystemTools::IsPathToFramework(const char* path)
}
bool cmSystemTools::CreateTar(const char* outFileName,
- const std::vector<cmStdString>& files,
+ const std::vector<std::string>& files,
bool gzip, bool bzip2, bool verbose)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -1481,7 +1445,7 @@ bool cmSystemTools::CreateTar(const char* outFileName,
cmArchiveWrite::CompressNone)),
cmArchiveWrite::TypeTAR);
a.SetVerbose(verbose);
- for(std::vector<cmStdString>::const_iterator i = files.begin();
+ for(std::vector<std::string>::const_iterator i = files.begin();
i != files.end(); ++i)
{
std::string path = *i;
@@ -1664,7 +1628,9 @@ long copy_data(struct archive *ar, struct archive *aw)
return (r);
}
}
- return r;
+#if !defined(__clang__) && !defined(__HP_aCC)
+ return r; /* this should not happen but it quiets some compilers */
+#endif
}
bool extract_tar(const char* outFileName, bool verbose,
@@ -2153,7 +2119,7 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
// remove symlinks
exe = cmSystemTools::GetRealPath(exe.c_str());
exe_dir =
- cmSystemTools::GetFilenamePath(exe.c_str());
+ cmSystemTools::GetFilenamePath(exe);
}
else
{
@@ -2338,10 +2304,10 @@ bool cmSystemTools::GuessLibrarySOName(std::string const& fullPath,
bool cmSystemTools::GuessLibraryInstallName(std::string const& fullPath,
std::string& soname)
{
- std::vector<cmStdString> cmds;
+ std::vector<std::string> cmds;
cmds.push_back("otool");
cmds.push_back("-D");
- cmds.push_back(fullPath.c_str());
+ cmds.push_back(fullPath);
std::string output;
if(!RunSingleCommand(cmds, &output, 0, 0, OUTPUT_NONE))