Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4ec4445db3e64ef91e1cd6292d8390a010d89fdc
[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   if(!file) {
172     WARN0("I hope you know what you're doing... you just gave me a NULL pointer!");
173     return;
174   }
175   if(!surf_input_buffer_stack) 
176     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL);
177   if(!surf_file_to_parse_stack) 
178     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL);
179
180   surf_file_to_parse = surf_fopen(file,"r");
181   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",file);
182   surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
183   surf_parse__switch_to_buffer(surf_input_buffer);
184   surf_parse_lineno = 1;
185 }
186
187 void  surf_parse_close(void) {
188   if(surf_input_buffer_stack) 
189     xbt_dynar_free(&surf_input_buffer_stack);
190   if(surf_file_to_parse_stack) 
191     xbt_dynar_free(&surf_file_to_parse_stack);
192
193   if(surf_file_to_parse) {
194     surf_parse__delete_buffer(surf_input_buffer);
195     fclose(surf_file_to_parse);
196   }
197 }
198
199
200 static int _surf_parse(void)
201 {
202   return surf_parse_lex();
203 }
204
205 int_f_void_t surf_parse = _surf_parse;
206
207 void surf_parse_get_double(double *value,const char *string)
208
209   int ret = 0;
210
211   ret = sscanf(string, "%lg", value);
212   xbt_assert2((ret==1), "Parse error line %d : %s not a number", surf_parse_lineno,
213               string);
214 }
215
216 void surf_parse_get_trace(tmgr_trace_t *trace, const char *string)
217 {
218   if ((!string) || (strcmp(string, "") == 0))
219     *trace = NULL;
220   else
221     *trace = tmgr_trace_new(string);
222 }
223