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. */
9 #include "xbt/sysdep.h"
11 #include "xbt/asserts.h"
13 #include "xbt/dynar.h"
14 #include "xbt/graphxml_parse.h"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(graphxml_parse, xbt ,"Logging specific to the graphxml parsing module");
21 static xbt_dynar_t xbt_graph_input_buffer_stack=NULL;
22 static xbt_dynar_t xbt_graph_file_to_parse_stack=NULL;
24 static void nil_function(void)
29 void_f_void_t STag_graphxml_graph_fun = nil_function;
30 void_f_void_t ETag_graphxml_graph_fun = nil_function;
31 void_f_void_t STag_graphxml_node_fun = nil_function;
32 void_f_void_t ETag_graphxml_node_fun = nil_function;
33 void_f_void_t STag_graphxml_edge_fun = nil_function;
34 void_f_void_t ETag_graphxml_edge_fun = nil_function;
36 YY_BUFFER_STATE xbt_graph_input_buffer;
37 FILE *xbt_graph_file_to_parse;
39 void xbt_graph_parse_reset_parser(void)
41 STag_graphxml_graph_fun = nil_function;
42 ETag_graphxml_graph_fun = nil_function;
43 STag_graphxml_node_fun = nil_function;
44 ETag_graphxml_node_fun = nil_function;
45 STag_graphxml_edge_fun = nil_function;
46 ETag_graphxml_edge_fun = nil_function;
49 void STag_graphxml_graph(void)
51 (*STag_graphxml_graph_fun)();
54 void ETag_graphxml_graph(void)
56 (*ETag_graphxml_graph_fun)();
60 void STag_graphxml_node(void)
62 (*STag_graphxml_node_fun)();
65 void ETag_graphxml_node(void)
67 (*ETag_graphxml_node_fun)();
71 void STag_graphxml_edge(void)
73 (*STag_graphxml_edge_fun)();
76 void ETag_graphxml_edge(void)
78 (*ETag_graphxml_edge_fun)();
83 void xbt_graph_parse_open(const char *file) {
85 WARN0("I hope you know what you're doing... you just gave me a NULL pointer!");
88 if(!xbt_graph_input_buffer_stack)
89 xbt_graph_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL);
90 if(!xbt_graph_file_to_parse_stack)
91 xbt_graph_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL);
93 xbt_graph_file_to_parse = fopen(file,"r"); /* FIXME should use something like surf_fopen */
94 xbt_assert1((xbt_graph_file_to_parse), "Unable to open \"%s\"\n",file);
95 xbt_graph_input_buffer = xbt_graph_parse__create_buffer( xbt_graph_file_to_parse, 10);
96 xbt_graph_parse__switch_to_buffer(xbt_graph_input_buffer);
97 xbt_graph_parse_lineno = 1;
100 void xbt_graph_parse_close(void) {
101 if(xbt_graph_input_buffer_stack)
102 xbt_dynar_free(&xbt_graph_input_buffer_stack);
103 if(xbt_graph_file_to_parse_stack)
104 xbt_dynar_free(&xbt_graph_file_to_parse_stack);
106 if(xbt_graph_file_to_parse) {
107 xbt_graph_parse__delete_buffer(xbt_graph_input_buffer);
108 fclose(xbt_graph_file_to_parse);
113 static int _xbt_graph_parse(void)
115 return xbt_graph_parse_lex();
118 int_f_void_t xbt_graph_parse = _xbt_graph_parse;
120 void xbt_graph_parse_get_double(double *value,const char *string)
124 ret = sscanf(string, "%lg", value);
125 xbt_assert2((ret==1), "Parse error line %d : %s not a number", xbt_graph_parse_lineno,