Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
don't weep you little user, we are no bastards, we only look like
[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.1),"******* BIG FAT WARNING *********\n "
91               "You're using an old XML file. "
92               "Since SimGrid 3.0.2, units are Bytes, Flops, and seconds "
93               "instead of MBytes, MFlops and seconds. "
94               "A script to help you convert your old platform files "
95               "is available in the contrib/platform_generation directory "
96               "of the simgrid repository. Please check also out the "
97               "SURF section of the ChangeLog for the 3.0.2 version. "
98               "Last, do not forget to also update your values for "
99               "the calls to MSG_task_create.");
100
101   STag_surfxml_platform_description_fun();
102 }
103
104 void ETag_surfxml_platform_description(void)
105 {
106   ETag_surfxml_platform_description_fun();
107 }
108
109 void STag_surfxml_cpu(void)
110 {
111   STag_surfxml_cpu_fun();
112 }
113
114 void ETag_surfxml_cpu(void)
115 {
116   ETag_surfxml_cpu_fun();
117 }
118
119 void STag_surfxml_network_link(void)
120 {
121   STag_surfxml_network_link_fun();
122 }
123
124 void ETag_surfxml_network_link(void)
125 {
126   ETag_surfxml_network_link_fun();
127 }
128
129 void STag_surfxml_route(void)
130 {
131   STag_surfxml_route_fun();
132 }
133
134 void ETag_surfxml_route(void)
135 {
136   ETag_surfxml_route_fun();
137 }
138
139 void STag_surfxml_route_element(void)
140 {
141   STag_surfxml_route_element_fun();
142 }
143
144 void ETag_surfxml_route_element(void)
145 {
146   ETag_surfxml_route_element_fun();
147 }
148
149 void STag_surfxml_process(void)
150 {
151   STag_surfxml_process_fun();
152 }
153
154 void ETag_surfxml_process(void)
155 {
156   ETag_surfxml_process_fun();
157 }
158
159 void STag_surfxml_argument(void)
160 {
161   STag_surfxml_argument_fun();
162 }
163
164 void ETag_surfxml_argument(void)
165 {
166   ETag_surfxml_argument_fun();
167 }
168
169 void  surf_parse_open(const char *file) {
170   if(!file) {
171     WARN0("I hope you know what you're doing... you just gave me a NULL pointer!");
172     return;
173   }
174   if(!surf_input_buffer_stack) 
175     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL);
176   if(!surf_file_to_parse_stack) 
177     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL);
178
179   surf_file_to_parse = surf_fopen(file,"r");
180   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",file);
181   surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
182   surf_parse__switch_to_buffer(surf_input_buffer);
183   surf_parse_lineno = 1;
184 }
185
186 void  surf_parse_close(void) {
187   if(surf_input_buffer_stack) 
188     xbt_dynar_free(&surf_input_buffer_stack);
189   if(surf_file_to_parse_stack) 
190     xbt_dynar_free(&surf_file_to_parse_stack);
191
192   if(surf_file_to_parse) {
193     surf_parse__delete_buffer(surf_input_buffer);
194     fclose(surf_file_to_parse);
195   }
196 }
197
198
199 static int _surf_parse(void)
200 {
201   return surf_parse_lex();
202 }
203
204 int_f_void_t surf_parse = _surf_parse;
205
206 void surf_parse_get_double(double *value,const char *string)
207
208   int ret = 0;
209
210   ret = sscanf(string, "%lg", value);
211   xbt_assert2((ret==1), "Parse error line %d : %s not a number", surf_parse_lineno,
212               string);
213 }
214
215 void surf_parse_get_trace(tmgr_trace_t *trace, const char *string)
216 {
217   if ((!string) || (strcmp(string, "") == 0))
218     *trace = NULL;
219   else
220     *trace = tmgr_trace_new(string);
221 }
222