3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
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. */
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");
17 static xbt_dynar_t surf_input_buffer_stack=NULL;
18 static xbt_dynar_t surf_file_to_parse_stack=NULL;
20 void nil_function(void);
21 void nil_function(void)
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;
41 YY_BUFFER_STATE surf_input_buffer;
42 FILE *surf_file_to_parse;
44 void surf_parse_reset_parser(void)
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;
62 void STag_include(void)
64 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
65 xbt_dynar_push(surf_file_to_parse_stack,&surf_file_to_parse);
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);
74 void ETag_include(void)
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);
83 void STag_platform_description(void)
85 STag_platform_description_fun();
88 void ETag_platform_description(void)
90 ETag_platform_description_fun();
103 void STag_network_link(void)
105 STag_network_link_fun();
108 void ETag_network_link(void)
110 ETag_network_link_fun();
113 void STag_route(void)
118 void ETag_route(void)
123 void STag_route_element(void)
125 STag_route_element_fun();
128 void ETag_route_element(void)
130 ETag_route_element_fun();
133 void STag_process(void)
138 void ETag_process(void)
143 void STag_argument(void)
148 void ETag_argument(void)
153 void surf_parse_open(const char *file) {
155 WARN0("I hope you know what you're doing... you just gave me a NULL pointer!");
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);
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;
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);
176 if(surf_file_to_parse) {
177 surf_parse__delete_buffer(surf_input_buffer);
178 fclose(surf_file_to_parse);
183 static int _surf_parse(void)
185 return surf_parse_lex();
188 int_f_void_t surf_parse = _surf_parse;
190 void surf_parse_get_double(double *value,const char *string)
194 ret = sscanf(string, "%lg", value);
195 xbt_assert2((ret==1), "Parse error line %d : %s not a number", surf_parse_lineno,
199 void surf_parse_get_trace(tmgr_trace_t *trace, const char *string)
201 if ((!string) || (strcmp(string, "") == 0))
204 *trace = tmgr_trace_new(string);