From dbad2a6901e2686bff8923ab5d5f38de6e844d24 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Wed, 30 Aug 2000 14:00:44 -0400 Subject: ENH: add ability to compile all the files in a sub-directory --- MakefileTemplate.in | 4 ++ Source/cmDirectory.cxx | 122 +++++++++++++++++++++++++++++++++++++++++++++++++ Source/cmDirectory.h | 61 +++++++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 MakefileTemplate.in create mode 100644 Source/cmDirectory.cxx create mode 100644 Source/cmDirectory.h diff --git a/MakefileTemplate.in b/MakefileTemplate.in new file mode 100644 index 0000000..0ce54fe --- /dev/null +++ b/MakefileTemplate.in @@ -0,0 +1,4 @@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_OBJ_DIR@/CMake/CMakeMaster.make@MAKEQUOTE@ diff --git a/Source/cmDirectory.cxx b/Source/cmDirectory.cxx new file mode 100644 index 0000000..a11d25b --- /dev/null +++ b/Source/cmDirectory.cxx @@ -0,0 +1,122 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) 2000 National Library of Medicine + All rights reserved. + + See COPYRIGHT.txt for copyright details. + +=========================================================================*/ +#include "cmDirectory.h" + + + +// First microsoft compilers + +#ifdef _MSC_VER +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/** + * + */ +bool +cmDirectory +::Load(const char* name) +{ + char* buf; + int 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 + long 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; +} + +#else + +// Now the POSIX style directory access + +#include +#include + +/** + * + */ +bool +cmDirectory +::Load(const char* name) +{ + DIR* dir = opendir(name); + if ( !dir ) + { + return 0; + } + + dirent* d =0; + dir = opendir(name); + for ( d = readdir(dir); d; d = readdir(dir) ) + { + m_Files.push_back(d->d_name); + } + m_Path = name; + closedir(dir); + return 1; +} + +#endif + + +/** + * + */ +const char* +cmDirectory +::GetFile(unsigned int index) +{ + if ( index >= m_Files.size() ) + { + std::cerr << "Bad index for GetFile on cmDirectory\n"; + return 0; + } + return m_Files[index].c_str(); +} + diff --git a/Source/cmDirectory.h b/Source/cmDirectory.h new file mode 100644 index 0000000..44d9593 --- /dev/null +++ b/Source/cmDirectory.h @@ -0,0 +1,61 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) 2000 National Library of Medicine + All rights reserved. + + See COPYRIGHT.txt for copyright details. + +=========================================================================*/ +#ifndef __cmDirectory_h +#define __cmDirectory_h + +#include +#include +#include + + +/** \class cmDirectory + * \brief Portable directory/filename traversal. + * + * cmDirectory provides a portable way of finding the names of the files + * in a system directory. + * + * cmDirectory works with windows and unix only. + */ + + +class cmDirectory +{ +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. + */ + int GetNumberOfFiles() { return m_Files.size();} + + /** + * Return the file at the given index, the indexing is 0 based + */ + const char* GetFile(unsigned int index); + +private: + std::vector m_Files; // Array of Files + std::string m_Path; // Path to Open'ed directory +}; // End Class: cmDirectory + + +#endif -- cgit v0.12