Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Let's be brutal since we fail to understand the problem: time to get some food&sleep
[simgrid.git] / src / surf / surfxml_parse.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "xbt/misc.h"
9 #include "xbt/log.h"
10 #include "xbt/dict.h"
11 #include "surf/surfxml_parse_private.h"
12 #include "surf/surf_private.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(parse, surf,
14                                 "Logging specific to the SURF  module");
15
16 #undef CLEANUP
17 #include "surfxml.c"
18
19 /* make sure these symbols are defined as strong ones in this file so that the linked can resolve them */
20 xbt_dynar_t STag_surfxml_platform_description_cb_list = NULL;
21 xbt_dynar_t ETag_surfxml_platform_description_cb_list = NULL;
22 xbt_dynar_t STag_surfxml_host_cb_list = NULL;
23 xbt_dynar_t ETag_surfxml_host_cb_list = NULL;
24 xbt_dynar_t STag_surfxml_router_cb_list = NULL;
25 xbt_dynar_t ETag_surfxml_router_cb_list = NULL;
26 xbt_dynar_t STag_surfxml_link_cb_list = NULL;
27 xbt_dynar_t ETag_surfxml_link_cb_list = NULL;
28 xbt_dynar_t STag_surfxml_route_cb_list = NULL;
29 xbt_dynar_t ETag_surfxml_route_cb_list = NULL;
30 xbt_dynar_t STag_surfxml_link_c_ctn_cb_list = NULL;
31 xbt_dynar_t ETag_surfxml_link_c_ctn_cb_list = NULL;
32 xbt_dynar_t STag_surfxml_process_cb_list = NULL;
33 xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
34 xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
35 xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
36 xbt_dynar_t STag_surfxml_prop_cb_list = NULL;
37 xbt_dynar_t ETag_surfxml_prop_cb_list = NULL;
38
39 static xbt_dynar_t surf_input_buffer_stack = NULL;
40 static xbt_dynar_t surf_file_to_parse_stack = NULL;
41
42 void surfxml_call_cb_functions(xbt_dynar_t);
43
44 void nil_function(void);
45 void nil_function(void)
46 {
47   return;
48 }
49
50 YY_BUFFER_STATE surf_input_buffer;
51 FILE *surf_file_to_parse;
52
53 void surf_parse_reset_parser(void)
54 {
55
56   STag_surfxml_platform_description_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
57   ETag_surfxml_platform_description_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
58   STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
59   ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
60   STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
61   ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
62   STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
63   ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
64   STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
65   ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
66   STag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
67   ETag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
68   STag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
69   ETag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
70   STag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
71   ETag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
72   STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
73   ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
74
75 }
76
77 void STag_surfxml_include(void)
78 {
79   xbt_dynar_push(surf_input_buffer_stack, &surf_input_buffer);
80   xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse);
81
82   surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r");
83   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",
84               A_surfxml_include_file);
85   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
86   surf_parse__switch_to_buffer(surf_input_buffer);
87   printf("STAG\n");
88   fflush(NULL);
89 }
90
91 void ETag_surfxml_include(void)
92 {
93   printf("ETAG\n");
94   fflush(NULL);
95   surf_parse__delete_buffer(surf_input_buffer);
96   fclose(surf_file_to_parse);
97   xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
98   xbt_dynar_pop(surf_input_buffer_stack, &surf_input_buffer);
99 }
100
101 void STag_surfxml_platform_description(void)
102 {
103   double version = 0.0;
104
105   sscanf(A_surfxml_platform_description_version, "%lg", &version);
106
107   xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n "
108               "You're using an ancient XML file. "
109               "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
110               "instead of MBytes, MFlops and seconds. "
111               "A script (surfxml_update.pl) to help you convert your old "
112               "platform files "
113               "is available in the contrib/platform_generation directory "
114               "of the simgrid repository. Please check also out the "
115               "SURF section of the ChangeLog for the 3.1 version. "
116               "Last, do not forget to also update your values for "
117               "the calls to MSG_task_create (if any).");
118   xbt_assert0((version >= 2.0), "******* BIG FAT WARNING *********\n "
119               "You're using an old XML file. "
120               "A script (surfxml_update.pl) to help you convert your old "
121               "platform files "
122               "is available in the contrib/platform_generation directory "
123               "of the simgrid repository.");
124
125   surfxml_call_cb_functions(STag_surfxml_platform_description_cb_list);
126 }
127
128 void ETag_surfxml_platform_description(void)
129 {
130   surfxml_call_cb_functions(ETag_surfxml_platform_description_cb_list);
131 }
132
133 void STag_surfxml_host(void)
134 {
135   surfxml_call_cb_functions(STag_surfxml_host_cb_list);
136 }
137
138 void ETag_surfxml_host(void)
139 {
140   surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
141 }
142
143 void STag_surfxml_router(void)
144 {
145   surfxml_call_cb_functions(STag_surfxml_router_cb_list);
146 }
147
148 void ETag_surfxml_router(void)
149 {
150   surfxml_call_cb_functions(ETag_surfxml_router_cb_list);
151 }
152
153 void STag_surfxml_link(void)
154 {
155   surfxml_call_cb_functions(STag_surfxml_link_cb_list);
156 }
157
158 void ETag_surfxml_link(void)
159 {
160   surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
161 }
162
163 void STag_surfxml_route(void)
164 {
165   surfxml_call_cb_functions(STag_surfxml_route_cb_list);
166 }
167
168 void ETag_surfxml_route(void)
169 {
170   surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
171 }
172
173 void STag_surfxml_link_c_ctn(void)
174 {
175   surfxml_call_cb_functions(STag_surfxml_link_c_ctn_cb_list);
176 }
177
178 void ETag_surfxml_link_c_ctn(void)
179 {
180   surfxml_call_cb_functions(ETag_surfxml_link_c_ctn_cb_list);
181 }
182
183 void STag_surfxml_process(void)
184 {
185   surfxml_call_cb_functions(STag_surfxml_process_cb_list);
186 }
187
188 void ETag_surfxml_process(void)
189 {
190   surfxml_call_cb_functions(ETag_surfxml_process_cb_list);
191 }
192
193 void STag_surfxml_argument(void)
194 {
195   surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
196 }
197
198 void ETag_surfxml_argument(void)
199 {
200   surfxml_call_cb_functions(ETag_surfxml_argument_cb_list);
201 }
202
203 void STag_surfxml_prop(void)
204 {
205   surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
206 }
207 void ETag_surfxml_prop(void)
208 {
209   surfxml_call_cb_functions(ETag_surfxml_prop_cb_list);
210 }
211
212
213 void surf_parse_open(const char *file)
214 {
215   static int warned = 0;        /* warn only once */
216   if (!file) {
217     if (!warned) {
218       WARN0
219           ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.");
220       warned = 1;
221     }
222     return;
223   }
224   if (!surf_input_buffer_stack)
225     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
226   if (!surf_file_to_parse_stack)
227     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
228
229   surf_file_to_parse = surf_fopen(file, "r");
230   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
231   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
232   surf_parse__switch_to_buffer(surf_input_buffer);
233   surf_parse_lineno = 1;
234 }
235
236 void surf_parse_close(void)
237 {
238   if (surf_input_buffer_stack)
239     xbt_dynar_free(&surf_input_buffer_stack);
240   if (surf_file_to_parse_stack)
241     xbt_dynar_free(&surf_file_to_parse_stack);
242
243   if (surf_file_to_parse) {
244     surf_parse__delete_buffer(surf_input_buffer);
245     fclose(surf_file_to_parse);
246   }
247 }
248
249
250 static int _surf_parse(void)
251 {
252   return surf_parse_lex();
253 }
254
255 int_f_void_t surf_parse = _surf_parse;
256
257 void surf_parse_get_double(double *value, const char *string)
258 {
259   int ret = 0;
260
261   ret = sscanf(string, "%lg", value);
262   xbt_assert2((ret == 1), "Parse error line %d : %s not a number",
263               surf_parse_lineno, string);
264 }
265
266 void surf_parse_get_trace(tmgr_trace_t * trace, const char *string)
267 {
268   if ((!string) || (strcmp(string, "") == 0))
269     *trace = NULL;
270   else
271     *trace = tmgr_trace_new(string);
272 }
273
274 void parse_properties(void)
275 {
276   char *value = NULL;
277
278   if(!current_property_set) current_property_set = xbt_dict_new();
279
280    value = xbt_strdup(A_surfxml_prop_value);  
281    xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free);
282
283 }
284
285 void free_string(void *d)
286 {
287   free(*(void**)d);
288 }
289
290 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
291 {
292   xbt_dynar_push(cb_list, &function);
293 }
294
295 void surfxml_call_cb_functions(xbt_dynar_t cb_list)
296 {
297   int iterator;
298   void_f_void_t fun;
299   xbt_dynar_foreach(cb_list, iterator, fun){
300        DEBUG2("call %p %p",fun,*fun);
301        (*fun)();
302     }
303 }