Author: esr
Date: Thu Apr 26 05:41:11 2007
New Revision: 17103

URL: http://svn.gna.org/viewcvs/wesnoth?rev=17103&view=rev
Log:
Give macroscope the ability to detect duplicate resource files.

Modified:
    trunk/data/tools/Makefile
    trunk/data/tools/macroscope

Modified: trunk/data/tools/Makefile
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/Makefile?rev=17103&r1=17102&r2=17103&view=diff
==============================================================================
--- trunk/data/tools/Makefile (original)
+++ trunk/data/tools/Makefile Thu Apr 26 05:41:11 2007
@@ -9,7 +9,7 @@
 FAKE = --force-used "(terrain|buttons|cursors|cursors-bw|menu|icons)/"
 # Suppress meaningless errors about castle graphics and about resources 
 # used only by the GUI code in C++
-EXCLUDE = --exclude "(exploder|castle-cutter|UI)"
+EXCLUDE = --exclude ".dirstamp|po/|translations/|exploder/|castle-cutter/|UI/"
 
 unresolved:
        @echo "# Report on unresolved macro calls and resource references"
@@ -34,6 +34,10 @@
 definitions:
        @./macroscope --definitions --exclude data/scenarios --exclude 
data/campaigns $(EXCLUDE) $(TOPDIR)
 
+collisions:
+       @echo "# Report on duplicate resource files."
+       @./macroscope --collisions $(EXCLUDE) $(TOPDIR)
+
 macro-reference.xhtml:
        @cat helpheader.xhtml >macro-reference.xhtml
        @./macroscope --extracthelp --exclude data/scenarios --exclude 
data/tutorial --exclude data/campaigns $(EXCLUDE) $(TOPDIR) 
>>macro-reference.xhtml

Modified: trunk/data/tools/macroscope
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/macroscope?rev=17103&r1=17102&r2=17103&view=diff
==============================================================================
--- trunk/data/tools/macroscope (original)
+++ trunk/data/tools/macroscope Thu Apr 26 05:41:11 2007
@@ -366,6 +366,7 @@
     Options may be any of these:
     -h, --help                 Emit this help message and quit
     -c, --crossreference       Report resolved macro references (implies -w 1)
+    -C, --collisions           Report duplicate resource files   
     -d, --deflist              Make definition list
     -e reg, --exclude reg      Ignore files matching 
     -f dir, --from dir         Report only on macros defined under dir
@@ -379,9 +380,10 @@
 """)
 
     # Process options
-    (options, arguments) = getopt.getopt(sys.argv[1:], "cdhe:f:lr:uw:",
+    (options, arguments) = getopt.getopt(sys.argv[1:], "cCdhe:f:lr:uw:",
                                          [
                                           'crossreference',
+                                          'collisions',
                                           'definitions',
                                           'exclude=',
                                           'extracthelp',
@@ -399,6 +401,7 @@
     forceused = None
     exclude = []
     warnlevel = 0
+    collisions = False
     for (switch, val) in options:
         if switch in ('-h', '--help'):
             help()
@@ -408,6 +411,8 @@
         elif switch in ('-c', '--crossreference'):
             crossreference = True
             warnlevel = 1
+        elif switch in ('-C', '--collisions'):
+            collisions = True
         elif switch in ('-d', '--definitions'):
             definitions = True
         elif switch in ('-e', '--exclude'):
@@ -435,6 +440,24 @@
     elif listfiles:
         for filename in xref.filelist:
             print filename
+    if collisions:
+        collisions = []
+        for filename in xref.filelist:
+            ifp = open(filename)
+            collisions.append(md5.new(ifp.read()).digest())
+            ifp.close()
+        collisions = zip(xref.filelist, collisions)
+        hashcounts = {}
+        for (n, h) in collisions:
+            hashcounts[h] = hashcounts.get(h, 0) + 1
+        collisions = filter(lambda (n, h): hashcounts[h] > 1, collisions)
+        collisions.sort(lambda (n1, h1), (n2, h2): cmp(h1, h2))
+        lasthash = None
+        for (n, h) in collisions:
+            if h != lasthash:
+                print "%%"
+                lasthash = h
+            print n
     elif crossreference or definitions or listfiles or unresolved:
         print "# Macroscope reporting on %s" % time.ctime()
         print "# Invocation: %s" % " ".join(sys.argv)


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to