Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deprecate MSG_clean
[simgrid.git] / tools / gras / stub_generator.c
index 66c2596..bdd5613 100644 (file)
 
 #include "gras_stub_generator.h"
 #include <stdarg.h>
-
-
+extern char *xbt_binary_name;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen, gras, "Stub generator");
 
-
 #ifdef _XBT_WIN32
 #include <windows.h>
 #endif
@@ -43,64 +41,41 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen, gras, "Stub generator");
 xbt_dict_t process_function_set = NULL;
 xbt_dynar_t process_list = NULL;
 xbt_dict_t machine_set = NULL;
+char *warning = NULL;
 
 void s_process_free(void *process)
 {
   s_process_t *p = (s_process_t *) process;
-  int i;
-  for (i = 0; i < p->argc; i++)
-    free(p->argv[i]);
-  free(p->argv);
   free(p->host);
 }
 
 static s_process_t process;
 
-static void parse_process_init(void)
-{
-  xbt_dict_set(process_function_set, A_surfxml_process_function, NULL,
-               NULL);
-  xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
-  process.argc = 1;
-  process.argv = xbt_new(char *, 1);
-  process.argv[0] = xbt_strdup(A_surfxml_process_function);
-  process.host = strdup(A_surfxml_process_host);
-  /*VERB1("Function: %s",A_surfxml_process_function); */
-}
-
-static void parse_argument(void)
-{
-  process.argc++;
-  process.argv =
-      xbt_realloc(process.argv, (process.argc) * sizeof(char *));
-  process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
-}
-
-static void parse_process_finalize(void)
+static void parse_process(sg_platf_process_cbarg_t process_arg)
 {
+  xbt_dict_set(process_function_set, process_arg->function, NULL, NULL);
+  xbt_dict_set(machine_set, process_arg->host, NULL, NULL);
+  process.argc = process_arg->argc;
+  process.argv = (char**)(process_arg->argv);
+  process.host = strdup(process_arg->host);
+  /*XBT_VERB("Function: %s",A_surfxml_process_function); */
   xbt_dynar_push(process_list, &process);
-  /*VERB1("Function: %s",process.argv[0]); */
 }
 
-/*FIXME Defined in surfxml_parse.c*/
-#ifndef WIN32
-void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
-{
-  xbt_dynar_push(cb_list, &function);
-}
-#endif
-
-
 int main(int argc, char *argv[])
 {
   char *project_name = NULL;
   char *deployment_file = NULL;
   int i;
 
+  XBT_LOG_CONNECT(stubgen);
+
+  xbt_binary_name=xbt_strdup(argv[0]);
+
   surf_init(&argc, argv);
-  process_function_set = xbt_dict_new();
+  process_function_set = xbt_dict_new_homogeneous(NULL);
   process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free);
-  machine_set = xbt_dict_new();
+  machine_set = xbt_dict_new_homogeneous(NULL);
 
   for (i = 1; i < argc; i++) {
     int need_removal = 0;
@@ -122,24 +97,20 @@ int main(int argc, char *argv[])
     }
   }
 
-  xbt_assert1((argc >= 3),
+  xbt_assert((argc >= 3),
               "Usage: %s project_name deployment_file [deployment_file...]\n",
               argv[0]);
 
   project_name = argv[1];
 
-  surf_parse_reset_parser();
-  DEBUG2("%p %p", parse_process_init, &parse_process_init);
-  surfxml_add_callback(STag_surfxml_process_cb_list, &parse_process_init);
-  surfxml_add_callback(ETag_surfxml_argument_cb_list, &parse_argument);
-  surfxml_add_callback(ETag_surfxml_process_cb_list,
-                       &parse_process_finalize);
+  surf_parse_reset_callbacks();
+  sg_platf_process_add_cb(parse_process);
 
   for (i = 2; i < argc; i++) {
     deployment_file = argv[i];
     surf_parse_open(deployment_file);
     if (surf_parse())
-      xbt_assert1(0, "Parse error in %s", deployment_file);
+      xbt_die("Parse error in %s", deployment_file);
 
     surf_parse_close();
   }
@@ -156,7 +127,7 @@ int main(int argc, char *argv[])
      for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
      xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
      xbt_dict_cursor_step(cursor) ) {
-     DEBUG1("Function %s", key);      
+     XBT_DEBUG("Function %s", key);
      }
 
      xbt_dict_dump(process_function_set,print);
@@ -171,11 +142,18 @@ int main(int argc, char *argv[])
   generate_simulation_dsp_file(project_name);
   generate_real_live_dsp_file(project_name);
 
-  if (__gras_path)
-    xbt_free(__gras_path);
+  xbt_free(__gras_path);
 #endif
 
   free(warning);
+
+
+  xbt_free(process.argv);
+
+  xbt_dict_free(&process_function_set);
+  xbt_dynar_free(&process_list);
+  xbt_dict_free(&machine_set);
   surf_exit();
+
   return 0;
 }