Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
typo in comments (sorry for the noise)
[simgrid.git] / tools / tesh2 / src / fstreams.c
1 #include <fstreams.h>\r
2 #include <excludes.h>\r
3 #include <fstream.h>\r
4 \r XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
5 \r\rfstreams_t \r fstreams_new(void_f_pvoid_t fn_finalize) \r
6 {
7   \rfstreams_t fstreams = xbt_new0(s_fstreams_t, 1);
8   \rfstreams->items = xbt_dynar_new(sizeof(fstream_t), fn_finalize);
9   \r\rreturn fstreams;
10 \r}
11
12 \r\rint \r fstreams_exclude(fstreams_t fstreams, excludes_t excludes) \r
13 {
14   \rfstream_t fstream;
15   \runsigned int i;
16   \r\rif (!fstreams || !excludes)
17     \rreturn EINVAL;
18   \r\rif (excludes_is_empty(excludes))
19     \rreturn 0;
20   \r\r
21       /* collecte the file streams to exclude */ \r
22       xbt_dynar_foreach(fstreams->items, i, fstream) \r {
23     \rif (excludes_contains(excludes, fstream))
24       \r {
25       \rINFO1("excluding %s", fstream->name);
26       \rxbt_dynar_cursor_rm(fstreams->items, &i);
27       \r}
28   \r}
29   \r\rreturn 0;
30 \r}
31
32 \r\rint \r fstreams_contains(fstreams_t fstreams, fstream_t fstream) \r
33 {
34   \rfstream_t cur;
35   \runsigned int i;
36   \r\rif (!fstreams || !fstream)
37     \r {
38     \rerrno = EINVAL;
39     \rreturn 0;
40     \r}
41   \r\rxbt_dynar_foreach(fstreams->items, i, cur) \r {
42     \rif (!strcmp(cur->name, fstream->name)
43          && !strcmp(cur->directory, fstream->directory))
44       \rreturn 1;
45   \r}
46   \r\rreturn 0;
47 \r}
48
49 \r\rint \r fstreams_load(fstreams_t fstreams) \r
50 {
51   \rfstream_t fstream;
52   \runsigned int i;
53   \r\rif (!fstreams)
54     \rreturn EINVAL;
55   \r\rxbt_dynar_foreach(fstreams->items, i, fstream) \r {
56     \rfstream_open(fstream);
57   \r}
58   \r\r\rreturn 0;
59 \r}
60
61 \r\rint \r fstreams_add(fstreams_t fstreams, fstream_t fstream) \r
62 {
63   \rif (!fstreams)
64     \rreturn EINVAL;
65   \r\rxbt_dynar_push(fstreams->items, &fstream);
66   \r\rreturn 0;
67 \r}
68
69 \r\rint \r fstreams_free(void **fstreamsptr) \r
70 {
71   \rif (!(*fstreamsptr))
72     \rreturn EINVAL;
73   \r\rif ((*((fstreams_t *) fstreamsptr))->items)
74     \rxbt_dynar_free(&((*((fstreams_t *) fstreamsptr))->items));
75   \r\rfree(*fstreamsptr);
76   \r\r*fstreamsptr = NULL;
77   \rreturn 0;
78 \r}
79
80 \r\rint \r fstreams_get_size(fstreams_t fstreams) \r
81 {
82   \rif (!fstreams)
83     \r {
84     \rerrno = EINVAL;
85     \rreturn -1;
86     \r}
87   \r\rreturn xbt_dynar_length(fstreams->items);
88 \r}
89
90 \r\rint \r fstreams_is_empty(fstreams_t fstreams) \r
91 {
92   \rif (!fstreams)
93     \r {
94     \rerrno = EINVAL;
95     \rreturn -1;
96     \r}
97   \r\rreturn (0 == xbt_dynar_length(fstreams->items));
98 \r}
99
100 \r