Added scripts for source code maintainance
authorIngo Ruhnke <grumbel@gmx.de>
Thu, 19 Nov 2009 04:37:32 +0000 (04:37 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Thu, 19 Nov 2009 04:37:32 +0000 (04:37 +0000)
SVN-Revision: 6042

tools/fix_include_guards.sh [new file with mode: 0755]
tools/include_optimize.rb [new file with mode: 0755]

diff --git a/tools/fix_include_guards.sh b/tools/fix_include_guards.sh
new file mode 100755 (executable)
index 0000000..d8ecafa
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+for i in "$@"; do
+    echo $i
+    NAME=$(echo $i | sed "s/[\/\.]/_/g;s/^/HEADER_SUPERTUX_/" | tr [a-z] [A-Z])
+    sed  -i "s/^#ifndef .*_H_\$/#ifndef $NAME/" $i; 
+    sed  -i "s/^#define .*_H_\$/#define $NAME/" $i; 
+done
+
+# EOF #
diff --git a/tools/include_optimize.rb b/tools/include_optimize.rb
new file mode 100755 (executable)
index 0000000..5183da9
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/ruby -w
+
+def write_file_without_lines(source, lines, without_lines)
+  out = File.new(source, 'w')
+  lines.each_with_index { |v, i|
+    if without_lines.member? i then
+      out.print "//", v
+    else
+      out.print v
+    end
+  }
+  out.close()
+end
+
+def optimize(source, target)
+  lines = File.new(source).readlines()
+  includes = []
+  lines.each_with_index { |v, i|
+    if v =~ /^#include/ then
+      # puts v
+      includes << i
+    end
+  }
+
+  unneeded_includes = []
+
+  includes.each{|i|
+    # puts i
+    write_file_without_lines(source, lines, [i])
+
+    ret = system("scons", "-u", target)
+    if ret then
+      puts "INCUNNEEDED #{source} #{lines[i].chop}" 
+      unneeded_includes << i
+    end
+  }
+
+  write_file_without_lines(source, lines, unneeded_includes)
+end
+
+ARGV.each{ |filename|
+  source = filename
+  target = "build/#{filename.gsub(/\..pp$/, '.o')}"
+  puts "#{source} => #{target}"
+
+  optimize(source, target)
+}
+
+# EOF #