Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not request status if not requested by caller.
[simgrid.git] / src / bindings / lua / lua_stub_generator.c
index a52a4d3..58dfda9 100644 (file)
@@ -1,31 +1,12 @@
-/* gras_stub_generator - creates the main() to use a GRAS program           */
+/* lua_stub_generator - creates the main() to use a GRAS program           */
 
-/* Copyright (c) 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2010. The SimGrid Team.
  * 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 "lua_stub_generator.h"
-
-#include <stdio.h>
-#include "xbt/sysdep.h"
-#include "xbt/function_types.h"
-#include "xbt/log.h"
-#include "surf/surfxml_parse.h"
-#include "surf/surf.h"
-#include "portable.h"           /* Needed for the time of the SIMIX convertion */
-#include <stdarg.h>
-
-#include <lua.h>
-#include <lauxlib.h>
-#include <lualib.h>
-
-//XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen, gras, "lua Stub generator");
-
-//to geretae associed files
-//XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(stubgen);
-
+#include "simgrid_lua.h"
 
 #define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n"
 #define SIM_SOURCENAME  "_%s_simulator.c"
@@ -50,14 +31,14 @@ char *warning = NULL;
 /**********************************************/
 
 const char *SIM_PREEMBULE =
-  "/* specific to Borland Compiler */\n"
-  "#ifdef __BORLANDC__\n"
-  "#pragma hdrstop\n"
-  "#endif\n\n"
-  "#include <stdlib.h>\n"
-  "#include <stdio.h>\n"
-  "#include \"msg/msg.h\"\n"
-  "#include <gras.h>\n" "\n" "char *gras_log=NULL;\n";
+    "/* specific to Borland Compiler */\n"
+    "#ifdef __BORLANDC__\n"
+    "#pragma hdrstop\n"
+    "#endif\n\n"
+    "#include <stdlib.h>\n"
+    "#include <stdio.h>\n"
+    "#include \"msg/msg.h\"\n"
+    "#include <gras.h>\n" "\n" "char *gras_log=NULL;\n";
 
 
 #define SIM_LAUNCH_FUNC  \
@@ -80,23 +61,21 @@ const char *SIM_PREEMBULE =
 "}\n"
 
 const char *SIM_MAIN_POSTEMBULE = "\n"
-  "\n"
-  "  gras_load_platform_script(argv[1]);\n"
-  "\n"
-  "  /*  Run the simulation */\n"
-  "  gras_main();\n"
-  "\n"
-  "  /* cleanup the place */\n"
-  "  gras_clean();\n"
-  "  if (gras_log)\n" "    free(gras_log);\n" "  return 0;\n" "}\n";
+    "\n"
+    "  gras_load_environment_script(argv[1]);\n"
+    "\n"
+    "  /*  Run the simulation */\n"
+    "  gras_main();\n"
+    "\n"
+    "  /* cleanup the place */\n"
+    "  gras_clean();\n"
+    "  if (gras_log)\n" "    free(gras_log);\n" "  return 0;\n" "}\n";
 
 
 /***************************************
  * generator functions
  ***************************************/
 
-
-
 void generate_sim(const char *project)
 {
   xbt_dict_cursor_t cursor = NULL;
@@ -129,7 +108,6 @@ void generate_sim(const char *project)
   xbt_dict_foreach(process_function_set, cursor, key, data) {
     fprintf(OUT, SIM_LAUNCH_FUNC, key, key);
   }
-  fprintf(OUT, "\n%s\n", warning);
 
   fprintf(OUT, "%s", "/* specific to Borland Compiler */\n"
           "#ifdef __BORLANDDC__\n" "#pragma argsused\n" "#endif\n\n");
@@ -141,10 +119,10 @@ void generate_sim(const char *project)
           "  if (argc != 2) {\n"
           "    fprintf(stderr, \"Usage: lua platform_script.lua [--log=...]\\n\");\n"
           "    exit(1);\n" "  }\n" "\n");
-  fprintf(OUT,
-          "\n" "  /*  Application deployment */\n");
+  fprintf(OUT, "\n" "  /*  Application deployment */\n");
   xbt_dict_foreach(process_function_set, cursor, key, data) {
-    fprintf(OUT, "  gras_function_register(\"%s\", launch_%s);\n", key, key);
+    fprintf(OUT, "  gras_function_register(\"%s\", launch_%s);\n", key,
+            key);
   }
   fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
   fclose(OUT);
@@ -154,6 +132,7 @@ void generate_sim(const char *project)
 /**********************************************/
 /**** Generate the file for the real life *****/
 /**********************************************/
+
 void generate_rl(const char *project)
 {
   xbt_dict_cursor_t cursor = NULL;
@@ -164,14 +143,14 @@ void generate_rl(const char *project)
 
   xbt_dict_foreach(process_function_set, cursor, key, data) {
     filename =
-      xbt_new(char, strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
+        xbt_new(char,
+                strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
 
     sprintf(filename, RL_SOURCENAME, project, key);
 
     OUT = fopen(filename, "w");
     xbt_assert1(OUT, "Unable to open %s for writing", filename);
 
-    fprintf(OUT, "\n%s\n", warning);
     fprintf(OUT, "/* specific to Borland Compiler */\n"
             "#ifdef __BORLANDC__\n"
             "#pragma hdrstop\n"
@@ -194,7 +173,6 @@ void generate_rl(const char *project)
             "  _gras_procname = \"%s\";\n"
             "  errcode=%s(argc,argv);\n"
             " \n" "  return errcode;\n" "}\n", key, key, key);
-    fprintf(OUT, "\n%s\n", warning);
     fclose(OUT);
     free(filename);
   }
@@ -262,9 +240,6 @@ void generate_makefile_am(const char *project)
     fprintf(OUT, " ");
   }
   fprintf(OUT, SIM_SOURCENAME, project);
-  /*fprintf(OUT, ": %s\n", deployment);
-  fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project,
-          deployment);*/
   fclose(OUT);
 }
 
@@ -276,7 +251,8 @@ void generate_makefile_local(const char *project)
   char *filename = NULL;
   FILE *OUT = NULL;
 
-  filename = xbt_new(char, strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
+  filename =
+      xbt_new(char, strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
   sprintf(filename, MAKEFILE_FILENAME_LOCAL, project);
 
   OUT = fopen(filename, "w");