Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enable surfxml to live with an other xml parser in the same C code. Now dtd should...
[simgrid.git] / src / xbt / graphxml_parse.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2006 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 "xbt/asserts.h"
11
12 #include "xbt/dynar.h"
13 #include "xbt/graphxml_parse.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(graphxml_parse, xbt ,"Logging specific to the graphxml parsing  module");
16
17 #undef CLEANUP
18 #include "graphxml.c"
19
20 static xbt_dynar_t xbt_graph_input_buffer_stack=NULL;
21 static xbt_dynar_t xbt_graph_file_to_parse_stack=NULL;
22
23 static void nil_function(void)
24 {
25   return;
26 }
27
28 void_f_void_t STag_graphxml_graph_fun = nil_function;
29 void_f_void_t ETag_graphxml_graph_fun = nil_function;
30 void_f_void_t STag_graphxml_node_fun = nil_function;
31 void_f_void_t ETag_graphxml_node_fun = nil_function;
32 void_f_void_t STag_graphxml_edge_fun = nil_function;
33 void_f_void_t ETag_graphxml_edge_fun = nil_function;
34
35 YY_BUFFER_STATE xbt_graph_input_buffer;
36 FILE *xbt_graph_file_to_parse;
37
38 void xbt_graph_parse_reset_parser(void)
39 {
40   STag_graphxml_graph_fun = nil_function;
41   ETag_graphxml_graph_fun = nil_function;
42   STag_graphxml_node_fun = nil_function;
43   ETag_graphxml_node_fun = nil_function;
44   STag_graphxml_edge_fun = nil_function;
45   ETag_graphxml_edge_fun = nil_function;
46 }
47
48 void STag_graphxml_graph(void)
49 {
50   STag_graphxml_graph_fun();
51 }
52
53 void ETag_graphxml_graph(void)
54 {
55   ETag_graphxml_graph_fun();
56 }
57
58
59 void STag_graphxml_node(void)
60 {
61   STag_graphxml_node_fun();
62 }
63
64 void ETag_graphxml_node(void)
65 {
66   ETag_graphxml_node_fun();
67 }
68
69
70 void STag_graphxml_edge(void)
71 {
72   STag_graphxml_edge_fun();
73 }
74
75 void ETag_graphxml_edge(void)
76 {
77   ETag_graphxml_edge_fun();
78 }
79
80
81
82 void  xbt_graph_parse_open(const char *file) {
83   if(!file) {
84     WARN0("I hope you know what you're doing... you just gave me a NULL pointer!");
85     return;
86   }
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);
91
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;
97 }
98
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);
104
105   if(xbt_graph_file_to_parse) {
106     xbt_graph_parse__delete_buffer(xbt_graph_input_buffer);
107     fclose(xbt_graph_file_to_parse);
108   }
109 }
110
111
112 static int _xbt_graph_parse(void)
113 {
114   return xbt_graph_parse_lex();
115 }
116
117 int_f_void_t xbt_graph_parse = _xbt_graph_parse;
118
119 void xbt_graph_parse_get_double(double *value,const char *string)
120
121   int ret = 0;
122
123   ret = sscanf(string, "%lg", value);
124   xbt_assert2((ret==1), "Parse error line %d : %s not a number", xbt_graph_parse_lineno,
125               string);
126 }
127