Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ken-martin/kwsys
  • isanych/kwsys
  • scivision/kwsys
  • nvartolomei/kwsys
  • alexy.pellegrini/kwsys
  • leha-bot/kwsys
  • utils/kwsys
  • lakor64/kwsys
  • dbahadir/kwsys
  • evansanita713/kwsys
  • chrstphrchvz/kwsys
  • robertmaynard/kwsys
  • shannonbooth/kwsys
  • brad.king/kwsys
  • eberge/kwsys
  • gjasny/kwsys
  • ben.boeckel/kwsys
  • madscientist/kwsys
  • ulatekh/kwsys
  • Joker-Van/kwsys
  • chuck.atkins/kwsys
  • egorpugin/kwsys
  • mwestphal/kwsys
  • purpleKarrot/kwsys
  • do-m-en/kwsys
  • nicber/kwsys
  • FloriansGit/kwsys
  • pa.solodovnikov/kwsys
  • sbwilson/kwsys
  • R2RT/kwsys
  • asit-dhal/kwsys
  • qarni/kwsys
  • nilsgladitz/kwsys
  • fwinkl/kwsys
  • leon-richardt/kwsys
  • jdavidberger/kwsys
  • seanm/kwsys
  • shawn.waldon/kwsys
  • svelez/kwsys
  • jrtc27/kwsys
  • bdvd/kwsys
  • multiplemonomials/kwsys
  • mwillers/kwsys
  • hernancmartinez/kwsys
  • semlanik/kwsys
  • jesusjcmtool/kwsys
  • vvs31415/kwsys
  • DerDakon/kwsys
  • metti/kwsys
  • dublet/kwsys
  • blowekamp/kwsys
  • bryonbean/kwsys
  • luzpaz/kwsys
  • kfitch42/kwsys
  • sebholt/kwsys
  • clinton/kwsys
  • volo-zyko/kwsys
  • hjmjohnson/kwsys
  • kyle.edwards/kwsys
  • sankhesh/kwsys
  • sebastianlipponer/kwsys
  • veprbl/kwsys
  • nekto1989/kwsys
  • todoooo/kwsys
  • spiros.tsalikis/kwsys
  • dnakamura/kwsys
  • dawesc/kwsys
  • orgads/kwsys
  • whoozle/kwsys
  • makise-homura/kwsys
  • LetWe/kwsys
  • lemniscati/kwsys
  • rleigh/kwsys
  • sjoubert/kwsys
  • dzenanz/kwsys
  • georg-emg/kwsys
  • marc.chevrier/kwsys
  • mstorsjo/kwsys
  • clemenswasser/kwsys
  • besser82/kwsys
  • thewtex/kwsys
  • yuriy-odonnell-epic/kwsys
  • huangguojun/kwsys
  • ceztko/kwsys
  • klossto/kwsys
  • cory.quammen/kwsys
  • cwarner-8702/kwsys
  • flagarde/kwsys
  • petk/kwsys
  • tstellar/kwsys
  • Lekensteyn/kwsys
  • crondog/kwsys
  • ihnorton/kwsys
  • albert-astals-cid-kdab/kwsys
  • alimpfard/kwsys
  • leibabarry/kwsys
  • jvanboxtel/kwsys
  • laurent.malka/kwsys
  • martin.duffy/kwsys
  • brad0/kwsys
  • jpr42/kwsys
  • neek78/kwsys
  • nnemkin/kwsys
  • Pospelove/kwsys
  • timblechmann/kwsys
  • nocnokneo/kwsys
  • hygonsoc/kwsys
  • dutow/kwsys
  • novas0x2a/kwsys
  • Markus87/kwsys
  • Xeonacid/kwsys
111 results
Show changes
Commits on Source (783)
---
# This configuration requires clang-format 3.8 or higher.
# This configuration requires clang-format version 18 exactly.
BasedOnStyle: Mozilla
AlignOperands: false
AlwaysBreakAfterReturnType: None
AllowShortFunctionsOnASingleLine: InlineOnly
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterEnum: true
AfterFunction: true
AfterStruct: true
AfterUnion: true
BreakBeforeBraces: Custom
ColumnLimit: 79
IndentPPDirectives: AfterHash
QualifierAlignment: Right
SortUsingDeclarations: false
SpaceAfterTemplateKeyword: true
Standard: Cpp03
...
.git* export-ignore
# import off
.gitattributes -export-ignore
.hooks* export-ignore
# Custom attribute to mark sources as using the kwsys C code style.
[attr]kwsys-c-style whitespace=tab-in-indent format.clang-format=18
/GitSetup export-ignore
/SetupForDevelopment.sh export-ignore eol=lf
/*.sh export-ignore eol=lf
/*.bash export-ignore eol=lf
/.clang-format export-ignore
# import on
/CONTRIBUTING.rst conflict-marker-size=78
*.c kwsys-c-style
*.c.in kwsys-c-style
*.cxx kwsys-c-style
*.h kwsys-c-style
*.h.in kwsys-c-style
*.hxx kwsys-c-style
*.hxx.in kwsys-c-style
*.c whitespace=tab-in-indent,no-lf-at-eof
*.h whitespace=tab-in-indent,no-lf-at-eof
*.h.in whitespace=tab-in-indent,no-lf-at-eof
*.cxx whitespace=tab-in-indent,no-lf-at-eof
*.hxx whitespace=tab-in-indent,no-lf-at-eof
*.hxx.in whitespace=tab-in-indent,no-lf-at-eof
*.txt whitespace=tab-in-indent,no-lf-at-eof
*.cmake whitespace=tab-in-indent,no-lf-at-eof
*.cmake whitespace=tab-in-indent
*.rst whitespace=tab-in-indent conflict-marker-size=79
*.txt whitespace=tab-in-indent
[hooks "chain"]
pre-commit = GitSetup/pre-commit
......@@ -6,17 +6,15 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
#include "Base64.h.in"
# include "Base64.h.in"
#endif
/*--------------------------------------------------------------------------*/
static const unsigned char kwsysBase64EncodeTable[65] =
static unsigned char const kwsysBase64EncodeTable[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
/*--------------------------------------------------------------------------*/
static const unsigned char kwsysBase64DecodeTable[256] = {
static unsigned char const 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,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
......@@ -40,21 +38,18 @@ 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)
void kwsysBase64_Encode3(unsigned char const* src, unsigned char* dest)
{
dest[0] = kwsysBase64EncodeChar((src[0] >> 2) & 0x3F);
dest[1] =
......@@ -64,9 +59,8 @@ 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)
void kwsysBase64_Encode2(unsigned char const* src, unsigned char* dest)
{
dest[0] = kwsysBase64EncodeChar((src[0] >> 2) & 0x3F);
dest[1] =
......@@ -75,9 +69,8 @@ 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)
void kwsysBase64_Encode1(unsigned char const* src, unsigned char* dest)
{
dest[0] = kwsysBase64EncodeChar((src[0] >> 2) & 0x3F);
dest[1] = kwsysBase64EncodeChar(((src[0] << 4) & 0x30));
......@@ -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
......@@ -96,11 +88,11 @@ void kwsysBase64_Encode1(const unsigned char* src, unsigned char* dest)
actually knowing how much data to expect (if the input is not a multiple of
3 bytes then the extra padding needed to complete the encode 4 bytes will
stop the decoding anyway). */
size_t kwsysBase64_Encode(const unsigned char* input, size_t length,
size_t kwsysBase64_Encode(unsigned char const* input, size_t length,
unsigned char* output, int mark_end)
{
const unsigned char* ptr = input;
const unsigned char* end = input + length;
unsigned char const* ptr = input;
unsigned char const* end = input + length;
unsigned char* optr = output;
/* Encode complete triplet */
......@@ -135,11 +127,13 @@ 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)
int kwsysBase64_Decode3(unsigned char const* src, unsigned char* dest)
{
unsigned char d0, d1, d2, d3;
unsigned char d0;
unsigned char d1;
unsigned char d2;
unsigned char d3;
d0 = kwsysBase64DecodeChar(src[0]);
d1 = kwsysBase64DecodeChar(src[1]);
......@@ -169,7 +163,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
......@@ -179,16 +172,16 @@ int kwsysBase64_Decode3(const unsigned char* src, unsigned char* dest)
'length' parameter is ignored. This enables the caller to decode a stream
without actually knowing how much decoded data to expect (of course, the
buffer must be large enough). */
size_t kwsysBase64_Decode(const unsigned char* input, size_t length,
size_t kwsysBase64_Decode(unsigned char const* input, size_t length,
unsigned char* output, size_t max_input_length)
{
const unsigned char* ptr = input;
unsigned char const* ptr = input;
unsigned char* optr = output;
/* Decode complete triplet */
if (max_input_length) {
const unsigned char* end = input + max_input_length;
unsigned char const* end = input + max_input_length;
while (ptr < end) {
int len = kwsysBase64_Decode3(ptr, optr);
optr += len;
......
......@@ -12,17 +12,17 @@
not visible to user code. Use kwsysHeaderDump.pl to reproduce
these macros after making changes to the interface. */
#if !defined(KWSYS_NAMESPACE)
#define kwsys_ns(x) @KWSYS_NAMESPACE@##x
#define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
#endif
#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
#define kwsysBase64 kwsys_ns(Base64)
#define kwsysBase64_Decode kwsys_ns(Base64_Decode)
#define kwsysBase64_Decode3 kwsys_ns(Base64_Decode3)
#define kwsysBase64_Encode kwsys_ns(Base64_Encode)
#define kwsysBase64_Encode1 kwsys_ns(Base64_Encode1)
#define kwsysBase64_Encode2 kwsys_ns(Base64_Encode2)
#define kwsysBase64_Encode3 kwsys_ns(Base64_Encode3)
# define kwsysBase64 kwsys_ns(Base64)
# define kwsysBase64_Decode kwsys_ns(Base64_Decode)
# define kwsysBase64_Decode3 kwsys_ns(Base64_Decode3)
# define kwsysBase64_Encode kwsys_ns(Base64_Encode)
# define kwsysBase64_Encode1 kwsys_ns(Base64_Encode1)
# define kwsysBase64_Encode2 kwsys_ns(Base64_Encode2)
# define kwsysBase64_Encode3 kwsys_ns(Base64_Encode3)
#endif
#if defined(__cplusplus)
......@@ -32,19 +32,19 @@ extern "C" {
/**
* Encode 3 bytes into a 4 byte string.
*/
kwsysEXPORT void kwsysBase64_Encode3(const unsigned char* src,
kwsysEXPORT void kwsysBase64_Encode3(unsigned char const* src,
unsigned char* dest);
/**
* Encode 2 bytes into a 4 byte string.
*/
kwsysEXPORT void kwsysBase64_Encode2(const unsigned char* src,
kwsysEXPORT void kwsysBase64_Encode2(unsigned char const* src,
unsigned char* dest);
/**
* Encode 1 bytes into a 4 byte string.
*/
kwsysEXPORT void kwsysBase64_Encode1(const unsigned char* src,
kwsysEXPORT void kwsysBase64_Encode1(unsigned char const* src,
unsigned char* dest);
/**
......@@ -60,7 +60,7 @@ kwsysEXPORT void kwsysBase64_Encode1(const unsigned char* src,
* the extra padding needed to complete the encode 4 bytes will stop
* the decoding anyway).
*/
kwsysEXPORT size_t kwsysBase64_Encode(const unsigned char* input,
kwsysEXPORT size_t kwsysBase64_Encode(unsigned char const* input,
size_t length, unsigned char* output,
int mark_end);
......@@ -68,7 +68,7 @@ kwsysEXPORT size_t kwsysBase64_Encode(const unsigned char* input,
* Decode 4 bytes into a 3 byte string. Returns the number of bytes
* actually decoded.
*/
kwsysEXPORT int kwsysBase64_Decode3(const unsigned char* src,
kwsysEXPORT int kwsysBase64_Decode3(unsigned char const* src,
unsigned char* dest);
/**
......@@ -83,7 +83,7 @@ kwsysEXPORT int kwsysBase64_Decode3(const unsigned char* src,
* much decoded data to expect (of course, the buffer must be large
* enough).
*/
kwsysEXPORT size_t kwsysBase64_Decode(const unsigned char* input,
kwsysEXPORT size_t kwsysBase64_Decode(unsigned char const* input,
size_t length, unsigned char* output,
size_t max_input_length);
......@@ -94,17 +94,17 @@ kwsysEXPORT size_t kwsysBase64_Decode(const unsigned char* input,
/* If we are building a kwsys .c or .cxx file, let it use these macros.
Otherwise, undefine them to keep the namespace clean. */
#if !defined(KWSYS_NAMESPACE)
#undef kwsys_ns
#undef kwsysEXPORT
#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
#undef kwsysBase64
#undef kwsysBase64_Decode
#undef kwsysBase64_Decode3
#undef kwsysBase64_Encode
#undef kwsysBase64_Encode1
#undef kwsysBase64_Encode2
#undef kwsysBase64_Encode3
#endif
# undef kwsys_ns
# undef kwsysEXPORT
# if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsysBase64
# undef kwsysBase64_Decode
# undef kwsysBase64_Decode3
# undef kwsysBase64_Encode
# undef kwsysBase64_Encode1
# undef kwsysBase64_Encode2
# undef kwsysBase64_Encode3
# endif
#endif
#endif
This diff is collapsed.
Contributing to KWSys
*********************
Overview
========
Patches
=======
KWSys is kept in its own Git repository and shared by several projects
via copies in their source trees. Changes to KWSys should not be made
directly in a host project, except perhaps in maintenance branches.
Please visit
http://public.kitware.com/Wiki/KWSys/Git
KWSys uses `Kitware's GitLab Instance`_ to manage development and code review.
To contribute patches:
to contribute changes directly to KWSys upstream. Once changes are
reviewed, tested, and integrated there then the copies of KWSys within
dependent projects can be updated to get the changes.
#. Fork the upstream `KWSys Repository`_ into a personal account.
#. Base all new work on the upstream ``master`` branch.
#. Run ``./SetupForDevelopment.sh`` in new local work trees.
#. Create commits making incremental, distinct, logically complete changes.
#. Push a topic branch to a personal repository fork on GitLab.
#. Create a GitLab Merge Request targeting the upstream ``master`` branch.
Issues
======
Once changes are reviewed, tested, and integrated to KWSys upstream then
copies of KWSys within dependent projects can be updated to get the changes.
KWSys has no independent issue tracker. After encountering an issue
(bug) please try to submit a patch using the above instructions.
Otherwise please report the issue to the tracker for the project that
hosts the copy of KWSys in which the problem was found.
.. _`Kitware's GitLab Instance`: https://gitlab.kitware.com
.. _`KWSys Repository`: https://gitlab.kitware.com/utils/kwsys
Code Style
==========
We use `clang-format`_ to define our style for C++ code in the KWSys source
tree. See the `.clang-format`_ configuration file for our style settings.
Use ``clang-format`` version 3.8 or higher to format source files.
See also the `clang-format.bash`_ script.
We use `clang-format`_ version **18** to define our style for C++ code in
the KWSys source tree. See the `.clang-format`_ configuration file for
our style settings. Use the `clang-format.bash`_ script to format source
code. It automatically runs ``clang-format`` on the set of source files
for which we enforce style. The script also has options to format only
a subset of files, such as those that are locally modified.
.. _`clang-format`: http://clang.llvm.org/docs/ClangFormat.html
.. _`clang-format`: https://clang.llvm.org/docs/ClangFormat.html
.. _`.clang-format`: .clang-format
.. _`clang-format.bash`: clang-format.bash
License
=======
......
......@@ -3,7 +3,7 @@
set(CTEST_PROJECT_NAME "KWSys")
set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT")
set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_METHOD "https")
set(CTEST_DROP_SITE "open.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=KWSys")
set(CTEST_DROP_SITE_CDASH TRUE)
......@@ -12,3 +12,7 @@
list(APPEND CTEST_CUSTOM_MEMCHECK_IGNORE
kwsys.testProcess-10
)
list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
"LICENSE WARNING"
)
This diff is collapsed.
......@@ -62,6 +62,9 @@ public:
CommandLineArguments();
~CommandLineArguments();
CommandLineArguments(CommandLineArguments const&) = delete;
CommandLineArguments& operator=(CommandLineArguments const&) = delete;
/**
* Various argument types.
*/
......@@ -97,14 +100,14 @@ public:
/**
* Prototypes for callbacks for callback interface.
*/
typedef int (*CallbackType)(const char* argument, const char* value,
typedef int (*CallbackType)(char const* argument, char const* value,
void* call_data);
typedef int (*ErrorCallbackType)(const char* argument, void* client_data);
typedef int (*ErrorCallbackType)(char const* argument, void* client_data);
/**
* Initialize internal data structures. This should be called before parsing.
*/
void Initialize(int argc, const char* const argv[]);
void Initialize(int argc, char const* const argv[]);
void Initialize(int argc, char* argv[]);
/**
......@@ -113,7 +116,7 @@ public:
* are not available.
*/
void Initialize();
void ProcessArgument(const char* arg);
void ProcessArgument(char const* arg);
/**
* This method will parse arguments and call appropriate methods.
......@@ -126,56 +129,56 @@ public:
* argument help specifies the help string used with this option. The
* callback and call_data can be skipped.
*/
void AddCallback(const char* argument, ArgumentTypeEnum type,
CallbackType callback, void* call_data, const char* help);
void AddCallback(char const* argument, ArgumentTypeEnum type,
CallbackType callback, void* call_data, char const* help);
/**
* Add handler for argument which is going to set the variable to the
* specified value. If the argument is specified, the option is casted to the
* appropriate type.
*/
void AddArgument(const char* argument, ArgumentTypeEnum type, bool* variable,
const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type, int* variable,
const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
double* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
char** variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
std::string* variable, const char* help);
void AddArgument(char const* argument, ArgumentTypeEnum type, bool* variable,
char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type, int* variable,
char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
double* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
char** variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::string* variable, char const* help);
/**
* Add handler for argument which is going to set the variable to the
* specified value. If the argument is specified, the option is casted to the
* appropriate type. This will handle the multi argument values.
*/
void AddArgument(const char* argument, ArgumentTypeEnum type,
std::vector<bool>* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
std::vector<int>* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
std::vector<double>* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
std::vector<char*>* variable, const char* help);
void AddArgument(const char* argument, ArgumentTypeEnum type,
std::vector<std::string>* variable, const char* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<bool>* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<int>* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<double>* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<char*>* variable, char const* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
std::vector<std::string>* variable, char const* help);
/**
* Add handler for boolean argument. The argument does not take any option
* and if it is specified, the value of the variable is true/1, otherwise it
* is false/0.
*/
void AddBooleanArgument(const char* argument, bool* variable,
const char* help);
void AddBooleanArgument(const char* argument, int* variable,
const char* help);
void AddBooleanArgument(const char* argument, double* variable,
const char* help);
void AddBooleanArgument(const char* argument, char** variable,
const char* help);
void AddBooleanArgument(const char* argument, std::string* variable,
const char* help);
void AddBooleanArgument(char const* argument, bool* variable,
char const* help);
void AddBooleanArgument(char const* argument, int* variable,
char const* help);
void AddBooleanArgument(char const* argument, double* variable,
char const* help);
void AddBooleanArgument(char const* argument, char** variable,
char const* help);
void AddBooleanArgument(char const* argument, std::string* variable,
char const* help);
/**
* Set the callbacks for error handling.
......@@ -202,8 +205,8 @@ public:
* Return string containing help. If the argument is specified, only return
* help for that argument.
*/
const char* GetHelp() { return this->Help.c_str(); }
const char* GetHelp(const char* arg);
char const* GetHelp() { return this->Help.c_str(); }
char const* GetHelp(char const* arg);
/**
* Get / Set the help line length. This length is used when generating the
......@@ -216,7 +219,7 @@ public:
* Get the executable name (argv0). This is only available when using
* Initialize with argc/argv.
*/
const char* GetArgv0();
char const* GetArgv0();
/**
* Get index of the last argument parsed. This is the last argument that was
......@@ -228,30 +231,30 @@ protected:
void GenerateHelp();
//! This is internal method that registers variable with argument
void AddArgument(const char* argument, ArgumentTypeEnum type,
VariableTypeEnum vtype, void* variable, const char* help);
void AddArgument(char const* argument, ArgumentTypeEnum type,
VariableTypeEnum vtype, void* variable, char const* help);
bool GetMatchedArguments(std::vector<std::string>* matches,
const std::string& arg);
std::string const& arg);
//! Populate individual variables
bool PopulateVariable(CommandLineArgumentsCallbackStructure* cs,
const char* value);
char const* value);
//! Populate individual variables of type ...
void PopulateVariable(bool* variable, const std::string& value);
void PopulateVariable(int* variable, const std::string& value);
void PopulateVariable(double* variable, const std::string& value);
void PopulateVariable(char** variable, const std::string& value);
void PopulateVariable(std::string* variable, const std::string& value);
void PopulateVariable(std::vector<bool>* variable, const std::string& value);
void PopulateVariable(std::vector<int>* variable, const std::string& value);
void PopulateVariable(bool* variable, std::string const& value);
void PopulateVariable(int* variable, std::string const& value);
void PopulateVariable(double* variable, std::string const& value);
void PopulateVariable(char** variable, std::string const& value);
void PopulateVariable(std::string* variable, std::string const& value);
void PopulateVariable(std::vector<bool>* variable, std::string const& value);
void PopulateVariable(std::vector<int>* variable, std::string const& value);
void PopulateVariable(std::vector<double>* variable,
const std::string& value);
std::string const& value);
void PopulateVariable(std::vector<char*>* variable,
const std::string& value);
std::string const& value);
void PopulateVariable(std::vector<std::string>* variable,
const std::string& value);
std::string const& value);
typedef CommandLineArgumentsInternal Internal;
Internal* Internals;
......
......@@ -7,110 +7,64 @@
namespace. When not building a kwsys source file these macros are
temporarily defined inside the headers that use them. */
#if defined(KWSYS_NAMESPACE)
#define kwsys_ns(x) @KWSYS_NAMESPACE@##x
#define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
#endif
/* Disable some warnings inside kwsys source files. */
#if defined(KWSYS_NAMESPACE)
#if defined(__BORLANDC__)
#pragma warn - 8027 /* function not inlined. */
#endif
#if defined(__INTEL_COMPILER)
#pragma warning(disable : 1572) /* floating-point equality test */
#endif
#if defined(__sgi) && !defined(__GNUC__)
#pragma set woff 3970 /* pointer to int conversion */
#pragma set woff 3968 /* 64 bit conversion */
#endif
# if defined(__INTEL_COMPILER)
# pragma warning(disable : 1572) /* floating-point equality test */
# endif
# if defined(__sgi) && !defined(__GNUC__)
# pragma set woff 3970 /* pointer to int conversion */
# pragma set woff 3968 /* 64 bit conversion */
# endif
#endif
/* Whether kwsys namespace is "kwsys". */
#define @KWSYS_NAMESPACE@_NAME_IS_KWSYS @KWSYS_NAME_IS_KWSYS@
/* Whether Large File Support is requested. */
#define @KWSYS_NAMESPACE@_LFS_REQUESTED @KWSYS_LFS_REQUESTED@
/* Whether Large File Support is available. */
#if @KWSYS_NAMESPACE@_LFS_REQUESTED
#define @KWSYS_NAMESPACE@_LFS_AVAILABLE @KWSYS_LFS_AVAILABLE@
#endif
/* Setup Large File Support if requested. */
#if @KWSYS_NAMESPACE@_LFS_REQUESTED
/* Since LFS is requested this header must be included before system
headers whether or not LFS is available. */
#if 0 && (defined(_SYS_TYPES_H) || defined(_SYS_TYPES_INCLUDED))
#error "@KWSYS_NAMESPACE@/Configure.h must be included before sys/types.h"
#endif
/* Enable the large file API if it is available. */
#if @KWSYS_NAMESPACE@_LFS_AVAILABLE && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINES)
#if !defined(_LARGEFILE_SOURCE) && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGEFILE_SOURCE)
#define _LARGEFILE_SOURCE
#endif
#if !defined(_LARGEFILE64_SOURCE) && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGEFILE64_SOURCE)
#define _LARGEFILE64_SOURCE
#endif
#if !defined(_LARGE_FILES) && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_LARGE_FILES)
#define _LARGE_FILES
#endif
#if !defined(_FILE_OFFSET_BITS) && \
!defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_FILE_OFFSET_BITS)
#define _FILE_OFFSET_BITS 64
#endif
#if 0 && (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS < 64)
#error "_FILE_OFFSET_BITS must be defined to at least 64"
#endif
#endif
#endif
/* Setup the export macro. */
#if @KWSYS_BUILD_SHARED@
#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(@KWSYS_NAMESPACE@_EXPORTS)
#define @KWSYS_NAMESPACE@_EXPORT __declspec(dllexport)
# if defined(_WIN32) || defined(__CYGWIN__)
# if defined(@KWSYS_NAMESPACE@_EXPORTS)
# define @KWSYS_NAMESPACE@_EXPORT __declspec(dllexport)
# else
# define @KWSYS_NAMESPACE@_EXPORT __declspec(dllimport)
# endif
# elif __GNUC__ >= 4
# define @KWSYS_NAMESPACE@_EXPORT __attribute__((visibility("default")))
# else
# define @KWSYS_NAMESPACE@_EXPORT
# endif
#else
#define @KWSYS_NAMESPACE@_EXPORT __declspec(dllimport)
#endif
#elif __GNUC__ >= 4
#define @KWSYS_NAMESPACE@_EXPORT __attribute__((visibility("default")))
#else
#define @KWSYS_NAMESPACE@_EXPORT
#endif
#else
#define @KWSYS_NAMESPACE@_EXPORT
# define @KWSYS_NAMESPACE@_EXPORT
#endif
/* Enable warnings that are off by default but are useful. */
#if !defined(@KWSYS_NAMESPACE@_NO_WARNING_ENABLE)
#if defined(_MSC_VER)
#pragma warning(default : 4263) /* no override, call convention differs */
#endif
# if defined(_MSC_VER)
# pragma warning(default : 4263) /* no override, call convention differs \
*/
# endif
#endif
/* Disable warnings that are on by default but occur in valid code. */
#if !defined(@KWSYS_NAMESPACE@_NO_WARNING_DISABLE)
#if defined(_MSC_VER)
#pragma warning(disable : 4097) /* typedef is synonym for class */
#pragma warning(disable : 4127) /* conditional expression is constant */
#pragma warning(disable : 4244) /* possible loss in conversion */
#pragma warning(disable : 4251) /* missing DLL-interface */
#pragma warning(disable : 4305) /* truncation from type1 to type2 */
#pragma warning(disable : 4309) /* truncation of constant value */
#pragma warning(disable : 4514) /* unreferenced inline function */
#pragma warning(disable : 4706) /* assignment in conditional expression */
#pragma warning(disable : 4710) /* function not inlined */
#pragma warning(disable : 4786) /* identifier truncated in debug info */
#endif
#if defined(__BORLANDC__) && !defined(__cplusplus)
/* Code has no effect; raised by winnt.h in C (not C++) when ignoring an
unused parameter using "(param)" syntax (i.e. no cast to void). */
#pragma warn - 8019
#endif
# if defined(_MSC_VER)
# pragma warning(disable : 4097) /* typedef is synonym for class */
# pragma warning(disable : 4127) /* conditional expression is constant */
# pragma warning(disable : 4244) /* possible loss in conversion */
# pragma warning(disable : 4251) /* missing DLL-interface */
# pragma warning(disable : 4305) /* truncation from type1 to type2 */
# pragma warning(disable : 4309) /* truncation of constant value */
# pragma warning(disable : 4514) /* unreferenced inline function */
# pragma warning(disable : 4706) /* assignment in conditional expression \
*/
# pragma warning(disable : 4710) /* function not inlined */
# pragma warning(disable : 4786) /* identifier truncated in debug info */
# endif
#endif
/* MSVC 6.0 in release mode will warn about code it produces with its
......@@ -118,10 +72,10 @@
configuration. Real warnings will be revealed by a debug build or
by other compilers. */
#if !defined(@KWSYS_NAMESPACE@_NO_WARNING_DISABLE_BOGUS)
#if defined(_MSC_VER) && (_MSC_VER < 1300) && defined(NDEBUG)
#pragma warning(disable : 4701) /* Variable may be used uninitialized. */
#pragma warning(disable : 4702) /* Unreachable code. */
#endif
# if defined(_MSC_VER) && (_MSC_VER < 1300) && defined(NDEBUG)
# pragma warning(disable : 4701) /* Variable may be used uninitialized. */
# pragma warning(disable : 4702) /* Unreachable code. */
# endif
#endif
#endif
......@@ -12,16 +12,49 @@
#define @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H \
@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@
#if defined(__SUNPRO_CC) && __SUNPRO_CC > 0x5130 && defined(__has_attribute)
# define @KWSYS_NAMESPACE@_has_cpp_attribute(x) __has_attribute(x)
#elif defined(__has_cpp_attribute)
# define @KWSYS_NAMESPACE@_has_cpp_attribute(x) __has_cpp_attribute(x)
#else
# define @KWSYS_NAMESPACE@_has_cpp_attribute(x) 0
#endif
#if __cplusplus >= 201103L
# define @KWSYS_NAMESPACE@_NULLPTR nullptr
#else
# define @KWSYS_NAMESPACE@_NULLPTR 0
#endif
#ifndef @KWSYS_NAMESPACE@_FALLTHROUGH
# if __cplusplus >= 201703L && \
@KWSYS_NAMESPACE@_has_cpp_attribute(fallthrough)
# define @KWSYS_NAMESPACE@_FALLTHROUGH [[fallthrough]]
# elif __cplusplus >= 201103L && \
@KWSYS_NAMESPACE@_has_cpp_attribute(gnu::fallthrough)
# define @KWSYS_NAMESPACE@_FALLTHROUGH [[gnu::fallthrough]]
# elif __cplusplus >= 201103L && \
@KWSYS_NAMESPACE@_has_cpp_attribute(clang::fallthrough)
# define @KWSYS_NAMESPACE@_FALLTHROUGH [[clang::fallthrough]]
# endif
#endif
#ifndef @KWSYS_NAMESPACE@_FALLTHROUGH
# define @KWSYS_NAMESPACE@_FALLTHROUGH static_cast<void>(0)
#endif
#undef @KWSYS_NAMESPACE@_has_cpp_attribute
/* If building a C++ file in kwsys itself, give the source file
access to the macros without a configured namespace. */
#if defined(KWSYS_NAMESPACE)
#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
#define kwsys @KWSYS_NAMESPACE@
#endif
#define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS
#define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING
#define KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H \
@KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H
# if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys @KWSYS_NAMESPACE@
# endif
# define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING
# define KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H \
@KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H
# define KWSYS_FALLTHROUGH @KWSYS_NAMESPACE@_FALLTHROUGH
#endif
#endif
......@@ -15,18 +15,17 @@
#include <string>
#if defined(_WIN32)
#include <windows.h>
#if __cplusplus >= 201103L
#include <system_error>
#endif
# include <windows.h>
# if __cplusplus >= 201103L
# include <system_error>
# endif
#endif
namespace @KWSYS_NAMESPACE@ {
#if defined(_WIN32)
template <class CharT, class Traits = std::char_traits<CharT> >
class @KWSYS_NAMESPACE@_EXPORT BasicConsoleBuf
: public std::basic_streambuf<CharT, Traits>
class BasicConsoleBuf : public std::basic_streambuf<CharT, Traits>
{
public:
typedef typename Traits::int_type int_type;
......@@ -35,19 +34,30 @@ public:
class Manager
{
public:
Manager(std::basic_ios<CharT, Traits>& ios, const bool err = false)
Manager(std::basic_ios<CharT, Traits>& ios, bool const err = false)
: m_consolebuf(0)
{
m_ios = &ios;
try {
m_consolebuf = new BasicConsoleBuf<CharT, Traits>(err);
m_streambuf = m_ios->rdbuf(m_consolebuf);
} catch (const std::runtime_error& ex) {
} catch (std::runtime_error const& ex) {
std::cerr << "Failed to create ConsoleBuf!" << std::endl
<< ex.what() << std::endl;
};
}
BasicConsoleBuf<CharT, Traits>* GetConsoleBuf() { return m_consolebuf; }
void SetUTF8Pipes()
{
if (m_consolebuf) {
m_consolebuf->input_pipe_codepage = CP_UTF8;
m_consolebuf->output_pipe_codepage = CP_UTF8;
m_consolebuf->activateCodepageChange();
}
}
~Manager()
{
if (m_consolebuf) {
......@@ -62,7 +72,7 @@ public:
BasicConsoleBuf<CharT, Traits>* m_consolebuf;
};
BasicConsoleBuf(const bool err = false)
BasicConsoleBuf(bool const err = false)
: flush_on_newline(true)
, input_pipe_codepage(0)
, output_pipe_codepage(0)
......@@ -101,12 +111,12 @@ protected:
success = false;
}
if (m_hOutput && !m_obuffer.empty()) {
const std::wstring wbuffer = getBuffer(m_obuffer);
std::wstring const wbuffer = getBuffer(m_obuffer);
if (m_isConsoleOutput) {
DWORD charsWritten;
success =
::WriteConsoleW(m_hOutput, wbuffer.c_str(), (DWORD)wbuffer.size(),
&charsWritten, NULL) == 0
&charsWritten, nullptr) == 0
? false
: true;
} else {
......@@ -114,8 +124,9 @@ protected:
std::string buffer;
success = encodeOutputBuffer(wbuffer, buffer);
if (success) {
success = ::WriteFile(m_hOutput, buffer.c_str(),
(DWORD)buffer.size(), &bytesWritten, NULL) == 0
success =
::WriteFile(m_hOutput, buffer.c_str(), (DWORD)buffer.size(),
&bytesWritten, nullptr) == 0
? false
: true;
}
......@@ -136,42 +147,47 @@ protected:
return Traits::eof();
}
if (m_isConsoleInput) {
wchar_t wbuffer[128];
// ReadConsole doesn't tell if there's more input available
// don't support reading more characters than this
wchar_t wbuffer[8192];
DWORD charsRead;
if (::ReadConsoleW(m_hInput, wbuffer,
(sizeof(wbuffer) / sizeof(wbuffer[0])) - 1,
&charsRead, NULL) == 0 ||
if (ReadConsoleW(m_hInput, wbuffer,
(sizeof(wbuffer) / sizeof(wbuffer[0])), &charsRead,
nullptr) == 0 ||
charsRead == 0) {
_setg(true);
return Traits::eof();
}
wbuffer[charsRead] = L'\0';
setBuffer(wbuffer, m_ibuffer);
setBuffer(std::wstring(wbuffer, charsRead), m_ibuffer);
} else {
std::wstring totalBuffer;
std::wstring wbuffer;
char buffer[128];
std::string strbuffer;
DWORD bytesRead;
while (::ReadFile(m_hInput, buffer,
(sizeof(buffer) / sizeof(buffer[0])) - 1, &bytesRead,
NULL) == 0) {
if (::GetLastError() == ERROR_MORE_DATA) {
buffer[bytesRead] = '\0';
if (decodeInputBuffer(buffer, wbuffer)) {
totalBuffer += wbuffer;
continue;
}
LARGE_INTEGER size;
if (GetFileSizeEx(m_hInput, &size) == 0) {
_setg(true);
return Traits::eof();
}
char* buffer = new char[size.LowPart];
while (ReadFile(m_hInput, buffer, size.LowPart, &bytesRead, nullptr) ==
0) {
if (GetLastError() == ERROR_MORE_DATA) {
strbuffer += std::string(buffer, bytesRead);
continue;
}
_setg(true);
delete[] buffer;
return Traits::eof();
}
buffer[bytesRead] = '\0';
if (!decodeInputBuffer(buffer, wbuffer)) {
if (bytesRead > 0) {
strbuffer += std::string(buffer, bytesRead);
}
delete[] buffer;
if (!decodeInputBuffer(strbuffer, wbuffer)) {
_setg(true);
return Traits::eof();
}
totalBuffer += wbuffer;
setBuffer(totalBuffer, m_ibuffer);
setBuffer(wbuffer, m_ibuffer);
}
_setg();
}
......@@ -216,12 +232,12 @@ private:
(!input && m_hOutput == INVALID_HANDLE_VALUE)) {
std::string errmsg =
"GetStdHandle(" + handleName + ") returned INVALID_HANDLE_VALUE";
#if __cplusplus >= 201103L
# if __cplusplus >= 201103L
throw std::system_error(::GetLastError(), std::system_category(),
errmsg);
#else
# else
throw std::runtime_error(errmsg);
#endif
# endif
}
}
UINT getConsolesCodepage()
......@@ -249,6 +265,7 @@ private:
if (m_isConsoleInput) {
break;
}
@KWSYS_NAMESPACE@_FALLTHROUGH;
case FILE_TYPE_PIPE:
m_activeInputCodepage = input_pipe_codepage;
break;
......@@ -275,6 +292,7 @@ private:
if (m_isConsoleOutput) {
break;
}
@KWSYS_NAMESPACE@_FALLTHROUGH;
case FILE_TYPE_PIPE:
m_activeOutputCodepage = output_pipe_codepage;
break;
......@@ -302,55 +320,68 @@ private:
this->setp((char_type*)m_obuffer.data(),
(char_type*)m_obuffer.data() + m_obuffer.size());
}
bool encodeOutputBuffer(const std::wstring wbuffer, std::string& buffer)
bool encodeOutputBuffer(std::wstring const wbuffer, std::string& buffer)
{
const int length =
if (wbuffer.size() == 0) {
buffer = std::string();
return true;
}
int const length =
WideCharToMultiByte(m_activeOutputCodepage, 0, wbuffer.c_str(),
(int)wbuffer.size(), NULL, 0, NULL, NULL);
char* buf = new char[length + 1];
const bool success =
(int)wbuffer.size(), nullptr, 0, nullptr, nullptr);
char* buf = new char[length];
bool const success =
WideCharToMultiByte(m_activeOutputCodepage, 0, wbuffer.c_str(),
(int)wbuffer.size(), buf, length, NULL, NULL) > 0
(int)wbuffer.size(), buf, length, nullptr,
nullptr) > 0
? true
: false;
buf[length] = '\0';
buffer = buf;
buffer = std::string(buf, length);
delete[] buf;
return success;
}
bool decodeInputBuffer(const char* buffer, std::wstring& wbuffer)
bool decodeInputBuffer(std::string const buffer, std::wstring& wbuffer)
{
size_t length = buffer.length();
if (length == 0) {
wbuffer = std::wstring();
return true;
}
int actualCodepage = m_activeInputCodepage;
const char BOM_UTF8[] = { char(0xEF), char(0xBB), char(0xBF) };
if (std::memcmp(buffer, BOM_UTF8, sizeof(BOM_UTF8)) == 0) {
char const BOM_UTF8[] = { char(0xEF), char(0xBB), char(0xBF) };
char const* data = buffer.data();
size_t const BOMsize = sizeof(BOM_UTF8);
if (length >= BOMsize && std::memcmp(data, BOM_UTF8, BOMsize) == 0) {
// PowerShell uses UTF-8 with BOM for pipes
actualCodepage = CP_UTF8;
buffer += sizeof(BOM_UTF8);
data += BOMsize;
length -= BOMsize;
}
const int wlength =
MultiByteToWideChar(actualCodepage, 0, buffer, -1, NULL, 0);
size_t const wlength = static_cast<size_t>(MultiByteToWideChar(
actualCodepage, 0, data, static_cast<int>(length), nullptr, 0));
wchar_t* wbuf = new wchar_t[wlength];
const bool success =
MultiByteToWideChar(actualCodepage, 0, buffer, -1, wbuf, wlength) > 0
bool const success =
MultiByteToWideChar(actualCodepage, 0, data, static_cast<int>(length),
wbuf, static_cast<int>(wlength)) > 0
? true
: false;
wbuffer = wbuf;
wbuffer = std::wstring(wbuf, wlength);
delete[] wbuf;
return success;
}
std::wstring getBuffer(const std::basic_string<char> buffer)
std::wstring getBuffer(std::basic_string<char> const buffer)
{
return Encoding::ToWide(buffer);
}
std::wstring getBuffer(const std::basic_string<wchar_t> buffer)
std::wstring getBuffer(std::basic_string<wchar_t> const buffer)
{
return buffer;
}
void setBuffer(const std::wstring wbuffer, std::basic_string<char>& target)
void setBuffer(std::wstring const wbuffer, std::basic_string<char>& target)
{
target = Encoding::ToNarrow(wbuffer);
}
void setBuffer(const std::wstring wbuffer,
void setBuffer(std::wstring const wbuffer,
std::basic_string<wchar_t>& target)
{
target = wbuffer;
......
......@@ -7,64 +7,139 @@
#include KWSYS_HEADER(Encoding.hxx)
#include KWSYS_HEADER(SystemTools.hxx)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
#include "Configure.hxx.in"
#include "Directory.hxx.in"
#include "Encoding.hxx.in"
# include "Configure.hxx.in"
# include "Directory.hxx.in"
# include "Encoding.hxx.in"
#endif
#include <string>
#include <utility>
#include <vector>
#if defined(_WIN32) && !defined(__CYGWIN__)
# include <windows.h>
# include <ctype.h>
# include <fcntl.h>
# include <io.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/stat.h>
# include <sys/types.h>
#endif
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
class DirectoryInternals
{
public:
struct FileData
{
std::string Name;
#if defined(_WIN32) && !defined(__CYGWIN__)
WIN32_FIND_DATAW FindData;
#endif
FileData(std::string name
#if defined(_WIN32) && !defined(__CYGWIN__)
,
WIN32_FIND_DATAW data
#endif
)
: Name(std::move(name))
#if defined(_WIN32) && !defined(__CYGWIN__)
, FindData(std::move(data))
#endif
{
}
};
// Array of Files
std::vector<std::string> Files;
std::vector<FileData> Files;
// Path to Open'ed directory
std::string Path;
};
//----------------------------------------------------------------------------
Directory::Directory()
{
this->Internal = new DirectoryInternals;
}
//----------------------------------------------------------------------------
Directory::Directory(Directory&& other)
{
this->Internal = other.Internal;
other.Internal = nullptr;
}
Directory& Directory::operator=(Directory&& other)
{
std::swap(this->Internal, other.Internal);
return *this;
}
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
char const* Directory::GetFile(unsigned long dindex) const
{
if (dindex >= this->Internal->Files.size()) {
return 0;
return this->Internal->Files[dindex].Name.c_str();
}
std::string const& Directory::GetFileName(std::size_t i) const
{
return this->Internal->Files[i].Name;
}
std::string Directory::GetFilePath(std::size_t i) const
{
std::string abs = this->Internal->Path;
if (!abs.empty() && abs.back() != '/') {
abs += '/';
}
return this->Internal->Files[dindex].c_str();
abs += this->Internal->Files[i].Name;
return abs;
}
bool Directory::FileIsDirectory(std::size_t i) const
{
#if defined(_WIN32) && !defined(__CYGWIN__)
auto const& data = this->Internal->Files[i].FindData;
return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
#else
std::string const& path = this->GetFilePath(i);
return kwsys::SystemTools::FileIsDirectory(path);
#endif
}
//----------------------------------------------------------------------------
const char* Directory::GetPath() const
bool Directory::FileIsSymlink(std::size_t i) const
{
std::string const& path = this->GetFilePath(i);
#if defined(_WIN32) && !defined(__CYGWIN__)
auto const& data = this->Internal->Files[i].FindData;
return kwsys::SystemTools::FileIsSymlinkWithAttr(
Encoding::ToWindowsExtendedPath(path), data.dwFileAttributes);
#else
return kwsys::SystemTools::FileIsSymlink(path);
#endif
}
char const* Directory::GetPath() const
{
return this->Internal->Path.c_str();
}
//----------------------------------------------------------------------------
void Directory::Clear()
{
this->Internal->Path.resize(0);
......@@ -76,96 +151,99 @@ void Directory::Clear()
// First Windows platforms
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#include <ctype.h>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
// Wide function names can vary depending on compiler:
#ifdef __BORLANDC__
#define _wfindfirst_func __wfindfirst
#define _wfindnext_func __wfindnext
#else
#define _wfindfirst_func _wfindfirst
#define _wfindnext_func _wfindnext
#endif
namespace KWSYS_NAMESPACE {
bool Directory::Load(const std::string& name)
Status Directory::Load(std::string const& name, std::string* errorMessage)
{
this->Clear();
#if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
// Older Visual C++ and Embarcadero compilers.
long srchHandle;
#else // Newer Visual C++
intptr_t srchHandle;
#endif
HANDLE srchHandle;
char* buf;
size_t bufLength;
size_t n = name.size();
if (*name.rbegin() == '/' || *name.rbegin() == '\\') {
buf = new char[n + 1 + 1];
sprintf(buf, "%s*", name.c_str());
if (name.back() == '/' || name.back() == '\\') {
bufLength = n + 1 + 1;
buf = new char[bufLength];
snprintf(buf, bufLength, "%s*", name.c_str());
} else {
// Make sure the slashes in the wildcard suffix are consistent with the
// rest of the path
buf = new char[n + 2 + 1];
if (name.find('\\') != name.npos) {
sprintf(buf, "%s\\*", name.c_str());
bufLength = n + 2 + 1;
buf = new char[bufLength];
if (name.find('\\') != std::string::npos) {
snprintf(buf, bufLength, "%s\\*", name.c_str());
} else {
sprintf(buf, "%s/*", name.c_str());
snprintf(buf, bufLength, "%s/*", name.c_str());
}
}
struct _wfinddata_t data; // data of current file
WIN32_FIND_DATAW data; // data of current file
// Now put them into the file array
srchHandle =
_wfindfirst_func((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
FindFirstFileW(Encoding::ToWindowsExtendedPath(buf).c_str(), &data);
delete[] buf;
if (srchHandle == -1) {
return 0;
if (srchHandle == INVALID_HANDLE_VALUE) {
Status status = Status::POSIX_errno();
if (errorMessage) {
*errorMessage = status.GetString();
}
return status;
}
// Loop through names
do {
this->Internal->Files.push_back(Encoding::ToNarrow(data.name));
} while (_wfindnext_func(srchHandle, &data) != -1);
this->Internal->Files.emplace_back(Encoding::ToNarrow(data.cFileName),
data);
} while (FindNextFileW(srchHandle, &data));
this->Internal->Path = name;
return _findclose(srchHandle) != -1;
if (!FindClose(srchHandle)) {
Status status = Status::POSIX_errno();
if (errorMessage) {
*errorMessage = status.GetString();
}
return status;
}
return Status::Success();
}
unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
unsigned long Directory::GetNumberOfFilesInDirectory(std::string const& name,
std::string* errorMessage)
{
#if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
// Older Visual C++ and Embarcadero compilers.
long srchHandle;
#else // Newer Visual C++
intptr_t srchHandle;
#endif
HANDLE srchHandle;
char* buf;
size_t bufLength;
size_t n = name.size();
if (*name.rbegin() == '/') {
if (name.back() == '/') {
bufLength = n + 1 + 1;
buf = new char[n + 1 + 1];
sprintf(buf, "%s*", name.c_str());
snprintf(buf, bufLength, "%s*", name.c_str());
} else {
bufLength = n + 2 + 1;
buf = new char[n + 2 + 1];
sprintf(buf, "%s/*", name.c_str());
snprintf(buf, bufLength, "%s/*", name.c_str());
}
struct _wfinddata_t data; // data of current file
WIN32_FIND_DATAW data; // data of current file
// Now put them into the file array
srchHandle =
_wfindfirst_func((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
srchHandle = FindFirstFileW(Encoding::ToWide(buf).c_str(), &data);
delete[] buf;
if (srchHandle == -1) {
if (srchHandle == INVALID_HANDLE_VALUE) {
if (errorMessage) {
if (unsigned int errorId = GetLastError()) {
LPSTR message = nullptr;
DWORD size = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, errorId, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&message, 0, nullptr);
*errorMessage = std::string(message, size);
LocalFree(message);
} else {
*errorMessage = "Unknown error.";
}
}
return 0;
}
......@@ -173,8 +251,8 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
unsigned long count = 0;
do {
count++;
} while (_wfindnext_func(srchHandle, &data) != -1);
_findclose(srchHandle);
} while (FindNextFileW(srchHandle, &data));
FindClose(srchHandle);
return count;
}
......@@ -184,49 +262,68 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
// Now the POSIX style directory access
#include <sys/types.h>
# include <sys/types.h>
#include <dirent.h>
# include <dirent.h>
# include <errno.h>
# include <string.h>
// PGI with glibc has trouble with dirent and large file support:
// http://www.pgroup.com/userforum/viewtopic.php?
// https://www.pgroup.com/userforum/viewtopic.php?
// p=1992&sid=f16167f51964f1a68fe5041b8eb213b6
// Work around the problem by mapping dirent the same way as readdir.
#if defined(__PGI) && defined(__GLIBC__)
#define kwsys_dirent_readdir dirent
#define kwsys_dirent_readdir64 dirent64
#define kwsys_dirent kwsys_dirent_lookup(readdir)
#define kwsys_dirent_lookup(x) kwsys_dirent_lookup_delay(x)
#define kwsys_dirent_lookup_delay(x) kwsys_dirent_##x
#else
#define kwsys_dirent dirent
#endif
# if defined(__PGI) && defined(__GLIBC__)
# define kwsys_dirent_readdir dirent
# define kwsys_dirent_readdir64 dirent64
# define kwsys_dirent kwsys_dirent_lookup(readdir)
# define kwsys_dirent_lookup(x) kwsys_dirent_lookup_delay(x)
# define kwsys_dirent_lookup_delay(x) kwsys_dirent_##x
# else
# define kwsys_dirent dirent
# endif
namespace KWSYS_NAMESPACE {
bool Directory::Load(const std::string& name)
Status Directory::Load(std::string const& name, std::string* errorMessage)
{
this->Clear();
errno = 0;
DIR* dir = opendir(name.c_str());
if (!dir) {
return 0;
if (errorMessage) {
*errorMessage = std::string(strerror(errno));
}
return Status::POSIX_errno();
}
errno = 0;
for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) {
this->Internal->Files.push_back(d->d_name);
this->Internal->Files.emplace_back(d->d_name);
}
if (errno != 0) {
if (errorMessage) {
*errorMessage = std::string(strerror(errno));
}
return Status::POSIX_errno();
}
this->Internal->Path = name;
closedir(dir);
return 1;
return Status::Success();
}
unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
unsigned long Directory::GetNumberOfFilesInDirectory(std::string const& name,
std::string* errorMessage)
{
errno = 0;
DIR* dir = opendir(name.c_str());
if (!dir) {
if (errorMessage) {
*errorMessage = std::string(strerror(errno));
}
return 0;
}
......@@ -234,6 +331,13 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) {
count++;
}
if (errno != 0) {
if (errorMessage) {
*errorMessage = std::string(strerror(errno));
}
return false;
}
closedir(dir);
return count;
}
......
......@@ -4,7 +4,9 @@
#define @KWSYS_NAMESPACE@_Directory_hxx
#include <@KWSYS_NAMESPACE@/Configure.h>
#include <@KWSYS_NAMESPACE@/Status.hxx>
#include <cstddef>
#include <string>
namespace @KWSYS_NAMESPACE@ {
......@@ -23,14 +25,18 @@ class @KWSYS_NAMESPACE@_EXPORT Directory
{
public:
Directory();
Directory(Directory&& other);
Directory(Directory const&) = delete;
Directory& operator=(Directory const&) = delete;
Directory& operator=(Directory&& other);
bool operator==(Directory const&) = delete;
~Directory();
/**
* Load the specified directory and load the names of the files
* in that directory. 0 is returned if the directory can not be
* opened, 1 if it is opened.
* in that directory.
*/
bool Load(const std::string&);
Status Load(std::string const&, std::string* errorMessage = nullptr);
/**
* Return the number of files in the current directory.
......@@ -41,17 +47,38 @@ public:
* Return the number of files in the specified directory.
* A higher performance static method.
*/
static unsigned long GetNumberOfFilesInDirectory(const std::string&);
static unsigned long GetNumberOfFilesInDirectory(
std::string const&, std::string* errorMessage = nullptr);
/**
* Return the file at the given index, the indexing is 0 based
*/
const char* GetFile(unsigned long) const;
char const* GetFile(unsigned long) const;
/**
* Return the name of the file at the given 0-based index.
*/
std::string const& GetFileName(std::size_t i) const;
/**
* Return the absolute path to the file at the given 0-based index.
*/
std::string GetFilePath(std::size_t i) const;
/**
* Return whether the file at the given 0-based index is a directory.
*/
bool FileIsDirectory(std::size_t i) const;
/**
* Return whether the file at the given 0-based index is a symlink.
*/
bool FileIsSymlink(std::size_t i) const;
/**
* Return the path to Open'ed directory
*/
const char* GetPath() const;
char const* GetPath() const;
/**
* Clear the internal structure. Used internally at beginning of Load(...)
......@@ -62,10 +89,7 @@ public:
private:
// Private implementation details.
DirectoryInternals* Internal;
Directory(const Directory&); // Not implemented.
void operator=(const Directory&); // Not implemented.
}; // End Class: Directory
}; // End Class: Directory
} // namespace @KWSYS_NAMESPACE@
......
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#if defined(_WIN32)
# define NOMINMAX // hide min,max to not conflict with <limits>
#endif
#include "kwsysPrivate.h"
#include KWSYS_HEADER(DynamicLoader.hxx)
#include KWSYS_HEADER(Configure.hxx)
#include KWSYS_HEADER(Encoding.hxx)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
#include "Configure.hxx.in"
#include "DynamicLoader.hxx.in"
# include "Configure.hxx.in"
# include "DynamicLoader.hxx.in"
#endif
// This file is actually 3 different implementations.
// 1. HP machines which uses shl_load
// 2. Mac OS X 10.2.x and earlier which uses NSLinkModule
// 3. Windows which uses LoadLibrary
// 4. Most unix systems (including Mac OS X 10.3 and later) which use dlopen
// (default) Each part of the ifdef contains a complete implementation for
// This file actually contains several different implementations:
// * NOOP for environments without dynamic libs
// * HP machines which uses shl_load
// * Mac OS X 10.2.x and earlier which uses NSLinkModule
// * Windows which uses LoadLibrary
// * BeOS / Haiku
// * FreeMiNT for Atari
// * Default implementation for *NIX systems (including Mac OS X 10.3 and
// later) which use dlopen
//
// Each part of the ifdef contains a complete implementation for
// the static methods of DynamicLoader.
// ---------------------------------------------------------------
// 1. Implementation for HPUX machines
#ifdef __hpux
#include <dl.h>
#include <errno.h>
#define DYNAMICLOADER_DEFINED 1
#define CHECK_OPEN_FLAGS(var, supported, ret) \
do { \
/* Check for unknown flags. */ \
if ((var & AllOpenFlags) != var) { \
return ret; \
} \
\
/* Check for unsupported flags. */ \
if ((var & (supported)) != var) { \
return ret; \
} \
} while (0)
namespace KWSYS_NAMESPACE {
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
std::string const& libname)
{
return DynamicLoader::OpenLibrary(libname, 0);
}
}
#if !KWSYS_SUPPORTS_SHARED_LIBS
// Implementation for environments without dynamic libs
# include <string.h> // for strerror()
namespace KWSYS_NAMESPACE {
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
std::string const& libname, int flags)
{
return 0;
}
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
if (!lib) {
return 0;
}
return 1;
}
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, std::string const& sym)
{
return 0;
}
char const* DynamicLoader::LastError()
{
return "General error";
}
} // 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)
std::string const& libname, int flags)
{
CHECK_OPEN_FLAGS(flags, 0, 0);
return shl_load(libname.c_str(), BIND_DEFERRED | DYNAMIC_PATH, 0L);
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
if (!lib) {
......@@ -45,9 +109,8 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return !shl_unload(lib);
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
DynamicLoader::LibraryHandle lib, std::string const& sym)
{
void* addr;
int status;
......@@ -64,7 +127,7 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
}
const char* DynamicLoader::LastError()
char const* DynamicLoader::LastError()
{
// TODO: Need implementation with errno/strerror
/* If successful, shl_findsym returns an integer (int) value zero. If
......@@ -88,22 +151,18 @@ const char* DynamicLoader::LastError()
} // namespace KWSYS_NAMESPACE
#endif //__hpux
// ---------------------------------------------------------------
// 2. Implementation for Mac OS X 10.2.x and earlier
#ifdef __APPLE__
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
#include <mach-o/dyld.h>
#include <string.h> // for strlen
#define DYNAMICLOADER_DEFINED 1
#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)
std::string const& libname, int flags)
{
CHECK_OPEN_FLAGS(flags, 0, 0);
NSObjectFileImageReturnCode rc;
NSObjectFileImage image = 0;
......@@ -112,14 +171,13 @@ DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
if (rc != NSObjectFileImageSuccess) {
return 0;
}
NSModule handle =
NSLinkModule(image, libname.c_str(), NSLINKMODULE_OPTION_BINDNOW |
NSLINKMODULE_OPTION_RETURN_ON_ERROR);
NSModule handle = NSLinkModule(image, libname.c_str(),
NSLINKMODULE_OPTION_BINDNOW |
NSLINKMODULE_OPTION_RETURN_ON_ERROR);
NSDestroyObjectFileImage(image);
return handle;
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
// NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED
......@@ -131,85 +189,63 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return success;
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
DynamicLoader::LibraryHandle lib, std::string const& sym)
{
void* result = 0;
// Need to prepend symbols with '_' on Apple-gcc compilers
size_t len = sym.size();
char* rsym = new char[len + 1 + 1];
strcpy(rsym, "_");
strcat(rsym + 1, sym.c_str());
std::string rsym = '_' + sym;
NSSymbol symbol = NSLookupSymbolInModule(lib, rsym);
NSSymbol symbol = NSLookupSymbolInModule(lib, rsym.c_str());
if (symbol) {
result = NSAddressOfSymbol(symbol);
}
delete[] rsym;
// Hack to cast pointer-to-data to pointer-to-function.
return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
char const* DynamicLoader::LastError()
{
return 0;
}
} // namespace KWSYS_NAMESPACE
#endif // MAC_OS_X_VERSION_MAX_ALLOWED < 1030
#endif // __APPLE__
#elif defined(_WIN32) && !defined(__CYGWIN__)
// Implementation for Windows win32 code but not cygwin
# include <windows.h>
// ---------------------------------------------------------------
// 3. Implementation for Windows win32 code but not cygwin
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#define DYNAMICLOADER_DEFINED 1
# include <stdio.h>
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
std::string const& libname, int flags)
{
DynamicLoader::LibraryHandle lh;
int length = MultiByteToWideChar(CP_UTF8, 0, libname.c_str(), -1, NULL, 0);
wchar_t* wchars = new wchar_t[length + 1];
wchars[0] = '\0';
MultiByteToWideChar(CP_UTF8, 0, libname.c_str(), -1, wchars, length);
lh = LoadLibraryW(wchars);
delete[] wchars;
return lh;
CHECK_OPEN_FLAGS(flags, SearchBesideLibrary, nullptr);
DWORD llFlags = 0;
if (flags & SearchBesideLibrary) {
llFlags |= LOAD_WITH_ALTERED_SEARCH_PATH;
}
return LoadLibraryExW(Encoding::ToWindowsExtendedPath(libname).c_str(),
nullptr, llFlags);
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
return (int)FreeLibrary(lib);
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
DynamicLoader::LibraryHandle lib, std::string const& sym)
{
// TODO: The calling convention affects the name of the symbol. We
// should have a tool to help get the symbol with the desired
// calling convention. Currently we assume cdecl.
//
// Borland:
// __cdecl = "_func" (default)
// __fastcall = "@_func"
// __stdcall = "func"
//
// Watcom:
// __cdecl = "_func"
// __fastcall = "@_func@X"
// __stdcall = "_func@X"
// __watcall = "func_" (default)
//
// MSVC:
// __cdecl = "func" (default)
// __fastcall = "@_func@X"
......@@ -218,72 +254,64 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
// Note that the "@X" part of the name above is the total size (in
// bytes) of the arguments on the stack.
void* result;
#if defined(__BORLANDC__) || defined(__WATCOMC__)
// Need to prepend symbols with '_'
size_t len = sym.size();
char* rsym = new char[len + 1 + 1];
strcpy(rsym, "_");
strcat(rsym, sym.c_str());
#else
const char* rsym = sym.c_str();
#endif
char const* rsym = sym.c_str();
result = (void*)GetProcAddress(lib, rsym);
#if defined(__BORLANDC__) || defined(__WATCOMC__)
delete[] rsym;
#endif
// Hack to cast pointer-to-data to pointer-to-function.
#ifdef __WATCOMC__
return *(DynamicLoader::SymbolPointer*)(&result);
#else
return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
#endif
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
{
LPVOID lpMsgBuf = NULL;
# define DYNLOAD_ERROR_BUFFER_SIZE 1024
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR)&lpMsgBuf, 0, NULL);
char const* DynamicLoader::LastError()
{
wchar_t lpMsgBuf[DYNLOAD_ERROR_BUFFER_SIZE + 1];
DWORD error = GetLastError();
DWORD length = FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
lpMsgBuf, DYNLOAD_ERROR_BUFFER_SIZE, nullptr);
static char str[DYNLOAD_ERROR_BUFFER_SIZE + 1];
if (length < 1) {
/* FormatMessage failed. Use a default message. */
snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE,
"DynamicLoader encountered error 0x%lX. "
"FormatMessage failed with error 0x%lX",
error, GetLastError());
return str;
}
if (!lpMsgBuf) {
return NULL;
if (!WideCharToMultiByte(CP_UTF8, 0, lpMsgBuf, -1, str,
DYNLOAD_ERROR_BUFFER_SIZE, nullptr, nullptr)) {
/* WideCharToMultiByte failed. Use a default message. */
snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE,
"DynamicLoader encountered error 0x%lX. "
"WideCharToMultiByte failed with error 0x%lX",
error, GetLastError());
}
static char* str = 0;
delete[] str;
str = strcpy(new char[strlen((char*)lpMsgBuf) + 1], (char*)lpMsgBuf);
// Free the buffer.
LocalFree(lpMsgBuf);
return str;
}
} // namespace KWSYS_NAMESPACE
#endif //_WIN32
// ---------------------------------------------------------------
// 4. Implementation for BeOS
#if defined __BEOS__
#elif defined(__BEOS__)
// Implementation for BeOS / Haiku
# include <string.h> // for strerror()
#include <string.h> // for strerror()
#include <be/kernel/image.h>
#include <be/support/Errors.h>
#define DYNAMICLOADER_DEFINED 1
# include <be/kernel/image.h>
# include <be/support/Errors.h>
namespace KWSYS_NAMESPACE {
static image_id last_dynamic_err = B_OK;
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
std::string const& libname, int flags)
{
CHECK_OPEN_FLAGS(flags, 0, 0);
// image_id's are integers, errors are negative. Add one just in case we
// get a valid image_id of zero (is that even possible?).
image_id rc = load_add_on(libname.c_str());
......@@ -295,7 +323,6 @@ DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
return rc + 1;
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
if (!lib) {
......@@ -313,9 +340,8 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return 1;
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
DynamicLoader::LibraryHandle lib, std::string const& sym)
{
// Hack to cast pointer-to-data to pointer-to-function.
union
......@@ -324,7 +350,7 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::SymbolPointer psym;
} result;
result.psym = NULL;
result.psym = nullptr;
if (!lib) {
last_dynamic_err = B_BAD_VALUE;
......@@ -336,81 +362,36 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
get_image_symbol(lib - 1, sym.c_str(), B_SYMBOL_TYPE_ANY, &result.pvoid);
if (rc != B_OK) {
last_dynamic_err = rc;
result.psym = NULL;
result.psym = nullptr;
}
}
return result.psym;
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
char const* DynamicLoader::LastError()
{
const char* retval = strerror(last_dynamic_err);
char const* retval = strerror(last_dynamic_err);
last_dynamic_err = B_OK;
return retval;
}
} // namespace KWSYS_NAMESPACE
#endif
// ---------------------------------------------------------------
// 5. Implementation for systems without dynamic libs
// __gnu_blrts__ is IBM BlueGene/L
// __LIBCATAMOUNT__ is defined on Catamount on Cray compute nodes
#if defined(__gnu_blrts__) || defined(__LIBCATAMOUNT__) || \
defined(__CRAYXT_COMPUTE_LINUX_TARGET)
#include <string.h> // for strerror()
#define DYNAMICLOADER_DEFINED 1
#elif defined(__MINT__)
// Implementation for FreeMiNT on Atari
# define _GNU_SOURCE /* for program_invocation_name */
# include <dld.h>
# include <errno.h>
# include <malloc.h>
# include <string.h>
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
{
return 0;
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
std::string const& libname, int flags)
{
if (!lib) {
return 0;
}
return 1;
}
CHECK_OPEN_FLAGS(flags, 0, nullptr);
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
{
return 0;
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
{
return "General error";
}
} // namespace KWSYS_NAMESPACE
#endif
#ifdef __MINT__
#define DYNAMICLOADER_DEFINED 1
#define _GNU_SOURCE /* for program_invocation_name */
#include <dld.h>
#include <errno.h>
#include <malloc.h>
#include <string.h>
namespace KWSYS_NAMESPACE {
//----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
const std::string& libname)
{
char* name = (char*)calloc(1, libname.size() + 1);
dld_init(program_invocation_name);
strncpy(name, libname.c_str(), libname.size());
......@@ -418,7 +399,6 @@ DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
return (void*)name;
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
dld_unlink_by_file((char*)lib, 0);
......@@ -426,9 +406,8 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return 0;
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
DynamicLoader::LibraryHandle lib, std::string const& sym)
{
// Hack to cast pointer-to-data to pointer-to-function.
union
......@@ -440,33 +419,33 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
return result.psym;
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
char const* DynamicLoader::LastError()
{
return dld_strerror(dld_errno);
}
} // namespace KWSYS_NAMESPACE
#endif
// ---------------------------------------------------------------
// 6. Implementation for default UNIX machines.
// if nothing has been defined then use this
#ifndef DYNAMICLOADER_DEFINED
#define DYNAMICLOADER_DEFINED 1
// Setup for most unix machines
#include <dlfcn.h>
#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)
std::string const& libname, int flags)
{
return dlopen(libname.c_str(), RTLD_LAZY);
CHECK_OPEN_FLAGS(flags, RTLDGlobal, nullptr);
int llFlags = RTLD_LAZY;
if (flags & RTLDGlobal) {
llFlags |= RTLD_GLOBAL;
}
return dlopen(libname.c_str(), llFlags);
}
//----------------------------------------------------------------------------
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
if (lib) {
......@@ -477,9 +456,8 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
return 0;
}
//----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const std::string& sym)
DynamicLoader::LibraryHandle lib, std::string const& sym)
{
// Hack to cast pointer-to-data to pointer-to-function.
union
......@@ -491,12 +469,10 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
return result.psym;
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LastError()
char const* DynamicLoader::LastError()
{
return dlerror();
}
} // namespace KWSYS_NAMESPACE
#endif
......@@ -8,16 +8,16 @@
#include <string>
#if defined(__hpux)
#include <dl.h>
# include <dl.h>
#elif defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
# include <windows.h>
#elif defined(__APPLE__)
#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
#include <mach-o/dyld.h>
#endif
# include <AvailabilityMacros.h>
# if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
# include <mach-o/dyld.h>
# endif
#elif defined(__BEOS__)
#include <be/kernel/image.h>
# include <be/kernel/image.h>
#endif
namespace @KWSYS_NAMESPACE@ {
......@@ -35,7 +35,7 @@ namespace @KWSYS_NAMESPACE@ {
* or absolute) pathname. Otherwise, the dynamic linker searches for the
* library as follows : see ld.so(8) for further details):
* Whereas this distinction does not exist on Win32. Therefore ideally you
* should be doing full path to garantee to have a consistent way of dealing
* should be doing full path to guarantee to have a consistent way of dealing
* with dynamic loading of shared library.
*
* \warning the Cygwin implementation do not use the Win32 HMODULE. Put extra
......@@ -52,11 +52,11 @@ public:
#elif defined(_WIN32) && !defined(__CYGWIN__)
typedef HMODULE LibraryHandle;
#elif defined(__APPLE__)
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
# if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
typedef NSModule LibraryHandle;
#else
# else
typedef void* LibraryHandle;
#endif
# endif
#elif defined(__BEOS__)
typedef image_id LibraryHandle;
#else // POSIX
......@@ -66,26 +66,44 @@ public:
// Return type from DynamicLoader::GetSymbolAddress.
typedef void (*SymbolPointer)();
enum OpenFlags
{
// Search for dependent libraries beside the library being loaded.
//
// This is currently only supported on Windows.
SearchBesideLibrary = 0x00000001,
// Make loaded symbols visible globally
//
// This is currently only supported on *nix systems.
RTLDGlobal = 0x00000002,
AllOpenFlags = SearchBesideLibrary | RTLDGlobal
};
/** Load a dynamic library into the current process.
* The returned LibraryHandle can be used to access the symbols in the
* library. */
static LibraryHandle OpenLibrary(const std::string&);
* library. The optional second argument is a set of flags to use when
* opening the library. If unrecognized or unsupported flags are specified,
* the library is not opened. */
static LibraryHandle OpenLibrary(std::string const&);
static LibraryHandle OpenLibrary(std::string const&, int);
/** Attempt to detach a dynamic library from the
* process. A value of true is returned if it is sucessful. */
* process. A value of true is returned if it is successful. */
static int CloseLibrary(LibraryHandle);
/** Find the address of the symbol in the given library. */
static SymbolPointer GetSymbolAddress(LibraryHandle, const std::string&);
static SymbolPointer GetSymbolAddress(LibraryHandle, std::string const&);
/** Return the default module prefix for the current platform. */
static const char* LibPrefix() { return "@KWSYS_DynamicLoader_PREFIX@"; }
static char const* LibPrefix() { return "@KWSYS_DynamicLoader_PREFIX@"; }
/** Return the default module suffix for the current platform. */
static const char* LibExtension() { return "@KWSYS_DynamicLoader_SUFFIX@"; }
static char const* LibExtension() { return "@KWSYS_DynamicLoader_SUFFIX@"; }
/** Return the last error produced from a calls made on this class. */
static const char* LastError();
static char const* LastError();
}; // End Class: DynamicLoader
} // namespace @KWSYS_NAMESPACE@
......
......@@ -12,15 +12,15 @@
not visible to user code. Use kwsysHeaderDump.pl to reproduce
these macros after making changes to the interface. */
#if !defined(KWSYS_NAMESPACE)
#define kwsys_ns(x) @KWSYS_NAMESPACE@##x
#define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
#endif
#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
#define kwsysEncoding kwsys_ns(Encoding)
#define kwsysEncoding_mbstowcs kwsys_ns(Encoding_mbstowcs)
#define kwsysEncoding_DupToWide kwsys_ns(Encoding_DupToWide)
#define kwsysEncoding_wcstombs kwsys_ns(Encoding_wcstombs)
#define kwsysEncoding_DupToNarrow kwsys_ns(Encoding_DupToNarrow)
# define kwsysEncoding kwsys_ns(Encoding)
# define kwsysEncoding_mbstowcs kwsys_ns(Encoding_mbstowcs)
# define kwsysEncoding_DupToWide kwsys_ns(Encoding_DupToWide)
# define kwsysEncoding_wcstombs kwsys_ns(Encoding_wcstombs)
# define kwsysEncoding_DupToNarrow kwsys_ns(Encoding_DupToNarrow)
#endif
#if defined(__cplusplus)
......@@ -31,22 +31,22 @@ extern "C" {
On Windows, UTF-8 is assumed, and on other platforms,
the current locale is assumed.
*/
kwsysEXPORT size_t kwsysEncoding_mbstowcs(wchar_t* dest, const char* src,
kwsysEXPORT size_t kwsysEncoding_mbstowcs(wchar_t* dest, char const* src,
size_t n);
/* Convert a narrow string to a wide string.
This can return NULL if the conversion fails. */
kwsysEXPORT wchar_t* kwsysEncoding_DupToWide(const char* src);
kwsysEXPORT wchar_t* kwsysEncoding_DupToWide(char const* src);
/* Convert a wide string to a narrow string.
On Windows, UTF-8 is assumed, and on other platforms,
the current locale is assumed. */
kwsysEXPORT size_t kwsysEncoding_wcstombs(char* dest, const wchar_t* src,
kwsysEXPORT size_t kwsysEncoding_wcstombs(char* dest, wchar_t const* src,
size_t n);
/* Convert a wide string to a narrow string.
This can return NULL if the conversion fails. */
kwsysEXPORT char* kwsysEncoding_DupToNarrow(const wchar_t* str);
kwsysEXPORT char* kwsysEncoding_DupToNarrow(wchar_t const* str);
#if defined(__cplusplus)
} /* extern "C" */
......@@ -55,15 +55,15 @@ kwsysEXPORT char* kwsysEncoding_DupToNarrow(const wchar_t* str);
/* If we are building a kwsys .c or .cxx file, let it use these macros.
Otherwise, undefine them to keep the namespace clean. */
#if !defined(KWSYS_NAMESPACE)
#undef kwsys_ns
#undef kwsysEXPORT
#if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
#undef kwsysEncoding
#undef kwsysEncoding_mbstowcs
#undef kwsysEncoding_DupToWide
#undef kwsysEncoding_wcstombs
#undef kwsysEncoding_DupToNarrow
#endif
# undef kwsys_ns
# undef kwsysEXPORT
# if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsysEncoding
# undef kwsysEncoding_mbstowcs
# undef kwsysEncoding_DupToWide
# undef kwsysEncoding_wcstombs
# undef kwsysEncoding_DupToNarrow
# endif
#endif
#endif
......@@ -13,7 +13,7 @@ class @KWSYS_NAMESPACE@_EXPORT Encoding
{
public:
// Container class for argc/argv.
class CommandLineArguments
class @KWSYS_NAMESPACE@_EXPORT CommandLineArguments
{
public:
// On Windows, get the program command line arguments
......@@ -31,8 +31,8 @@ public:
// argc and wide argv. This is useful if wmain() is used.
CommandLineArguments(int argc, wchar_t const* const* argv);
~CommandLineArguments();
CommandLineArguments(const CommandLineArguments&);
CommandLineArguments& operator=(const CommandLineArguments&);
CommandLineArguments(CommandLineArguments const&);
CommandLineArguments& operator=(CommandLineArguments const&);
int argc() const;
char const* const* argv() const;
......@@ -41,23 +41,36 @@ public:
std::vector<char*> argv_;
};
/**
* Convert between char and wchar_t
*/
/**
* Convert between char and wchar_t
*/
#if @KWSYS_NAMESPACE@_STL_HAS_WSTRING
// Convert a narrow string to a wide string.
// On Windows, UTF-8 is assumed, and on other platforms,
// the current locale is assumed.
static std::wstring ToWide(const std::string& str);
static std::wstring ToWide(const char* str);
static std::wstring ToWide(std::string const& str);
static std::wstring ToWide(char const* str);
// Convert a wide string to a narrow string.
// On Windows, UTF-8 is assumed, and on other platforms,
// the current locale is assumed.
static std::string ToNarrow(const std::wstring& str);
static std::string ToNarrow(const wchar_t* str);
static std::string ToNarrow(std::wstring const& str);
static std::string ToNarrow(wchar_t const* str);
# if defined(_WIN32)
/**
* Convert the path to an extended length path to avoid MAX_PATH length
* limitations on Windows. If the input is a local path the result will be
* prefixed with \\?\; if the input is instead a network path, the result
* will be prefixed with \\?\UNC\. All output will also be converted to
* absolute paths with Windows-style backslashes.
**/
static std::wstring ToWindowsExtendedPath(std::string const&);
static std::wstring ToWindowsExtendedPath(char const* source);
static std::wstring ToWindowsExtendedPath(std::wstring const& wsource);
# endif
#endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING
......