Commit 7be70ca6 authored by Kitware Robot's avatar Kitware Robot Committed by Brad King
Browse files

KWSys 2017-05-16 (fe1f22ce)

Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit fe1f22ceefdae18df33e5bab8483fec7a82d4cee (master).

Upstream Shortlog
-----------------

Adam Weisi (3):
      8a799e36 Process: Improve definition ordering in header file
      7d56ef24 Process: Save results from all children internally
      b7eba998 Process: Add APIs to get results of individual processes

Ben Boeckel (2):
      cea71543 style: remove separator comments
      874dc559 style: help clang-format near macros
parent 2dec4695
......@@ -9,13 +9,11 @@
#include "Base64.h.in"
#endif
/*--------------------------------------------------------------------------*/
static const unsigned char kwsysBase64EncodeTable[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
/*--------------------------------------------------------------------------*/
static const unsigned char kwsysBase64DecodeTable[256] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
......@@ -40,19 +38,16 @@ static const unsigned char kwsysBase64DecodeTable[256] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
/*--------------------------------------------------------------------------*/
static unsigned char kwsysBase64EncodeChar(int c)
{
return kwsysBase64EncodeTable[(unsigned char)c];
}
/*--------------------------------------------------------------------------*/
static unsigned char kwsysBase64DecodeChar(unsigned char c)
{
return kwsysBase64DecodeTable[c];
}
/*--------------------------------------------------------------------------*/
/* Encode 3 bytes into a 4 byte string. */
void kwsysBase64_Encode3(const unsigned char* src, unsigned char* dest)
{
......@@ -64,7 +59,6 @@ void kwsysBase64_Encode3(const unsigned char* src, unsigned char* dest)
dest[3] = kwsysBase64EncodeChar(src[2] & 0x3F);
}
/*--------------------------------------------------------------------------*/
/* Encode 2 bytes into a 4 byte string. */
void kwsysBase64_Encode2(const unsigned char* src, unsigned char* dest)
{
......@@ -75,7 +69,6 @@ void kwsysBase64_Encode2(const unsigned char* src, unsigned char* dest)
dest[3] = '=';
}
/*--------------------------------------------------------------------------*/
/* Encode 1 bytes into a 4 byte string. */
void kwsysBase64_Encode1(const unsigned char* src, unsigned char* dest)
{
......@@ -85,7 +78,6 @@ void kwsysBase64_Encode1(const unsigned char* src, unsigned char* dest)
dest[3] = '=';
}
/*--------------------------------------------------------------------------*/
/* Encode 'length' bytes from the input buffer and store the
encoded stream into the output buffer. Return the length of the encoded
buffer (output). Note that the output buffer must be allocated by the caller
......@@ -135,7 +127,6 @@ size_t kwsysBase64_Encode(const unsigned char* input, size_t length,
return (size_t)(optr - output);
}
/*--------------------------------------------------------------------------*/
/* Decode 4 bytes into a 3 byte string. */
int kwsysBase64_Decode3(const unsigned char* src, unsigned char* dest)
{
......@@ -169,7 +160,6 @@ int kwsysBase64_Decode3(const unsigned char* src, unsigned char* dest)
return 3;
}
/*--------------------------------------------------------------------------*/
/* Decode bytes from the input buffer and store the decoded stream
into the output buffer until 'length' bytes have been decoded. Return the
real length of the decoded stream (which should be equal to 'length'). Note
......
......@@ -41,8 +41,6 @@
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
//============================================================================
struct CommandLineArgumentsCallbackStructure
{
const char* Argument;
......@@ -91,10 +89,7 @@ public:
VectorOfStrings UnusedArguments;
};
//============================================================================
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
CommandLineArguments::CommandLineArguments()
{
this->Internals = new CommandLineArguments::Internal;
......@@ -103,13 +98,11 @@ CommandLineArguments::CommandLineArguments()
this->StoreUnusedArgumentsFlag = false;
}
//----------------------------------------------------------------------------
CommandLineArguments::~CommandLineArguments()
{
delete this->Internals;
}
//----------------------------------------------------------------------------
void CommandLineArguments::Initialize(int argc, const char* const argv[])
{
int cc;
......@@ -121,26 +114,22 @@ void CommandLineArguments::Initialize(int argc, const char* const argv[])
}
}
//----------------------------------------------------------------------------
void CommandLineArguments::Initialize(int argc, char* argv[])
{
this->Initialize(argc, static_cast<const char* const*>(argv));
}
//----------------------------------------------------------------------------
void CommandLineArguments::Initialize()
{
this->Internals->Argv.clear();
this->Internals->LastArgument = 0;
}
//----------------------------------------------------------------------------
void CommandLineArguments::ProcessArgument(const char* arg)
{
this->Internals->Argv.push_back(arg);
}
//----------------------------------------------------------------------------
bool CommandLineArguments::GetMatchedArguments(
std::vector<std::string>* matches, const std::string& arg)
{
......@@ -164,7 +153,6 @@ bool CommandLineArguments::GetMatchedArguments(
return !matches->empty();
}
//----------------------------------------------------------------------------
int CommandLineArguments::Parse()
{
std::vector<std::string>::size_type cc;
......@@ -286,7 +274,6 @@ int CommandLineArguments::Parse()
return 1;
}
//----------------------------------------------------------------------------
void CommandLineArguments::GetRemainingArguments(int* argc, char*** argv)
{
CommandLineArguments::Internal::VectorOfStrings::size_type size =
......@@ -310,7 +297,6 @@ void CommandLineArguments::GetRemainingArguments(int* argc, char*** argv)
*argv = args;
}
//----------------------------------------------------------------------------
void CommandLineArguments::GetUnusedArguments(int* argc, char*** argv)
{
CommandLineArguments::Internal::VectorOfStrings::size_type size =
......@@ -334,7 +320,6 @@ void CommandLineArguments::GetUnusedArguments(int* argc, char*** argv)
*argv = args;
}
//----------------------------------------------------------------------------
void CommandLineArguments::DeleteRemainingArguments(int argc, char*** argv)
{
int cc;
......@@ -344,7 +329,6 @@ void CommandLineArguments::DeleteRemainingArguments(int argc, char*** argv)
delete[] * argv;
}
//----------------------------------------------------------------------------
void CommandLineArguments::AddCallback(const char* argument,
ArgumentTypeEnum type,
CallbackType callback, void* call_data,
......@@ -363,7 +347,6 @@ void CommandLineArguments::AddCallback(const char* argument,
this->GenerateHelp();
}
//----------------------------------------------------------------------------
void CommandLineArguments::AddArgument(const char* argument,
ArgumentTypeEnum type,
VariableTypeEnum vtype, void* variable,
......@@ -382,7 +365,6 @@ void CommandLineArguments::AddArgument(const char* argument,
this->GenerateHelp();
}
//----------------------------------------------------------------------------
#define CommandLineArgumentsAddArgumentMacro(type, ctype) \
void CommandLineArguments::AddArgument(const char* argument, \
ArgumentTypeEnum type, \
......@@ -392,22 +374,24 @@ void CommandLineArguments::AddArgument(const char* argument,
variable, help); \
}
/* clang-format off */
CommandLineArgumentsAddArgumentMacro(BOOL, bool)
CommandLineArgumentsAddArgumentMacro(INT, int)
CommandLineArgumentsAddArgumentMacro(DOUBLE, double)
CommandLineArgumentsAddArgumentMacro(STRING, char*)
CommandLineArgumentsAddArgumentMacro(STL_STRING, std::string)
CommandLineArgumentsAddArgumentMacro(VECTOR_BOOL, std::vector<bool>)
CommandLineArgumentsAddArgumentMacro(VECTOR_INT, std::vector<int>)
CommandLineArgumentsAddArgumentMacro(VECTOR_DOUBLE,
std::vector<double>)
CommandLineArgumentsAddArgumentMacro(VECTOR_STRING,
std::vector<char*>)
CommandLineArgumentsAddArgumentMacro(
VECTOR_STL_STRING, std::vector<std::string>)
//----------------------------------------------------------------------------
CommandLineArgumentsAddArgumentMacro(INT, int)
CommandLineArgumentsAddArgumentMacro(DOUBLE, double)
CommandLineArgumentsAddArgumentMacro(STRING, char*)
CommandLineArgumentsAddArgumentMacro(STL_STRING, std::string)
CommandLineArgumentsAddArgumentMacro(VECTOR_BOOL, std::vector<bool>)
CommandLineArgumentsAddArgumentMacro(VECTOR_INT, std::vector<int>)
CommandLineArgumentsAddArgumentMacro(VECTOR_DOUBLE, std::vector<double>)
CommandLineArgumentsAddArgumentMacro(VECTOR_STRING, std::vector<char*>)
CommandLineArgumentsAddArgumentMacro(VECTOR_STL_STRING,
std::vector<std::string>)
#ifdef HELP_CLANG_FORMAT
;
#endif
/* clang-format on */
#define CommandLineArgumentsAddBooleanArgumentMacro(type, ctype) \
void CommandLineArguments::AddBooleanArgument( \
const char* argument, ctype* variable, const char* help) \
......@@ -416,29 +400,28 @@ CommandLineArgumentsAddArgumentMacro(BOOL, bool)
CommandLineArguments::type##_TYPE, variable, help); \
}
CommandLineArgumentsAddBooleanArgumentMacro(BOOL, bool)
CommandLineArgumentsAddBooleanArgumentMacro(INT, int)
CommandLineArgumentsAddBooleanArgumentMacro(DOUBLE,
double)
CommandLineArgumentsAddBooleanArgumentMacro(STRING,
char*)
CommandLineArgumentsAddBooleanArgumentMacro(
STL_STRING, std::string)
/* clang-format off */
CommandLineArgumentsAddBooleanArgumentMacro(BOOL, bool)
CommandLineArgumentsAddBooleanArgumentMacro(INT, int)
CommandLineArgumentsAddBooleanArgumentMacro(DOUBLE, double)
CommandLineArgumentsAddBooleanArgumentMacro(STRING, char*)
CommandLineArgumentsAddBooleanArgumentMacro(STL_STRING, std::string)
#ifdef HELP_CLANG_FORMAT
;
#endif
/* clang-format on */
//----------------------------------------------------------------------------
void CommandLineArguments::SetClientData(void* client_data)
void CommandLineArguments::SetClientData(void* client_data)
{
this->Internals->ClientData = client_data;
}
//----------------------------------------------------------------------------
void CommandLineArguments::SetUnknownArgumentCallback(
CommandLineArguments::ErrorCallbackType callback)
{
this->Internals->UnknownArgumentCallback = callback;
}
//----------------------------------------------------------------------------
const char* CommandLineArguments::GetHelp(const char* arg)
{
CommandLineArguments::Internal::CallbacksMap::iterator it =
......@@ -461,7 +444,6 @@ const char* CommandLineArguments::GetHelp(const char* arg)
return cs->Help;
}
//----------------------------------------------------------------------------
void CommandLineArguments::SetLineLength(unsigned int ll)
{
if (ll < 9 || ll > 1000) {
......@@ -471,19 +453,16 @@ void CommandLineArguments::SetLineLength(unsigned int ll)
this->GenerateHelp();
}
//----------------------------------------------------------------------------
const char* CommandLineArguments::GetArgv0()
{
return this->Internals->Argv0.c_str();
}
//----------------------------------------------------------------------------
unsigned int CommandLineArguments::GetLastArgument()
{
return static_cast<unsigned int>(this->Internals->LastArgument + 1);
}
//----------------------------------------------------------------------------
void CommandLineArguments::GenerateHelp()
{
std::ostringstream str;
......@@ -633,7 +612,6 @@ void CommandLineArguments::GenerateHelp()
this->Help = str.str();
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(bool* variable,
const std::string& value)
{
......@@ -646,7 +624,6 @@ void CommandLineArguments::PopulateVariable(bool* variable,
}
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(int* variable,
const std::string& value)
{
......@@ -658,7 +635,6 @@ void CommandLineArguments::PopulateVariable(int* variable,
// }
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(double* variable,
const std::string& value)
{
......@@ -670,7 +646,6 @@ void CommandLineArguments::PopulateVariable(double* variable,
// }
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(char** variable,
const std::string& value)
{
......@@ -682,14 +657,12 @@ void CommandLineArguments::PopulateVariable(char** variable,
strcpy(*variable, value.c_str());
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(std::string* variable,
const std::string& value)
{
*variable = value;
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(std::vector<bool>* variable,
const std::string& value)
{
......@@ -702,7 +675,6 @@ void CommandLineArguments::PopulateVariable(std::vector<bool>* variable,
variable->push_back(val);
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(std::vector<int>* variable,
const std::string& value)
{
......@@ -714,7 +686,6 @@ void CommandLineArguments::PopulateVariable(std::vector<int>* variable,
// }
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(std::vector<double>* variable,
const std::string& value)
{
......@@ -726,7 +697,6 @@ void CommandLineArguments::PopulateVariable(std::vector<double>* variable,
// }
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(std::vector<char*>* variable,
const std::string& value)
{
......@@ -735,14 +705,12 @@ void CommandLineArguments::PopulateVariable(std::vector<char*>* variable,
variable->push_back(var);
}
//----------------------------------------------------------------------------
void CommandLineArguments::PopulateVariable(std::vector<std::string>* variable,
const std::string& value)
{
variable->push_back(value);
}
//----------------------------------------------------------------------------
bool CommandLineArguments::PopulateVariable(
CommandLineArgumentsCallbackStructure* cs, const char* value)
{
......
......@@ -20,7 +20,6 @@
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
class DirectoryInternals
{
public:
......@@ -31,25 +30,21 @@ public:
std::string Path;
};
//----------------------------------------------------------------------------
Directory::Directory()
{
this->Internal = new DirectoryInternals;
}
//----------------------------------------------------------------------------
Directory::~Directory()
{
delete this->Internal;
}
//----------------------------------------------------------------------------
unsigned long Directory::GetNumberOfFiles() const
{
return static_cast<unsigned long>(this->Internal->Files.size());
}
//----------------------------------------------------------------------------
const char* Directory::GetFile(unsigned long dindex) const
{
if (dindex >= this->Internal->Files.size()) {
......@@ -58,13 +53,11 @@ const char* Directory::GetFile(unsigned long dindex) const
return this->Internal->Files[dindex].c_str();
}
//----------------------------------------------------------------------------
const char* Directory::GetPath() const
{
return this->Internal->Path.c_str();
}
//----------------------------------------------------------------------------
void Directory::Clear()
{
this->Internal->Path.resize(0);
......
......@@ -26,20 +26,17 @@
// the static methods of DynamicLoader.
#if !KWSYS_SUPPORTS_SHARED_LIBS
//----------------------------------------------------------------------------
// Implementation for environments without dynamic libs
#include <string.h> // for strerror()
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
{
return 0;
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
if (!lib) {
......@@ -49,14 +46,12 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return 1;
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
{
return 0;
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
{
return "General error";
......@@ -65,21 +60,18 @@ const char* DynamicLoader::LastError()
} // namespace KWSYS_NAMESPACE
#elif defined(__hpux)
//----------------------------------------------------------------------------
// Implementation for HPUX machines
#include <dl.h>
#include <errno.h>
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
{
return shl_load(libname.c_str(), BIND_DEFERRED | DYNAMIC_PATH, 0L);
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
if (!lib) {
......@@ -88,7 +80,6 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return !shl_unload(lib);
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
{
......@@ -132,14 +123,12 @@ const char* DynamicLoader::LastError()
} // namespace KWSYS_NAMESPACE
#elif defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED < 1030)
//----------------------------------------------------------------------------
// Implementation for Mac OS X 10.2.x and earlier
#include <mach-o/dyld.h>
#include <string.h> // for strlen
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
{
......@@ -158,7 +147,6 @@ DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
return handle;
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
// NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED
......@@ -170,7 +158,6 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return success;
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
{
......@@ -191,7 +178,6 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
{
return 0;
......@@ -200,13 +186,11 @@ const char* DynamicLoader::LastError()
} // namespace KWSYS_NAMESPACE
#elif defined(_WIN32) && !defined(__CYGWIN__)
//----------------------------------------------------------------------------
// Implementation for Windows win32 code but not cygwin
#include <windows.h>
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
{
......@@ -220,13 +204,11 @@ DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
return lh;
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
return (int)FreeLibrary(lib);
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
{
......@@ -274,7 +256,6 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
#endif
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
{
LPVOID lpMsgBuf = NULL;
......@@ -299,7 +280,6 @@ const char* DynamicLoader::LastError()
} // namespace KWSYS_NAMESPACE
#elif defined(__BEOS__)
//----------------------------------------------------------------------------
// Implementation for BeOS / Haiku
#include <string.h> // for strerror()
......@@ -310,7 +290,6 @@ namespace KWSYS_NAMESPACE {
static image_id last_dynamic_err = B_OK;
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
{
......@@ -325,7 +304,6 @@ DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
return rc + 1;
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
if (!lib) {
......@@ -343,7 +321,6 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return 1;
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
{
......@@ -372,7 +349,6 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
return result.psym;
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
{
const char* retval = strerror(last_dynamic_err);
......@@ -383,7 +359,6 @@ const char* DynamicLoader::LastError()
} // namespace KWSYS_NAMESPACE
#elif defined(__MINT__)
//----------------------------------------------------------------------------
// Implementation for FreeMiNT on Atari
#define _GNU_SOURCE /* for program_invocation_name */
#include <dld.h>
......@@ -393,7 +368,6 @@ const char* DynamicLoader::LastError()
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
{
......@@ -404,7 +378,6 @@ DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
return (void*)name;
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
dld_unlink_by_file((char*)lib, 0);
......@@ -412,7 +385,6 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return 0;
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
{
......@@ -426,7 +398,6 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
return result.psym;
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
{
return dld_strerror(dld_errno);
......@@ -435,21 +406,18 @@ const char* DynamicLoader::LastError()
} // namespace KWSYS_NAMESPACE
#else
//----------------------------------------------------------------------------
// Default implementation for *NIX systems (including Mac OS X 10.3 and
// later) which use dlopen
#include <dlfcn.h>
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
{
return dlopen(libname.c_str(), RTLD_LAZY);
}