Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1bbc565c230c8f2c1aa775201999301df00f51b9
[simgrid.git] / src / surf / surf_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/surf_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_platform_description_fun = nil_function;
27 void_f_void_t ETag_platform_description_fun = nil_function;
28 void_f_void_t STag_cpu_fun = nil_function;
29 void_f_void_t ETag_cpu_fun = nil_function;
30 void_f_void_t STag_network_link_fun = nil_function;
31 void_f_void_t ETag_network_link_fun = nil_function;
32 void_f_void_t STag_route_fun = nil_function;
33 void_f_void_t ETag_route_fun = nil_function;
34 void_f_void_t STag_route_element_fun = nil_function;
35 void_f_void_t ETag_route_element_fun = nil_function;
36 void_f_void_t STag_process_fun = nil_function;
37 void_f_void_t ETag_process_fun = nil_function;
38 void_f_void_t STag_argument_fun = nil_function;
39 void_f_void_t ETag_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_platform_description_fun = nil_function;
47   ETag_platform_description_fun = nil_function;
48   STag_cpu_fun = nil_function;
49   ETag_cpu_fun = nil_function;
50   STag_network_link_fun = nil_function;
51   ETag_network_link_fun = nil_function;
52   STag_route_fun = nil_function;
53   ETag_route_fun = nil_function;
54   STag_route_element_fun = nil_function;
55   ETag_route_element_fun = nil_function;
56   STag_process_fun = nil_function;
57   ETag_process_fun = nil_function;
58   STag_argument_fun = nil_function;
59   ETag_argument_fun = nil_function;
60 }
61
62 void STag_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_include_file,"r");
68   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",A_include_file);
69   surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
70   surf_parse__switch_to_buffer(surf_input_buffer);
71   printf("STAG\n"); fflush(NULL);
72 }
73
74 void ETag_include(void)
75 {
76   printf("ETAG\n"); fflush(NULL);
77   surf_parse__delete_buffer(surf_input_buffer);
78   fclose(surf_file_to_parse);
79   xbt_dynar_pop(surf_file_to_parse_stack,&surf_file_to_parse);
80   xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
81 }
82
83 void STag_platform_description(void)
84 {
85   STag_platform_description_fun();
86 }
87
88 void ETag_platform_description(void)
89 {
90   ETag_platform_description_fun();
91 }
92
93 void STag_cpu(void)
94 {
95   STag_cpu_fun();
96 }
97
98 void ETag_cpu(void)
99 {
100   ETag_cpu_fun();
101 }
102
103 void STag_network_link(void)
104 {
105   STag_network_link_fun();
106 }
107
108 void ETag_network_link(void)
109 {
110   ETag_network_link_fun();
111 }
112
113 void STag_route(void)
114 {
115   STag_route_fun();
116 }
117
118 void ETag_route(void)
119 {
120   ETag_route_fun();
121 }
122
123 void STag_route_element(void)
124 {
125   STag_route_element_fun();
126 }
127
128 void ETag_route_element(void)
129 {
130   ETag_route_element_fun();
131 }
132
133 void STag_process(void)
134 {
135   STag_process_fun();
136 }
137
138 void ETag_process(void)
139 {
140   ETag_process_fun();
141 }
142
143 void STag_argument(void)
144 {
145   STag_argument_fun();
146 }
147
148 void ETag_argument(void)
149 {
150   ETag_argument_fun();
151 }
152
153 void  surf_parse_open(const char *file) {
154   if(!file) {
155     WARN0("I hope you know what you're doing... you just gave me a NULL pointer!");
156     return;
157   }
158   if(!surf_input_buffer_stack) 
159     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL);
160   if(!surf_file_to_parse_stack) 
161     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL);
162
163   surf_file_to_parse = surf_fopen(file,"r");
164   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",file);
165   surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
166   surf_parse__switch_to_buffer(surf_input_buffer);
167   surf_parse_lineno = 1;
168 }
169
170 void  surf_parse_close(void) {
171   if(surf_input_buffer_stack) 
172     xbt_dynar_free(&surf_input_buffer_stack);
173   if(surf_file_to_parse_stack) 
174     xbt_dynar_free(&surf_file_to_parse_stack);
175
176   if(surf_file_to_parse) {
177     surf_parse__delete_buffer(surf_input_buffer);
178     fclose(surf_file_to_parse);
179   }
180 }
181
182
183 static int _surf_parse(void)
184 {
185   return surf_parse_lex();
186 }
187
188 int_f_void_t surf_parse = _surf_parse;
189
190 void surf_parse_get_double(double *value,const char *string)
191
192   int ret = 0;
193
194   ret = sscanf(string, "%lg", value);
195   xbt_assert2((ret==1), "Parse error line %d : %s not a number", surf_parse_lineno,
196               string);
197 }
198
199 void surf_parse_get_trace(tmgr_trace_t *trace, const char *string)
200 {
201   if ((!string) || (strcmp(string, "") == 0))
202     *trace = NULL;
203   else
204     *trace = tmgr_trace_new(string);
205 }
206