Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
proper use of the HAVE_TRACING variable defined by Cmake through -Dtracing=on
[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/sysdep.h"
10 #include "xbt/log.h"
11 #include "xbt/asserts.h"
12
13 #include "xbt/dynar.h"
14 #include "xbt/graphxml_parse.h"
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(graphxml_parse, xbt,
17                                 "Logging specific to the graphxml parsing  module");
18
19 #undef CLEANUP
20 #include "graphxml.c"
21
22 static xbt_dynar_t xbt_graph_input_buffer_stack = NULL;
23 static xbt_dynar_t xbt_graph_file_to_parse_stack = NULL;
24
25 static void nil_function(void)
26 {
27   return;
28 }
29
30 void_f_void_t STag_graphxml_graph_fun = nil_function;
31 void_f_void_t ETag_graphxml_graph_fun = nil_function;
32 void_f_void_t STag_graphxml_node_fun = nil_function;
33 void_f_void_t ETag_graphxml_node_fun = nil_function;
34 void_f_void_t STag_graphxml_edge_fun = nil_function;
35 void_f_void_t ETag_graphxml_edge_fun = nil_function;
36
37 YY_BUFFER_STATE xbt_graph_input_buffer;
38 FILE *xbt_graph_file_to_parse;
39
40 void xbt_graph_parse_reset_parser(void)
41 {
42   STag_graphxml_graph_fun = nil_function;
43   ETag_graphxml_graph_fun = nil_function;
44   STag_graphxml_node_fun = nil_function;
45   ETag_graphxml_node_fun = nil_function;
46   STag_graphxml_edge_fun = nil_function;
47   ETag_graphxml_edge_fun = nil_function;
48 }
49
50 void STag_graphxml_graph(void)
51 {
52   (*STag_graphxml_graph_fun) ();
53 }
54
55 void ETag_graphxml_graph(void)
56 {
57   (*ETag_graphxml_graph_fun) ();
58 }
59
60
61 void STag_graphxml_node(void)
62 {
63   (*STag_graphxml_node_fun) ();
64 }
65
66 void ETag_graphxml_node(void)
67 {
68   (*ETag_graphxml_node_fun) ();
69 }
70
71
72 void STag_graphxml_edge(void)
73 {
74   (*STag_graphxml_edge_fun) ();
75 }
76
77 void ETag_graphxml_edge(void)
78 {
79   (*ETag_graphxml_edge_fun) ();
80 }
81
82
83
84 void xbt_graph_parse_open(const char *file)
85 {
86   if (!file) {
87     WARN0
88       ("I hope you know what you're doing... you just gave me a NULL pointer!");
89     return;
90   }
91   if (!xbt_graph_input_buffer_stack)
92     xbt_graph_input_buffer_stack =
93       xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
94   if (!xbt_graph_file_to_parse_stack)
95     xbt_graph_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
96
97   xbt_graph_file_to_parse = fopen(file, "r");   /* FIXME should use something like surf_fopen */
98   xbt_assert1((xbt_graph_file_to_parse), "Unable to open \"%s\"\n", file);
99   xbt_graph_input_buffer =
100     xbt_graph_parse__create_buffer(xbt_graph_file_to_parse, 10);
101   xbt_graph_parse__switch_to_buffer(xbt_graph_input_buffer);
102   xbt_graph_parse_lineno = 1;
103 }
104
105 void xbt_graph_parse_close(void)
106 {
107   if (xbt_graph_input_buffer_stack)
108     xbt_dynar_free(&xbt_graph_input_buffer_stack);
109   if (xbt_graph_file_to_parse_stack)
110     xbt_dynar_free(&xbt_graph_file_to_parse_stack);
111
112   if (xbt_graph_file_to_parse) {
113     xbt_graph_parse__delete_buffer(xbt_graph_input_buffer);
114     fclose(xbt_graph_file_to_parse);
115   }
116 }
117
118
119 static int _xbt_graph_parse(void)
120 {
121   return xbt_graph_parse_lex();
122 }
123
124 int_f_void_t xbt_graph_parse = _xbt_graph_parse;
125
126 void xbt_graph_parse_get_double(double *value, const char *string)
127 {
128   int ret = 0;
129
130   ret = sscanf(string, "%lg", value);
131   xbt_assert2((ret == 1), "Parse error line %d : %s not a number",
132               xbt_graph_parse_lineno, string);
133 }