+++ /dev/null
-#include <directory.h>\r
-#include <fstreams.h>\r
-#include <fstream.h>\r
-\r XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
-\r\rdirectory_t \r directory_new(const char *name) \r
-{
- \rdirectory_t directory;
- \r\rif (!name)
- \r {
- \rerrno = EINVAL;
- \rreturn NULL;
- \r}
- \r\rdirectory = xbt_new0(s_directory_t, 1);
- \r\r\rdirectory->name = strdup(name);
- \r\r\rdirectory->stream = NULL;
- \r\rreturn directory;
-\r}
-
-\r\rint \r directory_open(directory_t directory) \r
-{
- \rif (!directory || directory->stream)
- \rreturn EINVAL;
- \r\rif (!(directory->stream = opendir(directory->name)))
- \rreturn errno;
- \r\rreturn 0;
-\r}
-
-\r\r\rint \r directory_close(directory_t directory) \r
-{
- \rif (!directory)
- \rreturn EINVAL;
- \r\rif (!directory->stream)
- \rreturn EBADF;
- \r\rif (closedir(directory->stream))
- \rreturn errno;
- \r\rdirectory->stream = NULL;
- \rreturn 0;
-\r}
-
-\r\rint \r
-directory_load(directory_t directory, fstreams_t fstreams,
- xbt_dynar_t suffixes) \r
-{
- \rstruct dirent *entry = { 0 };
- \rs_fstream_t sfstream = {
- 0};
- \rchar *suffix;
- \runsigned int i;
- \rint has_valid_suffix;
- \rint is_empty = 1;
- \rint rv;
- \r\rif (!directory || !fstreams)
- \rreturn EINVAL;
- \r\rif (!directory->stream)
- \rreturn EBADF;
- \r\rsfstream.directory = strdup(directory->name);
- \r\rwhile ((entry = readdir(directory->stream)))
- \r {
- \rhas_valid_suffix = 0;
- \r\rxbt_dynar_foreach(suffixes, i, suffix) \r {
- \rif (!strncmp
- (suffix,
- entry->d_name + (strlen(entry->d_name) - strlen(suffix)),
- strlen(suffix)))
- \r {
- \rhas_valid_suffix = 1;
- \rbreak;
- \r}
- \r}
- \r\rif (!has_valid_suffix)
- \rcontinue;
- \r\rsfstream.name = strdup(entry->d_name);
- \r\r
- /* check first if the file stream is already in the file streams to run */ \r
- if (fstreams_contains(fstreams, &sfstream))
- \r {
- \rWARN1("file %s already registred", entry->d_name);
- \rfree(sfstream.name);
- \rcontinue;
- \r}
- \r\r
- /* add the fstream to the list of file streams to run */ \r
- if ((rv =
- fstreams_add(fstreams,
- fstream_new(directory->name, entry->d_name))))
- \r {
- \rfree(sfstream.directory);
- \rfree(sfstream.name);
- \rreturn rv;
- \r}
- \r\ris_empty = 0;
- \rfree(sfstream.name);
- \r}
- \r\rif (is_empty)
- \rWARN1("no tesh file found in the directory %s", directory->name);
- \r\rfree(sfstream.directory);
- \r\r\rreturn 0;
-\r}
-
-\r\rint \r directory_free(void **directoryptr) \r
-{
- \rdirectory_t directory;
- \r\rif (!(*directoryptr))
- \rreturn EINVAL;
- \r\rdirectory = *((directory_t *) directoryptr);
- \r\rif (directory->stream)
- \rif (directory_close(directory))
- \rreturn errno;
- \r\rif (directory->name)
- \rfree(directory->name);
- \r\rfree(*directoryptr);
- \r*directoryptr = NULL;
- \r\rreturn 0;
-\r}
-
-\r\rconst char *\r directory_get_name(directory_t directory) \r
-{
- \rif (!directory)
- \r {
- \rerrno = EINVAL;
- \rreturn NULL;
- \r}
- \r\rreturn (const char *) directory->name;
-\r} \r