Logo AND Algorithmique Numérique Distribuée

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