Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fixed licence and copyright. No more reference to da GRAS possee or the
[simgrid.git] / src / surf / surf_parse.l
index 0d10054..750b151 100644 (file)
@@ -1,7 +1,9 @@
-/* Authors: Arnaud Legrand                                                  */
+/*     $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. */
* under the terms of the license (GNU LGPL) which comes with this package. */
 
 %option noyywrap
 %{
@@ -140,6 +142,46 @@ e_surf_token_t surf_parse(void) {
   return(tok_num);
 }
 
+void find_section(const char* file, const char* section_name)
+{
+  e_surf_token_t token;
+  int found = 0;
+
+  surf_parse_open(file);
+
+  while((token=surf_parse())) {
+    if(token!=TOKEN_BEGIN_SECTION) continue;
+
+    token=surf_parse();
+    xbt_assert1((token==TOKEN_WORD),"Parse error line %d",line_pos);
+    if(strcmp(surf_parse_text,section_name)==0) found=1;
+
+    token=surf_parse();
+    xbt_assert1((token==TOKEN_CLOSURE),"Parse error line %d",line_pos);
+
+    if(found) return;
+  }
+
+  CRITICAL2("Could not find %s section in %s\n",section_name,file);
+  xbt_abort();
+}
+
+void close_section(const char* section_name)
+{
+  e_surf_token_t token;
+
+  token=surf_parse();
+  xbt_assert1((token==TOKEN_WORD),"Parse error line %d",line_pos);
+  xbt_assert1((strcmp(surf_parse_text,section_name)==0), 
+             "Closing section does not match the opening one (%s).", 
+             section_name);
+  
+  token=surf_parse();
+  xbt_assert1((token==TOKEN_CLOSURE),"Parse error line %d",line_pos);
+
+  surf_parse_close();
+}
+
 void  surf_parse_open(const char *file) {
   file_to_parse = fopen(file,"r");
   xbt_assert1((file_to_parse), "Unable to open \"%s\"\n",file)
@@ -160,6 +202,29 @@ void  surf_parse_close(void) {
   tok_num = 0;
 }
 
+void surf_parse_float(xbt_maxmin_float_t *value)
+{ 
+  e_surf_token_t token;
+  int ret = 0;
+
+  token = surf_parse();                /* power_scale */
+  xbt_assert1((token == TOKEN_WORD), "Parse error line %d", line_pos);
+  ret = sscanf(surf_parse_text, XBT_MAXMIN_FLOAT_T, value);
+  xbt_assert2((ret==1), "Parse error line %d : %s not a number", line_pos,
+             surf_parse_text);
+}
+
+void surf_parse_trace(tmgr_trace_t *trace)
+{
+  e_surf_token_t token;
+  
+  token = surf_parse();                /* power_trace */
+  xbt_assert1((token == TOKEN_WORD), "Parse error line %d", line_pos);
+  if (strcmp(surf_parse_text, "") == 0)
+    *trace = NULL;
+  else
+    *trace = tmgr_trace_new(surf_parse_text);
+}
 /*  Local variables: */
 /*  mode: c */
 /*  End: */