1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
12 #include <sys/types.h>
17 #include <anna/config/defines.hpp>
19 #include <anna/io/Directory.hpp>
20 #include <anna/io/internal/sccs.hpp>
25 io::Directory::Directory() :
30 void io::Directory::setPattern(const char* expression)
31 throw(RuntimeException) {
32 if(a_hasPattern == true) {
37 if(expression == NULL)
42 if((ret = regcomp(&a_regex, expression, REG_EXTENDED)) != 0) {
44 string msg("io::Directory | Pattern: ");
48 if(regerror(ret, &a_regex, err, sizeof(err)))
51 msg += "Invalid pattern";
53 throw RuntimeException(msg, ANNA_FILE_LOCATION);
59 void io::Directory:: read(const char* dirName, const Mode::_v mode)
60 throw(RuntimeException) {
65 if((handle = opendir(dirName)) == NULL) {
66 const int aux_errno(errno);
67 throw RuntimeException(string(dirName), aux_errno, ANNA_FILE_LOCATION);
72 while((entry = readdir(handle)) != NULL) {
73 if(!anna_strcmp(entry->d_name, ".") || !anna_strcmp(entry->d_name, ".."))
76 if(a_hasPattern == true)
77 if(regexec(&a_regex, entry->d_name, 0, NULL, 0) != 0)
80 if(mode == Mode::FullPath) {
83 file += entry->d_name;
87 a_files.push_back(file);
93 io::Directory::const_iterator io::Directory::find(const std::string& file) const
95 return std::find(begin(), end(), file);