+/*
+ * Stuff relative to the <include> tag
+ */
+
+static xbt_dynar_t surf_input_buffer_stack = NULL;
+static xbt_dynar_t surf_file_to_parse_stack = NULL;
+
+void STag_surfxml_include(void)
+{
+ XBT_INFO("STag_surfxml_include '%s'",A_surfxml_include_file);
+ xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old filename
+
+ surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new filename
+ xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
+ A_surfxml_include_file);
+ xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
+ surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
+ surf_parse_push_buffer_state(surf_input_buffer);
+ fflush(NULL);
+}
+
+void ETag_surfxml_include(void) {
+/* Nothing to do when done with reading the include tag.
+ * Instead, the handling should be deferred until the EOF of current buffer -- see below */
+}
+
+/** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
+ *
+ * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
+ * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
+ * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
+ * error message in that case.
+ *
+ * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
+ * directly: a command line flag could instruct it to do the correct thing when #include is encountered
+ * on a line.
+ */
+int ETag_surfxml_include_state(void)
+{
+ fflush(NULL);
+ XBT_INFO("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
+ if(xbt_dynar_length(surf_input_buffer_stack)!= 0)
+ return 1;
+ fclose(surf_file_to_parse);
+ xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
+ surf_parse_pop_buffer_state();
+ xbt_dynar_pop(surf_input_buffer_stack,surf_input_buffer);
+ return 0;
+}
+
+
+void surf_parse_init_callbacks(void)
+{
+ sg_platf_init(); // FIXME: move to a proper place?
+
+ STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_link_ctn_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_link_ctn_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_process_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_process_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_argument_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_argument_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_trace_connect_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_trace_connect_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_ASroute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_ASroute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_bypassRoute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_bypassRoute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_cluster_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_cluster_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_peer_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_peer_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_include_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_include_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+}
+
+void surf_parse_reset_callbacks(void)
+{
+ surf_parse_free_callbacks();
+ surf_parse_init_callbacks();
+}
+