Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
I can't believe I had forgotten to add surf_parse.c... Also add a wrapper to surf_par...
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 6 Jan 2005 21:47:51 +0000 (21:47 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 6 Jan 2005 21:47:51 +0000 (21:47 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@739 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/include/surf/surf_parse.h
src/surf/surf_parse.c [new file with mode: 0644]

index 7fa1e8b..32e810e 100644 (file)
@@ -30,9 +30,10 @@ extern void_f_void_t STag_argument_fun;
 extern void_f_void_t ETag_argument_fun;
 
 
-void  surf_parse_open(const char *file);
-void  surf_parse_close(void);
-void  surf_parse_reset_parser(void);
+void surf_parse_open(const char *file);
+void surf_parse_close(void);
+int  surf_parse(void);
+void surf_parse_reset_parser(void);
 void surf_parse_get_double(double *value,const char *string);
 void surf_parse_get_trace(tmgr_trace_t *trace, const char *string);
 
diff --git a/src/surf/surf_parse.c b/src/surf/surf_parse.c
new file mode 100644 (file)
index 0000000..02d8c0f
--- /dev/null
@@ -0,0 +1,191 @@
+/*     $Id$     */
+
+/* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "xbt/misc.h"
+#include "xbt/error.h"
+#include "surf/surf_parse.h"
+#include "surf/surf_private.h"
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(parse, surf ,"Logging specific to the SURF  module");
+
+#include "surfxml.c"
+
+static xbt_dynar_t surf_input_buffer_stack=NULL;
+static xbt_dynar_t surf_file_to_parse_stack=NULL;
+
+void nil_function(void);
+void nil_function(void)
+{
+  return;
+}
+
+void_f_void_t STag_platform_description_fun = nil_function;
+void_f_void_t ETag_platform_description_fun = nil_function;
+void_f_void_t STag_cpu_fun = nil_function;
+void_f_void_t ETag_cpu_fun = nil_function;
+void_f_void_t STag_network_link_fun = nil_function;
+void_f_void_t ETag_network_link_fun = nil_function;
+void_f_void_t STag_route_fun = nil_function;
+void_f_void_t ETag_route_fun = nil_function;
+void_f_void_t STag_route_element_fun = nil_function;
+void_f_void_t ETag_route_element_fun = nil_function;
+void_f_void_t STag_process_fun = nil_function;
+void_f_void_t ETag_process_fun = nil_function;
+void_f_void_t STag_argument_fun = nil_function;
+void_f_void_t ETag_argument_fun = nil_function;
+
+YY_BUFFER_STATE surf_input_buffer;
+FILE *surf_file_to_parse;
+
+void surf_parse_reset_parser(void)
+{
+  STag_platform_description_fun = nil_function;
+  ETag_platform_description_fun = nil_function;
+  STag_cpu_fun = nil_function;
+  ETag_cpu_fun = nil_function;
+  STag_network_link_fun = nil_function;
+  ETag_network_link_fun = nil_function;
+  STag_route_fun = nil_function;
+  ETag_route_fun = nil_function;
+  STag_route_element_fun = nil_function;
+  ETag_route_element_fun = nil_function;
+  STag_process_fun = nil_function;
+  ETag_process_fun = nil_function;
+  STag_argument_fun = nil_function;
+  ETag_argument_fun = nil_function;
+}
+
+void STag_include(void)
+{
+  xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
+  xbt_dynar_push(surf_file_to_parse_stack,&surf_file_to_parse);
+  
+  surf_file_to_parse = surf_fopen(A_include_file,"r");
+  xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",A_include_file);
+  surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
+  surf_parse__switch_to_buffer(surf_input_buffer);
+  printf("STAG\n"); fflush(NULL);
+}
+
+void ETag_include(void)
+{
+  printf("ETAG\n"); fflush(NULL);
+  surf_parse__delete_buffer(surf_input_buffer);
+  fclose(surf_file_to_parse);
+  xbt_dynar_pop(surf_file_to_parse_stack,&surf_file_to_parse);
+  xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
+}
+
+void STag_platform_description(void)
+{
+  STag_platform_description_fun();
+}
+
+void ETag_platform_description(void)
+{
+  ETag_platform_description_fun();
+}
+
+void STag_cpu(void)
+{
+  STag_cpu_fun();
+}
+
+void ETag_cpu(void)
+{
+  ETag_cpu_fun();
+}
+
+void STag_network_link(void)
+{
+  STag_network_link_fun();
+}
+
+void ETag_network_link(void)
+{
+  ETag_network_link_fun();
+}
+
+void STag_route(void)
+{
+  STag_route_fun();
+}
+
+void ETag_route(void)
+{
+  ETag_route_fun();
+}
+
+void STag_route_element(void)
+{
+  STag_route_element_fun();
+}
+
+void ETag_route_element(void)
+{
+  ETag_route_element_fun();
+}
+
+void STag_process(void)
+{
+  STag_process_fun();
+}
+
+void ETag_process(void)
+{
+  ETag_process_fun();
+}
+
+void STag_argument(void)
+{
+  STag_argument_fun();
+}
+
+void ETag_argument(void)
+{
+  ETag_argument_fun();
+}
+
+void  surf_parse_open(const char *file) {
+  if(!surf_input_buffer_stack) 
+    surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL);
+  if(!surf_file_to_parse_stack) 
+    surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL);
+
+  surf_file_to_parse = surf_fopen(file,"r");
+  xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",file);
+  surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
+  surf_parse__switch_to_buffer(surf_input_buffer);
+}
+
+void  surf_parse_close(void) {
+  surf_parse__delete_buffer(surf_input_buffer);
+  fclose(surf_file_to_parse);
+}
+
+int surf_parse(void)
+{
+  int ret=0;
+  return surf_parse_lex();
+}
+
+void surf_parse_get_double(double *value,const char *string)
+{ 
+  int ret = 0;
+
+  ret = sscanf(string, "%lg", value);
+  xbt_assert2((ret==1), "Parse error line %d : %s not a number", surf_parse_lineno,
+             string);
+}
+
+void surf_parse_get_trace(tmgr_trace_t *trace, const char *string)
+{
+  if ((!string) || (strcmp(string, "") == 0))
+    *trace = NULL;
+  else
+    *trace = tmgr_trace_new(string);
+}
+