Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use doxygen's section instead of my poor approximation; link to the list of all exist...
[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/error.h"
10 #include "surf/surf_parse.h"
11 #include "surf/surf_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(parse, surf ,"Logging specific to the SURF  module");
13
14 #include "surfxml.c"
15
16 static xbt_dynar_t surf_input_buffer_stack=NULL;
17 static xbt_dynar_t surf_file_to_parse_stack=NULL;
18
19 void nil_function(void);
20 void nil_function(void)
21 {
22   return;
23 }
24
25 void_f_void_t STag_platform_description_fun = nil_function;
26 void_f_void_t ETag_platform_description_fun = nil_function;
27 void_f_void_t STag_cpu_fun = nil_function;
28 void_f_void_t ETag_cpu_fun = nil_function;
29 void_f_void_t STag_network_link_fun = nil_function;
30 void_f_void_t ETag_network_link_fun = nil_function;
31 void_f_void_t STag_route_fun = nil_function;
32 void_f_void_t ETag_route_fun = nil_function;
33 void_f_void_t STag_route_element_fun = nil_function;
34 void_f_void_t ETag_route_element_fun = nil_function;
35 void_f_void_t STag_process_fun = nil_function;
36 void_f_void_t ETag_process_fun = nil_function;
37 void_f_void_t STag_argument_fun = nil_function;
38 void_f_void_t ETag_argument_fun = nil_function;
39
40 YY_BUFFER_STATE surf_input_buffer;
41 FILE *surf_file_to_parse;
42
43 void surf_parse_reset_parser(void)
44 {
45   STag_platform_description_fun = nil_function;
46   ETag_platform_description_fun = nil_function;
47   STag_cpu_fun = nil_function;
48   ETag_cpu_fun = nil_function;
49   STag_network_link_fun = nil_function;
50   ETag_network_link_fun = nil_function;
51   STag_route_fun = nil_function;
52   ETag_route_fun = nil_function;
53   STag_route_element_fun = nil_function;
54   ETag_route_element_fun = nil_function;
55   STag_process_fun = nil_function;
56   ETag_process_fun = nil_function;
57   STag_argument_fun = nil_function;
58   ETag_argument_fun = nil_function;
59 }
60
61 void STag_include(void)
62 {
63   xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
64   xbt_dynar_push(surf_file_to_parse_stack,&surf_file_to_parse);
65   
66   surf_file_to_parse = surf_fopen(A_include_file,"r");
67   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",A_include_file);
68   surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
69   surf_parse__switch_to_buffer(surf_input_buffer);
70   printf("STAG\n"); fflush(NULL);
71 }
72
73 void ETag_include(void)
74 {
75   printf("ETAG\n"); fflush(NULL);
76   surf_parse__delete_buffer(surf_input_buffer);
77   fclose(surf_file_to_parse);
78   xbt_dynar_pop(surf_file_to_parse_stack,&surf_file_to_parse);
79   xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
80 }
81
82 void STag_platform_description(void)
83 {
84   STag_platform_description_fun();
85 }
86
87 void ETag_platform_description(void)
88 {
89   ETag_platform_description_fun();
90 }
91
92 void STag_cpu(void)
93 {
94   STag_cpu_fun();
95 }
96
97 void ETag_cpu(void)
98 {
99   ETag_cpu_fun();
100 }
101
102 void STag_network_link(void)
103 {
104   STag_network_link_fun();
105 }
106
107 void ETag_network_link(void)
108 {
109   ETag_network_link_fun();
110 }
111
112 void STag_route(void)
113 {
114   STag_route_fun();
115 }
116
117 void ETag_route(void)
118 {
119   ETag_route_fun();
120 }
121
122 void STag_route_element(void)
123 {
124   STag_route_element_fun();
125 }
126
127 void ETag_route_element(void)
128 {
129   ETag_route_element_fun();
130 }
131
132 void STag_process(void)
133 {
134   STag_process_fun();
135 }
136
137 void ETag_process(void)
138 {
139   ETag_process_fun();
140 }
141
142 void STag_argument(void)
143 {
144   STag_argument_fun();
145 }
146
147 void ETag_argument(void)
148 {
149   ETag_argument_fun();
150 }
151
152 void  surf_parse_open(const char *file) {
153   if(!surf_input_buffer_stack) 
154     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL);
155   if(!surf_file_to_parse_stack) 
156     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL);
157
158   surf_file_to_parse = surf_fopen(file,"r");
159   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",file);
160   surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
161   surf_parse__switch_to_buffer(surf_input_buffer);
162   surf_parse_lineno = 1;
163 }
164
165 void  surf_parse_close(void) {
166   if(surf_input_buffer_stack) 
167     xbt_dynar_free(&surf_input_buffer_stack);
168   if(surf_file_to_parse_stack) 
169     xbt_dynar_free(&surf_file_to_parse_stack);
170
171   surf_parse__delete_buffer(surf_input_buffer);
172   fclose(surf_file_to_parse);
173 }
174
175 int surf_parse(void)
176 {
177   int ret=0;
178   return surf_parse_lex();
179 }
180
181 void surf_parse_get_double(double *value,const char *string)
182
183   int ret = 0;
184
185   ret = sscanf(string, "%lg", value);
186   xbt_assert2((ret==1), "Parse error line %d : %s not a number", surf_parse_lineno,
187               string);
188 }
189
190 void surf_parse_get_trace(tmgr_trace_t *trace, const char *string)
191 {
192   if ((!string) || (strcmp(string, "") == 0))
193     *trace = NULL;
194   else
195     *trace = tmgr_trace_new(string);
196 }
197