1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <cctype>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include "directory.h"
directory::~directory (void)
{
}
void
directory::scan (const std::string &dir)
{
DIR *ttfdir = opendir(dir.c_str ());
this->clear ();
dirpath = dir;
dirpath += '/';
while (struct dirent *entry = readdir (ttfdir)) {
std::string name = path () + entry->d_name;
if (this->select (name.c_str ())) {
this->push_back (entry->d_name);
}
}
closedir (ttfdir);
}
bool
directory::select (const char *name) const
{
return true;
}
bool
ttfdirectory::select (const char *name) const
{
int len;
struct stat buf;
/* must be a regular file */
if (::stat (name, &buf) || !(S_ISREG (buf.st_mode))) {
return false;
}
/* we make the decision by the extension of the file name */
return (((len = strlen (name)) > 4) &&
(name[len - 4] == '.') &&
(std::toupper(name[len - 3]) == 'T') &&
(std::toupper(name[len - 2]) == 'T') &&
((std::toupper(name[len - 1]) == 'F') ||
(std::toupper(name[len - 1]) == 'C')));
}
|