Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change function called.
[simgrid.git] / tools / tesh2 / src / fstreams.c
index 510121ae640aaab0c1835d1ec8403355ccff9eba..5fb75df75de500fc2dd97d5654632ba417a02510 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)
-{
-       fstreams_t fstreams;
-       
-       if(!(fstreams = (fstreams_t) calloc(1, sizeof(s_fstreams_t))))
-               return NULL;
-       
-       if(!(fstreams->items = vector_new(capacity, fn_finalize)))
-       {
-               free(fstreams);
-               return NULL;
-       }
-       
-       return fstreams;
-}
-
-int
-fstreams_exclude(fstreams_t fstreams, excludes_t excludes)
-{
-       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;
-       
-       /* 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);
-}
-
-int 
-fstreams_contains(fstreams_t fstreams, fstream_t fstream)
-{
-       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;
-}
-
-int
-fstreams_load(fstreams_t fstreams)
-{
-       register fstream_t fstream;
-       
-       if(!fstreams )
-               return EINVAL;
-       
-       vector_rewind(fstreams->items);
-       
-       while((fstream = vector_get(fstreams->items)))
-       {
-               fstream_open(fstream);
-               vector_move_next(fstreams->items);
-       }
-       
-       
-       return 0;
-}
-
-int
-fstreams_add(fstreams_t fstreams, fstream_t fstream)
-{
-       if(!fstreams)
-               return EINVAL;
-       
-       if(vector_push_back(fstreams->items, fstream))
-               return errno;
-       
-       return 0;
-       
-}
-
-int
-fstreams_free(void** fstreamsptr)
-{
-       int rv;
-       
-       if(!(* fstreamsptr))
-               return EINVAL;
-       
-       if(EAGAIN != (rv = vector_free(&((*((fstreams_t*)fstreamsptr))->items))))
-               return rv;
-               
-       free(*fstreamsptr);
-       
-       *fstreamsptr = NULL;
-       return 0;
-}
-
-int
-fstreams_get_size(fstreams_t fstreams)
-{
-       if(!fstreams)
-       {
-               errno = EINVAL;
-               return -1;
-       }
-       
-       return vector_get_size(fstreams->items);
-}
-
-int
-fstreams_is_empty(fstreams_t fstreams)
-{
-       if(!fstreams)
-       {
-               errno = EINVAL;
-               return -1;
-       }
-       
-       return vector_is_empty(fstreams->items);
-}
+#include <fstreams.h>\r
+#include <excludes.h>\r
+#include <fstream.h>\r
+\r
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);\r
+\r
+fstreams_t\r
+fstreams_new(void_f_pvoid_t fn_finalize)\r
+{\r
+       fstreams_t fstreams = xbt_new0(s_fstreams_t, 1);\r
+       fstreams->items = xbt_dynar_new(sizeof(fstream_t), fn_finalize);\r
+       \r
+       return fstreams;\r
+}\r
+\r
+int\r
+fstreams_exclude(fstreams_t fstreams, excludes_t excludes)\r
+{\r
+       fstream_t fstream;\r
+       unsigned int i;\r
+       \r
+       if(!fstreams || !excludes)\r
+               return EINVAL;\r
+               \r
+       if(excludes_is_empty(excludes))\r
+               return 0;\r
+       \r
+       /* collecte the file streams to exclude */\r
+       xbt_dynar_foreach(fstreams->items, i, fstream)\r
+       {\r
+               if(excludes_contains(excludes, fstream))\r
+               {\r
+                       INFO1("excluding %s",fstream->name);\r
+                       xbt_dynar_cursor_rm(fstreams->items, &i);\r
+               }\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+int \r
+fstreams_contains(fstreams_t fstreams, fstream_t fstream)\r
+{\r
+       fstream_t cur;\r
+       unsigned int i;\r
+       \r
+       if(!fstreams || !fstream)\r
+       {\r
+               errno = EINVAL;\r
+               return 0;\r
+       }\r
+\r
+       xbt_dynar_foreach(fstreams->items, i, cur)\r
+       {\r
+               if(!strcmp(cur->name, fstream->name) && !strcmp(cur->directory, fstream->directory))\r
+                       return 1;\r
+       }\r
+       \r
+       return 0;\r
+}\r
+\r
+int\r
+fstreams_load(fstreams_t fstreams)\r
+{\r
+       fstream_t fstream;\r
+       unsigned int i;\r
+       \r
+       if(!fstreams )\r
+               return EINVAL;\r
+\r
+       xbt_dynar_foreach(fstreams->items, i, fstream)\r
+       {\r
+               fstream_open(fstream);\r
+       }\r
+       \r
+       \r
+       return 0;\r
+}\r
+\r
+int\r
+fstreams_add(fstreams_t fstreams, fstream_t fstream)\r
+{\r
+       if(!fstreams)\r
+               return EINVAL;\r
+\r
+       xbt_dynar_push(fstreams->items, &fstream);\r
+       \r
+       return 0;\r
+}\r
+\r
+int\r
+fstreams_free(void** fstreamsptr)\r
+{\r
+       if(!(* fstreamsptr))\r
+               return EINVAL;\r
+       \r
+       if((*((fstreams_t*)fstreamsptr))->items)\r
+               xbt_dynar_free(&((*((fstreams_t*)fstreamsptr))->items));\r
+               \r
+       free(*fstreamsptr);\r
+       \r
+       *fstreamsptr = NULL;\r
+       return 0;\r
+}\r
+\r
+int\r
+fstreams_get_size(fstreams_t fstreams)\r
+{\r
+       if(!fstreams)\r
+       {\r
+               errno = EINVAL;\r
+               return -1;\r
+       }\r
+       \r
+       return xbt_dynar_length(fstreams->items);\r
+}\r
+\r
+int\r
+fstreams_is_empty(fstreams_t fstreams)\r
+{\r
+       if(!fstreams)\r
+       {\r
+               errno = EINVAL;\r
+               return -1;\r
+       }\r
+       \r
+       return (0 == xbt_dynar_length(fstreams->items));\r
+}\r