Commit 91ff5437 authored by Brad King's avatar Brad King

ENH: Added kwsys library for platform-independent system tools.

parents
.git* export-ignore
PROJECT(${KWSYS_NAMESPACE})
INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIStreamHeaders.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFileCXX.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/TestForSTDNamespace.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
CHECK_INCLUDE_FILE_CXX("sstream" CMAKE_HAS_ANSI_STRING_STREAM)
SET(KWSYS_NO_STD_NAMESPACE ${CMAKE_NO_STD_NAMESPACE})
SET(KWSYS_NO_ANSI_STREAM_HEADERS ${CMAKE_NO_ANSI_STREAM_HEADERS})
SET(KWSYS_NO_ANSI_STRING_STREAM ${CMAKE_NO_ANSI_STRING_STREAM})
SET(KWSYS_NO_ANSI_FOR_SCOPE ${CMAKE_NO_ANSI_FOR_SCOPE})
SET(CLASSES Directory RegularExpression SystemTools)
SET(HEADERS Configure StandardIncludes)
SET(SRCS)
SET(KWSYS_INCLUDES)
FOREACH(c ${CLASSES})
SET(SRCS ${SRCS} ${c}.cxx)
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${c}.hxx.in
${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/${c}.hxx
@ONLY IMMEDIATE)
SET(KWSYS_INCLUDES ${KWSYS_INCLUDES}
${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/${c}.hxx)
ENDFOREACH(c)
FOREACH(h ${HEADERS})
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.hxx.in
${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/${h}.hxx
@ONLY IMMEDIATE)
SET(KWSYS_INCLUDES ${KWSYS_INCLUDES}
${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE}/${h}.hxx)
ENDFOREACH(h)
ADD_LIBRARY(${KWSYS_NAMESPACE} ${SRCS})
ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}")
INCLUDE_DIRECTORIES(BEFORE ${PROJECT_BINARY_DIR}/../${KWSYS_NAMESPACE})
IF(KWSYS_LIBRARY_INSTALL_DIR)
INSTALL_TARGETS(${KWSYS_LIBRARY_INSTALL_DIR} ${KWSYS_NAMESPACE})
ENDIF(KWSYS_LIBRARY_INSTALL_DIR)
IF(KWSYS_INCLUDE_INSTALL_DIR)
INSTALL_FILES(${KWSYS_INCLUDE_INSTALL_DIR}/${KWSYS_NAMESPACE}
FILES ${KWSYS_INCLUDES})
ENDIF(KWSYS_INCLUDE_INSTALL_DIR)
#ifndef @KWSYS_NAMESPACE@_Configure_hxx
#define @KWSYS_NAMESPACE@_Configure_hxx
/* This configuration should match for all instances of kwsys. */
#cmakedefine KWSYS_NO_STD_NAMESPACE
#cmakedefine KWSYS_NO_ANSI_STREAM_HEADERS
#cmakedefine KWSYS_NO_ANSI_STRING_STREAM
#cmakedefine KWSYS_NO_ANSI_FOR_SCOPE
#endif
/*=========================================================================
Program: KWSys - Kitware System Library
Module: Directory.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <Directory.hxx>
// First microsoft compilers
#ifdef _MSC_VER
#include <windows.h>
#include <io.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
namespace KWSYS_NAMESPACE
{
bool Directory::Load(const char* name)
{
char* buf;
size_t n = strlen(name);
if ( name[n - 1] == '/' )
{
buf = new char[n + 1 + 1];
sprintf(buf, "%s*", name);
}
else
{
buf = new char[n + 2 + 1];
sprintf(buf, "%s/*", name);
}
struct _finddata_t data; // data of current file
// Now put them into the file array
size_t srchHandle = _findfirst(buf, &data);
delete [] buf;
if ( srchHandle == -1 )
{
return 0;
}
// Loop through names
do
{
m_Files.push_back(data.name);
}
while ( _findnext(srchHandle, &data) != -1 );
m_Path = name;
return _findclose(srchHandle) != -1;
}
} // namespace KWSYS_NAMESPACE
#else
// Now the POSIX style directory access
#include <sys/types.h>
#include <dirent.h>
namespace KWSYS_NAMESPACE
{
bool Directory::Load(const char* name)
{
DIR* dir = opendir(name);
if (!dir)
{
return 0;
}
for (dirent* d = readdir(dir); d; d = readdir(dir) )
{
m_Files.push_back(d->d_name);
}
m_Path = name;
closedir(dir);
return 1;
}
} // namespace KWSYS_NAMESPACE
#endif
namespace KWSYS_NAMESPACE
{
const char* Directory::GetFile(size_t dindex)
{
if ( dindex >= m_Files.size() )
{
return 0;
}
return m_Files[dindex].c_str();
}
} // namespace KWSYS_NAMESPACE
/*=========================================================================
Program: KWSys - Kitware System Library
Module: Directory.hxx.in
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef @KWSYS_NAMESPACE@_Directory_hxx
#define @KWSYS_NAMESPACE@_Directory_hxx
#include <@KWSYS_NAMESPACE@/StandardIncludes.hxx>
#include <string>
#include <vector>
namespace @KWSYS_NAMESPACE@
{
/** \class Directory
* \brief Portable directory/filename traversal.
*
* Directory provides a portable way of finding the names of the files
* in a system directory.
*
* Directory currently works with Windows and Unix operating systems.
*/
class Directory
{
public:
/**
* 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.
*/
bool Load(const char* dir);
/**
* Return the number of files in the current directory.
*/
size_t GetNumberOfFiles() { return m_Files.size();}
/**
* Return the file at the given index, the indexing is 0 based
*/
const char* GetFile(size_t );
private:
kwsys_std::vector<kwsys_std::string> m_Files; // Array of Files
kwsys_std::string m_Path; // Path to Open'ed directory
}; // End Class: Directory
} // namespace @KWSYS_NAMESPACE@
#endif
This diff is collapsed.
This diff is collapsed.
/*=========================================================================
Program: KWSys - Kitware System Library
Module: StandardIncludes.hxx.in
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef @KWSYS_NAMESPACE@_StandardIncludes_hxx
#define @KWSYS_NAMESPACE@_StandardIncludes_hxx
#include <@KWSYS_NAMESPACE@/Configure.hxx>
#ifndef KWSYS_NO_ANSI_STREAM_HEADERS
# include <fstream>
# include <iostream>
#else
# include <fstream.h>
# include <iostream.h>
#endif
#if !defined(KWSYS_NO_ANSI_STRING_STREAM)
# include <sstream>
#elif !defined(KWSYS_NO_ANSI_STREAM_HEADERS)
# include <strstream>
#else
# include <strstream.h>
#endif
#if defined(KWSYS_NO_STD_NAMESPACE)
# define kwsys_std
#else
# define kwsys_std std
#endif
#endif
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment