[Scummvm-cvs-logs] SF.net SVN: scummvm:[35607] scummvm/trunk/tools/themeparser.py

tanoku at users.sourceforge.net tanoku at users.sourceforge.net
Mon Dec 29 15:11:26 CET 2008


Revision: 35607
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35607&view=rev
Author:   tanoku
Date:     2008-12-29 14:11:26 +0000 (Mon, 29 Dec 2008)

Log Message:
-----------
Replaced Hex Dumper in Binary theme parser.
Turned parsing classes into New Style classes.

Modified Paths:
--------------
    scummvm/trunk/tools/themeparser.py

Modified: scummvm/trunk/tools/themeparser.py
===================================================================
--- scummvm/trunk/tools/themeparser.py	2008-12-29 14:06:31 UTC (rev 35606)
+++ scummvm/trunk/tools/themeparser.py	2008-12-29 14:11:26 UTC (rev 35607)
@@ -31,36 +31,24 @@
 import xml.dom.minidom as DOM
 import struct
 
-def printBinaryDump(buf):
-	LINE_WIDTH = 16
-	
-	def buildRepr(line):
-		out = ""
-		for c in line:
-			out += '.' if ord(c) < 0x20 or ord(c) > 0x7E else c
-		return out
-	
-	print "Binary dump of %d BYTES:\n" % len(buf)
-	for i in xrange(len(buf) // LINE_WIDTH):
-		bufLine = buf[LINE_WIDTH * i : LINE_WIDTH * (i + 1)]
-		
-		print "| %s | %s |" % (" ".join(["%0.2X" % ord(c) for c in bufLine]), buildRepr(bufLine))
-		
-	bufLine = buf[-(len(buf) % LINE_WIDTH):]
-	print "| %s%s | %s%s |" % (
-		" ".join(["%0.2X" % ord(c) for c in bufLine]), 
-		'   ' * (LINE_WIDTH - len(bufLine)), 
-		buildRepr(bufLine),
-		' ' * (LINE_WIDTH - len(bufLine))
-	)
-	
-	print ""
+FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
 
+# adapted from Activestate Snippet Cookbook
+def printBinaryDump(src, length=16):
+    N=0; result=''
+    while src:
+       s,src = src[:length],src[length:]
+       hexa = ' '.join(["%02X"%ord(x) for x in s])
+       s = s.translate(FILTER)
+       result += "%04X   %-*s   %s\n" % (N, length*3, hexa, s)
+       N+=length
+    print (result)
+
 def pbin(data):
 	return str(map(lambda c: hex(ord(c)), data))
 #	return " ".join(["%0.2X" % ord(c) for c in data])
 
-class STXBinaryFile:
+class STXBinaryFile(object):
 	class InvalidRGBColor(Exception):
 		pass
 		
@@ -76,7 +64,7 @@
 	class InvalidDialogOverlay(Exception):
 		pass
 		
-	class DrawStepData:
+	class DrawStepData(object):
 		def __init__(self, isDefault, packFormat, function):
 			self.isDefault = isDefault
 			self.packFormat = packFormat
@@ -159,11 +147,11 @@
 					self._stxFiles.append(filename)
 					
 	def debug(self, text):
-		if self._verbose: print text
+		if self._verbose: print (text)
 		
 	def debugBinary(self, data):
 		if self._verbose:
-			print "BINARY OUTPUT (%d bytes):" % len(data), " ".join(["%0.2X" % ord(c) for c in data])
+			print ("BINARY OUTPUT (%d bytes): %s" % (len(data), " ".join(["%0.2X" % ord(c) for c in data])))
 			
 	def addSTXFile(self, filename):
 		if not os.path.isfile(filename):
@@ -197,7 +185,6 @@
 		
 		if bmp == "":
 			return 0x0
-		
 		if bmp not in self._bitmaps:
 			raise self.InvalidBitmapName
 		
@@ -263,7 +250,7 @@
 				size = struct.calcsize(layout)
 				packLayout += "B" * size
 				
-				for d in xrange(size):
+				for d in range(size):
 					packData.append(0)
 			else:
 				packLayout += layout
@@ -631,4 +618,4 @@
 if __name__ == '__main__':
 	bin = STXBinaryFile('../gui/themes/scummclassic', True, True)
 	bin.parse()
-	
\ No newline at end of file
+	


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list