Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Search msg.h where it is
[simgrid.git] / examples / gras_stub_generator
index 9670c75..e784543 100755 (executable)
@@ -9,8 +9,9 @@
 # under the terms of the license (GNU LGPL) which comes with this package.
   
 use strict;
-use warnings;
-
+eval qq{
+  use warnings;
+}; # warnings not defined in 5.00503/sun4-solaris
 
 sub usage {
     my ($msg)=@_;
@@ -45,9 +46,11 @@ $warn
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <msg.h>
+#include "msg/msg.h"
 #include <gras.h>
 
+char *gras_log=NULL;
+    
 EOF
  ;
 foreach (keys %process) { print OUT "int $_(int argc,char *argv[]);\n";        }
@@ -57,13 +60,22 @@ print OUT "\n$warn\n";
 
 foreach (keys %process) {
     print OUT<<EOF
-int launch_$_(int argc, char *argv[]) {
+int launch_$_(int argc, char **argv) {
+  char **myargv=argv;
+  int myargc=argc;
+  int i;
+  int retcode;
     
-  if (gras_process_init()) exit(1);
-  $_(argc,argv);
-  if (gras_process_exit()) exit(1);
-
-  return 0;
+  if (gras_log) {
+    myargv=malloc((argc+1) * sizeof(char**));
+    for (i=0; i<argc; i++)
+      myargv[i] = argv[i];
+    myargv[myargc++] = gras_log;
+  }
+  retcode = $_(myargc,myargv);
+  if (myargv != argv)
+    free(myargv);
+  return retcode;
 }
 
 EOF
@@ -73,19 +85,37 @@ print OUT "\n$warn\n";
 
 print OUT <<EOF
 int main (int argc,char *argv[]) {
-    
-  if (argc < 3) {
-    fprintf(stderr, "Usage: %s platform_file application_description.txt [extra args]\\n",argv[0]);
-    exit(1);
+  int i,j;
+
+  /* Save the gras-log argument of real command line to pass it to all processes */
+  for (i=1; i<argc; i++) {
+    if (!strncmp(argv[i],"--gras-log=",strlen("--gras-log="))) {
+      if (gras_log) {
+        char *tmp=malloc(strlen(gras_log)+strlen(argv[i])+2);
+        sprintf(tmp,"%s %s",gras_log, argv[i]);
+        free(gras_log);
+        gras_log=tmp;
+      } else {
+         gras_log = strdup(argv[i]);
+      }
+      for (j=i+1; j<argc; j++) {
+       argv[j-1] = argv[j];
+      } 
+      argv[j-1] = NULL;
+      argc--;
+      i--; /* compensate effect of next loop incrementation */
+    }
   }
 
-  /* GRAS setup */
-  gras_init(&argc, argv);
+  if (argc != 3) {
+    fprintf(stderr, "Usage: %s platform_file application_description.txt [--gras-log=...]\\n",argv[0]);
+    exit(1);
+  }
 
   /*  Simulation setup */
   MSG_global_init();
   MSG_set_verbosity(MSG_SILENT);
-  MSG_set_channel_number(GRAS_MAX_CHANNEL);
+  MSG_set_channel_number(10); // GRAS_MAX_CHANNEL hardcoded since Alvin killed its definition
   MSG_create_environment(argv[1]);
 
   /*  Application deployment */
@@ -101,6 +131,10 @@ print OUT <<EOF
   /*  Run the simulation */
   MSG_main();
 
+  /* cleanup the place */
+  MSG_clean();
+  if (gras_log)
+    free(gras_log);
   return 0;
 }
 $warn
@@ -127,11 +161,7 @@ $warn
 int main(int argc, char *argv[]){
   int errcode;
 
-  gras_init(&argc,argv);
-  gras_process_init();
   errcode=$pname(argc,argv);
-  gras_process_exit();
-  gras_exit();
  
   return errcode;
 }