Commit 14e01a70 authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'update-kwsys'

c70d738a Merge branch 'upstream-KWSys' into update-kwsys
62b9eb5b KWSys 2016-11-03 (37306a1c)
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Ben Boeckel's avatarBen Boeckel <ben.boeckel@kitware.com>
Merge-request: !2142
parents 41f01be4 c70d738a
......@@ -123,6 +123,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
SET(KWSYS_USE_FStream 1)
SET(KWSYS_USE_String 1)
SET(KWSYS_USE_SystemInformation 1)
SET(KWSYS_USE_ConsoleBuf 1)
ENDIF()
# Enforce component dependencies.
......@@ -154,6 +155,9 @@ ENDIF()
IF(KWSYS_USE_FStream)
SET(KWSYS_USE_Encoding 1)
ENDIF()
IF(KWSYS_USE_ConsoleBuf)
SET(KWSYS_USE_Encoding 1)
ENDIF()
# Setup the large file support default.
IF(KWSYS_LFS_DISABLE)
......@@ -632,6 +636,11 @@ IF(KWSYS_USE_SystemInformation)
ENDIF()
ENDIF()
IF(KWSYS_USE_FStream)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H
"Checking whether <ext/stdio_filebuf.h> is available" DIRECT)
ENDIF()
#-----------------------------------------------------------------------------
# Choose a directory for the generated headers.
IF(NOT KWSYS_HEADER_ROOT)
......@@ -668,7 +677,7 @@ SET(KWSYS_HXX_FILES Configure String
# Add selected C++ classes.
SET(cppclasses
Directory DynamicLoader Encoding Glob RegularExpression SystemTools
CommandLineArguments IOStream FStream SystemInformation
CommandLineArguments IOStream FStream SystemInformation ConsoleBuf
)
FOREACH(cpp ${cppclasses})
IF(KWSYS_USE_${cpp})
......@@ -921,6 +930,20 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
testFStream
)
ENDIF()
IF(KWSYS_USE_ConsoleBuf)
ADD_EXECUTABLE(testConsoleBufChild testConsoleBufChild.cxx)
SET_PROPERTY(TARGET testConsoleBufChild PROPERTY LABELS ${KWSYS_LABELS_EXE})
TARGET_LINK_LIBRARIES(testConsoleBufChild ${KWSYS_NAMESPACE})
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
testConsoleBuf
)
IF("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC" AND
NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0")
set_property(SOURCE testConsoleBuf.cxx testConsoleBufChild.cxx PROPERTY COMPILE_FLAGS /utf-8)
ENDIF()
SET_PROPERTY(SOURCE testConsoleBuf.cxx APPEND PROPERTY COMPILE_DEFINITIONS
KWSYS_ENCODING_DEFAULT_CODEPAGE=${KWSYS_ENCODING_DEFAULT_CODEPAGE})
ENDIF()
IF(KWSYS_USE_SystemInformation)
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testSystemInformation)
ENDIF()
......
......@@ -17,6 +17,8 @@
/* Whether wstring is available. */
#define @KWSYS_NAMESPACE@_STL_HAS_WSTRING @KWSYS_STL_HAS_WSTRING@
/* Whether <ext/stdio_filebuf.h> is available. */
#define @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H @KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@
/* If building a C++ file in kwsys itself, give the source file
access to the macros without a configured namespace. */
......@@ -24,8 +26,9 @@
# 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_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
#endif
#endif
This diff is collapsed.
......@@ -84,9 +84,9 @@ void Directory::Clear()
} // namespace KWSYS_NAMESPACE
// First microsoft compilers
// First Windows platforms
#if defined(_MSC_VER) || defined(__WATCOMC__)
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#include <io.h>
#include <ctype.h>
......@@ -97,15 +97,25 @@ void Directory::Clear()
#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)
{
this->Clear();
#if _MSC_VER < 1300
#if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
// Older Visual C++ and Embarcadero compilers.
long srchHandle;
#else
#else // Newer Visual C++
intptr_t srchHandle;
#endif
char* buf;
......@@ -132,7 +142,7 @@ bool Directory::Load(const std::string& name)
struct _wfinddata_t data; // data of current file
// Now put them into the file array
srchHandle = _wfindfirst((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
srchHandle = _wfindfirst_func((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
delete [] buf;
if ( srchHandle == -1 )
......@@ -145,16 +155,17 @@ bool Directory::Load(const std::string& name)
{
this->Internal->Files.push_back(Encoding::ToNarrow(data.name));
}
while ( _wfindnext(srchHandle, &data) != -1 );
while ( _wfindnext_func(srchHandle, &data) != -1 );
this->Internal->Path = name;
return _findclose(srchHandle) != -1;
}
unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
{
#if _MSC_VER < 1300
#if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
// Older Visual C++ and Embarcadero compilers.
long srchHandle;
#else
#else // Newer Visual C++
intptr_t srchHandle;
#endif
char* buf;
......@@ -172,7 +183,7 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
struct _wfinddata_t data; // data of current file
// Now put them into the file array
srchHandle = _wfindfirst((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
srchHandle = _wfindfirst_func((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
delete [] buf;
if ( srchHandle == -1 )
......@@ -186,7 +197,7 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
{
count++;
}
while ( _wfindnext(srchHandle, &data) != -1 );
while ( _wfindnext_func(srchHandle, &data) != -1 );
_findclose(srchHandle);
return count;
}
......
......@@ -12,154 +12,250 @@
#ifndef @KWSYS_NAMESPACE@_FStream_hxx
#define @KWSYS_NAMESPACE@_FStream_hxx
#include <@KWSYS_NAMESPACE@/Configure.hxx>
#include <@KWSYS_NAMESPACE@/Encoding.hxx>
#include <fstream>
#if defined(_WIN32)
# if !defined(_MSC_VER) && @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H
# include <ext/stdio_filebuf.h>
# endif
#endif
namespace @KWSYS_NAMESPACE@
{
#if defined(_MSC_VER) && _MSC_VER >= 1400
#if defined(_WIN32) && (defined(_MSC_VER) || @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H)
# if defined(_NOEXCEPT)
# define @KWSYS_NAMESPACE@_FStream_NOEXCEPT _NOEXCEPT
# else
# define @KWSYS_NAMESPACE@_FStream_NOEXCEPT
# endif
#if defined(_MSC_VER)
template<typename CharType,typename Traits>
class basic_filebuf : public std::basic_filebuf<CharType,Traits>
{
# if _MSC_VER >= 1400
public:
typedef std::basic_filebuf<CharType,Traits> my_base_type;
basic_filebuf *open(char const *s,std::ios_base::openmode mode)
{
const std::wstring wstr = Encoding::ToWide(s);
return static_cast<basic_filebuf*>(
my_base_type::open(Encoding::ToWide(s).c_str(), mode)
my_base_type::open(wstr.c_str(), mode)
);
}
# endif
};
#else
inline std::wstring getcmode(const std::ios_base::openmode mode) {
std::wstring cmode;
bool plus = false;
if (mode & std::ios_base::app) {
cmode += L"a";
plus = mode & std::ios_base::in ? true : false;
} else if (mode & std::ios_base::trunc ||
(mode & std::ios_base::out && (mode & std::ios_base::in) == 0)) {
cmode += L"w";
plus = mode & std::ios_base::in ? true : false;
} else {
cmode += L"r";
plus = mode & std::ios_base::out ? true : false;
}
if (plus) {
cmode += L"+";
}
if (mode & std::ios_base::binary) {
cmode += L"b";
} else {
cmode += L"t";
}
return cmode;
};
#endif
template<typename CharType,typename Traits = std::char_traits<CharType> >
class basic_ifstream : public std::basic_istream<CharType,Traits>
class basic_efilebuf
{
public:
#if defined(_MSC_VER)
typedef basic_filebuf<CharType,Traits> internal_buffer_type;
#else
typedef __gnu_cxx::stdio_filebuf<CharType,Traits> internal_buffer_type;
#endif
basic_efilebuf() : file_(0)
{
buf_ = 0;
}
bool _open(char const *file_name,std::ios_base::openmode mode)
{
if (is_open() || file_) {
return false;
}
#if defined(_MSC_VER)
const bool success = buf_->open(file_name,mode) != 0;
#else
const std::wstring wstr = Encoding::ToWide(file_name);
bool success = false;
std::wstring cmode = getcmode(mode);
file_ = _wfopen(wstr.c_str(), cmode.c_str());
if (file_) {
if (buf_) {
delete buf_;
}
buf_ = new internal_buffer_type(file_, mode);
success = true;
}
#endif
return success;
}
bool is_open()
{
if (!buf_) {
return false;
}
return buf_->is_open();
}
bool is_open() const
{
if (!buf_) {
return false;
}
return buf_->is_open();
}
bool _close()
{
bool success = false;
if (buf_) {
success = buf_->close() != 0;
#if !defined(_MSC_VER)
if (file_) {
success = fclose(file_) == 0 ? success : false;
file_ = 0;
}
#endif
}
return success;
}
static void _set_state(bool success, std::basic_ios<CharType,Traits> *ios, basic_efilebuf* efilebuf)
{
#if !defined(_MSC_VER)
ios->rdbuf(efilebuf->buf_);
#else
static_cast<void>(efilebuf);
#endif
if (!success) {
ios->setstate(std::ios_base::failbit);
} else {
ios->clear();
}
}
~basic_efilebuf()
{
if (buf_) {
delete buf_;
}
}
protected:
internal_buffer_type* buf_;
FILE *file_;
};
template<typename CharType,typename Traits = std::char_traits<CharType> >
class basic_ifstream : public std::basic_istream<CharType,Traits>,
public basic_efilebuf<CharType,Traits>
{
using basic_efilebuf<CharType,Traits>::is_open;
public:
typedef basic_filebuf<CharType,Traits> internal_buffer_type;
typedef typename basic_efilebuf<CharType, Traits>::internal_buffer_type internal_buffer_type;
typedef std::basic_istream<CharType,Traits> internal_stream_type;
basic_ifstream() : internal_stream_type(new internal_buffer_type())
{
buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
this->buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
}
explicit basic_ifstream(char const *file_name,
std::ios_base::openmode mode = std::ios_base::in)
: internal_stream_type(new internal_buffer_type())
{
buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
this->buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
open(file_name,mode);
}
void open(char const *file_name,std::ios_base::openmode mode = std::ios_base::in)
{
if(!buf_->open(file_name,mode | std::ios_base::in))
{
this->setstate(std::ios_base::failbit);
}
else
{
this->clear();
}
}
bool is_open()
{
return buf_->is_open();
}
bool is_open() const
{
return buf_->is_open();
mode = mode | std::ios_base::in;
this->_set_state(this->_open(file_name, mode), this, this);
}
void close()
{
if(!buf_->close())
{
this->setstate(std::ios_base::failbit);
}
else
{
this->clear();
}
this->_set_state(this->_close(), this, this);
}
internal_buffer_type *rdbuf() const
{
return buf_;
return this->buf_;
}
~basic_ifstream() @KWSYS_NAMESPACE@_FStream_NOEXCEPT
{
buf_->close();
delete buf_;
close();
}
private:
internal_buffer_type* buf_;
};
template<typename CharType,typename Traits = std::char_traits<CharType> >
class basic_ofstream : public std::basic_ostream<CharType,Traits>
class basic_ofstream : public std::basic_ostream<CharType,Traits>,
public basic_efilebuf<CharType,Traits>
{
using basic_efilebuf<CharType,Traits>::is_open;
public:
typedef basic_filebuf<CharType,Traits> internal_buffer_type;
typedef typename basic_efilebuf<CharType, Traits>::internal_buffer_type internal_buffer_type;
typedef std::basic_ostream<CharType,Traits> internal_stream_type;
basic_ofstream() : internal_stream_type(new internal_buffer_type())
{
buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
this->buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
}
explicit basic_ofstream(char const *file_name,std::ios_base::openmode mode = std::ios_base::out) :
internal_stream_type(new internal_buffer_type())
{
buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
this->buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
open(file_name,mode);
}
void open(char const *file_name,std::ios_base::openmode mode = std::ios_base::out)
{
if(!buf_->open(file_name,mode | std::ios_base::out))
{
this->setstate(std::ios_base::failbit);
}
else
{
this->clear();
}
}
bool is_open()
{
return buf_->is_open();
}
bool is_open() const
{
return buf_->is_open();
mode = mode | std::ios_base::out;
this->_set_state(this->_open(file_name, mode), this, this);
}
void close()
{
if(!buf_->close())
{
this->setstate(std::ios_base::failbit);
}
else
{
this->clear();
}
this->_set_state(this->_close(), this, this);
}
internal_buffer_type *rdbuf() const
{
return buf_.get();
return this->buf_;
}
~basic_ofstream() @KWSYS_NAMESPACE@_FStream_NOEXCEPT
{
buf_->close();
delete buf_;
close();
}
private:
internal_buffer_type* buf_;
};
typedef basic_ifstream<char> ifstream;
......
......@@ -79,9 +79,9 @@ typedef int siginfo_t;
# undef _WIN32
#endif
#ifdef __FreeBSD__
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
# include <sys/param.h>
# include <sys/sysctl.h>
# include <fenv.h>
# include <sys/socket.h>
# include <netdb.h>
# include <netinet/in.h>
......@@ -91,19 +91,10 @@ typedef int siginfo_t;
# endif
#endif
#if defined(__OpenBSD__) || defined(__NetBSD__)
# include <sys/param.h>
# include <sys/sysctl.h>
#endif
#if defined(KWSYS_SYS_HAS_MACHINE_CPU_H)
# include <machine/cpu.h>
#endif
#if defined(__DragonFly__)
# include <sys/sysctl.h>
#endif
#ifdef __APPLE__
# include <sys/sysctl.h>
# include <mach/vm_statistics.h>
......@@ -123,7 +114,7 @@ typedef int siginfo_t;
# endif
#endif
#ifdef __linux
#if defined(__linux) || defined (__sun) || defined(_SCO_DS)
# include <fenv.h>
# include <sys/socket.h>
# include <netdb.h>
......
This diff is collapsed.
......@@ -53,6 +53,7 @@ namespace @KWSYS_NAMESPACE@
class SystemToolsTranslationMap;
class SystemToolsPathCaseMap;
class SystemToolsEnvMap;
/** \class SystemToolsManager
* \brief Use to make sure SystemTools is initialized before it is used
......@@ -304,6 +305,11 @@ public:
*/
static std::string ConvertToWindowsOutputPath(const std::string&);
/**
* Return true if a path with the given name exists in the current directory.
*/
static bool PathExists(const std::string& path);
/**
* Return true if a file exists in the current directory.
* If isFile = true, then make sure the file is a file and
......@@ -368,10 +374,11 @@ public:
static const char* GetExecutableExtension();
/**
* Given a path that exists on a windows machine, return the
* actuall case of the path as it was created. If the file
* does not exist path is returned unchanged. This does nothing
* on unix but return path.
* Given a path on a Windows machine, return the actual case of
* the path as it exists on disk. Path components that do not
* exist on disk are returned unchanged. Relative paths are always
* returned unchanged. Drive letters are always made upper case.
* This does nothing on non-Windows systems but return the path.
*/
static std::string GetActualCaseForPath(const std::string& path);
......@@ -843,6 +850,8 @@ public:
static const char* GetEnv(const std::string& key);
static bool GetEnv(const char* key, std::string& result);
static bool GetEnv(const std::string& key, std::string& result);
static bool HasEnv(const char* key);
static bool HasEnv(const std::string& key);
/** Put a string into the environment
of the form var=value */
......@@ -981,6 +990,7 @@ private:
std::vector<std::string>(),
bool no_system_path = false);
static const char* GetEnvImpl(const char* key);
/**
* Path translation table from dir to refdir
......@@ -989,6 +999,7 @@ private:
static SystemToolsTranslationMap *TranslationMap;
#ifdef _WIN32
static SystemToolsPathCaseMap *PathCaseMap;
static SystemToolsEnvMap *EnvMap;
#endif
#ifdef __CYGWIN__
static SystemToolsTranslationMap *Cyg2Win32Map;
......
......@@ -349,3 +349,8 @@ int main()
void f(std ::wstring*) {}
int main() { return 0; }
#endif
#ifdef TEST_KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H
#include <ext/stdio_filebuf.h>
int main() { return 0; }
#endif
This diff is collapsed.
/*============================================================================
KWSys - Kitware System Library
Copyright 2000-2016 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#ifndef testConsoleBuf_hxx
#define testConsoleBuf_hxx
static const wchar_t cmdConsoleBufChild[] = L"testConsoleBufChild";
static const wchar_t BeforeInputEventName[] = L"BeforeInputEvent";
static const wchar_t AfterOutputEventName[] = L"AfterOutputEvent";
// यूनिकोड είναι здорово!
static const wchar_t UnicodeTestString[] = L"\u092F\u0942\u0928\u093F\u0915\u094B\u0921 "
L"\u03B5\u03AF\u03BD\u03B1\u03B9 "
L"\u0437\u0434\u043E\u0440\u043E\u0432\u043E!";
#endif
/*============================================================================
KWSys - Kitware System Library
Copyright 2000-2016 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "kwsysPrivate.h"
#include KWSYS_HEADER(ConsoleBuf.hxx)
#include KWSYS_HEADER(Encoding.hxx)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
# include "ConsoleBuf.hxx.in"
# include "Encoding.hxx.in"
#endif
#include <iostream>
#include "testConsoleBuf.hxx"
//----------------------------------------------------------------------------
int main(int argc, const char* argv[])
{
#if defined(_WIN32)
kwsys::ConsoleBuf::Manager out(std::cout);
kwsys::ConsoleBuf::Manager err(std::cerr, true);
kwsys::ConsoleBuf::Manager in(std::cin);
if (argc > 1) {
std::cout << argv[1] << std::endl;
std::cerr << argv[1] << std::endl;
} else {
std::string str = kwsys::Encoding::ToNarrow(UnicodeTestString);
std::cout << str << std::endl;
std::cerr << str << std::endl;
}
std::string input;
HANDLE event = OpenEventW(EVENT_MODIFY_STATE, FALSE, BeforeInputEventName);
if (event) {
SetEvent(event);
CloseHandle(event);
}
std::cin >> input;
std::cout << input << std::endl;
event = OpenEventW(EVENT_MODIFY_STATE, FALSE, AfterOutputEventName);
if (event) {
SetEvent(event);
CloseHandle(event);
}
#else
static_cast<void>(argc);
static_cast<void>(argv);
#endif
return 0;
}
......@@ -204,6 +204,14 @@ static bool CheckFileOperations()
<< testNewDir << std::endl;
res = false;
}
// check existence
if (!kwsys::SystemTools::PathExists(testNewDir))
{
std::cerr
<< "Problem with PathExists for: "
<< testNewDir << std::endl;
res = false;
}
// remove it
if (!kwsys::SystemTools::RemoveADirectory(testNewDir))
{
......@@ -221,6 +229,15 @@ static bool CheckFileOperations()
<< testNewDir << std::endl;
res = false;
}
// check existence
if (kwsys::SystemTools::PathExists(testNewDir))
{
std::cerr
<< "After RemoveADirectory: "
<< "Problem with PathExists for: "
<< testNewDir << std::endl;
res = false;
}
// create it using the char* version
if (!kwsys::SystemTools::MakeDirectory(testNewDir.c_str()))
{
......@@ -329,6 +346,31 @@ static bool CheckFileOperations()
res = false;
}
// calling with an empty string should return false
if (kwsys::SystemTools::PathExists(std::string()))
{
std::cerr
<< "Problem with PathExists(std::string())"
<< std::endl;
res = false;
}
// PathExists(x) should return true on a directory
if (!kwsys::SystemTools::PathExists(testNewDir))
{
std::cerr
<< "Problem with PathExists for: "
<< testNewDir << std::endl;
res = false;
}
// should work, was created as new file before
if (!kwsys::SystemTools::PathExists(testNewFile))
{
std::cerr
<< "Problem with PathExists for: "
<< testNewDir << std::endl;
res = false;
}
// Reset umask
#if defined(_WIN32) && !defined(__CYGWIN__)
// NOTE: Windows doesn't support toggling _S_IREAD.
......@@ -848,9 +890,9 @@ static bool CheckPutEnv(const std::string& env, const char* name, const char* va