1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #include "simgrid/platf.h"
12 #include "surf/surfxml_parse.h"
13 #include "surf/surf_private.h"
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
18 * Allow the cluster tag to mess with the parsing buffer.
19 * (this will probably become obsolete once the cluster tag do not mess with the parsing callbacks directly)
22 /* This buffer is used to store the original buffer before substituting it by out own buffer. Useful for the cluster tag */
23 static xbt_dynar_t surfxml_bufferstack_stack = NULL;
24 int surfxml_bufferstack_size = 2048;
26 static char *old_buff = NULL;
28 unsigned int surfxml_buffer_stack_stack_ptr;
29 unsigned int surfxml_buffer_stack_stack[1024];
32 void surfxml_bufferstack_push(int new)
35 old_buff = surfxml_bufferstack;
37 xbt_dynar_push(surfxml_bufferstack_stack, &surfxml_bufferstack);
38 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
42 void surfxml_bufferstack_pop(int new)
45 surfxml_bufferstack = old_buff;
47 free(surfxml_bufferstack);
48 xbt_dynar_pop(surfxml_bufferstack_stack, &surfxml_bufferstack);
56 xbt_dict_t traces_set_list = NULL;
57 xbt_dict_t trace_connect_list_host_avail = NULL;
58 xbt_dict_t trace_connect_list_power = NULL;
59 xbt_dict_t trace_connect_list_link_avail = NULL;
60 xbt_dict_t trace_connect_list_bandwidth = NULL;
61 xbt_dict_t trace_connect_list_latency = NULL;
63 /* This function acts as a main in the parsing area. */
64 void parse_platform_file(const char *file)
68 surf_parse_init_callbacks();
70 /* Register classical callbacks */
71 storage_register_callbacks();
72 routing_register_callbacks();
74 /* init the flex parser */
75 surfxml_buffer_stack_stack_ptr = 1;
76 surfxml_buffer_stack_stack[0] = 0;
78 surf_parse_open(file);
81 if (!surfxml_bufferstack_stack)
82 surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL);
84 traces_set_list = xbt_dict_new_homogeneous(NULL);
85 trace_connect_list_host_avail = xbt_dict_new_homogeneous(free);
86 trace_connect_list_power = xbt_dict_new_homogeneous(free);
87 trace_connect_list_link_avail = xbt_dict_new_homogeneous(free);
88 trace_connect_list_bandwidth = xbt_dict_new_homogeneous(free);
89 trace_connect_list_latency = xbt_dict_new_homogeneous(free);
91 /* Do the actual parsing */
92 parse_status = surf_parse();
95 xbt_dict_free(&trace_connect_list_host_avail);
96 xbt_dict_free(&trace_connect_list_power);
97 xbt_dict_free(&trace_connect_list_link_avail);
98 xbt_dict_free(&trace_connect_list_bandwidth);
99 xbt_dict_free(&trace_connect_list_latency);
100 xbt_dict_free(&traces_set_list);
101 xbt_dict_free(&random_data_list);
102 xbt_dynar_free(&surfxml_bufferstack_stack);
104 /* Stop the flex parser */
107 xbt_die("Parse error in %s", file);