Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix
[simgrid.git] / src / xbt / xbt_replay.cpp
index f17014a..9af925b 100644 (file)
@@ -42,8 +42,8 @@ static char **action_get_action(char *name);
 static char *str_tolower (const char *str)
 {
   char *ret = xbt_strdup (str);
-  int i, n = strlen (ret);
-  for (i = 0; i < n; i++)
+  int n     = strlen(ret);
+  for (int i = 0; i < n; i++)
     ret[i] = tolower (str[i]);
   return ret;
 }
@@ -63,10 +63,8 @@ xbt_replay_reader_t xbt_replay_reader_new(const char *filename)
 
 const char **xbt_replay_reader_get(xbt_replay_reader_t reader)
 {
-  ssize_t read;
-  xbt_dynar_t d;
-  read = xbt_getline(&reader->line, &reader->line_len, reader->fp);
-  //XBT_INFO("got from trace: %s",reader->line);
+  ssize_t read = xbt_getline(&reader->line, &reader->line_len, reader->fp);
+  XBT_DEBUG("got from trace: %s", reader->line);
   reader->linenum++;
   if (read==-1)
     return nullptr; /* end of file */
@@ -77,7 +75,7 @@ const char **xbt_replay_reader_get(xbt_replay_reader_t reader)
   if (reader->line[0] == '\0')
     return xbt_replay_reader_get(reader); /* Get next line */
 
-  d=xbt_str_split_quoted_in_place(reader->line);
+  xbt_dynar_t d = xbt_str_split_quoted_in_place(reader->line);
   if (xbt_dynar_is_empty(d)) {
     xbt_dynar_free(&d);
     return xbt_replay_reader_get(reader); /* Get next line */
@@ -109,6 +107,9 @@ void xbt_replay_reader_free(xbt_replay_reader_t *reader)
  */
 void xbt_replay_action_register(const char *action_name, action_fun function)
 {
+  if (xbt_action_funs == nullptr) // If the user registers a function before the start
+    _xbt_replay_action_init();
+
   char* lowername = str_tolower (action_name);
   xbt_dict_set(xbt_action_funs, lowername, (void*) function, nullptr);
   xbt_free(lowername);
@@ -147,12 +148,11 @@ void _xbt_replay_action_exit()
  */
 int xbt_replay_action_runner(int argc, char *argv[])
 {
-  int i;
   if (xbt_action_fp) {              // A unique trace file
     while (true) {
       char **evt = action_get_action(argv[0]);
       if (evt == nullptr)
-        break;
+        break;
 
       char* lowername = str_tolower (evt[1]);
       action_fun function = (action_fun)xbt_dict_get(xbt_action_funs, lowername);
@@ -163,7 +163,7 @@ int xbt_replay_action_runner(int argc, char *argv[])
       catch(xbt_ex& e) {
         xbt_die("Replay error :\n %s", e.what());
       }
-      for (i=0;evt[i]!= nullptr;i++)
+      for (int i=0;evt[i]!= nullptr;i++)
         free(evt[i]);
       free(evt);
     }
@@ -234,7 +234,7 @@ static char **action_get_action(char *name)
         xbt_dynar_push(otherqueue, &evt);
       }
     }
-    goto todo_done;             // end of file reached while searching in vain for more work
+    // end of file reached while searching in vain for more work
   } else {
     // Get something from my queue and return it
     xbt_dynar_shift(myqueue, &evt);