Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
commiting some more automatic source patching stuff, and renamed some of the
[simgrid.git] / src / smpi / fixsrc.pl
diff --git a/src/smpi/fixsrc.pl b/src/smpi/fixsrc.pl
new file mode 100755 (executable)
index 0000000..096c720
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+# FIXME: here we make the assumption that people don't do things like put
+# multiple statements after a declaration, but separated by semicolons. It's a
+# reasonable assumption for the time being, but technically it could cause
+# problems for some code.
+OUTER: while ($line = <STDIN>) {
+    if ($line =~ /#include <mpi\.h>/) {
+        print "#include <smpi.h>\n";
+        print "#include <smpi_cocci.h>\n";
+    } elsif ($line =~ /SMPI_VARINIT/) {
+        do {
+            chomp $line;
+            $line =~ s/\s+/ /g;
+            while ($line =~ s/(SMPI_VARINIT[A-Z0-9_]*?\(.*?\))//) {
+                print "$1\n";
+            } 
+            if ($line =~ /SMPI_VARINIT/) {
+                # should only happen for bad code...
+                if (!($nextline = <STDIN>)) {
+                    last OUTER;
+                }
+                $line .= $nextline;
+
+            }
+        } while ($line =~ /SMPI_VARINIT/);
+    } else {
+        print $line;
+    }
+}