ENH: add ability to compile all the files in a sub-directory

This commit is contained in:
Bill Hoffman 2000-08-30 14:00:44 -04:00
parent 077c31484e
commit dbad2a6901
3 changed files with 187 additions and 0 deletions

4
MakefileTemplate.in Normal file
View File

@ -0,0 +1,4 @@
srcdir = @srcdir@
VPATH = @srcdir@
@MAKEINCLUDE@ @MAKEQUOTE@@CMAKE_OBJ_DIR@/CMake/CMakeMaster.make@MAKEQUOTE@

122
Source/cmDirectory.cxx Normal file
View File

@ -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 <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>
/**
*
*/
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 <sys/types.h>
#include <dirent.h>
/**
*
*/
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();
}

61
Source/cmDirectory.h Normal file
View File

@ -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 <iostream>
#include <string>
#include <vector>
/** \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<std::string> m_Files; // Array of Files
std::string m_Path; // Path to Open'ed directory
}; // End Class: cmDirectory
#endif