Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sanitize the use of logs in unit testing of parmap to fix supernovae
[simgrid.git] / tools / tesh2 / src / fstreams.c
index 27905ee..66336a3 100644 (file)
-#include <fstreams.h>
-#include <excludes.h>
-#include <fstream.h>
-
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
-
-fstreams_t
-fstreams_new(int capacity, fn_finalize_t fn_finalize)
+#include <fstreams.h>\r
+#include <excludes.h>\r
+#include <fstream.h>\r
+\r XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
+\r\rfstreams_t \r fstreams_new(void_f_pvoid_t fn_finalize) \r
 {
-       fstreams_t fstreams;
-       fstreams = xbt_new0(s_fstreams_t, 1);
-       
-       if(!(fstreams->items = vector_new(capacity, fn_finalize)))
-       {
-               free(fstreams);
-               return NULL;
-       }
-       
-       return fstreams;
-}
+  \rfstreams_t fstreams = xbt_new0(s_fstreams_t, 1);
+  \rfstreams->items = xbt_dynar_new(sizeof(fstream_t), fn_finalize);
+  \r\rreturn fstreams;
+\r}
 
-int
-fstreams_exclude(fstreams_t fstreams, excludes_t excludes)
+\r\rint \r fstreams_exclude(fstreams_t fstreams, excludes_t excludes) \r
 {
-       vector_t to_erase;
-       fstream_t fstream;
-       
-       if(!fstreams || !excludes)
-               return EINVAL;
-               
-       if(excludes_is_empty(excludes))
-               return 0;
-       
-       if(!(to_erase = vector_new(8, NULL)))
-               return errno;
-       
-       INFO0("excluding file streams");
-       
-       /* collecte the file streams to exclude */
-       vector_rewind(fstreams->items);
-       
-       while((fstream = vector_get(fstreams->items)))
-       {
-               if(excludes_contains(excludes, fstream))
-                       vector_push_back(to_erase, fstream);
-               
-               
-               vector_move_next(fstreams->items);
-       }
-       
-       if(!vector_is_empty(to_erase))
-       {
-       
-               /* erase the file streams to exclude from the vector of file streams to run */
-               vector_rewind(to_erase);
-               
-               while((fstream = vector_get(to_erase)))
-               {
-                       vector_erase(fstreams->items, fstream);
-                       
-                       vector_move_next(to_erase);
-               }
-       }
-       
-       return vector_free(&to_erase);
-}
+  \rfstream_t fstream;
+  \runsigned int i;
+  \r\rif (!fstreams || !excludes)
+    \rreturn EINVAL;
+  \r\rif (excludes_is_empty(excludes))
+    \rreturn 0;
+  \r\r
+      /* collecte the file streams to exclude */ \r
+      xbt_dynar_foreach(fstreams->items, i, fstream) \r {
+    \rif (excludes_contains(excludes, fstream))
+      \r {
+      \rINFO1("excluding %s", fstream->name);
+      \rxbt_dynar_cursor_rm(fstreams->items, &i);
+      \r}
+  \r}
+  \r\rreturn 0;
+\r}
 
-int 
-fstreams_contains(fstreams_t fstreams, fstream_t fstream)
+\r\rint \r fstreams_contains(fstreams_t fstreams, fstream_t fstream) \r
 {
-       register fstream_t cur;
-       
-       if(!fstreams || !fstream)
-       {
-               errno = EINVAL;
-               return 0;
-       }
-       
-       vector_rewind(fstreams->items);
-       
-       while((cur = vector_get(fstreams->items)))
-       {
-               if(!strcmp(cur->name, fstream->name) && !strcmp(cur->directory, fstream->directory))
-                       return 1;
-               
-               vector_move_next(fstreams->items);
-       }
-       
-       return 0;
-}
+  \rfstream_t cur;
+  \runsigned int i;
+  \r\rif (!fstreams || !fstream)
+    \r {
+    \rerrno = EINVAL;
+    \rreturn 0;
+    \r}
+  \r\rxbt_dynar_foreach(fstreams->items, i, cur) \r {
+    \rif (!strcmp(cur->name, fstream->name)
+         && !strcmp(cur->directory, fstream->directory))
+      \rreturn 1;
+  \r}
+  \r\rreturn 0;
+\r}
 
-int
-fstreams_load(fstreams_t fstreams)
+\r\rint \r fstreams_load(fstreams_t fstreams) \r
 {
-       register fstream_t fstream;
-       const char* directory = NULL;
-       
-       
-       if(!fstreams )
-               return EINVAL;
-       
-       vector_rewind(fstreams->items);
-       
-       while((fstream = vector_get(fstreams->items)))
-       {
-               chdir(root_directory->name);
-               
-               if(!directory || strcmp(directory, fstream->directory))
-               {
-                       directory = fstream->directory; 
-                       
-                       if(!dont_want_display_directory)
-                               INFO1("entering directory \"%s\"",directory);
-                               
-               }
-               
-               chdir(fstream->directory);
-               
-               fstream_open(fstream);
-               
-               vector_move_next(fstreams->items);
-       }
-       
-       return 0;
-}
+  \rfstream_t fstream;
+  \runsigned int i;
+  \r\rif (!fstreams)
+    \rreturn EINVAL;
+  \r\rxbt_dynar_foreach(fstreams->items, i, fstream) \r {
+    \rfstream_open(fstream);
+  \r}
+  \r\r\rreturn 0;
+\r}
 
-int
-fstreams_add(fstreams_t fstreams, fstream_t fstream)
+\r\rint \r fstreams_add(fstreams_t fstreams, fstream_t fstream) \r
 {
-       if(!fstreams)
-               return EINVAL;
-       
-       if(vector_push_back(fstreams->items, fstream))
-               return errno;
-       
-       return 0;
-       
-}
+  \rif (!fstreams)
+    \rreturn EINVAL;
+  \r\rxbt_dynar_push(fstreams->items, &fstream);
+  \r\rreturn 0;
+\r}
 
-int
-fstreams_free(void** fstreamsptr)
+\r\rint \r fstreams_free(void **fstreamsptr) \r
 {
-       if(!(* fstreamsptr))
-               return EINVAL;
-               
-       
-       if((errno = vector_free(&((*((fstreams_t*)fstreamsptr))->items))))
-               return errno;
-               
-       free(*fstreamsptr);
-       
-       *fstreamsptr = NULL;
-       return 0;
-}
+  \rif (!(*fstreamsptr))
+    \rreturn EINVAL;
+  \r\rif ((*((fstreams_t *) fstreamsptr))->items)
+    \rxbt_dynar_free(&((*((fstreams_t *) fstreamsptr))->items));
+  \r\rfree(*fstreamsptr);
+  \r\r*fstreamsptr = NULL;
+  \rreturn 0;
+\r}
 
-int
-fstreams_get_size(fstreams_t fstreams)
+\r\rint \r fstreams_get_size(fstreams_t fstreams) \r
 {
-       if(!fstreams)
-       {
-               errno = EINVAL;
-               return -1;
-       }
-       
-       return vector_get_size(fstreams->items);
-}
+  \rif (!fstreams)
+    \r {
+    \rerrno = EINVAL;
+    \rreturn -1;
+    \r}
+  \r\rreturn xbt_dynar_length(fstreams->items);
+\r}
 
-int
-fstreams_is_empty(fstreams_t fstreams)
+\r\rint \r fstreams_is_empty(fstreams_t fstreams) \r
 {
-       if(!fstreams)
-       {
-               errno = EINVAL;
-               return -1;
-       }
-       
-       return vector_is_empty(fstreams->items);
-}
+  \rif (!fstreams)
+    \r {
+    \rerrno = EINVAL;
+    \rreturn -1;
+    \r}
+  \r\rreturn (0 == xbt_dynar_length(fstreams->items));
+\r}
+
+\r