Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reindent.
[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 "surf/surfxml_parse_private.h"
11 #include "surf/surf_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(parse, surf,
13                                 "Logging specific to the SURF  module");
14
15 #undef CLEANUP
16 #include "surfxml.c"
17
18 static xbt_dynar_t surf_input_buffer_stack = NULL;
19 static xbt_dynar_t surf_file_to_parse_stack = NULL;
20
21 void nil_function(void);
22 void nil_function(void)
23 {
24   return;
25 }
26
27 void_f_void_t *STag_surfxml_platform_description_fun = nil_function;
28 void_f_void_t *ETag_surfxml_platform_description_fun = nil_function;
29 void_f_void_t *STag_surfxml_cpu_fun = nil_function;
30 void_f_void_t *ETag_surfxml_cpu_fun = nil_function;
31 void_f_void_t *STag_surfxml_router_fun = nil_function;
32 void_f_void_t *ETag_surfxml_router_fun = nil_function;
33 void_f_void_t *STag_surfxml_network_link_fun = nil_function;
34 void_f_void_t *ETag_surfxml_network_link_fun = nil_function;
35 void_f_void_t *STag_surfxml_route_fun = nil_function;
36 void_f_void_t *ETag_surfxml_route_fun = nil_function;
37 void_f_void_t *STag_surfxml_route_element_fun = nil_function;
38 void_f_void_t *ETag_surfxml_route_element_fun = nil_function;
39 void_f_void_t *STag_surfxml_process_fun = nil_function;
40 void_f_void_t *ETag_surfxml_process_fun = nil_function;
41 void_f_void_t *STag_surfxml_argument_fun = nil_function;
42 void_f_void_t *ETag_surfxml_argument_fun = nil_function;
43
44 YY_BUFFER_STATE surf_input_buffer;
45 FILE *surf_file_to_parse;
46
47 void surf_parse_reset_parser(void)
48 {
49   STag_surfxml_platform_description_fun = nil_function;
50   ETag_surfxml_platform_description_fun = nil_function;
51   STag_surfxml_cpu_fun = nil_function;
52   ETag_surfxml_cpu_fun = nil_function;
53   STag_surfxml_router_fun = nil_function;
54   ETag_surfxml_router_fun = nil_function;
55   STag_surfxml_network_link_fun = nil_function;
56   ETag_surfxml_network_link_fun = nil_function;
57   STag_surfxml_route_fun = nil_function;
58   ETag_surfxml_route_fun = nil_function;
59   STag_surfxml_route_element_fun = nil_function;
60   ETag_surfxml_route_element_fun = nil_function;
61   STag_surfxml_process_fun = nil_function;
62   ETag_surfxml_process_fun = nil_function;
63   STag_surfxml_argument_fun = nil_function;
64   ETag_surfxml_argument_fun = nil_function;
65 }
66
67 void STag_surfxml_include(void)
68 {
69   xbt_dynar_push(surf_input_buffer_stack, &surf_input_buffer);
70   xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse);
71
72   surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r");
73   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",
74               A_surfxml_include_file);
75   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
76   surf_parse__switch_to_buffer(surf_input_buffer);
77   printf("STAG\n");
78   fflush(NULL);
79 }
80
81 void ETag_surfxml_include(void)
82 {
83   printf("ETAG\n");
84   fflush(NULL);
85   surf_parse__delete_buffer(surf_input_buffer);
86   fclose(surf_file_to_parse);
87   xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
88   xbt_dynar_pop(surf_input_buffer_stack, &surf_input_buffer);
89 }
90
91 void STag_surfxml_platform_description(void)
92 {
93   double version = 0.0;
94
95   sscanf(A_surfxml_platform_description_version, "%lg", &version);
96
97   xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n "
98               "You're using an old XML file. "
99               "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
100               "instead of MBytes, MFlops and seconds. "
101               "A script (surfxml_update.pl) to help you convert your old "
102               "platform files "
103               "is available in the contrib/platform_generation directory "
104               "of the simgrid repository. Please check also out the "
105               "SURF section of the ChangeLog for the 3.1 version. "
106               "Last, do not forget to also update your values for "
107               "the calls to MSG_task_create (if any).");
108
109   STag_surfxml_platform_description_fun();
110 }
111
112 void ETag_surfxml_platform_description(void)
113 {
114   ETag_surfxml_platform_description_fun();
115 }
116
117 void STag_surfxml_cpu(void)
118 {
119   STag_surfxml_cpu_fun();
120 }
121
122 void ETag_surfxml_cpu(void)
123 {
124   ETag_surfxml_cpu_fun();
125 }
126
127 void STag_surfxml_router(void)
128 {
129   STag_surfxml_router_fun();
130 }
131
132 void ETag_surfxml_router(void)
133 {
134   ETag_surfxml_router_fun();
135 }
136
137 void STag_surfxml_network_link(void)
138 {
139   STag_surfxml_network_link_fun();
140 }
141
142 void ETag_surfxml_network_link(void)
143 {
144   ETag_surfxml_network_link_fun();
145 }
146
147 void STag_surfxml_route(void)
148 {
149   STag_surfxml_route_fun();
150 }
151
152 void ETag_surfxml_route(void)
153 {
154   ETag_surfxml_route_fun();
155 }
156
157 void STag_surfxml_route_element(void)
158 {
159   STag_surfxml_route_element_fun();
160 }
161
162 void ETag_surfxml_route_element(void)
163 {
164   ETag_surfxml_route_element_fun();
165 }
166
167 void STag_surfxml_process(void)
168 {
169   STag_surfxml_process_fun();
170 }
171
172 void ETag_surfxml_process(void)
173 {
174   ETag_surfxml_process_fun();
175 }
176
177 void STag_surfxml_argument(void)
178 {
179   STag_surfxml_argument_fun();
180 }
181
182 void ETag_surfxml_argument(void)
183 {
184   ETag_surfxml_argument_fun();
185 }
186
187 void surf_parse_open(const char *file)
188 {
189   static int warned = 0;        /* warn only once */
190   if (!file) {
191     if (!warned) {
192       WARN0
193           ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.");
194       warned = 1;
195     }
196     return;
197   }
198   if (!surf_input_buffer_stack)
199     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
200   if (!surf_file_to_parse_stack)
201     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
202
203   surf_file_to_parse = surf_fopen(file, "r");
204   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
205   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
206   surf_parse__switch_to_buffer(surf_input_buffer);
207   surf_parse_lineno = 1;
208 }
209
210 void surf_parse_close(void)
211 {
212   if (surf_input_buffer_stack)
213     xbt_dynar_free(&surf_input_buffer_stack);
214   if (surf_file_to_parse_stack)
215     xbt_dynar_free(&surf_file_to_parse_stack);
216
217   if (surf_file_to_parse) {
218     surf_parse__delete_buffer(surf_input_buffer);
219     fclose(surf_file_to_parse);
220   }
221 }
222
223
224 static int _surf_parse(void)
225 {
226   return surf_parse_lex();
227 }
228
229 int_f_void_t *surf_parse = _surf_parse;
230
231 void surf_parse_get_double(double *value, const char *string)
232 {
233   int ret = 0;
234
235   ret = sscanf(string, "%lg", value);
236   xbt_assert2((ret == 1), "Parse error line %d : %s not a number",
237               surf_parse_lineno, string);
238 }
239
240 void surf_parse_get_trace(tmgr_trace_t * trace, const char *string)
241 {
242   if ((!string) || (strcmp(string, "") == 0))
243     *trace = NULL;
244   else
245     *trace = tmgr_trace_new(string);
246 }