diff --git a/MakefileTemplate.in b/MakefileTemplate.in new file mode 100644 index 000000000..0ce54fede --- /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 000000000..a11d25b30 --- /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 000000000..44d9593ea --- /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