3 /* Copyright (c) 2006 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 "xbt/asserts.h"
12 #include "xbt/dynar.h"
13 #include "xbt/graphxml_parse.h"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(graphxml_parse, xbt ,"Logging specific to the graphxml parsing module");
20 static xbt_dynar_t xbt_graph_input_buffer_stack=NULL;
21 static xbt_dynar_t xbt_graph_file_to_parse_stack=NULL;
23 static void nil_function(void)
28 void_f_void_t STag_graph_fun = nil_function;
29 void_f_void_t ETag_graph_fun = nil_function;
30 void_f_void_t STag_node_fun = nil_function;
31 void_f_void_t ETag_node_fun = nil_function;
32 void_f_void_t STag_edge_fun = nil_function;
33 void_f_void_t ETag_edge_fun = nil_function;
35 YY_BUFFER_STATE xbt_graph_input_buffer;
36 FILE *xbt_graph_file_to_parse;
38 void xbt_graph_parse_reset_parser(void)
40 STag_graph_fun = nil_function;
41 ETag_graph_fun = nil_function;
42 STag_node_fun = nil_function;
43 ETag_node_fun = nil_function;
44 STag_edge_fun = nil_function;
45 ETag_edge_fun = nil_function;
82 void xbt_graph_parse_open(const char *file) {
84 WARN0("I hope you know what you're doing... you just gave me a NULL pointer!");
87 if(!xbt_graph_input_buffer_stack)
88 xbt_graph_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL);
89 if(!xbt_graph_file_to_parse_stack)
90 xbt_graph_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL);
92 xbt_graph_file_to_parse = fopen(file,"r"); /* FIXME should use something like surf_fopen */
93 xbt_assert1((xbt_graph_file_to_parse), "Unable to open \"%s\"\n",file);
94 xbt_graph_input_buffer = xbt_graph_parse__create_buffer( xbt_graph_file_to_parse, 10);
95 xbt_graph_parse__switch_to_buffer(xbt_graph_input_buffer);
96 xbt_graph_parse_lineno = 1;
99 void xbt_graph_parse_close(void) {
100 if(xbt_graph_input_buffer_stack)
101 xbt_dynar_free(&xbt_graph_input_buffer_stack);
102 if(xbt_graph_file_to_parse_stack)
103 xbt_dynar_free(&xbt_graph_file_to_parse_stack);
105 if(xbt_graph_file_to_parse) {
106 xbt_graph_parse__delete_buffer(xbt_graph_input_buffer);
107 fclose(xbt_graph_file_to_parse);
112 static int _xbt_graph_parse(void)
114 return xbt_graph_parse_lex();
117 int_f_void_t xbt_graph_parse = _xbt_graph_parse;
119 void xbt_graph_parse_get_double(double *value,const char *string)
123 ret = sscanf(string, "%lg", value);
124 xbt_assert2((ret==1), "Parse error line %d : %s not a number", xbt_graph_parse_lineno,